[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Space.java,1.30,1.31
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2006-05-09 00:56:29
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5560 Modified Files: Space.java Log Message: fixed copy method to work proper recursively Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Space.java 7 May 2006 09:33:36 -0000 1.30 --- Space.java 7 May 2006 16:58:53 -0000 1.31 *************** *** 946,1039 **** Map copiedSurfaces = new HashMap(); Map copiedSpaces = new HashMap(); ! ! Space copy = new Space("*copy of " + this.getName() + "*", this.getType(), this.isContainer()); ! ! /* Copying the envelope of this space */ ! /* vertices */ ! Iterator it = this.collect().iterator(); while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! Vertex newVertex = v.copy(); ! if (vertices.values().contains(v)) { ! copy.add(newVertex); ! } else { ! Project.getInstance().add(newVertex); } - copiedVertices.put(v, newVertex); } ! ! /* surfaces and edges */ ! it = this.envelope.iterator(); while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! Iterator edgeIt = s.getEdges().iterator(); ! List newEdges = new LinkedList(); ! while (edgeIt.hasNext()) { ! Edge e = (Edge)edgeIt.next(); ! if (copiedEdges.keySet().contains(e)) { ! newEdges.add(copiedEdges.get(e)); ! } else { ! Edge newEdge = new Edge((Vertex)copiedVertices.get(e.getTo()), ! (Vertex)copiedVertices.get(e.getFrom())); ! Project.getInstance().add(newEdge); ! copiedEdges.put(e, newEdge); ! newEdges.add(newEdge); ! } ! } ! Surface newSurface = new Surface(newEdges); ! Space worldEmpty = Project.getInstance().world().getEmpty(); ! if (s.getBackDomain() == this) { ! newSurface.setBackDomain(copy); ! } else { ! newSurface.setBackDomain(worldEmpty); ! } ! ! if (s.getFrontDomain() == this) { ! newSurface.setFrontDomain(copy); ! } else { ! newSurface.setFrontDomain(worldEmpty); ! } ! copiedSurfaces.put(s, newSurface); ! Project.getInstance().add(newSurface); } - - Set newSurfaces = new HashSet(copiedSurfaces.values()); - copy.setEnvelope(newSurfaces); - Project.getInstance().add(copy); - - /* Copying elements of this space */ - - /* edges */ it = edges.values().iterator(); while (it.hasNext()) { Edge e = (Edge)it.next(); ! Edge elementEdge = new Edge((Vertex)copiedVertices.get(e.getTo()), ! (Vertex)copiedVertices.get(e.getFrom())); ! copiedEdges.put(e, elementEdge); ! copy.add(elementEdge); } - - /* surfaces */ it = surfaces.values().iterator(); while (it.hasNext()) { Surface s = (Surface)it.next(); ! List edgeCopies = new LinkedList(); Iterator edgeIt = s.getEdges().iterator(); while (edgeIt.hasNext()) { ! Edge e = (Edge)edgeIt.next(); ! edgeCopies.add(copiedEdges.get(e)); } ! Surface elementSurface = new Surface(edgeCopies); ! elementSurface.setBackDomain(s.getBackDomain()); ! elementSurface.setFrontDomain(s.getFrontDomain()); ! copiedSurfaces.put(s, elementSurface); ! copy.add(elementSurface); } ! ! return copy; } } --- 946,1122 ---- Map copiedSurfaces = new HashMap(); Map copiedSpaces = new HashMap(); ! Space copy = this.copy(copiedVertices, copiedEdges, ! copiedSurfaces, copiedSpaces); ! Project.getInstance().add(copy); ! Project.getInstance().checkpoint(); ! return copy; ! } ! ! /** ! * Copy this space and return the copy ! * @param copiedVertices map of vertices and their copies. ! * @param copiedEdges map of edges and their copies. ! * @param copiedSurfaces map of surfaces and their copies. ! * @param copiedSpaces map of spaces and their copies. ! * @return the copy of this space ! */ ! private Space copy(Map copiedVertices, ! Map copiedEdges, ! Map copiedSurfaces, ! Map copiedSpaces) { Space copy = new Space("*copy of " + this.getName() + "*", this.getType(), this.isContainer()); ! Set envelopeCopy = copyEnvelope(copiedVertices, ! copiedEdges, ! copiedSurfaces, ! copy); ! copy.setEnvelope(envelopeCopy); ! if (copy.isContainer()) { ! copyInteriorGeometry(copiedVertices, ! copiedEdges, ! copiedSurfaces, ! copy); ! copyInteriorSpaces(copiedVertices, ! copiedEdges, ! copiedSurfaces, ! copiedSpaces, ! copy); ! } ! return copy; ! } ! /** ! * Copies the interior spaces of this space. ! * The method maintains the four copy maps of vertices, edges, ! * surfaces and spaces. ! * @param copiedVertices map of vertices and their copies. ! * @param copiedEdges map of edges and their copies. ! * @param copiedSurfaces map of surfaces and their copies. ! * @param copiedSpaces map of spaces and their copies. ! * @param copy the copy of this space ! */ ! private void copyInteriorSpaces(Map copiedVertices, ! Map copiedEdges, ! Map copiedSurfaces, ! Map copiedSpaces, ! Space copy) { ! Iterator it = elements.values().iterator(); while (it.hasNext()) { ! Space sp = (Space)it.next(); ! if (!(sp.toString().equals("Void"))) { ! Space newSpace = sp.copy(copiedVertices, ! copiedEdges, ! copiedSurfaces, ! copiedSpaces); ! copiedSpaces.put(sp, newSpace); ! copy.add(newSpace); } } ! } ! ! /** ! * Copies the interior surfaces edges and vertices of this space. ! * The method maintains the three copy maps of vertices, edges and ! * surfaces. ! * @param copiedVertices map of vertices and their copies. ! * @param copiedEdges map of edges and their copies. ! * @param copiedSurfaces map of surfaces and their copies. ! * @param copy the copy of this space ! */ ! private void copyInteriorGeometry(Map copiedVertices, ! Map copiedEdges, ! Map copiedSurfaces, ! Space copy) { ! Iterator it = vertices.values().iterator(); while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! Vertex vCopy = v.copy(); ! copiedVertices.put(v, vCopy); ! copy.add(vCopy); } it = edges.values().iterator(); while (it.hasNext()) { Edge e = (Edge)it.next(); ! Edge eCopy = new Edge((Vertex)copiedVertices.get(e.getTo()), ! (Vertex)copiedVertices.get(e.getFrom())); ! copiedEdges.put(e, eCopy); ! copy.add(eCopy); } it = surfaces.values().iterator(); while (it.hasNext()) { Surface s = (Surface)it.next(); ! List newEdges = new LinkedList(); Iterator edgeIt = s.getEdges().iterator(); while (edgeIt.hasNext()) { ! newEdges.add(copiedEdges.get((Edge)edgeIt.next())); } ! Surface newSurface = new Surface(newEdges); ! newSurface.setFrontDomain(copy.getEmpty()); ! newSurface.setBackDomain(copy.getEmpty()); ! copiedSurfaces.put(s, newSurface); ! copy.add(newSurface); } ! } ! ! /** ! * Copies the envelope of this space and returns the ! * set of surfaces that is the envelope. The method maintains the ! * three copy maps of vertices, edges and surfaces. ! * @param copiedVertices map of vertices and their copies. ! * @param copiedEdges map of edges and their copies. ! * @param copiedSurfaces map of surfaces and their copies. ! * @param copy the copy of this space. ! * @return the envelope set of surfaces ! */ ! private Set copyEnvelope(Map copiedVertices, ! Map copiedEdges, ! Map copiedSurfaces, ! Space copy) { ! Iterator it = this.envelope.iterator(); ! Set envelopeCopy = new HashSet(); ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! Surface surfaceCopy; ! if (copiedSurfaces.keySet().contains(s)) { ! surfaceCopy = (Surface)copiedSurfaces.get(s); ! envelopeCopy.add(surfaceCopy); ! } else { ! /* This should only apply to the outer layer */ ! Iterator edgeIt = s.getEdges().iterator(); ! List edgeCopies = new LinkedList(); ! while (edgeIt.hasNext()) { ! Edge e = (Edge)edgeIt.next(); ! if (!copiedVertices.keySet().contains(e.getTo())) { ! copiedVertices.put(e.getTo(), e.getTo().copy()); ! Project.getInstance().add((Vertex)copiedVertices.get(e.getTo())); ! } ! if (!copiedVertices.keySet().contains(e.getFrom())) { ! copiedVertices.put(e.getFrom(), e.getFrom().copy()); ! Project.getInstance().add((Vertex)copiedVertices.get(e.getFrom())); ! } ! if (!copiedEdges.keySet().contains(e)) { ! copiedEdges.put(e, new Edge((Vertex)copiedVertices.get(e.getFrom()), ! (Vertex)copiedVertices.get(e.getTo()))); ! } ! Project.getInstance().add((Edge)copiedEdges.get(e)); ! edgeCopies.add(copiedEdges.get(e)); ! } ! surfaceCopy = new Surface(edgeCopies); ! Project.getInstance().add(surfaceCopy); ! surfaceCopy.setFrontDomain(Project.getInstance().world().getEmpty()); ! surfaceCopy.setBackDomain(Project.getInstance().world().getEmpty()); ! envelopeCopy.add(surfaceCopy); ! copiedSurfaces.put(s, surfaceCopy); ! } ! if (s.getFrontDomain() == this) { ! surfaceCopy.setFrontDomain(copy); ! } ! if (s.getBackDomain() == this) { ! surfaceCopy.setBackDomain(copy); ! } ! surfaceCopy.getVertices(); ! } ! return envelopeCopy; } } |