[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ToolFactory.java, 1.68, 1.69 Rotation
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2006-12-05 09:07:33
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28099/src/net/sourceforge/bprocessor/gl/tool Modified Files: ToolFactory.java RotationTool.java Log Message: readded modified rotation tool Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** ToolFactory.java 30 Nov 2006 22:03:41 -0000 1.68 --- ToolFactory.java 5 Dec 2006 09:07:25 -0000 1.69 *************** *** 110,113 **** --- 110,116 ---- private RectTool altRect; + /** The Rotation tool */ + private RotationTool rotation; + /** The selection button */ private JToggleButton selBut; *************** *** 122,125 **** --- 125,131 ---- private JToggleButton moveBut; + /** The move button */ + private JToggleButton rotationBut; + /** The extrude button */ private JToggleButton extrudeBut; *************** *** 182,185 **** --- 188,192 ---- alternate = new VectorMoveTool(glv, pencilcursor); controlled = new ControlledMoveTool(glv, pencilcursor); + rotation = new RotationTool(glv, null); extrude = new ExtrusionTool(glv, pencilcursor); clipplane = new ClipplaneTool(glv, pencilcursor); *************** *** 212,215 **** --- 219,223 ---- moveBut.setMnemonic(KeyEvent.VK_M); registerTool(Tool.CONTROLLED_MOVE_TOOL, controlled, "Biconmovetool.gif", "Controlled Move"); + rotationBut = this.registerTool(Tool.ROTATION_TOOL, rotation, "Biconrotaxe.gif", "Rotate"); tb.addSeparator(3); tmBut = this.registerTool(Tool.TAPE_MEASURE_TOOL, tapeMeasure, Index: RotationTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RotationTool.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** RotationTool.java 8 Sep 2006 06:42:28 -0000 1.20 --- RotationTool.java 5 Dec 2006 09:07:25 -0000 1.21 *************** *** 8,25 **** import net.sourceforge.bprocessor.gl.GLView; - import net.sourceforge.bprocessor.model.ClippingPlane; import net.sourceforge.bprocessor.model.Edge; - import net.sourceforge.bprocessor.model.Entity; - import net.sourceforge.bprocessor.model.Geometric; import net.sourceforge.bprocessor.model.Geometry; ! import net.sourceforge.bprocessor.model.Plane; ! import net.sourceforge.bprocessor.model.Project; ! import net.sourceforge.bprocessor.model.Vertex; ! import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Selection; ! ! import net.sourceforge.bprocessor.gl.view.Transformation; ! import net.sourceforge.bprocessor.gl.view.View; import java.awt.Cursor; --- 8,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.Geometry; ! import net.sourceforge.bprocessor.model.Line; import net.sourceforge.bprocessor.model.Selection; ! import net.sourceforge.bprocessor.model.Vertex; import java.awt.Cursor; *************** *** 28,31 **** --- 21,27 ---- import java.util.HashSet; import java.util.Iterator; + import java.util.LinkedList; + import java.util.List; + import java.util.Set; import org.apache.log4j.Logger; *************** *** 34,75 **** * The rotation tool */ ! public class RotationTool extends AbstractTool { ! /** */ ! private static final int X_AXIS = 1; ! /** */ ! private static final int Y_AXIS = 2; ! /** */ ! private static final int Z_AXIS = 3; ! ! /** The chosen axis */ ! private int axis; ! /** The logger */ private static Logger log = Logger.getLogger(RotationTool.class); ! ! /** The initial vertex */ ! private Vertex initial; ! /** The vertex at drag start */ ! private Vertex from; ! /** The previous vertex when dragging */ ! private Vertex prev; ! ! /** The vertex at drag start */ ! private Vertex center; ! ! /** The maximum distance in x y and z */ ! private double dist = 0; ! ! /** The circle in the xy plane */ ! private HashSet zCircle = new HashSet(); ! /** The circle in the zy plane */ ! private HashSet xCircle = new HashSet(); ! /** The circle in the xz plane */ ! private HashSet yCircle = new HashSet(); ! /** The set containing the guide line */ ! private HashSet guide = new HashSet(); /** The vertexes to rotate */ ! private HashSet vertices = new HashSet(); ! /** * The Constructor --- 30,45 ---- * The rotation tool */ ! public class RotationTool extends AbstractPencil { /** The logger */ private static Logger log = Logger.getLogger(RotationTool.class); ! /** The vertexes to rotate */ ! private Set vertices = new HashSet(); ! /***/ ! private Intersection p1; ! /***/ ! private Intersection p2; ! /***/ ! private Line l; /** * The Constructor *************** *** 86,216 **** */ protected void pressed(MouseEvent e) { ! { ! if (target != null && target instanceof Entity) { ! // If one edge in a rotate circle are selected all should be ! if (xCircle.contains(target)) { ! axis = X_AXIS; ! clearConstructors(zCircle); ! clearConstructors(yCircle); ! } else if (yCircle.contains(target)) { ! axis = Y_AXIS; ! clearConstructors(xCircle); ! clearConstructors(zCircle); ! } else if (zCircle.contains(target)) { ! axis = Z_AXIS; ! clearConstructors(xCircle); ! clearConstructors(yCircle); ! } else { ! // ther were no rotation selection ! axis = 0; ! ! } ! ! if (axis != 0) { ! // do the rotation preparation and wait for drag events ! initial = findInitial(target, e); ! from = initial.copy(); ! prev = initial; ! Edge edge = new Edge(center, initial); ! edge.setStrippled(true); ! guide.clear(); ! guide.add(edge); ! displayConstructors(guide); ! } ! } else { ! clear(); ! } ! } } /** ! * Invoked when a mouse button has been released on a component. ! * @param e The MouseEvent */ ! protected void released(MouseEvent e) { ! findTarget(e); ! if (axis != 0) { ! rotate(from, initial, this.center); ! ! // We were rotating so show all constructor line again ! displayConstructors(xCircle); ! displayConstructors(yCircle); ! displayConstructors(zCircle); ! // remove guideline ! clearConstructors(guide); ! guide.clear(); ! } ! // make selection ! if (target != null && target instanceof Geometric) { ! if (target instanceof Edge && ((Edge)target).getStrippled()) { ! // If it is a constructor it should not be rotateable ! return; ! } ! clear(); ! Geometry.collect(Selection.primary(), vertices); ! ! // find the size of the handles ! center = ((Geometric)target).center(); ! dist = 0; ! gatherInformation(center, vertices); ! ! drawCircles(((Geometric)target).center(), dist); } else { ! // There were nothing selected ! if (axis == 0) { ! dist = 0; ! initial = null; ! from = null; } } } ! ! /** ! * Invoked when the mouse is held pressed and moved ! * @param e The MouseEvent object */ ! protected void dragged(MouseEvent e) { ! { ! if (target != null && ! (xCircle.contains(target) || yCircle.contains(target) || zCircle.contains(target))) { ! Vertex ny = findInitial(target, e); ! initial.setX(ny.getX()); ! initial.setY(ny.getY()); ! initial.setZ(ny.getZ()); ! ! prev = initial; } } } /** ! * Rotate the selected vertexes the angle from v1 to v2 ! * @param v1 The from vertex ! * @param v2 The to vertex ! * @param center the vertex to rotate about */ ! private void rotate(Vertex v1, Vertex v2, Vertex center) { ! //TODO need to take constratints into account ! Vertex first = from.minus(center); ! Vertex second = initial.minus(center); ! double direction = first.cross(second).getX() + ! first.cross(second).getY() + ! first.cross(second).getZ(); ! double angle = Math.acos(first.dot(second) / (first.length() * second.length()));; ! int x = axis == X_AXIS ? 1 : 0; ! int y = axis == Y_AXIS ? 1 : 0; ! int z = axis == Z_AXIS ? 1 : 0; ! if (!new Double(angle).isNaN()) { ! Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! Vertex v = (Vertex)iter.next(); ! if (direction > 0) { ! Geometry.rotate(angle, x, y, z, v, center); ! } else { ! Geometry.rotate(-angle, x, y, z, v, center); ! } ! } ! } ! Project.getInstance().changed(vertices); } --- 56,143 ---- */ protected void pressed(MouseEvent e) { ! process(e); } /** ! * On Vertex */ ! public void onVertex() { ! process(null); ! } ! ! /** ! * Process click ! * @param e MouseEvent ! */ ! private void process(MouseEvent e) { ! if (p1 == null) { ! p1 = current; ! start = p1; ! active = true; ! } else if (p2 == null) { ! p2 = current; ! start = p2; ! active = true; } else { ! if (start == p2) { ! //finish tool ! current = findIntersection(e); ! start = current; ! active = true; ! } else { ! current = findIntersection(e); ! Vertex v1 = new Edge(p1.vertex(), start.vertex()).getDirection(); ! Vertex v2 = new Edge(p1.vertex(), current.vertex()).getDirection(); ! double angle = v1.angle(v2); ! vertices = Selection.primary().collect(); ! Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! Vertex v = (Vertex) iter.next(); ! Geometry.rotate(angle, l.getDirection().getX(), ! l.getDirection().getY(), l.getDirection().getZ(), v, l.getOrigin()); ! } ! clear(); ! active = false; } } + updateFeedback(); } ! ! /** ! * bla ! * */ ! private void updateFeedback() { ! List points = new LinkedList(); ! List edges = new LinkedList(); ! if (p1 != null) { ! points.add(p1.vertex()); ! if (p2 != null) { ! if (l == null) { ! l = new Line(p1.vertex(), p2.vertex().minus(p1.vertex())); ! l.setActive(true); ! } ! edges.add(l); ! Edge e = new Edge(p1.vertex(), start.vertex()); ! e.setStrippled(true); ! edges.add(e); ! e = new Edge(p1.vertex(), current.vertex()); ! e.setStrippled(true); ! edges.add(e); } } + excluded(edges); + points(points); + feedback(edges); + makeTarget(current); + updateConstructors(); } /** ! * Invoked when a mouse button has been released on a component. ! * @param e The MouseEvent */ ! protected void released(MouseEvent e) { ! } *************** *** 219,224 **** */ public void cleanUp() { clear(); ! Selection.primary().clear(); } --- 146,152 ---- */ public void cleanUp() { + super.cleanUp(); clear(); ! updateFeedback(); } *************** *** 227,364 **** */ private void clear() { - clearConstructors(xCircle); - clearConstructors(yCircle); - clearConstructors(zCircle); - xCircle.clear(); - yCircle.clear(); - zCircle.clear(); vertices.clear(); } ! /** ! * Draw the three circles ! * @param center The center of the circles ! * @param radius The radius of the circles */ ! private void drawCircles(Vertex center, double radius) { ! zCircle.clear(); ! double xr = radius; ! double yr = 0; ! ! int segments = 20; ! double cos = Math.cos(Math.PI * 2.0 / segments); ! double sin = Math.sin(Math.PI * 2.0 / segments); ! // DRAW THE XY CIRCLE ! Vertex first = new Vertex(xr + center.getX(), yr + center.getY(), center.getZ()); ! Vertex parent = first.copy(); ! for (int i = 0; i < segments; ++i) { ! double temp = xr * cos + yr * sin; ! yr = yr * cos - xr * sin; ! xr = temp; ! Vertex prev = parent; ! parent = new Vertex(xr + center.getX(), yr + center.getY(), center.getZ()); ! Edge e = new Edge(prev, parent); ! e.setStrippled(true); ! zCircle.add(e); ! } ! Edge e = new Edge(parent, first); ! e.setStrippled(true); ! zCircle.add(e); ! displayConstructors(zCircle); ! // DRAW THE YZ CIRCLE ! xCircle.clear(); ! yr = radius; ! double zr = 0; ! first = new Vertex(center.getX(), yr + center.getY(), zr + center.getZ()); ! parent = first.copy(); ! for (int i = 0; i < segments; ++i) { ! double temp = yr * cos + zr * sin; ! zr = zr * cos - yr * sin; ! yr = temp; ! Vertex prev = parent; ! parent = new Vertex(center.getX(), yr + center.getY(), zr + center.getZ()); ! e = new Edge(prev, parent); ! e.setStrippled(true); ! xCircle.add(e); ! } ! e = new Edge(parent, first); ! e.setStrippled(true); ! xCircle.add(e); ! displayConstructors(xCircle); ! // DRAW THE XZ CIRCLE ! yCircle.clear(); ! xr = radius; ! zr = 0; ! first = new Vertex(xr + center.getX(), center.getY(), zr + center.getZ()); ! parent = first.copy(); ! for (int i = 0; i < segments; ++i) { ! double temp = xr * cos + zr * sin; ! zr = zr * cos - xr * sin; ! xr = temp; ! Vertex prev = parent; ! parent = new Vertex(xr + center.getX(), center.getY(), zr + center.getZ()); ! e = new Edge(prev, parent); ! e.setStrippled(true); ! yCircle.add(e); } - e = new Edge(parent, first); - e.setStrippled(true); - yCircle.add(e); - displayConstructors(yCircle); } ! /** ! * Gather information about size of bound ! * @param vertices The vertices to rotate ! * @param center The center of the element */ ! private void gatherInformation(Vertex center, HashSet vertices) { ! Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! Vertex cur = (Vertex)iter.next(); ! Vertex temp = cur.minus(center); ! if (temp.length() > dist) { ! dist = temp.length(); } } ! dist *= 1.1; ! } ! ! /** ! * Finds the initial point clicked for movement. ! * @param entity the entity initialy clicked ! * @param e the mouse event associated with the click. ! * @return the initial point of movement. ! */ ! protected Vertex findInitial(Object entity, MouseEvent e) { ! double x = e.getX(); ! double y = View.getHeight() - e.getY(); ! View v = glv.getView(); ! Transformation transformation = v.transformation(); ! Vertex near = new Vertex(x, y, 0.0); ! Vertex far = new Vertex(x, y, 1.0); ! Edge ray = new Edge(near, far); ! ray = transformation.unProject(ray); ! if (entity instanceof Vertex) { ! return ((Vertex)entity).copy(); ! } else if (entity instanceof Surface) { ! Plane plane = ((Surface)entity).plane(); ! return plane.intersection(ray); ! } else if (entity instanceof Edge) { ! Edge edge = (Edge) entity; ! Edge intersection = edge.intersection(ray); ! return intersection.getFrom(); ! } else if (entity instanceof ClippingPlane) { ! Plane plane = ((ClippingPlane) entity).getPlane(); ! return plane.intersection(ray); } - log.warn("The clicked object is not an Entity"); - return null; - } - - /** - * @param e MouseEvent - */ - protected void moved(MouseEvent e) { } } --- 155,199 ---- */ private void clear() { vertices.clear(); + p1 = null; + p2 = null; + start = null; + current = null; + incident = null; + l = null; } ! /** ! * @param e MouseEvent */ ! protected void moved(MouseEvent e) { ! current = findIntersection(e); ! if (current != null) { ! updateFeedback(); } } ! /** ! * Update the length field */ ! protected void updateLength() { ! Vertex v1 = null; ! Vertex v2 = null; ! if (p1 != null && p2 != null) { ! if (current != null) { ! if (start != null) { ! v1 = new Edge(p1.vertex(), start.vertex()).getDirection(); ! v2 = new Edge(p1.vertex(), current.vertex()).getDirection(); ! } else if (incident != null) { ! v1 = new Edge(p1.vertex(), incident.vertex()).getDirection(); ! v2 = new Edge(p1.vertex(), current.vertex()).getDirection(); ! } } } ! if (v1 != null && v2 != null) { ! setLength(v1.angle(v2)); ! } else { ! glv.setLengthValue(""); } } } |