[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ExtrudeTool.java,1.15,1.16
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-04-10 07:55:16
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16950/src/net/sourceforge/bprocessor/gl/tool Modified Files: ExtrudeTool.java Log Message: Now the tool does extrude holes as well unless ALT is pressed at extrusion start. Have done some refactoring of methods so there now are startExtrusion and beginExtrusion methods and a removeExtrusion method. Made a cleanUp method Index: ExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrudeTool.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ExtrudeTool.java 5 Apr 2006 09:36:16 -0000 1.15 --- ExtrudeTool.java 10 Apr 2006 07:55:09 -0000 1.16 *************** *** 70,73 **** --- 70,79 ---- private int direction = 0; + /** Tells if holes are supposed to be extruded */ + private boolean extrudeAll = true; + + /** The sides of the extruded holes */ + private Set holeSides; + /** * Constructor *************** *** 85,97 **** */ protected void pressed(MouseEvent e) { ! t = 0.0; ! upperLimit = 0.0; ! lowerLimit = 0.0; ! extrudeSurface = null; ! top = null; ! sides = null; prevX = e.getX(); prevY = e.getY(); - number = new String(); findTarget(e); --- 91,97 ---- */ protected void pressed(MouseEvent e) { ! cleanUp(); prevX = e.getX(); prevY = e.getY(); findTarget(e); *************** *** 141,155 **** /** ! * */ private void removeExtrusion() { if (top != null) { top.delete(); top = null; ! Iterator iter = sides.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); current.delete(); } sides = null; } --- 141,172 ---- /** ! * Remove the current extrusion */ private void removeExtrusion() { if (top != null) { + Collection c = top.getHoles(); + Set holes = new HashSet(); + holes.addAll(c); + Iterator iter = holes.iterator(); + while (iter.hasNext()) { + Surface hole = (Surface)iter.next(); + hole.delete(); + } top.delete(); top = null; ! iter = sides.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); current.delete(); } + + if (holeSides != null) { + iter = holeSides.iterator(); + while (iter.hasNext()) { + Surface current = (Surface) iter.next(); + current.delete(); + } + holeSides = null; + } sides = null; } *************** *** 162,173 **** private void apply(double length) { removeExtrusion(); ! if (extrudeSurface != null) { sides = new HashSet(); if (direction > 0) { length = -length; } top = extrudeSurface.extrude(length, sides); ! holeAnalysis(top); ! Project.getInstance().checkpoint(); } } --- 179,251 ---- private void apply(double length) { removeExtrusion(); ! if (extrudeSurface != null && length > 0) { sides = new HashSet(); + holeSides = null; if (direction > 0) { length = -length; } top = extrudeSurface.extrude(length, sides); ! if (extrudeAll) { ! extrudeHoles(extrudeSurface, length); ! } ! finishExtrusion(); ! } ! } ! ! /** ! * Begin the extrusion ! * @param s The surface to extrude ! * @param d The length of the extrusion ! */ ! private void startExtrusion(Surface s, double d) { ! top = s.extrude(d, sides); ! if (extrudeAll) { ! holeSides = new HashSet(); ! extrudeHoles(s, d); ! } ! } ! ! /** ! * Complete the Extrusion ! */ ! private void finishExtrusion() { ! holeAnalysis(top); ! Iterator iter = sides.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! holeAnalysis(current); ! } ! Project.getInstance().checkpoint(); ! } ! ! /** Do tool cleanup */ ! public void cleanUp() { ! t = 0.0; ! upperLimit = 0.0; ! lowerLimit = 0.0; ! extrudeSurface = null; ! top = null; ! sides = null; ! holeSides = null; ! number = new String(); ! } ! ! /** ! * Extrude the holes of the given surface ! * @param s The surface whose holes are supposed to be extruded ! * @param length The length of extrusion ! */ ! private void extrudeHoles(Surface s, double length) { ! Collection holes = s.getHoles(); ! Iterator it = holes.iterator(); ! while (it.hasNext()) { ! Surface hole = (Surface)(it.next()); ! Set temp = new HashSet(); ! Surface holeTop = hole.extrude(length, temp); ! /* Add all surfaces that the hole generates to the holeSides set */ ! holeSides.addAll(temp); ! holeSides.add(holeTop); ! holeAnalysis(holeTop); ! extrudeHoles(hole, length); } } *************** *** 254,258 **** double y = e.getY() - prevY; if (x * x + y * y > 16) { ! top = extrudeSurface.extrude(normDotDelta, sides); t = -normDotDelta; if (t > 0) { --- 332,336 ---- double y = e.getY() - prevY; if (x * x + y * y > 16) { ! startExtrusion(extrudeSurface, normDotDelta); t = -normDotDelta; if (t > 0) { *************** *** 271,274 **** --- 349,355 ---- elements.addAll(sides); elements.add(top); + if (extrudeAll) { + elements.addAll(holeSides); + } Iterator iter = elements.iterator(); while (iter.hasNext()) { *************** *** 312,316 **** } } ! /** * Invoked when a mouse button has been released on a component. --- 393,397 ---- } } ! /** * Invoked when a mouse button has been released on a component. *************** *** 321,334 **** removeExtrusion(); } else { ! holeAnalysis(top); ! Iterator iter = sides.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! holeAnalysis(current); ! } ! Project.getInstance().checkpoint(); } } ! /** * Invoked when a key has been pressed. --- 402,409 ---- removeExtrusion(); } else { ! finishExtrusion(); } } ! /** * Invoked when a key has been pressed. *************** *** 374,377 **** --- 449,456 ---- } } + if ((e.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) == KeyEvent.ALT_DOWN_MASK) { + // Alt were pressed so holes are not supposed to be extruded + extrudeAll = false; + } if (number.equals("") || number.equals("-")) { *************** *** 386,389 **** } super.keyPressed(e); ! } } --- 465,479 ---- } super.keyPressed(e); ! } ! ! /** ! * Called when a key is released ! * @param e The KeyEvent object ! */ ! public void keyReleased(KeyEvent e) { ! if ((e.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) == 0) { ! /* Alt were not pressed so we should extrude holes anyway */ ! extrudeAll = true; ! } ! } } |