From 70122a4400ec112e9c2c071724d444fa40282076 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 27 Oct 2015 16:29:46 +0300 Subject: [PATCH] Introduce internal edit operation state in PartSet module in order to have a virtual active widget to activate the selection of the first control of restarted operation. --- src/ModuleBase/ModuleBase_FilterValidated.cpp | 2 +- src/ModuleBase/ModuleBase_IModule.h | 3 + .../ModuleBase_WidgetMultiSelector.cpp | 9 +-- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 11 ++-- src/ModuleBase/ModuleBase_WidgetSelector.h | 7 +- src/ModuleBase/ModuleBase_WidgetValidated.h | 8 +-- src/PartSet/PartSet_Module.cpp | 65 ++++++++++++++++--- src/PartSet/PartSet_Module.h | 20 ++++-- src/PartSet/PartSet_WidgetEditor.cpp | 2 +- src/XGUI/XGUI_Workshop.cpp | 2 + 10 files changed, 92 insertions(+), 37 deletions(-) diff --git a/src/ModuleBase/ModuleBase_FilterValidated.cpp b/src/ModuleBase/ModuleBase_FilterValidated.cpp index 88f16c6d8..08314d734 100644 --- a/src/ModuleBase/ModuleBase_FilterValidated.cpp +++ b/src/ModuleBase/ModuleBase_FilterValidated.cpp @@ -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 (aCurrentWidget); ModuleBase_ViewerPrs aPrs; diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 747dda203..7ed9c8f6a 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -101,6 +101,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject return 0; } + /// Returns the active widget, by default it is the property panel active widget + virtual ModuleBase_ModelWidget* activeWidget() const = 0; + /// Returns current workshop ModuleBase_IWorkshop* workshop() const { return myWorkshop; } diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index af676208c..cadef7521 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -304,8 +304,7 @@ QList ModuleBase_WidgetMultiSelector::getControls() const //******************************************************************** void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { - activateSelection(true); - activateFilters(true); + activateSelectionAndFilters(true); QList 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; } } diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 268a2515f..d4ed903ec 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -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(); } diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 0deb253bd..cb7d76e42 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -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(); diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index f1a5ef17e..385f11a00 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -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& 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; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index bbe6d0293..1348ef970 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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 (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(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 aWidgets = aPanel->modelWidgets(); + ModuleBase_ModelWidget* aFirstWidget = 0; + ModuleBase_ModelWidget* aWgt; + QList::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 - (anActiveWidget); - if (aWidgetValidated) - aWidgetValidated->activateFilters(true); + ModuleBase_WidgetSelector* aWSelector = dynamic_cast(anActiveWidget); + if (aWSelector) + aWSelector->activateSelectionAndFilters(true); } } } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 5128d3f19..eac6dad27 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -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; diff --git a/src/PartSet/PartSet_WidgetEditor.cpp b/src/PartSet/PartSet_WidgetEditor.cpp index 4857863b5..d0a129aba 100644 --- a/src/PartSet/PartSet_WidgetEditor.cpp +++ b/src/PartSet/PartSet_WidgetEditor.cpp @@ -23,7 +23,7 @@ PartSet_WidgetEditor::PartSet_WidgetEditor(QWidget* theParent, ModuleBase_IWorks bool PartSet_WidgetEditor::focusTo() { PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); - if (aModule->isMouseOverWindow()) + if (aModule->isMouseOverWindow() && !isEditingMode()) return ModuleBase_WidgetEditor::focusTo(); else { return ModuleBase_WidgetDoubleValue::focusTo(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 4f5e03c28..cb6e77a0e 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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())); } //****************************************************** -- 2.39.2