1 package org.simantics.structural2.internal.queries;
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.HashSet;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.Statement;
11 import org.simantics.db.common.request.ResourceRead2;
12 import org.simantics.db.common.utils.NameUtils;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.structural.stubs.StructuralResource2;
15 import org.simantics.structural2.queries.Terminal;
16 import org.simantics.structural2.utils.StructuralUtils;
19 * @author Tuukka Lehtonen
21 public class ConnectedTo extends ResourceRead2<Set<Terminal>> {
23 private static final boolean DEBUG = false;
25 public ConnectedTo(Resource component, Resource connectionPoint) {
26 super(component, connectionPoint);
30 public Set<Terminal> perform(ReadGraph graph) throws DatabaseException {
32 System.out.println("connectedTo(" + NameUtils.getSafeName(graph, resource) + ", " + NameUtils.getSafeName(graph, resource2) + ")");
34 Collection<Resource> connections = graph.getObjects(resource, resource2);
35 if (connections.isEmpty())
36 return Collections.emptySet();
38 Set<Resource> reachableConnections = new HashSet<Resource>();
39 for (Resource connection : connections) {
40 reachableConnections.addAll(StructuralUtils.getRelatedConnections(graph, connection));
43 StructuralResource2 sr = StructuralResource2.getInstance(graph);
45 Set<Terminal> connectedTo = new HashSet<Terminal>();
47 for (Resource connection : reachableConnections) {
49 System.out.println(" checking connection: " + NameUtils.getSafeName(graph, connection));
51 for (Statement stm : graph.getStatements(connection, sr.Connects)) {
52 Resource connectionPoint2 = graph.getInverse(stm.getPredicate());
53 if (resource2.equals(connectionPoint2) && resource.equals(stm.getObject()))
57 System.out.println(" connected to (" + NameUtils.getSafeName(graph, stm.getObject()) + ", " + NameUtils.getSafeName(graph, connectionPoint2) + ")");
59 connectedTo.add(new Terminal(stm.getObject(), connectionPoint2));