Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool MultiExtrudeTool.java,1.15,1.16
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-04-19 16:16:30
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19195/src/net/sourceforge/bprocessor/gl/tool Modified Files: MultiExtrudeTool.java Log Message: Repaired the tool to assign the spaces correct and use negative extrusions in one of the directions.... Index: MultiExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MultiExtrudeTool.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** MultiExtrudeTool.java 5 Apr 2006 10:23:27 -0000 1.15 --- MultiExtrudeTool.java 19 Apr 2006 16:16:25 -0000 1.16 *************** *** 21,25 **** 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; --- 21,24 ---- *************** *** 39,45 **** private static Logger log = Logger.getLogger(MultiExtrudeTool.class); - /** Point based snapping? */ - private static final boolean SNAPPING = false; - /** The dragSurface and extrudeSurface */ private Surface top, extrudeSurface; --- 38,41 ---- *************** *** 68,71 **** --- 64,70 ---- /** The length of the extrusion */ private String number; + + /** The normal to drag along */ + private Vertex normal; /** *************** *** 85,95 **** protected void pressed(MouseEvent e) { findTarget(e); - extrudeSurface = null; - top = null; t = 0; - v2dir = null; - elements = new HashSet(); number = ""; ! if (target instanceof Surface) { if (Selection.primary().isEmpty() || Selection.primary().contains(target)) { --- 84,93 ---- 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)) { *************** *** 108,111 **** --- 106,111 ---- ray = trans.unProject(ray); dragPlane = extrudeSurface.plane().orthogonalPlane(ray); + normal = extrudeSurface.normal().copy(); + normal.scale(-1); } } *************** *** 119,199 **** if (extrudeSurface != null) { // it is possible to make an extrusion find the direction - Vertex normal; - if (top == null) { - normal = extrudeSurface.normal(); - } else { - normal = top.normal(); - } View view = glv.getView(); Vertex from = view.toPlaneCoords(new double[] {pressX, pressY}, dragPlane); ! Vertex to; ! if (SNAPPING) { ! Set ignore = new HashSet(); ! if (elements != null) { ! ignore.addAll(elements); ! } ! ignore.add(extrudeSurface); ! ignore.addAll(extrudeSurface.getEdges()); ! Intersection intersection = ! (Intersection) view.getObjectAtPoint(e.getX(), e.getY(), ignore, true, dragPlane); ! if (intersection == null || intersection.type() == Intersection.SURFACE) { ! to = view.toPlaneCoords(new double[] {e.getX(), e.getY()}, dragPlane); ! } else { ! to = intersection.vertex(); ! } ! } else { ! to = view.toPlaneCoords(new double[] {e.getX(), e.getY()}, dragPlane); ! } ! Vertex delta = to.minus(from); ! double normDotDelta = normal.dot(delta); ! if (Math.abs(normDotDelta) < 0.000001) { ! normDotDelta = 0; } ! ! if (direction == 0) { ! //we have never set the direction; direction = normDotDelta; } ! if (top == null) { ! // there are no extrusion make one if we move the mouse ! if ((e.getX() - pressX) * (e.getX() - pressX) + ! (e.getY() - pressY) * (e.getY() - pressY) > 16) { ! direction = normDotDelta; ! elements = makeExtrusion(); ! } ! } ! if (!SNAPPING && v2dir != null) { // The extrusion were succesfull move it // Find the move direction ! findTarget(e, elements); ! if (target != null && 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 != extrudeSurface && 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); ! if (Math.abs(d) > 0.0000001) { moveTo(v2dir.values(), d); - return; } } } - } - // 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 ! remove(elements); ! elements = makeExtrusion(); ! direction = normDotDelta; ! if (v2dir != null) { moveTo(v2dir.values(), normDotDelta); } } --- 119,187 ---- 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); + } } } *************** *** 215,221 **** } } } } ! /** * Move a collection of vertex, direction pairs --- 203,233 ---- } } + cleanUp(); } } ! ! /** ! * Clean up after use ! */ ! public void cleanUp() { ! top = null; ! v2dir = null; ! elements = new HashSet(); ! surfaces = new HashSet(); ! } ! ! /** ! * Finish of the extrusion ! */ ! private void finishExtrusion() { ! Iterator iter = elements.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! holeAnalysis(current); ! } ! Project.getInstance().changed(Project.getInstance()); ! Project.getInstance().checkpoint(); ! } ! /** * Move a collection of vertex, direction pairs *************** *** 234,238 **** } t = to; ! glv.setLength(Math.abs(t)); } --- 246,250 ---- } t = to; ! glv.setLength(t); } *************** *** 247,260 **** return; } else if (v2dir != null) { ! Iterator iter = elements.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! holeAnalysis(current); ! } ! Project.getInstance().changed(Project.getInstance()); ! Project.getInstance().checkpoint(); } } ! /** * Make the extrusion from either a set of surfaces --- 259,266 ---- return; } else if (v2dir != null) { ! finishExtrusion(); } } ! /** * Make the extrusion from either a set of surfaces *************** *** 285,289 **** while (iter.hasNext()) { 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 --- 291,295 ---- while (iter.hasNext()) { 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 *************** *** 321,333 **** */ private void apply(double length) { ! if (v2dir != null) { ! moveTo(v2dir.values(), length); } else { ! makeExtrusion(); ! moveTo(v2dir.values(), length); ! } ! Iterator iter = elements.iterator(); ! while (iter.hasNext()) { ! holeAnalysis((Surface)(iter.next())); } } --- 327,347 ---- */ 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(); } } *************** *** 363,366 **** --- 377,384 ---- } 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("")) { *************** *** 368,371 **** --- 386,390 ---- apply(length); glv.repaint(); + number = ""; } } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { |