1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include "GeomValidators_Edge.h"
5 #include "GeomValidators_Tools.h"
7 #include <GeomAPI_Curve.h>
8 #include <Events_Error.h>
9 #include <ModelAPI_Result.h>
11 #include <StdSelect_TypeOfEdge.hxx>
17 typedef std::map<std::string, GeomValidators_Edge::TypeOfEdge> EdgeTypes;
18 static EdgeTypes MyEdgeTypes;
20 GeomValidators_Edge::TypeOfEdge GeomValidators_Edge::edgeType(const std::string& theType)
22 if (MyEdgeTypes.size() == 0) {
23 MyEdgeTypes["line"] = Line;
24 MyEdgeTypes["circle"] = Circle;
26 std::string aType = std::string(theType.c_str());
27 if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
28 return MyEdgeTypes[aType];
30 Events_Error::send("Edge type defined in XML is not implemented!");
34 bool GeomValidators_Edge::isValid(const AttributePtr& theAttribute,
35 const std::list<std::string>& theArguments) const
39 TypeOfEdge anEdgeType = AnyEdge;
40 if (theArguments.size() == 1) {
41 std::string anArgument = theArguments.front();
42 anEdgeType = edgeType(anArgument);
45 ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
46 if (anObject.get() != NULL) {
47 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
48 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
49 if (aResult.get() != NULL) {
50 GeomShapePtr aShape = aResult->shape();
51 if (aShape.get() != NULL && aShape->isEdge()) {
52 aValid = anEdgeType == AnyEdge;
54 bool isCircle = GeomAPI_Curve(aShape).isCircle();
55 aValid = (isCircle && anEdgeType == Circle) ||
56 (!isCircle && anEdgeType == Line);
62 //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);