Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Space.java,1.32,1.33
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2006-05-15 12:14:31
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22614 Modified Files: Space.java Log Message: changed copying implementation Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Space.java 15 May 2006 10:33:09 -0000 1.32 --- Space.java 15 May 2006 12:14:26 -0000 1.33 *************** *** 546,550 **** surface.getExterior().addHole(curHole); } else { ! curHole.setExterior(null); } } --- 546,550 ---- surface.getExterior().addHole(curHole); } else { ! curHole.setExterior(null); } } *************** *** 798,801 **** --- 798,802 ---- } elements.put(id, element); + element.setOwner(this); } else { throw new Error("adding element to non-container " + this); *************** *** 898,902 **** Iterator it = verts.iterator(); while (it.hasNext()) { ! average.add((Vertex)it.next()); } average.scale(1.0 / (double)verts.size()); --- 899,903 ---- Iterator it = verts.iterator(); while (it.hasNext()) { ! average = average.add((Vertex)it.next()); } average.scale(1.0 / (double)verts.size()); *************** *** 1017,1021 **** Space copy = this.copy(copiedVertices, copiedEdges, copiedSurfaces, copiedSpaces); ! Project.getInstance().add(copy); Project.getInstance().checkpoint(); return copy; --- 1018,1022 ---- Space copy = this.copy(copiedVertices, copiedEdges, copiedSurfaces, copiedSpaces); ! this.getOwner().add(copy); Project.getInstance().checkpoint(); return copy; *************** *** 1034,1040 **** Map copiedSurfaces, Map copiedSpaces) { ! Space copy = new Space("*copy of " + this.getName() + "*", this.getType(), this.isContainer()); Set envelopeCopy = copyEnvelope(copiedVertices, copiedEdges, --- 1035,1042 ---- Map copiedSurfaces, Map copiedSpaces) { ! Space copy = new Space("", this.getType(), this.isContainer()); + copy.setName(this.getName()); Set envelopeCopy = copyEnvelope(copiedVertices, copiedEdges, *************** *** 1074,1078 **** while (it.hasNext()) { Space sp = (Space)it.next(); ! if (!(sp.toString().equals("Void"))) { Space newSpace = sp.copy(copiedVertices, copiedEdges, --- 1076,1081 ---- while (it.hasNext()) { Space sp = (Space)it.next(); ! //make prettier ! if (sp != sp.getOwner().getEmpty()) { Space newSpace = sp.copy(copiedVertices, copiedEdges, *************** *** 1081,1084 **** --- 1084,1088 ---- copiedSpaces.put(sp, newSpace); copy.add(newSpace); + copy.setName(copy.getName() + "::" + copy.getId()); } } *************** *** 1116,1119 **** --- 1120,1142 ---- while (it.hasNext()) { Surface s = (Surface)it.next(); + copyInnerSurface(s, + copiedEdges, + copiedSurfaces, + copy); + } + } + + /** + * Copies a surface in the inner layers of the copy + * @param s the surface to copy + * @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 copyInnerSurface(Surface s, + Map copiedEdges, + Map copiedSurfaces, + Space copy) { + if (!copiedSurfaces.keySet().contains(s)) { List newEdges = new LinkedList(); Iterator edgeIt = s.getEdges().iterator(); *************** *** 1122,1125 **** --- 1145,1159 ---- } Surface newSurface = new Surface(newEdges); + if (s.getExterior() != null) { + Surface exteriorCopy; + if (!copiedSurfaces.keySet().contains(s.getExterior())) { + copyInnerSurface(s.getExterior(), + copiedEdges, + copiedSurfaces, + copy); + } + exteriorCopy = (Surface)copiedSurfaces.get(s.getExterior()); + exteriorCopy.addHole(newSurface); + } newSurface.setFrontDomain(copy.getEmpty()); newSurface.setBackDomain(copy.getEmpty()); *************** *** 1150,1182 **** 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); --- 1184,1195 ---- if (copiedSurfaces.keySet().contains(s)) { surfaceCopy = (Surface)copiedSurfaces.get(s); } else { /* This should only apply to the outer layer */ ! surfaceCopy = copyOuterSurface(s, copiedVertices, ! copiedEdges, ! copiedSurfaces); ! } + envelopeCopy.add(surfaceCopy); if (s.getFrontDomain() == this) { surfaceCopy.setFrontDomain(copy); *************** *** 1185,1191 **** surfaceCopy.setBackDomain(copy); } - surfaceCopy.getVertices(); } return envelopeCopy; } } --- 1198,1251 ---- surfaceCopy.setBackDomain(copy); } } return envelopeCopy; } + + /** + * Copies a surface in the outer layer of the copy + * @param s the surface to 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. + * @return the copy of the surface + */ + private Surface copyOuterSurface(Surface s, + Map copiedVertices, + Map copiedEdges, + Map copiedSurfaces) { + Surface surfaceCopy; + { + 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()); + this.getOwner().add((Vertex)copiedVertices.get(e.getTo())); + } + if (!copiedVertices.keySet().contains(e.getFrom())) { + copiedVertices.put(e.getFrom(), e.getFrom().copy()); + this.getOwner().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()))); + } + this.getOwner().add((Edge)copiedEdges.get(e)); + edgeCopies.add(copiedEdges.get(e)); + } + surfaceCopy = new Surface(edgeCopies); + this.getOwner().add(surfaceCopy); + surfaceCopy.setFrontDomain(this.getOwner().getEmpty()); + surfaceCopy.setBackDomain(this.getOwner().getEmpty()); + + copiedSurfaces.put(s, surfaceCopy); + } + Iterator it = s.getHoles().iterator(); + while (it.hasNext()) { + Surface hole = (Surface)it.next(); + surfaceCopy.addHole(copyOuterSurface(hole, copiedVertices, copiedEdges, copiedSurfaces)); + } + return surfaceCopy; + } } |