X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2Fcontrolpoint%2FControlPointFactory.java;fp=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2Fcontrolpoint%2FControlPointFactory.java;h=193cdd27d16745d6483b83ee99a802185604ca06;hb=22bb24d2a7e26c70b0dd4c57080f2c25ac3d40a8;hp=0000000000000000000000000000000000000000;hpb=16ec8075f708c6589937f8e760f8074ba27d86c4;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java new file mode 100644 index 00000000..193cdd27 --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java @@ -0,0 +1,134 @@ +package org.simantics.plant3d.scenegraph.controlpoint; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.plant3d.ontology.Plant3D; +import org.simantics.plant3d.scenegraph.PipelineComponent; +import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Type; +import org.simantics.plant3d.utils.Item; +import org.simantics.plant3d.utils.P3DUtil; + +public class ControlPointFactory { + + private static Map cache = new HashMap(); + + + public static void preloadCache() throws Exception { + List items = P3DUtil.getEnds(); + items.addAll(P3DUtil.getInlines()); + items.addAll(P3DUtil.getNozzles()); + items.addAll(P3DUtil.getTurns()); + + for (Item item : items) { + Instruction inst = createInstruction(item.getUri()); + cache.put(item.getUri(), inst); + } + } + + public static PipeControlPoint create(PipelineComponent component) throws Exception { + Instruction inst = cache.get(component.getType()); + if (inst == null) { + inst = createInstruction(component.getType()); + cache.put(component.getType(), inst); + } + if (inst == null) { + return null; + } + + PipeControlPoint pcp = new PipeControlPoint(component); + pcp.setType(inst.type); + pcp.setFixed(inst.fixed); + switch(inst.type) { + case END: + + break; + case INLINE: + if (inst.isOffset || inst.isSizeChange) { + PipeControlPoint sub = new PipeControlPoint(component); + pcp.children.add(sub); + sub.parent = pcp; + sub.setType(inst.type); + sub.setFixed(inst.fixed); + sub.setSub(true); +// pcp.setOffset(0.0); + if (inst.isOffset) + pcp.setOffset(0.0); + } + + break; + case TURN: + + break; + } + return pcp; + } + + + private static class Instruction { + Type type; + boolean fixed; + boolean isOffset; + boolean isSizeChange; + + + } + + private static Instruction createInstruction(final String type) throws Exception { + return Simantics.getSession().syncRequest(new Read() { + @Override + public Instruction perform(ReadGraph graph) throws DatabaseException { + Resource res = graph.getResource(type); + Plant3D p3d = Plant3D.getInstance(graph); + Instruction i = new Instruction(); + i.fixed = false; + i.isOffset = false; + i.isSizeChange = false; + i.type = Type.INLINE; + if (graph.isInheritedFrom(res, p3d.Nozzle)) { + i.fixed = true; + i.isOffset = false; + i.isSizeChange = false; + i.type = Type.END; + } else if (graph.isInheritedFrom(res, p3d.InlineComponent)){ + + i.type = Type.INLINE; + if (graph.hasStatement(res,p3d.VariableLengthInlineComponent)) { + i.fixed = false; + } else if (graph.hasStatement(res,p3d.FixedLengthInlineComponent)) { + i.fixed = true; + } + + if (graph.hasStatement(res,p3d.SizeChangeComponent)) { + i.isSizeChange = true; + } + + if (graph.hasStatement(res,p3d.OffsetComponent)) { + i.isOffset = true; + } + + } else if (graph.isInheritedFrom(res, p3d.TurnComponent)) { + i.type = Type.TURN; + if (graph.hasStatement(res,p3d.VariableAngleTurnComponent)) { + i.fixed = false; + } else if (graph.hasStatement(res,p3d.FixedAngleTurnComponent)) { + i.fixed = true; + } + } else if (graph.isInheritedFrom(res, p3d.EndComponent)) { + i.fixed = false; + i.type = Type.END; + } else { + return null; + } + return i; + } + }); + } + +}