From 871d21cd6e0ab86c79867145cb90a7e9dd7cd830 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 23 Jul 2014 18:22:23 +0400 Subject: [PATCH] Result attributes validators created --- src/Model/Model_Validator.cpp | 12 +++ src/Model/Model_Validator.h | 3 + src/ModelAPI/ModelAPI_Validator.h | 4 + src/ModuleBase/CMakeLists.txt | 2 + src/ModuleBase/ModuleBase_ModelWidget.cpp | 11 +-- src/ModuleBase/ModuleBase_ModelWidget.h | 9 +- .../ModuleBase_ResultValidators.cpp | 83 +++++++++++++++++++ src/ModuleBase/ModuleBase_ResultValidators.h | 36 ++++++++ src/ModuleBase/ModuleBase_WidgetBoolValue.cpp | 6 +- src/ModuleBase/ModuleBase_WidgetBoolValue.h | 2 +- .../ModuleBase_WidgetDoubleValue.cpp | 6 +- src/ModuleBase/ModuleBase_WidgetDoubleValue.h | 2 +- src/ModuleBase/ModuleBase_WidgetEditor.cpp | 7 +- src/ModuleBase/ModuleBase_WidgetEditor.h | 2 +- src/ModuleBase/ModuleBase_WidgetFactory.cpp | 26 ++++-- src/ModuleBase/ModuleBase_WidgetFactory.h | 1 + src/ModuleBase/ModuleBase_WidgetFeature.cpp | 23 ++++- src/ModuleBase/ModuleBase_WidgetFeature.h | 2 +- .../ModuleBase_WidgetFeatureOrAttribute.cpp | 5 +- .../ModuleBase_WidgetFeatureOrAttribute.h | 2 +- src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 5 +- src/ModuleBase/ModuleBase_WidgetPoint2D.h | 2 +- .../ModuleBase_WidgetPoint2dDistance.cpp | 5 +- .../ModuleBase_WidgetPoint2dDistance.h | 2 +- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 5 +- src/ModuleBase/ModuleBase_WidgetSelector.h | 2 +- src/PartSet/PartSet_Module.cpp | 10 +-- .../PartSet_OperationFeatureCreate.cpp | 6 +- src/PartSet/PartSet_WidgetSketchLabel.cpp | 5 +- src/PartSet/PartSet_WidgetSketchLabel.h | 4 +- src/SketchPlugin/plugin-Sketch.xml | 37 +++++++-- src/XGUI/XGUI_Workshop.cpp | 14 ++++ src/XGUI/XGUI_Workshop.h | 3 + 33 files changed, 280 insertions(+), 64 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_ResultValidators.cpp create mode 100644 src/ModuleBase/ModuleBase_ResultValidators.h diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index 771ea6c34..8ca1bf09f 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -79,6 +79,18 @@ const ModelAPI_Validator* Model_ValidatorsFactory::validator(const string& theFe return NULL; // not found } +const ModelAPI_Validator* Model_ValidatorsFactory::validator( + const std::string& theFeatureID, const std::string& theAttrID) const +{ + map > > >::const_iterator + aFeature = myAttrs.find(theFeatureID); + if (aFeature == myAttrs.cend()) return NULL; // feature is not found + map > >::const_iterator + anAttr = aFeature->second.find(theAttrID); + if (anAttr == aFeature->second.cend()) return NULL; // attribute is not found + return anAttr->second.first; +} + /*bool Model_ValidatorsFactory::validate( const boost::shared_ptr& theFeature, const string& theAttrID ) const { diff --git a/src/Model/Model_Validator.h b/src/Model/Model_Validator.h index a917911d9..8655b91a9 100644 --- a/src/Model/Model_Validator.h +++ b/src/Model/Model_Validator.h @@ -43,6 +43,9 @@ public: /// Provides a validator for the feature, returns NULL if no validator MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theFeatureID) const; + /// Provides a validator for the attribute, returns NULL if no validator + MODEL_EXPORT virtual const ModelAPI_Validator* validator( + const std::string& theFeatureID, const std::string& theAttrID) const; /// Returns the result of "validate" method for attribute of validator. /// If validator is not exists, returns true: everything is valid by default. diff --git a/src/ModelAPI/ModelAPI_Validator.h b/src/ModelAPI/ModelAPI_Validator.h index 4c807763a..7bc08324a 100644 --- a/src/ModelAPI/ModelAPI_Validator.h +++ b/src/ModelAPI/ModelAPI_Validator.h @@ -67,6 +67,10 @@ public: /// Provides a validator for the feature, returns NULL if no validator virtual const ModelAPI_Validator* validator(const std::string& theFeatureID) const = 0; + /// Provides a validator for the attribute, returns NULL if no validator + virtual const ModelAPI_Validator* validator( + const std::string& theFeatureID, const std::string& theAttrID) const = 0; + /// Returns the result of "validate" method for attribute of validator. /// If validator is not exists, returns true: everything is valid by default. //virtual bool validate( diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 350af8c02..1d8531d4d 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PROJECT_HEADERS ModuleBase_ISelection.h ModuleBase_ViewerPrs.h ModuleBase_Tools.h + ModuleBase_ResultValidators.h ) SET(PROJECT_SOURCES @@ -46,6 +47,7 @@ SET(PROJECT_SOURCES ModuleBase_WidgetValue.cpp ModuleBase_WidgetValueFeature.cpp ModuleBase_Tools.cpp + ModuleBase_ResultValidators.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 178eb5d63..756451c29 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -11,8 +11,10 @@ #include -ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData) - : QObject(theParent), myHasDefaultValue(false) +ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : QObject(theParent), myHasDefaultValue(false), myParentId(theParentId) { myAttributeID = theData ? theData->widgetId() : ""; } @@ -35,8 +37,3 @@ bool ModuleBase_ModelWidget::focusTo() } return true; } - -std::string ModuleBase_ModelWidget::attributeID() const -{ - return myAttributeID; -} diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 8e4b010f6..45c5789a5 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -33,7 +33,7 @@ public: /// Constructor /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData); + ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); /// Destructor virtual ~ModuleBase_ModelWidget() {}; @@ -68,7 +68,11 @@ public: /// Returns the attribute name /// \returns the string value - std::string attributeID() const; + std::string attributeID() const { return myAttributeID; } + + /// Returns the parent of the attribute + /// \returns the string value + std::string parentID() const { return myParentId; } signals: /// The signal about widget values changed @@ -90,6 +94,7 @@ protected: private: std::string myAttributeID; /// the attribute name of the model feature + std::string myParentId; /// name of parent }; #endif diff --git a/src/ModuleBase/ModuleBase_ResultValidators.cpp b/src/ModuleBase/ModuleBase_ResultValidators.cpp new file mode 100644 index 000000000..631857d15 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ResultValidators.cpp @@ -0,0 +1,83 @@ +// File: ModuleBase_ResultValidators.cpp +// Created: 23 July 2014 +// Author: Vitaly SMETANNIKOV + +#include "ModuleBase_ResultValidators.h" +#include "ModuleBase_Tools.h" + +#include +#include + +#include +#include +#include +#include +#include + + +ResultPtr result(const ObjectPtr theObject) +{ + return boost::dynamic_pointer_cast(theObject); +} + +TopoDS_Shape shape(ResultPtr theResult) +{ + boost::shared_ptr aShape = ModuleBase_Tools::shape(theResult); + if (aShape) + return aShape->impl(); + return TopoDS_Shape(); +} + + +bool ModuleBase_ResulPointValidator::isValid(const ObjectPtr theObject) const +{ + ResultPtr aResult = result(theObject); + if (!aResult) + return false; + TopoDS_Shape aShape = shape(aResult); + if (aShape.IsNull()) + return false; + + return aShape.ShapeType() == TopAbs_VERTEX; +} + + +bool ModuleBase_ResulLineValidator::isValid(const ObjectPtr theObject) const +{ + ResultPtr aResult = result(theObject); + if (!aResult) + return false; + TopoDS_Shape aShape = shape(aResult); + if (aShape.IsNull()) + return false; + + if (aShape.ShapeType() == TopAbs_EDGE) { + TopoDS_Edge aEdge = TopoDS::Edge(aShape); + Standard_Real aStart, aEnd; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd); + GeomAdaptor_Curve aAdaptor(aCurve); + return aAdaptor.GetType() == GeomAbs_Line; + } + return false; +} + + +bool ModuleBase_ResulArcValidator::isValid(const ObjectPtr theObject) const +{ + ResultPtr aResult = result(theObject); + if (!aResult) + return false; + TopoDS_Shape aShape = shape(aResult); + if (aShape.IsNull()) + return false; + + if (aShape.ShapeType() == TopAbs_EDGE) { + TopoDS_Edge aEdge = TopoDS::Edge(aShape); + Standard_Real aStart, aEnd; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd); + GeomAdaptor_Curve aAdaptor(aCurve); + return aAdaptor.GetType() == GeomAbs_Circle; + } + return false; +} + diff --git a/src/ModuleBase/ModuleBase_ResultValidators.h b/src/ModuleBase/ModuleBase_ResultValidators.h new file mode 100644 index 000000000..50cc2e7b1 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ResultValidators.h @@ -0,0 +1,36 @@ +// File: ModuleBase_ResultValidators.h +// Created: 23 July 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef ModuleBase_ResultValidators_H +#define ModuleBase_ResultValidators_H + +#include "ModuleBase.h" +#include +#include + +class ModuleBase_ResultValidator: public ModelAPI_Validator +{ +public: + virtual bool isValid(const ObjectPtr theObject) const = 0; +}; + +class ModuleBase_ResulPointValidator: public ModuleBase_ResultValidator +{ +public: + MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const; +}; + +class ModuleBase_ResulLineValidator: public ModuleBase_ResultValidator +{ +public: + MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const; +}; + +class ModuleBase_ResulArcValidator: public ModuleBase_ResultValidator +{ +public: + MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const; +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp index 2c5faadd2..1c3b68d1d 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -17,8 +17,10 @@ #include #include -ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData) - : ModuleBase_ModelWidget(theParent, theData) +ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId) { QString aText = QString::fromStdString(theData->widgetLabel()); QString aToolTip = QString::fromStdString(theData->widgetTooltip()); diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.h b/src/ModuleBase/ModuleBase_WidgetBoolValue.h index 3969e643e..17c5a6849 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.h +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.h @@ -19,7 +19,7 @@ public: /// Constructor /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData); + ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~ModuleBase_WidgetBoolValue(); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index f246713cd..04f80d879 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -25,8 +25,10 @@ #endif -ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData) - : ModuleBase_ModelWidget(theParent, theData) +ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId) { myContainer = new QWidget(theParent); QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 909855d18..a04a4e928 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -20,7 +20,7 @@ public: /// Constructor /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData); + ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~ModuleBase_WidgetDoubleValue(); diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 16d4c52cb..9774a52bb 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -25,13 +25,14 @@ #include ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_WidgetDoubleValue(theParent, theData) + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) { } ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const std::string& theAttribute) -: ModuleBase_WidgetDoubleValue(theParent, 0) +: ModuleBase_WidgetDoubleValue(theParent, 0, "") { setAttributeID(theAttribute); } diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.h b/src/ModuleBase/ModuleBase_WidgetEditor.h index 4585bdbbc..9c567bfcc 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetEditor.h @@ -26,7 +26,7 @@ public: /// \theParent the parent object /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData); + ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); /// Constructor /// \theParent the parent object /// \theParent the parent object diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 0c62cf361..6f292f3a6 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -54,6 +54,7 @@ ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory() void ModuleBase_WidgetFactory::createWidget(QWidget* theParent) { + myParentId = myWidgetApi->widgetId(); if (!myWidgetApi->toChildWidget()) return; @@ -177,7 +178,8 @@ QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, Q QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent) { - ModuleBase_WidgetDoubleValue* aDblWgt = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi); + ModuleBase_WidgetDoubleValue* aDblWgt = + new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId); myModelWidgets.append(aDblWgt); return aDblWgt->getControl(); @@ -185,29 +187,32 @@ QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent) QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent) { - ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent, myWidgetApi); + ModuleBase_WidgetPoint2D* aWidget = + new ModuleBase_WidgetPoint2D(theParent, myWidgetApi, myParentId); myModelWidgets.append(aWidget); return aWidget->getControl(); } QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent) { - ModuleBase_WidgetFeature* aWidget = new ModuleBase_WidgetFeature(theParent, myWidgetApi); + ModuleBase_WidgetFeature* aWidget = + new ModuleBase_WidgetFeature(theParent, myWidgetApi, myParentId); myModelWidgets.append(aWidget); return aWidget->getControl(); } QWidget* ModuleBase_WidgetFactory::featureOrAttributeSelectorControl(QWidget* theParent) { - ModuleBase_WidgetFeatureOrAttribute* aWidget = new ModuleBase_WidgetFeatureOrAttribute(theParent, - myWidgetApi); + ModuleBase_WidgetFeatureOrAttribute* aWidget = + new ModuleBase_WidgetFeatureOrAttribute(theParent, myWidgetApi, myParentId); myModelWidgets.append(aWidget); return aWidget->getControl(); } QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent) { - ModuleBase_WidgetEditor* aWidget = new ModuleBase_WidgetEditor(theParent, myWidgetApi); + ModuleBase_WidgetEditor* aWidget = + new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId); myModelWidgets.append(aWidget); return aWidget->getControl(); } @@ -230,7 +235,8 @@ bool ModuleBase_WidgetFactory::isInternalWidget(const std::string& theType) QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent) { - ModuleBase_WidgetSelector* aSelector = new ModuleBase_WidgetSelector(theParent, myWorkshop, myWidgetApi); + ModuleBase_WidgetSelector* aSelector = + new ModuleBase_WidgetSelector(theParent, myWorkshop, myWidgetApi, myParentId); myModelWidgets.append(aSelector); return aSelector->getControl(); } @@ -238,7 +244,8 @@ QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent) QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent) { - ModuleBase_WidgetBoolValue* aBoolWgt = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi); + ModuleBase_WidgetBoolValue* aBoolWgt = + new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId); myModelWidgets.append(aBoolWgt); return aBoolWgt->getControl(); @@ -247,7 +254,8 @@ QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent) QWidget* ModuleBase_WidgetFactory::point2dDistanceControl(QWidget* theParent) { - ModuleBase_WidgetPoint2dDistance* aDistWgt = new ModuleBase_WidgetPoint2dDistance(theParent, myWidgetApi); + ModuleBase_WidgetPoint2dDistance* aDistWgt = + new ModuleBase_WidgetPoint2dDistance(theParent, myWidgetApi, myParentId); myModelWidgets.append(aDistWgt); return aDistWgt->getControl(); diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index dbbdcffd2..5360f35db 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -58,6 +58,7 @@ private: ModuleBase_IWorkshop* myWorkshop; QList myModelWidgets; + std::string myParentId; }; #endif /* ModuleBase_WidgetFactory_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp index 7bf014ed3..6d533508e 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include #include @@ -24,11 +26,13 @@ #include ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData) + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_ModelWidget(theParent, theData, theParentId) { - QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE)); - myObjectKinds = aKinds.split(" "); + //QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE)); + //myObjectKinds = aKinds.split(" "); + //theData-> myContainer = new QWidget(theParent); QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); @@ -70,6 +74,17 @@ bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue) bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject) { + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + const ModelAPI_Validator* aValidator = aFactory->validator(parentID(), attributeID()); + if (aValidator) { + const ModuleBase_ResultValidator* aResValidator = + dynamic_cast(aValidator); + if (aResValidator) { + if (!aResValidator->isValid(theObject)) + return false; + } + } // TODO //if (!myObjectKinds.contains(theObject->getKind().c_str())) // return false; diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.h b/src/ModuleBase/ModuleBase_WidgetFeature.h index 8cfd499a6..fbfc7e2e9 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.h +++ b/src/ModuleBase/ModuleBase_WidgetFeature.h @@ -29,7 +29,7 @@ public: /// \theParent the parent object /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetFeature(QWidget* theParent, const Config_WidgetAPI* theData); + ModuleBase_WidgetFeature(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); /// Destructor virtual ~ModuleBase_WidgetFeature(); diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp index 70c0fe959..633adbc43 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp @@ -29,8 +29,9 @@ #include ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_WidgetFeature(theParent, theData) + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_WidgetFeature(theParent, theData, theParentId) { } diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h index 7084165a5..dc9bad6d8 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h @@ -25,7 +25,7 @@ public: /// \theParent the parent object /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, const Config_WidgetAPI* theData); + ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); /// Destructor virtual ~ModuleBase_WidgetFeatureOrAttribute(); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index cefa92847..9fbc7b7e6 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -28,8 +28,9 @@ #include ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData) + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_ModelWidget(theParent, theData, theParentId) { myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM); myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)), diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index 5c7269520..ed249c4b7 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -29,7 +29,7 @@ public: /// \theParent the parent object /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData); + ModuleBase_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); /// Destructor virtual ~ModuleBase_WidgetPoint2D(); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp index 871654bd2..ef5cf3207 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp @@ -14,8 +14,9 @@ #include -ModuleBase_WidgetPoint2dDistance::ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData) - : ModuleBase_WidgetDoubleValue(theParent, theData) +ModuleBase_WidgetPoint2dDistance::ModuleBase_WidgetPoint2dDistance(QWidget* theParent, + const Config_WidgetAPI* theData, const std::string& theParentId) + : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) { myFirstPntName = theData->getProperty("first_point"); } diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h index c635aa4f5..3ab47c62c 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h @@ -19,7 +19,7 @@ public: /// Constructor /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData); + ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~ModuleBase_WidgetPoint2dDistance(); diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 5e0cd3e98..1ae894aeb 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -56,8 +56,9 @@ TopAbs_ShapeEnum ModuleBase_WidgetSelector::shapeType(const QString& theType) ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop), myActivateOnStart(false) + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop), myActivateOnStart(false) { myContainer = new QWidget(theParent); QHBoxLayout* aLayout = new QHBoxLayout(myContainer); diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index b1782d072..1388bc773 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -28,7 +28,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetSelector: public ModuleBase_ModelWidget public: ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData); + const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~ModuleBase_WidgetSelector(); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 99d36b0ad..6ddaeabe1 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -106,10 +106,6 @@ XGUI_Workshop* PartSet_Module::workshop() const void PartSet_Module::createFeatures() { - Config_ModuleReader aXMLReader = Config_ModuleReader(); - aXMLReader.readAll(); - myFeaturesInFiles = aXMLReader.featuresInFiles(); - //!! Test registering of validators PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); @@ -118,6 +114,10 @@ void PartSet_Module::createFeatures() aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator); aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator); aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator); + + Config_ModuleReader aXMLReader = Config_ModuleReader(); + aXMLReader.readAll(); + myFeaturesInFiles = aXMLReader.featuresInFiles(); } void PartSet_Module::featureCreated(QAction* theFeature) @@ -613,7 +613,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* Config_WidgetAPI* theWidgetApi, QList& theModelWidgets) { if (theType == "sketch-start-label") { - PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi); + PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, ""); aWgt->setOperationsMgr(myWorkshop->operationMgr()); theModelWidgets.append(aWgt); return aWgt->getControl(); diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 1c8c5836b..0b390fe76 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -146,11 +146,11 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle } } ObjectPtr aFeature; -/* TODO if (!theSelected.empty()) { + if (!theSelected.empty()) { ModuleBase_ViewerPrs aPrs = theSelected.front(); aFeature = aPrs.object(); - } else*/ - aFeature = feature(); // for the widget distance only + } else + aFeature = feature(); // for the widget distance only bool isApplyed = setWidgetValue(aFeature, aX, anY); if (isApplyed) { diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 4b39dc60e..6089ab850 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -13,8 +13,9 @@ #include PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData) + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_ModelWidget(theParent, theData, theParentId) { myText = QString::fromStdString(theData->getProperty("title")); myLabel = new QLabel(myText, theParent); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 839b3ec57..558747b46 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -17,7 +17,9 @@ class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_ModelWidget { Q_OBJECT public: - PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData); + PartSet_WidgetSketchLabel(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId); virtual ~PartSet_WidgetSketchLabel() {}; diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 999d742d2..e6d71aa23 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -25,37 +25,58 @@ + + + + - - + + + + + + + - - + + + + + + diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 0ca48658f..9505d9cf2 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -135,6 +136,7 @@ void XGUI_Workshop::startApplication() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); + registerValidators(); activateModule(); if (myMainWindow) { myMainWindow->show(); @@ -997,3 +999,15 @@ void XGUI_Workshop::updateCommandsOnViewSelection() } } } + + +//************************************************************** +void XGUI_Workshop::registerValidators() const +{ + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + + aFactory->registerValidator("ModuleBase_ResulPointValidator", new ModuleBase_ResulPointValidator); + aFactory->registerValidator("ModuleBase_ResulLineValidator", new ModuleBase_ResulLineValidator); + aFactory->registerValidator("ModuleBase_ResulArcValidator", new ModuleBase_ResulArcValidator); +} diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index c0d5d6455..74c20b177 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -177,6 +177,9 @@ protected slots: private: void initMenu(); + void registerValidators() const; + + ModuleBase_IModule* loadModule(const QString& theModule); bool activateModule(); -- 2.30.2