[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Space.java, 1.187, 1.188
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-10-29 18:10:19
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23069/src/net/sourceforge/bprocessor/model Modified Files: Space.java Log Message: added a lock on space, and a createUnion from a list of spaces Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.187 retrieving revision 1.188 diff -C2 -d -r1.187 -r1.188 *** Space.java 29 Oct 2007 09:04:29 -0000 1.187 --- Space.java 29 Oct 2007 18:10:15 -0000 1.188 *************** *** 66,69 **** --- 66,72 ---- private int level; + /** Tell if the space is finished and therefore cannot be edited */ + private boolean locked = false; + /** If the constructionspace is transparent */ private boolean transparent; *************** *** 172,175 **** --- 175,179 ---- */ protected Space() { + super(); envelope = new HashSet<Surface>(); transform = new TransformStack(); *************** *** 231,247 **** */ public Space createConstructionSpace(String name) { ! if (this.level == PART_LEVEL) { ! throw new Error("Not legal to make further levels of detail, max level is PART"); ! } ! if (this.level == ELEMENT_LEVEL) { ! return new Space(name, Space.CONSTRUCTION, PART_LEVEL, false); ! } ! if (this.level == SPACE_LEVEL) { ! return new Space(name, Space.CONSTRUCTION, ELEMENT_LEVEL, true); ! } ! if (this.level == PROJECT_LEVEL) { ! return new Space(name, Space.CONSTRUCTION, SPACE_LEVEL, true); ! } ! return null; } --- 235,240 ---- */ public Space createConstructionSpace(String name) { ! int lvl = this.level + 1; ! return new Space(name, Space.CONSTRUCTION, lvl, true); } *************** *** 253,258 **** public Space createUnion(String name) { Space s = createConstructionSpace(name); ! s.setLevel(this.getLevel()); s.setUnion(true); return s; } --- 246,252 ---- public Space createUnion(String name) { Space s = createConstructionSpace(name); ! s.add(new CoordinateSystem(new Vertex(0, 0, 0))); s.setUnion(true); + s.setLevel(level--); return s; } *************** *** 264,284 **** */ public Space createConstructionSpace(Classification cl) { ! Space cur; ! if (this.level == ELEMENT_LEVEL) { ! cur = new Space("", Space.CONSTRUCTION, PART_LEVEL, false); ! cur.setClassification(cl); ! return cur; ! } ! if (this.level == SPACE_LEVEL) { ! cur = new Space("", Space.CONSTRUCTION, ELEMENT_LEVEL, true); ! cur.setClassification(cl); ! return cur; ! } ! if (this.level == PROJECT_LEVEL) { ! cur = new Space("", Space.CONSTRUCTION, SPACE_LEVEL, true); cur.setClassification(cl); - return cur; } ! return null; } --- 258,266 ---- */ public Space createConstructionSpace(Classification cl) { ! Space cur = createConstructionSpace(""); ! if (cur != null) { cur.setClassification(cl); } ! return cur; } *************** *** 289,302 **** */ public Space createFunctionalSpace(String name) { ! if (this.level == ELEMENT_LEVEL) { ! return new Space(name, Space.FUNCTIONAL, PART_LEVEL, true); ! } ! if (this.level == SPACE_LEVEL) { ! return new Space(name, Space.FUNCTIONAL, ELEMENT_LEVEL, true); ! } ! if (this.level == PROJECT_LEVEL) { ! return new Space(name, Space.FUNCTIONAL, SPACE_LEVEL, true); } ! return null; } --- 271,279 ---- */ public Space createFunctionalSpace(String name) { ! int lvl = this.level + 1; ! if (isUnion()) { ! lvl--; } ! return new Space(name, Space.FUNCTIONAL, lvl, false); } *************** *** 305,331 **** * @param cl The classification * @return The space - * @throws Exception If a part is being extended */ ! public Space createFunctionalSpace(Classification cl) throws Exception { ! Space cur; ! if (this.level == PART_LEVEL) { ! throw new Exception("Not leagal to make further levels of detail, max level is PART"); ! } ! if (this.level == ELEMENT_LEVEL) { ! cur = new Space("", Space.FUNCTIONAL , PART_LEVEL, true); ! cur.setClassification(cl); ! return cur; ! } ! if (this.level == SPACE_LEVEL) { ! cur = new Space("", Space.FUNCTIONAL, ELEMENT_LEVEL, true); ! cur.setClassification(cl); ! return cur; ! } ! if (this.level == PROJECT_LEVEL) { ! cur = new Space("", Space.FUNCTIONAL, SPACE_LEVEL, true); cur.setClassification(cl); - return cur; } ! return null; } --- 282,292 ---- * @param cl The classification * @return The space */ ! public Space createFunctionalSpace(Classification cl) { ! Space cur = createFunctionalSpace(""); ! if (cur != null) { cur.setClassification(cl); } ! return cur; } *************** *** 1432,1460 **** */ public String getLevelName() { ! String lvl; ! switch (level) { case ELEMENT_LEVEL: ! lvl = "Elm"; break; case PART_LEVEL: ! lvl = "Prt"; break; case SPACE_LEVEL: ! lvl = "Spc"; break; case NET_LEVEL: ! lvl = "Net"; break; case PROJECT_LEVEL: ! lvl = "Proj"; break; default: ! lvl = "Unk"; break; } if (isUnion()) { ! return lvl + " Union " + id; } else { ! return lvl + id; } } --- 1393,1425 ---- */ public String getLevelName() { ! String res; ! int lvl = level; ! if (isUnion()) { ! lvl++; ! } ! switch (lvl) { case ELEMENT_LEVEL: ! res = "Elm"; break; case PART_LEVEL: ! res = "Prt"; break; case SPACE_LEVEL: ! res = "Spc"; break; case NET_LEVEL: ! res = "Net"; break; case PROJECT_LEVEL: ! res = "Proj"; break; default: ! res = "Unk"; break; } if (isUnion()) { ! return res + " Union " + id; } else { ! return res + id; } } *************** *** 1510,1515 **** result.addAll(s.collect()); } ! if (container) { ! result.addAll(collectInterior()); } return result; --- 1475,1484 ---- result.addAll(s.collect()); } ! if (isUnion()) { ! result.add(getConstructors().iterator().next().center()); ! } else { ! if (container) { ! result.addAll(collectInterior()); ! } } return result; *************** *** 1591,1596 **** Space copy = this.copy(copiedVertices, copiedEdges, copiedSurfaces, copiedSpaces); - this.getOwner().add(copy); - Project.getInstance().checkpoint(); return copy; } --- 1560,1563 ---- *************** *** 2937,2939 **** --- 2904,3003 ---- } } + + /** + * Tell if the space is locked or not + * @return the locked + */ + public boolean isLocked() { + return locked; + } + + /** + * Set a lock on the space to tell that it is finish + * @param locked the locked to set + */ + public void setLocked(boolean locked) { + this.locked = locked; + } + + /** + * Make a union out of a collection of spaces + * -All boundary surfaces are found and kept as envelope<br> + * -All geometry are copied into the union + * @param interior The spaces to make a union of + */ + public static void makeUnion(Collection<Space> interior) { + Collection<Surface> boundary = new LinkedList<Surface>(); + Collection<Surface> innerSurfs = new LinkedList<Surface>(); + Space owner = null; + for (Space s : interior) { + owner = s.getOwner(); + for (Surface surface : s.getEnvelope()) { + if (interior.contains(surface.getFrontDomain()) && + interior.contains(surface.getBackDomain())) { + innerSurfs.add(surface); + } else { + boundary.add(surface); + } + } + } + + Space union = owner.createUnion("unnamed"); + owner.add(union); + + Map<Geometric, Geometric> map = new HashMap<Geometric, Geometric>(); + Map<Vertex, Vertex> copiedVertices = new HashMap<Vertex, Vertex>(); + Map<Edge, Edge> copiedEdges = new HashMap<Edge, Edge>(); + Map<Surface, Surface> copiedSurfaces = new HashMap<Surface, Surface>(); + Map<Space, Space> copiedSpaces = new HashMap<Space, Space>(); + for (Space space : interior) { + Space copy = space.copy(copiedVertices, copiedEdges, copiedSurfaces, copiedSpaces); + map.put(space, copy); + union.add(copy); + } + + for (Surface surface : innerSurfs) { + Surface copy = (Surface) surface.copy(map); + Space front = surface.getFrontDomain(); + if (front != owner.getEmpty()) { + Space newFront = (Space) map.get(front); + if (newFront != null) { + copy.setFrontDomain(newFront); + } + } + Space back = surface.getBackDomain(); + if (back != owner.getEmpty()) { + Space newBack = (Space) map.get(back); + if (newBack != null) { + copy.setBackDomain(newBack); + } + } + union.add(copy); + surface.erase(); + } + + Map<Geometric, Geometric> map2 = new HashMap<Geometric, Geometric>(); + for (Surface surface : boundary) { + Surface copy = copiedSurfaces.get(surface); + Space front = surface.getFrontDomain(); + if (!interior.contains(front)) { + copy.setFrontDomain(union.getEmpty()); + } else { + copy.setFrontDomain((Space)map.get(front)); + surface.setFrontDomain(union); + } + Space back = surface.getBackDomain(); + if (!interior.contains(back)) { + copy.setBackDomain(union.getEmpty()); + } else { + copy.setBackDomain((Space)map.get(back)); + surface.setBackDomain(union); + } + union.add(copy); + } + + for (Space s : interior) { + s.delete(); + } + } } |