Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view AbstractView.java,1.2,1.3
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-08-05 11:06:20
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1390 Modified Files: AbstractView.java Log Message: added notification and drawing of selected surfaces Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbstractView.java 4 Aug 2005 10:49:55 -0000 1.2 --- AbstractView.java 5 Aug 2005 11:06:11 -0000 1.3 *************** *** 9,12 **** --- 9,15 ---- import net.sourceforge.bprocessor.kernel.notification.Notification; + import net.sourceforge.bprocessor.gl.tool.Util; + import net.sourceforge.bprocessor.gl.GLView; + import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.EdgeFacade; *************** *** 14,17 **** --- 17,21 ---- import net.sourceforge.bprocessor.model.VertexFacade; import net.sourceforge.bprocessor.model.Surface; + import net.sourceforge.bprocessor.model.SurfaceFacade; import java.util.Iterator; *************** *** 22,27 **** import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; - import net.java.games.jogl.GLUquadric; - import net.java.games.jogl.util.GLUT; import org.apache.log4j.Logger; --- 26,29 ---- *************** *** 51,54 **** --- 53,59 ---- public static final double[] GRID_COLOR = new double[] {0.85, 0.85, 0.85}; + /** Used for selected objects */ + public static final double[] SELECTED_COLOR = new double[] {1.0, 0.4, 1.0}; + /** The view transformation matrix (it is shown transposed) see p. 187 [GL BIBLE]*/ protected static double[] viewTrans = new double[] {1.0, 0.0, 0.0, 0.0, *************** *** 84,87 **** --- 89,98 ---- protected static Vertex selectedVertex = null; + /** The selected edge */ + protected static Edge selectedEdge = null; + + /** The selected surface */ + protected static Surface selectedSurface = null; + /** The GL */ protected GL gl = null; *************** *** 89,92 **** --- 100,114 ---- /** The zoomFactor in the parent view */ protected double zoomFactor = 1.0; + + /** The GLView */ + protected GLView glv = null; + + /** + * The constructor + * @param glv The glview + */ + public AbstractView(GLView glv) { + this.glv = glv; + } /** *************** *** 164,168 **** GL gl = gld.getGL(); GLU glu = gld.getGLU(); - GLUT glut = new GLUT(); Iterator it = edges.iterator(); --- 186,189 ---- *************** *** 219,232 **** } ! // draw selection if (selectedVertex != null) { ! gl.glColor3d(0.0, 1.0, 0.0); ! gl.glPushMatrix(); ! gl.glTranslated(selectedVertex.getX(), selectedVertex.getY(), selectedVertex.getZ()); ! GLUquadric quad = glu.gluNewQuadric(); ! glu.gluQuadricDrawStyle(quad, GLU.GLU_FILL); ! glu.gluSphere(quad, 0.3, 15, 15); ! glu.gluDeleteQuadric(quad); ! gl.glPopMatrix(); } } --- 240,271 ---- } ! // draw selected vertex if (selectedVertex != null) { ! gl.glColor3dv(SELECTED_COLOR); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); ! selectedVertex = VertexFacade.getInstance().findById(selectedVertex.getId()); ! gl.glVertex3d(selectedVertex.getX(), selectedVertex.getY(), selectedVertex.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); ! } ! ! // draw selected edge ! if (selectedEdge != null) { ! gl.glColor3dv(SELECTED_COLOR); ! selectedEdge = EdgeFacade.getInstance().findById(selectedEdge.getId()); ! Vertex to = selectedEdge.getTo(); ! Vertex from = selectedEdge.getFrom(); ! gl.glBegin(GL.GL_LINES); ! gl.glVertex3d(to.getX(), to.getY(), to.getZ()); ! gl.glVertex3d(from.getX(), from.getY(), from.getZ()); ! gl.glEnd(); ! } ! ! // draw selected surface ! if (selectedSurface != null) { ! gl.glColor3dv(SELECTED_COLOR); ! selectedSurface = SurfaceFacade.getInstance().findById(selectedSurface.getId()); ! drawSurface(selectedSurface); } } *************** *** 237,245 **** */ private void drawSurface(Surface s) { ! List edges = s.getEdges(); ! Iterator it = edges.iterator(); ! while (it.hasNext()) { ! Edge e = (Edge)it.next(); ! drawEdge(e); } } --- 276,287 ---- */ private void drawSurface(Surface s) { ! List l = Util.traverse(s); ! if (l != null) { ! gl.glBegin(GL.GL_POLYGON); ! for (int i = 0; i < l.size(); i++) { ! Vertex v = (Vertex)l.get(i); ! gl.glVertex3d(v.getX(), v.getY(), v.getZ()); ! } ! gl.glEnd(); } } *************** *** 367,370 **** --- 409,421 ---- /** + * Return the distance on the canvas matching the given double + * @param dist The window coordinates + * @return The relative distance + */ + public double toCanvasDistance(double dist) { + return 2 * size * aspect * zoomFactor * (dist / height); + } + + /** * Handle a notification * @param n The notification *************** *** 373,377 **** --- 424,439 ---- if (n.getType().equals(Notification.VERTEX_SELECTED)) { selectedVertex = VertexFacade.getInstance().findById(n.getObject()); + } else if (n.getType().equals(Notification.VERTEX_DESELECTED)) { + selectedVertex = null; + } else if (n.getType().equals(Notification.EDGE_SELECTED)) { + selectedEdge = EdgeFacade.getInstance().findById(n.getObject()); + } else if (n.getType().equals(Notification.EDGE_DESELECTED)) { + selectedEdge = null; + } else if (n.getType().equals(Notification.SURFACE_SELECTED)) { + selectedSurface = SurfaceFacade.getInstance().findById(n.getObject()); + } else if (n.getType().equals(Notification.SURFACE_DESELECTED)) { + selectedSurface = null; } + glv.repaint(); } *************** *** 382,388 **** */ public boolean isNotificationEnabled(String type) { ! if (type.equals(Notification.VERTEX_SELECTED)) { return true; ! } return false; } --- 444,455 ---- */ public boolean isNotificationEnabled(String type) { ! if (type.equals(Notification.VERTEX_SELECTED) || ! type.equals(Notification.VERTEX_DESELECTED) || ! type.equals(Notification.EDGE_SELECTED) || ! type.equals(Notification.EDGE_DESELECTED) || ! type.equals(Notification.SURFACE_SELECTED) || ! type.equals(Notification.SURFACE_DESELECTED)) { return true; ! } return false; } |