From 811681738727583c29043cd55903fb71cec19038 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 1 Sep 2016 19:30:42 +0300 Subject: [PATCH] Issue #1701 Preselecting before calling constraints does not put objects in the input field Issue #1655(checked) In the Sketcher, automatically unselect eventuel selected objects when returning to the neutral point Code improvement to store selection before commit of previous operation --- src/ModuleBase/ModuleBase_IModule.cpp | 11 ++++++-- .../ModuleBase_OperationFeature.cpp | 28 +++++++++---------- src/ModuleBase/ModuleBase_OperationFeature.h | 7 ++--- src/PartSet/PartSet_SketcherMgr.cpp | 4 +-- src/PartSet/PartSet_SketcherReetntrantMgr.cpp | 2 -- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 424260dcb..73ab7d310 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -71,15 +71,20 @@ void ModuleBase_IModule::launchModal(const QString& theCmdId) void ModuleBase_IModule::launchOperation(const QString& theCmdId) { + /// selection should be obtained from workshop before ask if the operation can be started as + /// the canStartOperation method performs commit/abort of previous operation. Sometimes commit/abort + /// may cause selection clear(Sketch operation) as a result it will be lost and is not used for preselection. + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + QList aPreSelected = aSelection->getSelected(ModuleBase_ISelection::AllControls); + if (!myWorkshop->canStartOperation(theCmdId)) return; ModuleBase_OperationFeature* aFOperation = dynamic_cast (createOperation(theCmdId.toStdString())); if (aFOperation) { - ModuleBase_ISelection* aSelection = myWorkshop->selection(); - // Initialise operation with preliminary selection - aFOperation->initSelection(aSelection, myWorkshop->viewer()); + aFOperation->initSelection(aPreSelected); + workshop()->processLaunchOperation(aFOperation); } } diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 9745c5fe0..450e52399 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -448,30 +448,30 @@ FeaturePtr ModuleBase_OperationFeature::previousCurrentFeature() return myPreviousCurrentFeature; } -void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelection, - ModuleBase_IViewer* theViewer) +void ModuleBase_OperationFeature::initSelection(const QList& thePreSelected) { - QList aPreSelected; + QObjectPtrList aCurrentFeatureResults; + // Check that the selected result are not results of operation feature FeaturePtr aFeature = feature(); if (aFeature) { - QList aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls); - std::list aResults; ModelAPI_Tools::allResults(aFeature, aResults); - QObjectPtrList aResList; std::list::const_iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) - aResList.append(*aIt); - - foreach (ModuleBase_ViewerPrsPtr aPrs, aSelected) { - if ((!aResList.contains(aPrs->object())) && (aPrs->object() != aFeature)) + aCurrentFeatureResults.append(*aIt); + } + + if (aCurrentFeatureResults.empty()) /// filtering of selection is not necessary + setPreselection(thePreSelected); + else { // create preselection list without results of current feature + QList aPreSelected; + foreach (ModuleBase_ViewerPrsPtr aPrs, thePreSelected) { + if ((!aCurrentFeatureResults.contains(aPrs->object())) && (aPrs->object() != aFeature)) aPreSelected.append(aPrs); } - } else - aPreSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls); - - setPreselection(aPreSelected); + setPreselection(aPreSelected); + } } void ModuleBase_OperationFeature::setPreselection(const QList& theValues) diff --git a/src/ModuleBase/ModuleBase_OperationFeature.h b/src/ModuleBase/ModuleBase_OperationFeature.h index 268b1d759..7e1ffb291 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.h +++ b/src/ModuleBase/ModuleBase_OperationFeature.h @@ -93,10 +93,9 @@ Q_OBJECT virtual bool isDisplayedOnStart(ObjectPtr theObject); /// Initialisation of operation with preliminary selection - /// \param theSelection an instance of Selection class - /// \param theViewer a viewer to have the viewer the eye position - virtual void initSelection(ModuleBase_ISelection* theSelection, - ModuleBase_IViewer* theViewer); + /// \param thePreSelected a container of selected presentations + virtual void initSelection( + const QList>& thePreSelected); /// Fill internal map by preselection /// \param theValues a list of preselection diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 03781cb7a..abe3a586f 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -1017,9 +1017,7 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation) //} /// improvement to deselect automatically all eventual selected objects, when // returning to the neutral point of the Sketcher - // if the operation is restarted, the previous selection is used to initialize started operation - if (!myModule->sketchReentranceMgr()->isInternalEditStarted()) - workshop()->selector()->clearSelection(); + workshop()->selector()->clearSelection(); } void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) diff --git a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp index 2c6dee25f..95a68cf42 100755 --- a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp @@ -458,8 +458,6 @@ void PartSet_SketcherReetntrantMgr::restartOperation() if (aFOperation) { myNoMoreWidgetsAttribute = ""; myIsFlagsBlocked = true; - FeaturePtr aPrevFeature = aFOperation->feature(); - aFOperation->commit(); module()->launchOperation(aFOperation->id()); myIsFlagsBlocked = false; resetFlags(); -- 2.39.2