From: nds Date: Wed, 29 Apr 2015 16:59:49 +0000 (+0300) Subject: Rigid constraint should process selection of vertex, lines and circles. So, a new... X-Git-Tag: V_1.2.0~178^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c135d354a2431bd8edcef0750add2f354d0fba4a;p=modules%2Fshaper.git Rigid constraint should process selection of vertex, lines and circles. So, a new validator ShapeType is created. It uses a combination of given parameters. The functionality of Edge and EdgeOrVertex validators are replaced by this new validator fully. So, they are removed. --- diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index 3a07a17cb..fda2411f4 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -5,19 +5,17 @@ INCLUDE(Common) SET(PROJECT_HEADERS GeomValidators.h GeomValidators_ConstructionComposite.h - GeomValidators_Edge.h - GeomValidators_EdgeOrVertex.h GeomValidators_Face.h GeomValidators_Positive.h + GeomValidators_ShapeType.h GeomValidators_Tools.h ) SET(PROJECT_SOURCES GeomValidators_ConstructionComposite.cpp - GeomValidators_Edge.cpp - GeomValidators_EdgeOrVertex.cpp GeomValidators_Face.cpp GeomValidators_Positive.cpp + GeomValidators_ShapeType.cpp GeomValidators_Tools.cpp ) diff --git a/src/GeomValidators/GeomValidators_Edge.cpp b/src/GeomValidators/GeomValidators_Edge.cpp deleted file mode 100644 index 0518f4af4..000000000 --- a/src/GeomValidators/GeomValidators_Edge.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// 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 deleted file mode 100644 index 5b29a8254..000000000 --- a/src/GeomValidators/GeomValidators_Edge.h +++ /dev/null @@ -1,43 +0,0 @@ -// 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 deleted file mode 100644 index cfd78c994..000000000 --- a/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// 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::typeId(); - } - } - } - return aValid; -} diff --git a/src/GeomValidators/GeomValidators_EdgeOrVertex.h b/src/GeomValidators/GeomValidators_EdgeOrVertex.h deleted file mode 100644 index 52b7add0f..000000000 --- a/src/GeomValidators/GeomValidators_EdgeOrVertex.h +++ /dev/null @@ -1,30 +0,0 @@ -// 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_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp new file mode 100644 index 000000000..f5ce2fd0b --- /dev/null +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -0,0 +1,90 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + + +#include "GeomValidators_ShapeType.h" +#include "GeomValidators_Tools.h" + +#include +#include + +#include +#include "ModelAPI_AttributeRefAttr.h" + +#include + +#include +#include + + +typedef std::map EdgeTypes; +static EdgeTypes MyEdgeTypes; + +GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const std::string& theType) +{ + if (MyEdgeTypes.size() == 0) { + MyEdgeTypes["vertex"] = Vertex; + 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 AnyShape; +} + +bool GeomValidators_ShapeType::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + bool aValid = false; + + std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); + for (; anIt != aLast && !aValid; anIt++) { + aValid = isValidArgument(theAttribute, *anIt); + } + + return aValid; +} + +bool GeomValidators_ShapeType::isValidArgument(const AttributePtr& theAttribute, + const std::string& theArgument) const +{ + bool aValid = false; + TypeOfShape aShapeType = shapeType(theArgument); + if (aShapeType == AnyShape) + return true; + + 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) { + switch (aShapeType) { + case Line: + aValid = aShape->isEdge() && !GeomAPI_Curve(aShape).isCircle(); + break; + case Circle: + aValid = aShape->isEdge() && GeomAPI_Curve(aShape).isCircle(); + break; + case Vertex: + aValid = aShape->isVertex(); + break; + default: break; + } + } + } + } + else { + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr.get() != NULL) { + if (aShapeType == Vertex) { + AttributePtr aRefAttr = anAttr->attr(); + aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::typeId(); + } + } + } + return aValid; +} diff --git a/src/GeomValidators/GeomValidators_ShapeType.h b/src/GeomValidators/GeomValidators_ShapeType.h new file mode 100644 index 000000000..ce3232d61 --- /dev/null +++ b/src/GeomValidators/GeomValidators_ShapeType.h @@ -0,0 +1,50 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_ShapeType.h +// Created: 19 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef GeomValidators_ShapeType_H +#define GeomValidators_ShapeType_H + +#include "GeomValidators.h" +#include "ModelAPI_AttributeValidator.h" + +#include + +/** +* \ingroup Validators +* A validator for shape types, such as vertex, line, circe or arc. +* If there are some argument parameters, this validator returns true if the attribute satisfied +* at least one argument (OR combination of arguments). +*/ +class GeomValidators_ShapeType : public ModelAPI_AttributeValidator +{ + public: + // the edge type + enum TypeOfShape + { + AnyShape, + Vertex, + Line, + Circle + }; + + public: + GEOMVALIDATORS_EXPORT GeomValidators_ShapeType() {} + //! 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 TypeOfShape value + /// \param theType a string value + static TypeOfShape shapeType(const std::string& theType); + + bool isValidArgument(const AttributePtr& theAttribute, + const std::string& theArgument) const; + +}; + +#endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 7ae10661d..684d94071 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -18,8 +18,7 @@ #include #include #include -#include -#include +#include #include #include @@ -138,9 +137,7 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator); aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator); - aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge); - aFactory->registerValidator("GeomValidators_EdgeOrVertex", - new GeomValidators_EdgeOrVertex); + aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType); aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face); aFactory->registerValidator("GeomValidators_ConstructionComposite", diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 68857aa26..9dfdb5171 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include @@ -48,20 +48,20 @@ bool SketchPlugin_DistanceAttrValidator::isValid( // 1. check whether the references object is a linear ObjectPtr anObject = aRefAttr->object(); - const ModelAPI_AttributeValidator* anEdgeValidator = - dynamic_cast(aFactory->validator("GeomValidators_Edge")); + const ModelAPI_AttributeValidator* aShapeValidator = + dynamic_cast(aFactory->validator("GeomValidators_ShapeType")); std::list anArguments; anArguments.push_back("circle"); - bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments); + bool aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments); // the circle line is not a valid case - if (anEdgeValid) + if (aShapeValid) return false; anArguments.clear(); anArguments.push_back("line"); - anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments); + aShapeValid = aShapeValidator->isValid(aRefAttr, anArguments); // if the attribute value is not a line, that means it is a vertex. A vertex is always valid - if (!anEdgeValid) + if (!aShapeValid) return true; FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 8fe582a60..e42c826c8 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -54,7 +54,7 @@ shape_types="edge vertex"> - + /> - + @@ -80,7 +80,7 @@