From: spo Date: Fri, 4 Sep 2015 13:41:24 +0000 (+0300) Subject: Issue #504 - 1.17. Error user feedback when a feature fail X-Git-Tag: V_1.4.0_beta4~116 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5a3b32ce1c1c302bce9a4372cb6eee1965da3e09;p=modules%2Fshaper.git Issue #504 - 1.17. Error user feedback when a feature fail --- diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 8e96b123e..cfa5e8a09 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -68,6 +68,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_CoincidenceAttrValidator); aFactory->registerValidator("SketchPlugin_CopyValidator", new SketchPlugin_CopyValidator); + aFactory->registerValidator("SketchPlugin_SolverErrorValidator", + new SketchPlugin_SolverErrorValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index c8f7a22e6..1c0edb44e 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -56,6 +57,7 @@ void SketchPlugin_Sketch::initAttributes() data()->addAttribute(SketchPlugin_SketchEntity::EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory( getKind(), SketchPlugin_SketchEntity::EXTERNAL_ID()); + data()->addAttribute(SketchPlugin_Sketch::SOLVER_ERROR(), ModelAPI_AttributeString::typeId()); } void SketchPlugin_Sketch::execute() diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index fe0df3ba8..3246a2ad7 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -61,6 +61,12 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu static const std::string MY_FEATURES_ID("Features"); return MY_FEATURES_ID; } + /// Sketch solver error + inline static const std::string& SOLVER_ERROR() + { + static const std::string MY_SOLVER_ERROR("SolverError"); + return MY_SOLVER_ERROR; + } /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 377affa7f..e67bae3b8 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -5,13 +5,15 @@ // Author: Vitaly SMETANNIKOV #include "SketchPlugin_Validators.h" -#include "SketchPlugin_ConstraintDistance.h" + +#include "SketchPlugin_Arc.h" +#include "SketchPlugin_Circle.h" #include "SketchPlugin_ConstraintCoincidence.h" +#include "SketchPlugin_ConstraintDistance.h" #include "SketchPlugin_ConstraintRigid.h" #include "SketchPlugin_Line.h" -#include "SketchPlugin_Arc.h" -#include "SketchPlugin_Circle.h" #include "SketchPlugin_Point.h" +#include "SketchPlugin_Sketch.h" #include "SketcherPrs_Tools.h" @@ -21,6 +23,7 @@ #include #include #include +#include #include #include @@ -297,3 +300,22 @@ bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute, return true; } +bool SketchPlugin_SolverErrorValidator::isValid(const std::shared_ptr& theFeature, + const std::list& theArguments, + std::string& theError) const +{ + AttributeStringPtr aAttributeString = theFeature->string(SketchPlugin_Sketch::SOLVER_ERROR()); + + if (!aAttributeString->value().empty()) { + theError = aAttributeString->value(); + return false; + } + + return true; +} + +bool SketchPlugin_SolverErrorValidator::isNotObligatory(std::string theFeature, std::string theAttribute) +{ + return true; +} + diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index f9f45506f..7016177d5 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -9,6 +9,7 @@ #include "SketchPlugin.h" #include +#include /**\class SketchPlugin_DistanceAttrValidator * \ingroup Validators @@ -133,4 +134,24 @@ class SketchPlugin_CopyValidator : public ModelAPI_AttributeValidator std::string& theError) const; }; +/**\class SketchPlugin_SolverErrorValidator + * \ingroup Validators + * \brief Validator for the solver error. + * + * Simply checks that solver error attribute is empty. Returns the attribute value as an error. + */ +class SketchPlugin_SolverErrorValidator : public ModelAPI_FeatureValidator +{ + public: + //! returns true if there are no solver errors + //! \param theFeature the checked feature + //! \param theArguments arguments of the feature (not used) + virtual bool isValid(const std::shared_ptr& theFeature, + const std::list& theArguments, + std::string& theError) const; + + /// Returns true if the attribute in feature is not obligatory for the feature execution + virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); +}; + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index d1ab44b6c..c27d599b7 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -13,6 +13,7 @@ + diff --git a/src/SketchSolver/SketchSolver_Constraint.h b/src/SketchSolver/SketchSolver_Constraint.h index 2a12fc5e9..8589dc19b 100644 --- a/src/SketchSolver/SketchSolver_Constraint.h +++ b/src/SketchSolver/SketchSolver_Constraint.h @@ -51,7 +51,7 @@ public: /// \brief Returns the type of constraint virtual int getType() const = 0; - /// \brief The constraint is made temoparary + /// \brief The constraint is made temporary void makeTemporary() const; /// \brief Checks the constraint is used by current object @@ -87,7 +87,7 @@ protected: /// \return \c true if some attributes are changed virtual bool checkAttributesChanged(ConstraintPtr theConstraint); - /// \brief This method is used in derived objects to check consistence of constraint. + /// \brief This method is used in derived objects to check consistency of constraint. /// E.g. the distance between line and point may be signed. virtual void adjustConstraint() {} diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 9325a6e1e..589b6a320 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -27,16 +28,17 @@ #include #include +#include #include #include #include -#include #include #include #include #include #include #include +#include #include #include @@ -482,11 +484,12 @@ bool SketchSolver_Group::resolveConstraints() } } } catch (...) { - Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this); +// Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this); if (myPrevSolved) { sendMessage(EVENT_SOLVER_FAILED); myPrevSolved = false; } + getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(SketchSolver_Error::SOLVESPACE_CRASH()); return false; } if (aResult == SLVS_RESULT_OKAY) { // solution succeeded, store results into correspondent attributes @@ -499,12 +502,14 @@ bool SketchSolver_Group::resolveConstraints() sendMessage(EVENT_SOLVER_REPAIRED); myPrevSolved = true; } + getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(""); } else if (!myConstraints.empty()) { - Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this); +// Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this); if (myPrevSolved) { sendMessage(EVENT_SOLVER_FAILED); myPrevSolved = false; } + getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(SketchSolver_Error::CONSTRAINTS()); } aResolved = true;