From: spo Date: Wed, 8 Jul 2015 09:33:45 +0000 (+0300) Subject: Issue #660 - Move Group is still not implemented -- Check refs only between the selec... X-Git-Tag: V_1.3.0~79 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=01159d19136fded13c08b72974dc897173376eb4;p=modules%2Fshaper.git Issue #660 - Move Group is still not implemented -- Check refs only between the selected and the current features --- diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 533443827..bf5be2e6b 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1250,15 +1250,55 @@ bool hasResults(QObjectPtrList theObjects, const std::set& theTypes } //************************************************************** +// Returns the list of features placed between theObject and the current feature +// in the same document. Excludes theObject, includes the current feature. +std::list toCurrentFeatures(const ObjectPtr& theObject) +{ + std::list aResult; + DocumentPtr aDocument = theObject->document(); + std::list anAllFeatures = aDocument->allFeatures(); + // find the object iterator + std::list::iterator aObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject); + if (aObjectIt == anAllFeatures.end()) + return aResult; + // find the current feature iterator + std::list::iterator aCurrentIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true)); + if (aCurrentIt == anAllFeatures.end()) + return aResult; + // check the right order + if (std::distance(aObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end())) + return aResult; + // exclude the object + std::advance(aObjectIt, 1); + // include the current feature + std::advance(aCurrentIt, 1); + return std::list(aObjectIt, aCurrentIt); +} + bool XGUI_Workshop::canMoveFeature() { QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); - std::set aRefFeatures; foreach (ObjectPtr aObject, aObjects) { - std::set aFeatures = refFeatures(aObject, false); - aRefFeatures.insert(aFeatures.begin(), aFeatures.end()); + // 1. Get features placed between selected and current in the document + std::list aFeaturesBetween = toCurrentFeatures(aObject); + // if aFeaturesBetween is empty it means wrong order or aObject is the current feature + if (aFeaturesBetween.empty()) + return false; + std::set aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end()); + // 2. Get all reference features to the selected object in the document + std::set aRefFeatures = refFeatures(aObject, false); + if (aRefFeatures.empty()) + continue; + // 3. Find any placed features in all reference features + std::set aIntersectionFeatures; + std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(), + aPlacedFeatures.begin(), aPlacedFeatures.end(), + std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin())); + // 4. Return false if any reference feature is placed before curent feature + if (!aIntersectionFeatures.empty()) + return false; } - return aRefFeatures.empty(); + return true; } //**************************************************************