[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Project.java, 1.158, 1.159
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2009-02-13 13:17:16
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28297/src/net/sourceforge/bprocessor/model Modified Files: Project.java Log Message: PPLM generation Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.158 retrieving revision 1.159 diff -C2 -d -r1.158 -r1.159 *** Project.java 12 Feb 2009 12:35:20 -0000 1.158 --- Project.java 13 Feb 2009 11:34:53 -0000 1.159 *************** *** 1265,1272 **** } ! /** ! * ! */ ! public void export() { Location root = new Location(); root.setId("building"); --- 1265,1314 ---- } ! ! private boolean eq(dk.au.perpos.spatialsupport.routefinding.Point p1, ! dk.au.perpos.spatialsupport.routefinding.Point p2) { ! if (p1.getX() != p2.getX()) { ! return false; ! } ! if (p1.getY() != p2.getY()) { ! return false; ! } ! return true; ! } ! private boolean eq(Segment s1, Segment s2) { ! if (eq(s1.getFrom(), s2.getFrom()) && eq(s1.getTo(), s2.getTo())) { ! return true; ! } ! if (eq(s1.getFrom(), s2.getTo()) && eq(s1.getTo(), s2.getFrom())) { ! return true; ! } ! return false; ! } ! private Segment find(Location location, Segment segment) { ! Boundary boundary = location.getExternalBoundary(); ! for (Segment current : boundary.getSegments()) { ! if (eq(current, segment)) { ! return current; ! } ! } ! return null; ! } ! ! private dk.au.perpos.spatialsupport.routefinding.Point convert(Vertex vertex) { ! dk.au.perpos.spatialsupport.routefinding.Point point ! = new dk.au.perpos.spatialsupport.routefinding.Point(); ! point.setX(vertex.getX()); ! point.setY(vertex.getY()); ! return point; ! } ! ! private Segment convert(Edge edge) { ! Segment segment = new Segment(); ! segment.setFrom(convert(edge.getFrom())); ! segment.setTo(convert(edge.getTo())); ! return segment; ! } ! ! private Location createLocationModel() { Location root = new Location(); root.setId("building"); *************** *** 1274,1277 **** --- 1316,1321 ---- Map<Surface, Location> map = new HashMap(); Map<Edge, List<Surface>> e2s = new HashMap(); + int openingId = 0; + int connectionId = 0; for (Edge edge : world().getEdges()) { e2s.put(edge, new LinkedList()); *************** *** 1285,1289 **** Location node = new Location(); map.put(surface, node); ! List<dk.au.perpos.spatialsupport.routefinding.Point> points = new LinkedList(); for (Vertex vertex : surface.getVertices()) { --- 1329,1333 ---- Location node = new Location(); map.put(surface, node); ! node.setHeight(3); List<dk.au.perpos.spatialsupport.routefinding.Point> points = new LinkedList(); for (Vertex vertex : surface.getVertices()) { *************** *** 1317,1321 **** } node.setId(name); ! node.setDescription("cell"); root.addChild(node); } --- 1361,1365 ---- } node.setId(name); ! node.setDescription("room"); root.addChild(node); } *************** *** 1328,1340 **** --- 1372,1515 ---- Location n2 = map.get(s2); Opening o1 = new Opening(); + openingId++; + o1.setId("opening-" + String.valueOf(openingId)); + Segment segment = convert(edge); + Segment seg1 = find(n1, segment); + o1.setSegment(seg1); + o1.setWidth(edge.getLength()); n1.addOpening(o1); + Opening o2 = new Opening(); + openingId++; + o2.setId("opening-" + String.valueOf(openingId)); + Segment seg2 = find(n2, segment); + o2.setSegment(seg2); + o2.setWidth(edge.getLength()); n2.addOpening(o2); + dk.au.perpos.spatialsupport.routefinding.Connection connection = new dk.au.perpos.spatialsupport.routefinding.Connection(); + connectionId++; + connection.setId("connection-" + String.valueOf(connectionId)); connection.setFrom(o1); connection.setTo(o2); } } + return root; + } + + + private class PPLMPrinter { + private PrintStream out; + private int indent; + + public PPLMPrinter(PrintStream out) { + this.out = out; + this.indent = 0; + } + + public void println(Object object) { + for (int i = 0; i < indent; i++) { + out.print(" "); + } + out.println(object); + } + + public void printPoint(dk.au.perpos.spatialsupport.routefinding.Point point) { + println("<Point X=\"" + point.getX() + "\" Y=\"" + point.getY() + "\" />"); + } + + public void printLocationAttributes(Location location) { + StringBuffer buffer = new StringBuffer(); + buffer.append("<Location "); + buffer.append("LocationID=\"" + location.getId() + "\" "); + buffer.append("Floor=\"" + location.getFloor() + "\" "); + buffer.append("Height=\"" + location.getHeight() + "\" "); + buffer.append("Description=\"" + location.getDescription() + "\""); + buffer.append(">"); + println(buffer); + } + + public void printOpening(Opening opening) { + StringBuffer buffer = new StringBuffer(); + buffer.append("<Opening "); + buffer.append("OpeningID=\"" + opening.getId() + "\" "); + buffer.append("ConnectionID=\"" + opening.getConnection().getId() + "\" "); + buffer.append("Distance=\"" + opening.getDistance() + "\" "); + buffer.append("OpeningDiameter=\"" + opening.getWidth() + "\""); + buffer.append(">"); + println(buffer); + } + + public void printConnection(dk.au.perpos.spatialsupport.routefinding.Connection connection) { + StringBuffer buffer = new StringBuffer(); + buffer.append("<Connection "); + buffer.append("ConnectionID=\"" + connection.getId() + "\" "); + buffer.append("OpeningID1=\"" + connection.getFrom().getId() + "\" "); + buffer.append("OpeningID2=\"" + connection.getTo().getId() + "\" "); + buffer.append(">"); + println(buffer); + } + + public void printLocationModel(Location root) { + HashSet<dk.au.perpos.spatialsupport.routefinding.Connection> connections + = new HashSet(); + println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); + println("<LocationModel>"); + indent++; + println("<Location LocationID=\"bygning\">"); + indent++; + for (Location node : root.getChildren()) { + printLocationAttributes(node); + indent++; + println("<Boundary>"); + indent++; + for (Segment current : node.getExternalBoundary().getSegments()) { + println("<Segment>"); + indent++; + printPoint(current.getFrom()); + printPoint(current.getTo()); + for (Opening opening : node.getOpenings()) { + if (opening.getSegment() == current) { + printOpening(opening); + } + } + indent--; + println("</Segment>"); + } + indent--; + println("</Boundary>"); + indent--; + for (Opening current : node.getOpenings()) { + connections.add(current.getConnection()); + } + println("</Location>"); + + } + indent--; + println("</Location>"); + for (dk.au.perpos.spatialsupport.routefinding.Connection current : connections) { + printConnection(current); + } + indent--; + println("</LocationModel>"); + } + } + + /** + * + */ + public void exportPPLM() { + Location root = createLocationModel(); + PrintStream out = System.out; + PPLMPrinter printer = new PPLMPrinter(out); + printer.printLocationModel(root); + } + + /** + * + */ + public void exportJLMA() { + Location root = createLocationModel(); PrintStream out = System.out; out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); |