X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintGroup.h;h=c8a673029e2ce047589e971d17e7cdb2b132dd70;hb=24f1ad2fd93475684288c899fb4fffcf05f6c21e;hp=d182233a571c9695a01311fb0999e0c18d6f276d;hpb=beb7b62b44875845bc640e1d9ccde5ea15ee1a2a;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.h b/src/SketchSolver/SketchSolver_ConstraintGroup.h index d182233a5..c8a673029 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.h +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.h @@ -2,19 +2,22 @@ // Created: 27 May 2014 // Author: Artem ZHIDKOV -#ifndef SketchSolver_ConstraintGroup_Headerfile -#define SketchSolver_ConstraintGroup_Headerfile +#ifndef SketchSolver_ConstraintGroup_H_ +#define SketchSolver_ConstraintGroup_H_ #include "SketchSolver.h" #include #include +#include #include #include #include #include +typedef std::map< boost::shared_ptr, std::vector > + ConstraintMap; /** \class SketchSolver_ConstraintGroup * \ingroup DataModel @@ -22,43 +25,56 @@ */ class SketchSolver_ConstraintGroup { -public: + public: /** \brief New group based on specified workplane. * Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type * \remark Type of theSketch is not verified inside */ - SketchSolver_ConstraintGroup(boost::shared_ptr theWorkplane); + SketchSolver_ConstraintGroup(boost::shared_ptr theWorkplane); ~SketchSolver_ConstraintGroup(); /// \brief Returns group's unique identifier inline const Slvs_hGroup& getId() const - {return myID;} + { + return myID; + } /// \brief Returns true if the group has no constraints yet inline bool isEmpty() const - {return myConstraints.empty();} + { + return myConstraints.empty(); + } + + /// \brief Check for valid sketch data + inline bool isWorkplaneValid() const + { + return mySketch->data() && mySketch->data()->isValid(); + } /** \brief Adds or updates a constraint in the group * \param[in] theConstraint constraint to be changed * \return \c true if the constraint added or updated successfully */ bool changeConstraint(boost::shared_ptr theConstraint); + bool changeRigidConstraint(boost::shared_ptr theConstraint); - /** \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 Verifies the feature attributes are used in this group + * \param[in] theFeature constraint or any other object for verification of interaction + * \return \c true if some of attributes are used in current group */ - bool isInteract(boost::shared_ptr theConstraint) const; + bool isInteract(boost::shared_ptr theFeature) const; /** \brief Verifies the specified feature is equal to the base workplane for this group * \param[in] theWorkplane the feature to be compared with base workplane * \return \c true if workplanes are the same */ - bool isBaseWorkplane(boost::shared_ptr theWorkplane) const; + bool isBaseWorkplane(boost::shared_ptr theWorkplane) const; - boost::shared_ptr getWorkplane() const - { return mySketch; } + boost::shared_ptr getWorkplane() const + { + return mySketch; + } /** \brief Update parameters of workplane. Should be called when Update event is coming. * \return \c true if workplane updated successfully, \c false if workplane parameters are not consistent @@ -71,7 +87,7 @@ public: void updateEntityIfPossible(boost::shared_ptr theEntity); /** \brief Searches invalid features and constraints in the group and avoids them - * \return \c true if the group's sketch is invalid and the group should be removed + * \return \c true if the group several constraints were removed */ bool updateGroup(); @@ -80,11 +96,22 @@ public: */ void mergeGroups(const SketchSolver_ConstraintGroup& theGroup); + /** \brief Cut from the group several subgroups, which are not connected to the current one by any constraint + * \param[out] theCuts enlarge this list by newly created groups + */ + void splitGroup(std::vector& theCuts); + /** \brief Start solution procedure if necessary and update attributes of features + * \return \c false when no need to solve constraints */ - void resolveConstraints(); + bool resolveConstraints(); + + /** \brief Searches the constraints built on the entity and emit the signal to update them + * \param[in] theEntity attribute of the constraint + */ + void updateRelatedConstraints(boost::shared_ptr theEntity) const; + void updateRelatedConstraints(boost::shared_ptr theFeature) const; -protected: /** \brief Adds or updates an entity in the group * * The parameters of entity will be parsed and added to the list of SolveSpace parameters. @@ -94,7 +121,9 @@ protected: * \return identifier of changed entity or 0 if entity could not be changed */ Slvs_hEntity changeEntity(boost::shared_ptr theEntity); + Slvs_hEntity changeEntity(FeaturePtr theEntity); +protected: /** \brief Adds or updates a normal in the group * * Normal is a special entity in SolveSpace, which defines a direction in 3D and @@ -121,57 +150,89 @@ protected: Slvs_hParam changeParameter(const double& theParam, std::vector::const_iterator& thePrmIter); + /** \brief Removes specified entities and their parameters + * \param[in] theEntities list of IDs of the entities to be removed + */ + void removeEntitiesById(const std::set& theEntities); + + /** \brief Removes constraints from the group + * \param[in] theConstraint constraint to be removed + */ + void removeConstraint(boost::shared_ptr theConstraint); + /** \brief Change values of attribute by parameters received from SolveSpace solver * \param[in,out] theAttribute pointer to the attribute to be changed * \param[in] theEntityID identifier of SolveSpace entity, which contains updated data + * \return \c true if the attribute's value has changed */ - void updateAttribute(boost::shared_ptr theAttribute, const Slvs_hEntity& theEntityID); + bool updateAttribute(boost::shared_ptr theAttribute, + const Slvs_hEntity& theEntityID); /** \brief Adds a constraint for a point which should not be changed during computations - * \param[in] theEntity the base for the constraint + * \param[in] theEntity the base for the constraint + * \param[in] theAllowToFit this flag shows that the entity may be placed into + * the 'dragged' field of SolveSpace solver, so this entity + * may be changed a little during solution */ - void addTemporaryConstraintWhereDragged(boost::shared_ptr theEntity); + void addTemporaryConstraintWhereDragged(boost::shared_ptr theEntity, + bool theAllowToFit = true); /** \brief Remove all temporary constraint after computation finished + * \param[in] theRemoved indexes of constraints to be removed. If empty, all temporary constraints should be deleted */ - void removeTemporaryConstraints(); + void removeTemporaryConstraints(const std::set& theRemoved = + std::set()); -private: + private: /** \brief Creates a workplane from the sketch parameters * \param[in] theSketch parameters of workplane are the attributes of this sketch * \return \c true if success, \c false if workplane parameters are not consistent */ - bool addWorkplane(boost::shared_ptr theSketch); + bool addWorkplane(boost::shared_ptr theSketch); + + /** \brief Add the entities of constraint for points coincidence into the appropriate list + * \param[in] thePoint1 identifier of the first point + * \param[in] thePoint2 identifier of the second point + * \return \c true if the points are added successfully, and + * \c false if the constraint is the extra one (should not be created in SolveSpace) + */ + bool addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2); + + /** \brief Verifies and changes parameters of constriant, + * e.g. sign of the distance between line and point + * \param[in,out] theConstraint SolveSpace constraint to be verified + */ + void checkConstraintConsistence(Slvs_Constraint& theConstraint); -private: + private: // SolveSpace entities - 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 (not equal to myParams size) - std::vector myEntities; ///< List of entities of the constaints - Slvs_hEntity myEntityMaxID; ///< Actual maximal ID of entities (not equal to myEntities size) + 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 (not equal to myParams size) + std::vector myEntities; ///< List of entities of the constaints + std::vector myEntOfConstr; ///< Flags show that certain entity used in constraints + Slvs_hEntity myEntityMaxID; ///< Actual maximal ID of entities (not equal to myEntities size) std::vector myConstraints; ///< List of constraints in SolveSpace format - Slvs_hConstraint myConstrMaxID; ///< Actual maximal ID of constraints (not equal to myConstraints size) - bool myNeedToSolve; ///< Indicator that something changed in the group and constraint system need to be rebuilt - - SketchSolver_Solver myConstrSolver; ///< Solver for set of equations obtained by constraints + Slvs_hConstraint myConstrMaxID; ///< Actual maximal ID of constraints (not equal to myConstraints size) + bool myNeedToSolve; ///< Indicator that something changed in the group and constraint system need to be rebuilt - std::vector myTempPointWhereDragged; ///< Parameters of one of the points which is moved by user - Slvs_hEntity myTempPointWDrgdID; ///< Identifier of such point - std::list myTempConstraints; ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user - // NOTE: First ID in the list corresponds to myTempPointWhereDragged parameters and does not added to myConstraints list + SketchSolver_Solver myConstrSolver; ///< Solver for set of equations obtained by constraints - std::vector< std::set > - myCoincidentPoints; ///< Stores the lists of identifiers of coincident points (to avoid unnecessary coincidence constraints) + std::vector myTempPointWhereDragged; ///< Parameters of one of the points which is moved by user + Slvs_hEntity myTempPointWDrgdID; ///< Identifier of such point + std::list myTempConstraints; ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user // SketchPlugin entities - boost::shared_ptr - mySketch; ///< Equivalent to workplane - std::map, Slvs_hConstraint> - myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints - std::map, Slvs_hEntity> - myEntityMap; ///< The map between parameters of constraints and their equivalent SolveSpace entities + boost::shared_ptr mySketch; ///< Equivalent to workplane + ConstraintMap myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints + std::map, Slvs_hEntity> myEntityAttrMap; ///< The map between "attribute" parameters of constraints and their equivalent SolveSpace entities + std::map myEntityFeatMap; ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities + + // Conincident items + std::vector > myCoincidentPoints; ///< Stores the lists of identifiers of coincident points (to avoid unnecessary coincidence constraints) + std::set > myExtraCoincidence; ///< Additional coincidence constraints which are not necessary (coincidence between points already done + ///< by other constraints) but created by GUI tools. Useful when some coincidence constraints were removed }; #endif