From: nds Date: Fri, 26 Jun 2015 09:07:06 +0000 (+0300) Subject: Issue #604 Creation of an unexpected line in the Sketcher X-Git-Tag: V_1.3.0~179 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6fbb6b77447a0c4a4a21c12e216ce56833ac766b;p=modules%2Fshaper.git Issue #604 Creation of an unexpected line in the Sketcher An additional condition for Apply button validity. --- diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 987b17491..f15a9321f 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -128,6 +128,11 @@ bool ModuleBase_IModule::canRedo() const return aMgr->hasModuleDocument() && aMgr->canRedo() && !aMgr->isOperation(); } +bool ModuleBase_IModule::canCommitOperation() const +{ + return true; +} + void ModuleBase_IModule::onFeatureTriggered() { QAction* aCmd = dynamic_cast(sender()); diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index ba082667e..bea23dbcd 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -120,6 +120,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject //! Returns True if there are available Redos and there is not an active operation virtual bool canRedo() const; + /// Returns True if the current operation can be committed. By default it is true. + /// \return a boolean value + virtual bool canCommitOperation() const; + /// Returns whether the object can be displayed. The default realization returns true. /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index d90aec240..2e87de581 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -315,6 +315,11 @@ bool PartSet_Module::canRedo() const return aCanRedo; } +bool PartSet_Module::canCommitOperation() const +{ + return mySketchMgr->canCommitOperation(); +} + bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const { // the sketch manager put the restriction to the objects display diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 46012ad16..d6c2d4786 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -99,6 +99,10 @@ public: /// \return the boolean result virtual bool canRedo() const; + /// Returns True if the current operation can be committed. Asks the sketch manager. + /// \return a boolean value + virtual bool canCommitOperation() const; + /// Returns whether the object can be displayed at the bounds of the active operation. /// Display only current operation results for usual operation and ask the sketcher manager /// if it is a sketch operation diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 323c9ffd1..099bd16b3 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -12,6 +12,7 @@ #include "PartSet_WidgetSketchLabel.h" #include +#include #include #include @@ -19,10 +20,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -189,6 +190,7 @@ void PartSet_SketcherMgr::onEnterViewPort() // redisplayed before this update, the feature presentation jumps from reset value to current. myIsMouseOverWindow = true; myIsPropertyPanelValueChanged = false; + operationMgr()->onValidateOperation(); #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str()); #endif @@ -218,6 +220,7 @@ void PartSet_SketcherMgr::onLeaveViewPort() myIsMouseOverViewProcessed = false; myIsMouseOverWindow = false; myIsPropertyPanelValueChanged = false; + operationMgr()->onValidateOperation(); #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str()); #endif @@ -294,6 +297,7 @@ void PartSet_SketcherMgr::onValuesChangedInPropertyPanel() // visualize the current operation feature myIsPropertyPanelValueChanged = true; + operationMgr()->onValidateOperation(); ModuleBase_Operation* aOperation = getCurrentOperation(); // the feature is to be erased here, but it is correct to call canDisplayObject because // there can be additional check (e.g. editor widget in distance constraint) @@ -822,6 +826,7 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) connectToPropertyPanel(false); myIsPropertyPanelValueChanged = false; myIsMouseOverViewProcessed = true; + operationMgr()->onValidateOperation(); } void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) @@ -846,6 +851,16 @@ bool PartSet_SketcherMgr::canRedo() const return isNestedCreateOperation(getCurrentOperation()); } +bool PartSet_SketcherMgr::canCommitOperation() const +{ + bool aCanCommit = true; + + if (isNestedCreateOperation(getCurrentOperation()) && !canDisplayCurrentCreatedFeature()) + aCanCommit = false; + + return aCanCommit; +} + bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const { bool aCanDisplay = true; @@ -1198,3 +1213,12 @@ QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const return QString("myIsPropertyPanelValueChanged = %1, myIsMouseOverWindow = %2") .arg(myIsPropertyPanelValueChanged).arg(myIsMouseOverWindow); } + +XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const +{ + ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); + XGUI_ModuleConnector* aConnector = dynamic_cast(anIWorkshop); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + + return aWorkshop->operationMgr(); +} diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 973924a3e..677c4a163 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -28,6 +28,7 @@ class PartSet_Module; class ModuleBase_IViewWindow; class ModuleBase_ModelWidget; class ModuleBase_Operation; +class XGUI_OperationMgr; class QMouseEvent; /** @@ -134,6 +135,10 @@ public: /// \return the boolean result bool canRedo() const; + /// Returns False only if the sketch creating feature can not be visualized. + /// \return a boolean value + bool canCommitOperation() const; + /// Returns whether the object can be displayed at the bounds of the active operation. /// Display only current operation results for usual operation and ask the sketcher manager /// if it is a sketch operation @@ -267,6 +272,8 @@ private: /// \return a string value QString mouseOverWindowFlagsInfo() const; + XGUI_OperationMgr* operationMgr() const; + private: PartSet_Module* myModule; diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 65e76b68c..fc45ef3f8 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -7,13 +7,17 @@ #include "XGUI_OperationMgr.h" #include "ModuleBase_Operation.h" +#include "ModuleBase_IWorkshop.h" +#include "ModuleBase_IModule.h" #include #include #include -XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent) - : QObject(theParent), myIsValidationLock(false), myIsApplyEnabled(false) +XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent, + ModuleBase_IWorkshop* theWorkshop) +: QObject(theParent), myIsValidationLock(false), myIsApplyEnabled(false), + myWorkshop(theWorkshop) { } @@ -153,7 +157,8 @@ void XGUI_OperationMgr::onValidateOperation() return; ModuleBase_Operation* anOperation = currentOperation(); if(anOperation) { - setApplyEnabled(!myIsValidationLock && anOperation->isValid()); + bool aCanCommit = myWorkshop->module()->canCommitOperation(); + setApplyEnabled(!myIsValidationLock && aCanCommit && anOperation->isValid()); } } diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 812c61c3d..155d4ef48 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -17,6 +17,8 @@ class QKeyEvent; +class ModuleBase_IWorkshop; + /**\class XGUI_OperationMgr * \ingroup GUI * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack @@ -32,10 +34,13 @@ Q_OBJECT public: /// Constructor /// \param theParent the parent - XGUI_OperationMgr(QObject* theParent); + XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop); /// Destructor virtual ~XGUI_OperationMgr(); + void setWorkshop(ModuleBase_IWorkshop* theWorkshop) + { myWorkshop = theWorkshop; }; + /// Returns the current operation or NULL /// \return the current operation ModuleBase_Operation* currentOperation() const; @@ -173,6 +178,10 @@ signals: Operations myOperations; ///< a stack of started operations. The active operation is on top, // others are suspended and started by the active is finished + /// Current workshop + ModuleBase_IWorkshop* myWorkshop; + + /// Lock/Unlock access to Ok button in property panel bool myIsValidationLock; /// Lock/Unlock access to Ok button in property panel diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 49abca202..cfc79f6b7 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -127,7 +127,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) mySelector = new XGUI_SelectionMgr(this); //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands())); - myOperationMgr = new XGUI_OperationMgr(this); + myOperationMgr = new XGUI_OperationMgr(this, 0); myActionsMgr = new XGUI_ActionsMgr(this); myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop()); myContextMenuMgr = new XGUI_ContextMenuMgr(this); @@ -139,6 +139,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myActionsMgr, SLOT(updateOnViewSelection())); myModuleConnector = new XGUI_ModuleConnector(this); + myOperationMgr->setWorkshop(moduleConnector()); connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)), SLOT(onOperationStarted(ModuleBase_Operation*)));