[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ExtrusionTool.java, 1.57, 1.58
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-05-15 11:36:27
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15902/src/net/sourceforge/bprocessor/gl/tool Modified Files: ExtrusionTool.java Log Message: made a total refacture of extrusiontool to make it extrude selected surfaces and selected edges as well as non selected ones. A doubleclick now repeat the extrusion, could be handy Index: ExtrusionTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrusionTool.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** ExtrusionTool.java 9 May 2007 09:32:38 -0000 1.57 --- ExtrusionTool.java 15 May 2007 11:36:27 -0000 1.58 *************** *** 19,22 **** --- 19,23 ---- 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; *************** *** 95,131 **** space.changed(); } - - /** - * Extrude - * @param distance double - * @param all Extrude all - * @param finish Finish extrusion - */ - private void extrude(double distance, boolean all, boolean finish) { - Space space = Project.getInstance().getActiveSpace(); - if (extrusion != null) { - space.removeProtected(extrusion); - space.computeNextId(); - extrusion = null; - } - extrusion = new LinkedList<Surface>(); - Collection<Surface> sides = new LinkedList<Surface>(); - Set<Surface> tops = new HashSet<Surface>(); - 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 { - space.addProtected(extrusion); - } - } /** --- 96,99 ---- *************** *** 145,161 **** Collection<Surface> sides = new LinkedList<Surface>(); Set<Surface> tops = new HashSet<Surface>(); if (p == null) { ! log.info("Found null plane"); ! return; ! } ! if (all) { ! extrudesurface.extrusionAllOnto(p, sides, tops); ! extrusion.addAll(sides); ! extrusion.addAll(tops); } else { ! Surface top = extrudesurface.extrusionOnto(p, sides); ! extrusion.add(top); ! extrusion.addAll(sides); } if (finish) { insert(space, extrusion); --- 113,136 ---- Collection<Surface> sides = new LinkedList<Surface>(); Set<Surface> tops = new HashSet<Surface>(); + Surface top = null; if (p == null) { ! // just extrude the distance ! if (all) { ! extrudesurface.extrusionall(distance, sides, tops); ! } else { ! top = extrudesurface.extrusion(distance, sides); ! extrusion.add(top); ! } } else { ! // extrude to the plane ! if (all) { ! extrudesurface.extrusionAllOnto(p, sides, tops); ! } else { ! top = extrudesurface.extrusionOnto(p, sides); ! extrusion.add(top); ! } } + extrusion.addAll(sides); + extrusion.addAll(tops); if (finish) { insert(space, extrusion); *************** *** 196,321 **** */ protected void moved(MouseEvent e) { ! if (Selection.primary().isEmpty()) { ! // extrude surface ! if (extrudesurface == null) { ! //the extrusion isn't started yet ! findTarget(e); ! if (target instanceof Surface) { ! glv.getView().makeTarget(target); ! } else if (target == null) { ! glv.getView().makeTarget(null); ! } ! active = true; ! ! } else { ! // a extrudesurface have been chosen ! to = glv.getView().toPlaneCoords(e.getX(), e.getY(), dragplane); ! Vertex normal = extrudesurface.normal(); ! //a bit cleanup ! ontoPlane = null; ! // the list of all extruded geometric objects ! Set<Geometric> elements = new HashSet<Geometric>(); ! if (extrusion != null) { ! elements.addAll(extrusion); ! elements.addAll(Surface.edges(extrusion)); ! elements.add(extrudesurface); ! } ! //ignore the extruded surface and holes when extruding ! Set<Surface> ignore = new HashSet<Surface>(2); ! ignore.add(extrudesurface); ! if (extrudesurface.getExterior() != null) { ! ignore.add(extrudesurface.getExterior()); ! } ! findTarget(e, ignore); ! { ! if (target instanceof Surface && extrusion != null && !extrusion.contains(target)) { ! Surface surface = (Surface) target; ! if (!elements.contains(surface)) { ! Vertex n = surface.normal(); ! Vertex cross = normal.cross(n); ! if (cross.isZero()) { ! // the surfaces are coplanar ! Vertex v = surface.getFirstVertex(); ! if (!extrudesurface.plane().contains(v)) { ! to = v; ! } calcDistCallExtrude(to, from, normal); } else { ! ontoPlane = surface.plane(); ! if (Math.abs(ontoPlane.normal().dot(normal)) <= 0.1) { ! // the two normals have a greater angle between 0 and 84 or 94 and 180 degrees ! calcDistCallExtrude(to, from, normal); ! } else { ! extrudeOnto(ontoPlane, all, false); ! } } } ! } else if (target instanceof Edge) { ! Edge edge = (Edge) target; ! if (!elements.contains(edge)) { ! to = edge.center(); ! Vertex v = edge.center(); ! if (!extrudesurface.plane().contains(v)) { ! to = v; ! } } - calcDistCallExtrude(to, from, normal); - } else { - calcDistCallExtrude(to, from, normal); } } } ! } else { ! //The extrusion should be found in the selection (EDGE EXTRUSION) ! if (extrudeEdges != null) { ! // the extrusion should begin ! to = glv.getView().toPlaneCoords(e.getX(), e.getY(), dragplane); ! ! //list of moving elements ! Set<Geometric> elements = new HashSet<Geometric>(extrudeEdges); ! if (extrusion != null) { ! elements.addAll(extrusion); ! elements.addAll(Surface.edges(extrusion)); ! } ! ! // ignore the extruded surface and holes when extruding ! List<Geometric> ignore = new LinkedList<Geometric>(extrudeEdges); ! if (extrusion != null) { ! ignore.addAll(extrusion); ! ignore.addAll(Surface.edges(extrusion)); ! ignore.addAll(Geometry.collect(extrusion)); ! } ! excluded(ignore); ! current = findIntersection(e); ! if (e.isShiftDown()) { to = current.vertex(); ! } ! findTarget(e, ignore); ! updateConstructors(); ! log.info("Target is " + target); ! if (target != null && !elements.contains(target)) { ! if (target instanceof Surface) { ! ontoPlane = ((Surface) target).plane(); ! makeTarget(current); ! } else if (target instanceof Plane && target != plane) { ! ontoPlane = (Plane)target; ! makeTarget(current); ! } else if (target instanceof Line || ! target instanceof Constructor || ! target instanceof Edge) { ! to = current.vertex(); ! makeTarget(current); ! ontoPlane = null; ! } else { ! ontoPlane = null; ! } } else { ontoPlane = null; } - distance = to.minus(from).length(); - extrudeEdgesOnto(ontoPlane, false); } else { ! current = findIntersection(e); ! makeTarget(current); } } --- 171,298 ---- */ protected void moved(MouseEvent e) { ! if (extrudesurface != null) { ! // a extrudesurface have been chosen ! to = glv.getView().toPlaneCoords(e.getX(), e.getY(), dragplane); ! Vertex normal = extrudesurface.normal(); ! //a bit cleanup ! ontoPlane = null; ! // the list of all extruded geometric objects ! Set<Geometric> elements = new HashSet<Geometric>(); ! if (extrusion != null) { ! elements.addAll(extrusion); ! elements.addAll(Surface.edges(extrusion)); ! elements.add(extrudesurface); ! } ! //ignore the extruded surface and holes when extruding ! Set<Surface> ignore = new HashSet<Surface>(2); ! ignore.add(extrudesurface); ! if (extrudesurface.getExterior() != null) { ! ignore.add(extrudesurface.getExterior()); ! } ! findTarget(e, ignore); ! { ! if (target instanceof Surface && extrusion != null && !extrusion.contains(target)) { ! Surface surface = (Surface) target; ! if (!elements.contains(surface)) { ! Vertex n = surface.normal(); ! Vertex cross = normal.cross(n); ! if (cross.isZero()) { ! // the surfaces are coplanar ! Vertex v = surface.getFirstVertex(); ! if (!extrudesurface.plane().contains(v)) { ! to = v; ! } ! calcDistCallExtrude(to, from, normal); ! } else { ! ontoPlane = surface.plane(); ! if (Math.abs(ontoPlane.normal().dot(normal)) <= 0.1) { ! // the two normals have a greater angle between 0 and 84 or 94 and 180 degrees calcDistCallExtrude(to, from, normal); } else { ! extrudeOnto(ontoPlane, all, false); } } ! } ! } else if (target instanceof Edge) { ! Edge edge = (Edge) target; ! if (!elements.contains(edge)) { ! Vertex v = edge.center(); ! if (!extrudesurface.plane().contains(v)) { ! to = v; } } + calcDistCallExtrude(to, from, normal); + } else if (target instanceof Vertex) { + if (!elements.contains(target)) { + to = (Vertex)target; + } + calcDistCallExtrude(to, from, normal); + } else { + calcDistCallExtrude(to, from, normal); } } ! } else if (extrudeEdges != null) { ! // make the extrusion of edges ! to = glv.getView().toPlaneCoords(e.getX(), e.getY(), dragplane); ! ! //list of moving elements ! Set<Geometric> elements = new HashSet<Geometric>(extrudeEdges); ! if (extrusion != null) { ! elements.addAll(extrusion); ! elements.addAll(Surface.edges(extrusion)); ! } ! ! // ignore the extruded surface and holes when extruding ! List<Geometric> ignore = new LinkedList<Geometric>(extrudeEdges); ! if (extrusion != null) { ! ignore.addAll(extrusion); ! ignore.addAll(Surface.edges(extrusion)); ! ignore.addAll(Geometry.collect(extrusion)); ! } ! excluded(ignore); ! current = findIntersection(e); ! if (e.isShiftDown()) { ! to = current.vertex(); ! } ! findTarget(e, ignore); ! updateConstructors(); ! if (target != null && !elements.contains(target)) { ! if (target instanceof Surface) { ! ontoPlane = ((Surface) target).plane(); ! makeTarget(current); ! } else if (target instanceof Plane && target != plane) { ! ontoPlane = (Plane)target; ! makeTarget(current); ! } else if (target instanceof Line || ! target instanceof Constructor || ! target instanceof Edge) { to = current.vertex(); ! makeTarget(current); ! ontoPlane = null; } else { ontoPlane = null; } } else { ! ontoPlane = null; ! } ! distance = to.minus(from).length(); ! extrudeEdgesOnto(ontoPlane, false); ! } else { ! // do highlighting ! if (Selection.primary().isEmpty()) { ! //the extrusion isn't started yet ! findTarget(e); ! if (target instanceof Surface) { ! glv.getView().makeTarget(target); ! } else if (target == null) { ! glv.getView().makeTarget(null); ! } ! active = true; ! } else { ! Geometric g = Selection.primary().iterator().next(); ! if (Selection.primary().size() == 1 && ! g instanceof Surface) { ! target = g; ! } } } *************** *** 331,335 **** Vertex delta = to.minus(from); distance = normal.dot(delta); ! extrude(distance, all, false); } --- 308,312 ---- Vertex delta = to.minus(from); distance = normal.dot(delta); ! extrudeOnto(null, all, false); } *************** *** 339,420 **** */ protected void pressed(MouseEvent e) { ! if (!Selection.primary().isEmpty()) { ! if (extrudeEdges == null) { extrudeEdges = new ArrayList<Edge>(); for (Object o : Selection.primary()) { if (o instanceof Edge) { extrudeEdges.add((Edge) o); } else { extrudeEdges.clear(); } } ! if (extrudeEdges.size() != Selection.primary().size()) { extrudeEdges = null; ! GUI.getInstance().alert("Either no selection or a selection" + ! " only consisting of edges are possible"); } else { ! 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 = new Plane(0, 0, 1, extrudeEdges.get(0).getFrom()); ! dragplane = plane.orthogonalPlane(ray); ! active = true; ! start = findIntersection(e); ! from = start.vertex(); ! } ! } else { ! if (extrusion != null) { ! if (ontoPlane != null) { ! extrudeEdgesOnto(ontoPlane, true); ! } else { ! extrudeEdgesOnto(null, true); } } ! extrusion = null; ! Project.getInstance().checkpoint(); ! cleanUp(); ! } ! } else { ! 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(startx, starty, dragplane); - all = !e.isAltDown(); } else { GUI.getInstance().alert(target + " ain't extrudeable only Surfaces are"); } ! } else { if (extrusion != null) { if (ontoPlane != null) { ! extrudeOnto(ontoPlane, all, true); } else { ! extrude(distance, all, true); } - extrusion = null; - Project.getInstance().checkpoint(); } ! cleanUp(); ! moved(e); } } } --- 316,428 ---- */ protected void pressed(MouseEvent e) { ! if (e.getClickCount() > 1 && extrusion == null) { ! // do a extrusion of the same length once more ! if (extrudesurface != null) { ! extrudeOnto(ontoPlane, true, true); ! } else if (extrudeEdges != null) { ! extrudeEdgesOnto(ontoPlane, true); ! } ! } ! ! if (start == null) { ! // initialize the extrusion ! if (!Selection.primary().isEmpty()) { ! //find the selected object to extrude extrudeEdges = new ArrayList<Edge>(); for (Object o : Selection.primary()) { if (o instanceof Edge) { extrudeEdges.add((Edge) o); + } else if (o instanceof Surface) { + findTarget(e); + if (target == o) { + extrudesurface = (Surface)o; + } } else { extrudeEdges.clear(); + extrudesurface = null; + break; } } ! if (extrudeEdges.isEmpty()) { extrudeEdges = null; ! if (extrudesurface == null) { ! GUI.getInstance().alert("Either select a conected set of edges or a single surface" + ! " to extrude or select nothing and extrude surfaces"); ! } } else { ! if (extrudesurface != null) { ! // there were both edges and surfaces in the selection ! extrudesurface = null; ! extrudeEdges = null; ! GUI.getInstance().alert("Different geometrics in a selection ain't extrudeable"); } } ! } else { ! //find the target to extrude findTarget(e); if (target instanceof Surface) { extrudesurface = (Surface) target; } else { GUI.getInstance().alert(target + " ain't extrudeable only Surfaces are"); } ! } ! // Do initialization ! if (extrudeEdges != null) { ! 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 = new Plane(0, 0, 1, extrudeEdges.get(0).getFrom()); ! dragplane = plane.orthogonalPlane(ray); ! active = true; ! start = findIntersection(e); ! from = start.vertex(); ! } else if (extrudesurface != null) { ! 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(startx, starty, dragplane); ! start = new Intersection(from, Intersection.SURFACE, extrudesurface); ! all = !e.isAltDown(); ! active = true; ! } ! } else { ! // stop the extrusion ! if (extrudeEdges != null) { if (extrusion != null) { if (ontoPlane != null) { ! extrudeEdgesOnto(ontoPlane, true); } else { ! extrudeEdgesOnto(null, true); } } ! } else if (extrudesurface != null) { ! if (extrusion != null) { ! extrudeOnto(ontoPlane, all, true); ! } ! } else { ! //something weird happend ! log.error("Got into a finalize state without initialization of either edges or surface"); } + extrusion = null; + Selection.primary().clear(); + Project.getInstance().checkpoint(); + cleanUp(); + moved(e); } } *************** *** 425,429 **** @Override public void onVertex() { ! } --- 433,437 ---- @Override public void onVertex() { ! // Overrides apply so no need for any action in onVertex } *************** *** 438,442 **** length = -length; } ! extrude(length, all, true); } else if (extrudeEdges != null) { if (to != null) { --- 446,451 ---- length = -length; } ! distance = length; ! extrudeOnto(null, all, true); } else if (extrudeEdges != null) { if (to != null) { *************** *** 479,483 **** all = false; dragplane = null; ! ontoPlane = null; from = null; to = null; --- 488,493 ---- all = false; dragplane = null; ! //keep for repeat ! //ontoPlane = null; from = null; to = null; *************** *** 485,489 **** Project.getInstance().getActiveSpace().removeProtected(extrusion); Project.getInstance().getActiveSpace().computeNextId(); ! Project.getInstance().getActiveSpace().changed(); extrusion = null; } --- 495,499 ---- Project.getInstance().getActiveSpace().removeProtected(extrusion); Project.getInstance().getActiveSpace().computeNextId(); ! //Project.getInstance().getActiveSpace().changed(); extrusion = null; } |