X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Futils%2FStructuralUtils.java;h=97038c63548f6833ef115c30cbd6781a11156d55;hb=1f8b50d81a1aa1bbd67a77f7cbc1060f2eb805d4;hp=9f5897f06a24d476a44d2b4424ac7d58444170a8;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;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 9f5897f06..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 @@ -7,13 +7,13 @@ import java.util.List; import java.util.Set; import org.simantics.databoard.Bindings; -import org.simantics.datatypes.literal.GUID; import org.simantics.db.ReadGraph; import org.simantics.db.RequestProcessor; 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; @@ -24,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; @@ -40,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); @@ -141,8 +160,8 @@ public class StructuralUtils { Resource component = ir.perform(g); g.claim(component, L0.HasName, Layer0Utils.literal(g, name)); g.claim(component, L0.HasLabel, Layer0Utils.literal(g, "")); - g.addLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING); g.claim(parent, L0.ConsistsOf, component); + Layer0Utils.claimNewIdentifier(g, component, true); // Add comment to change set. CommentMetadata cm = g.getMetadata(CommentMetadata.class); g.addMetadata(cm.add("Created component " + component)); @@ -169,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); @@ -266,7 +286,7 @@ public class StructuralUtils { if(property == null) return null; Connection conn = property.getPossibleValue(graph); if(conn == null) return null; - Collection cps = conn.getConnectionPoints(graph, null); + Collection cps = conn.getConnectionPoints(graph, component, null); if(cps.size() == 2) { for(Variable var : cps) { if(property.equals(var)) continue; @@ -288,8 +308,38 @@ public class StructuralUtils { ; } - public static List structuralConnectionConnectionPoints(ReadGraph graph, Connection conn, Resource relationType) throws DatabaseException { - return new ArrayList(conn.getConnectionPoints(graph, relationType)); + 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); + } + + }