[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ArcTool.java,1.1,1.2
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-03-15 09:12:17
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17382/src/net/sourceforge/bprocessor/gl/tool Modified Files: ArcTool.java Log Message: Center found in ArcTool (but the actual arc are not created yet) Index: ArcTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ArcTool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ArcTool.java 14 Mar 2006 23:36:28 -0000 1.1 --- ArcTool.java 15 Mar 2006 09:12:09 -0000 1.2 *************** *** 14,22 **** --- 14,25 ---- import java.util.Iterator; 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.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Plane; + import net.sourceforge.bprocessor.model.Vertex; /** *************** *** 38,42 **** private Intersection end; - /** * Show feedback --- 41,44 ---- *************** *** 73,76 **** --- 75,192 ---- /** + * Update feedback + * + */ + protected void updateFeedback() { + if (start != null) { + if (end != null) { + + Edge e1 = new Edge(start.vertex(), current.vertex()); + Edge e2 = new Edge(current.vertex(), end.vertex()); + Collection edges = new LinkedList(); + edges.add(e1); + edges.add(e2); + + feedback(createArc(start.vertex(), current.vertex(), end.vertex())); + } else { + Edge edge = new Edge(start.vertex(), current.vertex()); + Collection edges = new LinkedList(); + edges.add(edge); + feedback(edges); + } + } else { + feedback(new LinkedList()); + } + makeTarget(current); + } + + /** + * 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 + * @param mid Mid point + * @param end End point + * @return Edges + */ + protected List createArc(Vertex start, Vertex mid, Vertex end) { + List edges = new LinkedList(); + Edge e1 = new Edge(start, mid); + Edge e2 = new Edge(mid, end); + CoordinateSystem system = CoordinateSystem.create(e1, e2); + if (system != null) { + Vertex p = system.translate(start); + Vertex m = system.translate(mid); + Vertex q = system.translate(end); + + double x; + double y; + + Vertex v1 = m.minus(p); + v1.scale(0.5); + Vertex m1 = p.add(v1); + + x = v1.getX(); + y = v1.getY(); + v1.setX(-y); + v1.setY(x); + v1.scale(10 / v1.length()); + Edge l1 = new Edge(system.unTranslate(m1.minus(v1)), system.unTranslate(m1.add(v1))); + + Vertex v2 = m.minus(q); + v2.scale(0.5); + Vertex m2 = q.add(v2); + + x = v2.getX(); + y = v2.getY(); + v2.setX(-y); + v2.setY(x); + v2.scale(10 / v2.length()); + Edge l2 = new Edge(system.unTranslate(m2.minus(v2)), system.unTranslate(m2.add(v2))); + l1.setConstructor(true); + l2.setConstructor(true); + + edges.add(e1); + edges.add(e2); + edges.add(l1); + edges.add(l2); + } + return edges; + } + + /** * Constructor * @param glv GLView *************** *** 86,106 **** protected void moved(MouseEvent e) { current = (Intersection) glv.getView().getObjectAtPoint(e.getX(), e.getY(), ! new HashSet(), true, new Plane(0, 0, 1, 0)); if (current != null) { ! if (start != null) { ! if (end != null) { ! Edge e1 = new Edge(start.vertex(), current.vertex()); ! Edge e2 = new Edge(current.vertex(), end.vertex()); ! Collection edges = new LinkedList(); ! edges.add(e1); ! edges.add(e2); ! feedback(edges); ! } else { ! Edge edge = new Edge(start.vertex(), current.vertex()); ! Collection edges = new LinkedList(); ! edges.add(edge); ! feedback(edges); ! } ! } } } --- 202,208 ---- 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(); } } *************** *** 110,123 **** */ protected void pressed(MouseEvent e) { ! if (start == null) { ! start = current; ! } else { ! if (end == null) { ! end = current; } else { ! feedback(new LinkedList()); ! start = null; ! end = null; } } } --- 212,227 ---- */ protected void pressed(MouseEvent e) { ! if (current != null) { ! if (start == null) { ! start = current; } else { ! if (end == null) { ! end = current; ! } else { ! start = null; ! end = null; ! } } + updateFeedback(); } } |