X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetValidated.cpp;h=caadc6be7582cc17eb8121963161c657c171b058;hb=872ac5e3e0196ad70c2a01a79bd070c9a7d4a2e6;hp=d17cd98e84a2d224342c55deb8920f13a7b9cec0;hpb=e3f1f11a6fa18935c70877e804bae039d375094b;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index d17cd98e8..caadc6be7 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -3,15 +3,18 @@ #include #include #include +#include #include #include -#include #include +#include #include #include +#include + #include ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent, @@ -25,29 +28,57 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated() { } +//******************************************************************** bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue) { bool isDone = false; - Handle(SelectMgr_EntityOwner) anOwner = theValue.owner(); - if (isValid(anOwner)) { - //storeAttributeValue(anOwner); - setSelection(anOwner); + if (isValidSelection(theValue)) { + isDone = setSelectionCustom(theValue); updateObject(myFeature); - //isDone = setSelection(anOwner); emit valuesChanged(); } return isDone; } -bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner) +//******************************************************************** +bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& theValue) { - backupAttributeValue(true); + DataPtr aData = myFeature->data(); + AttributePtr anAttribute = myFeature->attribute(attributeID()); + + // stores the current values of the widget attribute + Events_Loop* aLoop = Events_Loop::loop(); + // blocks the flush signals to avoid the temporary objects visualization in the viewer + // they should not be shown in order to do not lose highlight by erasing them + aLoop->activateFlushes(false); + + aData->blockSendAttributeUpdated(true); + bool isAttributeBlocked = anAttribute->blockSetInitialized(true); + storeAttributeValue(); - setSelection(theOwner); - bool aValid = isValidAttribute(); + // saves the owner value to the widget attribute + bool aValid = setSelectionCustom(theValue); - backupAttributeValue(false); + if (aValid) + // checks the attribute validity + aValid = isValidAttribute(); + + // restores the current values of the widget attribute + restoreAttributeValue(aValid); + aData->blockSendAttributeUpdated(false); + anAttribute->blockSetInitialized(isAttributeBlocked); + aLoop->activateFlushes(true); + + // In particular case the results are deleted and called as redisplayed inside of this + // highlight-selection, to they must be flushed as soon as possible. + // Example: selection of group-vertices subshapes with shift pressend on body. Without + // these 4 lines below the application crashes because of left presentations on + // removed results still in the viewer. + static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED); + static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); + aLoop->flush(aDeletedEvent); + aLoop->flush(aRedispEvent); return aValid; } @@ -59,14 +90,11 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); std::list aValidators; std::list > anArguments; - aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments); DataPtr aData = myFeature->data(); AttributePtr anAttribute = myFeature->attribute(attributeID()); - aData->blockSendAttributeUpdated(true); - - // 3. check the acceptability of the current values std::list::iterator aValidator = aValidators.begin(); std::list >::iterator aArgs = anArguments.begin(); bool aValid = true; @@ -77,37 +105,9 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const aValid = aAttrValidator->isValid(anAttribute, *aArgs); } } - aData->blockSendAttributeUpdated(false); - return aValid; } -//******************************************************************** -bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const -{ - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::list aValidators; - std::list > anArguments; - aFactory->validators(parentID(), attributeID(), aValidators, anArguments); - - // Check the type of selected object - std::list::iterator aValidator = aValidators.begin(); - bool isValid = true; - for (; aValidator != aValidators.end(); aValidator++) { - const ModelAPI_ResultValidator* aResValidator = - dynamic_cast(*aValidator); - if (aResValidator) { - isValid = false; - if (aResValidator->isValid(theObj)) { - isValid = true; - break; - } - } - } - return isValid; -} - void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const { @@ -118,35 +118,26 @@ void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorksh aViewer->addSelectionFilter(aSelFilter); else aViewer->removeSelectionFilter(aSelFilter); -/* - // apply filters loaded from the XML definition of the widget - ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters(); - SelectMgr_ListOfFilter aFactoryFilters; - aFactory->filters(parentID(), attributeID(), aFactoryFilters); - SelectMgr_ListIteratorOfListOfFilter aFactoryIt(aFactoryFilters); - for (; aFactoryIt.More(); aFactoryIt.Next()) { - Handle(SelectMgr_Filter) aSelFilter = aFactoryIt.Value(); - if (aSelFilter.IsNull()) - continue; - if (toActivate) - aViewer->addSelectionFilter(aSelFilter); - else - aViewer->removeSelectionFilter(aSelFilter); - }*/ } -void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop, - SelectMgr_ListOfFilter& theFilters) const +QList ModuleBase_WidgetValidated::getSelectedEntitiesOrObjects( + ModuleBase_ISelection* theSelection) const { - ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters(); - SelectMgr_ListOfFilter aFilters; - aFactory->filters(parentID(), attributeID(), aFilters); - SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); - for (; aIt.More(); aIt.Next()) { - Handle(SelectMgr_Filter) aSelFilter = aIt.Value(); - if (aSelFilter.IsNull()) - continue; - - theFilters.Append(aSelFilter); + QList aSelectedPrs; + + // find selected presentation either in the viewer or in OB + // the selection in OCC viewer - the selection of a sub-shapes in the viewer + aSelectedPrs = theSelection->getSelected(); + if (aSelectedPrs.empty()) { + // the selection in Object Browser + QObjectPtrList anObjects = theSelection->selectedObjects(); + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (anObject.get() != NULL) { + aSelectedPrs.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL)); + } + } } + return aSelectedPrs; }