Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv18112/src/net/sourceforge/bprocessor/model
Modified Files:
CoordinateSystem.java
Log Message:
Improved handling of relations
Index: CoordinateSystem.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/CoordinateSystem.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** CoordinateSystem.java 13 Mar 2007 15:21:24 -0000 1.44
--- CoordinateSystem.java 14 Mar 2007 10:22:13 -0000 1.45
***************
*** 48,54 ****
if (geometrics.size() > 0) {
Geometric leader = geometrics.iterator().next();
! CoordinateSystem system = systemFor(leader);
for (Geometric geometric : geometrics) {
! system.relate(geometric);
}
Project.getInstance().world().add(system);
--- 48,64 ----
if (geometrics.size() > 0) {
Geometric leader = geometrics.iterator().next();
! CoordinateSystem system = systemOf(leader);
! if (system == null) {
! system = systemFor(leader);
! }
for (Geometric geometric : geometrics) {
! CoordinateSystem existing = systemOf(geometric);
! if (existing != null) {
! if (existing != system) {
! system.relate(existing);
! }
! } else {
! system.relate(geometric);
! }
}
Project.getInstance().world().add(system);
***************
*** 80,83 ****
--- 90,118 ----
/**
+ * Returns a CoordinateSystem that the given geometric is related
+ * to if it exists.
+ * @param geometric Geometric object of wich to return a related CoordinateSystem
+ * @return A CoordinateSystem related to the given geometric object.
+ */
+ public static CoordinateSystem systemOf(Geometric geometric) {
+ Space space = geometric.getOwner();
+ List<CoordinateSystem> result = new LinkedList();
+ Collection<CoordinateSystem> systems = space.getCoordinateSystems();
+ for (CoordinateSystem current : systems) {
+ Collection<Relation> relations = current.relations();
+ for (Relation relation : relations) {
+ if (relation.geometric() == geometric) {
+ result.add(current);
+ }
+ }
+ }
+ if (result.size() > 0) {
+ return result.get(0);
+ } else {
+ return null;
+ }
+ }
+
+ /**
* Empty constructor for persistence only
*/
***************
*** 150,154 ****
relate((Surface) geometric);
} else {
!
}
}
--- 185,192 ----
relate((Surface) geometric);
} else {
! Vertex origin = geometric.center();
! double distance = plane().distance(origin);
! Relation relation = new Relation(geometric, String.valueOf(distance));
! add(relation);
}
}
|