From: nds Date: Fri, 8 Apr 2016 08:20:22 +0000 (+0300) Subject: Issue #1393 Angle constraint : incorrect angle displayed. solution: do not select... X-Git-Tag: V_2.3.0~259 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=def1d660542e39cc9ed4ee27ab8cce8d231be01a;p=modules%2Fshaper.git Issue #1393 Angle constraint : incorrect angle displayed. solution: do not select any object in the viewer when passed through point widget is active. This commit is a validator creator for such widgets(a candidate to replace WidgetValidated). It is used now for Distance of Circle widget and Flyout point of dimensional constraints. The next integration is for the bug purpose(arc's passed point) --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index c7b2e215c..d2d93c9b5 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -58,6 +58,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetSwitch.h ModuleBase_WidgetToolbox.h ModuleBase_WidgetValidated.h + ModuleBase_WidgetValidator.h ModuleBase_IconFactory.h ModuleBase_WidgetErrorLabel.h ) @@ -114,6 +115,7 @@ SET(PROJECT_SOURCES ModuleBase_WidgetSwitch.cpp ModuleBase_WidgetToolbox.cpp ModuleBase_WidgetValidated.cpp + ModuleBase_WidgetValidator.cpp ModuleBase_IconFactory.cpp ModuleBase_WidgetErrorLabel.cpp ModuleBase_SelectionValidator.cpp diff --git a/src/ModuleBase/ModuleBase_FilterValidated.cpp b/src/ModuleBase/ModuleBase_FilterValidated.cpp index a41f15463..3d57d9f18 100644 --- a/src/ModuleBase/ModuleBase_FilterValidated.cpp +++ b/src/ModuleBase/ModuleBase_FilterValidated.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter); @@ -30,8 +31,12 @@ Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityO (aCurrentWidget); ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs()); myWorkshop->selection()->fillPresentation(aPrs, theOwner); - - aValid = !aWidgetValidated || aWidgetValidated->isValidSelection(aPrs); + if (aWidgetValidated) + aValid = !aWidgetValidated || aWidgetValidated->isValidSelection(aPrs); + else if (aCurrentWidget->widgetValidator()) { + ModuleBase_WidgetValidator* aWidgetValidator = aCurrentWidget->widgetValidator(); + aValid = aWidgetValidator->isValidSelection(aPrs); + } } #ifdef DEBUG_FILTERS diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 1985400a4..dc56812fc 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -7,6 +7,7 @@ #include "ModuleBase_ModelWidget.h" #include "ModuleBase_ViewerPrs.h" #include "ModuleBase_Tools.h" +#include "ModuleBase_WidgetValidator.h" #include #include @@ -30,7 +31,8 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, : QWidget(theParent), myIsEditing(false), myState(Stored), - myIsValueStateBlocked(false) + myIsValueStateBlocked(false), + myWidgetValidator(0) { myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false); @@ -168,6 +170,10 @@ void ModuleBase_ModelWidget::activate() if (anAttribute.get() != NULL && !anAttribute->isInitialized()) initializeValueByActivate(); } + + if (myWidgetValidator) + myWidgetValidator->activateFilters(true); + activateCustom(); } @@ -177,6 +183,9 @@ void ModuleBase_ModelWidget::deactivate() if (myState == ModifiedInPP || myState == ModifiedInViewer) storeValue(); myState = Stored; + + if (myWidgetValidator) + myWidgetValidator->activateFilters(false); } void ModuleBase_ModelWidget::initializeValueByActivate() diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 6712bc029..11d983a33 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -18,6 +18,7 @@ class Config_WidgetAPI; class ModuleBase_IWorkshop; class ModuleBase_ViewerPrs; +class ModuleBase_WidgetValidator; class QKeyEvent; /**\class ModuleBase_ModelWidget @@ -114,6 +115,14 @@ Q_OBJECT /// \param theValues a list of presentations virtual void getHighlighted(QList>& theValues) {}; + /// Checks if the selection presentation is valid in widget + /// \param theValue a selected presentation in the view + /// \return a boolean value + virtual bool isValidSelectionCustom(const std::shared_ptr& theValue) { return true; } + + /// Returns widget validator, by default it is NULL. To be created in a child if necessary + ModuleBase_WidgetValidator* widgetValidator() { return myWidgetValidator; } + /// Restore value from attribute data to the widget's control. Emits signals before and after store /// \return True in success bool restoreValue(); @@ -280,6 +289,7 @@ protected slots: void onWidgetValuesModified(); protected: + ModuleBase_WidgetValidator* myWidgetValidator; /// own validator, by default it is zero /// The attribute name of the model feature std::string myAttributeID; diff --git a/src/ModuleBase/ModuleBase_WidgetValidator.cpp b/src/ModuleBase/ModuleBase_WidgetValidator.cpp new file mode 100755 index 000000000..330b4c468 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetValidator.cpp @@ -0,0 +1,51 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include + +#include +#include +#include +#include + +ModuleBase_WidgetValidator::ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget, + ModuleBase_IWorkshop* theWorkshop) +: myModelWidget(theModelWidget), myWorkshop(theWorkshop) +{ +} + +ModuleBase_WidgetValidator::~ModuleBase_WidgetValidator() +{ +} + +//******************************************************************** +bool ModuleBase_WidgetValidator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue) +{ + return myModelWidget->isValidSelectionCustom(theValue); +} + +bool ModuleBase_WidgetValidator::isFilterActivated() const +{ + bool isActivated = false; + + Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter(); + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + + return aViewer->hasSelectionFilter(aSelFilter); +} + +bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate) +{ + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + + Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter(); + bool aHasSelectionFilter = aViewer->hasSelectionFilter(aSelFilter); + + if (toActivate) + aViewer->addSelectionFilter(aSelFilter); + else { + aViewer->removeSelectionFilter(aSelFilter); + //clearValidatedCash(); + } + + return aHasSelectionFilter; +} diff --git a/src/ModuleBase/ModuleBase_WidgetValidator.h b/src/ModuleBase/ModuleBase_WidgetValidator.h new file mode 100755 index 000000000..942e9bc93 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetValidator.h @@ -0,0 +1,57 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_WidgetValidator.h +// Created: 12 Mar 2015 +// Author: Natalia ERMOLAEVA + + +#ifndef ModuleBase_WidgetValidator_H_ +#define ModuleBase_WidgetValidator_H_ + +#include + +#include + +class ModuleBase_ModelWidget; +class ModuleBase_IWorkshop; +class ModuleBase_ViewerPrs; + +/** +* \ingroup GUI +* Implementation of widget with validators and filters processing. +*/ +class MODULEBASE_EXPORT ModuleBase_WidgetValidator +{ + public: + /// Constructor + /// \param theModelWidget the model widget to be validated + /// \param theWorkshop the current workshop + ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget, + ModuleBase_IWorkshop* theWorkshop); + virtual ~ModuleBase_WidgetValidator(); + + /// 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 + virtual bool isValidSelection(const std::shared_ptr& theValue); + + /// It obtains selection filters from the workshop and activates them in the active viewer + /// \param toActivate a flag about activation or deactivation the filters + /// \return true if the selection filter of the widget is activated in viewer context + bool activateFilters(const bool toActivate); + +private: + /// Returns true if the workshop validator filter has been already activated + /// \return boolean value + bool isFilterActivated() const; + +protected: + /// Reference to workshop + ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated + ModuleBase_IWorkshop* myWorkshop; ///< the active workshop +}; + +#endif /* ModuleBase_WidgetValidator_H_ */ diff --git a/src/PartSet/PartSet_WidgetPoint2DFlyout.cpp b/src/PartSet/PartSet_WidgetPoint2DFlyout.cpp index bb4d54b0e..f02e6a2b7 100755 --- a/src/PartSet/PartSet_WidgetPoint2DFlyout.cpp +++ b/src/PartSet/PartSet_WidgetPoint2DFlyout.cpp @@ -6,6 +6,8 @@ #include "PartSet_WidgetPoint2DFlyout.h" +#include "ModuleBase_WidgetValidator.h" + #include #include #include @@ -21,6 +23,13 @@ PartSet_WidgetPoint2DFlyout::PartSet_WidgetPoint2DFlyout(QWidget* theParent, const Config_WidgetAPI* theData) : PartSet_WidgetPoint2D(theParent, theWorkshop, theData) { + myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop); +} + +bool PartSet_WidgetPoint2DFlyout::isValidSelectionCustom( + const std::shared_ptr& theValue) +{ + return false; } bool PartSet_WidgetPoint2DFlyout::useSelectedShapes() const diff --git a/src/PartSet/PartSet_WidgetPoint2DFlyout.h b/src/PartSet/PartSet_WidgetPoint2DFlyout.h index f6247b33f..f6eeb7af3 100755 --- a/src/PartSet/PartSet_WidgetPoint2DFlyout.h +++ b/src/PartSet/PartSet_WidgetPoint2DFlyout.h @@ -30,6 +30,11 @@ public: /// Destructor virtual ~PartSet_WidgetPoint2DFlyout() {}; + /// Checks if the selection presentation is valid in widget + /// \param theValue a selected presentation in the view + /// \return a boolean value + virtual bool isValidSelectionCustom(const std::shared_ptr& theValue); + /// Activates the editor control only in case if the mouse over the OCC window, otherwise /// set focus to the usual double value control /// \return the state whether the widget can accept the focus diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 07270eacc..a2c024503 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -116,6 +117,22 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_Tools::zeroMargins(aLayout); aLayout->addWidget(myGroupBox); setLayout(aLayout); + + myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop); +} + +bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue) +{ + bool aValid = true; + /*if (getValidState(theValue, aValid)) { + return aValid; + } + aValid = isValidSelectionCustom(theValue); + if (aValid) + aValid = isValidSelectionForAttribute(theValue, attribute()); + + storeValidState(theValue, aValid); + */return aValid; } bool PartSet_WidgetPoint2D::resetCustom() diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index c685c5ca0..449b890f3 100755 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -47,6 +47,11 @@ Q_OBJECT /// Destructor virtual ~PartSet_WidgetPoint2D(); + /// Checks if the selection presentation is valid in widget + /// \param theValue a selected presentation in the view + /// \return a boolean value + virtual bool isValidSelectionCustom(const std::shared_ptr& theValue); + /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValues the wrapped widget values diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index ed8165c23..f3991587b 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -33,12 +34,19 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, myValueIsCashed(false), myIsFeatureVisibleInCash(true), myValueInCash(0) { myFirstPntName = theData->getProperty("first_point"); + myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop); } PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance() { } +bool PartSet_WidgetPoint2dDistance::isValidSelectionCustom( + const std::shared_ptr& theValue) +{ + return false; +} + bool PartSet_WidgetPoint2dDistance::resetCustom() { bool aDone = false; diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index c81a3dc82..55825c4b6 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -47,6 +47,11 @@ Q_OBJECT virtual ~PartSet_WidgetPoint2dDistance(); + /// Checks if the selection presentation is valid in widget + /// \param theValue a selected presentation in the view + /// \return a boolean value + virtual bool isValidSelectionCustom(const std::shared_ptr& theValue); + /// The methiod called when widget is deactivated virtual void deactivate();