Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ExtrudeTool.java,NONE,1.1 PencilTool.j
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2005-12-05 07:56:58
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10503/src/net/sourceforge/bprocessor/gl/tool Modified Files: PencilTool.java ToolFactory.java Added Files: ExtrudeTool.java Log Message: - Colors depend on space-assignment - Space assigned when making holes - Improved pencils usage of constructor lines - Started refactoring of extrusion --- NEW FILE: ExtrudeTool.java --- //--------------------------------------------------------------------------------- // $Id: ExtrudeTool.java,v 1.1 2005/12/05 07:56:50 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.tool; import java.awt.Cursor; import java.awt.event.MouseEvent; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.AbstractView; import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * The ExtrudeTool */ public class ExtrudeTool extends SelectTool { /** The dragSurface */ private Surface dragSurface; /** The extrudeSurface */ private Surface extrudeSurface; /** The dragplane */ private Plane dragplane; /** The previous x-coordinate */ private double prevX; /** The previous y-coordinate */ private double prevY; /** current distance from start along normal t */ private double t = 0; /** * Direction (1 or -1) */ private int direction = 0; /** * Constructor * @param glv THe GLCanvas * @param cursor The cursor */ public ExtrudeTool(GLView glv, Cursor cursor) { super(glv, cursor); } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ protected void pressed(MouseEvent e) { t = 0.0; prevX = e.getX(); prevY = e.getY(); super.pressed(e); if (target instanceof Surface) { extrudeSurface = (Surface) target; View view = glv.getView(); Transformation trans = view.transformation(); double x = prevX; double y = AbstractView.getHeight() - prevY; Vertex near = new Vertex("near", x, y, 0.0); Vertex far = new Vertex("far", x, y, 1.0); Edge ray = new Edge("ray", near, far); ray = trans.unProject(ray); dragplane = extrudeSurface.plane().orthogonalPlane(ray); } } /** * Moves the extrusion a given offset in the direction of the normal. * @param delta the offset. */ private void move(double delta) { if (dragSurface != null) { Vertex normal = dragSurface.normal(); normal.scale(1 / normal.length()); normal.scale(delta / (normal.length() * normal.length())); dragSurface.move(normal.getX(), normal.getY(), normal.getZ()); } } /** * Move to to * @param to A distance a long the normal */ private void moveTo(double to) { if (direction > 0) { if (to < 0) { to = 0; } } else { if (to > 0) { to = 0; } } double delta = to - t; move(delta); t = to; } /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ protected void dragged(MouseEvent e) { if (extrudeSurface != null) { Vertex normal; if (dragSurface == null) { normal = extrudeSurface.normal(); } else { normal = dragSurface.normal(); } normal.scale(1 / normal.length()); View view = glv.getView(); Vertex from = view.toPlaneCoords(new double[] {prevX, prevY}, dragplane); Vertex to = view.toPlaneCoords(new double[] {e.getX(), e.getY()}, dragplane); Vertex delta = to.minus(from); double normDotDelta = normal.dot(delta); double x = e.getX(); double y = e.getY(); if (dragSurface == null) { if (x * x + y * y > 16) { dragSurface = extrudeSurface.extrude(normDotDelta); t = -normDotDelta; if (t > 0) { direction = 1; } else { direction = -1; } } } else { moveTo(normDotDelta); } } } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ protected void released(MouseEvent e) { super.released(e); dragplane = null; dragSurface = null; } } Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ToolFactory.java 1 Dec 2005 10:10:02 -0000 1.17 --- ToolFactory.java 5 Dec 2005 07:56:50 -0000 1.18 *************** *** 41,45 **** /** extrusion tool */ ! private ExtrusionTool extrusion; /** pencil tool */ --- 41,45 ---- /** extrusion tool */ ! private SelectTool extrusion; /** pencil tool */ Index: PencilTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/PencilTool.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** PencilTool.java 1 Dec 2005 10:10:02 -0000 1.41 --- PencilTool.java 5 Dec 2005 07:56:50 -0000 1.42 *************** *** 108,114 **** target = e1; } else { ! target = intersect.getFrom(); ! splitE1 = e1; ! splitE2 = e2; } } else { --- 108,118 ---- target = e1; } else { ! if (intersect.getLength() > 0.0000001) { ! target = e1; ! } else { ! target = intersect.getFrom(); ! splitE1 = e1; ! splitE2 = e2; ! } } } else { *************** *** 182,186 **** setSnapVertex(null); number = ""; ! if (active == null) { edges = new ArrayList(); --- 186,198 ---- setSnapVertex(null); number = ""; ! ! { ! Set vertices = Project.getInstance().findByLocation ! (vertex.getX(), vertex.getY(), vertex.getZ(), 0.0000001); ! if (!vertices.isEmpty()) { ! vertex = (Vertex) vertices.iterator().next(); ! } ! } ! if (active == null) { edges = new ArrayList(); *************** *** 216,220 **** } if (vertex.getId() == null) { - //log.info("ID was null on " + vertex); intern(vertex); active.setTo(vertex); --- 228,231 ---- *************** *** 237,241 **** --- 248,267 ---- if (from == to) { Surface surface = new Surface("S" + surfaceNum++, edges); + + + Set surfaces = Project.getInstance().getSurfaces(); + Iterator iter = surfaces.iterator(); + while (iter.hasNext()) { + Surface current = (Surface) iter.next(); + if (current.surrounds(surface)) { + current.addHole(surface); + } else if (surface.surrounds(current)) { + surface.addHole(current); + } + } intern(surface); + + exterior = null; + if (exterior != null) { exterior.addHole(surface); *************** *** 244,258 **** } - // Do automation with spaces - Space sp = findSpace(surface); - if (sp != null) { - sp.addSurface(surface); - surface.setFrontDomain(sp); - surface.setBackDomain(sp); - Project.getInstance().update(surface); - Project.getInstance().update(sp); - } else { - //log.warn("No space was found"); - } } else { Geometry.insert(edges); --- 270,273 ---- *************** *** 434,438 **** snap = true; if (vertex != null) { ! vertex.setName("current"); current = vertex; } else { --- 449,456 ---- snap = true; if (vertex != null) { ! // FIXME The plane intersection should take care ! // of the following round off ! vertex.setZ(0.0); ! vertex.setName("xy-plane"); current = vertex; } else { |