[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ExtrusionTool.java, 1.39, 1.40 MoveTo
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8751/src/net/sourceforge/bprocessor/gl/tool Modified Files: MoveTool.java ExtrudeTool.java ToolFactory.java SpaceTool.java AbstractPencil.java Added Files: ExtrusionTool.java Log Message: New extrusion tool: - Uses the new Space.insert() operations that integrates new geometry with existing geometry. - Direction of extrusion can be changed during extrusion Index: ExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrudeTool.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** ExtrudeTool.java 10 Oct 2006 15:01:01 -0000 1.25 --- ExtrudeTool.java 22 Oct 2006 14:32:55 -0000 1.26 *************** *** 29,38 **** */ public class ExtrudeTool extends AbstractPencil { - - /** Limit offset */ - static final boolean LIMIT = false; /** If the mode has not been decided */ ! static final int UNDICIDED = 0; /** If the input mode is press - press */ --- 29,35 ---- */ public class ExtrudeTool extends AbstractPencil { /** If the mode has not been decided */ ! static final int UNDECIDED = 0; /** If the input mode is press - press */ *************** *** 40,44 **** /** Tool mode */ ! private int mode = UNDICIDED; /** The dragSurface */ --- 37,41 ---- /** Tool mode */ ! private int mode = UNDECIDED; /** The dragSurface */ *************** *** 98,102 **** prevX = e.getX(); prevY = e.getY(); ! if (mode == UNDICIDED) { cleanUp(); findTarget(e); --- 95,99 ---- prevX = e.getX(); prevY = e.getY(); ! if (mode == UNDECIDED) { cleanUp(); findTarget(e); *************** *** 186,190 **** sides = null; } ! mode = UNDICIDED; } --- 183,187 ---- sides = null; } ! mode = UNDECIDED; } *************** *** 239,243 **** removeExtrusion(); } ! mode = UNDICIDED; } --- 236,240 ---- removeExtrusion(); } ! mode = UNDECIDED; } *************** *** 259,263 **** sides = null; holeSides = null; ! mode = UNDICIDED; super.cleanUp(); } --- 256,260 ---- sides = null; holeSides = null; ! mode = UNDECIDED; super.cleanUp(); } *************** *** 288,292 **** */ protected void findLimits() { - if (direction > 0) { lowerLimit = 0.0; --- 285,288 ---- *************** *** 297,332 **** lowerLimit = Double.NEGATIVE_INFINITY; } - if (LIMIT) { - Collection surfaces = Project.getInstance().getActiveSpace().getSurfaces(); - Iterator iter = surfaces.iterator(); - Vertex normal = top.normal(); - Vertex origin = extrudeSurface.getFirstVertex(); - while (iter.hasNext()) { - Surface current = (Surface) iter.next(); - if (current != extrudeSurface && current != top) { - Vertex n = current.normal(); - Vertex cross = normal.cross(n); - if (cross.isZero()) { - Vertex o = current.getFirstVertex(); - Vertex vector = o.minus(origin); - double d = vector.dot(normal); - if (direction > 0) { - if (d > 0.0000001) { - if (d < upperLimit) { - upperLimit = d; - } - } - } - if (direction < 0) { - if (d < -0.0000001) { - if (d > lowerLimit) { - lowerLimit = d; - } - } - } - } - } - } - } } --- 293,296 ---- *************** *** 336,340 **** */ protected void moved(MouseEvent e) { ! if (mode == UNDICIDED) { findTarget(e); if (target != null) { --- 300,304 ---- */ protected void moved(MouseEvent e) { ! if (mode == UNDECIDED) { findTarget(e); if (target != null) { *************** *** 383,431 **** } } else { ! if (!LIMIT) { ! Set elements = new HashSet(); ! { ! Set edges = new HashSet(); ! elements.add(extrudeSurface); ! elements.addAll(sides); ! elements.add(top); ! if (holeSides != null) { ! elements.addAll(holeSides); ! } ! Iterator iter = elements.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! edges.addAll(current.getEdges()); ! } ! elements.addAll(edges); } ! findTarget(e, elements); ! if (target instanceof Surface) { ! Vertex origin = extrudeSurface.getFirstVertex(); ! Surface surface = (Surface) target; ! if (surface != extrudeSurface && surface != top && !elements.contains(surface)) { ! Vertex n = surface.normal(); ! Vertex cross = normal.cross(n); ! if (cross.isZero()) { ! Vertex o = surface.getFirstVertex(); ! Vertex vector = o.minus(origin); ! double d = vector.dot(normal); ! if (Math.abs(d) > 0.0000001) { ! moveTo(d); ! return; ! } } } } ! if (target instanceof Edge) { ! Vertex origin = extrudeSurface.getFirstVertex(); ! Edge edge = (Edge) target; ! Vertex o = edge.center(); ! Vertex vector = o.minus(origin); ! double d = vector.dot(normal); ! if (Math.abs(d) > 0.0000001) { ! moveTo(d); ! return; ! } } } --- 347,393 ---- } } else { ! Set elements = new HashSet(); ! { ! Set edges = new HashSet(); ! elements.add(extrudeSurface); ! elements.addAll(sides); ! elements.add(top); ! if (holeSides != null) { ! elements.addAll(holeSides); } ! Iterator iter = elements.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! edges.addAll(current.getEdges()); ! } ! elements.addAll(edges); ! } ! findTarget(e, elements); ! if (target instanceof Surface) { ! Vertex origin = extrudeSurface.getFirstVertex(); ! Surface surface = (Surface) target; ! if (surface != extrudeSurface && surface != top && !elements.contains(surface)) { ! Vertex n = surface.normal(); ! Vertex cross = normal.cross(n); ! if (cross.isZero()) { ! Vertex o = surface.getFirstVertex(); ! Vertex vector = o.minus(origin); ! double d = vector.dot(normal); ! if (Math.abs(d) > 0.0000001) { ! moveTo(d); ! return; } } } ! } ! if (target instanceof Edge) { ! Vertex origin = extrudeSurface.getFirstVertex(); ! Edge edge = (Edge) target; ! Vertex o = edge.center(); ! Vertex vector = o.minus(origin); ! double d = vector.dot(normal); ! if (Math.abs(d) > 0.0000001) { ! moveTo(d); ! return; } } Index: MoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MoveTool.java,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** MoveTool.java 10 Oct 2006 15:02:07 -0000 1.71 --- MoveTool.java 22 Oct 2006 14:32:55 -0000 1.72 *************** *** 215,219 **** last = null; active = false; - dragging = false; excluded(new LinkedList()); super.cleanUp(); --- 215,218 ---- Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** ToolFactory.java 9 Oct 2006 14:02:05 -0000 1.61 --- ToolFactory.java 22 Oct 2006 14:32:55 -0000 1.62 *************** *** 62,67 **** private AbstractTool controlled; ! /** extrusion tool */ ! private ExtrudeTool extrusion; /** pencil tool */ --- 62,67 ---- private AbstractTool controlled; ! /** Extrusion tool */ ! private ExtrusionTool extrude; /** pencil tool */ *************** *** 175,179 **** alternate = new VectorMoveTool(glv, pencilcursor); controlled = new ControlledMoveTool(glv, pencilcursor); ! extrusion = new ExtrudeTool(glv, pencilcursor); clipplane = new ClipplaneTool(glv, pencilcursor); tapeMeasure = new TapeMeasureTool(glv, pencilcursor); --- 175,179 ---- alternate = new VectorMoveTool(glv, pencilcursor); controlled = new ControlledMoveTool(glv, pencilcursor); ! extrude = new ExtrusionTool(glv, pencilcursor); clipplane = new ClipplaneTool(glv, pencilcursor); tapeMeasure = new TapeMeasureTool(glv, pencilcursor); *************** *** 199,204 **** arcb.setMnemonic(KeyEvent.VK_Z); tb.addSeparator(3); ! extrudeBut = this.registerTool(Tool.EXTRUSION_TOOL, extrusion, ! "Biconextrudetool.gif", "Extrude"); extrudeBut.setMnemonic(KeyEvent.VK_V); moveBut = this.registerTool(Tool.MOVE_TOOL, alternate, "Biconmovetool.gif", "Move"); --- 199,203 ---- arcb.setMnemonic(KeyEvent.VK_Z); tb.addSeparator(3); ! extrudeBut = registerTool(Tool.EXTRUSION_TOOL, extrude, "Biconextrudetool.gif", "Extrude"); extrudeBut.setMnemonic(KeyEvent.VK_V); moveBut = this.registerTool(Tool.MOVE_TOOL, alternate, "Biconmovetool.gif", "Move"); --- NEW FILE: ExtrusionTool.java --- //--------------------------------------------------------------------------------- // $Id: ExtrusionTool.java,v 1.40 2006/10/22 14:32:55 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.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.Set; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * Extrusion Tool */ public class ExtrusionTool extends AbstractPencil { /** Surface to extrude */ private Surface extrudesurface; /** start x */ private int startx; /** start y */ private int starty; /** drag plane */ private Plane dragplane; /** from */ private Vertex from; /** to */ private Vertex to; /** extrude distance */ private double distance; /** extrue all */ private boolean all; /** Extrusion */ private Collection extrusion; /** * Constructor * @param glv GLVIew * @param cursor Cursor */ public ExtrusionTool(GLView glv, Cursor cursor) { super(glv, cursor); } /** * Remove extrusion to active space * @param space Space * @param extrusion Collection of surface */ public void remove(Space space, Collection extrusion) { Iterator surfaces = extrusion.iterator(); while (surfaces.hasNext()) { Surface surface = (Surface) surfaces.next(); if (surface.getOwner() == space) { space.remove(surface); } Iterator edges = surface.getEdges().iterator(); while (edges.hasNext()) { Edge edge = (Edge) edges.next(); if (!extrudesurface.contains(edge)) { if (edge.getOwner() == space) { space.remove(edge); } Vertex from = edge.getFrom(); if (from.getOwner() == space) { space.remove(from); } Vertex to = edge.getTo(); if (to.getOwner() == space) { space.remove(to); } } } } } /** * Add extrusion from space * @param space Space * @param extrusion Collection of surfaces */ public void add(Space space, Collection extrusion) { Iterator surfaces = extrusion.iterator(); while (surfaces.hasNext()) { Surface surface = (Surface) surfaces.next(); Iterator edges = surface.getEdges().iterator(); while (edges.hasNext()) { Edge edge = (Edge) edges.next(); Vertex from = edge.getFrom(); if (from.getOwner() == null) { space.add(from); } Vertex to = edge.getTo(); if (to.getOwner() == null) { space.add(to); } if (edge.getOwner() == null) { space.add(edge); } } if (surface.getOwner() == null) { space.add(surface); } } } /** * Insert extrusion into space * @param space Space * @param extrusion Collection of surfaces */ public void insert(Space space, Collection extrusion) { Iterator surfaces = extrusion.iterator(); while (surfaces.hasNext()) { Surface surface = (Surface) surfaces.next(); space.insert(surface); } } /** * Extrude * @param distance double * @param all Extrude all * @param finish Finish extrusion */ public void extrude(double distance, boolean all, boolean finish) { Space space = Project.getInstance().getActiveSpace(); if (extrusion != null) { remove(space, extrusion); extrusion = null; } extrusion = new LinkedList(); Set sides = new HashSet(); Set tops = new HashSet(); if (all) { extrudesurface.extrusionall(distance, sides, tops); extrusion.addAll(sides); extrusion.addAll(tops); } else { Surface top = extrudesurface.extrusion(distance, sides); extrusion.add(top); extrusion.addAll(sides); } if (finish) { insert(space, extrusion); } else { add(space, extrusion); } } /** * Moved * @param e MouseEvent */ protected void moved(MouseEvent e) { if (extrudesurface == null) { findTarget(e); if (target instanceof Surface) { glv.getView().makeTarget(target); } else if (target == null) { glv.getView().makeTarget(null); } } else { active = true; to = glv.getView().toPlaneCoords(new double[] {e.getX(), e.getY()}, dragplane); Vertex normal = extrudesurface.normal(); Set elements = new HashSet(); if (extrusion != null) { elements.addAll(extrusion); elements.addAll(Surface.edges(extrusion)); elements.add(extrudesurface); } findTarget(e, elements); if (target instanceof Surface) { Surface surface = (Surface) target; Vertex n = surface.normal(); Vertex cross = normal.cross(n); if (cross.isZero()) { Vertex v = surface.getFirstVertex(); if (!extrudesurface.plane().contains(v)) { to = v; } } } else if (target instanceof Edge) { Edge edge = (Edge) target; to = edge.center(); Vertex v = edge.center(); if (!extrudesurface.plane().contains(v)) { to = v; } } Vertex delta = to.minus(from); distance = normal.dot(delta); extrude(distance, all, false); } } /** * Pressed * @param e MouseEvent */ protected void pressed(MouseEvent e) { if (extrudesurface == null) { findTarget(e); if (target instanceof Surface) { extrudesurface = (Surface) target; startx = e.getX(); starty = e.getY(); View view = glv.getView(); Transformation trans = view.transformation(); double x = startx; double y = View.getHeight() - starty; Vertex near = new Vertex(x, y, 0.0); Vertex far = new Vertex(x, y, 1.0); Edge ray = new Edge(near, far); ray = trans.unProject(ray); Plane plane = extrudesurface.plane(); dragplane = plane.orthogonalPlane(ray); from = view.toPlaneCoords(new double[] {startx, starty}, dragplane); all = !e.isAltDown(); } } else { if (extrusion != null) { extrude(distance, all, true); extrusion = null; Project.getInstance().checkpoint(); } cleanUp(); moved(e); } } /** * Apply current tool with specified length value * @param length The lengthfield value */ public void apply(double length) { if (extrusion != null) { if (distance < 0) { length = -length; } extrude(length, all, true); extrusion = null; Project.getInstance().checkpoint(); cleanUp(); } } /** * */ public void cleanUp() { all = false; dragplane = null; from = null; to = null; if (extrusion != null) { remove(Project.getInstance().getActiveSpace(), extrusion); extrusion = null; } extrudesurface = null; super.cleanUp(); } } Index: AbstractPencil.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractPencil.java,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** AbstractPencil.java 10 Oct 2006 14:59:33 -0000 1.70 --- AbstractPencil.java 22 Oct 2006 14:32:55 -0000 1.71 *************** *** 97,104 **** protected Timer timer; ! /** Wherther or not the tool is doing some work */ protected boolean active; ! /** Wherther or not the tool is dragging */ protected boolean dragging; --- 97,104 ---- protected Timer timer; ! /** Whether or not the tool is doing some work */ protected boolean active; ! /** Whether or not the tool is dragging */ protected boolean dragging; Index: SpaceTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SpaceTool.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** SpaceTool.java 20 Oct 2006 17:04:40 -0000 1.58 --- SpaceTool.java 22 Oct 2006 14:32:55 -0000 1.59 *************** *** 769,772 **** --- 769,799 ---- }); + globals.put("extrudeall", new Builtin() { + public void evaluate(Environment env, Stack stack) { + Surface surface = (Surface) env.get(0); + Double distance = (Double) env.get(1); + HashSet sides = new HashSet(); + HashSet tops = new HashSet(); + surface.extrusionall(distance.doubleValue(), sides, tops); + stack.push(surface); + { + Iterator iter = sides.iterator(); + while (iter.hasNext()) { + Surface current = (Surface) iter.next(); + stack.push(current); + } + } + { + Iterator iter = tops.iterator(); + while (iter.hasNext()) { + Surface current = (Surface) iter.next(); + stack.push(current); + } + } + } + }); + + + String script = Project.getInstance().getScript(); try { *************** *** 811,814 **** --- 838,842 ---- } catch (Exception error) { System.out.println(error); + error.printStackTrace(); } } catch (Exception error) { |