Salome HOME
2.5. Select the point of a sketch entity must display the editing point panel
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 1747b7495e5ae59ac7dd05cf4c998bb9f7e83475..eebe7c38bc7354caad96142ce4e277105f1b7231 100755 (executable)
@@ -242,6 +242,7 @@ void XGUI_Workshop::activateModule()
   QIntList aModes;
   module()->activeSelectionModes(aModes);
   aDisplayer->activateObjects(aModes, aDisplayed);
+  myOperationMgr->activate();
 }
 
 void XGUI_Workshop::deactivateModule()
@@ -259,6 +260,8 @@ void XGUI_Workshop::deactivateModule()
   XGUI_Displayer* aDisplayer = displayer();
   QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
   aDisplayer->deactivateObjects(aDisplayed, true);
+
+  myOperationMgr->deactivate();
 }
 
 //******************************************************
@@ -564,13 +567,15 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
     return;
 
   showPropertyPanel();
-  QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
-  ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
-
   myPropertyPanel->cleanContent();
-  aFactory.createWidget(myPropertyPanel->contentWidget());
 
-  QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
+  QList<ModuleBase_ModelWidget*> aWidgets;
+  if (!module()->createWidgets(theOperation, aWidgets)) {
+    QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
+    ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
+    aFactory.createWidget(myPropertyPanel->contentWidget());
+    aWidgets = aFactory.getModelWidgets();
+  }
 
   // check compatibility of feature and widgets
   FeaturePtr aFeature = aFOperation->feature();
@@ -1060,11 +1065,11 @@ void XGUI_Workshop::createDockWidgets()
 
   QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
   connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
-  connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
-          myOperationMgr,  SLOT(onKeyReleased(QKeyEvent*)));
+  connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
+          myOperationMgr,  SLOT(onKeyReleased(QObject*, QKeyEvent*)));
 
-  connect(myPropertyPanel, SIGNAL(enterClicked()),
-          myOperationMgr,  SLOT(onProcessEnter()));
+  connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
+          myOperationMgr,  SLOT(onProcessEnter(QObject*)));
 }
 
 //******************************************************
@@ -1179,9 +1184,6 @@ void XGUI_Workshop::deleteObjects()
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
   if (!abortAllOperations())
     return;
-  // It is necessary to clear selection in order to avoid selection changed event during
-  // deletion and negative consequences connected with processing of already deleted items
-  mySelector->clearSelection();
   // check whether the object can be deleted. There should not be parts which are not loaded
   if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects))
     return;
@@ -1202,11 +1204,20 @@ void XGUI_Workshop::deleteObjects()
 
   // 3. delete objects
   std::set<FeaturePtr> anIgnoredFeatures;
-  if (deleteFeatures(anObjects, anIgnoredFeatures, desktop(), true)) {
-    operationMgr()->commitOperation();
-  }
-  else {
-    operationMgr()->abortOperation(operationMgr()->currentOperation());
+  std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
+  findReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures);
+
+  bool doDeleteReferences = true;
+  if (isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures,
+                                    desktop(), doDeleteReferences)) {
+    // It is necessary to clear selection in order to avoid selection changed event during
+    // deletion and negative consequences connected with processing of already deleted items
+    mySelector->clearSelection();
+    if (deleteFeaturesInternal(anObjects, aDirectRefFeatures, aIndirectRefFeatures,
+                               anIgnoredFeatures, doDeleteReferences))
+      operationMgr()->commitOperation();
+    else
+      operationMgr()->abortOperation(operationMgr()->currentOperation());
   }
 }
 
@@ -1217,20 +1228,30 @@ void XGUI_Workshop::cleanHistory()
     return;
 
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
-
-  // 1. find all referenced features
-  QList<ObjectPtr> anUnusedObjects;
-  std::set<FeaturePtr> aDirectRefFeatures;
+  QObjectPtrList aFeatures;
   foreach (ObjectPtr anObject, anObjects) {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
     // for parameter result, use the corresponded reature to be removed
     if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
       aFeature = ModelAPI_Feature::feature(anObject);
     }
