1 package org.simantics.plant3d.scenegraph.controlpoint;
3 import java.util.HashMap;
7 import org.simantics.Simantics;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.request.Read;
12 import org.simantics.plant3d.ontology.Plant3D;
13 import org.simantics.plant3d.scenegraph.PipelineComponent;
14 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.PointType;
15 import org.simantics.plant3d.utils.Item;
16 import org.simantics.plant3d.utils.P3DUtil;
18 public class ControlPointFactory {
20 private static Map<String,Instruction> cache = new HashMap<String, Instruction>();
23 public static void preloadCache(String libUri) throws Exception {
24 List<Item> items = P3DUtil.getEnds(libUri);
25 items.addAll(P3DUtil.getInlines(libUri));
26 items.addAll(P3DUtil.getNozzles(libUri));
27 items.addAll(P3DUtil.getTurns(libUri));
29 for (Item item : items) {
30 Instruction inst = createInstruction(item.getUri());
31 cache.put(item.getUri(), inst);
35 public static PipeControlPoint create(PipelineComponent component) throws Exception {
36 Instruction inst = cache.get(component.getType());
38 inst = createInstruction(component.getType());
39 cache.put(component.getType(), inst);
45 PipeControlPoint pcp = new PipeControlPoint(component);
46 pcp.setType(inst.type);
47 pcp.setFixed(inst.fixed);
48 pcp.setRotate(inst.isRotate);
49 pcp.setReverse(inst.isReverse);
55 if (inst.isOffset || inst.isSizeChange) {
56 PipeControlPoint sub = new PipeControlPoint(component);
57 pcp.children.add(sub);
59 sub.setType(inst.type);
60 sub.setFixed(inst.fixed);
62 sub.setDeletable(false);
65 if (inst.isSizeChange)
66 pcp.setSizeChange(true);
78 private static class Instruction {
88 private static Instruction createInstruction(final String type) throws Exception {
89 return Simantics.getSession().syncRequest(new Read<Instruction>() {
91 public Instruction perform(ReadGraph graph) throws DatabaseException {
92 Resource res = graph.getResource(type);
93 Plant3D p3d = Plant3D.getInstance(graph);
94 Instruction i = new Instruction();
97 i.isSizeChange = false;
100 i.type = PointType.INLINE;
101 if (graph.isInheritedFrom(res, p3d.Nozzle)) {
104 i.isSizeChange = false;
105 i.type = PointType.END;
106 } else if (graph.isInheritedFrom(res, p3d.InlineComponent)){
108 i.type = PointType.INLINE;
109 if (graph.hasStatement(res,p3d.VariableLengthInlineComponent)) {
111 } else if (graph.hasStatement(res,p3d.FixedLengthInlineComponent)) {
115 if (graph.hasStatement(res,p3d.SizeChangeComponent)) {
116 i.isSizeChange = true;
119 if (graph.hasStatement(res,p3d.OffsetComponent)) {
122 if (graph.hasStatement(res,p3d.RotateComponent)) {
126 if (graph.hasStatement(res,p3d.ReverseComponent)) {
130 } else if (graph.isInheritedFrom(res, p3d.TurnComponent)) {
131 i.type = PointType.TURN;
132 if (graph.hasStatement(res,p3d.VariableAngleTurnComponent)) {
134 } else if (graph.hasStatement(res,p3d.FixedAngleTurnComponent)) {
137 } else if (graph.isInheritedFrom(res, p3d.EndComponent)) {
139 i.type = PointType.END;