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
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<ModuleBase_ViewerPrsPtr> aPreSelected = aSelection->getSelected(ModuleBase_ISelection::AllControls);
+
if (!myWorkshop->canStartOperation(theCmdId))
return;
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(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);
}
}
return myPreviousCurrentFeature;
}
-void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelection,
- ModuleBase_IViewer* theViewer)
+void ModuleBase_OperationFeature::initSelection(const QList<ModuleBase_ViewerPrsPtr>& thePreSelected)
{
- QList<ModuleBase_ViewerPrsPtr> aPreSelected;
+ QObjectPtrList aCurrentFeatureResults;
+
// Check that the selected result are not results of operation feature
FeaturePtr aFeature = feature();
if (aFeature) {
- QList<ModuleBase_ViewerPrsPtr> aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls);
-
std::list<ResultPtr> aResults;
ModelAPI_Tools::allResults(aFeature, aResults);
- QObjectPtrList aResList;
std::list<ResultPtr>::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<ModuleBase_ViewerPrsPtr> 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<ModuleBase_ViewerPrsPtr>& theValues)
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<std::shared_ptr<ModuleBase_ViewerPrs>>& thePreSelected);
/// Fill internal map by preselection
/// \param theValues a list of preselection
//}
/// 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)
if (aFOperation) {
myNoMoreWidgetsAttribute = "";
myIsFlagsBlocked = true;
- FeaturePtr aPrevFeature = aFOperation->feature();
- aFOperation->commit();
module()->launchOperation(aFOperation->id());
myIsFlagsBlocked = false;
resetFlags();