Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool AbstractTool.java,1.61,1.62 MoveTool.j
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-03-12 12:33:17
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3275/src/net/sourceforge/bprocessor/gl/tool Modified Files: AbstractTool.java MoveTool.java ExtrudeTool.java ToolFactory.java RotationTool.java MultiExtrudeTool.java SelectTool.java Log Message: All tools now inherit from AbstractTool instead of SelectTool Index: ExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrudeTool.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ExtrudeTool.java 28 Feb 2006 20:53:53 -0000 1.13 --- ExtrudeTool.java 12 Mar 2006 12:33:01 -0000 1.14 *************** *** 29,33 **** * The ExtrudeTool */ ! public class ExtrudeTool extends SelectTool { /** The dragSurface */ --- 29,33 ---- * The ExtrudeTool */ ! public class ExtrudeTool extends AbstractTool { /** The dragSurface */ *************** *** 92,101 **** prevY = e.getY(); number = new String(); ! if (directMode) { ! super.pressed(e); ! } ! if (e.isShiftDown() && !directMode) { ! super.pressed(e); ! } else if (!selection.isEmpty()) { Object object = selection.iterator().next(); if (object instanceof Surface) { --- 92,96 ---- prevY = e.getY(); number = new String(); ! if (!selection.isEmpty()) { Object object = selection.iterator().next(); if (object instanceof Surface) { *************** *** 221,227 **** */ protected void moved(MouseEvent e) { - if (e.isShiftDown() || directMode) { - super.moved(e); - } } --- 216,219 ---- *************** *** 231,238 **** */ protected void dragged(MouseEvent e) { - if (e.isShiftDown()) { - super.dragged(e); - return; - } if (extrudeSurface != null) { Vertex normal; --- 223,226 ---- *************** *** 271,277 **** */ protected void released(MouseEvent e) { - if (e.isShiftDown() && !directMode) { - super.released(e); - } if (Math.abs(t) < 0.0000001) { if (top != null) { --- 259,262 ---- Index: MoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MoveTool.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** MoveTool.java 10 Mar 2006 16:41:25 -0000 1.44 --- MoveTool.java 12 Mar 2006 12:33:00 -0000 1.45 *************** *** 37,41 **** * The move tool */ ! public class MoveTool extends SelectTool { /** The logger */ --- 37,41 ---- * The move tool */ ! public class MoveTool extends AbstractTool { /** The logger */ *************** *** 152,161 **** protected void pressed(MouseEvent e) { findTarget(e); ! if (directMode) { ! super.pressed(e); ! } ! if (e.isShiftDown() && !directMode) { ! super.pressed(e); ! } else { clearConstructors(moveConstructors); if (target != null) { --- 152,156 ---- protected void pressed(MouseEvent e) { findTarget(e); ! { clearConstructors(moveConstructors); if (target != null) { *************** *** 263,267 **** */ protected void released(MouseEvent e) { ! super.released(e); clearConstructors(moveConstructors); moveConstructors = null; --- 258,262 ---- */ protected void released(MouseEvent e) { ! findTarget(e); clearConstructors(moveConstructors); moveConstructors = null; *************** *** 278,282 **** */ protected void moved(MouseEvent e) { ! super.moved(e); if (moveMode == THREE_CLICK && threeClickConst != null) { if (target != null) { --- 273,277 ---- */ protected void moved(MouseEvent e) { ! findTarget(e); if (moveMode == THREE_CLICK && threeClickConst != null) { if (target != null) { *************** *** 294,307 **** */ 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 (e.isShiftDown()) { - super.dragged(e); - return; - } findRestrictions(e); if (dragPlane != null && restrictionVector != null) { --- 289,292 ---- Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** ToolFactory.java 10 Mar 2006 16:41:25 -0000 1.32 --- ToolFactory.java 12 Mar 2006 12:33:01 -0000 1.33 *************** *** 50,54 **** /** extrusion tool */ ! private SelectTool extrusion; /** pencil tool */ --- 50,54 ---- /** extrusion tool */ ! private AbstractTool extrusion; /** pencil tool */ Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** SelectTool.java 28 Feb 2006 20:53:53 -0000 1.55 --- SelectTool.java 12 Mar 2006 12:33:01 -0000 1.56 *************** *** 16,29 **** import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; - import net.sourceforge.bprocessor.model.Space; import java.awt.Cursor; - import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.KeyEvent; - import javax.swing.JPopupMenu; - import javax.swing.JMenuItem; - import java.util.ArrayList; import java.util.HashSet; --- 16,24 ---- *************** *** 52,55 **** --- 47,51 ---- private boolean multipleSelection = false; + /** * The constructor *************** *** 84,92 **** } ! /** ! * Invoked when the mouse is held pressed and moved ! * @param e The MouseEvent object */ ! protected void dragged(MouseEvent e) { if (multipleSelection) { Transformation t = glv.getView().transformation(); --- 80,125 ---- } ! ! /** ! * Handle a pressed event as selection tool ! * @param e MouseEvent */ ! protected void selectionPressed(MouseEvent e) { ! Transformation t = glv.getView().transformation(); ! first = t.unProject(new Vertex(e.getX(), View.getHeight() - e.getY(), 0.001)); ! e1.setFrom(first); ! e4.setTo(first); ! if (e.getClickCount() >= 2 && target instanceof Surface) { ! Surface surface = (Surface) target; ! if (surface.getBackDomain() != null) { ! selection.addAll(surface.getBackDomain().getEnvelope()); ! } ! if (surface.getFrontDomain() != null) { ! selection.addAll(surface.getFrontDomain().getEnvelope()); ! } ! } else { ! if (target == null) { ! selection.clear(); ! multipleSelection = true; ! } else if (e.isShiftDown()) { ! if (!selection.contains(target)) { ! selection.add(target); ! } else { ! selection.remove(target); ! } ! } else { ! if (!selection.contains(target)) { ! selection.clear(); ! selection.add(target); ! } ! } ! } ! } ! ! /** ! * Handle a dragged event as selection tool ! * @param e MouseEvent ! */ ! protected void selectionDragged(MouseEvent e) { if (multipleSelection) { Transformation t = glv.getView().transformation(); *************** *** 103,188 **** } } ! /** ! * Invoked when a mouse button has been pressed on a component. ! * @param e The MouseEvent object */ ! protected void pressed(MouseEvent e) { ! // for multiple selection ! Transformation t = glv.getView().transformation(); ! first = t.unProject(new Vertex(e.getX(), View.getHeight() - e.getY(), 0.001)); ! e1.setFrom(first); ! e4.setTo(first); ! if (e.getButton() == MouseEvent.BUTTON3) { ! if (target != null) { ! if (target instanceof String) { ! JPopupMenu toolsmenu = toolsmenu((String) target); ! glv.popup(toolsmenu, e.getX(), e.getY()); ! } ! } } - if (e.getButton() == MouseEvent.BUTTON1) { - if (e.getClickCount() >= 2 && target instanceof Surface) { - Surface surface = (Surface) target; - if (surface.getBackDomain() != null) { - selection.addAll(surface.getBackDomain().getEnvelope()); - } - if (surface.getFrontDomain() != null) { - selection.addAll(surface.getFrontDomain().getEnvelope()); - } - } else { - if (target == null) { - selection.clear(); - multipleSelection = true; - } else if (e.isShiftDown()) { - if (!selection.contains(target)) { - selection.add(target); - } else { - selection.remove(target); - } - } else { - if (!selection.contains(target)) { - selection.clear(); - selection.add(target); - } - } - } - } } - /** ! * Create the toolsmenu ! * @param name Space name ! * @return The toolsmenu */ ! private JPopupMenu toolsmenu(String name) { ! JPopupMenu menu = new JPopupMenu("Tools"); ! Space space = null; ! Surface surface = null; ! Iterator iter = selection.iterator(); ! while (iter.hasNext()) { ! Object current = iter.next(); ! if (current instanceof Surface) { ! surface = (Surface) current; ! break; ! } ! } ! if (surface != null) { ! if (name.equals("back")) { ! space = (Space) surface.getBackDomain(); ! } ! if (name.equals("front")) { ! space = (Space) surface.getFrontDomain(); ! } ! } ! if (space != null) { ! ActionListener listener = new CatmullClarkActionListener(space); ! JMenuItem catmullClarkItem = new JMenuItem("Catmull-Clark"); ! catmullClarkItem.addActionListener(listener); ! menu.add(catmullClarkItem); } ! return menu; } --- 136,173 ---- } } ! /** ! * Handle a released event as selection tool ! * @param e MouseEvent */ ! protected void selectionReleased(MouseEvent e) { ! if (multipleSelection) { ! selection.clear(); ! clearConstructors(box); ! List l = glv.getView().getObjectInArea(pressPos[0], pressPos[1], ! e.getX(), e.getY()); ! glv.getView().makeTarget(null); ! selection.addAll(l); ! multipleSelection = false; } } /** ! * Invoked when a mouse button has been pressed on a component. ! * @param e The MouseEvent object */ ! protected void pressed(MouseEvent e) { ! if (e.getButton() == MouseEvent.BUTTON1) { ! selectionPressed(e); } ! } ! ! /** ! * Invoked when the mouse is held pressed and moved ! * @param e The MouseEvent object ! */ ! protected void dragged(MouseEvent e) { ! selectionDragged(e); } *************** *** 192,205 **** */ protected void released(MouseEvent e) { ! if (multipleSelection) { ! selection.clear(); ! clearConstructors(box); ! List l = glv.getView().getObjectInArea(pressPos[0], pressPos[1], ! e.getX(), e.getY()); ! glv.getView().makeTarget(null); ! selection.addAll(l); ! multipleSelection = false; ! } ! } /** --- 177,182 ---- */ protected void released(MouseEvent e) { ! selectionReleased(e); ! } /** Index: AbstractTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractTool.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** AbstractTool.java 7 Mar 2006 22:31:03 -0000 1.61 --- AbstractTool.java 12 Mar 2006 12:33:00 -0000 1.62 *************** *** 252,279 **** if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || e.getButton() == MouseEvent.BUTTON2) { ! View view = glv.getView(); ! Camera c = Project.getInstance().getCurrentCamera(); ! double[] center = c.getCenter(); ! double[] camera = c.getCamera(); ! double dx = camera[0] - center[0]; ! double dy = camera[1] - center[1]; ! double dz = camera[2] - center[2]; ! double sqr = Math.sqrt(dx * dx + dy * dy + dz * dz); ! if (sqr < 1) { ! dx *= 1 / sqr; ! dy *= 1 / sqr; ! dz *= 1 / sqr; ! } ! double d = -dx * center[0] - dy * center[1] - dz * center[2]; ! Vertex first = view.toPlaneCoords(new double[] {previousPos[0], ! previousPos[1]}, ! new Plane(dx, dy, dz, d)); ! Vertex second = view.toPlaneCoords(new double[] {e.getX(), ! e.getY()}, ! new Plane(dx, dy, dz, d)); ! c.translate(new double[] {first.getX() - second.getX(), ! first.getY() - second.getY(), ! first.getZ() - second.getZ()}); ! Project.getInstance().changed(c); } else { dragged(e); --- 252,256 ---- if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || e.getButton() == MouseEvent.BUTTON2) { ! panDragged(e); } else { dragged(e); *************** *** 337,341 **** if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || e.getButton() == MouseEvent.BUTTON2) { ! glv.setCursor(dragCursor); } else { pressed(e); --- 314,318 ---- if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || e.getButton() == MouseEvent.BUTTON2) { ! panPressed(e); } else { pressed(e); *************** *** 351,355 **** if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || e.getButton() == MouseEvent.BUTTON2) { ! glv.setCursor(cursor); } else { released(e); --- 328,332 ---- if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || e.getButton() == MouseEvent.BUTTON2) { ! panReleased(e); } else { released(e); *************** *** 358,361 **** --- 335,386 ---- } + + /** + * Handle pressed event as pan tool + * @param e MouseEvent + */ + protected void panPressed(MouseEvent e) { + glv.setCursor(dragCursor); + } + + /** + * Handle dragged event as pan tool + * @param e MouseEvent + */ + protected void panDragged(MouseEvent e) { + View view = glv.getView(); + Camera c = Project.getInstance().getCurrentCamera(); + double[] center = c.getCenter(); + double[] camera = c.getCamera(); + double dx = camera[0] - center[0]; + double dy = camera[1] - center[1]; + double dz = camera[2] - center[2]; + double sqr = Math.sqrt(dx * dx + dy * dy + dz * dz); + if (sqr < 1) { + dx *= 1 / sqr; + dy *= 1 / sqr; + dz *= 1 / sqr; + } + double d = -dx * center[0] - dy * center[1] - dz * center[2]; + Vertex first = view.toPlaneCoords(new double[] {previousPos[0], + previousPos[1]}, + new Plane(dx, dy, dz, d)); + Vertex second = view.toPlaneCoords(new double[] {e.getX(), + e.getY()}, + new Plane(dx, dy, dz, d)); + c.translate(new double[] {first.getX() - second.getX(), + first.getY() - second.getY(), + first.getZ() - second.getZ()}); + Project.getInstance().changed(c); + } + + /** + * Handle released event as pan tool + * @param e MouseEvent + */ + protected void panReleased(MouseEvent e) { + glv.setCursor(cursor); + } + /** * Make and register a new vertex *************** *** 557,566 **** protected abstract void moved(MouseEvent e); - /** - * Invoked when the mouse is held pressed and moved - * @param e The MouseEvent object - */ - protected abstract void dragged(MouseEvent e); - /** * Invoked when a mouse button has been pressed on a component. --- 582,585 ---- *************** *** 569,572 **** --- 588,597 ---- protected abstract void pressed(MouseEvent e); + /** + * Invoked when the mouse is held pressed and moved + * @param e The MouseEvent object + */ + protected abstract void dragged(MouseEvent e); + /** * Invoked when a mouse button has been released on a component. Index: RotationTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RotationTool.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RotationTool.java 17 Feb 2006 09:56:06 -0000 1.12 --- RotationTool.java 12 Mar 2006 12:33:01 -0000 1.13 *************** *** 34,38 **** * The rotation tool */ ! public class RotationTool extends SelectTool { /** */ private static final int X_AXIS = 1; --- 34,38 ---- * The rotation tool */ ! public class RotationTool extends AbstractTool { /** */ private static final int X_AXIS = 1; *************** *** 86,92 **** */ protected void pressed(MouseEvent e) { ! if (e.isShiftDown()) { ! super.pressed(e); ! } else { if (target != null && target instanceof Entity) { // If one edge in a rotate circle are selected all should be --- 86,90 ---- */ protected void pressed(MouseEvent e) { ! { if (target != null && target instanceof Entity) { // If one edge in a rotate circle are selected all should be *************** *** 131,135 **** */ protected void released(MouseEvent e) { ! super.released(e); if (axis != 0) { rotate(from, initial, this.center); --- 129,133 ---- */ protected void released(MouseEvent e) { ! findTarget(e); if (axis != 0) { rotate(from, initial, this.center); *************** *** 173,179 **** */ protected void dragged(MouseEvent e) { ! if (e.isShiftDown()) { ! super.dragged(e); ! } else { if (target != null && (xCircle.contains(target) || yCircle.contains(target) || zCircle.contains(target))) { --- 171,175 ---- */ protected void dragged(MouseEvent e) { ! { if (target != null && (xCircle.contains(target) || yCircle.contains(target) || zCircle.contains(target))) { *************** *** 375,377 **** --- 371,379 ---- return null; } + + /** + * @param e MouseEvent + */ + protected void moved(MouseEvent e) { + } } Index: MultiExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MultiExtrudeTool.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MultiExtrudeTool.java 10 Mar 2006 16:41:25 -0000 1.7 --- MultiExtrudeTool.java 12 Mar 2006 12:33:01 -0000 1.8 *************** *** 34,38 **** * The ExtrudeTool */ ! public class MultiExtrudeTool extends SelectTool { /** The logger */ private static Logger log = Logger.getLogger(MultiExtrudeTool.class); --- 34,38 ---- * The ExtrudeTool */ ! public class MultiExtrudeTool extends AbstractTool { /** The logger */ private static Logger log = Logger.getLogger(MultiExtrudeTool.class); *************** *** 76,79 **** --- 76,80 ---- */ protected void pressed(MouseEvent e) { + findTarget(e); extrudeSurface = null; top = null; *************** *** 81,91 **** v2dir = null; elements = new HashSet(); - if (directMode) { - super.pressed(e); - } - if (e.isShiftDown() && !directMode) { - super.pressed(e); - return; - } if (target instanceof Surface) { extrudeSurface = (Surface)target; --- 82,85 ---- *************** *** 233,237 **** */ protected void released(MouseEvent e) { ! super.released(e); if (top != null && Math.abs(t) < 0.1) { remove(elements); --- 227,231 ---- */ protected void released(MouseEvent e) { ! findTarget(e); if (top != null && Math.abs(t) < 0.1) { remove(elements); *************** *** 281,283 **** --- 275,285 ---- return elements; } + + /** + * @param e MouseEvent + */ + protected void moved(MouseEvent e) { + findTarget(e); + + } } |