From: nds Date: Fri, 20 Mar 2015 12:31:45 +0000 (+0300) Subject: Union of validator and filter functionalities. X-Git-Tag: V_1.1.0~97 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4f8e856c994a2cd04b21aa38fc79a2d91114cb6a;p=modules%2Fshaper.git Union of validator and filter functionalities. FaceFilter is replaced on ModuleBase_ValidatorFace --- diff --git a/src/ConstructionPlugin/plane_widget.xml b/src/ConstructionPlugin/plane_widget.xml index 7600c1b19..193bfe019 100644 --- a/src/ConstructionPlugin/plane_widget.xml +++ b/src/ConstructionPlugin/plane_widget.xml @@ -7,7 +7,7 @@ label="Plane face" tooltip="Select a planar face" shape_types="face"> - + + +#include + +#include +#include + +typedef QMap FaceTypes; +static FaceTypes MyFaceTypes; + +GeomAbs_SurfaceType ModuleBase_ValidatorFace::faceType(const std::string& theType) +{ + if (MyFaceTypes.count() == 0) { + MyFaceTypes["plane"] = GeomAbs_Plane; + MyFaceTypes["cylinder"] = GeomAbs_Cylinder; + } + QString aType = QString(theType.c_str()).toLower(); + if (MyFaceTypes.contains(aType)) + return MyFaceTypes[aType]; + + Events_Error::send("Face type defined in XML is not implemented!"); + return GeomAbs_Plane; +} + +bool ModuleBase_ValidatorFace::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + bool aValid = false; + + GeomAbs_SurfaceType aFaceType = GeomAbs_Plane; + if (theArguments.size() == 1) { + std::string anArgument = theArguments.front(); + aFaceType = faceType(anArgument); + } + + ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute); + if (anObject.get() != NULL) { + AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast + (theAttribute); + std::shared_ptr aGeomShape = aSelectionAttr->value(); + std::shared_ptr aGeomFace(new GeomAPI_Face(aGeomShape)); + if (aGeomFace.get() != NULL) { + switch(aFaceType) { + case GeomAbs_Plane: + aValid = aGeomFace->isPlanar(); + break; + case GeomAbs_Cylinder: + break; + default: + break; + } + } + } + return aValid; +} diff --git a/src/ModuleBase/ModuleBase_ValidatorFace.h b/src/ModuleBase/ModuleBase_ValidatorFace.h new file mode 100644 index 000000000..9923c9c09 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ValidatorFace.h @@ -0,0 +1,34 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_ValidatorFace.h +// Created: 20 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_ValidatorFace_H +#define ModuleBase_ValidatorFace_H + +#include "ModuleBase.h" +#include "ModelAPI_AttributeValidator.h" + +#include + +/** +* \ingroup Validators +* A validator of selection +*/ +class ModuleBase_ValidatorFace : public ModelAPI_AttributeValidator +{ + public: + MODULEBASE_EXPORT ModuleBase_ValidatorFace() {} + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +protected: + /// Convert string to TypeOfFace value + /// \param theType a string value + static GeomAbs_SurfaceType faceType(const std::string& theType); +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h index f88527abf..a2b315936 100644 --- a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h +++ b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h @@ -10,8 +10,6 @@ #include "ModuleBase.h" #include "ModelAPI_AttributeValidator.h" -#include - /** * \ingroup Validators * A validator of selection @@ -35,7 +33,7 @@ class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute, const std::list& theArguments) const; protected: - /// Convert string to StdSelect_TypeOfFace value + /// Convert string to TypeOfEdge value /// \param theType a string value static TypeOfEdge edgeType(const std::string& theType); }; diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 84a15322e..a5ddfb704 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -57,7 +57,7 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); std::list aValidators; std::list > anArguments; - aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments); DataPtr aData = myFeature->data(); AttributePtr anAttribute = myFeature->attribute(attributeID()); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 489db5aed..8406ad191 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -133,6 +134,7 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge); aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex", new ModuleBase_ValidatorLinearEdgeOrVertex); + aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace); } void PartSet_Module::registerFilters()