From 99e39321c82010bba9ff78242c9e44584301bc11 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 11 Dec 2014 16:46:24 +0300 Subject: [PATCH] Commit of the current operation if the preselection is activated. --- src/ModuleBase/ModuleBase_IModule.cpp | 6 -- src/ModuleBase/ModuleBase_IModule.h | 12 ++- src/ModuleBase/ModuleBase_Operation.cpp | 22 ++--- src/ModuleBase/ModuleBase_Operation.h | 4 +- src/PartSet/PartSet_Module.cpp | 2 +- src/PartSet/PartSet_Module.h | 6 +- src/XGUI/XGUI_PropertyPanel.cpp | 1 + src/XGUI/XGUI_Workshop.cpp | 107 ++++++++++++++---------- src/XGUI/XGUI_Workshop.h | 16 +++- 9 files changed, 105 insertions(+), 71 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index ab6aa1f3e..9f7da7a38 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -20,15 +20,9 @@ ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent) : QObject(theParent), myWorkshop(theParent) { - connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)), - SLOT(onOperationStarted(ModuleBase_Operation*))); - connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), SLOT(onOperationStopped(ModuleBase_Operation*))); - connect(myWorkshop, SIGNAL(operationResumed(ModuleBase_Operation*)), - SLOT(onOperationResumed(ModuleBase_Operation*))); - connect(myWorkshop, SIGNAL(operationComitted(ModuleBase_Operation*)), SLOT(onOperationComitted(ModuleBase_Operation*))); diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index f6219675c..bf1675bfa 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -45,6 +45,14 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theCmdId the operation name virtual void launchOperation(const QString& theCmdId); + /// Realizes some functionality by an operation start + /// \param theOperation a started operation + virtual void operationStarted(ModuleBase_Operation* theOperation) {} + + /// Realizes some functionality by an operation resume + /// \param theOperation a resumed operation + virtual void operationResumed(ModuleBase_Operation* theOperation) {} + /// Called when it is necessary to update a command state (enable or disable it) //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0; @@ -66,14 +74,10 @@ public slots: void onFeatureTriggered(); protected slots: - /// SLOT, that is called after the operation is started. Connect on the focus activated signal - virtual void onOperationStarted(ModuleBase_Operation* theOperation) {} - /// SLOT, that is called after the operation is stopped. Switched off the modfications performed /// by the operation start virtual void onOperationStopped(ModuleBase_Operation* theOperation) {} - virtual void onOperationResumed(ModuleBase_Operation* theOperation) {} virtual void onOperationComitted(ModuleBase_Operation* theOperation) {} diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 58d0c2d9c..798a82987 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -169,6 +169,7 @@ void ModuleBase_Operation::start() startOperation(); emit started(); + } void ModuleBase_Operation::postpone() @@ -230,16 +231,16 @@ void ModuleBase_Operation::setRunning(bool theState) } } -bool ModuleBase_Operation::activateByPreselection() +void ModuleBase_Operation::activateByPreselection() { if (!myPropertyPanel || myPreSelection.empty()) { myPropertyPanel->activateNextWidget(NULL); - return false; + return; } const QList& aWidgets = myPropertyPanel->modelWidgets(); if (aWidgets.empty()) { myPropertyPanel->activateNextWidget(NULL); - return false; + return; } ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0; @@ -264,14 +265,10 @@ bool ModuleBase_Operation::activateByPreselection() } } - if (aFilledWgt) { - myPropertyPanel->activateNextWidget(aFilledWgt); + myPropertyPanel->activateNextWidget(aFilledWgt); + if (aFilledWgt) emit activatedByPreselection(); - return true; - } - else - myPropertyPanel->activateNextWidget(NULL); - return false; + } void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, @@ -355,6 +352,11 @@ void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) myPropertyPanel->setEditingMode(isEditOperation()); //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, // SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); + + // Do not activate widgets by default if the current operation is editing operation + // Because we don't know which widget is going to be edited. + if (!isEditOperation()) + activateByPreselection(); } bool ModuleBase_Operation::isGranted(QString theId) const diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 17233f0f2..f20c7f476 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -126,8 +126,8 @@ Q_OBJECT ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; } - /// Activates widgets by preselection if it is accepted - virtual bool activateByPreselection(); + /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct + virtual void activateByPreselection(); /// If the operation works with feature which is sub-feature of another one /// then this variable has to be initialised by parent feature diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index b47766109..bffa6148d 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -178,7 +178,7 @@ void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation) breakOperationSequence(); } -void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation) +void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation) { if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) { // Display all sketcher sub-Objects diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 129df5353..e9a145ebb 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -49,6 +49,10 @@ public: QStringList sketchOperationIdList() const; + /// Realizes some functionality by an operation start + /// \param theOperation a started operation + virtual void operationStarted(ModuleBase_Operation* theOperation); + public slots: /// SLOT, that is called by no more widget signal emitted by property panel /// Set a specific flag to restart the sketcher operation @@ -60,8 +64,6 @@ protected slots: virtual void onOperationAborted(ModuleBase_Operation* theOperation); - virtual void onOperationStarted(ModuleBase_Operation* theOperation); - virtual void onOperationStopped(ModuleBase_Operation* theOperation); /// Called when previous operation is finished diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index b94bb1903..e788d15da 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -77,6 +77,7 @@ void XGUI_PropertyPanel::cleanContent() myWidgets.clear(); qDeleteAll(myCustomWidget->children()); myActiveWidget = NULL; + setWindowTitle(tr("Property Panel")); } void XGUI_PropertyPanel::setModelWidgets(const QList& theWidgets) diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 91041203f..f8fe475ca 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -146,8 +146,9 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myModuleConnector = new XGUI_ModuleConnector(this); connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)), - SLOT(onOperationStarted())); - connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)), SLOT(onOperationStarted())); + SLOT(onOperationStarted(ModuleBase_Operation*))); + connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)), + SLOT(onOperationResumed(ModuleBase_Operation*))); connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), SLOT(onOperationStopped(ModuleBase_Operation*))); connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit())); @@ -557,56 +558,34 @@ void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptrcurrentOperation(); - if (this->isSalomeMode()) - aOperation->setNestedFeatures(mySalomeConnector->nestedActions(aOperation->id())); - else - aOperation->setNestedFeatures(myActionsMgr->nestedCommands(aOperation->id())); - - if (aOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel - connectWithOperation(aOperation); - - showPropertyPanel(); - QString aXmlRepr = aOperation->getDescription()->xmlRepresentation(); - ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(), - myModuleConnector); - - myPropertyPanel->cleanContent(); - aFactory.createWidget(myPropertyPanel->contentWidget()); - ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget()); - - QList aWidgets = aFactory.getModelWidgets(); - foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { - aWidget->setFeature(aOperation->feature()); - aWidget->enableFocusProcessing(); - QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); - // Init default values - if (!aOperation->isEditOperation() && !aWidget->isComputedDefault()) { - aWidget->storeValue(); - } - } + setNestedFeatures(theOperation); - myPropertyPanel->setModelWidgets(aWidgets); - aOperation->setPropertyPanel(myPropertyPanel); - // Do not activate widgets by default if the current operation is editing operation - // Because we don't know which widget is going to be edited. - if ((!aOperation->isEditOperation())) { - aOperation->activateByPreselection(); - } - // Set final definitions if they are necessary - myModule->propertyPanelDefined(aOperation); + if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel + connectWithOperation(theOperation); + setPropertyPanel(theOperation); + } + updateCommandStatus(); - // Widget activation (from the previous method) may commit the current operation - // if pre-selection is enougth for it. So we shouldn't update prop panel's title - if(myOperationMgr->isCurrentOperation(aOperation)) { - myPropertyPanel->setWindowTitle(aOperation->getDescription()->description()); - } + myModule->operationStarted(theOperation); +} + +//****************************************************** +void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation) +{ + setNestedFeatures(theOperation); + + if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel + connectWithOperation(theOperation); + setPropertyPanel(theOperation); } updateCommandStatus(); + + myModule->operationResumed(theOperation); } + //****************************************************** void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) { @@ -625,6 +604,44 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) } } +void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation) +{ + if (this->isSalomeMode()) + theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id())); + else + theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id())); +} + +void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) +{ + showPropertyPanel(); + QString aXmlRepr = theOperation->getDescription()->xmlRepresentation(); + ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(), + myModuleConnector); + + myPropertyPanel->cleanContent(); + aFactory.createWidget(myPropertyPanel->contentWidget()); + ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget()); + + QList aWidgets = aFactory.getModelWidgets(); + foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { + aWidget->setFeature(theOperation->feature()); + aWidget->enableFocusProcessing(); + QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); + // Init default values + if (!theOperation->isEditOperation() && !aWidget->isComputedDefault()) { + aWidget->storeValue(); + } + } + + myPropertyPanel->setModelWidgets(aWidgets); + theOperation->setPropertyPanel(myPropertyPanel); + + myModule->propertyPanelDefined(theOperation); + + myPropertyPanel->setWindowTitle(theOperation->getDescription()->description()); +} + bool XGUI_Workshop::event(QEvent * theEvent) { PostponeMessageQtEvent* aPostponedEv = dynamic_cast(theEvent); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index fd02a8bba..f8c293c5e 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -219,6 +219,14 @@ signals: void closeDocument(); protected: + // Find the nested features and set them into the operation + // \param theOperation an operation + void setNestedFeatures(ModuleBase_Operation* theOperation); + // Update the property panel content by the XML description of the operation and set the panel + // into the operation + // \param theOperation an operation + void setPropertyPanel(ModuleBase_Operation* theOperation); + bool event(QEvent * theEvent); //Event-loop processing methods: void addFeature(const std::shared_ptr&); @@ -240,7 +248,13 @@ signals: private slots: /// SLOT, that is called after the operation is started. Update workshop state according to /// the started operation, e.g. visualizes the property panel and connect to it. - void onOperationStarted(); + /// \param theOpertion a started operation + void onOperationStarted(ModuleBase_Operation* theOperation); + + /// SLOT, that is called after the operation is resumed. Update workshop state according to + /// the started operation, e.g. visualizes the property panel and connect to it. + /// \param theOpertion a resumed operation + virtual void onOperationResumed(ModuleBase_Operation* theOperation); /// SLOT, that is called after the operation is stopped. Update workshop state, e.g. /// hides the property panel and udpate the command status. -- 2.39.2