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);
#include <GeomAlgoAPI_PointBuilder.h>
#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
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()
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()
// 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"
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Session.h>
#include <GeomValidators_ShapeType.h>
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;
+}
+
#include "SketchPlugin.h"
#include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_FeatureValidator.h>
/**\class SketchPlugin_DistanceAttrValidator
* \ingroup Validators
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
<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">
/// \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
/// \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()
{}
#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>
}
}
} 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
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;