[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool MultiExtrudeTool.java,1.16,1.17
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-05-01 09:59:12
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2342/src/net/sourceforge/bprocessor/gl/tool Modified Files: MultiExtrudeTool.java Log Message: Changed the tool to use abstract pencil instead of abstracttool. Ther are still many fixes to be made Index: MultiExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MultiExtrudeTool.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** MultiExtrudeTool.java 19 Apr 2006 16:16:25 -0000 1.16 --- MultiExtrudeTool.java 1 May 2006 09:59:00 -0000 1.17 *************** *** 9,17 **** import java.awt.Cursor; - import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; --- 9,18 ---- import java.awt.Cursor; import java.awt.event.MouseEvent; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; + import java.util.LinkedList; + import java.util.Map; import java.util.Set; *************** *** 21,29 **** 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.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; --- 22,27 ---- import net.sourceforge.bprocessor.gl.GLView; ! import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.model.Direction; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selection; *************** *** 34,43 **** * The ExtrudeTool */ ! public class MultiExtrudeTool extends AbstractTool { /** The logger */ private static Logger log = Logger.getLogger(MultiExtrudeTool.class); ! /** The dragSurface and extrudeSurface */ ! private Surface top, extrudeSurface; /** The surfaces to extrude */ --- 32,41 ---- * The ExtrudeTool */ ! public class MultiExtrudeTool extends AbstractPencil { /** The logger */ private static Logger log = Logger.getLogger(MultiExtrudeTool.class); ! /** The extrudeSurface */ ! private Surface extrudeSurface; /** The surfaces to extrude */ *************** *** 46,55 **** /** A vertex-direction map */ private Map v2dir; - - /** The Plane to draw in */ - private Plane dragPlane; - - /** The previous coordinate */ - private int pressX, pressY; /** The previous position of the drag */ --- 44,47 ---- *************** *** 61,70 **** /** The extrusion direction */ private double direction = 0.0; - - /** The length of the extrusion */ - private String number; - - /** The normal to drag along */ - private Vertex normal; /** --- 53,56 ---- *************** *** 75,79 **** --- 61,72 ---- public MultiExtrudeTool(GLView glv, Cursor cursor) { super(glv, cursor); + start = null; + t = 0; number = ""; + extrudeSurface = null; + direction = 0.0; + v2dir = null; + elements = new HashSet(); + surfaces = new HashSet(); } *************** *** 83,112 **** */ protected void pressed(MouseEvent e) { ! findTarget(e); ! t = 0; ! number = ""; ! extrudeSurface = null; ! direction = 0.0; ! normal = null; ! cleanUp(); ! if (target instanceof Surface) { ! if (Selection.primary().isEmpty() || Selection.primary().contains(target)) { ! extrudeSurface = (Surface)target; ! surfaces.addAll(Selection.primary()); ! surfaces.add(extrudeSurface); ! View view = glv.getView(); ! Transformation trans = view.transformation(); ! pressX = e.getX(); ! pressY = e.getY(); ! double x = pressX; ! double y = View.getHeight() - pressY; ! 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); ! dragPlane = extrudeSurface.plane().orthogonalPlane(ray); ! normal = extrudeSurface.normal().copy(); ! normal.scale(-1); } } } --- 76,101 ---- */ 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)) { ! extrudeSurface = (Surface)target; ! surfaces.addAll(Selection.primary()); ! surfaces.add(extrudeSurface); ! Vertex normal = extrudeSurface.normal().copy(); ! normal.scale(-1); ! lock = true; ! locked = normal; ! } } + } else { + if (v2dir != null && Math.abs(t) < 0.1) { + deleteExtrusion(); + return; + } else if (v2dir != null) { + finishExtrusion(); + } + cleanUp(); } } *************** *** 117,209 **** */ protected void dragged(MouseEvent e) { ! if (extrudeSurface != null) { ! // it is possible to make an extrusion find the direction ! View view = glv.getView(); ! Vertex from = view.toPlaneCoords(new double[] {pressX, pressY}, dragPlane); ! Vertex to = view.toPlaneCoords(new double[] {e.getX(), e.getY()}, dragPlane); ! double normDotDelta = 0.0; ! if (to != null && from != null) { ! Vertex delta = to.minus(from); ! normDotDelta = normal.dot(delta); ! } ! if (v2dir == null) { ! direction = normDotDelta; ! elements = makeExtrusion(); ! } ! if (v2dir != null) { ! // The extrusion were succesfull move it ! // Find the move direction ! Set ignore = new HashSet(); ! if (elements != null) { ! ignore.addAll(elements); ! Iterator iter = elements.iterator(); ! while (iter.hasNext()) { ! Surface sur = (Surface)iter.next(); ! ignore.addAll(sur.getEdges()); ! } ! } ! ignore.add(extrudeSurface); ! ignore.removeAll(extrudeSurface.getEdges()); ! findTarget(e, ignore); ! if (target != null) { ! if (target instanceof Surface) { ! //If there are a target that is a surface drag to that surface ! Vertex origin = extrudeSurface.getFirstVertex(); ! Surface current = (Surface) target; ! if (current != top && !elements.contains(current)) { ! Vertex n = current.normal(); ! Vertex cross = normal.cross(n); ! if (cross.isZero()) { ! Vertex cur = current.getFirstVertex(); ! Vertex vector = cur.minus(origin); ! double d = vector.dot(normal); ! moveTo(v2dir.values(), d); ! } ! } ! } else if (target instanceof Edge) { ! Edge tar = (Edge)target; ! Vertex ver = (tar).center(); ! Vertex origin = extrudeSurface.getFirstVertex(); ! if (!ignore.contains(tar)) { ! Vertex vector = ver.minus(origin); ! double d = vector.dot(normal); ! moveTo(v2dir.values(), d); ! } ! } ! } else { ! // otherwise do a normal extrude ! if (direction * normDotDelta > 0) { ! // the extrusion is still in the same direction ! moveTo(v2dir.values(), normDotDelta); ! } else { ! // we have to remove the extrusion and make a new one ! direction = normDotDelta; ! remove(elements); ! elements = makeExtrusion(); ! if (v2dir != null) { ! moveTo(v2dir.values(), normDotDelta); ! } ! } ! } ! } ! } } /** ! * 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(); ! } } /** --- 106,139 ---- */ protected void dragged(MouseEvent e) { ! current = findIntersection(e); ! makeTarget(current); } /** ! * Deletes the extrusion ! * */ ! 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(); + // } + // } /** *************** *** 211,218 **** */ public void cleanUp() { ! top = null; v2dir = null; elements = new HashSet(); surfaces = new HashSet(); } --- 141,153 ---- */ public void cleanUp() { ! start = null; ! t = 0; ! number = ""; ! extrudeSurface = null; ! direction = 0.0; v2dir = null; elements = new HashSet(); surfaces = new HashSet(); + super.cleanUp(); } *************** *** 224,229 **** while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! holeAnalysis(current); } Project.getInstance().changed(Project.getInstance()); Project.getInstance().checkpoint(); --- 159,167 ---- while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! if (current != null) { ! holeAnalysis(current); ! } } + cleanUp(); Project.getInstance().changed(Project.getInstance()); Project.getInstance().checkpoint(); *************** *** 254,279 **** */ protected void released(MouseEvent e) { - findTarget(e); - if (top != null && Math.abs(t) < 0.1) { - remove(elements); - return; - } else if (v2dir != null) { - finishExtrusion(); - } } /** ! * Make the extrusion from either a set of surfaces ! * @return the elements created for extrusion */ ! private Set makeExtrusion() { ! Collection c; ! if (Selection.primary().size() == 0) { ! c = new HashSet(); ! c.add(extrudeSurface); ! } else { ! c = Selection.primary(); ! } ! Set elements = new HashSet(); Map e2e = new HashMap(); // edge to edge map Map e2s = new HashMap(); // edge to surface map --- 192,206 ---- */ protected void released(MouseEvent e) { } /** ! * Make the extrusion from the given list of surfaces ! * @param c The collection of surfaces to extrude ! * @param direction The direction to extrude in ! * @return True if the surface were extruded */ ! 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 *************** *** 285,289 **** while (iter.hasNext()) { if (!(iter.next() instanceof Surface)) { ! return null; } } --- 212,216 ---- while (iter.hasNext()) { if (!(iter.next() instanceof Surface)) { ! return false; } } *************** *** 292,303 **** Surface cur = (Surface)iter.next(); Surface s = cur.extrude(-direction, elements, e2e, v2e, e2s, v2dir); - if (cur == extrudeSurface) { - // Set the top to the extruded surface of target - top = s; - } elements.add(s); } t = 0; ! return elements; } --- 219,226 ---- Surface cur = (Surface)iter.next(); Surface s = cur.extrude(-direction, elements, e2e, v2e, e2s, v2dir); elements.add(s); } t = 0; ! return true; } *************** *** 306,410 **** */ protected void moved(MouseEvent e) { ! findTarget(e); ! if (target instanceof Surface) { ! glv.getView().makeTarget(target); ! } else { ! glv.getView().makeTarget(null); } } /** ! * Log an object ! * @param message Object to log */ ! public static void info(Object message) { ! log.info(message); } /** ! * Apply extrusion ! * @param length The length */ ! private void apply(double length) { ! if (length != 0.0 && extrudeSurface != null) { ! if (direction * length <= 0.0) { ! direction = length; ! log.info("Changed dir to: " + direction); ! remove(elements); ! cleanUp(); ! } if (v2dir != null) { moveTo(v2dir.values(), length); } else { ! elements = makeExtrusion(); moveTo(v2dir.values(), length); } finishExtrusion(); - } else { - remove(elements); - cleanUp(); } } ! /** ! * 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"; ! } else if (e.getKeyCode() == KeyEvent.VK_3) { ! number += "3"; ! } else if (e.getKeyCode() == KeyEvent.VK_4) { ! number += "4"; ! } else if (e.getKeyCode() == KeyEvent.VK_5) { ! number += "5"; ! } else if (e.getKeyCode() == KeyEvent.VK_6) { ! number += "6"; ! } else if (e.getKeyCode() == KeyEvent.VK_7) { ! number += "7"; ! } else if (e.getKeyCode() == KeyEvent.VK_8) { ! number += "8"; ! } else if (e.getKeyCode() == KeyEvent.VK_9) { ! number += "9"; ! } else if (e.getKeyCode() == KeyEvent.VK_0) { ! number += "0"; ! } else if (e.getKeyCode() == KeyEvent.VK_MINUS) { ! if (number.equals("")) { ! number += "-"; ! } ! } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { ! if (!number.equals("")) { ! double length = glv.getLength(); ! apply(length); ! glv.repaint(); ! number = ""; ! } ! } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { ! int length = number.length(); ! if (length > 0) { ! number = number.substring(0, length - 1); ! } ! } ! } ! ! if (number.equals("") || number.equals("-")) { ! glv.setLength(0); ! } else { ! try { ! double d = Double.parseDouble(number); ! glv.setLength(d / 1000); ! } catch (NumberFormatException exp) { ! System.out.println(exp); ! } ! } ! super.keyPressed(e); ! } } --- 229,352 ---- */ protected void moved(MouseEvent e) { ! current = findIntersection(e); ! makeTarget(current); ! if (start != null) { ! // do the shit ! modifyExtrusion(); } } /** ! * Do the appropiate changes to the extrusion */ ! private void modifyExtrusion() { ! if (extrudeSurface != null) { ! // it is possible to make an extrusion find the direction ! Vertex from = start.vertex(); ! Vertex to = current.vertex(); ! double normDotDelta = 0.0; ! if (to != null && from != null) { ! Vertex delta = to.minus(from); ! 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) { ! direction = normDotDelta; ! deleteExtrusion(); ! makeExtrusion(surfaces, direction); ! } ! moveTo(v2dir.values(), normDotDelta); ! } ! } } /** ! * Called when enter have been pressed */ ! public void onVertex() { ! if (start != null && current != null) { ! double length = (current.vertex().minus(start.vertex())).length(); if (v2dir != null) { + if (direction * length < 0) { + //the direction have changed + direction = length; + deleteExtrusion(); + makeExtrusion(surfaces, direction); + } moveTo(v2dir.values(), length); } else { ! direction = length; ! makeExtrusion(surfaces, direction); moveTo(v2dir.values(), length); } finishExtrusion(); } } ! // /** ! // * 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"; ! // } else if (e.getKeyCode() == KeyEvent.VK_3) { ! // number += "3"; ! // } else if (e.getKeyCode() == KeyEvent.VK_4) { ! // number += "4"; ! // } else if (e.getKeyCode() == KeyEvent.VK_5) { ! // number += "5"; ! // } else if (e.getKeyCode() == KeyEvent.VK_6) { ! // number += "6"; ! // } else if (e.getKeyCode() == KeyEvent.VK_7) { ! // number += "7"; ! // } else if (e.getKeyCode() == KeyEvent.VK_8) { ! // number += "8"; ! // } else if (e.getKeyCode() == KeyEvent.VK_9) { ! // number += "9"; ! // } else if (e.getKeyCode() == KeyEvent.VK_0) { ! // number += "0"; ! // } else if (e.getKeyCode() == KeyEvent.VK_MINUS) { ! // if (number.equals("")) { ! // number += "-"; ! // } ! // } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { ! // if (!number.equals("")) { ! // double length = glv.getLength(); ! // apply(length); ! // glv.repaint(); ! // number = ""; ! // } ! // } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { ! // int length = number.length(); ! // if (length > 0) { ! // number = number.substring(0, length - 1); ! // } ! // } ! // } ! // ! // if (number.equals("") || number.equals("-")) { ! // glv.setLength(0); ! // } else { ! // try { ! // double d = Double.parseDouble(number); ! // glv.setLength(d / 1000); ! // } catch (NumberFormatException exp) { ! // System.out.println(exp); ! // } ! // } ! // super.keyPressed(e); ! // } } |