]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Procedural connectivity was broken
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 2 Nov 2018 04:49:03 +0000 (06:49 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Fri, 2 Nov 2018 04:49:03 +0000 (06:49 +0200)
Change-Id: I0b8f2f35f0eef887a40517d53f220609398448d9

bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java

index 3f5219e6176aa9aed61b5f8278cf21a52e939697..524d2737ca2e144c2bd0fc7a60a01aa9b523a9ad 100644 (file)
@@ -15,15 +15,21 @@ import gnu.trove.set.hash.THashSet;
 
 public class FixedConnection implements Connection, Connection2 {
 
-    final private Variable parent;
+    /*
+     * This is the parent of the component to be connected
+     */
+    final private Variable procedural;
     
     final private Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
     
-    public FixedConnection(Variable parent) {
-        this.parent = parent;
+    public FixedConnection(Variable procedural) {
+        this.procedural = procedural;
     }
     
     public void addAll(List<Pair<String,Resource>> cps) throws DatabaseException {
+        /*
+         * For interface connections the name is null
+         */
         for(Pair<String,Resource> cp : cps) {
             this.cps.add(cp);
         }
@@ -35,30 +41,59 @@ public class FixedConnection implements Connection, Connection2 {
     
     public void addConnectionDescriptors(ReadGraph graph, Variable curConfiguration, Collection<VariableConnectionPointDescriptor> result) throws DatabaseException {
         for(Pair<String,Resource> cpzz : cps) {
-            // This is a connection to an interface terminal. It is handled by ConnectionBrowser in separate logic. Do not include it here.
-            if(cpzz.first == null) continue;
-            /*if(cpzz.first == null) {
-                String message = "Lifted connection was not resolved. Child = " + parent.getURI(graph);
+            // This is a connection to an interface terminal. It is handled by ConnectionBrowser in separate logic. We should never have gotten this far
+            if(cpzz.first == null) {
+                String message = "Lifted connection was not resolved. Child = " + procedural.getURI(graph);
                 throw new DatabaseException(message);
-            }*/
+            }
             result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
         }
     }
     
     @Override
     public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
-        return getConnectionPoints(graph, parent, relationType);
+        Set<Variable> result = new THashSet<Variable>();
+        for(Pair<String,Resource> cp : cps) {
+            Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first); 
+            Variable cp2 = component.getPossibleProperty(graph, cp.second);
+            if(cp2 != null)
+                for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
+                    result.add(desc.getVariable(graph));
+                }
+            else
+                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+        }
+        return result;
     }
     
        @Override
        public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
-           return getConnectionPointURIs(graph, parent, relationType);
-               
+        Set<String> result = new THashSet<String>();
+        for(Pair<String,Resource> cp : cps) {
+            Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
+            Variable cp2 = component.getPossibleProperty(graph, cp.second);
+            if(cp2 != null)
+                for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
+                    result.add(desc.getURI(graph));
+                }
+            else
+                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+        }
+        return result;
        }
        
        @Override
        public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
-           return getConnectionPointDescriptors(graph, parent, relationType);
+        Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
+        for(Pair<String,Resource> cp : cps) {
+            Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first); 
+            Variable cp2 = component.getPossibleProperty(graph, cp.second);
+            if(cp2 != null)
+                result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
+            else
+                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+        }
+        return result;
        }
 
     @Override
@@ -67,7 +102,7 @@ public class FixedConnection implements Connection, Connection2 {
                int result = 1;
                result = prime * result + ((cps == null) ? 0 : cps.hashCode());
                result = prime * result
-                               + ((parent == null) ? 0 : parent.hashCode());
+                               + ((procedural == null) ? 0 : procedural.hashCode());
                return result;
        }
 
@@ -85,20 +120,20 @@ public class FixedConnection implements Connection, Connection2 {
                                return false;
                } else if (!cps.equals(other.cps))
                        return false;
-               if (parent == null) {
-                       if (other.parent != null)
+               if (procedural == null) {
+                       if (other.procedural != null)
                                return false;
-               } else if (!parent.equals(other.parent))
+               } else if (!procedural.equals(other.procedural))
                        return false;
                return true;
        }
 
        @Override
        public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
-               Variable parent, Resource relationType) throws DatabaseException {
+               Variable component_, Resource relationType) throws DatabaseException {
         Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
         for(Pair<String,Resource> cp : cps) {
-            Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); 
+            Variable component = cp.first == null ? component_.getParent(graph) : component_;
             Variable cp2 = component.getPossibleProperty(graph, cp.second);
             if(cp2 != null)
                 result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
@@ -109,11 +144,11 @@ public class FixedConnection implements Connection, Connection2 {
        }
        
        @Override
-       public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable parent, Resource relationType)
+       public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component_, Resource relationType)
                throws DatabaseException {
         Set<Variable> result = new THashSet<Variable>();
         for(Pair<String,Resource> cp : cps) {
-            Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); 
+            Variable component = cp.first == null ? component_.getParent(graph) : component_;
             Variable cp2 = component.getPossibleProperty(graph, cp.second);
             if(cp2 != null)
                 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
@@ -126,11 +161,11 @@ public class FixedConnection implements Connection, Connection2 {
        }
        
        @Override
-       public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable parent, Resource relationType)
+       public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component_, Resource relationType)
                throws DatabaseException {
         Set<String> result = new THashSet<String>();
         for(Pair<String,Resource> cp : cps) {
-            Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
+            Variable component = cp.first == null ? component_.getParent(graph) : component_;
             Variable cp2 = component.getPossibleProperty(graph, cp.second);
             if(cp2 != null)
                 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {