]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java
Remove dependencies on log4j
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / controlpoint / ControlPointFactory.java
index ae71b7afa9e5da1734a382e93903e40a8fc31938..441d1276477c08c1c1b710ea456a210b27eefed4 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Map;
 
 import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.request.Read;
@@ -20,14 +21,14 @@ public class ControlPointFactory {
        private static Map<String,Instruction> cache = new HashMap<String, Instruction>();
        
        
-       public static void preloadCache() throws Exception {
-               List<Item> items = P3DUtil.getEnds(Plant3D.URIs.Builtin);
-               items.addAll(P3DUtil.getInlines(Plant3D.URIs.Builtin));
-               items.addAll(P3DUtil.getNozzles(Plant3D.URIs.Builtin));
-               items.addAll(P3DUtil.getTurns(Plant3D.URIs.Builtin));
+       public static void preloadCache(RequestProcessor session, String libUri) throws Exception {
+               List<Item> items = P3DUtil.getEnds(session, libUri);
+               items.addAll(P3DUtil.getInlines(session, libUri));
+               items.addAll(P3DUtil.getNozzles(session, libUri));
+               items.addAll(P3DUtil.getTurns(session, libUri));
                
                for (Item item : items) {
-                       Instruction inst = createInstruction(item.getUri());
+                       Instruction inst = createInstruction(session, item.getUri());
                        cache.put(item.getUri(), inst);
                }
        }
@@ -35,7 +36,7 @@ public class ControlPointFactory {
        public static PipeControlPoint create(PipelineComponent component) throws Exception {
                Instruction inst = cache.get(component.getType());
                if (inst == null) {
-                       inst = createInstruction(component.getType());
+                       inst = createInstruction(Simantics.getSession(), component.getType());
                        cache.put(component.getType(), inst);
                }
                if (inst == null) {
@@ -45,6 +46,7 @@ public class ControlPointFactory {
                PipeControlPoint pcp = new PipeControlPoint(component);
                pcp.setType(inst.type);
                pcp.setFixed(inst.fixed);
+               pcp.setMod(inst.mod);
                pcp.setRotate(inst.isRotate);
                pcp.setReverse(inst.isReverse);
                switch(inst.type) {
@@ -58,6 +60,7 @@ public class ControlPointFactory {
                                sub.parent = pcp;
                                sub.setType(inst.type);
                                sub.setFixed(inst.fixed);
+                               sub.setMod(inst.mod);
                                sub.setSub(true);
                                sub.setDeletable(false);
                                if (inst.isOffset)
@@ -78,6 +81,7 @@ public class ControlPointFactory {
        private static class Instruction {
                PointType type;
                boolean fixed;
+               boolean mod;
                boolean isOffset;
                boolean isSizeChange;
                boolean isRotate;
@@ -85,8 +89,8 @@ public class ControlPointFactory {
                
        }
        
-       private static Instruction createInstruction(final String type) throws Exception {
-               return Simantics.getSession().syncRequest(new Read<Instruction>() {
+       private static Instruction createInstruction(RequestProcessor session, final String type) throws Exception {
+               return session.syncRequest(new Read<Instruction>() {
                        @Override
                        public Instruction perform(ReadGraph graph) throws DatabaseException {
                                Resource res = graph.getResource(type);
@@ -98,6 +102,7 @@ public class ControlPointFactory {
                                i.isRotate = false;
                                i.isReverse = false;
                                i.type = PointType.INLINE;
+                               i.mod = false;
                                if (graph.isInheritedFrom(res, p3d.Nozzle)) {
                                        i.fixed = true;
                                        i.isOffset = false;
@@ -110,6 +115,11 @@ public class ControlPointFactory {
                                                i.fixed = false;
                                        } else if (graph.hasStatement(res,p3d.FixedLengthInlineComponent)) {
                                                i.fixed = true;
+                                       } else if (graph.hasStatement(res,p3d.AdjustableLengthInlineComponent)) {
+                                           i.fixed = true;
+                                           i.mod = true;
+                                       } else {
+                                           throw new DatabaseException("Inline component type " + res + " does not have length configuration.");
                                        }
                                        
                                        if (graph.hasStatement(res,p3d.SizeChangeComponent)) {
@@ -133,6 +143,8 @@ public class ControlPointFactory {
                                                i.fixed = false;
                                        } else if (graph.hasStatement(res,p3d.FixedAngleTurnComponent)) {
                                                i.fixed = true; 
+                                       } else {
+                                           throw new DatabaseException("Turn component type " + res + " does not have angle configuration.");
                                        }
                                } else if (graph.isInheritedFrom(res, p3d.EndComponent)) {
                                        i.fixed = false;