Thread: [Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui PopupMenu.java, 1.82, 1.83
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2007-12-04 12:21:09
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29219/src/net/sourceforge/bprocessor/gui Modified Files: PopupMenu.java Log Message: Align Axes implemented for more objects Index: PopupMenu.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/PopupMenu.java,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** PopupMenu.java 3 Dec 2007 15:01:42 -0000 1.82 --- PopupMenu.java 4 Dec 2007 12:21:11 -0000 1.83 *************** *** 57,76 **** /** - * make a popup menu for a surface - * @param surface the surface - * @return the popupmenu - */ - public static JPopupMenu getSurfaceMenu(Surface surface) { - Collection c = new LinkedList(); - c.add(surface); - return getSurfaceMenu(c); - } - - /** * Make a popupmenu for a list of surfaces * @param surfaces the list of surfaces * @return the popupmenu */ ! public static JPopupMenu getSurfaceMenu(Collection surfaces) { JPopupMenu menu = getGeometricMenu(surfaces); if (surfaces.size() == 1) { --- 57,65 ---- /** * Make a popupmenu for a list of surfaces * @param surfaces the list of surfaces * @return the popupmenu */ ! private static JPopupMenu getSurfaceMenu(Collection surfaces) { JPopupMenu menu = getGeometricMenu(surfaces); if (surfaces.size() == 1) { *************** *** 156,160 **** * @return Menu for edges */ ! public static JPopupMenu getEdgeMenu(Collection edges) { JPopupMenu menu = getGeometricMenu(edges); { --- 145,149 ---- * @return Menu for edges */ ! private static JPopupMenu getEdgeMenu(Collection edges) { JPopupMenu menu = getGeometricMenu(edges); { *************** *** 194,214 **** * @return Menu for coordinate systems */ ! public static JPopupMenu getCoordinateSystemMenu(Collection systems) { JPopupMenu menu = getGeometricMenu(systems); return menu; } - /** - * A popup generator for a space - * @param space the space - * @return the popup menu - */ - public static JPopupMenu getSpaceMenu(Space space) { - Collection c = new LinkedList(); - c.add(space); - return getSpaceMenu(c); - } - - private abstract static class ModellorAction extends AbstractAction { protected Modellor modellor; --- 183,191 ---- * @return Menu for coordinate systems */ ! private static JPopupMenu getCoordinateSystemMenu(Collection systems) { JPopupMenu menu = getGeometricMenu(systems); return menu; } private abstract static class ModellorAction extends AbstractAction { protected Modellor modellor; *************** *** 227,231 **** * @return the popup menu */ ! public static JPopupMenu getSpaceMenu(Collection s) { JPopupMenu menu = PopupMenu.getGeometricMenu(s); --- 204,208 ---- * @return the popup menu */ ! private static JPopupMenu getSpaceMenu(Collection s) { JPopupMenu menu = PopupMenu.getGeometricMenu(s); *************** *** 462,465 **** --- 439,488 ---- return pm; } + + private static CoordinateSystem systemFor(Geometric geometric) { + if (geometric instanceof Vertex) { + return systemFor((Vertex) geometric); + } else if (geometric instanceof Surface) { + return systemFor((Surface) geometric); + } else if (geometric instanceof CoordinateSystem) { + return (CoordinateSystem) geometric; + } else { + CoordinateSystem active = Project.getInstance().getActiveCoordinateSystem(); + return active.copy(geometric.center()); + } + } + + private static CoordinateSystem systemFor(Vertex vertex) { + Collection<Edge> edges = vertex.getEdges(); + double x = 0; + double y = 0; + double z = 0; + for (Edge current : edges) { + Vertex other = current.otherVertex(vertex); + Vertex v = other.minus(vertex); + x += v.getX(); + y += v.getY(); + z += v.getZ(); + } + x /= edges.size(); + y /= edges.size(); + z /= edges.size(); + Vertex n = new Vertex(-x, -y, -z); + Edge edge = edges.iterator().next(); + Vertex other = edge.otherVertex(vertex); + + Vertex v = other.minus(vertex); + Vertex i = n.cross(v); + Vertex j = n.cross(i); + + Vertex o = vertex.copy(); + return new CoordinateSystem(i, j, n, o); + } + + private static CoordinateSystem systemFor(Surface surface) { + Vertex normal = surface.normal(); + Vertex origin = surface.center(); + return CoordinateSystem.systemFor(origin, normal); + } /** *************** *** 468,472 **** * @return the popupmenu */ ! public static JPopupMenu getGeometricMenu(Collection<Geometric> arguments) { JPopupMenu menu = new JPopupMenu(); AbstractAction delete = new GeometricMenuAction(arguments, "Delete") { --- 491,495 ---- * @return the popupmenu */ ! private static JPopupMenu getGeometricMenu(Collection<Geometric> arguments) { JPopupMenu menu = new JPopupMenu(); AbstractAction delete = new GeometricMenuAction(arguments, "Delete") { *************** *** 535,569 **** if (entities.size() == 1) { Geometric geometric = entities.iterator().next(); ! if (geometric instanceof Vertex) { ! Vertex vertex = (Vertex) geometric; ! Collection<Edge> edges = vertex.getEdges(); ! double x = 0; ! double y = 0; ! double z = 0; ! for (Edge current : edges) { ! Vertex other = current.otherVertex(vertex); ! Vertex v = other.minus(vertex); ! x += v.getX(); ! y += v.getY(); ! z += v.getZ(); ! } ! x /= edges.size(); ! y /= edges.size(); ! z /= edges.size(); ! Vertex n = new Vertex(x, y, z); ! Edge edge = edges.iterator().next(); ! Vertex other = edge.otherVertex(vertex); ! ! Vertex v = other.minus(vertex); ! Vertex i = n.cross(v); ! Vertex j = n.cross(i); ! ! Vertex o = vertex.copy(); ! CoordinateSystem system = Project.getInstance().getActiveCoordinateSystem(); ! system.setIJN(i, j, n); ! system.setOrigin(o); ! Project.getInstance().changed(Project.getInstance()); ! Project.getInstance().checkpoint(); ! } } } --- 558,571 ---- if (entities.size() == 1) { Geometric geometric = entities.iterator().next(); ! CoordinateSystem system = systemFor(geometric); ! Vertex i = system.getI(); ! Vertex j = system.getJ(); ! Vertex n = system.getN(); ! Vertex o = system.getOrigin(); ! CoordinateSystem active = Project.getInstance().getActiveCoordinateSystem(); ! active.setIJN(i, j, n); ! active.setOrigin(o); ! Project.getInstance().changed(Project.getInstance()); ! Project.getInstance().checkpoint(); } } *************** *** 749,753 **** * @return JPopupMenu */ ! public JPopupMenu getAnalysisMenu() { JPopupMenu menu = new JPopupMenu(); AbstractAction planeanalysis = new AbstractAction("Plane Analysis") { --- 751,755 ---- * @return JPopupMenu */ ! private JPopupMenu getAnalysisMenu() { JPopupMenu menu = new JPopupMenu(); AbstractAction planeanalysis = new AbstractAction("Plane Analysis") { |