1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include "ModuleBase_ValidatorLinearEdge.h"
5 #include "ModuleBase_WidgetShapeSelector.h"
7 #include <GeomAPI_Curve.h>
9 #include <Events_Error.h>
11 #include <StdSelect_TypeOfEdge.hxx>
17 typedef QMap<QString, ModuleBase_ValidatorLinearEdge::TypeOfEdge> EdgeTypes;
18 static EdgeTypes MyEdgeTypes;
20 ModuleBase_ValidatorLinearEdge::TypeOfEdge ModuleBase_ValidatorLinearEdge::edgeType(const std::string& theType)
22 if (MyEdgeTypes.count() == 0) {
23 MyEdgeTypes["line"] = Line;
24 MyEdgeTypes["circle"] = Circle;
26 QString aType = QString(theType.c_str()).toLower();
27 if (MyEdgeTypes.contains(aType))
28 return MyEdgeTypes[aType];
30 Events_Error::send("Edge type defined in XML is not implemented!");
34 bool ModuleBase_ValidatorLinearEdge::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 = ModuleBase_WidgetShapeSelector::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);