From ed329a97add10e760a2e636697f50968a7f4d289 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 23 Mar 2015 15:57:03 +0300 Subject: [PATCH] Union of validator and filter functionalities. This is moving of ModuleBase validators to the GeomValidator project --- src/ConstructionPlugin/axis_widget.xml | 4 +- src/ConstructionPlugin/plane_widget.xml | 2 +- src/GeomValidators/CMakeLists.txt | 22 ++++- .../GeomValidators_ConstructionComposite.cpp} | 4 +- .../GeomValidators_ConstructionComposite.h | 28 ++++++ .../GeomValidators_Edge.cpp} | 26 +++--- .../GeomValidators_Edge.h} | 18 ++-- .../GeomValidators_EdgeOrVertex.cpp} | 17 ++-- .../GeomValidators_EdgeOrVertex.h | 30 ++++++ .../GeomValidators_Face.cpp} | 18 ++-- src/GeomValidators/GeomValidators_Face.h | 34 +++++++ src/GeomValidators/GeomValidators_Tools.cpp | 36 ++++++++ src/GeomValidators/GeomValidators_Tools.h | 23 +++++ src/ModuleBase/CMakeLists.txt | 10 +- src/ModuleBase/ModuleBase_ValidatorFace.h | 34 ------- .../ModuleBase_ValidatorLinearEdgeOrVertex.h | 30 ------ ...uleBase_ValidatorNoConstructionSubShapes.h | 28 ------ .../ModuleBase_WidgetShapeSelector.cpp | 30 +----- .../ModuleBase_WidgetShapeSelector.h | 4 - src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_Module.cpp | 20 ++-- src/PartSet/PartSet_Validators.cpp | 5 +- src/SketchPlugin/CMakeLists.txt | 2 + src/SketchPlugin/SketchPlugin_Validators.cpp | 91 ++----------------- src/SketchPlugin/SketchPlugin_Validators.h | 27 +----- src/SketchPlugin/plugin-Sketch.xml | 20 ++-- 26 files changed, 259 insertions(+), 306 deletions(-) rename src/{ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp => GeomValidators/GeomValidators_ConstructionComposite.cpp} (93%) create mode 100644 src/GeomValidators/GeomValidators_ConstructionComposite.h rename src/{ModuleBase/ModuleBase_ValidatorLinearEdge.cpp => GeomValidators/GeomValidators_Edge.cpp} (64%) rename src/{ModuleBase/ModuleBase_ValidatorLinearEdge.h => GeomValidators/GeomValidators_Edge.h} (57%) rename src/{ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp => GeomValidators/GeomValidators_EdgeOrVertex.cpp} (71%) create mode 100644 src/GeomValidators/GeomValidators_EdgeOrVertex.h rename src/{ModuleBase/ModuleBase_ValidatorFace.cpp => GeomValidators/GeomValidators_Face.cpp} (73%) create mode 100644 src/GeomValidators/GeomValidators_Face.h create mode 100644 src/GeomValidators/GeomValidators_Tools.cpp create mode 100644 src/GeomValidators/GeomValidators_Tools.h delete mode 100644 src/ModuleBase/ModuleBase_ValidatorFace.h delete mode 100644 src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h delete mode 100644 src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index 435a2e7b3..38638ecf5 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -8,14 +8,14 @@ icon=":icons/point.png" tooltip="Select a first point" shape_types="vertex"> - + - + diff --git a/src/ConstructionPlugin/plane_widget.xml b/src/ConstructionPlugin/plane_widget.xml index 193bfe019..4300f5f6f 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"> - + & theArguments) const { bool aValid = false; diff --git a/src/GeomValidators/GeomValidators_ConstructionComposite.h b/src/GeomValidators/GeomValidators_ConstructionComposite.h new file mode 100644 index 000000000..abe123fe5 --- /dev/null +++ b/src/GeomValidators/GeomValidators_ConstructionComposite.h @@ -0,0 +1,28 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_ConstructionComposite.h +// Created: 20 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef GeomValidators_ConstructionComposite_H +#define GeomValidators_ConstructionComposite_H + +#include "GeomValidators.h" +#include "ModelAPI_AttributeValidator.h" + +/** +* \ingroup Validators +* A validator of selection +*/ +class GeomValidators_ConstructionComposite : public ModelAPI_AttributeValidator +{ + public: + GEOMVALIDATORS_EXPORT GeomValidators_ConstructionComposite() {} + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp b/src/GeomValidators/GeomValidators_Edge.cpp similarity index 64% rename from src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp rename to src/GeomValidators/GeomValidators_Edge.cpp index cf2d28082..0518f4af4 100644 --- a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp +++ b/src/GeomValidators/GeomValidators_Edge.cpp @@ -1,38 +1,38 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -#include "ModuleBase_ValidatorLinearEdge.h" -#include "ModuleBase_WidgetShapeSelector.h" +#include "GeomValidators_Edge.h" +#include "GeomValidators_Tools.h" #include - #include +#include #include -#include -#include +#include +#include -typedef QMap EdgeTypes; +typedef std::map EdgeTypes; static EdgeTypes MyEdgeTypes; -ModuleBase_ValidatorLinearEdge::TypeOfEdge ModuleBase_ValidatorLinearEdge::edgeType(const std::string& theType) +GeomValidators_Edge::TypeOfEdge GeomValidators_Edge::edgeType(const std::string& theType) { - if (MyEdgeTypes.count() == 0) { + if (MyEdgeTypes.size() == 0) { MyEdgeTypes["line"] = Line; MyEdgeTypes["circle"] = Circle; } - QString aType = QString(theType.c_str()).toLower(); - if (MyEdgeTypes.contains(aType)) + std::string aType = std::string(theType.c_str()); + if (MyEdgeTypes.find(aType) != MyEdgeTypes.end()) return MyEdgeTypes[aType]; Events_Error::send("Edge type defined in XML is not implemented!"); return AnyEdge; } -bool ModuleBase_ValidatorLinearEdge::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const +bool GeomValidators_Edge::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const { bool aValid = false; @@ -42,7 +42,7 @@ bool ModuleBase_ValidatorLinearEdge::isValid(const AttributePtr& theAttribute, anEdgeType = edgeType(anArgument); } - ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute); + ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); if (anObject.get() != NULL) { FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); ResultPtr aResult = std::dynamic_pointer_cast(anObject); diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h b/src/GeomValidators/GeomValidators_Edge.h similarity index 57% rename from src/ModuleBase/ModuleBase_ValidatorLinearEdge.h rename to src/GeomValidators/GeomValidators_Edge.h index a2b315936..5b29a8254 100644 --- a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h +++ b/src/GeomValidators/GeomValidators_Edge.h @@ -1,20 +1,22 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// File: ModuleBase_ValidatorLinearEdge.h +// File: GeomValidators_Edge.h // Created: 19 Mar 2015 // Author: Natalia ERMOLAEVA -#ifndef ModuleBase_ValidatorLinearEdge_H -#define ModuleBase_ValidatorLinearEdge_H +#ifndef GeomValidators_Edge_H +#define GeomValidators_Edge_H -#include "ModuleBase.h" +#include "GeomValidators.h" #include "ModelAPI_AttributeValidator.h" +#include + /** * \ingroup Validators * A validator of selection */ -class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator +class GeomValidators_Edge : public ModelAPI_AttributeValidator { public: // the edge type @@ -26,12 +28,12 @@ class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator }; public: - MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdge() {} + GEOMVALIDATORS_EXPORT GeomValidators_Edge() {} //! 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; + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; protected: /// Convert string to TypeOfEdge value /// \param theType a string value diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp b/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp similarity index 71% rename from src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp rename to src/GeomValidators/GeomValidators_EdgeOrVertex.cpp index b9c8ce1eb..642d1cde9 100644 --- a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp +++ b/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp @@ -1,11 +1,12 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -#include "ModuleBase_ValidatorLinearEdgeOrVertex.h" -#include "ModuleBase_WidgetShapeSelector.h" -#include "ModuleBase_ValidatorLinearEdge.h" +#include "GeomValidators_EdgeOrVertex.h" +#include "GeomValidators_Tools.h" +#include "GeomValidators_Edge.h" #include "ModelAPI_AttributeRefAttr.h" +#include "ModelAPI_Result.h" #include @@ -20,8 +21,8 @@ #include -bool ModuleBase_ValidatorLinearEdgeOrVertex::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const +bool GeomValidators_EdgeOrVertex::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const { bool aValid = false; @@ -30,15 +31,15 @@ bool ModuleBase_ValidatorLinearEdgeOrVertex::isValid(const AttributePtr& theAttr SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - const ModuleBase_ValidatorLinearEdge* aLinearEdgeValidator = - dynamic_cast(aFactory->validator("ModuleBase_ValidatorLinearEdge")); + const GeomValidators_Edge* aLinearEdgeValidator = + dynamic_cast(aFactory->validator("GeomValidators_Edge")); std::list anArguments; anArguments.push_back("line"); aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments); if (!aValid) { //2. check whether the attribute is a vertex - ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute); + ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); if (anObject.get() != NULL) { FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); ResultPtr aResult = std::dynamic_pointer_cast(anObject); diff --git a/src/GeomValidators/GeomValidators_EdgeOrVertex.h b/src/GeomValidators/GeomValidators_EdgeOrVertex.h new file mode 100644 index 000000000..52b7add0f --- /dev/null +++ b/src/GeomValidators/GeomValidators_EdgeOrVertex.h @@ -0,0 +1,30 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_EdgeOrVertex.h +// Created: 19 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef GeomValidators_EdgeOrVertex_H +#define GeomValidators_EdgeOrVertex_H + +#include "GeomValidators.h" +#include "ModelAPI_AttributeValidator.h" + +#include + +/** +* \ingroup Validators +* A validator of selection +*/ +class GeomValidators_EdgeOrVertex : public ModelAPI_AttributeValidator +{ + public: + GEOMVALIDATORS_EXPORT GeomValidators_EdgeOrVertex() {} + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_ValidatorFace.cpp b/src/GeomValidators/GeomValidators_Face.cpp similarity index 73% rename from src/ModuleBase/ModuleBase_ValidatorFace.cpp rename to src/GeomValidators/GeomValidators_Face.cpp index fbc389ba8..6f2608618 100644 --- a/src/ModuleBase/ModuleBase_ValidatorFace.cpp +++ b/src/GeomValidators/GeomValidators_Face.cpp @@ -1,8 +1,8 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -#include "ModuleBase_ValidatorFace.h" -#include "ModuleBase_WidgetShapeSelector.h" +#include "GeomValidators_Face.h" +#include "GeomValidators_Tools.h" #include "ModelAPI_AttributeSelection.h" @@ -13,24 +13,24 @@ #include #include -typedef QMap FaceTypes; +typedef std::map FaceTypes; static FaceTypes MyFaceTypes; -GeomAbs_SurfaceType ModuleBase_ValidatorFace::faceType(const std::string& theType) +GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType) { - if (MyFaceTypes.count() == 0) { + if (MyFaceTypes.size() == 0) { MyFaceTypes["plane"] = GeomAbs_Plane; MyFaceTypes["cylinder"] = GeomAbs_Cylinder; } - QString aType = QString(theType.c_str()).toLower(); - if (MyFaceTypes.contains(aType)) + std::string aType = std::string(theType.c_str()); + if (MyFaceTypes.find(aType) != MyFaceTypes.end()) return MyFaceTypes[aType]; Events_Error::send("Face type defined in XML is not implemented!"); return GeomAbs_Plane; } -bool ModuleBase_ValidatorFace::isValid(const AttributePtr& theAttribute, +bool GeomValidators_Face::isValid(const AttributePtr& theAttribute, const std::list& theArguments) const { bool aValid = false; @@ -41,7 +41,7 @@ bool ModuleBase_ValidatorFace::isValid(const AttributePtr& theAttribute, aFaceType = faceType(anArgument); } - ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute); + ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); if (anObject.get() != NULL) { AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast (theAttribute); diff --git a/src/GeomValidators/GeomValidators_Face.h b/src/GeomValidators/GeomValidators_Face.h new file mode 100644 index 000000000..2ff49551c --- /dev/null +++ b/src/GeomValidators/GeomValidators_Face.h @@ -0,0 +1,34 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_Face.h +// Created: 20 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef GeomValidators_Face_H +#define GeomValidators_Face_H + +#include "GeomValidators.h" +#include "ModelAPI_AttributeValidator.h" + +#include + +/** +* \ingroup Validators +* A validator of selection +*/ +class GeomValidators_Face : public ModelAPI_AttributeValidator +{ + public: + GEOMVALIDATORS_EXPORT GeomValidators_Face() {} + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +protected: + /// Convert string to TypeOfFace value + /// \param theType a string value + GEOMVALIDATORS_EXPORT static GeomAbs_SurfaceType faceType(const std::string& theType); +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_Tools.cpp b/src/GeomValidators/GeomValidators_Tools.cpp new file mode 100644 index 000000000..f98088ed3 --- /dev/null +++ b/src/GeomValidators/GeomValidators_Tools.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_Tools.cpp +// Created: 06 Aug 2014 +// Author: Vitaly Smetannikov + +#include "GeomValidators_Tools.h" + +#include "ModelAPI_AttributeRefAttr.h" +#include "ModelAPI_AttributeSelection.h" +#include "ModelAPI_AttributeReference.h" + +namespace GeomValidators_Tools { + + ObjectPtr getObject(const AttributePtr& theAttribute) + { + ObjectPtr anObject; + std::string anAttrType = theAttribute->attributeType(); + if (anAttrType == ModelAPI_AttributeRefAttr::type()) { + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr != NULL && anAttr->isObject()) + anObject = anAttr->object(); + } + if (anAttrType == ModelAPI_AttributeSelection::type()) { + AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr != NULL && anAttr->isInitialized()) + anObject = anAttr->context(); + } + if (anAttrType == ModelAPI_AttributeReference::type()) { + AttributeReferencePtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr.get() != NULL && anAttr->isInitialized()) + anObject = anAttr->value(); + } + return anObject; + } +} diff --git a/src/GeomValidators/GeomValidators_Tools.h b/src/GeomValidators/GeomValidators_Tools.h new file mode 100644 index 000000000..bb1db6644 --- /dev/null +++ b/src/GeomValidators/GeomValidators_Tools.h @@ -0,0 +1,23 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_Tools.h +// Created: 23 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef GeomValidators_Tools_HeaderFile +#define GeomValidators_Tools_HeaderFile + +#include "GeomValidators.h" +#include "ModelAPI_Object.h" +#include "ModelAPI_Attribute.h" + + +namespace GeomValidators_Tools +{ + // Returns the object from the attribute + /// \param theObj an object + GEOMVALIDATORS_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute); + +}; + +#endif diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 5dcc40908..b623713fc 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -37,10 +37,6 @@ SET(PROJECT_HEADERS ModuleBase_IViewer.h ModuleBase_WidgetLineEdit.h ModuleBase_WidgetMultiSelector.h - ModuleBase_ValidatorFace.h - ModuleBase_ValidatorLinearEdge.h - ModuleBase_ValidatorLinearEdgeOrVertex.h - ModuleBase_ValidatorNoConstructionSubShapes.h ModuleBase_ViewerFilters.h ModuleBase_ResultPrs.h ModuleBase_IViewWindow.h @@ -84,10 +80,6 @@ SET(PROJECT_SOURCES ModuleBase_DoubleSpinBox.cpp ModuleBase_WidgetLineEdit.cpp ModuleBase_WidgetMultiSelector.cpp - ModuleBase_ValidatorFace.cpp - ModuleBase_ValidatorLinearEdge.cpp - ModuleBase_ValidatorLinearEdgeOrVertex.cpp - ModuleBase_ValidatorNoConstructionSubShapes.cpp ModuleBase_ViewerFilters.cpp ModuleBase_ResultPrs.cpp ModuleBase_WidgetLabel.cpp @@ -108,6 +100,7 @@ SET(PROJECT_LIBRARIES ModelAPI GeomAPI GeomAlgoAPI + GeomValidators ${QT_LIBRARIES} ${CAS_VIEWER} ${CAS_KERNEL} @@ -135,6 +128,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/GeomDataAPI ${CMAKE_SOURCE_DIR}/src/GeomAPI ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI + ${CMAKE_SOURCE_DIR}/src/GeomValidators ${SUIT_INCLUDE} ) diff --git a/src/ModuleBase/ModuleBase_ValidatorFace.h b/src/ModuleBase/ModuleBase_ValidatorFace.h deleted file mode 100644 index 9923c9c09..000000000 --- a/src/ModuleBase/ModuleBase_ValidatorFace.h +++ /dev/null @@ -1,34 +0,0 @@ -// 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_ValidatorLinearEdgeOrVertex.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h deleted file mode 100644 index 0df6c882f..000000000 --- a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_ValidatorLinearEdgeOrVertex.h -// Created: 19 Mar 2015 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_ValidatorLinearEdgeOrVertex_H -#define ModuleBase_ValidatorLinearEdgeOrVertex_H - -#include "ModuleBase.h" -#include "ModelAPI_AttributeValidator.h" - -#include - -/** -* \ingroup Validators -* A validator of selection -*/ -class ModuleBase_ValidatorLinearEdgeOrVertex : public ModelAPI_AttributeValidator -{ - public: - MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdgeOrVertex() {} - //! 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; -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h deleted file mode 100644 index 1338fcef7..000000000 --- a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_ValidatorNoConstructionSubShapes.h -// Created: 20 Mar 2015 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_ValidatorNoConstructionSubShapes_H -#define ModuleBase_ValidatorNoConstructionSubShapes_H - -#include "ModuleBase.h" -#include "ModelAPI_AttributeValidator.h" - -/** -* \ingroup Validators -* A validator of selection -*/ -class ModuleBase_ValidatorNoConstructionSubShapes : public ModelAPI_AttributeValidator -{ - public: - MODULEBASE_EXPORT ModuleBase_ValidatorNoConstructionSubShapes() {} - //! 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; -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 265a9e42c..d88a84410 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -271,29 +272,6 @@ bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptrattributeType(); - if (anAttrType == ModelAPI_AttributeRefAttr::type()) { - AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); - if (anAttr != NULL && anAttr->isObject()) - anObject = anAttr->object(); - } - if (anAttrType == ModelAPI_AttributeSelection::type()) { - AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttribute); - if (anAttr != NULL && anAttr->isInitialized()) - anObject = anAttr->context(); - } - if (anAttrType == ModelAPI_AttributeReference::type()) { - AttributeReferencePtr anAttr = std::dynamic_pointer_cast(theAttribute); - if (anAttr.get() != NULL && anAttr->isInitialized()) - anObject = anAttr->value(); - } - return anObject; -} - - //******************************************************************** GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const { @@ -323,7 +301,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() isNameUpdated = true; } if (!isNameUpdated) { - ObjectPtr anObject = getObject(myFeature->attribute(attributeID())); + ObjectPtr anObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID())); if (anObject.get() != NULL) { std::string aName = anObject->data()->name(); myTextLine->setText(QString::fromStdString(aName)); @@ -398,7 +376,7 @@ void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup) AttributePtr anAttribute = myFeature->attribute(attributeID()); if (isBackup) { - myObject = getObject(anAttribute); + myObject = GeomValidators_Tools::getObject(anAttribute); myShape = getShape(); myRefAttribute = NULL; myIsObject = false; @@ -426,7 +404,7 @@ bool ModuleBase_WidgetShapeSelector::setSelection(const Handle_SelectMgr_EntityO ModuleBase_ViewerPrs aPrs; myWorkshop->selection()->fillPresentation(aPrs, theOwner); ObjectPtr aObject = aPrs.object(); - ObjectPtr aCurrentObject = getObject(myFeature->attribute(attributeID())); + ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID())); if ((!aCurrentObject) && (!aObject)) return false; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 2c5e253b3..bcf13cbf1 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -89,10 +89,6 @@ Q_OBJECT /// The methiod called when widget is deactivated virtual void deactivate(); - // Get the object from the attribute - /// \param theObj an object - static ObjectPtr getObject(const AttributePtr& theAttribute); - public slots: /// Activate or deactivate selection diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 326fb1c61..bdbc48c52 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -46,6 +46,7 @@ SET(PROJECT_LIBRARIES ModuleBase Config GeomAPI + GeomValidators ${QT_LIBRARIES} ${CAS_KERNEL} ${CAS_SHAPE} @@ -78,6 +79,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI ${CMAKE_SOURCE_DIR}/src/SketchPlugin ${CMAKE_SOURCE_DIR}/src/FeaturesPlugin ${CMAKE_SOURCE_DIR}/src/GeomAPI + ${CMAKE_SOURCE_DIR}/src/GeomValidators ${CMAKE_SOURCE_DIR}/src/AppElements ${CAS_INCLUDE_DIRS} ${SUIT_INCLUDE} diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 9646b8398..0b2e410b1 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -21,10 +21,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include @@ -131,13 +131,13 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator); aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator); - aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge); - aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex", - new ModuleBase_ValidatorLinearEdgeOrVertex); - aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace); + aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge); + aFactory->registerValidator("GeomValidators_EdgeOrVertex", + new GeomValidators_EdgeOrVertex); + aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face); - aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes", - new ModuleBase_ValidatorNoConstructionSubShapes); + aFactory->registerValidator("GeomValidators_ConstructionComposite", + new GeomValidators_ConstructionComposite); aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator); diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index b246046d5..85b0dd3ec 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -119,7 +120,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute // 1. check whether the object of the attribute is not among the feature attributes // find the attribute's object - ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute); + ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); // check whether the object is not among other feature attributes if (anObject.get() != NULL) { @@ -132,7 +133,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute // the function parameter attribute should be skipped if (anAttr.get() == NULL || anAttr->id() == theAttribute->id()) continue; - ObjectPtr aCurObject = ModuleBase_WidgetShapeSelector::getObject(anAttr); + ObjectPtr aCurObject = GeomValidators_Tools::getObject(anAttr); if (aCurObject && aCurObject == anObject) return false; } diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 992bd6bdb..22ce7d27e 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -63,6 +63,7 @@ SET(PROJECT_LIBRARIES Config GeomAPI GeomAlgoAPI + GeomValidators ModelAPI SketcherPrs ${CAS_KERNEL} @@ -84,6 +85,7 @@ INCLUDE_DIRECTORIES( ../GeomAPI ../GeomAlgoAPI ../GeomDataAPI + ../GeomValidators ../SketcherPrs ) diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index ec5e929ab..32a0b30b5 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -12,7 +12,7 @@ #include #include -//#include +#include #include @@ -35,33 +35,22 @@ bool SketchPlugin_DistanceAttrValidator::isValid( } else { // 1. check whether the references object is a linear ObjectPtr anObject = aRefAttr->object(); - /* - const ModelAPI_AttributeValidator* aCircleValidator = - dynamic_cast(aFactory->validator("ModuleBase_ValidatorLinearEdge")); + + const ModelAPI_AttributeValidator* anEdgeValidator = + dynamic_cast(aFactory->validator("GeomValidators_Edge")); std::list anArguments; anArguments.push_back("circle"); - bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments); + bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments); + // the circle line is not a valid case if (anEdgeValid) return false; anArguments.clear(); anArguments.push_back("line"); - bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments); + anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments); + // if the attribute value is not a line, that means it is a vertex. A vertex is always valid if (!anEdgeValid) - return true;*/ - - /*const ModelAPI_ResultValidator* anArcValidator = aFactory->validator("ModuleBase_ValidatorLinearEdge"); - //dynamic_cast(aFactory->validator("SketchPlugin_ResultArc")); - bool anArcValid = anArcValidator->isValid(anObject); - if (anArcValid) - return false; - - // If the object is not a line then it is accepted. It can be a point feature selected - const ModelAPI_ResultValidator* aLineValidator = - dynamic_cast(aFactory->validator("SketchPlugin_ResultLine")); - bool aLineValid = aLineValidator->isValid(anObject); - if (!aLineValid) - return true;*/ + return true; FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); // If it is a line then we have to check that first attribute id not a line @@ -71,65 +60,3 @@ bool SketchPlugin_DistanceAttrValidator::isValid( } return false; } - -//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, -// const std::list& theArguments, -// const ObjectPtr& theObject) const -//{ -// std::list > anAttrs = -// theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type()); -// std::list >::iterator anAttr = anAttrs.begin(); -// for(; anAttr != anAttrs.end(); anAttr++) { -// if (*anAttr) { -// std::shared_ptr aRef = -// std::dynamic_pointer_cast(*anAttr); -// // check the object is already presented -// if (aRef->isObject() && aRef->object() == theObject) -// return false; -// } -// } -// return true; -//} - -//bool SketchPlugin_DifferentObjectsValidator::isValid( -// const AttributePtr& theAttribute, const std::list& theArguments ) const -//{ -// std::shared_ptr anOrigAttr = -// std::dynamic_pointer_cast(theAttribute); -// if (anOrigAttr && anOrigAttr->isObject()) { -// const ObjectPtr& anObj = theAttribute->owner(); -// const FeaturePtr aFeature = std::dynamic_pointer_cast(anObj); -// -// std::list > anAttrs = -// aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type()); -// std::list >::iterator anAttr = anAttrs.begin(); -// for(; anAttr != anAttrs.end(); anAttr++) { -// if (*anAttr && *anAttr != theAttribute) { -// std::shared_ptr aRef = -// std::dynamic_pointer_cast(*anAttr); -// // check the object is already presented -// if (aRef->isObject() && aRef->object() == anOrigAttr->object()) -// return false; -// } -// } -// } -// return true; -//} - -//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, -// const std::list& theArguments, const AttributePtr& theAttribute) const -//{ -// std::list > anAttrs = -// theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type()); -// std::list >::iterator anAttr = anAttrs.begin(); -// for(; anAttr != anAttrs.end(); anAttr++) { -// if (*anAttr) { -// std::shared_ptr aRef = -// std::dynamic_pointer_cast(*anAttr); -// // check the object is already presented -// if (!aRef->isObject() && aRef->attr() == theAttribute) -// return false; -// } -// } -// return true; -//} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index ff2183425..f686d3e6e 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -22,31 +22,8 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator //! returns true if attribute is valid //! \param theAttribute the checked attribute //! \param theArguments arguments of the attribute - virtual bool isValid( - const AttributePtr& theAttribute, const std::list& theArguments) const; + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; }; -/**\class SketchPlugin_DifferentObjectsValidator - * \ingroup Validators - * - * Check that there is no same object was already selected in the feature. - * For an example: to avoid perpendicularity on line and the same line. - */ -// Use PartSet_DifferentObjectsValidator -//class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator -//{ -// public: -// //! returns true if attribute is valid -// //! \param theAttribute the checked attribute -// //! \param theArguments arguments of the attribute -// virtual bool isValid( -// const AttributePtr& theAttribute, const std::list& theArguments) const; -// //! Returns true if object is good for the feature attribute -// virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, -// const ObjectPtr& theObject) const; -// //! Returns true if the attribute is good for the feature attribute -// virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, -// const AttributePtr& theAttribute) const; -//}; - #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 498db23dd..1c7974d6d 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -56,7 +56,7 @@ tooltip="Select point, line end point, line, center of circle or arc." shape_types="edge vertex"> - + /> - + @@ -82,7 +82,7 @@