+    aFeatures.append(aFeature);
+  }
+
+  // 1. find all referenced features
+  QList<ObjectPtr> anUnusedObjects;
+  std::set<FeaturePtr> aDirectRefFeatures;
+  //foreach (ObjectPtr anObject, anObjects) {
+  foreach (ObjectPtr anObject, aFeatures) {
+    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+    // for parameter result, use the corresponded reature to be removed
+    //if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
+    //  aFeature = ModelAPI_Feature::feature(anObject);
+    //}
     if (aFeature.get()) {
       std::set<FeaturePtr> alreadyProcessed;
       aDirectRefFeatures.clear();
-      XGUI_Tools::refsDirectToFeatureInAllDocuments(aFeature, aFeature, anObjects,
+      XGUI_Tools::refsDirectToFeatureInAllDocuments(aFeature, aFeature, aFeatures,
                                                     aDirectRefFeatures, alreadyProcessed);
       if (aDirectRefFeatures.empty() && !anUnusedObjects.contains(aFeature))
         anUnusedObjects.append(aFeature);
@@ -1312,23 +1333,10 @@ void XGUI_Workshop::moveObjects()
 }
 
 //**************************************************************
-bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
-                                   const std::set<FeaturePtr>& theIgnoredFeatures,
-                                   QWidget* theParent,
-                                   const bool theAskAboutDeleteReferences)
+void XGUI_Workshop::findReferences(const QObjectPtrList& theList,
+                                   std::set<FeaturePtr>& aDirectRefFeatures,
+                                   std::set<FeaturePtr>& aIndirectRefFeatures)
 {
-#ifdef DEBUG_DELETE
-  QStringList aDInfo;
-  QObjectPtrList::const_iterator aDIt = theList.begin(), aDLast = theList.end();
-  for (; aDIt != aDLast; ++aDIt) {
-    aDInfo.append(ModuleBase_Tools::objectInfo((*aDIt)));
-  }
-  QString anInfoStr = aDInfo.join(", ");
-  qDebug(QString("deleteFeatures: %1, %2").arg(theList.size()).arg(anInfoStr).toStdString().c_str());
-#endif
-
-  // 1. find all referenced features
-  std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
   foreach (ObjectPtr aDeletedObj, theList) {
     std::set<FeaturePtr> alreadyProcessed;
     XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, theList, aDirectRefFeatures,
@@ -1339,11 +1347,17 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
                         std::inserter(aDifference, aDifference.begin()));
     aIndirectRefFeatures = aDifference;
   }
+}
 
-  bool doDeleteReferences = true;
+bool XGUI_Workshop::isDeleteFeatureWithReferences(const QObjectPtrList& theList,
+                                   const std::set<FeaturePtr>& aDirectRefFeatures,
+                                   const std::set<FeaturePtr>& aIndirectRefFeatures,
+                                   QWidget* theParent,
+                                   bool& doDeleteReferences)
+{
+  doDeleteReferences = true;
 
-  // 2. warn about the references remove, break the delete operation if the user chose it
-  if (theAskAboutDeleteReferences && !aDirectRefFeatures.empty()) {
+  if (!aDirectRefFeatures.empty()) {
     QStringList aDirectRefNames;
     foreach (const FeaturePtr& aFeature, aDirectRefFeatures)
       aDirectRefNames.append(aFeature->name().c_str());
@@ -1391,8 +1405,24 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
       doDeleteReferences = false;
     }
   }
+  return true;
+}
 
-  // 3. remove referenced features
+bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theFeatures,
+                                   const std::set<FeaturePtr>& theIgnoredFeatures)
+{
+  std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
+  findReferences(theFeatures, aDirectRefFeatures, aIndirectRefFeatures);
+  return deleteFeaturesInternal(theFeatures, aDirectRefFeatures, aIndirectRefFeatures,
+                                theIgnoredFeatures);
+}
+
+bool XGUI_Workshop::deleteFeaturesInternal(const QObjectPtrList& theList,
+                                           const std::set<FeaturePtr>& aDirectRefFeatures,
+                                           const std::set<FeaturePtr>& aIndirectRefFeatures,
+                                           const std::set<FeaturePtr>& theIgnoredFeatures,
+                                           const bool doDeleteReferences)
+{
   if (doDeleteReferences) {
     std::set<FeaturePtr> aFeaturesToDelete = aDirectRefFeatures;
     aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
@@ -1418,7 +1448,7 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
   }
 
   QString anActionId = "DELETE_CMD";
-  removeFeatures(theList, theIgnoredFeatures, anActionId);
+  return removeFeatures(theList, theIgnoredFeatures, anActionId);
 }
 
 //**************************************************************