[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool EdgeMoveTool.java, NONE, 1.1 Tool.jav
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-03-22 11:47:07
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28888/src/net/sourceforge/bprocessor/gl/tool Modified Files: Tool.java ToolFactory.java Added Files: EdgeMoveTool.java Log Message: added a edgeMoveTool to the system, it is not done yet, need som bug fixing --- NEW FILE: EdgeMoveTool.java --- //--------------------------------------------------------------------------------- // $Id: EdgeMoveTool.java,v 1.1 2007/03/22 11:47:06 rimestad 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 java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Geometry; import net.sourceforge.bprocessor.model.Line; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Relation; import net.sourceforge.bprocessor.model.Selection; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * Alternative Move Tool */ public class EdgeMoveTool extends AbstractPencil { private Edge edge; private Plane dragplane; private Map<Surface, Collection<Vertex>> verticesMap; private Map<Vertex, Collection<Edge>> map; private HashMap<Surface, CoordinateSystem> coordMap; private HashMap<Surface, Line> swiwel; private Intersection previous; /** * @param glv GLView * @param cursor Cursor */ public EdgeMoveTool(GLView glv, Cursor cursor) { super(glv, cursor); } private void move(Vertex to, Vertex from) { if (to == null) { System.out.println("move-to null"); } else { for (Surface surface : coordMap.keySet()) { CoordinateSystem system = coordMap.get(surface); Vertex about = swiwel.get(surface).getOrigin(); Vertex v1 = to.minus(about); Vertex v2 = from.minus(about); double angle = v1.dot(v2); System.out.println("Angle were " + angle); system.rotate(angle, swiwel.get(surface)); for (Vertex vertex : verticesMap.get(surface)) { Vertex vector = system.getN(); Collection<Edge> binding = map.get(vertex); if (!binding.isEmpty()) { Edge bind = binding.iterator().next(); vector = bind.getDirection(); vector.normalize(); } Vertex project = system.slide(vertex, vector); vertex.set(project); } system.update(); } /* system.setOrigin(to); for (Vertex vertex : vertices) { Vertex vector = system.getN(); Collection<Edge> binding = map.get(vertex); if (!binding.isEmpty()) { Edge bind = binding.iterator().next(); vector = bind.getDirection(); vector.normalize(); } Vertex project = system.slide(vertex, vector); vertex.set(project); } system.update();*/ } } /** {@inheritDoc} */ @Override protected void moved(MouseEvent e) { List<Edge> edges = new LinkedList<Edge>(); if (coordMap == null) { findTarget(e, View.OBJECTS); glv.getView().makeTarget(target); } else { Vertex hit = glv.getView().toPlaneCoords(e.getX(), e.getY(), dragplane); previous = current; current = new Intersection(hit, Intersection.EDGE, null); Vertex from = start.vertex(); makeTarget(current); Vertex to = current.vertex(); Edge edge = new Edge(from, to); edge.setStrippled(true); edges.add(edge); move(to, previous.vertex()); } feedback(edges); } /** {@inheritDoc} */ @Override protected void pressed(MouseEvent e) { if (coordMap == null) { findTarget(e, View.OBJECTS); glv.getView().makeTarget(target); if (target instanceof Edge) { edge = (Edge) target; Set<Surface> surfaces = edge.getSurfaces(); verticesMap = new HashMap<Surface, Collection<Vertex>>(); coordMap = new HashMap<Surface, CoordinateSystem>(); swiwel = new HashMap<Surface, Line>(); Space space = edge.getOwner(); // find relations Collection<CoordinateSystem> systems = space.getCoordinateSystems(); for (CoordinateSystem current : systems) { Collection<Relation> relations = current.relations(); for (Relation relation : relations) { if (surfaces.contains(relation.geometric())) { coordMap.put((Surface)relation.geometric(), current); } } } // find rotation lines and vertices for (Surface surface : surfaces) { Vertex center = surface.oppositeVertex(edge); swiwel.put(surface, new Line(center, edge.getDirection())); verticesMap.put(surface, surface.getVertices()); } map = space.edgeMap(Geometry.collect(surfaces)); Selection.primary().set(edge); for (Surface surface : surfaces) { if (!coordMap.containsKey(surface)) { CoordinateSystem system = surface.coordinateSystem(); system.onlyPlane(true); system.setActive(true); coordMap.put(surface, system); } } } start = findIntersection(e); makeTarget(start); for (CoordinateSystem cs : coordMap.values()) { glv.getView().addTempConstructor(cs); } View view = glv.getView(); Transformation trans = view.transformation(); double x = e.getX(); double y = View.getHeight() - e.getY(); Vertex near = new Vertex(x, y, 0.0); Vertex far = new Vertex(x, y, 1.0); Edge ray = new Edge(near, far); ray = trans.unProject(ray); Vertex dir = edge.getDirection(); Plane plane = new Plane(dir.getX(), dir.getY(), dir.getZ(), start.vertex()); dragplane = plane.orthogonalPlane(ray); } else { Project.getInstance().checkpoint(); cleanUp(); moved(e); } } /** {@inheritDoc} */ @Override public void cleanUp() { if (start != null) { move(current.vertex(), start.vertex()); } if (coordMap != null) { for (CoordinateSystem cs : coordMap.values()) { glv.getView().removeTempConstructor(cs); } } edge = null; coordMap = null; swiwel = null; dragplane = null; verticesMap = null; map = null; Selection.primary().clear(); super.cleanUp(); } } Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** ToolFactory.java 28 Feb 2007 15:25:52 -0000 1.78 --- ToolFactory.java 22 Mar 2007 11:47:06 -0000 1.79 *************** *** 119,125 **** private FocusTool focusTool; ! /** The too for moving alternatively */ private AltMoveTool altMoveTool; /** The selection button */ private JToggleButton selBut; --- 119,128 ---- private FocusTool focusTool; ! /** The tool for moving alternatively */ private AltMoveTool altMoveTool; + /** The tool for moving edges alternatively */ + private EdgeMoveTool edgeMoveTool; + /** The selection button */ private JToggleButton selBut; *************** *** 214,217 **** --- 217,221 ---- focusTool = new FocusTool(glv, null); altMoveTool = new AltMoveTool(glv, pencilcursor); + edgeMoveTool = new EdgeMoveTool(glv, pencilcursor); Toolbar tb = Toolbar.getInstance(); *************** *** 237,240 **** --- 241,245 ---- registerTool(Tool.CONTROLLED_MOVE_TOOL, controlled, "Biconmovetool.gif", "Controlled Move"); registerTool(Tool.ALT_MOVE_TOOL, altMoveTool, "Biconmovetool.gif", "Alternative Moving"); + registerTool(Tool.EDGE_MOVE_TOOL, edgeMoveTool, "Biconmovetool.gif", "Edge moving"); rotationBut = this.registerTool(Tool.ROTATION_TOOL, rotation, "Biconrotaxe.gif", "Rotate"); tb.addSeparator(3); Index: Tool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Tool.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Tool.java 28 Feb 2007 15:25:52 -0000 1.30 --- Tool.java 22 Mar 2007 11:47:06 -0000 1.31 *************** *** 66,69 **** --- 66,71 ---- /** the tool for alternative moving of objects */ public static final int ALT_MOVE_TOOL = 22; + /** the tool for alternative moving of edges */ + public static final int EDGE_MOVE_TOOL = 23; /** |