1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include "GeomValidators_ShapeType.h"
5 #include "GeomValidators_Tools.h"
7 #include <GeomAPI_Curve.h>
8 #include <GeomDataAPI_Point2D.h>
10 #include <ModelAPI_Result.h>
11 #include "ModelAPI_AttributeRefAttr.h"
13 #include <Events_Error.h>
19 typedef std::map<std::string, GeomValidators_ShapeType::TypeOfShape> EdgeTypes;
20 static EdgeTypes MyEdgeTypes;
22 GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const std::string& theType)
24 if (MyEdgeTypes.size() == 0) {
25 MyEdgeTypes["vertex"] = Vertex;
26 MyEdgeTypes["line"] = Line;
27 MyEdgeTypes["circle"] = Circle;
29 std::string aType = std::string(theType.c_str());
30 if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
31 return MyEdgeTypes[aType];
33 Events_Error::send("Edge type defined in XML is not implemented!");
37 bool GeomValidators_ShapeType::isValid(const AttributePtr& theAttribute,
38 const std::list<std::string>& theArguments) const
42 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
43 for (; anIt != aLast && !aValid; anIt++) {
44 aValid = isValidArgument(theAttribute, *anIt);
50 bool GeomValidators_ShapeType::isValidArgument(const AttributePtr& theAttribute,
51 const std::string& theArgument) const
54 TypeOfShape aShapeType = shapeType(theArgument);
55 if (aShapeType == AnyShape)
58 ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
59 if (anObject.get() != NULL) {
60 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
61 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
62 if (aResult.get() != NULL) {
63 GeomShapePtr aShape = aResult->shape();
64 if (aShape.get() != NULL) {
67 aValid = aShape->isEdge() && !GeomAPI_Curve(aShape).isCircle();
70 aValid = aShape->isEdge() && GeomAPI_Curve(aShape).isCircle();
73 aValid = aShape->isVertex();
81 AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
82 if (anAttr.get() != NULL) {
83 if (aShapeType == Vertex) {
84 AttributePtr aRefAttr = anAttr->attr();
85 aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::typeId();