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.RequestProcessor;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.request.Read;
13 import org.simantics.plant3d.ontology.Plant3D;
14 import org.simantics.plant3d.scenegraph.PipelineComponent;
15 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.PointType;
16 import org.simantics.plant3d.utils.Item;
17 import org.simantics.plant3d.utils.P3DUtil;
19 public class ControlPointFactory {
21 private static Map<String,Instruction> cache = new HashMap<String, Instruction>();
24 public static void preloadCache(RequestProcessor session, String libUri) throws Exception {
25 List<Item> items = P3DUtil.getEnds(session, libUri);
26 items.addAll(P3DUtil.getInlines(session, libUri));
27 items.addAll(P3DUtil.getNozzles(session, libUri));
28 items.addAll(P3DUtil.getTurns(session, libUri));
30 for (Item item : items) {
31 Instruction inst = createInstruction(session, item.getUri());
32 cache.put(item.getUri(), inst);
36 public static PipeControlPoint create(PipelineComponent component) throws Exception {
37 Instruction inst = cache.get(component.getType());
39 inst = createInstruction(Simantics.getSession(), component.getType());
40 cache.put(component.getType(), inst);
46 PipeControlPoint pcp = new PipeControlPoint(component);
47 pcp.setType(inst.type);
48 pcp.setFixed(inst.fixed);
50 pcp.setRotate(inst.isRotate);
51 pcp.setReverse(inst.isReverse);
57 if (inst.isOffset || inst.isSizeChange) {
58 PipeControlPoint sub = new PipeControlPoint(component);
59 pcp.children.add(sub);
61 sub.setType(inst.type);
62 sub.setFixed(inst.fixed);
65 sub.setDeletable(false);
68 if (inst.isSizeChange)
69 pcp.setSizeChange(true);
81 private static class Instruction {
92 private static Instruction createInstruction(RequestProcessor session, final String type) throws Exception {
93 return session.syncRequest(new Read<Instruction>() {
95 public Instruction perform(ReadGraph graph) throws DatabaseException {
96 Resource res = graph.getResource(type);
97 Plant3D p3d = Plant3D.getInstance(graph);
98 Instruction i = new Instruction();
101 i.isSizeChange = false;
104 i.type = PointType.INLINE;
106 if (graph.isInheritedFrom(res, p3d.Nozzle)) {
109 i.isSizeChange = false;
110 i.type = PointType.END;
111 } else if (graph.isInheritedFrom(res, p3d.InlineComponent)){
113 i.type = PointType.INLINE;
114 if (graph.hasStatement(res,p3d.VariableLengthInlineComponent)) {
116 } else if (graph.hasStatement(res,p3d.FixedLengthInlineComponent)) {
118 } else if (graph.hasStatement(res,p3d.AdjustableLengthInlineComponent)) {
122 throw new DatabaseException("Inline component type " + res + " does not have length configuration.");
125 if (graph.hasStatement(res,p3d.SizeChangeComponent)) {
126 i.isSizeChange = true;
129 if (graph.hasStatement(res,p3d.OffsetComponent)) {
132 if (graph.hasStatement(res,p3d.RotateComponent)) {
136 if (graph.hasStatement(res,p3d.ReverseComponent)) {
140 } else if (graph.isInheritedFrom(res, p3d.TurnComponent)) {
141 i.type = PointType.TURN;
142 if (graph.hasStatement(res,p3d.VariableAngleTurnComponent)) {
144 } else if (graph.hasStatement(res,p3d.FixedAngleTurnComponent)) {
147 throw new DatabaseException("Turn component type " + res + " does not have angle configuration.");
149 } else if (graph.isInheritedFrom(res, p3d.EndComponent)) {
151 i.type = PointType.END;