X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Tools.cpp;h=9bb1dfa84d357c5c5c3cde1cbdad0019ebbab8ea;hb=220bd2b37119be1c65abf88a88792445cb9d99f8;hp=b835629a7e37dbbb877aef8592f488b87741f4e0;hpb=1a7281af4aeb1c5fe521989cc66e4e8c5870a576;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index b835629a7..9bb1dfa84 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -2,6 +2,11 @@ #include "XGUI_Tools.h" +#include "XGUI_ModuleConnector.h" +#include "XGUI_Workshop.h" + +#include "ModuleBase_IWorkshop.h" + #include #include #include @@ -11,6 +16,8 @@ #include #include #include +#include +#include #include @@ -54,6 +61,18 @@ QString addSlash(const QString& path) return res; } +//****************************************************************** +QString unionOfObjectNames(const QObjectPtrList& theObjects, const QString& theSeparator) +{ + QStringList aObjectNames; + foreach (ObjectPtr aObj, theObjects) { + if (!aObj->data()->isValid()) + continue; + aObjectNames << QString::fromStdString(aObj->data()->name()); + } + return aObjectNames.join(", "); +} + //****************************************************************** bool isModelObject(FeaturePtr theFeature) { @@ -104,6 +123,24 @@ bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects) return aResult; } +//****************************************************************** +bool canRename(const ObjectPtr& theObject, const QString& theName) +{ + if (std::dynamic_pointer_cast(theObject).get()) { + double aValue; + ResultParameterPtr aParam; + if (ModelAPI_Tools::findVariable(theObject->document(), qPrintable(theName), aValue, aParam)) { + QString aErrMsg(QObject::tr("Selected parameter can not be renamed to: %1. \ + There is a parameter with the same name. Its value is: %2.").arg(qPrintable(theName)).arg(aValue)); + // We can not use here a dialog box for message - it will crash editing process in ObjectBrowser + Events_Error::send(aErrMsg.toStdString()); + return false; + } + } + + return true; +} + //****************************************************************** bool allDocumentsActivated(QString& theNotActivatedNames) { @@ -154,13 +191,69 @@ bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature) return isSub; } +//************************************************************** +bool isSubOfComposite(const ObjectPtr& theObject) +{ + bool isSub = false; + std::set aRefFeatures; + refsToFeatureInFeatureDocument(theObject, aRefFeatures); + std::set::const_iterator anIt = aRefFeatures.begin(), + aLast = aRefFeatures.end(); + for (; anIt != aLast && !isSub; anIt++) { + isSub = isSubOfComposite(theObject, *anIt); + } + return isSub; +} + //************************************************************** void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject, - std::set& theRefFeatures) + const QObjectPtrList& theIgnoreList, + std::set& theDirectRefFeatures, + std::set& theIndirectRefFeatures, + std::set& theAlreadyProcessed) +{ + refsDirectToFeatureInAllDocuments(theSourceObject, theObject, theIgnoreList, theDirectRefFeatures, + theAlreadyProcessed); + + // Run recursion. It is possible recursive dependency, like the following: plane, extrusion uses plane, + // axis is built on extrusion. Delete of a plane should check the dependency from the axis also. + std::set::const_iterator aFeatureIt = theDirectRefFeatures.begin(); + for (; aFeatureIt != theDirectRefFeatures.end(); ++aFeatureIt) { + std::set aRecursiveRefFeatures; + refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, theIgnoreList, + aRecursiveRefFeatures, aRecursiveRefFeatures, theAlreadyProcessed); + theIndirectRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end()); + } + +} + +//************************************************************** +void refsDirectToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject, + const QObjectPtrList& theIgnoreList, + std::set& theDirectRefFeatures, + std::set& theAlreadyProcessed) { FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (!aFeature.get()) return; + if (theAlreadyProcessed.find(aFeature) != theAlreadyProcessed.end()) + return; + theAlreadyProcessed.insert(aFeature); + + //convert ignore object list to containt sub-features if the composite feature is in the list + QObjectPtrList aFullIgnoreList; + QObjectPtrList::const_iterator anIIt = theIgnoreList.begin(), anILast = theIgnoreList.end(); + for (; anIIt != anILast; anIIt++) { + aFullIgnoreList.append(*anIIt); + CompositeFeaturePtr aComposite = std::dynamic_pointer_cast(*anIIt); + // if the current feature is aborted, the composite is removed and has invalid data + if (aComposite.get() && aComposite->data()->isValid()) { + int aNbSubs = aComposite->numberOfSubs(); + for (int aSub = 0; aSub < aNbSubs; aSub++) { + aFullIgnoreList.append(aComposite->subFeature(aSub)); + } + } + } // 1. find references in the current document std::set aRefFeatures; @@ -168,8 +261,9 @@ void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectP std::set::const_iterator anIt = aRefFeatures.begin(), aLast = aRefFeatures.end(); for (; anIt != aLast; anIt++) { - if (!isSubOfComposite(theSourceObject, *anIt)) - theRefFeatures.insert(*anIt); + // composite feature should not be deleted when the sub feature is to be deleted + if (!isSubOfComposite(theSourceObject, *anIt) && !aFullIgnoreList.contains(*anIt)) + theDirectRefFeatures.insert(*anIt); } // 2. find references in all documents if the document of the feature is @@ -223,20 +317,18 @@ void refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectP } } } - if (aHasReferenceToObject && !isSubOfComposite(theSourceObject, aFeature)) - theRefFeatures.insert(aFeature); + if (aHasReferenceToObject && !isSubOfComposite(theSourceObject, aFeature) && + !theIgnoreList.contains(aFeature)) + theDirectRefFeatures.insert(aFeature); } } } +} - // Run recursion. It is possible recusive dependency, like the folowing: plane, extrusion uses plane, - // axis is built on extrusion. Delete of a plane should check the dependency from the axis also. - std::set aRecursiveRefFeatures; - std::set::const_iterator aFeatureIt = theRefFeatures.begin(); - for (; aFeatureIt != theRefFeatures.end(); ++aFeatureIt) { - refsToFeatureInAllDocuments(theSourceObject, *aFeatureIt, aRecursiveRefFeatures); - } - theRefFeatures.insert(aRecursiveRefFeatures.begin(), aRecursiveRefFeatures.end()); +XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop) +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); + return aConnector->workshop(); } }