From 312c60ce13126a82e02b4db09e0885ef526199f8 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 11 Apr 2017 16:36:35 +0300 Subject: [PATCH] Issue #2122: Unexpected Sketcher behavior when creating Coincidence : Preselection is corrected. --- src/ModuleBase/ModuleBase_IModule.cpp | 21 +++++++++++++++++++-- src/ModuleBase/ModuleBase_IModule.h | 8 ++++++++ src/PartSet/PartSet_Module.cpp | 9 +++++++++ src/PartSet/PartSet_Module.h | 7 +++++++ src/PartSet/PartSet_SketcherMgr.cpp | 16 ++++++++++++++++ src/PartSet/PartSet_SketcherMgr.h | 6 ++++++ src/PartSet/PartSet_WidgetSketchLabel.cpp | 2 ++ 7 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index ad7eb2edd..9fad87772 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -88,7 +88,7 @@ void ModuleBase_IModule::launchOperation(const QString& theCmdId, ModuleBase_OperationFeature* aCurOperation = dynamic_cast (myWorkshop->currentOperation()); - QString anOperationKind = aCurOperation ? aCurOperation->getDescription()->operationId() : ""; + QString aCurOperationKind = aCurOperation ? aCurOperation->getDescription()->operationId() : ""; bool isCommitted; if (!myWorkshop->canStartOperation(theCmdId, isCommitted)) @@ -105,7 +105,7 @@ void ModuleBase_IModule::launchOperation(const QString& theCmdId, if (aMessage.get()) { setReentrantPreSelection(aMessage); } - else if (anOperationKind.isEmpty() || anOperationKind == theCmdId) { + else if (canUsePreselection(aCurOperationKind, theCmdId)) { // restore of previous opeation is absent or new launched operation has the same kind aFOperation->initSelection(aPreSelected); } @@ -215,6 +215,23 @@ bool ModuleBase_IModule::canDisplayObject(const ObjectPtr& theObject) const return true; } +bool ModuleBase_IModule::canUsePreselection(const QString& thePreviousOperationKind, + const QString& theStartedOperationKind) +{ + // no previous operation + if (thePreviousOperationKind.isEmpty()) + return true; + // edit operation + if (thePreviousOperationKind.endsWith(ModuleBase_OperationFeature::EditSuffix())) + return true; + + // reentrant operation + if (thePreviousOperationKind == theStartedOperationKind) + return true; + + return false; +} + bool ModuleBase_IModule::canUndo() const { SessionPtr aMgr = ModelAPI_Session::get(); diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 11a32c888..30f9d2060 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -183,6 +183,14 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; + /// Returns whether the started operation may use preselection of the previous one + /// Cases are: previous operation is null, edit operation, previuos and started operations + /// kinds are the same + /// \param thePreviousOperationKind a kind of previous operation + /// \param theStartedOperationKind a kind of a started operation + virtual bool canUsePreselection(const QString& thePreviousOperationKind, + const QString& theStartedOperationKind); + /// Make some functionality after the objects are hidden in viewer /// \param theObjects a list of hidden objects //virtual void processHiddenObject(const std::list& theObjects) {}; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 2b14c2506..a9905b884 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -480,6 +480,15 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const return mySketchMgr->canDisplayObject(theObject); } +bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind, + const QString& theStartedOperationKind) +{ + if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind)) + return true; + + return mySketchMgr->isNestedSketchFeature(theStartedOperationKind); +} + /*void PartSet_Module::processHiddenObject(const std::list& theObjects) { mySketchMgr->processHiddenObject(theObjects); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 79aa314f3..71a94e60d 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -170,6 +170,13 @@ public: /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; + /// Returns parent result if accepted, true if the started operation is a nested operation + /// of the previous operation + /// \param thePreviousOperationKind a kind of previous operation + /// \param theStartedOperationKind a kind of a new operation + virtual bool canUsePreselection(const QString& thePreviousOperationKind, + const QString& theStartedOperationKind); + /// Make some functionality after the objects are hidden in viewer /// \param theObjects a list of hidden objects //virtual void processHiddenObject(const std::list& theObjects); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 2a5ed0d37..9f8e4cf21 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -812,6 +812,22 @@ bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOpera return aNestedSketch; } +bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const +{ + bool aNestedSketch = false; + + FeaturePtr anActiveSketch = activeSketch(); + if (anActiveSketch.get()) { + ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation( + anActiveSketch->getKind().c_str()); + if (aSketchOperation) { + QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds(); + aNestedSketch = aGrantedOpIds.contains(theFeatureKind); + } + } + return aNestedSketch; +} + bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation, const CompositeFeaturePtr& theSketch) const { diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 648ed988b..b1ab8cb4c 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -111,6 +111,12 @@ public: /// \return the boolean result bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const; + /// Returns true if the feature kind belongs to list of granted features of Sketch + /// operation. An operation of a sketch should be started before. + /// \param theOperation an operation + /// \return the boolean result + bool isNestedSketchFeature(const QString& theFeatureKind) const; + /// Returns true if the operation is a create and nested sketch operationn /// \param theOperation a checked operation /// \param theSketch a sketch feature diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 2b53b2ec9..473f6e5d6 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -348,7 +348,9 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs // 6. Update sketcher actions XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr(); + myWorkshop->updateCommandStatus(); + aWorkshop->selector()->clearSelection(); myWorkshop->viewer()->update(); } -- 2.39.2