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 <GeomAbs_SurfaceType.hxx>
13 #include <Events_InfoMessage.h>
18 typedef std::map<std::string, GeomAbs_SurfaceType> FaceTypes;
19 static FaceTypes MyFaceTypes;
21 GeomAbs_SurfaceType faceType(const std::string& theType)
23 if (MyFaceTypes.size() == 0) {
24 MyFaceTypes["plane"] = GeomAbs_Plane;
25 MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
27 std::string aType = std::string(theType.c_str());
28 if (MyFaceTypes.find(aType) != MyFaceTypes.end())
29 return MyFaceTypes[aType];
31 Events_InfoMessage("GeomValidators_Face", "Face type defined in XML is not implemented!").send();
35 bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
36 const std::list<std::string>& theArguments,
37 Events_InfoMessage& theError) const
39 std::string anAttributeType = theAttribute->attributeType();
40 if (anAttributeType != ModelAPI_AttributeSelection::typeId()) {
41 theError = "The attribute with the %1 type is not processed";
42 theError.arg(theAttribute->attributeType());
47 ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
48 if (!anObject.get()) {
49 aValid = true; // an empty face selected is valid.
52 AttributeSelectionPtr aSelectionAttr =
53 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
54 std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
55 if (!aGeomShape.get()) {
56 // if the shape is empty, apply the validator to the shape of result
57 aGeomShape = aSelectionAttr->context()->shape();
59 // it is necessary to check whether the shape is face in order to set in selection a value
60 // with any type and check the type in this validator
61 // It is realized to select any object in OB and filter it in this validator (sketch plane)
62 if (!aGeomShape->isFace()) {
64 theError = "The shape is not a face.";
67 std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
68 if (!aGeomFace.get()) {
70 theError = "The shape is not a face.";
73 GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
74 if (theArguments.size() == 1)
75 aFaceType = faceType(theArguments.front());
79 aValid = aGeomFace->isPlanar();
81 theError = "The shape is not a plane.";
84 case GeomAbs_Cylinder:{
85 aValid = aGeomFace->isCylindrical();
87 theError = "The shape is not a cylinder.";
92 theError = "The shape is not an available face.";