[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool VectorMoveStrategy.java,1.1,1.2 Contro
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2006-03-29 18:39:28
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4522 Modified Files: VectorMoveStrategy.java ControlledMoveStrategy.java MoveTool.java Log Message: restructoring and making work by Movetool extending abstractpencil, beware controlled move does not work right now Index: MoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MoveTool.java,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** MoveTool.java 27 Mar 2006 14:40:04 -0000 1.49 --- MoveTool.java 29 Mar 2006 18:39:25 -0000 1.50 *************** *** 9,12 **** --- 9,13 ---- import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.model.ClippingPlane; + import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.model.Edge; *************** *** 16,19 **** --- 17,21 ---- import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; + import net.sourceforge.bprocessor.model.Geometric; import net.sourceforge.bprocessor.gl.view.Transformation; *************** *** 28,31 **** --- 30,36 ---- import java.util.Set; import java.util.HashSet; + import java.util.LinkedList; + //import java.util.Timer; + import java.util.TimerTask; *************** *** 35,39 **** * The move tool */ ! public class MoveTool extends AbstractTool { /** The logger */ --- 40,44 ---- * The move tool */ ! public class MoveTool extends AbstractPencil { /** The logger */ *************** *** 60,63 **** --- 65,81 ---- /** The move strategy */ private MoveTool strategy; + + /** The move vector */ + protected Edge moveVector; + + /** The aligning edge */ + protected Edge alignEdge; + + /** Number of clicks when in 3 click mode */ + protected int numberOfClicks; + + /** The plane that the movevector ends + in if nothing else is hit */ + protected Plane currentPlane; /** *************** *** 70,78 **** strategy = null; lastMoveDirection = null; } /** * Update selection - * */ protected void update() { --- 88,99 ---- strategy = null; lastMoveDirection = null; + alignEdge = null; + numberOfClicks = 1; + currentPlane = null; + start = null; } /** * Update selection */ protected void update() { *************** *** 89,93 **** } } ! Project.getInstance().changed(vertices); } --- 110,116 ---- } } ! if (vertices != null) { ! Project.getInstance().changed(vertices); ! } } *************** *** 100,111 **** strategy.pressed(e); } else { ! moveEntities = new HashSet(); ! findTarget(e); ! if (selection.isEmpty()) { ! moveEntities.add(target); } else { ! moveEntities.addAll(selection); } ! } } --- 123,174 ---- strategy.pressed(e); } else { ! if (start == null) { ! moveEntities = new HashSet(); ! Geometric primary = current.object(); ! if (selection.isEmpty() && primary != null) { ! moveEntities.add(primary); ! } else if (!selection.isEmpty()) { ! moveEntities.addAll(selection); ! } ! excluded(getAffected(moveEntities)); ! if (!moveEntities.isEmpty()) { ! start = current; ! } } else { ! start = null; ! moveEntities = null; ! excluded(new HashSet()); } ! } ! /* ! findTarget(e); ! if (numberOfClicks == 1) { ! moveEntities = new HashSet(); ! if (target != null) { ! Vertex moveStart = findInitial(target, e); ! moveVector = new Edge(moveStart, moveStart); ! moveVector.setConstructor(true); ! glv.getView().addTempEdgeOnTop(moveVector); ! initial = moveStart.copy(); ! from = moveStart.copy(); ! numberOfClicks = 2; ! number = ""; ! } ! if (selection.isEmpty() && target != null) { ! moveEntities.add(target); ! } else if (!selection.isEmpty()) { ! moveEntities.addAll(selection); ! } ! } else if (numberOfClicks == 2) { ! glv.getView().removeEntityOnTop(moveVector); ! moveVector = null; ! if (alignEdge != null) { ! glv.getView().removeTempEdge(alignEdge); ! alignEdge = null; ! } ! update(); ! numberOfClicks = 1; ! } ! }*/ } *************** *** 141,146 **** Plane plane = ((ClippingPlane) entity).getPlane(); return plane.intersection(ray); } ! log.warn("The clicked object is not an Entity"); return null; } --- 204,214 ---- Plane plane = ((ClippingPlane) entity).getPlane(); return plane.intersection(ray); + } else if (entity instanceof Plane) { + Plane plane = (Plane)entity; + return plane.intersection(ray); + } else if (entity instanceof Intersection) { + return ((Intersection)entity).vertex(); } ! log.warn("The object is not an Entity"); return null; } *************** *** 168,174 **** strategy.moved(e); } else { ! findTarget(e); ! glv.getView().makeTarget(target); } } --- 236,305 ---- strategy.moved(e); } else { ! Intersection oldCurrent = current; ! current = findIntersection(e); ! if (current != null && ! oldCurrent != null && ! moveEntities != null) { ! move(moveEntities, current.vertex().minus(oldCurrent.vertex())); ! } ! updateConstructors(); } + /* + if (numberOfClicks == 2) { + boolean showAlign = false; + Set moveConstructors = makeXYZConerConstructors(new Vertex(0, 0, 0)); + displayConstructors(moveConstructors); + glv.getView().removeEntityOnTop(moveVector); + if (alignEdge != null) { + glv.getView().addTempEdge(alignEdge); + } + findTarget(e, (Set)moveEntities); + glv.getView().makeTarget(target); + if (target != null) { + if (target instanceof Edge) { + Edge targetEdge = (Edge)target; + if (!targetEdge.equals(alignEdge)) { + Timer alignTimer = new Timer(); + TimerTask alignTask = new AlignTask(targetEdge); + alignTimer.schedule(alignTask, 300); + } + if (alignEdge != null) { + Vertex alignDir = alignEdge.getDirection(); + Vertex targetDir = targetEdge.getDirection(); + Vertex dirCross = alignDir.cross(targetDir); + showAlign = dirCross.length() < 0.000001; + } + } + } + Intersection endPoint = + (Intersection)glv.getView().getObjectAtPoint(e.getX(), e.getY(), + (Set)moveEntities, true, + currentPlane); + Vertex to = endPoint.vertex(); + if (to != null) { + moveVector.setTo(to); + lastMoveDirection = to.minus(initial).copy(); + glv.setLength(lastMoveDirection.length()); + //Do we really want this to move also? + Vertex movement = to.minus(from); + if (vertices != null) { + move(vertices, movement); + } + from = to; + } + + if (moveVector != null) { + glv.getView().addTempEdgeOnTop(moveVector); + } + if (!showAlign) { + glv.getView().removeTempEdge(alignEdge); + } + clearConstructors(moveConstructors); + } else { + findTarget(e); + glv.getView().makeTarget(target); + } + } + */ } *************** *** 310,312 **** --- 441,529 ---- this.strategy = strategy; } + + /** + * + * Update constructors + */ + public void updateConstructors() { + if (start != null && current != null) { + super.updateConstructors(); + Edge edge = new Edge(start.vertex(), current.vertex()); + edge.setConstructor(true); + constructors.add(edge); + excluded.add(edge); + Set constcopy = new HashSet(); + constcopy.addAll(constructors); + constructors(constcopy); + Set excopy = new HashSet(); + excopy.addAll(excluded); + excluded(excopy); + glv.setLength(edge.getLength()); + } else { + constructors(new LinkedList()); + feedback(new LinkedList()); + } + makeTarget(current); + } + + /** + * Gets the set of elements that can be affected by moveing a + * set of elements. + * @param moveElements the elements to move + * @return the affected elements + */ + private Collection getAffected(Collection moveElements) { + HashSet affected = new HashSet(); + HashSet affectedEdges = new HashSet(); + HashSet affectedSurfaces = new HashSet(); + collect(moveElements, affected); + Iterator it = affected.iterator(); + while (it.hasNext()) { + affectedEdges.addAll(((Vertex)it.next()).getEdges()); + affectedSurfaces.addAll(((Vertex)it.next()).getSurfaces()); + } + affected.addAll(affectedEdges); + affected.addAll(affectedSurfaces); + return affected; + } + + + /** + * Class for handeling the task of assigning an alignedge. + */ + protected class AlignTask extends TimerTask { + /** The edge candidate to become the alignedge */ + private Edge candidateEdge; + + /** + * Constructor + * @param candidate the candidate to become alignedge + */ + public AlignTask(Edge candidate) { + super(); + candidateEdge = candidate; + } + + /** + * checks if the target is still the same edge, + * thus making it the alignedge + */ + public void run() { + + if (target instanceof Edge) { + candidateEdge.equals((Edge)target); + + Vertex direction = candidateEdge.getDirection(); + Vertex alignTo = direction.copy(); + Vertex alignFrom = direction.copy(); + alignFrom.scale(-1000); + alignTo.scale(1000); + glv.getView().removeTempEdge(alignEdge); + alignEdge = new Edge(alignFrom.add(initial), alignTo.add(initial)); + alignEdge.setConstructor(true); + glv.getView().addTempEdge(alignEdge); + glv.repaint(true); + } + } + } } Index: VectorMoveStrategy.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/VectorMoveStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VectorMoveStrategy.java 27 Mar 2006 14:38:48 -0000 1.1 --- VectorMoveStrategy.java 29 Mar 2006 18:39:25 -0000 1.2 *************** *** 9,19 **** import net.sourceforge.bprocessor.gl.GLView; ! import net.sourceforge.bprocessor.model.Edge; ! import net.sourceforge.bprocessor.model.Vertex; import java.util.HashSet; - import java.util.Set; - import java.util.Timer; - import java.util.TimerTask; import java.awt.event.MouseEvent; --- 9,15 ---- import net.sourceforge.bprocessor.gl.GLView; ! import net.sourceforge.bprocessor.model.Plane; import java.util.HashSet; import java.awt.event.MouseEvent; *************** *** 29,41 **** public class VectorMoveStrategy extends MoveTool { - /** Number of clicks when in 3 click mode */ - private int numberOfClicks; - - /** The Three click constructors edge */ - private Edge threeClickConst; - - /** The aligning edge */ - private Edge alignEdge; - /** The logger */ private static Logger log = Logger.getLogger(VectorMoveStrategy.class); --- 25,28 ---- *************** *** 48,53 **** public VectorMoveStrategy(GLView glv, Cursor cursor) { super(glv, cursor); ! alignEdge = null; ! numberOfClicks = 1; } --- 35,39 ---- public VectorMoveStrategy(GLView glv, Cursor cursor) { super(glv, cursor); ! currentPlane = new Plane(0, 0, 1, 0); } *************** *** 57,82 **** */ protected void pressed(MouseEvent e) { ! if (numberOfClicks == 1) { ! super.pressed(e); vertices = new HashSet(); collect(moveEntities, vertices); - from = findInitial(target, e); - initial = from.copy(); - threeClickConst = new Edge(initial, initial); - threeClickConst.setConstructor(true); - glv.getView().addTempEdge(threeClickConst); - numberOfClicks = 2; - number = ""; - } else if (numberOfClicks == 2) { - Vertex movement = findInitial(target, e).minus(initial); - move(moveEntities, movement); - glv.getView().removeTempEdge(threeClickConst); - threeClickConst = null; - if (alignEdge != null) { - glv.getView().removeTempEdge(alignEdge); - alignEdge = null; - } - update(); - numberOfClicks = 1; } } --- 43,50 ---- */ protected void pressed(MouseEvent e) { ! super.pressed(e); ! if (numberOfClicks == 2) { vertices = new HashSet(); collect(moveEntities, vertices); } } *************** *** 87,180 **** */ protected void moved(MouseEvent e) { ! boolean showAlign = false; ! if (threeClickConst != null) { ! Set moveConstructors = makeXYZConerConstructors(new Vertex(0, 0, 0)); ! displayConstructors(moveConstructors); ! glv.getView().removeTempEdge(threeClickConst); ! if (alignEdge != null) { ! glv.getView().addTempEdge(alignEdge); ! } ! findTarget(e); ! glv.getView().makeTarget(target); ! if (target != null) { ! Vertex to = findInitial(target, e); ! if (target instanceof Edge) { ! Edge targetEdge = (Edge)target; ! if (!targetEdge.equals(alignEdge)) { ! Timer alignTimer = new Timer(); ! TimerTask alignTask = new AlignTask(targetEdge); ! alignTimer.schedule(alignTask, 300); ! } ! if (alignEdge != null) { ! Vertex alignDir = alignEdge.getDirection(); ! Vertex targetDir = targetEdge.getDirection(); ! Vertex dirCross = alignDir.cross(targetDir); ! showAlign = dirCross.length() < 0.000001; ! } ! } ! ! if (to != null) { ! threeClickConst.setTo(to); ! lastMoveDirection = to.minus(initial).copy(); ! glv.setLength(lastMoveDirection.length()); ! //Do we really want this to move also? ! //Vertex movement = to.minus(from); ! //move(moveEntities, movement); ! //from = to; ! } ! } else { ! threeClickConst.setTo(from); ! ! } ! ! if (threeClickConst != null) { ! glv.getView().addTempEdge(threeClickConst); ! } ! if (!showAlign) { ! glv.getView().removeTempEdge(alignEdge); ! } ! clearConstructors(moveConstructors); ! } else { ! findTarget(e); ! glv.getView().makeTarget(target); ! } ! } ! ! /** ! * Class for handeling the task of assigning an alignedge. ! */ ! private class AlignTask extends TimerTask { ! /** The edge candidate to become the alignedge */ ! private Edge candidateEdge; ! ! /** ! * Constructor ! * @param candidate the candidate to become alignedge ! */ ! public AlignTask(Edge candidate) { ! super(); ! candidateEdge = candidate; ! } ! ! /** ! * checks if the target is still the same edge, ! * thus making it the alignedge ! */ ! public void run() { ! if (target instanceof Edge) { ! candidateEdge.equals((Edge)target); ! ! Vertex direction = candidateEdge.getDirection(); ! Vertex alignTo = direction.copy(); ! Vertex alignFrom = direction.copy(); ! alignFrom.scale(-1000); ! alignTo.scale(1000); ! glv.getView().removeTempEdge(alignEdge); ! alignEdge = new Edge(alignFrom.add(initial), alignTo.add(initial)); ! alignEdge.setConstructor(true); ! glv.getView().addTempEdge(alignEdge); ! glv.repaint(true); ! } ! } } --- 55,59 ---- */ protected void moved(MouseEvent e) { ! super.moved(e); } Index: ControlledMoveStrategy.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ControlledMoveStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ControlledMoveStrategy.java 27 Mar 2006 14:38:48 -0000 1.1 --- ControlledMoveStrategy.java 29 Mar 2006 18:39:25 -0000 1.2 *************** *** 49,55 **** private Vertex restrictionVector; - /** The initial movepoint */ - private Vertex initial; - /** * The Constructor --- 49,52 ---- *************** *** 69,78 **** protected void pressed(MouseEvent e) { super.pressed(e); ! if (target != null) { ! initial = findInitial(target, e); ! from = initial.copy(); slideMap = new HashMap(); vertices = new HashSet(); ! if (!moveEntities.isEmpty()) { Iterator it = moveEntities.iterator(); --- 66,73 ---- protected void pressed(MouseEvent e) { super.pressed(e); ! if (numberOfClicks == 2) { slideMap = new HashMap(); vertices = new HashSet(); ! if (!moveEntities.isEmpty()) { Iterator it = moveEntities.iterator(); *************** *** 81,87 **** moveEntities.clear(); moveEntities.add(controlled); ! number = ""; } - collect(moveEntities, vertices); } --- 76,97 ---- moveEntities.clear(); moveEntities.add(controlled); ! collect(moveEntities, vertices); ! } else if (numberOfClicks == 1) { ! slideMap = null; ! controlled = null; ! } ! } ! ! /** ! * Invoked when the mouse cursor has been moved ! * @param e The MouseEvent object ! */ ! protected void moved(MouseEvent e) { ! if (dragPlane == null) { ! findRestrictions(e); ! } ! if (dragPlane != null) { ! super.moved(e); } } *************** *** 91,123 **** */ protected void dragged(MouseEvent e) { ! findRestrictions(e); ! if (dragPlane != null && restrictionVector != null) { ! int x = e.getX(); ! int y = e.getY(); ! Vertex parentPos = glv.getView().toPlaneCoords(new double[] {x, y}, dragPlane); ! if (parentPos != null) { ! Vertex delta = parentPos.minus(from); ! ! //Restricting movement. ! Vertex restrictCopy = restrictionVector.copy(); ! restrictCopy.scale(1 / restrictCopy.length()); ! restrictCopy.scale(delta.dot(restrictCopy)); ! delta = restrictCopy; ! ! if (log.isDebugEnabled()) { ! log.debug("from " + from.getX() + ", " + from.getY() + ", " + from.getZ()); ! log.debug("delta " + delta.getX() + ", " + delta.getY() + ", " + delta.getZ()); ! } ! ! move(vertices, delta); ! ! from.move(delta.getX(), delta.getY(), delta.getZ()); ! glv.setLength(from.minus(initial).length()); ! lastMoveDirection = delta.copy(); ! update(); ! } else { ! log.warn("could not hit the dragplane"); ! } ! } } --- 101,105 ---- */ protected void dragged(MouseEvent e) { ! moved(e); } *************** *** 137,140 **** --- 119,123 ---- glv.getView().makeTarget(target); dragPlane = targetSurface.plane(); + currentPlane = dragPlane; Vertex controlledDir = controlledEdge.getDirection(); Vertex surfaceNormal = targetSurface.normal(); *************** *** 248,251 **** --- 231,235 ---- dragPlane = new Plane(planeNormal.getX(), planeNormal.getY(), planeNormal.getZ(), -planeNormal.dot(initial)); + currentPlane = dragPlane; } *************** *** 257,260 **** --- 241,248 ---- */ protected void move(Collection vertices, Vertex delta) { + Vertex restrictCopy = restrictionVector.copy(); + restrictCopy.scale(1 / restrictCopy.length()); + restrictCopy.scale(delta.dot(restrictCopy)); + delta = restrictCopy; Vertex deltaUnit = delta.copy(); deltaUnit.scale(1 / delta.length()); *************** *** 262,266 **** while (it.hasNext()) { Vertex vertex = (Vertex)it.next(); ! Vertex slideDir = (Vertex)slideMap.get(vertex); double slideScale; if (delta == null) { --- 250,255 ---- while (it.hasNext()) { Vertex vertex = (Vertex)it.next(); ! Vertex slideDir = ((Vertex)slideMap.get(vertex)).copy(); ! slideDir.scale(1 / slideDir.length()); double slideScale; if (delta == null) { |