[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ExtrusionTool.java,1.20,1.21
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-10-26 12:56:39
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12275 Modified Files: ExtrusionTool.java Log Message: extrusion now assigns the right spaces. Bug when rotating and extruding at the same time fixed Index: ExtrusionTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrusionTool.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ExtrusionTool.java 3 Oct 2005 18:41:34 -0000 1.20 --- ExtrusionTool.java 26 Oct 2005 12:56:26 -0000 1.21 *************** *** 19,24 **** import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; ! import net.sourceforge.bprocessor.model.ConstructionSpace; ! import net.sourceforge.bprocessor.model.FunctionalSpace; import net.sourceforge.bprocessor.model.Domain; import net.sourceforge.bprocessor.model.Plane; --- 19,24 ---- import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; ! //import net.sourceforge.bprocessor.model.ConstructionSpace; ! //import net.sourceforge.bprocessor.model.FunctionalSpace; import net.sourceforge.bprocessor.model.Domain; import net.sourceforge.bprocessor.model.Plane; *************** *** 30,33 **** --- 30,35 ---- import java.util.Iterator; import java.util.Set; + import java.util.HashSet; + import java.util.LinkedList; import org.apache.log4j.Logger; *************** *** 39,57 **** private static Logger log = Logger.getLogger(ExtrusionTool.class); ! /** the new surface to drag */ private static Surface dragSurface = null; ! /** the dragplane */ private Plane dragplane; ! /*** the previous x-coordinate */ private double prevX; ! /** the previous y-coordinate */ private double prevY; /** The extrusion edge */ private Edge extrusion; ! /** * The Constructor --- 41,68 ---- private static Logger log = Logger.getLogger(ExtrusionTool.class); ! /** The new surface to drag */ private static Surface dragSurface = null; ! /** The dragplane */ private Plane dragplane; ! /** The previous x-coordinate */ private double prevX; ! /** The previous y-coordinate */ private double prevY; /** The extrusion edge */ private Edge extrusion; ! ! /** The extruded surface */ ! private Surface extrudeSurface; ! ! /** The list of surfaces created by the current extrusion */ ! private LinkedList extrudedSurfaces; ! ! /** The set of surfaces created from the inner surfaces */ ! private Set innerExSurfs; ! /** * The Constructor *************** *** 67,78 **** */ protected void dragged(MouseEvent e) { if (target instanceof Surface) { Surface selectedSurface = (Surface)target; if (dragSurface == null) { ! if (isExtrudeable(selectedSurface)) { ! dragSurface = selectedSurface; ! } else { ! dragSurface = createExtension(selectedSurface); ! } } else { Vertex normal = dragSurface.normal(); --- 78,91 ---- */ protected void dragged(MouseEvent e) { + //have to use getModifiersEx() getButton() gives wrong results + if ((e.getModifiersEx() & + MouseEvent.BUTTON3_DOWN_MASK) + == MouseEvent.BUTTON3_DOWN_MASK) { + return; + } if (target instanceof Surface) { Surface selectedSurface = (Surface)target; if (dragSurface == null) { ! dragSurface = createExtension(selectedSurface); } else { Vertex normal = dragSurface.normal(); *************** *** 84,88 **** double normDotDelta = normal.dot(delta); normal.scale(normDotDelta / (normal.length() * normal.length())); - //normal.scale(delta); List l = dragSurface.getVertices(); //moving the dragged surface along its normal vector --- 97,100 ---- *************** *** 118,159 **** /** - * Checks if a surface is extrudeable - * @param s Surface - * @return true if the surface is extrudeable otherwise false - */ - private boolean isExtrudeable(Surface s) { - if (s == null || s.getIsInner()) { - return false; - } - Vertex normal = s.normal(); - List l = s.getVertices(); - if (l != null) { - for (int i = 0; i < l.size(); i++) { - Vertex v = (Vertex)l.get(i); - Set edges = v.getEdges(); - if (edges.size() >= 3) { - Iterator it = edges.iterator(); - while (it.hasNext()) { - Edge e = (Edge)it.next(); - if (!s.contains(e)) { - extrusion = e; - Vertex v1 = e.otherVertex(v); - Vertex v2 = v1.minus(v); - Vertex cross = v2.cross(normal); - if (Math.abs(cross.length()) > 0.0001) { - return false; - } - } - } - } else { - return false; - } - } - return true; - } - return false; - } - - /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object --- 130,133 ---- *************** *** 184,204 **** protected void released(MouseEvent e) { super.released(e); dragSurface = null; extrusion = null; } ! /** * Extends a single surface to a corresponding 3D figure. * @param extendSurf the surface to extend. ! * @return the top surface of the extended surface. */ ! private Surface extendSurface(Surface extendSurf) { // HAVE TO BE CHANGED IN FUTURE RELEASE ! Domain newSpace = extendSurf.getBackDomain(); ! if (newSpace == null) { ! newSpace = new ConstructionSpace("innerSpace"); ! Project.getInstance().intern((ConstructionSpace) newSpace); ! } ! Domain outer = extendSurf.getFrontDomain(); Edge previousEdge = null; Vertex previousVertex = null; --- 158,246 ---- protected void released(MouseEvent e) { super.released(e); + + //this is when no surfaces is selected + if (extrudeSurface == null) { + return; + } + Surface top = (Surface)extrudedSurfaces.getFirst(); + Surface bottom = (Surface)extrudedSurfaces.getLast(); + Vertex norm = bottom.normal(); + Vertex dir = top.center().minus(bottom.center()); + Domain front = bottom.getFrontDomain(); + Domain back = bottom.getBackDomain(); + assignSpaces(extrudedSurfaces); + Iterator innerIt = innerExSurfs.iterator(); + while (innerIt.hasNext()) { + LinkedList innerSurfs = (LinkedList)innerIt.next(); + assignSpaces(innerSurfs); + innerSurfs.removeFirst(); + if (norm.dot(dir) > 0) { + assignFronts(front, innerSurfs); + } else { + assignBacks(back, innerSurfs); + } + } dragSurface = null; extrusion = null; + extrudeSurface = null; + extrudedSurfaces = null; } ! ! /** ! * Assigns spaces for a list of extruded surfaces. ! * @param surfaces the list of surfaces ! */ ! private void assignSpaces(LinkedList surfaces) { ! if (surfaces != null) { ! Surface top = (Surface)surfaces.getFirst(); ! Surface bottom = (Surface)surfaces.getLast(); ! Domain front = bottom.getFrontDomain(); ! Domain back = bottom.getBackDomain(); ! surfaces.removeLast(); ! Vertex norm = bottom.normal(); ! Vertex dir = top.center().minus(bottom.center()); ! if (norm.dot(dir) > 0) { ! assignBacks(front, surfaces); ! } else { ! assignFronts(back, surfaces); ! } ! } ! } ! /** ! * Assigns the given domain to the back of a set of surfaces ! * @param back the domain ! * @param surfaces the set of surfaces ! */ ! private void assignBacks(Domain back, LinkedList surfaces) { ! Iterator surfIt = surfaces.iterator(); ! while (surfIt.hasNext()) { ! Surface surf = (Surface)surfIt.next(); ! surf.setBackDomain(back); ! Project.getInstance().update(surf); ! } ! } ! /** ! * Assigns the given domain to the front of a set of surfaces ! * @param front the domain ! * @param surfaces the set of surfaces ! */ ! private void assignFronts(Domain front, LinkedList surfaces) { ! Iterator surfIt = surfaces.iterator(); ! while (surfIt.hasNext()) { ! Surface surf = (Surface)surfIt.next(); ! surf.setFrontDomain(front); ! Project.getInstance().update(surf); ! } ! } ! /** * Extends a single surface to a corresponding 3D figure. * @param extendSurf the surface to extend. ! * @return the list of new surfaces created by the extrusion ! * with the top surface as the head of the list. */ ! private LinkedList extendSurface(Surface extendSurf) { // HAVE TO BE CHANGED IN FUTURE RELEASE ! LinkedList newSurfaces = new LinkedList(); Edge previousEdge = null; Vertex previousVertex = null; *************** *** 207,212 **** List edges = extendSurf.getEdges(); List top = new ArrayList(edges.size()); - newSpace.addSurface(extendSurf); - extendSurf.setBackDomain(newSpace); Iterator i = edges.iterator(); Edge current = null; --- 249,252 ---- *************** *** 263,268 **** } Surface sur = createSurface(newEdges); ! newSpace.addSurface(sur); ! sur.setFrontDomain(newSpace); newEdges = new ArrayList(); --- 303,307 ---- } Surface sur = createSurface(newEdges); ! newSurfaces.add(sur); newEdges = new ArrayList(); *************** *** 281,304 **** } //moving this line to the top - Project.getInstance().update(newSpace); Surface topSurf = createSurface(top); - newSpace.addSurface(topSurf); - topSurf.setFrontDomain(newSpace); Notification n = new Notification(Notification.SURFACE_SELECTED, topSurf.getId()); Notifier.getInstance().sendNotification(n); ! if (outer instanceof FunctionalSpace) { ! n = new Notification(Notification.FUNCTIONAL_SPACE_MODIFIED, outer.getId()); ! } else if (outer instanceof ConstructionSpace) { ! n = new Notification(Notification.CONSTRUCTION_SPACE_MODIFIED, outer.getId()); ! } ! Notifier.getInstance().sendNotification(n); ! if (newSpace instanceof ConstructionSpace) { ! n = new Notification(Notification.CONSTRUCTION_SPACE_MODIFIED, newSpace.getId()); ! } else if (newSpace instanceof FunctionalSpace) { ! n = new Notification(Notification.FUNCTIONAL_SPACE_MODIFIED, newSpace.getId()); ! } ! Notifier.getInstance().sendNotification(n); ! ! return topSurf; } --- 320,329 ---- } //moving this line to the top Surface topSurf = createSurface(top); Notification n = new Notification(Notification.SURFACE_SELECTED, topSurf.getId()); Notifier.getInstance().sendNotification(n); ! ! newSurfaces.addFirst(topSurf); ! return newSurfaces; } *************** *** 309,320 **** */ private Surface createExtension(Surface selectedSurface) { ! ! Surface top = extendSurface(selectedSurface); Set innerSurfaces = selectedSurface.getInnerSurfaces(); if (innerSurfaces != null) { Iterator innerIt = innerSurfaces.iterator(); while (innerIt.hasNext()) { Surface innerSurf = (Surface)innerIt.next(); ! Surface newInnerSurf = extendSurface(innerSurf); top.addHole(newInnerSurf); newInnerSurf.setIsInner(true); --- 334,364 ---- */ private Surface createExtension(Surface selectedSurface) { ! extrudeSurface = selectedSurface; ! ! LinkedList extensions = extendSurface(selectedSurface); ! Surface top = (Surface)extensions.getFirst(); ! extensions.addLast(extrudeSurface); ! /* ! Note the first surface of the extensions lists is the top of the ! hole extension and the last surface is the bottom. This is used ! when assigning spaces to the surfaces. ! */ ! extrudedSurfaces = extensions; ! Set innerSurfaces = selectedSurface.getInnerSurfaces(); + innerExSurfs = new HashSet(); if (innerSurfaces != null) { Iterator innerIt = innerSurfaces.iterator(); while (innerIt.hasNext()) { Surface innerSurf = (Surface)innerIt.next(); ! extensions = extendSurface(innerSurf); ! Surface newInnerSurf = (Surface)extensions.getFirst(); ! extensions.addLast(innerSurf); ! /* ! Note the first surface of the extensions lists is the top of the ! hole extension and the last surface is the bottom. This is used ! when assigning spaces to the surfaces. ! */ ! innerExSurfs.add(extensions); top.addHole(newInnerSurf); newInnerSurf.setIsInner(true); |