1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include "GeomValidators_Face.h"
5 #include "GeomValidators_Tools.h"
7 #include "ModelAPI_AttributeSelection.h"
9 #include <GeomAPI_Face.h>
11 #include <Events_Error.h>
16 typedef std::map<std::string, GeomAbs_SurfaceType> FaceTypes;
17 static FaceTypes MyFaceTypes;
19 GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType)
21 if (MyFaceTypes.size() == 0) {
22 MyFaceTypes["plane"] = GeomAbs_Plane;
23 MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
25 std::string aType = std::string(theType.c_str());
26 if (MyFaceTypes.find(aType) != MyFaceTypes.end())
27 return MyFaceTypes[aType];
29 Events_Error::send("Face type defined in XML is not implemented!");
33 bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
34 const std::list<std::string>& theArguments,
35 std::string& theError) const
37 std::string anAttributeType = theAttribute->attributeType();
38 if (anAttributeType != ModelAPI_AttributeSelection::typeId()) {
39 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
44 ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
45 if (!anObject.get()) {
46 aValid = true; // an empty face selected is valid.
49 AttributeSelectionPtr aSelectionAttr =
50 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
51 std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
52 if (!aGeomShape.get()) {
53 // if the shape is empty, apply the validator to the shape of result
54 aGeomShape = aSelectionAttr->context()->shape();
56 // it is necessary to check whether the shape is face in order to set in selection a value
57 // with any type and check the type in this validator
58 // It is realized to select any object in OB and filter it in this validator (sketch plane)
59 if (!aGeomShape->isFace()) {
61 theError = "The shape is not a face.";
64 std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
65 if (!aGeomFace.get()) {
67 theError = "The shape is not a face.";
70 GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
71 if (theArguments.size() == 1)
72 aFaceType = faceType(theArguments.front());
76 aValid = aGeomFace->isPlanar();
78 theError = "The shape is not a plane.";
81 case GeomAbs_Cylinder:{
82 aValid = aGeomFace->isCylindrical();
84 theError = "The shape is not a cylinder.";
89 theError = "The shape is not an available face.";