]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.processeditor/src/org/simantics/processeditor/stubs/P3DNode.java
git-svn-id: https://www.simantics.org/svn/simantics/3d/branches/dev@7344 ac1ea38d...
[simantics/3d.git] / org.simantics.proconf.processeditor / src / org / simantics / processeditor / stubs / P3DNode.java
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.stubs;\r
12 \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
24 \r
25 public class P3DNode extends Entity implements IP3DNode {\r
26     \r
27     public P3DNode(Graph graph, ResourceContainer resourceContainer) {\r
28         super(graph, resourceContainer.getResource());\r
29     }\r
30     \r
31     public P3DNode(IEntity entity) {\r
32         super(entity.getGraph(), entity.getResource());\r
33     }\r
34     \r
35     public Graph getGraph() {\r
36         return graph;\r
37     }\r
38     \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
41     }\r
42     \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
47     }\r
48     \r
49     @Override\r
50     public Resource getResource() {\r
51         return resource;\r
52     }\r
53     \r
54     public org.simantics.proconf.g3d.stubs.G3DNode toG3DNode() {\r
55         return new org.simantics.proconf.g3d.stubs.G3DNode(graph, resource);\r
56     }\r
57     \r
58     public P3DNode toP3DNode() {\r
59         return this;\r
60     }\r
61     \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
67         return ret;\r
68     }\r
69     \r
70     public void addChild(ResourceContainer v) {\r
71         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());\r
72     }\r
73     \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
79             return null;\r
80         return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());\r
81     }\r
82     \r
83     public void addParent(ResourceContainer v) {\r
84         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());\r
85     }\r
86     \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
91     }\r
92     \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
98             return null;\r
99         return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());\r
100     }\r
101     \r
102     public void addLocalPosition(ResourceContainer v) {\r
103         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());\r
104     }\r
105     \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
110     }\r
111     \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
117             return null;\r
118         return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());\r
119     }\r
120     \r
121     public void addWorldPosition(ResourceContainer v) {\r
122         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());\r
123     }\r
124     \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
129     }\r
130     \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
136             return null;\r
137         return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());\r
138     }\r
139     \r
140     public void addLocalOrientation(ResourceContainer v) {\r
141         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());\r
142     }\r
143     \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
148     }\r
149     \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
155             return null;\r
156         return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());\r
157     }\r
158     \r
159     public void addWorldOrientation(ResourceContainer v) {\r
160         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());\r
161     }\r
162     \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
167     }\r
168     \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
174             return null;\r
175         return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());\r
176     }\r
177     \r
178     public void addCenter(ResourceContainer v) {\r
179         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());\r
180     }\r
181     \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
186     }\r
187     \r
188 }\r
189 \r