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 LibraryComponent extends Entity implements ILibraryComponent {
\r
27 public LibraryComponent(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public LibraryComponent(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\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
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
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 org.simantics.processeditor.stubs.PBSNode toPBSNode() {
\r
59 return new org.simantics.processeditor.stubs.PBSNode(graph, resource);
\r
62 public org.simantics.processeditor.stubs.P3DNode toP3DNode() {
\r
63 return new org.simantics.processeditor.stubs.P3DNode(graph, resource);
\r
66 public LibraryComponent toLibraryComponent() {
\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
78 public void addChild(ResourceContainer v) {
\r
79 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasChild, v.getResource());
\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
88 return new org.simantics.proconf.g3d.stubs.G3DNode(graph, statements[0].getObject());
\r
91 public void addParent(ResourceContainer v) {
\r
92 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasParent, v.getResource());
\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
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
107 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
110 public void addLocalPosition(ResourceContainer v) {
\r
111 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalPosition, v.getResource());
\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
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
126 return new org.simantics.proconf.g3d.stubs.Position(graph, statements[0].getObject());
\r
129 public void addWorldPosition(ResourceContainer v) {
\r
130 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldPosition, v.getResource());
\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
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
145 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
148 public void addLocalOrientation(ResourceContainer v) {
\r
149 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasLocalOrientation, v.getResource());
\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
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
164 return new org.simantics.proconf.g3d.stubs.Orientation(graph, statements[0].getObject());
\r
167 public void addWorldOrientation(ResourceContainer v) {
\r
168 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasWorldOrientation, v.getResource());
\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
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
183 return new org.simantics.proconf.g3d.stubs.Center(graph, statements[0].getObject());
\r
186 public void addCenter(ResourceContainer v) {
\r
187 graph.addStatement(resource, org.simantics.proconf.g3d.stubs.G3DResource.getInstance(graph).HasCenter, v.getResource());
\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
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
202 return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());
\r
205 public void addParentStructure(ResourceContainer v) {
\r
206 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());
\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
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
223 public void addChildStructure(ResourceContainer v) {
\r
224 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());
\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
233 return new org.simantics.proconf.g3d.stubs.G3DModel(graph, statements[0].getObject());
\r
236 public void addGraphics(ResourceContainer v) {
\r
237 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasGraphics, v.getResource());
\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