1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.processeditor.stubs;
\r
13 import org.simantics.db.Resource;
\r
14 import org.simantics.db.ResourceContainer;
\r
15 import org.simantics.db.Statement;
\r
16 import org.simantics.db.Graph;
\r
17 import org.simantics.db.ResourceContainer;
\r
18 import org.simantics.layer0.utils.ResourceDoesNotSatisfyAssumptionException;
\r
19 import org.simantics.layer0.utils.IEntity;
\r
20 import org.simantics.layer0.utils.internal.Entity;
\r
21 import org.simantics.layer0.utils.instantiation.InstanceFactory;
\r
22 import java.util.Collection;
\r
23 import java.util.ArrayList;
\r
25 public class P3DNode extends Entity implements IP3DNode {
\r
27 public P3DNode(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public P3DNode(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static P3DNode createDefault(Graph graph) {
\r
40 return new P3DNode(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).P3DNode));
\r
43 public static boolean isInstance(IEntity entity) {
\r
44 Graph graph = entity.getGraph();
\r
45 Resource type = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).P3DNode;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() {
\r
55 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource);
\r
58 public P3DNode toP3DNode() {
\r
62 public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {
\r
63 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);
\r
64 Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);
\r
65 for(Statement s : statements)
\r
66 ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));
\r
70 public void addChild(ResourceContainer v) {
\r
71 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());
\r
74 public org.simantics.proconf.g3d.stubs.G3DNode getParent() {
\r
75 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);
\r
76 if(statements.length > 1)
\r
77 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
78 if(statements.length == 0)
\r
80 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());
\r
83 public void addParent(ResourceContainer v) {
\r
84 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());
\r
87 public void setParent(ResourceContainer v) {
\r
88 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;
\r
89 graph.removeStatements(resource, predicate);
\r
90 graph.addStatement(resource, predicate, v.getResource());
\r
93 public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {
\r
94 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);
\r
95 if(statements.length > 1)
\r
96 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
97 if(statements.length == 0)
\r
99 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
102 public void addLocalPosition(ResourceContainer v) {
\r
103 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\r
106 public void setLocalPosition(ResourceContainer v) {
\r
107 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;
\r
108 graph.removeStatements(resource, predicate);
\r
109 graph.addStatement(resource, predicate, v.getResource());
\r
112 public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {
\r
113 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);
\r
114 if(statements.length > 1)
\r
115 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
116 if(statements.length == 0)
\r
118 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
121 public void addWorldPosition(ResourceContainer v) {
\r
122 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\r
125 public void setWorldPosition(ResourceContainer v) {
\r
126 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;
\r
127 graph.removeStatements(resource, predicate);
\r
128 graph.addStatement(resource, predicate, v.getResource());
\r
131 public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {
\r
132 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);
\r
133 if(statements.length > 1)
\r
134 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
135 if(statements.length == 0)
\r
137 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
140 public void addLocalOrientation(ResourceContainer v) {
\r
141 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\r
144 public void setLocalOrientation(ResourceContainer v) {
\r
145 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;
\r
146 graph.removeStatements(resource, predicate);
\r
147 graph.addStatement(resource, predicate, v.getResource());
\r
150 public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {
\r
151 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);
\r
152 if(statements.length > 1)
\r
153 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
154 if(statements.length == 0)
\r
156 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
159 public void addWorldOrientation(ResourceContainer v) {
\r
160 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\r
163 public void setWorldOrientation(ResourceContainer v) {
\r
164 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;
\r
165 graph.removeStatements(resource, predicate);
\r
166 graph.addStatement(resource, predicate, v.getResource());
\r
169 public org.simantics.proconf.g3d.stubs.Center getCenter() {
\r
170 Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);
\r
171 if(statements.length > 1)
\r
172 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
173 if(statements.length == 0)
\r
175 return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());
\r
178 public void addCenter(ResourceContainer v) {
\r
179 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());
\r
182 public void setCenter(ResourceContainer v) {
\r
183 Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;
\r
184 graph.removeStatements(resource, predicate);
\r
185 graph.addStatement(resource, predicate, v.getResource());
\r