From: nds Date: Fri, 20 Mar 2015 07:47:39 +0000 (+0300) Subject: Union of validator and filter functionalities. X-Git-Tag: V_1.1.0~103 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8053cdcd3da8770ad21fb75f2ea69deb6d08f97a;p=modules%2Fshaper.git Union of validator and filter functionalities. Code improvement. --- diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index e60c8cb30..2c970d174 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -223,66 +223,6 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() } } -//******************************************************************** -bool ModuleBase_WidgetShapeSelector::setSelectionPrs(ModuleBase_ViewerPrs theValue) -{ - ObjectPtr aObject = theValue.object(); - ObjectPtr aCurrentObject = getObject(myFeature->attribute(attributeID())); - if ((!aCurrentObject) && (!aObject)) - return false; - - // Check that the selected object is result (others can not be accepted) - ResultPtr aRes = std::dynamic_pointer_cast(aObject); - if (!aRes) - return false; - - if (myFeature) { - // We can not select a result of our feature - const std::list>& aResList = myFeature->results(); - std::list >::const_iterator aIt; - for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { - if ((*aIt) == aRes) - return false; - } - } - // Check that object belongs to active document or PartSet - DocumentPtr aDoc = aRes->document(); - SessionPtr aMgr = ModelAPI_Session::get(); - if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument())) - return false; - - // Check that the result has a shape - GeomShapePtr aShape = ModelAPI_Tools::shape(aRes); - if (!aShape) - return false; - - // Get sub-shapes from local selection - if (!theValue.shape().IsNull()) { - aShape = std::shared_ptr(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(theValue.shape())); - } - // Check that the selection corresponds to selection type - if (!acceptSubShape(aShape)) - return false; - - setObject(aObject, aShape); - return true; -} - -//******************************************************************** -void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr theShape) -{ - //if ( - storeAttributeValues(theObj, theShape);//) - // updateObject(myFeature); - - //if (theObj) { - // raisePanel(); - //} - //updateSelectionName(); - //emit valuesChanged(); -} - //******************************************************************** //bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const //{ @@ -475,59 +415,55 @@ void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup) bool ModuleBase_WidgetShapeSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner) { bool isDone = false; - //QList aSelected = myWorkshop->selection()->getSelected(); - //if (aSelected.size() > 0) { + ModuleBase_ViewerPrs aPrs; myWorkshop->selection()->fillPresentation(aPrs, theOwner); - isDone = setSelectionPrs(aPrs); - //} - return isDone; -} - -//******************************************************************** -void ModuleBase_WidgetShapeSelector::deactivate() -{ - activateSelection(false); - disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); -} + ObjectPtr aObject = aPrs.object(); + ObjectPtr aCurrentObject = getObject(myFeature->attribute(attributeID())); + if ((!aCurrentObject) && (!aObject)) + return false; -//******************************************************************** -/*bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr theShape) -{ - bool isValid = ModuleBase_WidgetValidated::isValid(theObj, theShape); - if (!isValid) + // Check that the selected object is result (others can not be accepted) + ResultPtr aRes = std::dynamic_pointer_cast(aObject); + if (!aRes) return false; + if (myFeature) { + // We can not select a result of our feature + const std::list>& aResList = myFeature->results(); + std::list >::const_iterator aIt; + for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { + if ((*aIt) == aRes) + return false; + } + } + // Check that object belongs to active document or PartSet + DocumentPtr aDoc = aRes->document(); SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::list aValidators; - std::list > anArguments; - aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument())) + return false; - DataPtr aData = myFeature->data(); - AttributePtr anAttribute = myFeature->attribute(attributeID()); + // Check that the result has a shape + GeomShapePtr aShape = ModelAPI_Tools::shape(aRes); + if (!aShape) + return false; - // 1. make a backup of the previous attribute values - backupAttributeValue(true); - // 2. store the current values, disable the model's update - 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; - for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) { - const ModelAPI_AttributeValidator* aAttrValidator = - dynamic_cast(*aValidator); - if (aAttrValidator) { - aValid = aAttrValidator->isValid(anAttribute, *aArgs); - } + // Get sub-shapes from local selection + if (!aPrs.shape().IsNull()) { + aShape = std::shared_ptr(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aPrs.shape())); } + // Check that the selection corresponds to selection type + if (!acceptSubShape(aShape)) + return false; - // 4. if the values are not valid, restore the previous values to the attribute - backupAttributeValue(false); + storeAttributeValues(aObject, aShape); + return true; +} - // 5. enable the model's update - aData->blockSendAttributeUpdated(false); - return aValid; -}*/ +//******************************************************************** +void ModuleBase_WidgetShapeSelector::deactivate() +{ + activateSelection(false); + disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); +} diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index c430fc170..2c5e253b3 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -82,11 +82,6 @@ Q_OBJECT /// \return a control list virtual QList getControls() const; - /// Set the given wrapped value to the current widget - /// This value should be processed in the widget according to the needs - /// \param theValue the wrapped widget value - virtual bool setSelectionPrs(ModuleBase_ViewerPrs theValue); - /// Fills the attribute with the value of the selected owner /// \param theOwner a selected owner virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner); @@ -132,20 +127,10 @@ Q_OBJECT /// \param theShape a shape virtual bool acceptSubShape(std::shared_ptr theShape) const; - // Set the given object as a value of the widget - /// \param theObj an object - /// \param theShape a shape - void setObject(ObjectPtr theObj, std::shared_ptr theShape = std::shared_ptr()); - // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute /// \return a shape GeomShapePtr getShape() const; - /// Check the selected with validators if installed - /// \param theObj the object for checking - /// \param theShape the shape for checking - //virtual bool isValid(ObjectPtr theObj, std::shared_ptr theShape); - /// Clear attribute void clearAttribute(); diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index d17cd98e8..84a15322e 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -31,10 +31,8 @@ bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue) Handle(SelectMgr_EntityOwner) anOwner = theValue.owner(); if (isValid(anOwner)) { - //storeAttributeValue(anOwner); setSelection(anOwner); updateObject(myFeature); - //isDone = setSelection(anOwner); emit valuesChanged(); } return isDone;