Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool RectTool.java,NONE,1.1 Tool.java,1.19,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-03-15 10:36:34
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24910/src/net/sourceforge/bprocessor/gl/tool Modified Files: Tool.java ToolFactory.java ArcTool.java AbstractPencil.java Added Files: RectTool.java Log Message: First version of RectTool (does not actually add the rect to the model yet) RectTool and ArcTool inherits AbstractPencil that contains common functionality Index: ArcTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ArcTool.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ArcTool.java 15 Mar 2006 09:24:21 -0000 1.3 --- ArcTool.java 15 Mar 2006 10:36:29 -0000 1.4 *************** *** 11,16 **** import java.awt.event.MouseEvent; import java.util.Collection; - import java.util.HashSet; - import java.util.Iterator; import java.util.LinkedList; import java.util.List; --- 11,14 ---- *************** *** 27,34 **** * */ ! public class ArcTool extends AbstractTool { ! ! /** Feedback elements */ ! private Collection elements = new HashSet(); /** Current intersection */ --- 25,29 ---- * */ ! public class ArcTool extends AbstractPencil { /** Current intersection */ *************** *** 42,78 **** /** - * Show feedback - */ - protected void showFeedback() { - Iterator iter = elements.iterator(); - while (iter.hasNext()) { - Edge current = (Edge) iter.next(); - glv.getView().addTempEdge(current); - } - } - - /** - * Hide feedback - */ - protected void hideFeedback() { - Iterator iter = elements.iterator(); - while (iter.hasNext()) { - Edge current = (Edge) iter.next(); - glv.getView().removeTempEdge(current); - } - } - - /** - * Give feedback - * @param feed Collection of edges - */ - protected void feedback(Collection feed) { - hideFeedback(); - elements.clear(); - elements.addAll(feed); - showFeedback(); - } - - /** * Update feedback * --- 37,40 ---- *************** *** 102,140 **** /** - * Make target - * @param intersection Intersection - */ - protected void makeTarget(Intersection intersection) { - if (intersection != null) { - Object target = null; - Vertex current = intersection.vertex(); - switch (intersection.type()) { - case Intersection.VERTEX: - target = current; - break; - case Intersection.EDGE: - target = intersection.object(); - break; - case Intersection.SURFACE: - target = intersection.object(); - break; - case Intersection.EDGE_MIDPOINT: - target = current; - break; - case Intersection.EDGE_INTERSECTION: - target = current; - break; - case Intersection.SURFACE_INTERSECTION: - target = current; - break; - case Intersection.PLANE_INTERSECTION: - target = null; - break; - } - glv.getView().makeTarget(target); - } - } - - /** * Create an arc * @param start Start point --- 64,67 ---- Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** ToolFactory.java 14 Mar 2006 23:36:28 -0000 1.36 --- ToolFactory.java 15 Mar 2006 10:36:29 -0000 1.37 *************** *** 75,78 **** --- 75,81 ---- /** arc tool */ private ArcTool arc; + + /** rect tool */ + private RectTool rect; /** pencil tool */ *************** *** 163,166 **** --- 166,170 ---- eraser = new EraserTool(glv, pencilcursor); arc = new ArcTool(glv, pencilcursor); + rect = new RectTool(glv, pencilcursor); move = new MoveTool(glv, pencilcursor); rotation = new RotationTool(glv, pencilcursor); *************** *** 179,182 **** --- 183,187 ---- eraserBut = this.registerTool(Tool.ERASER_TOOL, eraser, "Biconeraser.gif", "Eraser"); this.registerTool(Tool.ARC_TOOL, arc, "Biconarc.gif", "Arc"); + this.registerTool(Tool.RECT_TOOL, rect, "Biconrect.gif", "Rectangle"); moveBut = this.registerTool(Tool.MOVE_TOOL, move, "Biconmovetool.gif", "Move"); moveBut.addMouseListener(new MoveButtonMouseListener(moveBut)); --- NEW FILE: RectTool.java --- //--------------------------------------------------------------------------------- // $Id: RectTool.java,v 1.1 2006/03/15 10:36:29 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.tool; import java.awt.Cursor; import java.awt.event.MouseEvent; import java.util.LinkedList; import java.util.List; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Vertex; /** * RectTool */ public class RectTool extends AbstractPencil { /** Current intersection */ private Intersection current; /** Start */ private Intersection start; /** * Constructor * @param glv GLView * @param cursor Cursor */ public RectTool(GLView glv, Cursor cursor) { super(glv, cursor); } /** * 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); Vertex d = start.vertex().minus(current.vertex()); Vertex v1 = null; Vertex v3 = null; Vertex v2 = null; Vertex v4 = null; if (Math.abs(d.getZ()) < 0.00001) { v1 = start.vertex(); v3 = current.vertex(); 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.vertex(); v3 = current.vertex(); 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.vertex(); v3 = current.vertex(); v2 = new Vertex(v1.getX(), v1.getY(), v3.getZ()); v4 = new Vertex(v3.getX(), v3.getY(), v1.getZ()); } if (v1 != null) { Edge e1 = new Edge(v1, v2); Edge e2 = new Edge(v2, v3); Edge e3 = new Edge(v3, v4); Edge e4 = new Edge(v4, v1); edges.add(e1); edges.add(e2); edges.add(e3); edges.add(e4); } feedback(edges); } else { feedback(new LinkedList()); } makeTarget(current); } /** * @param e MouseEvent */ protected void moved(MouseEvent e) { current = (Intersection) glv.getView().getObjectAtPoint(e.getX(), e.getY(), elements, true, new Plane(0, 0, 1, 0)); if (current != null) { updateFeedback(); } } /** * @param e MouseEvent */ protected void pressed(MouseEvent e) { if (start == null) { start = current; } else { start = null; } updateFeedback(); } /** * @param e MouseEvent */ protected void dragged(MouseEvent e) { } /** * @param e MouseEvent */ protected void released(MouseEvent e) { } } Index: Tool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Tool.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Tool.java 14 Mar 2006 23:36:28 -0000 1.19 --- Tool.java 15 Mar 2006 10:36:28 -0000 1.20 *************** *** 42,47 **** /** The Eraser tool */ public static final int ERASER_TOOL = 10; ! /** The Eraser tool */ public static final int ARC_TOOL = 11; /** --- 42,49 ---- /** The Eraser tool */ public static final int ERASER_TOOL = 10; ! /** The Arc tool */ public static final int ARC_TOOL = 11; + /** The Rect tool */ + public static final int RECT_TOOL = 12; /** Index: AbstractPencil.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractPencil.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AbstractPencil.java 15 Mar 2006 09:37:42 -0000 1.1 --- AbstractPencil.java 15 Mar 2006 10:36:29 -0000 1.2 *************** *** 8,13 **** --- 8,19 ---- import java.awt.Cursor; + import java.util.Collection; + import java.util.HashSet; + import java.util.Iterator; 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; /** *************** *** 16,19 **** --- 22,28 ---- */ public abstract class AbstractPencil extends AbstractTool { + /** Feedback elements */ + protected Collection elements = new HashSet(); + /** * Constructor *************** *** 25,27 **** --- 34,104 ---- } + /** + * Show feedback + */ + protected void showFeedback() { + Iterator iter = elements.iterator(); + while (iter.hasNext()) { + Edge current = (Edge) iter.next(); + glv.getView().addTempEdge(current); + } + } + + /** + * Hide feedback + */ + protected void hideFeedback() { + Iterator iter = elements.iterator(); + while (iter.hasNext()) { + Edge current = (Edge) iter.next(); + glv.getView().removeTempEdge(current); + } + } + + /** + * Give feedback + * @param feed Collection of edges + */ + protected void feedback(Collection feed) { + hideFeedback(); + elements.clear(); + elements.addAll(feed); + showFeedback(); + } + + /** + * Make target + * @param intersection Intersection + */ + protected void makeTarget(Intersection intersection) { + if (intersection != null) { + Object target = null; + Vertex current = intersection.vertex(); + switch (intersection.type()) { + case Intersection.VERTEX: + target = current; + break; + case Intersection.EDGE: + target = intersection.object(); + break; + case Intersection.SURFACE: + target = intersection.object(); + break; + case Intersection.EDGE_MIDPOINT: + target = current; + break; + case Intersection.EDGE_INTERSECTION: + target = current; + break; + case Intersection.SURFACE_INTERSECTION: + target = current; + break; + case Intersection.PLANE_INTERSECTION: + target = null; + break; + } + glv.getView().makeTarget(target); + } + } + } |