X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Constraint.h;h=dbb64762394677943d612f1cf8faa6e13257b0f1;hb=383021cb51c4720904096ca851db5ee79255b402;hp=3f547d8d8a8a2ccd294f80bd8b1e74f65085d060;hpb=4cbd08290dc7a540e3fa93913d484e8336df90d9;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Constraint.h b/src/SketchSolver/SketchSolver_Constraint.h index 3f547d8d8..dbb647623 100644 --- a/src/SketchSolver/SketchSolver_Constraint.h +++ b/src/SketchSolver/SketchSolver_Constraint.h @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: SketchSolver_Constraint.h // Created: 27 May 2014 // Author: Artem ZHIDKOV @@ -6,40 +8,101 @@ #define SketchSolver_Constraint_H_ #include "SketchSolver.h" +#include #include +#include +#include + #include #include /** \class SketchSolver_Constraint - * \ingroup DataModel - * \brief Obtain information about SketchPlugin's constraint + * \ingroup Plugins + * \brief Converts SketchPlugin constraint to the constraint applicable for solver */ class SketchSolver_Constraint { +protected: + /// Default constructor + SketchSolver_Constraint() + : myGroupID(GID_UNKNOWN), + myType(CONSTRAINT_UNKNOWN) + {} + public: - SketchSolver_Constraint(); - SketchSolver_Constraint(boost::shared_ptr theConstraint); - - /** \brief Compute constraint type according to SolveSpace identifiers - * and verify that constraint parameters are correct - * \param[in] theConstraint constraint which type should be determined - * \return identifier of constraint type or SLVS_C_UNKNOWN if the type is wrong - */ - const int& getType(boost::shared_ptr theConstraint); - /// \brief Returns the type of myConstraint member - inline const int& getType() const + /// Constructor based on SketchPlugin constraint + SKETCHSOLVER_EXPORT SketchSolver_Constraint(ConstraintPtr theConstraint); + + virtual ~SketchSolver_Constraint() {} + + /// \brief Initializes parameters and start constraint creation + /// \param theStorage [in] storage where to place new constraint + /// \param theGroupID [in] group for constraint + /// \param theSketchID [in] sketch for constraint + void process(StoragePtr theStorage, const GroupID& theGroupID, const EntityID& theSketchID); + + /// \brief Update constraint + SKETCHSOLVER_EXPORT virtual void update(); + + /// \brief Tries to remove constraint + /// \return \c false, if current constraint contains another SketchPlugin constraints (like for multiple coincidence) + SKETCHSOLVER_EXPORT virtual bool remove(); + + /// \brief Obtain a type of SketchPlugin constraint + SKETCHSOLVER_EXPORT static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint); + + /// \brief Returns the type of constraint + virtual SketchSolver_ConstraintType getType() const { return myType; } - /// \brief Returns list of attributes names in the correct order required by SolveSpace - inline const std::vector& getAttributes() const - { return myAttributesList; } + /// \brief Returns list of attributes of constraint + const std::list& attributes() const + { return myAttributes; } -private: - boost::shared_ptr myConstraint; - int myType; - std::vector myAttributesList; + /// \brief Verify the feature or any its attribute is used by constraint + virtual bool isUsed(FeaturePtr theFeature) const; + /// \brief Verify the attribute is used by constraint + virtual bool isUsed(AttributePtr theAttribute) const; + + /// \brief Notify constraint, that coincidence appears or removed + virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1, EntityWrapperPtr theCoincAttr2) + { /* implement in derived class */ } + + /// \brief Shows error message + const std::string& error() const + { return myErrorMsg; } + +protected: + /// \brief Converts SketchPlugin constraint to a list of solver's constraints + virtual void process(); + + /// \brief Generate list of attributes of constraint in order useful for constraints + /// \param[out] theValue numerical characteristic of constraint (e.g. distance) + /// \param[out] theAttributes list of attributes to be filled + virtual void getAttributes(double& theValue, std::vector& theAttributes); + + /// \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() + {} + + /// \brief Removes last error + void cleanErrorMsg() + { myErrorMsg.clear(); } + +protected: + GroupID myGroupID; ///< identifier of the group, the constraint belongs to + EntityID mySketchID; ///< identifier of the sketch, the constraint belongs to + ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint + StoragePtr myStorage; ///< storage, which contains all information about entities and constraints + SketchSolver_ConstraintType myType; ///< type of constraint + std::list myAttributes; ///< attributes of constraint + + std::string myErrorMsg; ///< error message }; +typedef std::shared_ptr SolverConstraintPtr; + #endif