Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14941/src/net/sourceforge/bprocessor/model
Modified Files:
Geometry.java
Log Message:
Moved insert methods from abstract pencil to geometry
Index: Geometry.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Geometry.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** Geometry.java 24 Jul 2006 13:18:06 -0000 1.23
--- Geometry.java 7 Sep 2006 11:36:30 -0000 1.24
***************
*** 740,742 ****
--- 740,882 ----
return Math.asin(tmp.getZ());
}
+
+ /**
+ * Insert a vertex into model
+ * @param vertex Vertex
+ * @param split Split
+ * @return Vertex from model
+ */
+ public static Vertex insertVertex(Vertex vertex, boolean split) {
+ Project p = Project.getInstance();
+ Space space = p.getActiveSpace();
+
+ if (vertex.getOwner() != space) {
+ vertex = vertex.copy();
+ }
+
+ Vertex actual = null;
+ {
+ Set vertices = p.getActiveSpace().findByLocation
+ (vertex.getX(), vertex.getY(), vertex.getZ(), 0.0000001);
+ if (!vertices.isEmpty()) {
+ actual = (Vertex) vertices.iterator().next();
+ }
+ }
+
+ if (actual == null) {
+ actual = vertex;
+ if (actual.getOwner() == null) {
+ p.getActiveSpace().add(actual);
+ if (split) {
+ Set es = p.getActiveSpace().findEdge(actual);
+ if (es.size() > 0) {
+ Iterator iter = es.iterator();
+ while (iter.hasNext()) {
+ Edge e = (Edge) iter.next();
+ if (!e.getStrippled()) {
+ e.split(actual);
+ }
+ }
+ }
+ }
+ }
+ }
+ return actual;
+ }
+
+ /**
+ * Insert a Constructor into model
+ * @param c the constructor
+ * @return The model Constructor
+ */
+ public static Constructor insertConstructor(Constructor c) {
+ Space space = Project.getInstance().getActiveSpace();
+ return space.insert(c);
+ }
+
+ /**
+ * Insert an edge into model
+ * @param edge Edge
+ * @param split Split
+ * @return Edge from model null if to and from were the same
+ */
+ public static Edge insertEdge(Edge edge, boolean split) {
+ Edge actual = edge;
+ if (edge.getLength() == 0) {
+ return null;
+ }
+ Vertex from = insertVertex(edge.getFrom(), split);
+ Vertex to = insertVertex(edge.getTo(), split);
+ edge.setFrom(from);
+ edge.setTo(to);
+ if (edge.getLength() == 0.0) {
+ return null;
+ }
+ {
+ Collection edges = Project.getInstance().getActiveSpace().getEdges();
+ Iterator iter = edges.iterator();
+ while (iter.hasNext()) {
+ Edge current = (Edge) iter.next();
+ if (current.getFrom() == edge.getFrom() && current.getTo() == edge.getTo()) {
+ actual = current;
+ break;
+ }
+ if (current.getFrom() == edge.getTo() && current.getTo() == edge.getFrom()) {
+ actual = current;
+ break;
+ }
+ }
+ }
+ if (actual == edge) {
+ Project.getInstance().getActiveSpace().add(edge);
+ }
+ return actual;
+ }
+
+ /**
+ * Insert a number edges into the model
+ * @param edges List of edges
+ * @return Boolean indicating whether the edges are closed
+ */
+ public static boolean insertEdges(List edges) {
+ boolean closed = false;
+ if (!edges.isEmpty()) {
+ Vertex from = ((Edge) edges.get(0)).getFrom();
+ Vertex to = ((Edge) edges.get(edges.size() - 1)).getTo();
+
+ if (from == to) {
+ List actual = new LinkedList();
+ Iterator iter = edges.iterator();
+ while (iter.hasNext()) {
+ Edge current = (Edge) iter.next();
+ Edge edge = insertEdge(current, false);
+ if (edge != null) {
+ actual.add(edge);
+ }
+ }
+ if (actual.size() > 3) {
+ Surface surface = new Surface(actual);
+ Project.getInstance().getActiveSpace().insert(surface);
+ holeAnalysis(surface);
+ closed = true;
+ }
+ } else {
+ List actual = new LinkedList();
+ Iterator iter = edges.iterator();
+ while (iter.hasNext()) {
+ Edge current = (Edge) iter.next();
+ Edge edge = insertEdge(current, true);
+ if (edge != null) {
+ actual.add(edge);
+ }
+ }
+ closed = insert(actual);
+ }
+ }
+ Project.getInstance().changed(Project.getInstance());
+ Project.getInstance().checkpoint();
+ return closed;
+ }
+
+
}
|