@@ -269,15 +269,34 @@ Data::MappedElement Feature::searchByConnectedElements(TopoShape newShape, TopoS
269269
270270 // filter the ancestors to find one that can't be traced back to the oldShape
271271
272- for (const auto & ancestor : commonAncestors) {
273- if (!oldShape.getElementName (ancestor.name .toString ().c_str ()).index .toString ().size ()) {
274- Base::Console ().log (" Search by connected elements resolved: " );
275- Base::Console ().log (ancestor.index .toString ().c_str ());
276- Base::Console ().log (" | " );
277- Base::Console ().log (ancestor.name .toString ().c_str ());
278- Base::Console ().log (" \n " );
279-
280- return ancestor;
272+ if (commonAncestors.size () == 1 ) {
273+ Base::Console ().log (" Search by connected elements resolved: " );
274+ Base::Console ().log (commonAncestors[0 ].index .toString ().c_str ());
275+ Base::Console ().log (" | " );
276+ Base::Console ().log (commonAncestors[0 ].name .toString ().c_str ());
277+ Base::Console ().log (" | found connected ancestor size: " );
278+ Base::Console ().log (std::to_string (commonAncestors.size ()).c_str ());
279+ Base::Console ().log (" \n " );
280+
281+ return commonAncestors[0 ];
282+ } else if (commonAncestors.size ()) {
283+ for (const auto & commonAncestor : commonAncestors) {
284+ std::vector<TopoShape> relatedAncestors = getRelatedAncestors (newShape, oldShape, newShape.getSubTopoShape (commonAncestor.name .toString ().c_str ()), recursionCount);
285+ std::vector<Data::MappedElement> subCommonAncestors = getCommonAncestors (oldShape, relatedAncestors, oldElement.shapeType (), recursionCount);
286+
287+ for (const auto & subCommonAncestor : subCommonAncestors) {
288+ if (subCommonAncestor.name == name) {
289+ Base::Console ().log (" Search by connected elements resolved: " );
290+ Base::Console ().log (commonAncestor.index .toString ().c_str ());
291+ Base::Console ().log (" | " );
292+ Base::Console ().log (commonAncestor.name .toString ().c_str ());
293+ Base::Console ().log (" | found connected ancestor size: " );
294+ Base::Console ().log (std::to_string (commonAncestors.size ()).c_str ());
295+ Base::Console ().log (" \n " );
296+
297+ return commonAncestor;
298+ }
299+ }
281300 }
282301 }
283302 }
0 commit comments