X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintManager.h;h=a2d7ffaffe580a08ca944a71938b56dfae64092d;hb=7c14fff8f3b1848b5903a451a8f3e2fc071e7f30;hp=7bd108df6f62ad480d2a563bbc976de6e99a5959;hpb=d56fb361cb3725fbf72b3d6c5a152652b83ab463;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.h b/src/SketchSolver/SketchSolver_ConstraintManager.h index 7bd108df6..a2d7ffaff 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.h +++ b/src/SketchSolver/SketchSolver_ConstraintManager.h @@ -1,138 +1,112 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: SketchSolver_ConstraintManager.h // Created: 08 May 2014 // Author: Artem ZHIDKOV -#ifndef SketchSolver_ConstraintManager_Headerfile -#define SketchSolver_ConstraintManager_Headerfile +#ifndef SketchSolver_ConstraintManager_H_ +#define SketchSolver_ConstraintManager_H_ #include "SketchSolver.h" +#include +#include +#include #include -// Need to be defined before including SolveSpace to avoid additional dependances on Windows platform -#if defined(WIN32) && !defined(HAVE_C99_INTEGER_TYPES) -typedef unsigned int UINT32; -#endif #include #include +#include #include #include - - -// Unknown constraint (for error reporting) -#define SLVS_C_UNKNOWN 0 +#include /** \class SketchSolver_ConstraintManager - * \ingroup DataModel - * \brief Transforms the Constraint feature into the format understandable by SolveSpace library. + * \ingroup Plugins + * \brief Listens the changes of SketchPlugin features and transforms the Constraint + * feature into the format understandable by SolveSpace library. * - * Constraints created for SolveSpace library will be divided into the groups. + * Constraints created for SolveSpace library are divided into the groups. * The division order based on connectedness of the features by the constraints. * The groups may be fused or separated according to the new constraints. + * + * \remark This is a singleton. */ -class SketchSolver_ConstraintManager +class SketchSolver_ConstraintManager : public Events_Listener { -public: + public: + /** \brief Main method to create constraint manager + * \return pointer to the singleton + */ + static SketchSolver_ConstraintManager* Instance(); + + /** \brief Implementation of Event Listener method + * \param[in] theMessage the data of the event + */ + virtual void processEvent(const std::shared_ptr& theMessage); + + protected: SketchSolver_ConstraintManager(); ~SketchSolver_ConstraintManager(); - /** \brief Adds a constraint into the manager - * \param[in] theConstraint constraint to be added - * \return \c true if the constraint added successfully + /** \brief Adds or updates a constraint or an entity in the suitable group + * \param[in] theFeature sketch feature to be changed + * \return \c true if the feature changed successfully */ - SKETCHSOLVER_EXPORT bool addConstraint(boost::shared_ptr theConstraint); + bool changeConstraintOrEntity(std::shared_ptr theFeature); /** \brief Removes a constraint from the manager * \param[in] theConstraint constraint to be removed * \return \c true if the constraint removed successfully */ - SKETCHSOLVER_EXPORT bool removeConstraint(boost::shared_ptr theConstraint); - -private: - class SketchSolver_ConstraintGroup; - - /** \brief Searches list of groups which interact with specified constraint - * \param[in] theConstraint constraint to be found - * \param[out] theGroups list of group indexes interacted with constraint - */ - void findGroups(boost::shared_ptr theConstraint, - std::vector& theGroupIDs) const; + bool removeConstraint(std::shared_ptr theConstraint); -private: - std::vector myGroups; ///< groups of constraints -}; - - -/** \class SketchSolver_ConstraintGroup - * \ingroup DataModel - * \brief Keeps the group of constraints which based on the same entities - */ -class SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup -{ -public: - SketchSolver_ConstraintGroup(); - ~SketchSolver_ConstraintGroup(); - - /// \brief Returns group's unique identifier - const Slvs_hGroup& getId() const - {return myID;} - - /** \brief Adds a constraint into the group - * \param[in] theConstraint constraint to be added - * \return \c true if the constraint added successfully - */ - bool addConstraint(boost::shared_ptr theConstraint); - - /** \brief Removes a constraint into the group - * \param[in] theConstraint constraint to be removed - * \return \c true if the constraint removed successfully + /** \brief Adds or updates a workplane in the manager + * \param[in] theSketch the feature to create or update workplane + * \return \c true if the workplane changed successfully + * \remark Type of theSketch is not verified inside */ - bool removeConstraint(boost::shared_ptr theConstraint); + bool changeWorkplane(CompositeFeaturePtr theSketch); - /** \brief Verifies the constraint uses the objects from this group - * \param[in] theConstraint constraint for verification of interaction - * \return \c true if the constrained objects are used in current group + /** \brief Removes a workplane from the manager. + * All groups based on such workplane will be removed too. + * \param[in] theSketch the feature to be removed + * \return \c true if the workplane removed successfully */ - bool isInteract(boost::shared_ptr theConstraint) const; + bool removeWorkplane(std::shared_ptr theSketch); -protected: - /** \brief Creates a workplane from the sketch parameters - * \param[in] theParams list of the basic parameters of the workplane - * \return \c true if success + /** \brief Updates entity which is moved in GUI + * \param[in] theFeature entity to be updated */ - bool addWorkplane(std::list< boost::shared_ptr >& theParams); + void moveEntity(std::shared_ptr theFeature); - /** \brief Adds an entity into the group - * \param[in] theEntity the object of constraint - * \return identifier of created entity or 0 if entity was not added + /** \brief Goes through the list of groups and solve the constraints + * \param theForceUpdate flushes the update event in any case: something changed or not */ - Slvs_hEntity addEntity(boost::shared_ptr theEntity); + void resolveConstraints(const bool theForceUpdate); - /** \brief Adds a parameter into the group - * \param[in] theParam parameter to be added - * \return identifier of created parameter or 0 if it was not added + private: + /** \brief Searches list of groups which interact with specified feature + * \param[in] theFeature object to be found + * \param[out] theGroups list of group indexes interacted with the feature */ - Slvs_hParam addParameter(double theParam); + void findGroups(std::shared_ptr theFeature, + std::set& theGroupIDs) const; - /** \brief Compute constraint type according to SolveSpace identifiers - * \param[in] theConstraint constraint which type should be determined - * \return identifier of constraint type + /** \brief Searches in the list of groups the workplane which constains specified feature + * \param[in] theFeature object to be found + * \return workplane containing the feature */ - int getConstraintType(const boost::shared_ptr& theConstraint) const; - -private: - Slvs_hGroup myID; ///< the index of the group - Slvs_Entity myWorkplane; ///< Workplane for the current group - std::vector myParams; ///< List of parameters of the constraints - Slvs_hParam myParamMaxID; ///< Actual maximal ID of parameters - std::vector myEntities; ///< List of entities of the constaints - Slvs_hEntity myEntityMaxID; ///< Actual maximal ID of entities - std::vector myConstraints; ///< List of constraints in SolveSpace format - Slvs_hConstraint myConstrMaxID; ///< Actual maximal ID of constraints - Slvs_System myConstrSet; ///< SolveSpace's set of equations obtained by constraints - std::map, Slvs_Constraint> - myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints + std::shared_ptr findWorkplane( + std::shared_ptr theFeature) const; + + private: + static SketchSolver_ConstraintManager* _self; ///< Self pointer to implement singleton functionality + std::vector myGroups; ///< Groups of constraints + /// true if computation is performed and all "updates" are generated by this algo + /// and needs no recomputation + bool myIsComputed; }; #endif