]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java
Merge changes I78c3a258,I7bf72f04
[simantics/platform.git] / bundles / org.simantics.structural.synchronization / src / org / simantics / structural / synchronization / base / SynchronizationEventHandlerBase.java
index a6efeefb2534bc402c25cfc671705ccbb6ad0cbb..095640c4aa1f0a2185da8bd6a92010421da6d63a 100644 (file)
@@ -201,10 +201,14 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
 
                     // TODO these two lines can be removed when IncludedInSimulation -property is given to all composites
                     if(component.getParent() != null) {
-                       String parentName = solver.getName(component.getParent().getModuleId());
-                       solver.includeSubprocess(parentName, subprocessName);
-                       component.solverComponentName = subprocessName;
-                       solverComponentNameToComponent.put(subprocessName, component);
+                        int nearestParentId = getNearestParentComponentId(component);
+                        if (nearestParentId <= 0) {
+                            throw new SynchronizationException("Could not find parent with non-zero component id from Component("+name+", " + (component != null ? component.uid : "null") + "," + typeId + ")");
+                        }
+                        String parentName = solver.getName(nearestParentId);
+                        solver.includeSubprocess(parentName, subprocessName);
+                        component.solverComponentName = subprocessName;
+                        solverComponentNameToComponent.put(subprocessName, component);
                     }
                     
                     if(updater.isComposite) {
@@ -248,7 +252,7 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
                     if(oldChildMap != null)
                         for(T component : oldChildMap.values()) {
                             component.clearParent();
-                            mapping.addPendingRemoval(component);
+                            addPendingRemoval(component);
                         }
                 }
                 // Alternative implementation when uids are not available.
@@ -275,7 +279,7 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
                     if(oldChildMap != null)
                         for(T component : oldChildMap.values()) {
                             component.clearParent();
-                            mapping.addPendingRemoval(component);
+                            addPendingRemoval(component);
                         }
                 }
 
@@ -334,6 +338,23 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
         }
     }
 
+    private static int getNearestParentComponentId(ComponentBase<?> component) {
+        ComponentBase<?> parent = component.getParent();
+        while (parent != null) {
+            int pid = parent.getModuleId();
+            if (pid > 0)
+                return pid;
+            parent = parent.getParent();
+        }
+        return -1;
+    }
+
+    protected void addPendingRemoval(T component) {
+        if (TRACE_EVENTS)
+            System.out.println("addPendingRemoval(" + component.componentId + " : " + component.solverComponentName + ")");
+        mapping.addPendingRemoval(component);
+    }
+
     private String getSubprocessName(String name,
             Collection<SerializedVariable> properties) {
         for(SerializedVariable property : properties)