import org.simantics.db.Statement;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.common.request.ObjectsWithType;
import org.simantics.db.common.request.PossibleTypedParent;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.layer0.Layer0;
import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.Functions.StructuralOverrideData;
import org.simantics.structural2.internal.queries.ConnectedTo;
import org.simantics.structural2.internal.queries.RelatedConnections;
import org.simantics.structural2.internal.queries.RelatedConnectionsOfConnectionJoin;
*/
public class StructuralUtils {
+ public static enum StructuralComponentClass {
+
+ PRIMITIVE,REPLACEABLE,DEFINED,PROCEDURAL;
+
+ public static StructuralComponentClass get(ReadGraph graph, Resource componentType) throws DatabaseException {
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ if(graph.isInstanceOf(componentType, STR.ProceduralComponentType))
+ return StructuralComponentClass.PROCEDURAL;
+ else if(graph.hasStatement(componentType, STR.IsDefinedBy))
+ return StructuralComponentClass.DEFINED;
+ else if(graph.isInstanceOf(componentType, STR.ReplaceableDefinedComponentType))
+ return StructuralComponentClass.REPLACEABLE;
+ else
+ return StructuralComponentClass.PRIMITIVE;
+ }
+
+ }
+
public static Collection<Resource> getConnectionRelations(ReadGraph graph, Resource componentType) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
StructuralResource2 STR = StructuralResource2.getInstance(graph);
* Returns the component type of the given component or null if the
* parameter is not a component.
*/
+ @Deprecated
public static Resource getComponentType(ReadGraph g, Resource component) throws DatabaseException {
StructuralResource2 STR = StructuralResource2.getInstance(g);
return g.getPossibleType(component, STR.Component);
public static List<Variable> structuralConnectionConnectionPoints(ReadGraph graph, Variable component, Connection conn, Resource relationType) throws DatabaseException {
return new ArrayList<Variable>(conn.getConnectionPoints(graph, component, relationType));
}
+
+ public static Resource structuralTypeResource(ReadGraph graph, Variable component, Resource baseType) throws DatabaseException {
+
+ if(component.getURI(graph).endsWith("/Alternative/Alternative/Panel2"))
+ System.err.println("structuralTypeResource " + component.getURI(graph));
+
+ StructuralOverrideData od = StructuralOverrideData.compute(graph, component);
+ return od.type();
+
+// Resource represents = component.getPossibleRepresents(graph);
+// if(represents == null) {
+// String uri = component.getPossiblePropertyValue(graph, "typeURI");
+// if(uri != null) return graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.<Resource>instance());
+// throw new DatabaseException("No type for " + component.getURI(graph));
+// }
+// return graph.getPossibleType(represents, baseType);
+//
+// Pair<Resource,Resource> representsAndType = graph.syncRequest(new PossibleRepresentsAndTypeWithOverrides(component));
+// return representsAndType.second;
+
+ }
+
+ public static Resource getComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException {
+
+ Variable componentVariable = configuration.browse(graph, component);
+ return componentVariable.getType(graph);
+
+ }
+
+
}