Salome HOME
Do not use align to the left in the page group box widget.
[modules/shaper.git] / src / GeomValidators / GeomValidators_Edge.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3
4 #include "GeomValidators_Edge.h"
5 #include "GeomValidators_Tools.h"
6
7 #include <GeomAPI_Curve.h>
8 #include <Events_Error.h>
9 #include <ModelAPI_Result.h>
10
11 #include <StdSelect_TypeOfEdge.hxx>
12
13 #include <string>
14 #include <map>
15
16
17 typedef std::map<std::string, GeomValidators_Edge::TypeOfEdge> EdgeTypes;
18 static EdgeTypes MyEdgeTypes;
19
20 GeomValidators_Edge::TypeOfEdge GeomValidators_Edge::edgeType(const std::string& theType)
21 {
22   if (MyEdgeTypes.size() == 0) {
23     MyEdgeTypes["line"] = Line;
24     MyEdgeTypes["circle"] = Circle;
25   }
26   std::string aType = std::string(theType.c_str());
27   if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
28     return MyEdgeTypes[aType];
29   
30   Events_Error::send("Edge type defined in XML is not implemented!");
31   return AnyEdge;
32 }
33
34 bool GeomValidators_Edge::isValid(const AttributePtr& theAttribute,
35                                   const std::list<std::string>& theArguments) const
36 {
37   bool aValid = false;
38
39   TypeOfEdge anEdgeType = AnyEdge;
40   if (theArguments.size() == 1) {
41     std::string anArgument = theArguments.front();
42     anEdgeType = edgeType(anArgument);
43   }
44
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;
53         if (!aValid) {
54           bool isCircle = GeomAPI_Curve(aShape).isCircle();
55           aValid = (isCircle && anEdgeType == Circle) ||
56                    (!isCircle && anEdgeType == Line);
57         }
58       }
59     }
60   }
61   else {
62     //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
63   }
64   return aValid;
65 }