Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4864/src/net/sourceforge/bprocessor/gui
Modified Files:
PopupMenu.java
Log Message:
CoordinateSystem transformations
Index: PopupMenu.java
===================================================================
RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/PopupMenu.java,v
retrieving revision 1.83
retrieving revision 1.84
diff -C2 -d -r1.83 -r1.84
*** PopupMenu.java 4 Dec 2007 12:21:11 -0000 1.83
--- PopupMenu.java 4 Dec 2007 13:54:38 -0000 1.84
***************
*** 8,11 ****
--- 8,12 ----
import java.awt.event.ActionEvent;
+ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
***************
*** 455,481 ****
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);
}
--- 456,486 ----
private static CoordinateSystem systemFor(Vertex vertex) {
Collection<Edge> edges = vertex.getEdges();
! if (edges.size() == 0) {
! CoordinateSystem active = Project.getInstance().getActiveCoordinateSystem();
! return active.copy(vertex.copy());
! } else {
! 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);
}
}
***************
*** 659,662 ****
--- 664,707 ----
menu.add(action);
}
+ {
+ AbstractAction action = new GeometricMenuAction(arguments, "Transform In") {
+ public void actionPerformed(ActionEvent event) {
+ List<Vertex> vertices = new ArrayList(Geometry.collect(entities));
+ CoordinateSystem system = Project.getInstance().getActiveCoordinateSystem();
+ List<Vertex> locals = system.unTranslate(vertices);
+ for (int i = 0; i < locals.size(); i++) {
+ Vertex v1 = vertices.get(i);
+ Vertex v2 = locals.get(i);
+ v1.set(v2);
+ }
+ for (Vertex current : vertices) {
+ current.update();
+ }
+ Project.getInstance().changed(Project.getInstance());
+ Project.getInstance().checkpoint();
+ }
+ };
+ menu.add(action);
+ }
+ {
+ AbstractAction action = new GeometricMenuAction(arguments, "Transform Out") {
+ public void actionPerformed(ActionEvent event) {
+ List<Vertex> vertices = new ArrayList(Geometry.collect(entities));
+ CoordinateSystem system = Project.getInstance().getActiveCoordinateSystem();
+ List<Vertex> locals = system.translate(vertices);
+ for (int i = 0; i < locals.size(); i++) {
+ Vertex v1 = vertices.get(i);
+ Vertex v2 = locals.get(i);
+ v1.set(v2);
+ }
+ for (Vertex current : vertices) {
+ current.update();
+ }
+ Project.getInstance().changed(Project.getInstance());
+ Project.getInstance().checkpoint();
+ }
+ };
+ menu.add(action);
+ }
return menu;
|