[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ExtendTool.java, NONE, 1.1 ToolFactor
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-12-03 17:29:55
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8850/src/net/sourceforge/bprocessor/gl/tool Modified Files: ToolFactory.java Tool.java Added Files: ExtendTool.java Removed Files: ControlledExtrudeTool.java Log Message: Changed ControlledExtrudeTool to ExtendTool Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** ToolFactory.java 28 Nov 2007 12:46:47 -0000 1.95 --- ToolFactory.java 3 Dec 2007 17:29:48 -0000 1.96 *************** *** 135,139 **** private ZoomTool zoomTool; ! private ControlledExtrudeTool multiExtrude; protected static Cursor errorCursor; --- 135,139 ---- private ZoomTool zoomTool; ! private ExtendTool extendTool; protected static Cursor errorCursor; *************** *** 191,195 **** rotation = new RotationTool(editor, null); extrude = new ExtrusionTool(editor, pencilcursor); ! multiExtrude = new ControlledExtrudeTool(editor, pencilcursor); clipplane = new ClipplaneTool(editor, pencilcursor); tapeMeasure = new TapeMeasure(editor, pencilcursor); --- 191,195 ---- rotation = new RotationTool(editor, null); extrude = new ExtrusionTool(editor, pencilcursor); ! extendTool = new ExtendTool(editor, pencilcursor); clipplane = new ClipplaneTool(editor, pencilcursor); tapeMeasure = new TapeMeasure(editor, pencilcursor); *************** *** 227,231 **** registerTool(Tool.EXTRUSION_TOOL, extrude, "Biconextrudetool.gif", "Extrude"); extrudeBut.setMnemonic(KeyEvent.VK_V); ! registerTool(Tool.MULTI_EXTRUDE_TOOL, multiExtrude, "Biconextrudetool2.gif", "Extend"); --- 227,231 ---- registerTool(Tool.EXTRUSION_TOOL, extrude, "Biconextrudetool.gif", "Extrude"); extrudeBut.setMnemonic(KeyEvent.VK_V); ! registerTool(Tool.EXTEND_TOOL, extendTool, "Biconextrudetool2.gif", "Extend"); --- NEW FILE: ExtendTool.java --- //--------------------------------------------------------------------------------- // $Id: ExtendTool.java,v 1.1 2007/12/03 17:29:48 rimestad 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.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import org.apache.log4j.Logger; import net.sourceforge.bprocessor.gl.Editor; import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Direction; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Mesh; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selection; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * A tool for push/pulling geometry * Should work as follows: * When a surface is pressed all its bound and unbound vertexes are found. * A bound vertex have edges that is not in the plane of the surface * A unbound is the opposite * All unbound vertexes are copied and connected to the copy by a edge, the * bound are moved in the direction of the edge that bounds it, * which should give a push/pull effect */ public class ExtendTool extends AbstractPencil { private static Logger log = Logger.getLogger(ExtendTool.class); private HashSet<Surface> extrusion; private Map<Vertex, Direction> v2dir; private Surface pressedSurface; private Plane dragPlane; private Collection<Surface> affected; private Vertex normal; private double maxExtrude; private double minExtrude; private Surface topSurface; private double length; /** * Tool constructor * @param editor The view to work in * @param cursor The cursor to use */ public ExtendTool(Editor editor, Cursor cursor) { super(editor, cursor); extrusion = new HashSet<Surface>(); affected = new HashSet<Surface>(); v2dir = new HashMap<Vertex, Direction>(); } /** {@inheritDoc} */ @Override public void onVertex() { if (pressedSurface != null) { Plane p = new Plane(normal.getX(), normal.getY(), normal.getZ(), current.vertex()); extrudeTo(p); finishTool(); } } /** {@inheritDoc} */ @Override protected void moved(MouseEvent e) { editor.getView().makeTarget(null); ArrayList<Surface> starter = new ArrayList<Surface>(); if (topSurface != pressedSurface) { starter.add(pressedSurface); } findTarget(e, starter); double x = e.getX(); double y = View.getHeight() - e.getY(); Vertex near = new Vertex(x, y, 0.0); Vertex far = new Vertex(x, y, 1.0); Edge ray = new Edge(near, far); Transformation transformation = editor.getView().transformation(); ray = transformation.unProject(ray); if (pressedSurface == null) { // If the extrusion havn't started yet if (target instanceof Surface) { editor.getView().makeTarget(target); current = new Intersection(((Surface)target).intersection(ray), Intersection.SURFACE, target); } } else { // The extrusion is started Vertex hit = dragPlane.intersection(ray); current = new Intersection(hit.minus(start.vertex()).projectOnto(normal).add(start.vertex()), Intersection.PLANE_INTERSECTION, dragPlane); //Find the plane to extrude to Plane p = null; if (target instanceof Surface) { Surface s = (Surface)target; if (affected.contains(s)) { Plane tmpP = s.plane(); findTarget(e, affected); if (target instanceof Surface) { Surface sur = (Surface)target; double dist = tmpP.distance(sur.getFirstVertex()); if (Math.abs(dist) < 0.001) { p = sur.plane(); } } } else { if (Math.abs((Math.abs(s.normal().angle(normal)) - Math.PI / 2)) >= 0.05) { p = new Plane(normal.projectOnto(s.normal()), s.getFirstVertex()); } } } if (p == null) { p = new Plane(normal.getX(), normal.getY(), normal.getZ(), current.vertex()); } if (v2dir.isEmpty()) { // If the extrusion isn't generated generate it Vertex delta = current.vertex().minus(start.vertex()); length = delta.length(); if (delta.angle(normal) > Math.PI / 2) { length *= -1; } topSurface = pressedSurface.extrusionControlled(length, extrusion, v2dir); if (topSurface != pressedSurface) { extrusion.add(topSurface); } affected.add(pressedSurface); affected.addAll(extrusion); affected.addAll(Edge.surfaces(topSurface.getEdges())); excluded(affected); Project.getInstance().getActiveSpace().addProtected(extrusion); maxExtrude = Double.POSITIVE_INFINITY; minExtrude = Double.NEGATIVE_INFINITY; for (Vertex v : v2dir.keySet()) { Direction d = v2dir.get(v); double scalar = d.getDirection().projectOnto(p.normal()).length(); double maxval = d.upper() * scalar; if (maxval < maxExtrude) { maxExtrude = maxval; } double minVal = d.lower() * scalar; if (minVal > minExtrude) { minExtrude = minVal; } } } else { //the extrusion is generated move it to the correct location extrudeTo(p); } } } private void extrudeTo(Plane p) { double dist = p.distance(start.vertex()) * -1; if (dist < minExtrude) { p.moveDelta(dist - minExtrude); } if (dist > maxExtrude) { p.moveDelta(dist - maxExtrude); } if (dist != 0) { current.vertex().set(p.intersection(start.vertex(), normal, true)); } else { current.vertex().set(start.vertex()); } for (Vertex v : v2dir.keySet()) { Direction d = v2dir.get(v); Vertex intersection = p.intersection(d.getVertex(), d.getDirection(), true); if (intersection != null) { d.getVertex().set(intersection); } } updateLength(); } /** {@inheritDoc} */ @Override protected void pressed(MouseEvent e) { //current = findIntersection(e); if (v2dir.isEmpty() && target != null && target instanceof Surface) { active = true; start = current; pressedSurface = (Surface)target; Transformation transformation = editor.getView().transformation(); double x = e.getX(); double y = View.getHeight() - e.getY(); 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); Vertex dir = ray.getDirection(); dir.normalize(); normal = pressedSurface.normal(); Vertex tmp = dir.cross(normal); dir = tmp.cross(normal); dragPlane = new Plane(dir.getX(), dir.getY(), dir.getZ(), pressedSurface.intersection(ray)); } else { finishTool(); } } private void finishTool() { Space owner = Project.getInstance().getActiveSpace(); owner.removeProtected(extrusion); if (pressedSurface != null && !start.vertex().minus(current.vertex()).projectOnto(normal).isZero()) { excluded(new ArrayList()); Mesh m = new Mesh(extrusion); m = owner.insert(m); if (extrusion.isEmpty()) { owner.simplify(); } for (Surface s : m.surfaces()) { if (s.equivalent(pressedSurface)) { pressedSurface = s; } else if (s.equivalent(topSurface)) { topSurface = s; } } if (pressedSurface != null) { if (pressedSurface.getExterior() != null) { if (length > 0) { pressedSurface.assignFront(pressedSurface.getBackDomain(), true); } else { pressedSurface.assignBack(pressedSurface.getFrontDomain(), true); } } else { if (length > 0) { pressedSurface.assignFront(pressedSurface.getFrontDomain(), true); } else { pressedSurface.assignBack(pressedSurface.getBackDomain(), true); } } } if (topSurface != null) { if (topSurface.getExterior() != null) { Surface.mergeSpaceAssign(topSurface, topSurface.getExterior(), topSurface); } } owner.changed(); Project.getInstance().checkpoint(); } cleanUp(); } /** {@inheritDoc} */ @Override public void prepare() { super.prepare(); if (!getSelection().isEmpty()) { Selection.primary().clear(); } } /** {@inheritDoc} */ @Override public void escape() { if (pressedSurface != null) { Project.getInstance().resetState(); } cleanUp(); } /** {@inheritDoc} */ @Override public void cleanUp() { super.cleanUp(); extrusion.clear(); affected.clear(); v2dir.clear(); pressedSurface = null; topSurface = null; dragPlane = null; normal = null; active = false; length = 0; maxExtrude = Double.POSITIVE_INFINITY; minExtrude = Double.NEGATIVE_INFINITY; } /** {@inheritDoc} */ @Override public String initialTip() { return "Press a surface and drag it to push/pull it"; } } Index: Tool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Tool.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Tool.java 28 Nov 2007 10:39:21 -0000 1.40 --- Tool.java 3 Dec 2007 17:29:48 -0000 1.41 *************** *** 54,58 **** public static final int CONSTRUCTOR_TOOL = 14; /** The controlled extrude tool */ ! public static final int MULTI_EXTRUDE_TOOL = 15; /** The Offset tool */ public static final int OFFSET_TOOL = 16; --- 54,58 ---- public static final int CONSTRUCTOR_TOOL = 14; /** The controlled extrude tool */ ! public static final int EXTEND_TOOL = 15; /** The Offset tool */ public static final int OFFSET_TOOL = 16; --- ControlledExtrudeTool.java DELETED --- |