Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool SelectTool.java,1.7,1.8
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-08-23 11:57:07
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8024 Modified Files: SelectTool.java Log Message: support for deleting surfaces and edges Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SelectTool.java 22 Aug 2005 14:30:59 -0000 1.7 --- SelectTool.java 23 Aug 2005 11:56:48 -0000 1.8 *************** *** 22,25 **** --- 22,26 ---- import java.awt.event.MouseEvent; + import java.awt.event.KeyEvent; import java.util.Iterator; *************** *** 91,95 **** Notifier.getInstance().sendNotification(n); } - int x = e.getX(); int y = e.getY(); --- 92,95 ---- *************** *** 111,168 **** coordsx[0] == 0 && coordsx[1] == 0 && coordsx[2] == 0 && coordsy[0] == 0 && coordsy[1] == 0 && coordsy[2] == 0) { - Object o; viewType = View.VIEW_3D; ! o = view.getObjectAtPoint(x, y); ! if (o instanceof Vertex) { ! Vertex vertex = (Vertex)o; ! Notification n = new Notification(Notification.VERTEX_SELECTED, vertex.getId()); ! Notifier.getInstance().sendNotification(n); ! } ! if (o instanceof Edge) { ! Edge edge = (Edge)o; ! Notification n = new Notification(Notification.EDGE_SELECTED, edge.getId()); ! Notifier.getInstance().sendNotification(n); ! } ! if (o instanceof Surface) { ! Surface surface = (Surface)o; Notification n = new Notification(Notification.SURFACE_SELECTED, surface.getId()); Notifier.getInstance().sendNotification(n); ! } ! ! } else { ! Vertex v = vertexCollide(coords); ! if (v != null) { ! Notification n = new Notification(Notification.VERTEX_SELECTED, v.getId()); Notifier.getInstance().sendNotification(n); - } else { - Edge edge = edgeCollide(coords); - if (edge != null) { - Surface sur = null; - if (e.getClickCount() >= 2) { - Set s = SurfaceFacade.getInstance().findByEdge(edge); - Iterator i = s.iterator(); - if (i.hasNext()) { - sur = (Surface)i.next(); - } - } - if (sur != null) { - Notification n = new Notification(Notification.SURFACE_SELECTED, sur.getId()); - Notifier.getInstance().sendNotification(n); - } else { - Notification n = new Notification(Notification.EDGE_SELECTED, edge.getId()); - Notifier.getInstance().sendNotification(n); - } - } else { - Surface surface = surfaceCollide(coords, viewType); - if (surface != null) { - Notification n = new Notification(Notification.SURFACE_SELECTED, surface.getId()); - Notifier.getInstance().sendNotification(n); - } - } } ! } ! } } - /** --- 111,135 ---- coordsx[0] == 0 && coordsx[1] == 0 && coordsx[2] == 0 && coordsy[0] == 0 && coordsy[1] == 0 && coordsy[2] == 0) { viewType = View.VIEW_3D; ! } ! Vertex v = vertexCollide(coords); ! if ((v != null) && (viewType != View.VIEW_3D)) { ! Notification n = new Notification(Notification.VERTEX_SELECTED, v.getId()); ! Notifier.getInstance().sendNotification(n); ! } else { ! Object selectObject; ! selectObject = view.getObjectAtPoint(x, y); ! if (selectObject instanceof Surface) { ! Surface surface = (Surface)selectObject; Notification n = new Notification(Notification.SURFACE_SELECTED, surface.getId()); Notifier.getInstance().sendNotification(n); ! } else if (selectObject instanceof Edge) { ! Edge edge = (Edge)selectObject; ! Notification n = new Notification(Notification.EDGE_SELECTED, edge.getId()); Notifier.getInstance().sendNotification(n); } ! } ! } } /** *************** *** 173,287 **** } - /** - * Check if this coordinate collides with an Surface - * @param coord The coordinate to check for collision at - * @param viewType The type of the view - * @return The excisting surface on that coord, null if there ain't any - */ - protected Surface surfaceCollide(double[] coord, int viewType) { - double x = 0; - double y = 0; - Set surfaces = SurfaceFacade.getInstance().findAll(); - Iterator surfaceIt = surfaces.iterator(); - while (surfaceIt.hasNext()) { - Surface s = (Surface)surfaceIt.next(); - List edgeSet = s.getEdges(); - int crossCount = 0; - Iterator edgeIt = edgeSet.iterator(); - while (edgeIt.hasNext()) { - Edge e = (Edge)edgeIt.next(); - boolean upCross = false; - boolean downCross = false; - double[] first = new double[]{0 , 0}; - double[] last = new double[]{0 , 0}; - double[] to = new double[]{0 , 0}; - double[] from = new double[]{0 , 0}; - if (viewType == View.VIEW_XY) { - to[0] = e.getTo().getX(); - to[1] = e.getTo().getY(); - from[0] = e.getFrom().getX(); - from[1] = e.getFrom().getY(); - x = coord[0]; - y = coord[1]; - } - if (viewType == View.VIEW_XZ) { - to[0] = e.getTo().getX(); - to[1] = e.getTo().getZ(); - from[0] = e.getFrom().getX(); - from[1] = e.getFrom().getZ(); - x = coord[0]; - y = coord[2]; - } - if (viewType == View.VIEW_YZ) { - to[0] = e.getTo().getZ(); - to[1] = e.getTo().getY(); - from[0] = e.getFrom().getZ(); - from[1] = e.getFrom().getY(); - x = coord[2]; - y = coord[1]; - } - if (to[0] < from[0]) { - first = to; - last = from; - } else { - first = from; - last = to; - } - if (first[1] < y && last[1] > y) { - upCross = true; - } else { - if (first[1] > y && last[1] < y) { - downCross = true; - } - } - double right = ((last[0] - first[0]) * (y - first[1]) - - (x - first[0]) * (last[1] - first[1])); - if (downCross && right > 0) { - crossCount++; - } - if (upCross && right < 0) { - crossCount++; - } - } - if (crossCount % 2 == 1) { - return s; - } - } - return null; - } - - /** - * Check if this coordinate collide with an edge - * @param coord The coordinate to check for collision at - * @return The excisting edge on that coord, null if there ain't any - */ - protected Edge edgeCollide(double[] coord) { - Set edges = EdgeFacade.getInstance().findAll(); - Iterator it = edges.iterator(); - while (it.hasNext()) { - Edge e = (Edge)it.next(); - double[] r = new double[] {e.getTo().getX() - e.getFrom().getX(), - e.getTo().getY() - e.getFrom().getY(), - e.getTo().getZ() - e.getFrom().getZ()}; - double[] ppo = new double[] {coord[0] - e.getFrom().getX(), - coord[1] - e.getFrom().getY(), - coord[2] - e.getFrom().getZ()}; - double normr = Math.abs(Math.sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2])); - double[] temp = new double[] {r[1] * ppo[2] - ppo[1] * r[2], - r[2] * ppo[0] - ppo[2] * r[0], - r[0] * ppo[1] - ppo[0] * r[1]}; - double t = Math.abs(Math.sqrt(temp[0] * temp[0] + - temp[1] * temp[1] + - temp[2] * temp[2])); - double normppo = Math.abs(Math.sqrt(ppo[0] * ppo[0] + ppo[1] * ppo[1] + ppo[2] * ppo[2])); - double rppo = r[0] * ppo[0] + r[1] * ppo[1] + r[2] * ppo[2]; - - if (t / normr < EPSILON && normppo <= normr && rppo > 0) { - return e; - } - } - return null; - } - /** * Check if this cordinate collide with another vertex --- 140,143 ---- *************** *** 311,315 **** return Math.abs(a - b) < EPSILON; } ! /** * Handle a notification --- 167,237 ---- return Math.abs(a - b) < EPSILON; } ! ! ! /** ! * Invoked when a key has been pressed. Lets user delete what is selected. ! * @param e The KeyEvent ! */ ! public void keyPressed(KeyEvent e) { ! if (e.getKeyCode() == KeyEvent.VK_DELETE) { ! if (selectedSurface != null) { ! Notification n = new Notification(Notification.SURFACE_DESELECTED, ! selectedSurface.getId()); ! Notifier.getInstance().sendNotification(n); ! deleteSurface(selectedSurface); ! } else if (selectedEdge != null) { ! if (selectedEdge.getSurfaces().size() < 1) { ! Notification n = new Notification(Notification.EDGE_DESELECTED, ! selectedEdge.getId()); ! Notifier.getInstance().sendNotification(n); ! deleteEdge(selectedEdge); ! } ! } ! } else { ! super.keyPressed(e); ! } ! } ! ! ! /** ! * Deletes a surface and its edges if it is safe to do so. ! * @param surface the surface to delete ! */ ! private void deleteSurface(Surface surface) { ! List edges = surface.getEdges(); ! Iterator it = edges.iterator(); ! Edge edge = null; ! removeSurface(surface); ! while (it.hasNext()) { ! edge = (Edge)it.next(); ! deleteEdge(edge); ! } ! ! } ! ! /** ! * Deletes an edge and it's endpoint vertecies if it is safe to do so. ! * @param edge the edge to delete ! */ ! private void deleteEdge(Edge edge) { ! Set surfaces = edge.getSurfaces(); ! if (surfaces.size() < 1) { ! removeEdge(edge); ! deleteVertex(edge.getTo()); ! deleteVertex(edge.getFrom()); ! } ! } ! ! /** ! * Deletes a vertex if it is safe to do so. ! * @param vertex the vertex to delete ! */ ! private void deleteVertex(Vertex vertex) { ! Set edges = vertex.getEdges(); ! if (edges.size() < 1) { ! removeVertex(vertex); ! } ! } ! /** * Handle a notification |