[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ExtrudeTool.java,1.3,1.4
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2005-12-21 15:41:43
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24285/src/net/sourceforge/bprocessor/gl/tool Modified Files: ExtrudeTool.java Log Message: Index: ExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrudeTool.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExtrudeTool.java 19 Dec 2005 07:51:29 -0000 1.3 --- ExtrudeTool.java 21 Dec 2005 15:41:35 -0000 1.4 *************** *** 9,13 **** --- 9,15 ---- import java.awt.Cursor; + import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; + import java.util.HashSet; import java.util.Iterator; import java.util.Set; *************** *** 28,32 **** /** The dragSurface */ ! private Surface dragSurface; /** The extrudeSurface */ --- 30,38 ---- /** The dragSurface */ ! private Surface top; ! ! /** The sides */ ! ! private Set sides; /** The extrudeSurface */ *************** *** 37,40 **** --- 43,49 ---- private Plane dragplane; + /** The length typed in for length of the extrusion*/ + private String number; + /** The previous x-coordinate */ private double prevX; *************** *** 72,79 **** --- 81,95 ---- 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(); super.pressed(e); if (target instanceof Surface) { + sides = new HashSet(); extrudeSurface = (Surface) target; View view = glv.getView(); *************** *** 94,102 **** */ private void move(double delta) { ! if (dragSurface != null) { ! Vertex normal = dragSurface.normal(); normal.scale(1 / normal.length()); normal.scale(delta / (normal.length() * normal.length())); ! dragSurface.move(normal.getX(), normal.getY(), normal.getZ()); } } --- 110,118 ---- */ private void move(double delta) { ! if (top != null) { ! Vertex normal = top.normal(); normal.scale(1 / normal.length()); normal.scale(delta / (normal.length() * normal.length())); ! top.move(normal.getX(), normal.getY(), normal.getZ()); } } *************** *** 116,119 **** --- 132,157 ---- move(delta); t = to; + glv.setLength(Math.abs(t)); + } + + /** + * Apply extrusion + * @param length The length + */ + private void apply(double length) { + if (top != null) { + deleteSurface(top); + Iterator iter = sides.iterator(); + while (iter.hasNext()) { + Surface current = (Surface) iter.next(); + deleteSurface(current); + } + sides = null; + } + if (extrudeSurface != null) { + sides = new HashSet(); + top = extrudeSurface.extrude(length, sides); + holeAnalysis(top); + } } *************** *** 135,144 **** Set surfaces = Project.getInstance().getSurfaces(); Iterator iter = surfaces.iterator(); ! Vertex normal = dragSurface.normal(); Vertex origin = extrudeSurface.getFirstVertex(); normal.scale(1 / normal.length()); while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! if (current != extrudeSurface && current != dragSurface) { Vertex n = current.normal(); Vertex cross = normal.cross(n); --- 173,182 ---- Set surfaces = Project.getInstance().getSurfaces(); Iterator iter = surfaces.iterator(); ! Vertex normal = top.normal(); Vertex origin = extrudeSurface.getFirstVertex(); normal.scale(1 / normal.length()); while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! if (current != extrudeSurface && current != top) { Vertex n = current.normal(); Vertex cross = normal.cross(n); *************** *** 174,181 **** if (extrudeSurface != null) { Vertex normal; ! if (dragSurface == null) { normal = extrudeSurface.normal(); } else { ! normal = dragSurface.normal(); } normal.scale(1 / normal.length()); --- 212,219 ---- if (extrudeSurface != null) { Vertex normal; ! if (top == null) { normal = extrudeSurface.normal(); } else { ! normal = top.normal(); } normal.scale(1 / normal.length()); *************** *** 187,193 **** double x = e.getX(); double y = e.getY(); ! if (dragSurface == null) { if (x * x + y * y > 16) { ! dragSurface = extrudeSurface.extrude(normDotDelta); t = -normDotDelta; if (t > 0) { --- 225,231 ---- double x = e.getX(); double y = e.getY(); ! if (top == null) { if (x * x + y * y > 16) { ! top = extrudeSurface.extrude(normDotDelta, sides); t = -normDotDelta; if (t > 0) { *************** *** 210,217 **** protected void released(MouseEvent e) { super.released(e); ! holeAnalysis(dragSurface); ! dragplane = null; ! dragSurface = null; } } --- 248,322 ---- protected void released(MouseEvent e) { super.released(e); ! if (Math.abs(t) < 0.0000001) { ! deleteSurface(top); ! top = null; ! Iterator iter = sides.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! deleteSurface(current); ! } ! sides = null; ! } else { ! holeAnalysis(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 + */ + 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); + } + + } |