X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetValidated.h;h=8b2ae15ba440f206f71ba7b03f1d27d4bc2f4bff;hb=2469ecd08c3b16def494626928ff81e575bdfe3d;hp=8c05cbb046a64055f2bf67cee0ec5aa0d22c5c2b;hpb=af899dd91be39cdb63992c001908f27833835174;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index 8c05cbb04..8b2ae15ba 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -1,4 +1,4 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D // File: ModuleBase_WidgetValidated.h // Created: 12 Mar 2015 @@ -12,13 +12,19 @@ #include #include +#include #include +#include #include +#include + class QWidget; class ModuleBase_IWorkshop; class ModuleBase_ISelection; +class ModuleBase_WidgetSelectorStore; +class ModelAPI_Validator; class Config_WidgetAPI; class Handle_SelectMgr_EntityOwner; @@ -32,61 +38,132 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg public: /// Constructor /// \param theParent the parent object + /// \param theWorkshop a reference to workshop /// \param theData the widget configuation. The attribute of the model widget is obtained from - /// \param theParentId is Id of a parent of the current attribute ModuleBase_WidgetValidated(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId); + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData); virtual ~ModuleBase_WidgetValidated(); - /// Checks all widget validator if the owner is valid - /// \param theOwner a selected owner in the view + /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating, + /// next, the attribute's validating. It trying on the give selection to current attribute by + /// setting the value inside and calling validators. After this, the previous attribute value is + /// restored.The valid/invalid value is cashed. + /// \param theValue a selected presentation in the view /// \return a boolean value - bool isValidSelection(const ModuleBase_ViewerPrs& theValue); + virtual bool isValidSelection(const std::shared_ptr& theValue); + + //! Returns data object by AIS + ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const; - /// Set the given wrapped value to the current widget - /// This value should be processed in the widget according to the needs - /// The method is called by the current operation to process the operation preselection. - /// It is redefined to check the value validity and if it is, fill the attribute with by value - /// \param theValue the wrapped widget value - virtual bool setSelection(ModuleBase_ViewerPrs theValue); + //! Clear all validated cash in the widget + void clearValidatedCash(); protected: + /// Checks whether all active viewer filters validate the presentation + /// \param thePrs a selected presentation in the view + /// \return a boolean value + bool isValidInFilters(const std::shared_ptr& thePrs); + + /// Checks all attribute validators returns valid. It tries on the given selection + /// to current attribute by setting the value inside and calling validators. After this, + /// the previous attribute value is restored.The valid/invalid value is cashed. + /// \param theValue a selected presentation in the view + /// \return a boolean value + bool isValidSelectionForAttribute(const std::shared_ptr& theValue, + const AttributePtr& theAttribute); + + /// Retunrs attribute, which should be validated. In default implementation, + /// this is an attribute of ID + /// \return an attribute + virtual AttributePtr attribute() const; + /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different /// parameters of the current attribute - virtual void storeAttributeValue() = 0; + /// \param theAttribute an attribute to be stored + virtual void storeAttributeValue(const AttributePtr& theAttribute); /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different /// parameters of the current attribute + /// \param theAttribute an attribute to be restored /// \param theValid a boolean flag, if restore happens for valid parameters - virtual void restoreAttributeValue(const bool theValid) = 0; + virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid); - /// Fills the attribute with the value of the selected owner - /// \param theOwner a selected owner - virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0; + /// Checks the widget validity. By default, it returns true. + /// \param thePrs a selected presentation in the view + /// \return a boolean value + virtual bool isValidSelectionCustom(const std::shared_ptr& thePrs); - virtual void removePresentations() {}; + /// Fills the attribute with the value of the selected owner + /// \param thePrs a selected owner + virtual bool setSelectionCustom(const std::shared_ptr& thePrs) = 0; - /// Checks the current attibute in all attribute validators - // \return true if all validators return that the attribute is valid - bool isValidAttribute() const; + /// Returns a list of selected presentations in the viewer and object browser + /// The presentations from the object browser are filtered by the AIS context filters + /// \return a list of presentations + QList> getFilteredSelected(); /// It obtains selection filters from the workshop and activates them in the active viewer - /// \param theWorkshop an active workshop /// \param toActivate a flag about activation or deactivation the filters - virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const; - - /// Returns a list of selected presentations. Firstly it is obtained from the viewer, - /// if there are not selected objects in the viewer, it get the selection from the object browser. - /// If the browser has selected objects, the viewer prs objects are created with only object - /// field of the presentation initialized. The widget should accept the selection in the object - /// browser at the same way as in the viewer. - /// \param theSelection a selection, where the selected objects and presentations are found - /// \return a list of presentations - QList getSelectedEntitiesOrObjects(ModuleBase_ISelection* theSelection) const; + /// \return true if the selection filter of the widget is activated in viewer context + bool activateFilters(const bool toActivate); + + /// Block the model flush of update and intialization of attribute + /// \param theAttribute an attribute of blocking + /// \param theToBlock flag whether the model is blocked or unblocked + /// \param isActive out value if model is blocked, in value if model is unblocked + /// to be used to restore flush state when unblocked + /// \param isAttributeSetInitializedBlocked out value if model is blocked + /// in value if model is unblocked to be used to restore previous state when unblocked + virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock, + bool& isFlushesActived, bool& isAttributeSetInitializedBlocked); + +private: + /// Checks the current attibute in all attribute validators + /// \param theAttribute an attribute to be validated + /// \return true if all validators return that the attribute is valid + bool isValidAttribute(const AttributePtr& theAttribute) const; + /// Returns true if the workshop validator filter has been already activated + /// \return boolean value + bool isFilterActivated() const; + +protected: + /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored + /// \param theValue a viewer presentation + /// \param theValid a valid state + bool getValidState(const std::shared_ptr& theValue, bool& theValid); + + /// Store the validity state of the presentation in an internal map + /// \param theValue a viewer presentation + /// \param theValid a valid state + void storeValidState(const std::shared_ptr& theValue, const bool theValid); + +private: + /// Applies AIS context filters to the parameter list. The not approved presentations are + /// removed from the parameters. + /// \param theValues a list of presentations. + void filterPresentations(QList>& theValues); + + /// Remove subshapes of compsolids if whole compsolid is present. + /// \param theValues a list of presentations. + void filterCompSolids(QList>& theValues); + +protected: + /// Reference to workshop + ModuleBase_IWorkshop* myWorkshop; + /// The widget is in validation mode: store is performed, restore is not + bool myIsInValidate; + +private: + ObjectPtr myPresentedObject; /// back up of the filtered object + QList> myValidPrs; /// cash of valid selection presentations + QList> myInvalidPrs; /// cash of invalid selection presentations + + /// store to backup parameters of the model + ModuleBase_WidgetSelectorStore* myAttributeStore; }; #endif /* MODULEBASE_WIDGETVALIDATED_H_ */