]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Introduce internal edit operation state in PartSet module in order to have a virtual...
authornds <nds@opencascade.com>
Tue, 27 Oct 2015 13:29:46 +0000 (16:29 +0300)
committernds <nds@opencascade.com>
Tue, 27 Oct 2015 13:29:46 +0000 (16:29 +0300)
src/ModuleBase/ModuleBase_FilterValidated.cpp
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.h
src/ModuleBase/ModuleBase_WidgetValidated.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_WidgetEditor.cpp
src/XGUI/XGUI_Workshop.cpp

index 88f16c6d8deb50eb9a9cf36c5b00d66ae77b1490..08314d734cc3cf2793e3e601ac6a9a53d891551d 100644 (file)
@@ -25,7 +25,7 @@ Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityO
     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
     ModuleBase_ModelWidget* aCurrentWidget = aPanel->preselectionWidget();
     if (!aCurrentWidget)
-      aCurrentWidget = aPanel->activeWidget();
+      aCurrentWidget = myWorkshop->module()->activeWidget();
     ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
                                                                            (aCurrentWidget);
     ModuleBase_ViewerPrs aPrs;
index 747dda203268c5f65ab386613c268dce9152830c..7ed9c8f6a2ac8a82490f5d7554465c5c56e0610d 100644 (file)
@@ -101,6 +101,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
     return 0;\r
   }\r
 \r
+  /// Returns the active widget, by default it is the property panel active widget\r
+  virtual ModuleBase_ModelWidget* activeWidget() const = 0;\r
+\r
   /// Returns current workshop\r
   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }\r
 \r
index af676208cc5d3c9c53c12096e93c092d6ab06812..cadef7521a29517de99e82411f091e6feb78128c 100755 (executable)
@@ -304,8 +304,7 @@ QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
 {
-  activateSelection(true);
-  activateFilters(true);
+  activateSelectionAndFilters(true);
   QList<ModuleBase_ViewerPrs> anEmptyList;
   // This method will call Selection changed event which will call onSelectionChanged
   // To clear mySelection, myListControl and storeValue()
@@ -354,14 +353,12 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum
     aShapeTypeName = myTypeCombo->itemText(idx);
     TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
     if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
-      activateSelection(false);
-      activateFilters(false);
+      activateSelectionAndFilters(false);
       bool isBlocked = myTypeCombo->blockSignals(true);
       myTypeCombo->setCurrentIndex(idx);
       myTypeCombo->blockSignals(isBlocked);
 
-      activateSelection(true);
-      activateFilters(true);
+      activateSelectionAndFilters(true);
       break;
     }
   }
index 268a2515f95c8d40f71c7b42ae7b0a8e797dd160..d4ed903ec4b882de9328a8118efc852085ad1854 100755 (executable)
@@ -111,7 +111,7 @@ bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape,
 }
 
 //********************************************************************
-void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
+void ModuleBase_WidgetSelector::activateSelectionAndFilters(bool toActivate)
 {
   updateSelectionName();
 
@@ -120,6 +120,7 @@ void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
   } else {
     myWorkshop->deactivateSubShapesSelection();
   }
+  activateFilters(toActivate);
 }
 
 //********************************************************************
@@ -128,12 +129,10 @@ void ModuleBase_WidgetSelector::activateCustom()
   connect(myWorkshop, SIGNAL(selectionChanged()), this,
           SLOT(onSelectionChanged()), Qt::UniqueConnection);
   
-  activateSelection(true);
+  activateSelectionAndFilters(true);
 
   // Restore selection in the viewer by the attribute selection list
   myWorkshop->setSelected(getAttributeSelection());
-
-  activateFilters(true);
 }
 
 //********************************************************************
@@ -167,7 +166,7 @@ bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& t
 void ModuleBase_WidgetSelector::deactivate()
 {
   disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-  activateSelection(false);
-  activateFilters(false);
+  activateSelectionAndFilters(false);
+  ModuleBase_ModelWidget::deactivate();
 }
 
index 0deb253bdb1358353d186f7164d5aeb479164ba5..cb7d76e42ab1ada09ee8def3cacde5cd607ecadc 100755 (executable)
@@ -42,6 +42,9 @@ Q_OBJECT
   /// Defines if it is supposed that the widget should interact with the viewer.
   virtual bool isViewerSelector() { return true; }
 
+  /// Activate or deactivate selection and selection filters
+  void activateSelectionAndFilters(bool toActivate);
+
   /// Checks the widget validity. By default, it returns true.
   /// \param thePrs a selected presentation in the view
   /// \return a boolean value
