]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.processeditor/src/org/simantics/processeditor/stubs/LibraryComponent.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 / LibraryComponent.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 LibraryComponent extends Entity implements ILibraryComponent {\r
26     \r
27     public LibraryComponent(Graph graph, ResourceContainer resourceContainer) {\r
28         super(graph, resourceContainer.getResource());\r
29     }\r
30     \r
31     public LibraryComponent(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 LibraryComponent createDefault(Graph graph) {\r
40         return new LibraryComponent(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).LibraryComponent));\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).LibraryComponent;\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 org.simantics.processeditor.stubs.PBSNode toPBSNode() {\r
59         return new org.simantics.processeditor.stubs.PBSNode(graph, resource);\r
60     }\r
61     \r
62     public org.simantics.processeditor.stubs.P3DNode toP3DNode() {\r
63         return new org.simantics.processeditor.stubs.P3DNode(graph, resource);\r
64     }\r
65     \r
66     public LibraryComponent toLibraryComponent() {\r
67         return this;\r
68     }\r
69     \r
70     public Collection<org.simantics.proconf.g3d.stubs.G3DNode> getChild() {\r
71         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild);\r
72         Collection<org.simantics.proconf.g3d.stubs.G3DNode> ret = new ArrayList<org.simantics.proconf.g3d.stubs.G3DNode>(statements.length);\r
73         for(Statement s : statements)\r
74             ret.add(new org.simantics.proconf.g3d.stubs.G3DNode(graph, s.getObject()));\r
75         return ret;\r
76     }\r
77     \r
78     public void addChild(ResourceContainer v) {\r
79         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());\r
80     }\r
81     \r
82     public org.simantics.proconf.g3d.stubs.G3DNode getParent() {\r
83         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent);\r
84         if(statements.length > 1)\r
85             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
86         if(statements.length == 0)\r
87             return null;\r
88         return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());\r
89     }\r
90     \r
91     public void addParent(ResourceContainer v) {\r
92         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());\r
93     }\r
94     \r
95     public void setParent(ResourceContainer v) {\r
96         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent;\r
97         graph.removeStatements(resource, predicate);\r
98         graph.addStatement(resource, predicate, v.getResource());\r
99     }\r
100     \r
101     public org.simantics.proconf.g3d.stubs.Position getLocalPosition() {\r
102         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition);\r
103         if(statements.length > 1)\r
104             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
105         if(statements.length == 0)\r
106             return null;\r
107         return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());\r
108     }\r
109     \r
110     public void addLocalPosition(ResourceContainer v) {\r
111         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());\r
112     }\r
113     \r
114     public void setLocalPosition(ResourceContainer v) {\r
115         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition;\r
116         graph.removeStatements(resource, predicate);\r
117         graph.addStatement(resource, predicate, v.getResource());\r
118     }\r
119     \r
120     public org.simantics.proconf.g3d.stubs.Position getWorldPosition() {\r
121         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition);\r
122         if(statements.length > 1)\r
123             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
124         if(statements.length == 0)\r
125             return null;\r
126         return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());\r
127     }\r
128     \r
129     public void addWorldPosition(ResourceContainer v) {\r
130         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());\r
131     }\r
132     \r
133     public void setWorldPosition(ResourceContainer v) {\r
134         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition;\r
135         graph.removeStatements(resource, predicate);\r
136         graph.addStatement(resource, predicate, v.getResource());\r
137     }\r
138     \r
139     public org.simantics.proconf.g3d.stubs.Orientation getLocalOrientation() {\r
140         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation);\r
141         if(statements.length > 1)\r
142             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
143         if(statements.length == 0)\r
144             return null;\r
145         return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());\r
146     }\r
147     \r
148     public void addLocalOrientation(ResourceContainer v) {\r
149         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());\r
150     }\r
151     \r
152     public void setLocalOrientation(ResourceContainer v) {\r
153         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation;\r
154         graph.removeStatements(resource, predicate);\r
155         graph.addStatement(resource, predicate, v.getResource());\r
156     }\r
157     \r
158     public org.simantics.proconf.g3d.stubs.Orientation getWorldOrientation() {\r
159         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation);\r
160         if(statements.length > 1)\r
161             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
162         if(statements.length == 0)\r
163             return null;\r
164         return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());\r
165     }\r
166     \r
167     public void addWorldOrientation(ResourceContainer v) {\r
168         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());\r
169     }\r
170     \r
171     public void setWorldOrientation(ResourceContainer v) {\r
172         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation;\r
173         graph.removeStatements(resource, predicate);\r
174         graph.addStatement(resource, predicate, v.getResource());\r
175     }\r
176     \r
177     public org.simantics.proconf.g3d.stubs.Center getCenter() {\r
178         Statement[] statements = graph.getStatements(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter);\r
179         if(statements.length > 1)\r
180             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
181         if(statements.length == 0)\r
182             return null;\r
183         return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());\r
184     }\r
185     \r
186     public void addCenter(ResourceContainer v) {\r
187         graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());\r
188     }\r
189     \r
190     public void setCenter(ResourceContainer v) {\r
191         Resource predicate = org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter;\r
192         graph.removeStatements(resource, predicate);\r
193         graph.addStatement(resource, predicate, v.getResource());\r
194     }\r
195     \r
196     public org.simantics.processeditor.stubs.PBSNode getParentStructure() {\r
197         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);\r
198         if(statements.length > 1)\r
199             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
200         if(statements.length == 0)\r
201             return null;\r
202         return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());\r
203     }\r
204     \r
205     public void addParentStructure(ResourceContainer v) {\r
206         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());\r
207     }\r
208     \r
209     public void setParentStructure(ResourceContainer v) {\r
210         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;\r
211         graph.removeStatements(resource, predicate);\r
212         graph.addStatement(resource, predicate, v.getResource());\r
213     }\r
214     \r
215     public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {\r
216         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);\r
217         Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);\r
218         for(Statement s : statements)\r
219             ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));\r
220         return ret;\r
221     }\r
222     \r
223     public void addChildStructure(ResourceContainer v) {\r
224         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());\r
225     }\r
226     \r
227     public org.simantics.proconf.g3d.stubs.G3DModel getGraphics() {\r
228         Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics);\r
229         if(statements.length > 1)\r
230             throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");\r
231         if(statements.length == 0)\r
232             return null;\r
233         return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());\r
234     }\r
235     \r
236     public void addGraphics(ResourceContainer v) {\r
237         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());\r
238     }\r
239     \r
240     public void setGraphics(ResourceContainer v) {\r
241         Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics;\r
242         graph.removeStatements(resource, predicate);\r
243         graph.addStatement(resource, predicate, v.getResource());\r
244     }\r
245     \r
246 }\r
247 \r