From: azv Date: Thu, 4 Feb 2016 07:44:50 +0000 (+0300) Subject: Validator for tangent arc creation X-Git-Tag: V_2.2.0~157 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b0731def683ceed958476ceb7e1c228ce49a34c0;p=modules%2Fshaper.git Validator for tangent arc creation --- diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index a07675a53..6cd164a88 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -76,6 +76,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_FilletVertexValidator); aFactory->registerValidator("SketchPlugin_MiddlePointAttr", new SketchPlugin_MiddlePointAttrValidator); + aFactory->registerValidator("SketchPlugin_ArcTangentPoint", + new SketchPlugin_ArcTangentPointValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); @@ -192,6 +194,7 @@ std::shared_ptr SketchPlugin_Plugin aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintCollinear::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane); @@ -202,6 +205,7 @@ std::shared_ptr SketchPlugin_Plugin aMsg->setState(SketchPlugin_ConstraintVertical::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintEqual::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintTangent::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintMiddle::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintMirror::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintFillet::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintAngle::ID(), aHasSketchPlane); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 9ac7fec38..a29070b1f 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -650,3 +650,44 @@ bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttri } return true; } + +bool SketchPlugin_ArcTangentPointValidator::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); + AttributePtr anAttr = aRefAttr->attr(); + if (!anAttr) { + theError = "The attribute " + theAttribute->id() + " should be a point"; + return false; + } + + FeaturePtr anAttrFeature = std::dynamic_pointer_cast(anAttr->owner()); + const std::string& aFeatureType = anAttrFeature->getKind(); + if (aFeatureType == SketchPlugin_Arc::ID()) { + // selected point should not be a center of arc + const std::string& aPntId = anAttr->id(); + if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) { + theError = "The attribute " + aPntId + " is not supported"; + return false; + } + } + else if (aFeatureType == SketchPlugin_Line::ID()) { + // selected point should be bound point of line + const std::string& aPntId = anAttr->id(); + if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) { + theError = "The attribute " + aPntId + " is not supported"; + return false; + } + } + else { + theError = "Unable to build tangent arc on " + anAttrFeature->getKind(); + return false; + } + + return true; +} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 86f8ee295..ef5e77aba 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -199,4 +199,23 @@ class SketchPlugin_MiddlePointAttrValidator : public ModelAPI_AttributeValidator std::string& theError) const; }; + +/**\class SketchPlugin_ArcTangentPointValidator + * \ingroup Validators + * \brief Validator for the point where the tangent arc is building. + * + * Checks that the point is a start or end point just on line or arc. + */ +class SketchPlugin_ArcTangentPointValidator : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + //! \param theError error message + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 68e7e32f0..deaee27b9 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -77,7 +77,9 @@ - + + +