Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool MultiExtrudeTool.java,1.17,1.18
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2006-05-15 15:32:21
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv32042/src/net/sourceforge/bprocessor/gl/tool Modified Files: MultiExtrudeTool.java Log Message: Added and changed functionality to make it possible to make extrusion onto a other surface that is not co-planer. Repaired the move plane problem and added extrusion of holes... Index: MultiExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MultiExtrudeTool.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** MultiExtrudeTool.java 1 May 2006 09:59:00 -0000 1.17 --- MultiExtrudeTool.java 15 May 2006 15:32:16 -0000 1.18 *************** *** 9,12 **** --- 9,14 ---- import java.awt.Cursor; + import java.awt.event.KeyEvent; + import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.util.Collection; *************** *** 23,27 **** --- 25,33 ---- import net.sourceforge.bprocessor.gl.GLView; 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.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selection; *************** *** 32,36 **** * The ExtrudeTool */ ! public class MultiExtrudeTool extends AbstractPencil { /** The logger */ private static Logger log = Logger.getLogger(MultiExtrudeTool.class); --- 38,42 ---- * The ExtrudeTool */ ! public class MultiExtrudeTool extends AbstractPencil implements KeyListener { /** The logger */ private static Logger log = Logger.getLogger(MultiExtrudeTool.class); *************** *** 48,56 **** private double t; - /** The set of extruded elements*/ - private Set elements; - /** The extrusion direction */ private double direction = 0.0; /** --- 54,74 ---- private double t; /** The extrusion direction */ private double direction = 0.0; + + /** Tells if the extrude method is controlled or not */ + private boolean controlled = false; + + /** The constructor from start to current vertexes in AbstractPencil */ + private Edge moveConstructor; + + /** The direction constructior edge */ + private Edge dir; + + /** True if holes should also be extruded */ + private boolean extrudeAll; + + /** The created surfaces */ + private HashSet creations; /** *************** *** 69,72 **** --- 87,91 ---- elements = new HashSet(); surfaces = new HashSet(); + extrudeAll = true; } *************** *** 77,82 **** protected void pressed(MouseEvent e) { if (start == null) { - start = current; if (current.type() == Intersection.SURFACE) { Surface target = (Surface)current.object(); if (Selection.primary().isEmpty() || Selection.primary().contains(target)) { --- 96,101 ---- protected void pressed(MouseEvent e) { if (start == null) { if (current.type() == Intersection.SURFACE) { + start = current; Surface target = (Surface)current.object(); if (Selection.primary().isEmpty() || Selection.primary().contains(target)) { *************** *** 86,91 **** --- 105,132 ---- Vertex normal = extrudeSurface.normal().copy(); normal.scale(-1); + log.info("Length of normal: " + normal.length()); lock = true; locked = normal; + Transformation trans = glv.getView().transformation(); + double x = e.getX(); + double y = View.getHeight() - e.getX(); + 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 = extrudeSurface.plane().orthogonalPlane(ray); + log.info("Distance to ortho-plane from start " + plane.distance(start.vertex())); + log.info("Distance to plane from start " + + extrudeSurface.plane().distance(start.vertex())); + LinkedList planeinfo = new LinkedList(); + Vertex normalCopy = normal.copy(); + normalCopy.scale(20); + dir = new Edge(start.vertex().add(normalCopy), start.vertex().minus(normalCopy)); + dir.setConstructor(true); + glv.getView().changeColor(dir, new float[] {255f, 0, 0}); + planeinfo.add(dir); + constructors(planeinfo); + } else { + start = null; } } *************** *** 97,101 **** finishExtrusion(); } ! cleanUp(); } } --- 138,152 ---- finishExtrusion(); } ! start = null; ! t = 0; ! number = ""; ! extrudeSurface = null; ! direction = 0.0; ! v2dir = null; ! elements = new HashSet(); ! surfaces = new HashSet(); ! constructors(new LinkedList()); ! excluded(new LinkedList()); ! dir = null; } } *************** *** 115,139 **** */ private void deleteExtrusion() { ! excluded(new LinkedList()); ! Project.getInstance().undo(); ! cleanUp(); } - // - // /** - // * Remove all the created extrusion elements - // * @param elem The elements to remove - // */ - // private void remove(Set elem) { - // if (elem != null) { - // Iterator iter = elem.iterator(); - // while (iter.hasNext()) { - // Object o = iter.next(); - // if (o instanceof Surface) { - // ((Surface)o).delete(); - // } - // } - // cleanUp(); - // } - // } /** --- 166,175 ---- */ private void deleteExtrusion() { ! Project.getInstance().resetState(); ! t = 0; ! elements = new HashSet(); ! surfaces = new HashSet(); ! v2dir = null; } /** *************** *** 141,147 **** */ public void cleanUp() { start = null; t = 0; - number = ""; extrudeSurface = null; direction = 0.0; --- 177,186 ---- */ public void cleanUp() { + if (extrudeSurface != null) { + extrudeSurface = null; + deleteExtrusion(); + } start = null; t = 0; extrudeSurface = null; direction = 0.0; *************** *** 149,152 **** --- 188,193 ---- elements = new HashSet(); surfaces = new HashSet(); + dir = null; + extrudeAll = true; super.cleanUp(); } *************** *** 156,160 **** */ private void finishExtrusion() { ! Iterator iter = elements.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); --- 197,201 ---- */ private void finishExtrusion() { ! Iterator iter = creations.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); *************** *** 163,167 **** } } - cleanUp(); Project.getInstance().changed(Project.getInstance()); Project.getInstance().checkpoint(); --- 204,207 ---- *************** *** 171,181 **** * Move a collection of vertex, direction pairs * @param which The colelction of pairs * @param to The amount of the direction each vertex should move */ ! private void moveTo(Collection which, double to) { ! double delta = t - to; Iterator iter = which.iterator(); while (iter.hasNext()) { Direction d = (Direction)iter.next(); Vertex movement = d.getDirection(); Vertex v = movement.copy(); --- 211,226 ---- * Move a collection of vertex, direction pairs * @param which The colelction of pairs + * @param normal For finding the already moved distance * @param to The amount of the direction each vertex should move */ ! private void moveTo(Collection which, double to, Vertex normal) { ! log.info("Move all"); Iterator iter = which.iterator(); + t = 0.0; while (iter.hasNext()) { Direction d = (Direction)iter.next(); + t = start.vertex().minus(d.getVertex()).dot(normal); + log.info(d.getVertex() + " were " + t + " away"); + double delta = t - to; Vertex movement = d.getDirection(); Vertex v = movement.copy(); *************** *** 183,187 **** d.getVertex().move(v.getX(), v.getY(), v.getZ()); } ! t = to; glv.setLength(t); } --- 228,249 ---- d.getVertex().move(v.getX(), v.getY(), v.getZ()); } ! glv.setLength(t); ! } ! ! /** ! * Move a collection of vertex, direction pairs ! * @param which The colelction of pairs ! * @param normal For finding the already moved distance ! * @param to The amount of the direction each vertex should move ! */ ! private void moveTo(Direction which, double to, Vertex normal) { ! log.info("move one"); ! t = start.vertex().minus(which.getVertex()).dot(normal); ! double delta = t - to; ! log.info(which.getVertex() + " were " + t + " away"); ! Vertex movement = which.getDirection(); ! Vertex v = movement.copy(); ! v.scale(delta); ! which.getVertex().move(v.getX(), v.getY(), v.getZ()); glv.setLength(t); } *************** *** 201,206 **** */ private boolean makeExtrusion(Collection c, double direction) { ! Project.getInstance().checkpoint(); ! elements = new HashSet(); Map e2e = new HashMap(); // edge to edge map Map e2s = new HashMap(); // edge to surface map --- 263,268 ---- */ private boolean makeExtrusion(Collection c, double direction) { ! log.info(extrudeSurface + "were extruded"); ! creations = new HashSet(); Map e2e = new HashMap(); // edge to edge map Map e2s = new HashMap(); // edge to surface map *************** *** 218,224 **** while (iter.hasNext()) { Surface cur = (Surface)iter.next(); ! Surface s = cur.extrude(-direction, elements, e2e, v2e, e2s, v2dir); ! elements.add(s); } t = 0; return true; --- 280,306 ---- while (iter.hasNext()) { Surface cur = (Surface)iter.next(); ! Surface s; ! if (controlled) { ! if (extrudeAll) { ! Iterator holes = cur.getHoles().iterator(); ! while (holes.hasNext()) { ! Surface hole = (Surface) holes.next(); ! creations.add(hole.extrudeControlled(-direction, creations, e2e, v2e, e2s, v2dir)); ! } ! } ! s = cur.extrudeControlled(-direction, creations, e2e, v2e, e2s, v2dir); ! } else { ! if (extrudeAll) { ! Iterator holes = cur.getHoles().iterator(); ! while (holes.hasNext()) { ! Surface hole = (Surface) holes.next(); ! creations.add(hole.extrude(-direction, creations, e2e, v2e, e2s, v2dir)); ! } ! } ! s = cur.extrude(-direction, creations, e2e, v2e, e2s, v2dir); ! } ! creations.add(s); } + excluded(getAffected(creations)); t = 0; return true; *************** *** 231,236 **** current = findIntersection(e); makeTarget(current); if (start != null) { - // do the shit modifyExtrusion(); } --- 313,319 ---- current = findIntersection(e); makeTarget(current); + timer.stop(); + updateConstructors(); if (start != null) { modifyExtrusion(); } *************** *** 238,241 **** --- 321,349 ---- /** + * + * Update constructors + */ + public void updateConstructors() { + if (start != null && current != null) { + //super.updateConstructors(); + moveConstructor = new Edge(start.vertex(), current.vertex()); + moveConstructor.setConstructor(true); + LinkedList constCopy = new LinkedList(); + constCopy.add(moveConstructor); + constCopy.add(dir); + LinkedList excl = new LinkedList(); + excl.addAll(excluded); + excl.add(moveConstructor); + constructors(constCopy); + excluded(excl); + } else { + constructors(new LinkedList()); + feedback(new LinkedList()); + } + number = ""; + updateLength(); + } + + /** * Do the appropiate changes to the extrusion */ *************** *** 250,258 **** normDotDelta = -extrudeSurface.normal().dot(delta); } ! if (v2dir == null) { direction = normDotDelta; makeExtrusion(surfaces, direction); } if (v2dir != null) { // The extrusion were succesfull move it if (normDotDelta * direction < 0) { --- 358,367 ---- normDotDelta = -extrudeSurface.normal().dot(delta); } ! if (v2dir == null && Math.abs(normDotDelta) > 0) { direction = normDotDelta; makeExtrusion(surfaces, direction); } if (v2dir != null) { + //log.info("Direction were " + direction + " and extrude were " + normDotDelta); // The extrusion were succesfull move it if (normDotDelta * direction < 0) { *************** *** 261,265 **** makeExtrusion(surfaces, direction); } ! moveTo(v2dir.values(), normDotDelta); } } --- 370,404 ---- makeExtrusion(surfaces, direction); } ! if (current.type() == Intersection.SURFACE) { ! // should extrude to the surface if it is possible ! log.info(current + " were hit"); ! Iterator dirs = v2dir.values().iterator(); ! boolean wereInside = true; ! LinkedList lengths = new LinkedList(); ! while (dirs.hasNext()) { ! Direction dir = (Direction)dirs.next(); ! Plane p = ((Surface)current.object()).plane(); ! Vertex v = p.intersection(dir.getVertex(), dir.getDirection()); ! if (v == null) { ! wereInside = false; ! break; ! } else { ! lengths.addLast(new Double(-extrudeSurface.normal().dot(v.minus(dir.getVertex())))); ! } ! } ! if (wereInside) { ! log.info(current + " Were a good target"); ! dirs = v2dir.values().iterator(); ! int i = 0; ! Vertex nor = extrudeSurface.normal(); ! while (dirs.hasNext()) { ! Direction dir = (Direction)dirs.next(); ! moveTo(dir, ((Double)lengths.get(i)).doubleValue(), nor); ! i++; ! } ! } ! } ! ! moveTo(v2dir.values(), normDotDelta, extrudeSurface.normal()); } } *************** *** 279,287 **** makeExtrusion(surfaces, direction); } ! moveTo(v2dir.values(), length); } else { direction = length; makeExtrusion(surfaces, direction); ! moveTo(v2dir.values(), length); } finishExtrusion(); --- 418,426 ---- makeExtrusion(surfaces, direction); } ! moveTo(v2dir.values(), length, extrudeSurface.normal()); } else { direction = length; makeExtrusion(surfaces, direction); ! moveTo(v2dir.values(), length, extrudeSurface.normal()); } finishExtrusion(); *************** *** 289,304 **** } ! // /** ! // * Invoked when a key has been pressed. ! // * @param e The KeyEvent ! // */ ! // public void keyPressed(KeyEvent e) { ! // /*a length can only be typed in if some surface is selected ! // for extrusion, and if the "number"-variable has been initialised ! // */ ! // super.keyPressed(e); ! // if (extrudeSurface != null && number != null) { ! // if (e.getKeyCode() == KeyEvent.VK_1) { ! // number += "1"; // } else if (e.getKeyCode() == KeyEvent.VK_2) { // number += "2"; --- 428,465 ---- } ! /** ! * Invoked when a key has been pressed. ! * @param e The KeyEvent ! */ ! public void keyPressed(KeyEvent e) { ! /*a length can only be typed in if some surface is selected ! for extrusion, and if the "number"-variable has been initialised ! */ ! if ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) == KeyEvent.CTRL_DOWN_MASK) { ! controlled = !controlled; ! log.info("Controlle pressed"); ! } ! if ((e.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) == KeyEvent.ALT_DOWN_MASK) { ! extrudeAll = false; ! log.info("Alt pressed"); ! } ! super.keyPressed(e); ! } ! ! /** ! * Invoked when a key has been pressed. ! * @param e The KeyEvent ! */ ! public void keyReleased(KeyEvent e) { ! /*a length can only be typed in if some surface is selected ! for extrusion, and if the "number"-variable has been initialised ! */ ! if ((e.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) == KeyEvent.ALT_DOWN_MASK) { ! extrudeAll = true; ! log.info("Alt pressed"); ! } ! super.keyPressed(e); ! } ! } // } else if (e.getKeyCode() == KeyEvent.VK_2) { // number += "2"; *************** *** 348,352 **** // } // } ! // super.keyPressed(e); ! // } ! } --- 509,511 ---- // } // } ! |