Salome HOME
Issue #504 - 1.17. Error user feedback when a feature fail
authorspo <sergey.pokhodenko@opencascade.com>
Fri, 4 Sep 2015 13:41:24 +0000 (16:41 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 4 Sep 2015 13:41:48 +0000 (16:41 +0300)
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Constraint.h
src/SketchSolver/SketchSolver_Group.cpp

index 8e96b123e356550a033210d3a1d7d7c1bcb655e1..cfa5e8a095e35f92ed3c07b14d8d450579e931b6 100644 (file)
@@ -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);
index c8f7a22e6694d2239060ed00411651e21cdc3844..1c0edb44e6bc986c4990e84b929da541b12a897b 100644 (file)
@@ -19,6 +19,7 @@
 #include <GeomAlgoAPI_PointBuilder.h>
 
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
@@ -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()
index fe0df3ba8295c266da56b0da51bbd398d8e639c3..3246a2ad728721f27e3024645f43dc7ee9095cdd 100644 (file)
@@ -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()
index 377affa7f3377842ee7691eee4e754d76f917065..e67bae3b8b92081c28f7dfd4c1c82a308d3933ec 100755 (executable)
@@ -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 <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Session.h>
 
 #include <GeomValidators_ShapeType.h>
@@ -297,3 +300,22 @@ bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
   return true;
 }
 
+bool SketchPlugin_SolverErrorValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                                const std::list<std::string>& 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;
+}
+
index f9f45506feacef5e948913c7df791698db821abf..7016177d51799ab22fb5ece8476395911a2af7f1 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SketchPlugin.h"
 #include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_FeatureValidator.h>
 
 /**\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<ModelAPI_Feature>& theFeature,
+                       const std::list<std::string>& 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
index d1ab44b6c7375624d3904a08117c34ade6a3dac5..c27d599b7c4a3e3f88a2fb9a74d83db1a0589720 100644 (file)
@@ -13,6 +13,7 @@
         <sketch-start-label id="External" title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch">
           <validator id="GeomValidators_Face" parameters="plane"/>
         </sketch-start-label>
+        <validator id="SketchPlugin_SolverErrorValidator"/>
       <!--icon=":pictures/x_point.png"-->
       </feature>
       <feature id="SketchPoint" title="Point" tooltip="Create point" icon=":icons/point.png">
index 2a12fc5e95e47b0fb8ee7e21a37cf086bd645f0a..8589dc19bb7d5b3d2e23e48a71950db084f71e5b 100644 (file)
@@ -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()
   {}
index 9325a6e1ecd5c1d0e6721d7fd2738b78b248ed1c..589b6a320385e25749b23f36cc8a0eed6f8110f9 100644 (file)
@@ -20,6 +20,7 @@
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Validator.h>
 
 #include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintEqual.h>
 #include <SketchPlugin_ConstraintFillet.h>
 #include <SketchPlugin_ConstraintLength.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintMirror.h>
 #include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_ConstraintTangent.h>
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_MultiRotation.h>
 #include <SketchPlugin_MultiTranslation.h>
+#include <SketchPlugin_Sketch.h>
 
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
@@ -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;