package org.simantics.structural2.variables;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.simantics.db.common.request.BinaryRead;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.common.request.TransientUnaryRead;
-import org.simantics.db.common.utils.CommonDBUtils;
import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.common.utils.NearestOwnerFinder;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.NoSingleResultException;
import org.simantics.db.layer0.exception.MissingVariableException;
import org.simantics.structural2.Functions;
import org.simantics.structural2.Functions.InterfaceResolution;
import org.simantics.structural2.queries.ConnectionSet;
-import org.simantics.structural2.variables.StandardProceduralChildVariable.FixedConnection;
-import org.simantics.utils.datastructures.Pair;
+import org.simantics.structural2.utils.StructuralUtils;
+import org.simantics.structural2.utils.StructuralUtils.StructuralComponentClass;
+
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
public class ConnectionBrowser {
Resource relation = graph.getInverse(stat.getPredicate());
//System.out.println(NameUtils.getSafeName(graph, component) + "." + NameUtils.getSafeName(graph, relation));
Resource boundConnection = graph.getPossibleObject(relation, STR.IsBoundBy);
- Resource type = graph.getPossibleObject(component, L0.InstanceOf);
+ Resource type = StructuralUtils.getPossibleComponentType(graph, configuration, component);
Resource def = type != null ? graph.getPossibleObject(type, STR.IsDefinedBy) : null;
if(boundConnection != null && def != null) {
// The connection point is bound in component type
for (Resource composite : graph.getObjects(join, STR.JoinsComposite))
ancestorGenerators.add(composite);
}
- Resource ancestor = ancestorGenerators.size() == 1 ? ancestorGenerators.iterator().next() : CommonDBUtils.getNearestOwner(graph, ancestorGenerators);
+ Resource ancestor = ancestorGenerators.size() == 1 ? ancestorGenerators.iterator().next() : NearestOwnerFinder.getNearestOwnerFromDirectOwners(graph, ancestorGenerators);
List<Resource> result = colls.createList();
result.add(ancestor);
Variable conn = child.getPossibleProperty(graph, cp);
FixedConnection fc = (FixedConnection)conn.getValue(graph);
- Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>(1+fc.cps.size());
- result.add(new ComponentConnectionDescriptor(child, cp));// (graph, STR, curConfiguration, "/" + c.name + "#" + conn.getName(graph)));
- for(Pair<String,Resource> cpzz : fc.cps) {
- if(cpzz.first == null) {
- throw new DatabaseException("Lifted connection was not resolved.");
- }
- result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
- }
+ Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>(1+fc.size());
+ result.add(new ComponentConnectionDescriptor(child, cp));
+ fc.addConnectionDescriptors(graph, curConfiguration, result);
return result;
} else {
}
+ public static void reportDescriptor(ReadGraph graph, VariableConnectionPointDescriptor d) throws DatabaseException {
+
+ if(d instanceof ActualConnectionDescriptor) {
+ ActualConnectionDescriptor d2 = (ActualConnectionDescriptor)d;
+
+ System.err.println("--ActualConnectionPointDescriptor2");
+ System.err.println("---root: " + d2.root.getURI(graph));
+ System.err.println("---component: " + graph.getPossibleURI(d2.component));
+ System.err.println("---type: " + graph.getPossibleURI(d2.componentType));
+ System.err.println("---cp: " + graph.getPossibleURI(d2.cp));
+ System.err.println("---var: " + d2.getVariable(graph).getURI(graph));
+ }
+
+ }
+
public static class ConnectionVariables extends BinaryRead<Variable, List<Resource>, Collection<VariableConnectionPointDescriptor>> {
private ConnectionVariables(Variable parameter1, List<Resource> parameter2) {
@Override
public Collection<VariableConnectionPointDescriptor> perform(ReadGraph graph) throws DatabaseException {
if(parameter == null) return Collections.emptyList();
+ Layer0 L0 = Layer0.getInstance(graph);
StructuralResource2 STR = StructuralResource2.getInstance(graph);
ArrayList<VariableConnectionPointDescriptor> result = null;
for(int i=1;i<parameter2.size();i++) {
Resource component = stm.getObject();
Resource connectionPoint = graph.getInverse(stm.getPredicate());
if(result == null) result = new ArrayList<VariableConnectionPointDescriptor>();
- result.add(new ActualConnectionDescriptor(parameter, component, connectionPoint));
+ String componentName = graph.getRelatedValue(component, L0.HasName, Bindings.STRING);
+ Variable possibleChild = parameter.getPossibleChild(graph, componentName);
+ if(possibleChild != null) {
+ Resource type = possibleChild.getPossibleType(graph, STR.Component);
+ if(type != null) {
+ result.add(new ActualConnectionDescriptor(parameter, component, possibleChild.getType(graph), connectionPoint));
+ } else {
+ throw new DatabaseException("Child does not have a structural type: " + possibleChild.getURI(graph));
+ }
+ } else {
+ Resource type = graph.getPossibleType(component, STR.Component);
+ if(type != null) {
+ result.add(new ActualConnectionDescriptor(parameter, component, type, connectionPoint));
+ } else {
+ throw new DatabaseException("Child with name " + componentName + " does not have a structural type: " + parameter.getURI(graph));
+ }
+ }
}
}
if(result == null) return Collections.emptyList();
@Override
public Boolean perform(ReadGraph graph) throws DatabaseException {
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
-
- if(graph.isInstanceOf(resource, STR.ProceduralComponentType)) return false;
- if(graph.hasStatement(resource, STR.IsDefinedBy)) return false;
-
- return true;
+ StructuralComponentClass clazz = StructuralComponentClass.get(graph, resource);
+ return StructuralComponentClass.PRIMITIVE.equals(clazz);
}
public static Collection<VariableConnectionPointDescriptor> doFlatten(ReadGraph graph, Variable child, Resource cp, Resource relationType) throws DatabaseException {
- Collection<VariableConnectionPointDescriptor> climbed = climb(graph, child, cp, null);
- boolean needDrill = false;
+ Set<VariableConnectionPointDescriptor> result = null;
+ Set<VariableConnectionPointDescriptor> needDrill = null;
+
+ Collection<VariableConnectionPointDescriptor> climbed = climb(graph, child, cp, null);
for(VariableConnectionPointDescriptor desc : climbed) {
if(!desc.isLeaf(graph)) {
- needDrill = true;
- break;
+ if(needDrill == null)
+ needDrill = new THashSet<VariableConnectionPointDescriptor>(climbed.size());
+ needDrill.add(desc);
+ } else {
+ if(relationType != null) {
+ if(!filterByRelationType(graph, desc, relationType))
+ continue;
+ }
+ if(result == null)
+ result = new THashSet<VariableConnectionPointDescriptor>(climbed.size());
+ result.add(desc);
}
}
- if(!needDrill) {
- if(relationType != null) {
- ArrayList<VariableConnectionPointDescriptor> filtered = new ArrayList<VariableConnectionPointDescriptor>(climbed.size());
- for(VariableConnectionPointDescriptor desc : climbed)
- if(filterByRelationType(graph, desc, relationType))
- filtered.add(desc);
- return filtered;
+ if(needDrill != null) {
+ /*
+ * There were some descriptors that require drill
+ */
+ for(VariableConnectionPointDescriptor top : needDrill) {
+ Collection<VariableConnectionPointDescriptor> drilled = drill(graph, top);
+ if(drilled != null) {
+ for(VariableConnectionPointDescriptor drill : drilled) {
+ if(relationType != null) {
+ if(!filterByRelationType(graph, drill, relationType))
+ continue;
+ }
+ if(result == null)
+ result = new THashSet<VariableConnectionPointDescriptor>(climbed.size());
+ result.add(drill);
+ }
+ }
}
- return climbed;
}
-
- THashSet<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>(climbed.size());
- for(VariableConnectionPointDescriptor top : climbed) {
- Collection<VariableConnectionPointDescriptor> drilled = drill(graph, top);
- if(drilled != null) {
- for(VariableConnectionPointDescriptor drill : drilled) {
- if(relationType != null) {
- if(!filterByRelationType(graph, drill, relationType))
- continue;
- }
- result.add(drill);
- }
- }
+
+ if (result != null) {
+ return result;
+ } else {
+ return Collections.emptySet();
}
- return result;
-
}
private static boolean filterByRelationType(ReadGraph graph, VariableConnectionPointDescriptor desc, Resource relationType) throws DatabaseException {