X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_Face.cpp;h=51a5012cdab7ac5cc292a9478893ac9a9b9f3cb0;hb=3205d0f18200948632155bbe7b640bc1e482243d;hp=821b45cb0755d58d8e11b839b9167a4817beb3d1;hpb=a24b7e6f4d112d5e7889fd76f030298fc428cd01;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp index 821b45cb0..51a5012cd 100644 --- a/src/GeomValidators/GeomValidators_Face.cpp +++ b/src/GeomValidators/GeomValidators_Face.cpp @@ -31,35 +31,67 @@ GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType) } bool GeomValidators_Face::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const + const std::list& theArguments, + std::string& theError) const { - bool aValid = false; - - GeomAbs_SurfaceType aFaceType = GeomAbs_Plane; - if (theArguments.size() == 1) { - std::string anArgument = theArguments.front(); - aFaceType = faceType(anArgument); + std::string anAttributeType = theAttribute->attributeType(); + if (anAttributeType != ModelAPI_AttributeSelection::typeId()) { + theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed"; + return false; } + bool aValid = true; ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); - if (anObject.get() != NULL) { - AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast - (theAttribute); + if (!anObject.get()) { + aValid = true; // an empty face selected is valid. + } + else { + AttributeSelectionPtr aSelectionAttr = + std::dynamic_pointer_cast(theAttribute); std::shared_ptr aGeomShape = aSelectionAttr->value(); - std::shared_ptr aGeomFace(new GeomAPI_Face(aGeomShape)); - if (aGeomFace.get() != NULL) { - switch(aFaceType) { - case GeomAbs_Plane: + if (!aGeomShape.get()) { + // if the shape is empty, apply the validator to the shape of result + aGeomShape = aSelectionAttr->context()->shape(); + } + // it is necessary to check whether the shape is face in order to set in selection a value + // with any type and check the type in this validator + // It is realized to select any object in OB and filter it in this validator (sketch plane) + if (!aGeomShape->isFace()) { + aValid = false; + theError = "The shape is not a face."; + } + else { + std::shared_ptr aGeomFace(new GeomAPI_Face(aGeomShape)); + if (!aGeomFace.get()) { + aValid = false; + theError = "The shape is not a face."; + } + else { + GeomAbs_SurfaceType aFaceType = GeomAbs_Plane; + if (theArguments.size() == 1) + aFaceType = faceType(theArguments.front()); + + switch (aFaceType) { + case GeomAbs_Plane: { aValid = aGeomFace->isPlanar(); + if (!aValid) + theError = "The shape is not a plane."; + } + break; + case GeomAbs_Cylinder:{ + aValid = aGeomFace->isCylindrical(); + if (!aValid) + theError = "The shape is not a cylinder."; + } + break; + default: { + aValid = false; + theError = "The shape is not an available face."; break; - case GeomAbs_Cylinder: - break; - default: - break; + } + } } } } - else - aValid = true; // an empty face selected is valid. return aValid; }