Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool Protractor.java,1.1,1.2 ArcTool.java,1
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-03-26 21:40:38
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16287/src/net/sourceforge/bprocessor/gl/tool Modified Files: Protractor.java ArcTool.java RectTool.java Pencil.java AbstractPencil.java Log Message: Changes to pencil Index: Protractor.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Protractor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Protractor.java 22 Mar 2006 11:42:44 -0000 1.1 --- Protractor.java 26 Mar 2006 21:40:32 -0000 1.2 *************** *** 14,18 **** import net.sourceforge.bprocessor.gl.GLView; - import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Project; --- 14,17 ---- *************** *** 23,33 **** */ public class Protractor extends AbstractPencil { - - /** Current intersection */ - private Intersection current; - - /** Start */ - private Intersection start; - /** angling */ private boolean angling; --- 22,25 ---- Index: Pencil.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Pencil.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Pencil.java 16 Mar 2006 20:01:47 -0000 1.2 --- Pencil.java 26 Mar 2006 21:40:32 -0000 1.3 *************** *** 14,18 **** import net.sourceforge.bprocessor.gl.GLView; - import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.model.Edge; --- 14,17 ---- *************** *** 22,32 **** */ public class Pencil extends AbstractPencil { - - - /** Start point */ - private Intersection start; - - /** Current point */ - private Intersection current; /** --- 21,24 ---- *************** *** 50,53 **** --- 42,46 ---- feedback(edges); } else { + constructors(new LinkedList()); feedback(new LinkedList()); } *************** *** 62,65 **** --- 55,59 ---- if (current != null) { updateFeedback(); + updateConstructors(); } } *************** *** 69,72 **** --- 63,73 ---- */ protected void pressed(MouseEvent e) { + onVertex(); + } + + /** + * Current vertex is pressed + */ + public void onVertex() { if (start == null) { start = current; *************** *** 77,81 **** --- 78,85 ---- insertEdges(edges); start = null; + incident = null; } + updateConstructors(); + updateFeedback(); } Index: RectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RectTool.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RectTool.java 16 Mar 2006 20:01:47 -0000 1.3 --- RectTool.java 26 Mar 2006 21:40:32 -0000 1.4 *************** *** 14,18 **** 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; --- 14,17 ---- *************** *** 22,31 **** */ public class RectTool extends AbstractPencil { - - /** Current intersection */ - private Intersection current; - - /** Start */ - private Intersection start; /** --- 21,24 ---- *************** *** 119,122 **** --- 112,116 ---- insertEdges(createRect(start.vertex(), current.vertex())); start = null; + incident = null; } updateFeedback(); Index: AbstractPencil.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractPencil.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** AbstractPencil.java 25 Mar 2006 18:10:04 -0000 1.10 --- AbstractPencil.java 26 Mar 2006 21:40:32 -0000 1.11 *************** *** 8,11 **** --- 8,12 ---- import java.awt.Cursor; + import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.Collection; *************** *** 18,21 **** --- 19,23 ---- 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.Geometry; *************** *** 33,37 **** /** Feedback elements */ protected Collection elements = new HashSet(); ! /** * Constructor --- 35,55 ---- /** Feedback elements */ protected Collection elements = new HashSet(); ! ! /** Constructor elements */ ! protected Collection constructors = new HashSet(); ! ! /** Current intersection */ ! protected Intersection current; ! ! /** Start */ ! protected Intersection start; ! ! /** Incident */ ! protected Intersection incident; ! ! /** Number */ ! protected String number; ! ! /** * Constructor *************** *** 184,187 **** --- 202,279 ---- showFeedback(); } + + /** + * Show constructors + */ + protected void showConstructors() { + Iterator iter = constructors.iterator(); + while (iter.hasNext()) { + Edge current = (Edge) iter.next(); + glv.getView().addTempEdge(current); + } + } + + /** + * Hide constructors + */ + protected void hideConstructors() { + Iterator iter = constructors.iterator(); + while (iter.hasNext()) { + Edge current = (Edge) iter.next(); + glv.getView().removeTempEdge(current); + } + } + + /** + * Supply constructors + * @param feed Collection of edges + */ + protected void constructors(Collection feed) { + hideConstructors(); + constructors.clear(); + constructors.addAll(feed); + showConstructors(); + } + + /** + * Update constructors based on origin. + */ + protected void updateConstructors() { + if (start == null) { + if (incident != null) { + constructors(xyz(incident.vertex())); + } else { + constructors(new LinkedList()); + } + } else { + List constructors = new LinkedList(); + if (incident != null && current != null) { + Edge e1 = new Edge(incident.vertex(), current.vertex()); + Edge e2 = new Edge(current.vertex(), start.vertex()); + CoordinateSystem system = CoordinateSystem.create(e1, e2); + if (system != null) { + + Vertex a = system.translate(start.vertex()); + Vertex b = system.translate(current.vertex()); + Vertex p = system.translate(incident.vertex()); + + Vertex u = b.minus(a); + u.scale(1 / u.length()); + Vertex ap = p.minus(a); + double t = u.dot(ap); + u.scale(t); + Vertex q = a.add(u); + q = system.unTranslate(q); + Edge edge = new Edge(incident.vertex(), q); + edge.setConstructor(true); + constructors.add(edge); + constructors(constructors); + } + } + constructors.addAll(xyz(start.vertex())); + constructors(constructors); + number = ""; + } + } /** *************** *** 196,199 **** --- 288,298 ---- case Intersection.VERTEX: target = current; + if (start != null) { + if (intersection.vertex() != start.vertex()) { + incident = intersection; + } + } else { + incident = intersection; + } break; case Intersection.EDGE: *************** *** 205,208 **** --- 304,314 ---- case Intersection.EDGE_MIDPOINT: target = current; + if (start != null) { + if (intersection.vertex() != start.vertex()) { + incident = intersection; + } + } else { + incident = intersection; + } break; case Intersection.EDGE_INTERSECTION: *************** *** 219,222 **** --- 325,453 ---- } } + + /** + * onVertex - current vertex is pressed + */ + public void onVertex() { + + } + /** + * Make xyz in point origin + * @param origin Origin + * @return List of constructors + */ + protected List xyz(Vertex origin) { + List constructors = new LinkedList(); + Vertex i = new Vertex(1, 0, 0); + Vertex j = new Vertex(0, 1, 0); + Vertex n = new Vertex(0, 0, 1); + i.scale(50); + j.scale(50); + n.scale(50); + Edge e1 = new Edge(origin.minus(i), origin.add(i)); + Edge e2 = new Edge(origin.minus(j), origin.add(j)); + Edge e3 = new Edge(origin.minus(n), origin.add(n)); + e1.setConstructor(true); + e2.setConstructor(true); + e3.setConstructor(true); + constructors.add(e1); + constructors.add(e2); + constructors.add(e3); + return constructors; + } + + /** + * Invoked when a key has been pressed. Lets user delete what is selected. + * @param e The KeyEvent + */ + public void keyPressed(KeyEvent e) { + boolean changed = false; + if (number == null) { + number = ""; + } + if (e.getKeyCode() == KeyEvent.VK_1) { + number += "1"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_2) { + number += "2"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_3) { + number += "3"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_4) { + number += "4"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_5) { + number += "5"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_6) { + number += "6"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_7) { + number += "7"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_8) { + number += "8"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_9) { + number += "9"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_0) { + number += "0"; + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + int length = number.length(); + if (length > 1) { + number = number.substring(0, length - 1); + } else { + number = String.valueOf(0); + } + changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + try { + double d = Double.parseDouble(number); + if (current != null) { + Vertex before = null; + if (start != null) { + before = start.vertex(); + } else if (incident != null) { + before = incident.vertex(); + } + if (before != null) { + Vertex v = current.vertex().minus(before); + if (v.length() > 0.000000001) { + v.scale((d / 1000) / v.length()); + Vertex to = before.add(v); + current = new Intersection(to, Intersection.VERTEX, null); + onVertex(); + number = ""; + } + } + } + } catch (NumberFormatException exp) { + Project.info(exp); + } + } + if (changed) { + try { + double d = Double.parseDouble(number); + glv.setLength(d / 1000); + } catch (NumberFormatException exp) { + Project.info(exp); + } + } + } + + /** + * Clean up + */ + public void cleanUp() { + start = null; + current = null; + incident = null; + constructors(new LinkedList()); + feedback(new LinkedList()); + number = ""; + } } Index: ArcTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ArcTool.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ArcTool.java 22 Mar 2006 10:53:23 -0000 1.7 --- ArcTool.java 26 Mar 2006 21:40:32 -0000 1.8 *************** *** 25,35 **** */ public class ArcTool extends AbstractPencil { - - /** Current intersection */ - private Intersection current; - - /** Start */ - private Intersection start; - /** End */ private Intersection end; --- 25,28 ---- |