1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "GeomValidators_Face.h"
21 #include "GeomValidators_Tools.h"
23 #include "ModelAPI_AttributeSelection.h"
25 #include <GeomAPI_Face.h>
27 #include <GeomAbs_SurfaceType.hxx>
29 #include <Events_InfoMessage.h>
31 typedef std::map<std::string, GeomAbs_SurfaceType> FaceTypes;
32 static FaceTypes MyFaceTypes;
34 GeomAbs_SurfaceType faceType(const std::string& theType)
36 if (MyFaceTypes.size() == 0) {
37 MyFaceTypes["plane"] = GeomAbs_Plane;
38 MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
40 std::string aType = std::string(theType.c_str());
41 if (MyFaceTypes.find(aType) != MyFaceTypes.end())
42 return MyFaceTypes[aType];
44 Events_InfoMessage("GeomValidators_Face", "Face type defined in XML is not implemented!").send();
48 bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
49 const std::list<std::string>& theArguments,
50 Events_InfoMessage& theError) const
52 std::string anAttributeType = theAttribute->attributeType();
53 if (anAttributeType != ModelAPI_AttributeSelection::typeId()) {
54 theError = "The attribute with the %1 type is not processed";
55 theError.arg(theAttribute->attributeType());
60 ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
61 if (!anObject.get()) {
62 aValid = true; // an empty face selected is valid.
65 AttributeSelectionPtr aSelectionAttr =
66 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
67 std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
68 if (!aGeomShape.get()) {
69 // if the shape is empty, apply the validator to the shape of result
70 aGeomShape = aSelectionAttr->context()->shape();
72 // it is necessary to check whether the shape is face in order to set in selection a value
73 // with any type and check the type in this validator
74 // It is realized to select any object in OB and filter it in this validator (sketch plane)
75 if (!aGeomShape->isFace()) {
77 theError = "The shape is not a face.";
80 std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
81 if (!aGeomFace.get()) {
83 theError = "The shape is not a face.";
86 GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
87 if (theArguments.size() == 1)
88 aFaceType = faceType(theArguments.front());
92 aValid = aGeomFace->isPlanar();
94 theError = "The shape is not a plane.";
97 case GeomAbs_Cylinder:{
98 aValid = aGeomFace->isCylindrical();
100 theError = "The shape is not a cylinder.";
105 theError = "The shape is not an available face.";