Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool AbstractTool.java,1.60,1.61 PencilTool
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2006-03-07 22:31:12
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18504/src/net/sourceforge/bprocessor/gl/tool Modified Files: AbstractTool.java PencilTool.java MoveTool.java Log Message: Implemented general mechanism for finding point in model (vertex, point on edge, point on surface, edge intersection, surface/edge intersection, edge midpoint) Index: MoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MoveTool.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** MoveTool.java 6 Mar 2006 06:51:52 -0000 1.42 --- MoveTool.java 7 Mar 2006 22:31:04 -0000 1.43 *************** *** 373,384 **** delta = restrictCopy; } else if (moveMode == FREE_SNAP) { ! List objects = glv.getView().getObjectAtPoint(e.getX(), e.getY(), moveEntities, false); ! Iterator it = objects.iterator(); ! if (it.hasNext()) { ! Object o = it.next(); ! if (o != null) { ! snapEntity = (Entity)o; ! delta = findInitial(snapEntity, e).minus(from); ! } } } else if (moveMode == CONTROLLED) { --- 373,380 ---- delta = restrictCopy; } else if (moveMode == FREE_SNAP) { ! Object o = glv.getView().getObjectAtPoint(e.getX(), e.getY(), moveEntities, false); ! if (o != null) { ! snapEntity = (Entity)o; ! delta = findInitial(snapEntity, e).minus(from); } } else if (moveMode == CONTROLLED) { *************** *** 419,434 **** glv.getView().addTempSurface(hitSurface2); glv.getView().addTempSurface(hitSurface3); ! List objects = glv.getView().getObjectAtPoint(e.getX(), e.getY()); ! Iterator it = objects.iterator(); ! while (it.hasNext()) { ! Object ob = it.next(); ! if (ob instanceof Surface) { ! Surface surface = (Surface)ob; ! if (surface.equals(hitSurface1) || ! surface.equals(hitSurface2) || ! surface.equals(hitSurface3)) { ! dragPlane = surface.plane(); ! restrictionVector = new Vertex(0, 0, 0); ! } } } --- 415,426 ---- glv.getView().addTempSurface(hitSurface2); glv.getView().addTempSurface(hitSurface3); ! Object ob = glv.getView().getObjectAtPoint(e.getX(), e.getY()); ! if (ob instanceof Surface) { ! Surface surface = (Surface)ob; ! if (surface.equals(hitSurface1) || ! surface.equals(hitSurface2) || ! surface.equals(hitSurface3)) { ! dragPlane = surface.plane(); ! restrictionVector = new Vertex(0, 0, 0); } } Index: PencilTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/PencilTool.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** PencilTool.java 6 Mar 2006 06:51:52 -0000 1.61 --- PencilTool.java 7 Mar 2006 22:31:04 -0000 1.62 *************** *** 11,15 **** import java.awt.event.KeyEvent; import java.util.ArrayList; - import java.util.Collection; import java.util.List; import java.util.Set; --- 11,14 ---- *************** *** 17,23 **** 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.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Plane; --- 16,21 ---- import net.sourceforge.bprocessor.gl.GLView; ! import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Plane; *************** *** 25,29 **** import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; - import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Geometry; --- 23,26 ---- *************** *** 68,74 **** protected Vertex snapVertex = null; - /** The exterior Surface is a Surface, where a hole is being defined */ - protected Surface exterior = null; - /** The candidates are the Set of surfaces that could be the exterior * for a hole being defined. --- 65,68 ---- *************** *** 100,109 **** int y = event.getY(); View view = glv.getView(); ! List selection = view.getObjectAtPoint(x, y, new HashSet(), true); ! if (selection.isEmpty()) { target = null; ! } else { ! target = selection.get(0); } } --- 94,125 ---- int y = event.getY(); View view = glv.getView(); ! Intersection intersection = (Intersection) view.getObjectAtPoint(x, y, new HashSet(), true); ! current = intersection.vertex(); ! switch (intersection.type()) { ! case Intersection.VERTEX: ! target = current; ! setSnapVertex(current); ! break; ! case Intersection.EDGE: ! target = intersection.object(); ! break; ! case Intersection.SURFACE: ! target = intersection.object(); ! break; ! case Intersection.EDGE_MIDPOINT: ! target = current; ! setSnapVertex(current); ! break; ! case Intersection.EDGE_INTERSECTION: ! target = current; ! break; ! case Intersection.SURFACE_INTERSECTION: ! target = current; ! break; ! case Intersection.PLANE_INTERSECTION: target = null; ! break; } + view.makeTarget(target); } *************** *** 390,394 **** setAlignVertex(null); setSnapVertex(null); - exterior = null; currentPlane = null; } --- 406,409 ---- *************** *** 434,450 **** /** - * Round to grid - * @param value The value - * @return The rounded value - */ - protected double round(double value) { - if (Math.abs(value - Math.round(value)) < 0.3) { - return Math.round(value); - } else { - return ((double) Math.round(value * 1000)) / 1000.0; - } - } - - /** * Set current vertex to an appropriate vertex * @param event The MouseEvent --- 449,452 ---- *************** *** 453,548 **** protected boolean findVertex(MouseEvent event) { boolean legal = true; ! boolean snap = false; ! double x = event.getX(); ! double y = View.getHeight() - event.getY(); ! View v = glv.getView(); ! Transformation transformation = v.transformation(); ! Vertex near = new Vertex(x, y, 0.0); ! Vertex far = new Vertex(x, y, 1.0); ! Edge ray = new Edge(near, far); ! ray = transformation.unProject(ray); ! CoordinateSystem system = null; ! ! if (target != null) { ! if (target instanceof Vertex) { ! current = (Vertex) target; ! } ! if (target instanceof Surface) { ! Surface surface = (Surface) target; ! Plane plane = surface.plane(); ! Vertex vertex = plane.intersection(ray); ! system = surface.coordinateSystem(); ! current = vertex; ! if (active != null) { ! if (exterior != null) { ! legal = (target == exterior); ! } else { ! exterior = (Surface) target; ! legal = true; ! } ! } ! if (exterior != null) { ! system = exterior.coordinateSystem(); ! } ! } ! if (target instanceof Edge) { ! Edge edge = (Edge) target; ! Edge intersection = edge.intersection(ray); ! Vertex vertex = intersection.getFrom(); ! current = vertex; ! } ! } else { ! Plane xy = new Plane(0, 0, 1, 0); ! Vertex vertex = xy.intersection(ray); ! snap = true; ! if (vertex != null) { ! // FIXME The plane intersection should take care ! // of the following round off ! vertex.setZ(0.0); ! current = vertex; ! } else { ! // just to take an initial bug ! current = new Vertex(0, 0, 0); ! } ! } ! if (current.getId() == null) { ! if (snap) { ! Vertex origin = new Vertex(0, 0, 0); ! Vertex i = new Vertex(1, 0, 0); ! Vertex j = new Vertex(0, 1, 0); ! Vertex n = new Vertex(0, 0, 1); ! system = new CoordinateSystem(i, j, n, origin); ! //snapInSystem(system, current); ! } else { ! if (legal) { ! if (system != null) { ! //snapInSystem(system, current); ! } ! } ! } ! Set vertices = Project.getInstance().findByLocation ! (current.getX(), current.getY(), current.getZ(), 0.0); ! if (!vertices.isEmpty()) { ! //current = (Vertex) vertices.iterator().next(); ! } ! } ! ! /* ! * Should disallow you to draw out of the current plane if ! * you allready have two or more edges. Thus disallowing you ! * to draw non-plane surfaces. ! */ ! if (legal && ! currentPlane != null && ! edges != null && ! edges.size() > 1) { ! double[] planeRep = currentPlane.getDoublev(); ! if (Math.abs(current.getX() * planeRep[0] + ! current.getY() * planeRep[1] + ! current.getZ() * planeRep[2] + ! planeRep[3]) > 0.00001) { ! legal = false; ! } ! } return legal; } --- 455,459 ---- protected boolean findVertex(MouseEvent event) { boolean legal = true; ! current = (Vertex) target; return legal; } *************** *** 554,562 **** protected void pressed(MouseEvent e) { findPencilTarget(e); ! glv.getView().makeTarget(target); ! boolean legal = findVertex(e); ! if (legal) { ! onVertex(current); ! } } /** --- 465,469 ---- protected void pressed(MouseEvent e) { findPencilTarget(e); ! onVertex(current); } /** *************** *** 566,588 **** protected void moved(MouseEvent e) { findPencilTarget(e); ! glv.getView().makeTarget(target); ! if (target != null) { ! if (target instanceof Vertex) { ! Vertex vertex = (Vertex) target; ! if (vertex.getId() != null) { ! setSnapVertex(vertex); ! } ! } ! } ! boolean clear = (exterior == null); ! boolean legal = findVertex(e); ! if (clear) { ! exterior = null; ! } ! if (legal) { ! glv.getView().setCurrentVertex(current); ! } else { ! glv.getView().setCurrentVertex(current); ! } /** Show the length of the active edge */ if (active != null) { --- 473,477 ---- protected void moved(MouseEvent e) { findPencilTarget(e); ! glv.getView().setCurrentVertex(current); /** Show the length of the active edge */ if (active != null) { *************** *** 619,623 **** protected void released(MouseEvent e) { findPencilTarget(e); - glv.getView().makeTarget(target); } --- 508,511 ---- *************** *** 658,662 **** setAlignVertex(null); setSnapVertex(null); - exterior = null; glv.repaint(); } else if (e.getKeyCode() == KeyEvent.VK_1) { --- 546,549 ---- *************** *** 752,772 **** } } - } - - /** - * Find the space we did draw in - * @param s The surface to check for the location of - * @return The Space - */ - private Space findSpace(Surface s) { - Collection set = Project.getInstance().getFunctionalSpaces(); - Iterator it = set.iterator(); - while (it.hasNext()) { - Space fs = (Space)it.next(); - if (fs.getName().equals("Ext")) { - return fs; - } - } - return null; } --- 639,642 ---- Index: AbstractTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractTool.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** AbstractTool.java 1 Mar 2006 11:16:17 -0000 1.60 --- AbstractTool.java 7 Mar 2006 22:31:03 -0000 1.61 *************** *** 583,592 **** int y = event.getY(); View view = glv.getView(); ! List selection = view.getObjectAtPoint(x, y); ! if (selection.isEmpty()) { ! target = null; ! } else { ! target = selection.get(0); ! } } --- 583,587 ---- int y = event.getY(); View view = glv.getView(); ! target = view.getObjectAtPoint(x, y); } |