@@ -54,10 +57,6 @@ Q_OBJECT
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
-protected:
-  /// Activate or deactivate selection
-  void activateSelection(bool toActivate);
-
  private slots:
    /// Slot which is called on selection event
   void onSelectionChanged();
index f1a5ef17ee27842fb50ca4362c0fbef5de396996..385f11a00f04e334e29fd048ebad38dc6765ae0e 100644 (file)
@@ -67,10 +67,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg
   //! Returns data object by AIS
   ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
 
-  /// It obtains selection filters from the workshop and activates them in the active viewer
-  /// \param toActivate a flag about activation or deactivation the filters
-  void activateFilters(const bool toActivate);
-
 protected:
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
@@ -123,6 +119,10 @@ protected:
   /// \param theValues a list of presentations.
   void filterPresentations(QList<ModuleBase_ViewerPrs>& theValues);
 
+  /// It obtains selection filters from the workshop and activates them in the active viewer
+  /// \param toActivate a flag about activation or deactivation the filters
+  void activateFilters(const bool toActivate);
+
 protected:
   /// Reference to workshop
   ModuleBase_IWorkshop* myWorkshop; 
index bbe6d029300518cb130f01521d083b3552a34dbb..1348ef9708fc3d8350ba79aa536a9d0d0601f7cc 100755 (executable)
@@ -124,7 +124,8 @@ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop*
 
 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   : ModuleBase_IModule(theWshop),
-  myRestartingMode(RM_None), myVisualLayerId(0), myHasConstraintShown(true)
+  myRestartingMode(RM_None), myVisualLayerId(0), myHasConstraintShown(true),
+  myIsInternalEditOperation(false)
 {
   new PartSet_IconFactory();
 
@@ -275,7 +276,10 @@ void PartSet_Module::onOperationCommitted(ModuleBase_Operation* theOperation)
         FeaturePtr anOperationFeature = aFOperation->feature();
         if (anOperationFeature.get() != NULL) {
           editFeature(anOperationFeature);
-          // 4. activate the first obligatory widget
+          myIsInternalEditOperation = true;
+          onInternalActivateFirstWidgetSelection();
+
+          // activate the last active widget in the Property Panel
           if (!myPreviousAttributeID.empty()) {
             ModuleBase_Operation* anEditOperation = currentOperation();
             if (anEditOperation) {
@@ -286,13 +290,16 @@ void PartSet_Module::onOperationCommitted(ModuleBase_Operation* theOperation)
                 if (aWidgets[i]->attributeID() == myPreviousAttributeID)
                   aPreviousAttributeWidget = aWidgets[i];
               }
-              if (aPreviousAttributeWidget)
+              // If the current widget is a selector, do nothing, it processes the mouse press
+              if (aPreviousAttributeWidget && !aPreviousAttributeWidget->isViewerSelector())
                 aPreviousAttributeWidget->focusTo();
             }
           }
         }
       }
       else {
+        // the flag should be reset before start to do not react to the widget deactivate
+        myIsInternalEditOperation = false;
         launchOperation(myLastOperationId);
         breakOperationSequence();
       }
@@ -309,6 +316,7 @@ void PartSet_Module::breakOperationSequence()
 
 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
 {
+  myIsInternalEditOperation = false;
   breakOperationSequence();
 }
 
@@ -583,7 +591,7 @@ void PartSet_Module::onEnterReleased()
 {
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                                   (currentOperation());
-  if (!aFOperation->isEditOperation())
+  if (/*!aFOperation->isEditOperation() || */myIsInternalEditOperation)
     myRestartingMode = RM_EmptyFeatureUsed;
 }
 
@@ -618,6 +626,20 @@ void PartSet_Module::onNoMoreWidgets(const std::string& thePreviousAttributeID)
   }
 }
 
+void PartSet_Module::onInternalActivateFirstWidgetSelection()
+{
+  if (!myIsInternalEditOperation)
+    return;
+
+  ModuleBase_ModelWidget* aFirstWidget = activeWidget();
+  ModuleBase_IPropertyPanel* aPanel = currentOperation()->propertyPanel();
+  if (aFirstWidget != aPanel->activeWidget()) {
+    ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
+    if (aWSelector)
+      aWSelector->activateSelectionAndFilters(true);
+  }
+}
+
 void PartSet_Module::onVertexSelected()
 {
   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
@@ -697,6 +719,31 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
   return aWgt;
 }
 
+ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
+{
+  ModuleBase_ModelWidget* anActiveWidget = 0;
+  ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
+  if (aOperation) {
+    ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+    anActiveWidget = aPanel->activeWidget();
+    if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector())) {
+      // finds the first widget which can accept a value
+      QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
+      ModuleBase_ModelWidget* aFirstWidget = 0;
+      ModuleBase_ModelWidget* aWgt;
+      QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+      for (aWIt = aWidgets.begin(); aWIt != aWidgets.end() && !aFirstWidget; ++aWIt) {
+        aWgt = (*aWIt);
+        if (aWgt->canSetValue())
+          aFirstWidget = aWgt;
+      }
+      if (aFirstWidget)
+        anActiveWidget = aFirstWidget;
+    }
+  }
+
+  return anActiveWidget;
+}
 
 bool PartSet_Module::deleteObjects()
 {
@@ -1127,13 +1174,11 @@ void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
   // the filters of this widget should be activated in the created view
   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
   if (aOperation) {
-    ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
-    ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+    ModuleBase_ModelWidget* anActiveWidget = activeWidget();
     if (anActiveWidget) {
-      ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
-                                                                             (anActiveWidget);
-      if (aWidgetValidated)
-        aWidgetValidated->activateFilters(true);
+      ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
+      if (aWSelector)
+        aWSelector->activateSelectionAndFilters(true);
     }
   }
 }
index 5128d3f193e1c4d253bfc46a0012f54fcc2f542c..eac6dad27ce20415da65288c05baee08d894c8bd 100644 (file)
@@ -66,6 +66,10 @@ public:
   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
                                                      Config_WidgetAPI* theWidgetApi, std::string theParentId);
 
+  /// Returns the active widget, by default it is the property panel active widget
+  /// If the internal edit operation is started, this is the first widget of the operation
+  virtual ModuleBase_ModelWidget* activeWidget() const;
+
   /// Call back forlast tuning of property panel before operation performance
   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
 
@@ -203,11 +207,15 @@ public:
   /// Returns list of granted operation indices
   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
 
+  bool isInternalEditOperation() { return myIsInternalEditOperation; }
+
 public slots:
   /// SLOT, that is called by no more widget signal emitted by property panel
   /// Set a specific flag to restart the sketcher operation
   void onNoMoreWidgets(const std::string& thePreviousAttributeID);
 
+  void onInternalActivateFirstWidgetSelection();
+
   /// Redefines the parent method in order to customize the next case:
   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
   /// the operation should be always aborted.
@@ -271,13 +279,15 @@ protected slots:
   virtual bool deleteObjects();
 
  private:
-   QString myLastOperationId;
-   FeaturePtr myLastFeature;
+  QString myLastOperationId;
+  FeaturePtr myLastFeature;
+
+  std::string myPreviousAttributeID;
 
-   std::string myPreviousAttributeID;
+  // Automatical restarting mode flag
+  RestartingMode myRestartingMode;
 
-   // Automatical restarting mode flag
-   RestartingMode myRestartingMode;
+  bool myIsInternalEditOperation;
 
   SelectMgr_ListOfFilter mySelectionFilters;
 
index 4857863b5ea31d1f905187ffcb0a67fad13d6ac7..d0a129aba01b49031ea569c398776a79f3683fb8 100644 (file)
@@ -23,7 +23,7 @@ PartSet_WidgetEditor::PartSet_WidgetEditor(QWidget* theParent, ModuleBase_IWorks
 bool PartSet_WidgetEditor::focusTo()
 {
   PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
-  if (aModule->isMouseOverWindow())
+  if (aModule->isMouseOverWindow() && !isEditingMode())
     return ModuleBase_WidgetEditor::focusTo();
   else {
     return ModuleBase_WidgetDoubleValue::focusTo();
index 4f5e03c28dac1759a55079d49c98c5ee27f83c4d..cb6e77a0ed0840c6f2c6e2328b11dcc24e37c69f 100644 (file)
@@ -1016,6 +1016,8 @@ void XGUI_Workshop::createDockWidgets()
           myOperationMgr,  SLOT(onKeyReleased(QKeyEvent*)));
   //connect(myOperationMgr,  SIGNAL(validationStateChanged(bool)),
   //        this, SLOT(onValidationStateChanged(bool)));
+  connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
+          myModule, SLOT(onInternalActivateFirstWidgetSelection()));
 }
 
 //******************************************************