[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ExtrusionTool.java,1.25,1.26
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-11-07 19:22:30
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14730 Modified Files: ExtrusionTool.java Log Message: Extrusion can be adjusted by typing in a length (weird bug when typing in 1011 though) Index: ExtrusionTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrusionTool.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** ExtrusionTool.java 7 Nov 2005 07:21:21 -0000 1.25 --- ExtrusionTool.java 7 Nov 2005 19:22:19 -0000 1.26 *************** *** 24,27 **** --- 24,28 ---- import java.awt.Cursor; import java.awt.event.MouseEvent; + import java.awt.event.KeyEvent; import java.util.ArrayList; *************** *** 63,66 **** --- 64,70 ---- /** The set of surfaces created from the inner surfaces */ private Set innerExSurfs; + + /** The length typed in for length of the extrusion*/ + private String number; /** *************** *** 72,76 **** super(glv, cursor); } - /** * Invoked when the mouse is held pressed and moved --- 76,79 ---- *************** *** 96,126 **** Vertex delta = to.minus(from); double normDotDelta = normal.dot(delta); ! normal.scale(normDotDelta / (normal.length() * normal.length())); ! List l = dragSurface.getVertices(); ! //moving the dragged surface along its normal vector ! for (int count = 0; l != null && count < l.size() - 1; count++) { ! Vertex v = (Vertex)l.get(count); ! updateVertex(v, new double[] {v.getX() + normal.getX(), ! v.getY() + normal.getY(), ! v.getZ() + normal.getZ()}); ! } ! //also moving any inner surfaces ! Set innerSurfaces = dragSurface.getInnerSurfaces(); ! if (innerSurfaces != null) { ! Iterator innerIt = innerSurfaces.iterator(); ! while (innerIt.hasNext()) { ! Surface innerSurf = (Surface)innerIt.next(); ! List verticies = innerSurf.getVertices(); ! for (int count = 0; verticies != null && count < verticies.size() - 1; count++) { ! Vertex v = (Vertex)verticies.get(count); ! updateVertex(v, new double[] {v.getX() + normal.getX(), ! v.getY() + normal.getY(), ! v.getZ() + normal.getZ()}); ! } ! } ! } ! if (extrusion != null) { ! glv.setLength(extrusion.getLength()); ! } } } --- 99,103 ---- Vertex delta = to.minus(from); double normDotDelta = normal.dot(delta); ! moveDelta(normDotDelta); } } *************** *** 128,132 **** prevY = e.getY(); } ! /** * Invoked when a mouse button has been pressed on a component. --- 105,145 ---- prevY = e.getY(); } ! /** ! * Moves the extrusion a given offset in the direction of the normal. ! * @param delta the offset. ! */ ! private void moveDelta(double delta) { ! if (dragSurface != null) { ! Vertex normal = dragSurface.normal(); ! normal.scale(1 / normal.length()); ! normal.scale(delta / (normal.length() * normal.length())); ! List l = dragSurface.getVertices(); ! //moving the dragged surface along its normal vector ! for (int count = 0; l != null && count < l.size() - 1; count++) { ! Vertex v = (Vertex)l.get(count); ! updateVertex(v, new double[] {v.getX() + normal.getX(), ! v.getY() + normal.getY(), ! v.getZ() + normal.getZ()}); ! } ! //also moving any inner surfaces ! Set innerSurfaces = dragSurface.getInnerSurfaces(); ! if (innerSurfaces != null) { ! Iterator innerIt = innerSurfaces.iterator(); ! while (innerIt.hasNext()) { ! Surface innerSurf = (Surface)innerIt.next(); ! List verticies = innerSurf.getVertices(); ! for (int count = 0; verticies != null && count < verticies.size() - 1; count++) { ! Vertex v = (Vertex)verticies.get(count); ! updateVertex(v, new double[] {v.getX() + normal.getX(), ! v.getY() + normal.getY(), ! v.getZ() + normal.getZ()}); ! } ! } ! } ! if (extrusion != null) { ! glv.setLength(extrusion.getLength()); ! } ! } ! } /** * Invoked when a mouse button has been pressed on a component. *************** *** 134,140 **** */ protected void pressed(MouseEvent e) { - super.pressed(e); prevX = e.getX(); prevY = e.getY(); if (target instanceof Surface) { --- 147,160 ---- */ protected void pressed(MouseEvent e) { prevX = e.getX(); prevY = e.getY(); + dragSurface = null; + extrusion = null; + extrudeSurface = null; + extrudedSurfaces = null; + dragplane = null; + number = ""; + glv.setLength(0); + super.pressed(e); if (target instanceof Surface) { *************** *** 158,163 **** protected void released(MouseEvent e) { super.released(e); ! ! //this is when no surfaces is selected if (extrudeSurface == null) { return; --- 178,190 ---- protected void released(MouseEvent e) { super.released(e); ! spaceAssignment(); ! } ! ! /** ! * Does appropriate space assignments for the current extrusion. Does ! * Nothing if nothing has been extruded. ! */ ! private void spaceAssignment() { ! //this is when nothing is extruded if (extrudeSurface == null) { return; *************** *** 191,198 **** } } - dragSurface = null; - extrusion = null; - extrudeSurface = null; - extrudedSurfaces = null; } --- 218,221 ---- *************** *** 385,387 **** --- 408,477 ---- return top; } + + /** + * 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 + */ + if (dragSurface != null && number != null) { + if (number.equals("") && e.getKeyCode() == KeyEvent.VK_MINUS) { + number = "-"; + } else { + 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(); + double delta = extrusion.getLength() - length; + Vertex extrusionDir = extrusion.getFrom().minus(extrusion.getTo()); + Vertex normal = dragSurface.normal(); + normal.scale(1 / normal.length()); + if (normal.dot(extrusionDir) > 0) { + delta = 0 - delta; + } + moveDelta(delta); + 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) { + log.warn(exp); + } + } + } + log.info("Number: " + number); + } } |