X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Futils%2FStructuralUtils.java;h=584b4acf73f924f4ab57de7de12764fc39548ec3;hp=9a77d100fca3ded3b6924aee9915d05119f52ecb;hb=7402926f3949dbb38e9f8f45e864ba4dd65b59b9;hpb=bc24b049b5ec56feb66793df675a6db78860e28f 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 9a77d100f..584b4acf7 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 @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.structural2.utils; import java.util.ArrayList; @@ -23,6 +34,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 +51,25 @@ 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); + Set types = graph.getTypes(componentType); + if(types.contains(STR.ProceduralComponentType)) + return StructuralComponentClass.PROCEDURAL; + else if(graph.hasStatement(componentType, STR.IsDefinedBy)) + return StructuralComponentClass.DEFINED; + else if(types.contains(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 +199,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); @@ -288,7 +320,21 @@ public class StructuralUtils { } public static List structuralConnectionConnectionPoints(ReadGraph graph, Connection conn, Resource relationType) throws DatabaseException { - return new ArrayList(conn.getConnectionPoints(graph, relationType)); + return new ArrayList(conn.getConnectionPoints(graph, relationType)); + } + + public static Resource structuralTypeResource(ReadGraph graph, Variable component, Resource baseType) throws DatabaseException { + StructuralOverrideData od = StructuralOverrideData.compute(graph, component); + return od.type(); } + + public static Resource getComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException { + + Variable componentVariable = configuration.browse(graph, component); + return componentVariable.getType(graph); + + } + + }