From: Tuukka Lehtonen Date: Wed, 11 Sep 2019 21:32:39 +0000 (+0300) Subject: Handle componentless parent nodes of UCs in synchronization X-Git-Tag: v1.43.0~136^2~70^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F3246%2F1;p=simantics%2Fplatform.git Handle componentless parent nodes of UCs in synchronization gitlab #382 Change-Id: I78c3a258e5a33cb16ae38ef080424d382f42c710 --- diff --git a/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java b/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java index 67b120b64..095640c4a 100644 --- a/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java +++ b/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java @@ -201,10 +201,14 @@ public abstract class SynchronizationEventHandlerBase // 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) { @@ -334,6 +338,17 @@ public abstract class SynchronizationEventHandlerBase } } + 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 + ")");