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
)
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "GeomValidators_Edge.h"
-#include "GeomValidators_Tools.h"
-
-#include <GeomAPI_Curve.h>
-#include <Events_Error.h>
-#include <ModelAPI_Result.h>
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-#include <string>
-#include <map>
-
-
-typedef std::map<std::string, GeomValidators_Edge::TypeOfEdge> 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<std::string>& 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<ModelAPI_Result>(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<ModelAPI_AttributeRefAttr>(theAttribute);
- }
- return aValid;
-}
+++ /dev/null
-// 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 <string>
-
-/**
-* \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<std::string>& theArguments) const;
-protected:
- /// Convert string to TypeOfEdge value
- /// \param theType a string value
- static TypeOfEdge edgeType(const std::string& theType);
-};
-
-#endif
+++ /dev/null
-// 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 <ModelAPI_Session.h>
-
-#include <GeomAPI_Curve.h>
-#include <GeomDataAPI_Point2D.h>
-
-#include <Events_Error.h>
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-#include <QString>
-#include <QMap>
-
-
-bool GeomValidators_EdgeOrVertex::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& 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<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
-
- std::list<std::string> 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<ModelAPI_Result>(anObject);
- if (aResult.get() != NULL) {
- GeomShapePtr aShape = aResult->shape();
- if (aShape.get() != NULL) {
- aValid = aShape->isVertex();
- }
- }
- }
- else {
- AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (anAttr.get() != NULL) {
- AttributePtr aRefAttr = anAttr->attr();
- aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::typeId();
- }
- }
- }
- return aValid;
-}
+++ /dev/null
-// 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 <StdSelect_TypeOfEdge.hxx>
-
-/**
-* \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<std::string>& theArguments) const;
-};
-
-#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_ShapeType.h"
+#include "GeomValidators_Tools.h"
+
+#include <GeomAPI_Curve.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_Result.h>
+#include "ModelAPI_AttributeRefAttr.h"
+
+#include <Events_Error.h>
+
+#include <string>
+#include <map>
+
+
+typedef std::map<std::string, GeomValidators_ShapeType::TypeOfShape> 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<std::string>& theArguments) const
+{
+ bool aValid = false;
+
+ std::list<std::string>::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<ModelAPI_Result>(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<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (anAttr.get() != NULL) {
+ if (aShapeType == Vertex) {
+ AttributePtr aRefAttr = anAttr->attr();
+ aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::typeId();
+ }
+ }
+ }
+ return aValid;
+}
--- /dev/null
+// 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 <string>
+
+/**
+* \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<std::string>& 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
#include <ModuleBase_IPropertyPanel.h>
#include <ModuleBase_WidgetEditor.h>
#include <ModuleBase_FilterFactory.h>
-#include <GeomValidators_Edge.h>
-#include <GeomValidators_EdgeOrVertex.h>
+#include <GeomValidators_ShapeType.h>
#include <GeomValidators_Face.h>
#include <GeomValidators_ConstructionComposite.h>
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",
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Session.h>
-#include <GeomValidators_Edge.h>
+#include <GeomValidators_ShapeType.h>
#include <GeomDataAPI_Point2D.h>
// 1. check whether the references object is a linear
ObjectPtr anObject = aRefAttr->object();
- const ModelAPI_AttributeValidator* anEdgeValidator =
- dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
+ const ModelAPI_AttributeValidator* aShapeValidator =
+ dynamic_cast<const GeomValidators_ShapeType*>(aFactory->validator("GeomValidators_ShapeType"));
std::list<std::string> 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<ModelAPI_Feature>(theAttribute->owner());
shape_types="edge vertex">
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
<validator id="PartSet_DifferentObjects"/>
- <validator id="GeomValidators_EdgeOrVertex"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex,line"/>
</sketch_shape_selector>/>
<sketch_shape_selector
id="ConstraintEntityB"
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
- <validator id="GeomValidators_EdgeOrVertex"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex,line"/>
</sketch_shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<label title="Select a line on which to calculate length" tooltip="Select a line on which to calculate length"/>
<shape_selector id="ConstraintEntityA" label="Line" tooltip="Select an line"
shape_types="edge" >
- <validator id="GeomValidators_Edge" parameters="line"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Length" id="ConstraintValue" default="computed">
<label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
<shape_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc"
shape_types="edge">
- <validator id="GeomValidators_Edge" parameters="circle"/>
+ <validator id="GeomValidators_ShapeType" parameters="circle"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Radius" id="ConstraintValue" default="computed"/>
<feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
<sketch_shape_selector id="ConstraintEntityA"
label="First line" tooltip="Select a line" shape_types="edge">
- <validator id="GeomValidators_Edge" parameters="line"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
</sketch_shape_selector>
<sketch_shape_selector id="ConstraintEntityB" label="Second line" tooltip="Select a line"
shape_types="edge">
- <validator id="GeomValidators_Edge" parameters="line"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
</sketch_shape_selector>
shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
- <validator id="GeomValidators_Edge" parameters="line"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
</sketch_shape_selector>
<sketch_shape_selector id="ConstraintEntityB"
shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
- <validator id="GeomValidators_Edge" parameters="line"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
</sketch_shape_selector>
<validator id="PartSet_PerpendicularSelection"/>
</feature>
<sketch_shape_selector id="ConstraintEntityA" label="Object"
tooltip="Select point, line end point, line, center of circle or arc."
shape_types="edge vertex">
- <!--<validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>-->
- <validator id="GeomValidators_EdgeOrVertex"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex,line,circle"/>
<validator id="SketchPlugin_NotFixed"/>
</sketch_shape_selector>
<validator id="PartSet_RigidSelection"/>
<feature id="SketchConstraintHorizontal" title="Horizontal" tooltip="Create constraint defining horizontal line" icon=":icons/horisontal.png">
<sketch_shape_selector id="ConstraintEntityA"
label="Line" tooltip="Select a line" shape_types="edge" use_external="false">
- <validator id="GeomValidators_Edge" parameters="line"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
</sketch_shape_selector>
<validator id="PartSet_HVDirSelection"/>
</feature>
<feature id="SketchConstraintVertical" title="Vertical" tooltip="Create constraint defining vertical line" icon=":icons/vertical.png">
<sketch_shape_selector id="ConstraintEntityA"
label="Line" tooltip="Select a line" shape_types="edge" use_external="false">
- <validator id="GeomValidators_Edge" parameters="line"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
</sketch_shape_selector>
<validator id="PartSet_HVDirSelection"/>
</feature>
tooltip="Create constraint, mirroring group of objects">
<sketch_shape_selector id="ConstraintEntityA"
label="Mirror line" tooltip="Select mirror line" shape_types="edge">
- <validator id="GeomValidators_Edge" parameters="line"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
</sketch_shape_selector>
<sketch_multi_selector id="ConstraintMirrorList"
label="List of objects"