From: nds Date: Mon, 23 Mar 2015 12:57:03 +0000 (+0300) Subject: Union of validator and filter functionalities. X-Git-Tag: V_1.1.0~85^2~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed329a97add10e760a2e636697f50968a7f4d289;p=modules%2Fshaper.git Union of validator and filter functionalities. This is moving of ModuleBase validators to the GeomValidator project --- 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; + AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast + (theAttribute); + if (aSelectionAttr.get() == NULL) + return aValid; + + ResultPtr aResult = aSelectionAttr->context(); + GeomShapePtr aShape = aSelectionAttr->value(); + // global selection should be ignored, the filter processes only selected sub-shapes + // that means, that the shape of the context result is equal to the shape value + ///*ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); + if (aResult.get() != NULL) { + GeomShapePtr aShapePtr = aResult->shape(); + // it is important to call isEqual of the shape of result. + // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is + // GeomAPI_Shape. It is important to use the realization of the isEqual method from + // GeomAPI_Vertex class + aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape); + } + if (!aValid) { + ResultConstructionPtr aConstr = + std::dynamic_pointer_cast(aResult); + if (aConstr != NULL) { + // it provides selection only on compositie features, construction without composite + // feature is not selectable + FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr); + CompositeFeaturePtr aComposite = + std::dynamic_pointer_cast(aFeature); + aValid = aComposite && aComposite->numberOfSubs() > 0; + } + else { + // non-construction results should be accepted by this filter, e.g. body results + aValid = true; + } + } + return aValid; +} 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/GeomValidators/GeomValidators_Edge.cpp b/src/GeomValidators/GeomValidators_Edge.cpp new file mode 100644 index 000000000..0518f4af4 --- /dev/null +++ b/src/GeomValidators/GeomValidators_Edge.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +#include "GeomValidators_Edge.h" +#include "GeomValidators_Tools.h" + +#include +#include +#include + +#include + +#include +#include + + +typedef std::map EdgeTypes; +static EdgeTypes MyEdgeTypes; + +GeomValidators_Edge::TypeOfEdge GeomValidators_Edge::edgeType(const std::string& theType) +{ + if (MyEdgeTypes.size() == 0) { + MyEdgeTypes["line"] = Line; + MyEdgeTypes["circle"] = Circle; + } + 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 GeomValidators_Edge::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + bool aValid = false; + + TypeOfEdge anEdgeType = AnyEdge; + if (theArguments.size() == 1) { + std::string anArgument = theArguments.front(); + anEdgeType = edgeType(anArgument); + } + + ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); + if (anObject.get() != NULL) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get() != NULL) { + GeomShapePtr aShape = aResult->shape(); + if (aShape.get() != NULL && aShape->isEdge()) { + aValid = anEdgeType == AnyEdge; + if (!aValid) { + bool isCircle = GeomAPI_Curve(aShape).isCircle(); + aValid = (isCircle && anEdgeType == Circle) || + (!isCircle && anEdgeType == Line); + } + } + } + } + else { + //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); + } + return aValid; +} diff --git a/src/GeomValidators/GeomValidators_Edge.h b/src/GeomValidators/GeomValidators_Edge.h new file mode 100644 index 000000000..5b29a8254 --- /dev/null +++ b/src/GeomValidators/GeomValidators_Edge.h @@ -0,0 +1,43 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_Edge.h +// Created: 19 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef GeomValidators_Edge_H +#define GeomValidators_Edge_H + +#include "GeomValidators.h" +#include "ModelAPI_AttributeValidator.h" + +#include + +/** +* \ingroup Validators +* A validator of selection +*/ +class GeomValidators_Edge : public ModelAPI_AttributeValidator +{ + public: + // the edge type + enum TypeOfEdge + { + AnyEdge, + Line, + Circle + }; + + public: + GEOMVALIDATORS_EXPORT GeomValidators_Edge() {} + //! 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 TypeOfEdge value + /// \param theType a string value + static TypeOfEdge edgeType(const std::string& theType); +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp b/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp new file mode 100644 index 000000000..642d1cde9 --- /dev/null +++ b/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp @@ -0,0 +1,62 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +#include "GeomValidators_EdgeOrVertex.h" +#include "GeomValidators_Tools.h" +#include "GeomValidators_Edge.h" + +#include "ModelAPI_AttributeRefAttr.h" +#include "ModelAPI_Result.h" + +#include + +#include +#include + +#include + +#include + +#include +#include + + +bool GeomValidators_EdgeOrVertex::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + bool aValid = false; + + // 1. check whether the attribute is a linear edge + // there is a check whether the feature contains a point and a linear edge or two point values + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + + 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 = GeomValidators_Tools::getObject(theAttribute); + if (anObject.get() != NULL) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get() != NULL) { + GeomShapePtr aShape = aResult->shape(); + if (aShape.get() != NULL) { + aValid = aShape->isVertex(); + } + } + } + else { + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr.get() != NULL) { + AttributePtr aRefAttr = anAttr->attr(); + aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type(); + } + } + } + return aValid; +} 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/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp new file mode 100644 index 000000000..6f2608618 --- /dev/null +++ b/src/GeomValidators/GeomValidators_Face.cpp @@ -0,0 +1,63 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +#include "GeomValidators_Face.h" +#include "GeomValidators_Tools.h" + +#include "ModelAPI_AttributeSelection.h" + +#include + +#include + +#include +#include + +typedef std::map FaceTypes; +static FaceTypes MyFaceTypes; + +GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType) +{ + if (MyFaceTypes.size() == 0) { + MyFaceTypes["plane"] = GeomAbs_Plane; + MyFaceTypes["cylinder"] = GeomAbs_Cylinder; + } + 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 GeomValidators_Face::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 = GeomValidators_Tools::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/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.cpp b/src/ModuleBase/ModuleBase_ValidatorFace.cpp deleted file mode 100644 index fbc389ba8..000000000 --- a/src/ModuleBase/ModuleBase_ValidatorFace.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -#include "ModuleBase_ValidatorFace.h" -#include "ModuleBase_WidgetShapeSelector.h" - -#include "ModelAPI_AttributeSelection.h" - -#include - -#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 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_ValidatorLinearEdge.cpp b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp deleted file mode 100644 index cf2d28082..000000000 --- a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -#include "ModuleBase_ValidatorLinearEdge.h" -#include "ModuleBase_WidgetShapeSelector.h" - -#include - -#include - -#include - -#include -#include - - -typedef QMap EdgeTypes; -static EdgeTypes MyEdgeTypes; - -ModuleBase_ValidatorLinearEdge::TypeOfEdge ModuleBase_ValidatorLinearEdge::edgeType(const std::string& theType) -{ - if (MyEdgeTypes.count() == 0) { - MyEdgeTypes["line"] = Line; - MyEdgeTypes["circle"] = Circle; - } - QString aType = QString(theType.c_str()).toLower(); - if (MyEdgeTypes.contains(aType)) - 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 aValid = false; - - TypeOfEdge anEdgeType = AnyEdge; - if (theArguments.size() == 1) { - std::string anArgument = theArguments.front(); - anEdgeType = edgeType(anArgument); - } - - ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute); - if (anObject.get() != NULL) { - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get() != NULL) { - GeomShapePtr aShape = aResult->shape(); - if (aShape.get() != NULL && aShape->isEdge()) { - aValid = anEdgeType == AnyEdge; - if (!aValid) { - bool isCircle = GeomAPI_Curve(aShape).isCircle(); - aValid = (isCircle && anEdgeType == Circle) || - (!isCircle && anEdgeType == Line); - } - } - } - } - else { - //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); - } - return aValid; -} diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h deleted file mode 100644 index a2b315936..000000000 --- a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_ValidatorLinearEdge.h -// Created: 19 Mar 2015 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_ValidatorLinearEdge_H -#define ModuleBase_ValidatorLinearEdge_H - -#include "ModuleBase.h" -#include "ModelAPI_AttributeValidator.h" - -/** -* \ingroup Validators -* A validator of selection -*/ -class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator -{ - public: - // the edge type - enum TypeOfEdge - { - AnyEdge, - Line, - Circle - }; - - public: - MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdge() {} - //! 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 TypeOfEdge value - /// \param theType a string value - static TypeOfEdge edgeType(const std::string& theType); -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp b/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp deleted file mode 100644 index b9c8ce1eb..000000000 --- a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -#include "ModuleBase_ValidatorLinearEdgeOrVertex.h" -#include "ModuleBase_WidgetShapeSelector.h" -#include "ModuleBase_ValidatorLinearEdge.h" - -#include "ModelAPI_AttributeRefAttr.h" - -#include - -#include -#include - -#include - -#include - -#include -#include - - -bool ModuleBase_ValidatorLinearEdgeOrVertex::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const -{ - bool aValid = false; - - // 1. check whether the attribute is a linear edge - // there is a check whether the feature contains a point and a linear edge or two point values - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - - const ModuleBase_ValidatorLinearEdge* aLinearEdgeValidator = - dynamic_cast(aFactory->validator("ModuleBase_ValidatorLinearEdge")); - - 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); - if (anObject.get() != NULL) { - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get() != NULL) { - GeomShapePtr aShape = aResult->shape(); - if (aShape.get() != NULL) { - aValid = aShape->isVertex(); - } - } - } - else { - AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); - if (anAttr.get() != NULL) { - AttributePtr aRefAttr = anAttr->attr(); - aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type(); - } - } - } - return aValid; -} 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.cpp b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp deleted file mode 100644 index 7a6ab98c9..000000000 --- a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -#include "ModuleBase_ValidatorNoConstructionSubShapes.h" - -#include "ModelAPI_AttributeSelection.h" -#include "ModelAPI_ResultConstruction.h" -#include "ModelAPI_CompositeFeature.h" - -bool ModuleBase_ValidatorNoConstructionSubShapes::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const -{ - bool aValid = false; - AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast - (theAttribute); - if (aSelectionAttr.get() == NULL) - return aValid; - - ResultPtr aResult = aSelectionAttr->context(); - GeomShapePtr aShape = aSelectionAttr->value(); - // global selection should be ignored, the filter processes only selected sub-shapes - // that means, that the shape of the context result is equal to the shape value - ///*ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - if (aResult.get() != NULL) { - GeomShapePtr aShapePtr = aResult->shape(); - // it is important to call isEqual of the shape of result. - // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is - // GeomAPI_Shape. It is important to use the realization of the isEqual method from - // GeomAPI_Vertex class - aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape); - } - if (!aValid) { - ResultConstructionPtr aConstr = - std::dynamic_pointer_cast(aResult); - if (aConstr != NULL) { - // it provides selection only on compositie features, construction without composite - // feature is not selectable - FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr); - CompositeFeaturePtr aComposite = - std::dynamic_pointer_cast(aFeature); - aValid = aComposite && aComposite->numberOfSubs() > 0; - } - else { - // non-construction results should be accepted by this filter, e.g. body results - aValid = true; - } - } - return aValid; -} 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 @@