[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool SelectTool.java,1.3,1.4
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-08-15 12:49:38
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17332 Modified Files: SelectTool.java Log Message: Added selection of surfaces in 2D Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SelectTool.java 5 Aug 2005 10:55:31 -0000 1.3 --- SelectTool.java 15 Aug 2005 12:49:31 -0000 1.4 *************** *** 25,28 **** --- 25,29 ---- import java.util.Iterator; import java.util.Set; + import java.util.List; import org.apache.log4j.Logger; *************** *** 81,85 **** selectedEdge.getId()); Notifier.getInstance().sendNotification(n); ! } if (selectedSurface != null) { Notification n = new Notification(Notification.SURFACE_DESELECTED, --- 82,86 ---- selectedEdge.getId()); Notifier.getInstance().sendNotification(n); ! } if (selectedSurface != null) { Notification n = new Notification(Notification.SURFACE_DESELECTED, *************** *** 90,118 **** int x = e.getX(); int y = e.getY(); View view = glv.getView(); double[] coords = view.toCanvasCoords(new double[]{x, y}); ! 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) { ! if (e.getClickCount() >= 2) { ! Set s = SurfaceFacade.getInstance().findByEdge(edge); ! Iterator i = s.iterator(); Surface sur = null; ! if (i.hasNext()) { ! sur = (Surface)i.next(); } - Notification n = new Notification(Notification.SURFACE_SELECTED, sur.getId()); - Notifier.getInstance().sendNotification(n); } - Notification n = new Notification(Notification.EDGE_SELECTED, edge.getId()); - Notifier.getInstance().sendNotification(n); } } } } /** --- 91,152 ---- int x = e.getX(); int y = e.getY(); + int viewType = 0; View view = glv.getView(); double[] coords = view.toCanvasCoords(new double[]{x, y}); ! double[] coordsx = view.toCanvasCoords(new double[] {x + 1, y}); ! double[] coordsy = view.toCanvasCoords(new double[] {x , y + 1}); ! if (coords[0] == 0 && coordsx[0] == 0 && coordsy[0] == 0) { ! viewType = View.VIEW_YZ; ! } ! if (coords[1] == 0 && coordsx[1] == 0 && coordsy[1] == 0) { ! viewType = View.VIEW_XZ; ! } ! if (coords[2] == 0 && coordsx[2] == 0 && coordsy[2] == 0) { ! viewType = View.VIEW_XY; ! } ! if (coords[0] == 0 && coords[1] == 0 && coords[2] == 0 && ! coordsx[0] == 0 && coordsx[1] == 0 && coordsx[2] == 0 && ! coordsy[0] == 0 && coordsy[1] == 0 && coordsy[2] == 0) { ! viewType = View.VIEW_3D; ! Edge edge = edgeCollide3D(x, y); if (edge != null) { ! Notification n = new Notification(Notification.EDGE_SELECTED, edge.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); } } } } } } + /** *************** *** 123,129 **** } ! /** ! * Check if this cordinate collide with an edge ! * @param coord The cordinate to check for collision at * @return The excisting edge on that coord, null if there ain't any */ --- 157,241 ---- } ! /** ! * 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 */ *************** *** 184,187 **** --- 296,315 ---- } + + /** + * Check if a point is over any edge in 3D. + * @param x the x coordinate of the point + * @param y the y coordinate of the point + * @return an Edge the point is over, null if no Edge is found + */ + protected Edge edgeCollide3D(double x, double y) { + View view = glv.getView(); + Long id = view.getObjectAtPoint(x, y); + if (id != null) { + return EdgeFacade.getInstance().findById(id); + } + return null; + } + /** * Handle a notification |