[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool RotationToolB.java, NONE, 1.1 ToolFac
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv15624/src/net/sourceforge/bprocessor/gl/tool Modified Files: ToolFactory.java RotationTool.java FinalMoveTool.java AbstractPencil.java Added Files: RotationToolB.java Log Message: new rotation tool Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.106 retrieving revision 1.107 diff -C2 -d -r1.106 -r1.107 *** ToolFactory.java 14 Sep 2009 16:22:59 -0000 1.106 --- ToolFactory.java 13 Jan 2010 10:58:30 -0000 1.107 *************** *** 75,79 **** private AbstractTool protractor; private FinalMoveTool moving; ! private RotationTool rotation; private OffsetTool offset; private ExtrusionTool extrude; --- 75,79 ---- private AbstractTool protractor; private FinalMoveTool moving; ! private RotationToolB rotation; private OffsetTool offset; private ExtrusionTool extrude; *************** *** 146,150 **** eraser = new EraserTool(editor, pencilcursor); arc = new ArcTool(editor, pencilcursor); ! rotation = new RotationTool(editor, null); extrude = new ExtrusionTool(editor, pencilcursor); extend = new ExtendTool(editor, pencilcursor); --- 146,150 ---- eraser = new EraserTool(editor, pencilcursor); arc = new ArcTool(editor, pencilcursor); ! rotation = new RotationToolB(editor, null); extrude = new ExtrusionTool(editor, pencilcursor); extend = new ExtendTool(editor, pencilcursor); Index: FinalMoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/FinalMoveTool.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** FinalMoveTool.java 22 Dec 2009 13:51:51 -0000 1.55 --- FinalMoveTool.java 13 Jan 2010 10:58:30 -0000 1.56 *************** *** 216,220 **** public InstanceMove(Instance instance, CoordinateSystem handle) { this.instance = instance; ! this.initialCoordinate = instance.getInstanceAnchor().copy(); this.handle = handle.copy(); CoordinateSystem tmp = this.initialCoordinate.unTranslate(this.handle); --- 216,220 ---- public InstanceMove(Instance instance, CoordinateSystem handle) { this.instance = instance; ! this.initialCoordinate = instance.getAnchor(); this.handle = handle.copy(); CoordinateSystem tmp = this.initialCoordinate.unTranslate(this.handle); *************** *** 235,240 **** CoordinateSystem cs = null; if (current.object() instanceof Surface) { - // convert the handle into the coordinatesystems of the surface and translate - //the instance anchor according to that Surface surface = (Surface)current.object(); Vertex n = surface.normal(); --- 235,238 ---- *************** *** 262,271 **** prevCs = cs; } ! CoordinateSystem zero = new CoordinateSystem(new Vertex(1, 0, 0), new Vertex(0, 1, 0), ! new Vertex(0, 0, 1), new Vertex(0, 0, 0)); ! CoordinateSystem tmp = handle.translate(zero); ! tmp = cs.unTranslate(tmp); ! instance.getInstanceAnchor().setOrigin(tmp.center()); ! instance.getInstanceAnchor().setIJN(tmp.getI(), tmp.getJ(), tmp.getN()); } --- 260,264 ---- prevCs = cs; } ! instance.setAnchor(cs); } *************** *** 274,278 **** */ public void revert() { ! instance.getInstanceAnchor().setAttributes(initialCoordinate.getAttributes()); } } --- 267,271 ---- */ public void revert() { ! instance.setAnchor(initialCoordinate); } } *************** *** 626,631 **** */ public void activate(Instance instance) { ! CoordinateSystem anchor = instance.getInstanceAnchor(); ! Vertex center = anchor.unTranslate(anchor.getOrigin()); Intersection intersection = new Intersection(center, Intersection.VERTEX, instance); LinkedList<Geometric> geometrics = new LinkedList(); --- 619,624 ---- */ public void activate(Instance instance) { ! CoordinateSystem transformation = instance.getTransformation(); ! Vertex center = transformation.unTranslate(transformation.getOrigin()); Intersection intersection = new Intersection(center, Intersection.VERTEX, instance); LinkedList<Geometric> geometrics = new LinkedList(); *************** *** 674,689 **** if (geometrics.size() == 1) { ! Geometric work = geometrics.iterator().next(); ! if (work instanceof Instance) { ! Instance space = (Instance)work; ! CoordinateSystem anchor = null; ! for (CoordinateSystem currentSystem : space.getProto().getCoordinateSystems()) { ! anchor = currentSystem; ! break; ! } ! if (anchor == null) { ! anchor = Project.getInstance().getActiveCoordinateSystem().copy(); ! } ! mover = new InstanceMove(space, anchor); } } --- 667,675 ---- if (geometrics.size() == 1) { ! Geometric first = geometrics.iterator().next(); ! if (first instanceof Instance) { ! Instance instance = (Instance) first; ! CoordinateSystem handle = instance.getHandle(); ! mover = new InstanceMove(instance, handle); } } --- NEW FILE: RotationToolB.java --- //--------------------------------------------------------------------------------- // $Id: RotationToolB.java,v 1.1 2010/01/13 10:58:30 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.Iterator; import java.util.LinkedList; import java.util.List; import net.sourceforge.bprocessor.gl.Editor; import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Geometric; import net.sourceforge.bprocessor.model.Geometry; import net.sourceforge.bprocessor.model.Instance; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selection; import net.sourceforge.bprocessor.model.Vertex; /** * */ public class RotationToolB extends AbstractPencil { private CoordinateSystem system; private Protract protract; private Vertex base; private List<Vertex> vertices; private List<Vertex> originals; /** * * @param editor Editor * @param cursor Cursor */ public RotationToolB(Editor editor, Cursor cursor) { super(editor, cursor); showConstructors = false; } /** * */ public void onVertex() { } private void cache() { originals = new LinkedList(); for (Vertex current : vertices) { originals.add(current.copy()); } } private void reset() { Iterator<Vertex> actual = vertices.iterator(); Iterator<Vertex> original = originals.iterator(); while (actual.hasNext()) { Vertex current = actual.next(); Vertex value = original.next(); current.set(value); } } private void rotate(double angle) { if (!Double.isNaN(angle)) { Vertex center = center(); Vertex n = normal(); double x = n.getX(); double y = n.getY(); double z = n.getZ(); reset(); for (Vertex current : vertices) { Geometry.rotate(angle, x, y, z, current, center); } for (Vertex current : vertices) { current.update(); } } } private void finish() { base = null; Project.getInstance().checkpoint(); Project.getInstance().changed(vertices); cache(); } /** * {@inheritDoc} */ protected void moved(MouseEvent e) { current = findIntersection(e); if (current != null) { if (system != null) { if (base != null) { double angle = angle(); if (!Double.isNaN(angle)) { rotate(angle); } } } updateFeedback(); } } /** * {@inheritDoc} */ protected void pressed(MouseEvent e) { current = findIntersection(e); if (current != null) { if (system != null) { if (base == null) { base = direction(); } else { double angle = angle(); rotate(angle); finish(); } } else { if (start == null) { start = current; } else { Vertex origin = start.vertex(); Vertex to = current.vertex(); Vertex n = to.minus(origin); if (!n.isZero()) { n.normalize(); system = CoordinateSystem.systemFor(origin, n); start = null; } } } updateFeedback(); } } private Vertex direction() { Plane plane = system.plane(); Vertex vertex = plane.projection(current.vertex()); Vertex u = vertex.minus(system.getOrigin()); u.normalize(); return u; } private Vertex center() { return system.getOrigin(); } private Vertex normal() { return system.getN(); } private Vertex base() { if (base != null) { return base; } else { return system.getI(); } } private double angle() { Vertex i = base(); Vertex u = direction(); if (u.isZero()) { return Double.NaN; } if (i.cross(u).isZero()) { return 0; } else { double angle = i.angle(u); double box = i.cross(u).dot(system.getN()); if (box < 0) { angle = -angle; } return angle; } } /** * {@inheritDoc} */ protected void updateLength() { if (system != null) { double angle = angle() * 180 / Math.PI; setLength(angle / 1000); } else { clearLength(); } } /** * Update feedback */ protected void updateFeedback() { if (protract != null) { editor.getView().removeGlObjects3D(protract); protract = null; } List<Edge> edges = new LinkedList(); if (current != null) { if (system != null) { showConstructors = false; Vertex center = system.getOrigin(); Vertex i = base(); Vertex j = normal().cross(i); protract = new Protract(center, i, j, true); editor.getView().addGlObjects3D(protract); } else { showConstructors = true; if (start != null) { Vertex origin = start.vertex(); Vertex to = current.vertex(); Edge axis = new Edge(origin, to); axis.setStrippled(true); edges.add(axis); } } } feedback(edges); makeTarget(current); updateConstructors(); } /** * {@inheritDoc} */ public void apply(double value) { if (protract != null) { double angle = (value * 1000) * Math.PI / 180; rotate(angle); finish(); } } /** * {@inheritDoc} */ public void prepare() { setLabel("Angle:"); if (Selection.primary().size() == 1) { Geometric geometric = Selection.primary().iterator().next(); system = systemFor(geometric); if (system != null) { system = system.copy(); } } vertices = new LinkedList(Selection.primary().collect()); cache(); } private CoordinateSystem systemFor(Geometric geometric) { if (geometric instanceof Instance) { return systemFor((Instance) geometric); } return null; } private CoordinateSystem systemFor(Instance instance) { return instance.getAnchor(); } /** * {@inheritDoc} */ public String initialTip() { return "Rotate"; } /** * {@inheritDoc} */ public void cleanUp() { super.cleanUp(); if (protract != null) { editor.getView().removeGlObjects3D(protract); protract = null; } base = null; system = null; } } Index: AbstractPencil.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractPencil.java,v retrieving revision 1.111 retrieving revision 1.112 diff -C2 -d -r1.111 -r1.112 *** AbstractPencil.java 22 Dec 2009 13:51:51 -0000 1.111 --- AbstractPencil.java 13 Jan 2010 10:58:30 -0000 1.112 *************** *** 13,16 **** --- 13,17 ---- import java.awt.event.MouseEvent; import java.util.Collection; + import java.util.Collections; import java.util.HashSet; import java.util.Iterator; *************** *** 122,125 **** --- 123,128 ---- protected boolean dragging; + protected boolean showConstructors; + /** An extension of the locking edge when moving * outside the lockingedge */ *************** *** 144,147 **** --- 147,151 ---- lock = false; active = false; + showConstructors = true; } *************** *** 420,425 **** */ protected void updateConstructors() { ! List constructors = computeConstructors(); ! constructors(constructors); number = ""; updateLength(); --- 424,433 ---- */ protected void updateConstructors() { ! if (showConstructors) { ! List constructors = computeConstructors(); ! constructors(constructors); ! } else { ! constructors(Collections.EMPTY_LIST); ! } number = ""; updateLength(); Index: RotationTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RotationTool.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** RotationTool.java 22 Dec 2009 13:51:51 -0000 1.35 --- RotationTool.java 13 Jan 2010 10:58:30 -0000 1.36 *************** *** 45,49 **** /** The vertexes to rotate */ ! private Set vertices = new HashSet(); /** The first pressed point */ private Vertex p1; --- 45,49 ---- /** The vertexes to rotate */ ! private Set<Vertex> vertices = new HashSet(); /** The first pressed point */ private Vertex p1; *************** *** 54,58 **** /** the previous vertex when moving the mouse */ private Vertex previous; ! /** The plane whose normal is rotated aboud */ private Plane onto; /** The gl object drawing the rotation circle */ --- 54,58 ---- /** the previous vertex when moving the mouse */ private Vertex previous; ! /** The plane whose normal is rotated around */ private Plane onto; /** The gl object drawing the rotation circle */ *************** *** 295,303 **** */ private void rotate(double angle) { ! Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! Vertex v = (Vertex)iter.next(); ! Geometry.rotate(angle, onto.getDoublev()[Vertex.X], ! onto.getDoublev()[Vertex.Y], onto.getDoublev()[Vertex.Z], v, p1); } } --- 295,303 ---- */ private void rotate(double angle) { ! for (Vertex v : vertices) { ! Vertex n = onto.normal(); ! Geometry.rotate(angle, n.getX(), ! n.getY(), n.getZ(), v, p1); ! v.update(); } } |