Message box correction to show it only once with the list of refefenced features.
return aResult;
}
-void Model_Document::removeFeature(FeaturePtr theFeature, const bool theCheck)
+void Model_Document::refsToFeature(FeaturePtr theFeature,
+ std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
+ const bool isSendError)
{
- if (theCheck) {
- // check the feature: it must have no depended objects on it
- std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
- for(; aResIter != theFeature->results().cend(); aResIter++) {
- std::shared_ptr<Model_Data> aData =
- std::dynamic_pointer_cast<Model_Data>((*aResIter)->data());
- if (aData && !aData->refsToMe().empty()) {
- Events_Error::send(
- "Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
- return;
- }
+ // check the feature: it must have no depended objects on it
+ std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
+ for(; aResIter != theFeature->results().cend(); aResIter++) {
+ ResultPtr aResult = (*aResIter);
+ std::shared_ptr<Model_Data> aData =
+ std::dynamic_pointer_cast<Model_Data>(aResult->data());
+ if (aData && !aData->refsToMe().empty()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
+ if (aFeature.get() != NULL)
+ theRefs.insert(aFeature);
}
}
+ if (!theRefs.empty() && isSendError) {
+ Events_Error::send(
+ "Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
+ }
+}
+void Model_Document::removeFeature(FeaturePtr theFeature/*, const bool theCheck*/)
+{
std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theFeature->data());
if (aData) {
TDF_Label aFeatureLabel = aData->label().Father();
//! \param theID creates feature and puts it in the document
MODEL_EXPORT virtual FeaturePtr addFeature(std::string theID);
+ //! Return a list of features, which refers to the feature
+ //! \param theFeature a feature
+ //! \param theRefs a list of reference features
+ //! \param isSendError a flag whether the error message should be send
+ MODEL_EXPORT virtual void refsToFeature(FeaturePtr theFeature,
+ std::set<FeaturePtr>& theRefs,
+ const bool isSendError = true);
+
//! Removes the feature from the document (with result)
- //! \param theFeature the feature to be removed
- //! \param theCheck if it is false, do not check the references
- MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature, const bool theCheck = true);
+ //! \param theFeature a removed feature
+ MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature);
//! Returns the existing feature by the label
//! \param theLabel base label of the feature
#include <memory>
#include <vector>
#include <list>
+#include <set>
class ModelAPI_Feature;
class ModelAPI_Object;
//! \param theID creates feature and puts it in the document (if it is not action)
virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
+ //! Return a list of features, which refers to the feature
+ //! \param theFeature a feature
+ //! \param theRefs a list of features
+ //! \param isSendError a flag whether the error message should be send
+ virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
+ std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
+ const bool isSendError = true) = 0;
+
//! Removes the feature from the document
- virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
- const bool theCheck = true) = 0;
+ //! \param theFeature a feature to be removed
+ virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID) = 0;
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_ResultPart.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Feature.h>
void PartSetPlugin_Remove::execute()
{
if (aFeature) {
// do remove
aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
- aRoot->removeFeature(aFeature);
+ std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
+ aRoot->refsToFeature(aFeature, aRefFeatures);
+ if (aRefFeatures.empty())
+ aRoot->removeFeature(aFeature);
}
}
}
for (; anIt != aFeatures.end(); anIt++) {
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
if (aFeature) {
- // subs are referenced from sketch, but must be removed for sure, so not checkings
- document()->removeFeature(aFeature, false);
+ // subs are referenced from sketch, but must be removed for sure, so not checkings
+ document()->removeFeature(aFeature);
}
}
ModelAPI_CompositeFeature::erase();
void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
{
QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
- QMessageBox::StandardButton aRes = QMessageBox::warning(
- aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"),
- QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
- // ToDo: definbe deleting method
- if (aRes == QMessageBox::Yes) {
- SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation();
- foreach (ObjectPtr aObj, theList)
- {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
- if (aPart) {
- DocumentPtr aDoc = aPart->document();
- if (aDoc == aMgr->activeDocument()) {
- aDoc->close();
- }
- //aMgr->moduleDocument()->removeFeature(aPart->owner());
- } else {
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
- if (aFeature)
- aObj->document()->removeFeature(aFeature);
+
+ std::set<FeaturePtr> aRefFeatures;
+ foreach (ObjectPtr aObj, theList)
+ {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+ if (aPart) {
+ // TODO: check for what there is this condition. It is placed here historicaly because
+ // ther is this condition during remove features.
+ } else {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature) {
+ aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
}
}
- myDisplayer->updateViewer();
- aMgr->finishOperation();
}
+
+ if (!aRefFeatures.empty()) {
+ QStringList aRefNames;
+ std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
+ aLast = aRefFeatures.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = (*anIt);
+ std::string aFName = aFeature->data()->name().c_str();
+ std::string aName = (*anIt)->name().c_str();
+ aRefNames.append((*anIt)->name().c_str());
+ }
+ QString aNames = aRefNames.join(", ");
+
+ QMessageBox::StandardButton aRes = QMessageBox::warning(
+ aDesktop, tr("Delete features"),
+ QString(tr("Selected features are used in the following features: %1.\
+These features will be deleted also. Would you like to continue?")).arg(aNames),
+ QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
+ if (aRes != QMessageBox::Yes)
+ return;
+ }
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ aMgr->startOperation();
+ foreach (ObjectPtr aObj, theList)
+ {
+ DocumentPtr aDoc = aObj->document();
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+ if (aPart) {
+ if (aDoc == aMgr->activeDocument()) {
+ aDoc->close();
+ }
+ } else {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature) {
+ aDoc->removeFeature(aFeature);
+ }
+ }
+ }
+ myDisplayer->updateViewer();
+ aMgr->finishOperation();
}
//**************************************************************