ModuleBase_WidgetSwitch.h
ModuleBase_WidgetToolbox.h
ModuleBase_WidgetValidated.h
+ ModuleBase_WidgetValidator.h
ModuleBase_IconFactory.h
ModuleBase_WidgetErrorLabel.h
)
ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetToolbox.cpp
ModuleBase_WidgetValidated.cpp
+ ModuleBase_WidgetValidator.cpp
ModuleBase_IconFactory.cpp
ModuleBase_WidgetErrorLabel.cpp
ModuleBase_SelectionValidator.cpp
#include <ModuleBase_ISelection.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_WidgetValidated.h>
+#include <ModuleBase_WidgetValidator.h>
#include <ModuleBase_ViewerPrs.h>
IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter);
(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
#include "ModuleBase_ModelWidget.h"
#include "ModuleBase_ViewerPrs.h"
#include "ModuleBase_Tools.h"
+#include "ModuleBase_WidgetValidator.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_Attribute.h>
: QWidget(theParent),
myIsEditing(false),
myState(Stored),
- myIsValueStateBlocked(false)
+ myIsValueStateBlocked(false),
+ myWidgetValidator(0)
{
myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false);
if (anAttribute.get() != NULL && !anAttribute->isInitialized())
initializeValueByActivate();
}
+
+ if (myWidgetValidator)
+ myWidgetValidator->activateFilters(true);
+
activateCustom();
}
if (myState == ModifiedInPP || myState == ModifiedInViewer)
storeValue();
myState = Stored;
+
+ if (myWidgetValidator)
+ myWidgetValidator->activateFilters(false);
}
void ModuleBase_ModelWidget::initializeValueByActivate()
class Config_WidgetAPI;
class ModuleBase_IWorkshop;
class ModuleBase_ViewerPrs;
+class ModuleBase_WidgetValidator;
class QKeyEvent;
/**\class ModuleBase_ModelWidget
/// \param theValues a list of presentations
virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& 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<ModuleBase_ViewerPrs>& 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();
void onWidgetValuesModified();
protected:
+ ModuleBase_WidgetValidator* myWidgetValidator; /// own validator, by default it is zero
/// The attribute name of the model feature
std::string myAttributeID;
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include <ModuleBase_WidgetValidator.h>
+
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_IWorkshop.h>
+
+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;
+}
--- /dev/null
+// 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 <ModuleBase.h>
+
+#include <memory>
+
+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<ModuleBase_ViewerPrs>& 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_ */
#include "PartSet_WidgetPoint2DFlyout.h"
+#include "ModuleBase_WidgetValidator.h"
+
#include <XGUI_Workshop.h>
#include <XGUI_ModuleConnector.h>
#include <XGUI_Displayer.h>
const Config_WidgetAPI* theData)
: PartSet_WidgetPoint2D(theParent, theWorkshop, theData)
{
+ myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
+}
+
+bool PartSet_WidgetPoint2DFlyout::isValidSelectionCustom(
+ const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
+{
+ return false;
}
bool PartSet_WidgetPoint2DFlyout::useSelectedShapes() const
/// 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<ModuleBase_ViewerPrs>& 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
#include <ModuleBase_IViewWindow.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_WidgetValidator.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
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()
/// 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<ModuleBase_ViewerPrs>& 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
#include <ModuleBase_IViewWindow.h>
#include <ModuleBase_IViewer.h>
#include <ModuleBase_Tools.h>
+#include <ModuleBase_WidgetValidator.h>
#include <GeomAPI_Pnt2d.h>
#include <Config_WidgetAPI.h>
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<ModuleBase_ViewerPrs>& theValue)
+{
+ return false;
+}
+
bool PartSet_WidgetPoint2dDistance::resetCustom()
{
bool aDone = false;
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<ModuleBase_ViewerPrs>& theValue);
+
/// The methiod called when widget is deactivated
virtual void deactivate();