Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool MultiExtrudeTool.java,1.13,1.14
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-04-05 10:22:23
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11040/src/net/sourceforge/bprocessor/gl/tool Modified Files: MultiExtrudeTool.java Log Message: Added length measuring Index: MultiExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MultiExtrudeTool.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MultiExtrudeTool.java 5 Apr 2006 09:36:16 -0000 1.13 --- MultiExtrudeTool.java 5 Apr 2006 10:22:11 -0000 1.14 *************** *** 9,12 **** --- 9,13 ---- import java.awt.Cursor; + import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.Collection; *************** *** 41,50 **** private static final boolean SNAPPING = false; ! /** The dragSurface and extrudesurface */ private Surface top, extrudeSurface; ! /** The surfaces to extrude */ private Set surfaces; ! /** A vertex-direction map */ private Map v2dir; --- 42,51 ---- private static final boolean SNAPPING = false; ! /** The dragSurface and extrudeSurface */ private Surface top, extrudeSurface; ! /** The surfaces to extrude */ private Set surfaces; ! /** A vertex-direction map */ private Map v2dir; *************** *** 59,67 **** private double t; ! /** The set of extruded elements and the top surfaces of the extrusion*/ ! private Set elements, tops; /** The extrusion direction */ private double direction = 0.0; /** --- 60,71 ---- private double t; ! /** The set of extruded elements*/ ! private Set elements; /** The extrusion direction */ private double direction = 0.0; + + /** The length of the extrusion */ + private String number; /** *************** *** 72,75 **** --- 76,80 ---- public MultiExtrudeTool(GLView glv, Cursor cursor) { super(glv, cursor); + number = ""; } *************** *** 85,90 **** v2dir = null; elements = new HashSet(); ! surfaces = new HashSet(); ! if (target instanceof Surface) { if (Selection.primary().isEmpty() || Selection.primary().contains(target)) { --- 90,95 ---- v2dir = null; elements = new HashSet(); ! number = ""; ! if (target instanceof Surface) { if (Selection.primary().isEmpty() || Selection.primary().contains(target)) { *************** *** 146,157 **** } ! //if (direction == 0) { //we have never set the direction; ! //direction = normDotDelta; ! //} if (top == null) { // there are no extrusion make one if we move the mouse if ((e.getX() - pressX) * (e.getX() - pressX) + ! (e.getY() - pressY) * (e.getY() - pressY) > 32) { direction = normDotDelta; elements = makeExtrusion(surfaces); --- 151,162 ---- } ! if (direction == 0) { //we have never set the direction; ! direction = normDotDelta; ! } if (top == null) { // there are no extrusion make one if we move the mouse if ((e.getX() - pressX) * (e.getX() - pressX) + ! (e.getY() - pressY) * (e.getY() - pressY) > 16) { direction = normDotDelta; elements = makeExtrusion(surfaces); *************** *** 165,175 **** //If there are a target that is a surface drag to that surface Vertex origin = extrudeSurface.getFirstVertex(); ! Surface current = (Surface) target; if (current != extrudeSurface && current != top && !elements.contains(current)) { Vertex n = current.normal(); Vertex cross = normal.cross(n); if (cross.isZero()) { ! Vertex o = current.getFirstVertex(); ! Vertex vector = o.minus(origin); double d = vector.dot(normal); if (Math.abs(d) > 0.0000001) { --- 170,180 ---- //If there are a target that is a surface drag to that surface Vertex origin = extrudeSurface.getFirstVertex(); ! Surface current = (Surface) o; if (current != extrudeSurface && current != top && !elements.contains(current)) { Vertex n = current.normal(); Vertex cross = normal.cross(n); if (cross.isZero()) { ! Vertex cur = current.getFirstVertex(); ! Vertex vector = cur.minus(origin); double d = vector.dot(normal); if (Math.abs(d) > 0.0000001) { *************** *** 187,191 **** // we have to remove the extrusion and make a new one remove(elements); ! elements = makeExtrusion(surfaces); direction = normDotDelta; if (v2dir != null) { --- 192,196 ---- // we have to remove the extrusion and make a new one remove(elements); ! elements = makeExtrusion(); direction = normDotDelta; if (v2dir != null) { *************** *** 202,206 **** */ private void remove(Set elem) { - if (elem != null) { Iterator iter = elem.iterator(); --- 207,210 ---- *************** *** 220,224 **** */ private void moveTo(Collection which, double to) { - Project.info("move-to " + to); double delta = t - to; Iterator iter = which.iterator(); --- 224,227 ---- *************** *** 255,263 **** /** ! * Make the extrusion from a set of surfaces ! * @param c the collection of surfaces to extrude * @return the elements created for extrusion */ ! private Set makeExtrusion(Collection c) { Set elements = new HashSet(); Map e2e = new HashMap(); // edge to edge map --- 258,272 ---- /** ! * Make the extrusion from either a set of surfaces * @return the elements created for extrusion */ ! private Set makeExtrusion() { ! Collection c; ! if (Selection.primary().size() == 0) { ! c = new HashSet(); ! c.add(extrudeSurface); ! } else { ! c = Selection.primary(); ! } Set elements = new HashSet(); Map e2e = new HashMap(); // edge to edge map *************** *** 265,269 **** v2dir = new HashMap(); // vertex to direction map Map v2e = new HashMap(); // vertex to edge map - tops = new HashSet(); // Check for selection of only surfaces --- 274,277 ---- *************** *** 277,281 **** while (iter.hasNext()) { Surface cur = (Surface)iter.next(); - Project.info("extruding in " + direction); Surface s = cur.extrude(direction, elements, e2e, v2e, e2s, v2dir); if (cur == extrudeSurface) { --- 285,288 ---- *************** *** 283,287 **** top = s; } - tops.add(s); elements.add(s); } --- 290,293 ---- *************** *** 289,293 **** return elements; } ! /** * @param e MouseEvent --- 295,299 ---- return elements; } ! /** * @param e MouseEvent *************** *** 309,311 **** --- 315,391 ---- log.info(message); } + + /** + * Apply extrusion + * @param length The length + */ + private void apply(double length) { + if (v2dir != null) { + moveTo(v2dir.values(), length); + } else { + makeExtrusion(); + moveTo(v2dir.values(), length); + } + Iterator iter = elements.iterator(); + while (iter.hasNext()) { + holeAnalysis((Surface)(iter.next())); + } + } + + /** + * Invoked when a key has been pressed. + * @param e The KeyEvent + */ + public void keyPressed(KeyEvent e) { + /*a length can only be typed in if some surface is selected + for extrusion, and if the "number"-variable has been initialised + */ + super.keyPressed(e); + if (extrudeSurface != null && number != null) { + if (e.getKeyCode() == KeyEvent.VK_1) { + number += "1"; + } else if (e.getKeyCode() == KeyEvent.VK_2) { + number += "2"; + } else if (e.getKeyCode() == KeyEvent.VK_3) { + number += "3"; + } else if (e.getKeyCode() == KeyEvent.VK_4) { + number += "4"; + } else if (e.getKeyCode() == KeyEvent.VK_5) { + number += "5"; + } else if (e.getKeyCode() == KeyEvent.VK_6) { + number += "6"; + } else if (e.getKeyCode() == KeyEvent.VK_7) { + number += "7"; + } else if (e.getKeyCode() == KeyEvent.VK_8) { + number += "8"; + } else if (e.getKeyCode() == KeyEvent.VK_9) { + number += "9"; + } else if (e.getKeyCode() == KeyEvent.VK_0) { + number += "0"; + } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + if (!number.equals("")) { + double length = glv.getLength(); + apply(length); + glv.repaint(); + } + } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + int length = number.length(); + if (length > 0) { + number = number.substring(0, length - 1); + } + } + } + + if (number.equals("") || number.equals("-")) { + glv.setLength(0); + } else { + try { + double d = Double.parseDouble(number); + glv.setLength(d / 1000); + } catch (NumberFormatException exp) { + System.out.println(exp); + } + } + super.keyPressed(e); + } } |