Salome HOME
Update SketchBuilder to work on faces with holes (issue #1320)
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 8818366a0d8c6d2c2a4b31279d3b09128e54293d..feb5405db4d9996f8307efbd05b7f6c55c656db5 100755 (executable)
@@ -66,6 +66,8 @@
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_OperationFeature.h>
 #include <ModuleBase_OperationAction.h>
+#include <ModuleBase_PagedContainer.h>
+#include <ModuleBase_WidgetValidated.h>
 
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>
@@ -242,6 +244,7 @@ void XGUI_Workshop::activateModule()
   QIntList aModes;
   module()->activeSelectionModes(aModes);
   aDisplayer->activateObjects(aModes, aDisplayed);
+  myOperationMgr->activate();
 }
 
 void XGUI_Workshop::deactivateModule()
@@ -259,6 +262,8 @@ void XGUI_Workshop::deactivateModule()
   XGUI_Displayer* aDisplayer = displayer();
   QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
   aDisplayer->deactivateObjects(aDisplayed, true);
+
+  myOperationMgr->deactivate();
 }
 
 //******************************************************
@@ -564,13 +569,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();
@@ -616,11 +623,13 @@ void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
     const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
        myModule->connectToPropertyPanel(aWidget, isToConnect);
-      if (isToConnect) {
+       if (isToConnect) {
         connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
+        connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
       }
       else {
         disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
+        disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
       }
     }
   }
@@ -893,6 +902,27 @@ void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
   myModule->widgetStateChanged(thePreviousState);
 }
 
+//******************************************************
+void XGUI_Workshop::onValuesChanged()
+{
+  ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
+  if (!aSenderWidget || aSenderWidget->canSetValue())
+    return;
+
+  ModuleBase_ModelWidget* anActiveWidget = 0;
+  ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
+  if (anOperation) {
+    ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
+    if (aPanel)
+      anActiveWidget = aPanel->activeWidget();
+  }
+  if (anActiveWidget) {
+    ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
+                                                                           (anActiveWidget);
+    aWidgetValidated->clearValidatedCash();
+  }
+}
+
 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
 {
   QString libName = QString::fromStdString(library(theModule.toStdString()));
@@ -1063,8 +1093,8 @@ void XGUI_Workshop::createDockWidgets()
   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 +1209,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 +1229,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());
   }
 }
 
@@ -1322,23 +1358,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,
@@ -1349,11 +1372,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());
@@ -1401,8 +1430,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());