Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ToolFactory.java, 1.55, 1.56 RectTool
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-07-31 14:07:04
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv10343/src/net/sourceforge/bprocessor/gl/tool Modified Files: ToolFactory.java RectTool.java Removed Files: AltRectTool.java Log Message: Deleted RectTool and renamed AltRectTool to RectTool --- AltRectTool.java DELETED --- Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** ToolFactory.java 21 Jul 2006 15:14:57 -0000 1.55 --- ToolFactory.java 31 Jul 2006 14:06:56 -0000 1.56 *************** *** 87,93 **** /** arc tool */ private ArcTool arc; - - /** rect tool */ - private RectTool rect; /** pencil tool */ --- 87,90 ---- *************** *** 122,126 **** /** The Alternative Rect tool */ ! private AltRectTool altRect; /** The selection button */ --- 119,123 ---- /** The Alternative Rect tool */ ! private RectTool altRect; /** The selection button */ *************** *** 199,203 **** eraser = new EraserTool(glv, pencilcursor); arc = new ArcTool(glv, pencilcursor); - rect = new RectTool(glv, pencilcursor); controlledStrategy = new ControlledMoveStrategy(glv, pencilcursor); vectorStrategy = new VectorMoveStrategy(glv, pencilcursor); --- 196,199 ---- *************** *** 215,219 **** constructor = new ConstructorTool(glv, pencilcursor); offset = new OffsetTool(glv, pencilcursor); ! altRect = new AltRectTool(glv, pencilcursor); Toolbar tb = Toolbar.getInstance(); --- 211,215 ---- constructor = new ConstructorTool(glv, pencilcursor); offset = new OffsetTool(glv, pencilcursor); ! altRect = new RectTool(glv, pencilcursor); Toolbar tb = Toolbar.getInstance(); Index: RectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RectTool.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RectTool.java 21 Jun 2006 13:26:18 -0000 1.10 --- RectTool.java 31 Jul 2006 14:06:56 -0000 1.11 *************** *** 10,26 **** import java.awt.Cursor; import java.awt.event.MouseEvent; ! import java.util.HashSet; ! import java.util.LinkedList; import java.util.List; import org.apache.log4j.Logger; import net.sourceforge.bprocessor.gl.GLView; - import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Vertex; /** ! * RectTool */ public class RectTool extends AbstractPencil { --- 10,25 ---- import java.awt.Cursor; import java.awt.event.MouseEvent; ! import java.util.List; + import java.util.LinkedList; import org.apache.log4j.Logger; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Vertex; /** ! * An alternative Rectangle Tool */ public class RectTool extends AbstractPencil { *************** *** 28,47 **** private static Logger log = Logger.getLogger(RectTool.class); ! /** Tempoary edges for multiple selection */ ! protected Edge e1; ! ! /** Tempoary edges for multiple selection */ ! protected Edge e2; ! ! /** Tempoary edges for multiple selection */ ! protected Edge e3; ! ! /** Tempoary edges for multiple selection */ ! protected Edge e4; ! ! /** The drag box */ ! protected HashSet box; /** --- 27,45 ---- private static Logger log = Logger.getLogger(RectTool.class); + /** The edges of the rectangle */ + private List rectangle; ! /** The edge that will be moving while making the rectangle */ ! private Edge movingEdge; + /** The base edge of the rectangle */ + private Edge baseEdge; + + /** The last value of currents vertex + where the rectangle was moved */ + private Vertex lastCurrent; + + /** Dragging flag */ + private boolean dragging; /** *************** *** 52,135 **** public RectTool(GLView glv, Cursor cursor) { super(glv, cursor); } - /** ! * Create a rectangle ! * @param start Start point ! * @param end End point ! * @return List of edges forming a rectangle, null if the edges only form a line */ ! List createRect(Vertex start, Vertex end) { ! List edges = new LinkedList(); ! ! Vertex d = start.minus(end); ! /* So no edges are created with null vertices */ ! if (Math.abs(d.getX()) < 0.00001 && ! Math.abs(d.getY()) < 0.00001 && ! Math.abs(d.getZ()) < 0.00001) { ! return edges; ! } ! Vertex v1 = null; ! Vertex v3 = null; ! Vertex v2 = null; ! Vertex v4 = null; ! ! if (Math.abs(d.getZ()) < 0.00001) { ! v1 = start; ! v3 = end; ! v2 = new Vertex(v3.getX(), v1.getY(), v1.getZ()); ! v4 = new Vertex(v1.getX(), v3.getY(), v3.getZ()); ! } else if (Math.abs(d.getX()) < 0.00001) { ! v1 = start; ! v3 = end; ! v2 = new Vertex(v3.getX(), v1.getY(), v3.getZ()); ! v4 = new Vertex(v1.getX(), v3.getY(), v1.getZ()); ! } else if (Math.abs(d.getY()) < 0.00001) { ! v1 = start; ! v3 = end; ! v2 = new Vertex(v1.getX(), v1.getY(), v3.getZ()); ! v4 = new Vertex(v3.getX(), v3.getY(), v1.getZ()); ! } ! if ((Math.abs(d.getX()) < 0.00001 && Math.abs(d.getY()) < 0.00001) || ! (Math.abs(d.getX()) < 0.00001 && Math.abs(d.getZ()) < 0.00001) || ! (Math.abs(d.getZ()) < 0.00001 && Math.abs(d.getY()) < 0.00001)) { ! // The box is only in one direction and therefor just an edge ! return null; ! } ! if (v1 != null) { ! e1 = new Edge(v1, v2); ! e2 = new Edge(v2, v3); ! e3 = new Edge(v3, v4); ! e4 = new Edge(v4, v1); ! edges.add(e1); ! edges.add(e2); ! edges.add(e3); ! edges.add(e4); } ! return edges; } /** ! * Update feedback ! * */ ! protected void updateFeedback() { if (start != null) { ! List edges = new LinkedList(); ! Edge edge = new Edge(start.vertex(), current.vertex()); ! edge.setConstructor(true); ! edges.add(edge); ! List l = createRect(start.vertex(), current.vertex()); ! if (l != null) { ! edges.addAll(l); } else { ! edge.setConstructor(false); } ! feedback(edges); } else { ! feedback(new LinkedList()); } ! makeTarget(current); } --- 50,121 ---- public RectTool(GLView glv, Cursor cursor) { super(glv, cursor); + rectangle = new LinkedList(); + movingEdge = null; + baseEdge = null; + lastCurrent = null; + dragging = false; } /** ! * Update feedback */ ! public void updateFeedback() { ! if (start != null) { ! if (baseEdge == null) { ! Edge edge = new Edge(start.vertex(), current.vertex()); ! List edges = new LinkedList(); ! edges.add(edge); ! feedback(edges); ! } else { ! Vertex delta = lastCurrent.minus(current.vertex()); ! Vertex baseProjection = baseEdge.getDirection(); ! baseProjection.scale(1 / baseProjection.length()); ! baseProjection.scale(delta.dot(baseProjection)); ! Vertex movement = baseProjection.minus(delta); ! movingEdge.move(movement.getX(), movement.getY(), movement.getZ()); ! lastCurrent = current.vertex(); ! } } ! makeTarget(current); ! updateConstructors(); } /** ! * On vertex - to make "apply" work */ ! public void onVertex() { if (start != null) { ! if (baseEdge == null) { ! setUpRectangle(); } else { ! double length = start.vertex().minus(current.vertex()).length(); ! Vertex direction = movingEdge.getFrom().minus(baseEdge.getTo()); ! direction.scale((length - direction.length()) / direction.length()); ! movingEdge.move(direction.getX(), direction.getY(), direction.getZ()); ! insertEdges(rectangle); ! cleanUp(); ! feedback(rectangle); } ! updateFeedback(); } else { ! start = current; ! lastCurrent = start.vertex(); ! updateFeedback(); } ! } ! ! /** ! * Creates the base edge of the rectangle and sets up the ! * rectangle. ! */ ! private void setUpRectangle() { ! rectangle = new LinkedList(); ! baseEdge = new Edge(start.vertex(), current.vertex()); ! movingEdge = new Edge(current.vertex().copy(), start.vertex().copy()); ! rectangle.add(baseEdge); ! rectangle.add(new Edge(current.vertex(), movingEdge.getFrom())); ! rectangle.add(movingEdge); ! rectangle.add(new Edge(movingEdge.getTo(), start.vertex())); ! feedback(rectangle); } *************** *** 138,148 **** */ protected void updateLength() { ! if (e1 != null && e2 != null) { ! glv.setLength(e1.getLength(), e2.getLength()); } else { ! glv.setLength(0.0, 0.0); } } ! /** * @param e MouseEvent --- 124,134 ---- */ protected void updateLength() { ! if (baseEdge == null) { ! super.updateLength(); } else { ! glv.setLength(baseEdge.getFrom().minus(movingEdge.getTo()).length()); } } ! /** * @param e MouseEvent *************** *** 152,156 **** if (current != null) { updateFeedback(); - updateConstructors(); } } --- 138,141 ---- *************** *** 162,182 **** if (start == null) { start = current; ! e1 = null; ! e2 = null; ! e3 = null; ! e4 = null; } else { ! List edges = createRect(start.vertex(), current.vertex()); ! if (edges != null) { ! insertEdges(edges); ! } else { ! boolean split = (start.type() == Intersection.EDGE_INTERSECTION || ! current.type() == Intersection.EDGE_INTERSECTION); ! insertEdge(new Edge(start.vertex(), current.vertex()), split); ! } cleanUp(); } updateFeedback(); - updateConstructors(); } --- 147,159 ---- if (start == null) { start = current; ! lastCurrent = start.vertex(); ! } else if (baseEdge == null) { ! setUpRectangle(); } else { ! insertEdges(rectangle); cleanUp(); + feedback(rectangle); } updateFeedback(); } *************** *** 185,189 **** */ protected void dragged(MouseEvent e) { ! } --- 162,169 ---- */ protected void dragged(MouseEvent e) { ! moved(e); ! if (!dragging) { ! dragging = true; ! } } *************** *** 192,205 **** */ protected void released(MouseEvent e) { } ! /** ! * Clean up */ public void cleanUp() { ! e1 = null; ! e2 = null; ! e3 = null; ! e4 = null; super.cleanUp(); } --- 172,190 ---- */ protected void released(MouseEvent e) { + if (dragging) { + pressed(e); + dragging = false; + } } ! /** ! * do clean up */ public void cleanUp() { ! baseEdge = null; ! movingEdge = null; ! start = null; ! rectangle = new LinkedList(); ! dragging = false; super.cleanUp(); } |