[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool TapeMeasureTool.java,NONE,1.1
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-11-29 18:59:52
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27336 Added Files: TapeMeasureTool.java Log Message: tape measure tool, first draft --- NEW FILE: TapeMeasureTool.java --- //--------------------------------------------------------------------------------- // $Id: TapeMeasureTool.java,v 1.1 2005/11/29 18:59:40 nordholt 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.model.Edge; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.AbstractView; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.gl.GLView; import org.apache.log4j.Logger; /** * The TapeMeasureTool */ public class TapeMeasureTool extends AbstractTool { /** The logger */ private static Logger log = Logger.getLogger(TapeMeasureTool.class); /** The current edge */ private Edge currentEdge; /** The current construction edge */ private Edge currentConstruction; /** The edge point */ private Vertex edgePoint; /** The construction edge point */ private Vertex constructionPoint; /** The the edge between the current edge and the construction edge */ private Edge edgeToConstruction; /** The plane we are moving in */ private Plane movePlane; /** The edge normal */ private Vertex edgeNormal; /** * Constructor * @param glv The GLView * @param cursor The cursor */ public TapeMeasureTool(GLView glv, Cursor cursor) { super(glv, cursor); } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ protected void moved(MouseEvent e) { if (currentEdge != null) { if (movePlane == null) { findTarget(e); if (target instanceof Surface) { Surface targetSurface = (Surface)target; glv.getView().makeTarget(target); movePlane = targetSurface.plane(); Vertex edgeDirection = currentEdge.getTo().minus(currentEdge.getFrom()); Vertex surfaceNormal = targetSurface.normal(); edgeNormal = edgeDirection.cross(surfaceNormal); edgeNormal.scale(1 / edgeNormal.length()); double x = e.getX(); double y = AbstractView.getHeight() - e.getY(); View v = glv.getView(); Transformation transformation = v.transformation(); 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 = transformation.unProject(ray); Vertex intersect = movePlane.intersection(ray); Vertex delta = intersect.minus(constructionPoint); edgeNormal.scale(edgeNormal.dot(delta) / (edgeNormal.length() * edgeNormal.length())); currentConstruction.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); constructionPoint.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); } } else { edgeNormal.scale(1 / edgeNormal.length()); double x = e.getX(); double y = AbstractView.getHeight() - e.getY(); View v = glv.getView(); Transformation transformation = v.transformation(); 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 = transformation.unProject(ray); Vertex intersect = movePlane.intersection(ray); Vertex delta = intersect.minus(constructionPoint); edgeNormal.scale(edgeNormal.dot(delta) / (edgeNormal.length() * edgeNormal.length())); currentConstruction.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); constructionPoint.move(edgeNormal.getX(), edgeNormal.getY(), edgeNormal.getZ()); } } } /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ protected void dragged(MouseEvent e) { } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ protected void pressed(MouseEvent e) { findTarget(e); if (currentEdge == null) { if (target instanceof Edge) { currentEdge = (Edge)target; Vertex constructionFrom = createVertex(currentEdge.getFrom().copy()); Vertex constructionTo = createVertex(currentEdge.getTo().copy()); currentConstruction = createEdge(constructionFrom, constructionTo); currentConstruction.setConstructor(true); double x = e.getX(); double y = AbstractView.getHeight() - e.getY(); View v = glv.getView(); Transformation transformation = v.transformation(); 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 = transformation.unProject(ray); Edge intersection = currentEdge.intersection(ray); edgePoint = createVertex(intersection.getFrom()); constructionPoint = createVertex(edgePoint.copy()); edgeToConstruction = new Edge("lengthEdge", edgePoint, constructionPoint); } } else { currentEdge = null; currentConstruction = null; movePlane = null; edgeToConstruction = null; removeVertex(edgePoint); removeVertex(constructionPoint); } } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ protected void released(MouseEvent e) { } } |