[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool AbstractTool.java,1.53,1.54 PencilTool
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-01-25 10:02:19
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25269/src/net/sourceforge/bprocessor/gl/tool Modified Files: AbstractTool.java PencilTool.java ExtrudeTool.java TapeMeasureTool.java SelectTool.java Log Message: code cleanup Index: TapeMeasureTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/TapeMeasureTool.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TapeMeasureTool.java 26 Dec 2005 15:09:04 -0000 1.6 --- TapeMeasureTool.java 25 Jan 2006 10:02:09 -0000 1.7 *************** *** 12,15 **** --- 12,16 ---- import net.sourceforge.bprocessor.model.Edge; + import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; *************** *** 296,301 **** movePlane = null; edgeToConstruction = null; ! removeVertex(edgePoint); ! removeVertex(constructionPoint); measuring = false; } --- 297,302 ---- movePlane = null; edgeToConstruction = null; ! Project.getInstance().remove(edgePoint); ! Project.getInstance().remove(constructionPoint); measuring = false; } Index: ExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrudeTool.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ExtrudeTool.java 23 Jan 2006 10:16:22 -0000 1.7 --- ExtrudeTool.java 25 Jan 2006 10:02:09 -0000 1.8 *************** *** 142,150 **** private void apply(double length) { if (top != null) { ! deleteSurface(top); Iterator iter = sides.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! deleteSurface(current); } sides = null; --- 142,150 ---- private void apply(double length) { if (top != null) { ! Project.getInstance().delete(top); Iterator iter = sides.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! Project.getInstance().delete(current); } sides = null; *************** *** 254,263 **** if (Math.abs(t) < 0.0000001) { if (top != null) { ! deleteSurface(top); top = null; Iterator iter = sides.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! deleteSurface(current); } sides = null; --- 254,263 ---- if (Math.abs(t) < 0.0000001) { if (top != null) { ! Project.getInstance().delete(top); top = null; Iterator iter = sides.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! Project.getInstance().delete(current); } sides = null; Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** SelectTool.java 11 Jan 2006 12:05:33 -0000 1.51 --- SelectTool.java 25 Jan 2006 10:02:09 -0000 1.52 *************** *** 11,14 **** --- 11,15 ---- import net.sourceforge.bprocessor.model.Edge; + import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; *************** *** 156,167 **** Object selected = it.next(); if (selected instanceof Surface) { ! Surface selectedSurface = (Surface)selected; ! deleteSurface(selectedSurface); } else if (selected instanceof Edge) { ! Edge selectedEdge = (Edge)selected; ! deleteEdge(selectedEdge); } else if (selected instanceof Vertex) { ! deleteVertex((Vertex) selected); ! } else if (selected instanceof ClippingPlane) { glv.getView().removeClippingPlane((ClippingPlane)selected); } --- 157,166 ---- Object selected = it.next(); if (selected instanceof Surface) { ! Project.getInstance().delete((Surface)selected); } else if (selected instanceof Edge) { ! Project.getInstance().delete((Edge)selected); } else if (selected instanceof Vertex) { ! Project.getInstance().delete((Vertex) selected); ! } else if (selected instanceof ClippingPlane) { glv.getView().removeClippingPlane((ClippingPlane)selected); } *************** *** 169,173 **** selection.clear(); glv.getView().makeTarget(null); - glv.repaint(); } else { super.keyPressed(e); --- 168,171 ---- Index: PencilTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/PencilTool.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** PencilTool.java 24 Jan 2006 14:10:32 -0000 1.58 --- PencilTool.java 25 Jan 2006 10:02:09 -0000 1.59 *************** *** 671,680 **** if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { if (active != null) { ! deleteEdge(active); } Iterator it = edges.iterator(); while (it.hasNext()) { Edge edge = (Edge)it.next(); ! deleteEdge(edge); } edges = null; --- 671,680 ---- if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { if (active != null) { ! Project.getInstance().delete(active); } Iterator it = edges.iterator(); while (it.hasNext()) { Edge edge = (Edge)it.next(); ! Project.getInstance().delete(edge); } edges = null; Index: AbstractTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractTool.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** AbstractTool.java 24 Jan 2006 14:10:32 -0000 1.53 --- AbstractTool.java 25 Jan 2006 10:02:09 -0000 1.54 *************** *** 62,74 **** private static int dy = 0; - /** An vertex counter */ - protected static long vertexNum = 1; - - /** An edge counter */ - protected static long edgeNum = 1; - - /** An surface counter */ - protected static long surfaceNum = 1; - /** The snap variable */ protected static final double EPSILON = 0.4; --- 62,65 ---- *************** *** 375,410 **** /** - * @return The x distance the mouse has moved since press - */ - protected int getdx() { - return dx; - } - - /** - * @return The y distance the mouse has moved since press - */ - protected int getdy() { - return dy; - } - - /** - * Take a coordinate and check if it should snap to grid - * @param coords The coordinates to check for snapping - * @return the snapped coordinates - */ - protected double[] snapToGrid(double[] coords) { - if (Math.abs(coords[0] - Math.round(coords[0])) < EPSILON) { - coords[0] = Math.round(coords[0]); - } - if (Math.abs(coords[1] - Math.round(coords[1])) < EPSILON) { - coords[1] = Math.round(coords[1]); - } - if (Math.abs(coords[2] - Math.round(coords[2])) < EPSILON) { - coords[2] = Math.round(coords[2]); - } - return coords; - } - - /** * Make and register a new vertex * @param coord The coordinates to create with --- 366,369 ---- *************** *** 413,425 **** protected Vertex createVertex(double[] coord) { if (coord.length == 3) { ! Vertex v = new Vertex(); ! vertexNum++; ! ! v.setX(coord[0]); ! v.setY(coord[1]); ! v.setZ(coord[2]); ! Project.getInstance().add(v); ! ! return v; } else { log.error("[createVertex] wrong argument length was: " + coord.length); --- 372,378 ---- protected Vertex createVertex(double[] coord) { if (coord.length == 3) { ! Vertex vertex = new Vertex(coord[0], coord[1], coord[2]); ! Project.getInstance().add(vertex); ! return vertex; } else { log.error("[createVertex] wrong argument length was: " + coord.length); *************** *** 427,472 **** } } - - /** - * Make and register a new vertex - * @param vertex The vertex - * @return The registered Vertex - */ - protected Vertex createVertex(Vertex vertex) { - if (vertex != null) { - Vertex v = new Vertex(vertex.getX(), - vertex.getY(), - vertex.getZ()); - Project.getInstance().add(v); - return v; - } else { - log.warn("attempted to create null vertex"); - return null; - } - } - - /** - * Update the coordinates of the vertex v - * @param v The vertex to change coordinates on - * @param coord The new coordinates - */ - protected void updateVertex(Vertex v, double[] coord) { - if (coord.length == 3) { - v.setX(coord[0]); - v.setY(coord[1]); - v.setZ(coord[2]); - v.changed(); - } else { - log.error("[updateVertex] wrong argument length was: " + coord.length); - } - } - - /** - * Remove a vertex for good - * @param v Vertex to remove - */ - protected void removeVertex(Vertex v) { - Project.getInstance().remove(v); - } /** --- 380,383 ---- *************** *** 477,574 **** */ protected Edge createEdge(Vertex from, Vertex to) { ! Edge e = new Edge(); ! e.setTo(to); ! e.setFrom(from); ! Project.getInstance().add(e); ! return e; ! } ! ! /** ! * Remove a edge for good ! * @param e Edge to remove ! */ ! protected void removeEdge(Edge e) { ! Project.getInstance().remove(e); ! } ! ! /** ! * Updates the edge ! * @param e The edge to update ! */ ! protected void updateEdge(Edge e) { ! e.changed(); } /** * Make and register a new Surface ! * @param list The list of edges in the surface * @return The new Surface */ ! protected Surface createSurface(List list) { ! Surface s = new Surface(list); ! Project.getInstance().add(s); ! return s; ! } ! ! /** ! * Remove a Surface for good ! * @param s Surface to remove ! */ ! protected void removeSurface(Surface s) { ! Project.getInstance().remove(s); ! } ! ! /** ! * Deletes a surface and its edges if it is safe to do so. ! * @param surface the surface to delete ! */ ! protected void deleteSurface(Surface surface) { ! if (surface.getExterior() != null) { ! Surface exterior = surface.getExterior(); ! exterior.removeHole(surface); ! } ! removeSurface(surface); ! List edges = surface.getEdges(); ! Iterator it = edges.iterator(); ! while (it.hasNext()) { ! Edge edge = (Edge)it.next(); ! if (edge.getSurfaces().size() < 1) { ! deleteEdge(edge); ! } ! } ! glv.repaint(); ! } ! ! /** ! * Deletes an edge and it's endpoint vertecies if it is safe to do so. ! * @param edge the edge to delete ! */ ! protected void deleteEdge(Edge edge) { ! if (edge.getId() != null) { ! Set surfaces = edge.getSurfaces(); ! removeEdge(edge); ! Iterator it = surfaces.iterator(); ! while (it.hasNext()) { ! Surface surf = (Surface)it.next(); ! deleteSurface(surf); ! } ! deleteVertex(edge.getTo()); ! deleteVertex(edge.getFrom()); ! glv.repaint(); ! } ! } ! ! /** ! * Deletes a vertex if it is safe to do so. ! * @param vertex the vertex to delete ! */ ! protected void deleteVertex(Vertex vertex) { ! if (vertex.getId() != null) { ! Set edges = vertex.getEdges(); ! if (edges.size() < 1) { ! removeVertex(vertex); ! glv.repaint(); ! } ! } } --- 388,405 ---- */ protected Edge createEdge(Vertex from, Vertex to) { ! Edge edge = new Edge(from, to); ! Project.getInstance().add(edge); ! return edge; } /** * Make and register a new Surface ! * @param edges The list of edges in the surface * @return The new Surface */ ! protected Surface createSurface(List edges) { ! Surface surface = new Surface(edges); ! Project.getInstance().add(surface); ! return surface; } |