X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Validators.cpp;h=13d7138e1af1a97f1cd33ceb757e0601af5da4e6;hb=963b1b8ffcfaab221409c7e0540d8de7eb1297a9;hp=26c965dec1bf824a380a9b1fb222c997f131ca89;hpb=77b44e467b8a8ab3a5b20b8719e593f4f24dc25e;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 26c965dec..13d7138e1 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -30,9 +30,13 @@ #include #include +#include +#include #include #include +#include + const double tolerance = 1.e-7; bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute, @@ -683,3 +687,48 @@ bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttri return true; } + +bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) { + theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed"; + return false; + } + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + ResultPtr aResult = std::dynamic_pointer_cast(aRefAttr->object()); + if (!aResult) { + theError = "The attribute " + theAttribute->id() + " should be an object"; + return false; + } + + std::shared_ptr anEdge = std::dynamic_pointer_cast(aResult->shape()); + if (!anEdge || !anEdge->isLine()) { + theError = "The attribute " + theAttribute->id() + " should be a line"; + return false; + } + + std::shared_ptr aLineDir = anEdge->line()->direction(); + + // find a sketch + std::shared_ptr aSketch; + std::set aRefs = aRefAttr->owner()->data()->refsToMe(); + std::set::const_iterator anIt = aRefs.begin(); + for (; anIt != aRefs.end(); ++anIt) { + CompositeFeaturePtr aComp = + std::dynamic_pointer_cast((*anIt)->owner()); + if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) { + aSketch = std::dynamic_pointer_cast(aComp); + break; + } + } + if (!aSketch) { + theError = "There is no sketch referring to the current feature"; + return false; + } + + std::shared_ptr aPlane = aSketch->plane(); + std::shared_ptr aNormal = aPlane->direction(); + return fabs(aNormal->dot(aLineDir)) > tolerance * tolerance; +}