X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Futils%2FStructuralUtils.java;fp=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Futils%2FStructuralUtils.java;h=97038c63548f6833ef115c30cbd6781a11156d55;hb=1a8971ec56f21b4532e22d787c3f5a15df0b5f2b;hp=3181dd7c45d7ea2434eed586393a2d2c7127c5b2;hpb=8744cc98e176b7f74f166fde5df76c84089a63b9;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java index 3181dd7c4..97038c635 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java @@ -13,6 +13,7 @@ import org.simantics.db.Resource; 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; @@ -23,6 +24,7 @@ import org.simantics.db.layer0.util.Layer0Utils; 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; @@ -39,6 +41,24 @@ import gnu.trove.set.hash.THashSet; */ 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 getConnectionRelations(ReadGraph graph, Resource componentType) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); StructuralResource2 STR = StructuralResource2.getInstance(graph); @@ -168,6 +188,7 @@ public class StructuralUtils { * 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); @@ -290,5 +311,35 @@ public class StructuralUtils { public static List structuralConnectionConnectionPoints(ReadGraph graph, Variable component, Connection conn, Resource relationType) throws DatabaseException { return new ArrayList(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.instance()); +// throw new DatabaseException("No type for " + component.getURI(graph)); +// } +// return graph.getPossibleType(represents, baseType); +// +// Pair 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); + + } + + }