+/*******************************************************************************
+ * 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;
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);
+ Set<Resource> 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<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, Connection conn, Resource relationType) throws DatabaseException {
- return new ArrayList<Variable>(conn.getConnectionPoints(graph, relationType));
+ return new ArrayList<Variable>(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);
+
+ }
+
+
}