X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Storage.h;h=9e2eae02fbf9f94a4b489bed441941996d744dc9;hb=94b4ebd0def2f4659ee228f419214625f30aa855;hp=70f2622b15190c591fad9b9c7d45d1e23c2a7bd8;hpb=4cbfb073803b0c753a8a31e677a5b786974cf983;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 70f2622b1..9e2eae02f 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -1,134 +1,234 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D // File: SketchSolver_Storage.h -// Created: 18 Mar 2015 +// Created: 30 Nov 2015 // Author: Artem ZHIDKOV #ifndef SketchSolver_Storage_H_ #define SketchSolver_Storage_H_ -#include "SketchSolver.h" -#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +class SketchSolver_ConstraintDistance; +class SketchSolver_ConstraintFixedArcRadius; +typedef std::map > CoincidentPointsMap; -#include -#include -#include /** \class SketchSolver_Storage * \ingroup Plugins - * \brief Contains all necessary data in SolveSpace format to solve a single group of constraints + * \brief Interface to map SketchPlugin features to the entities of corresponding solver. */ class SketchSolver_Storage { -public: +private: SketchSolver_Storage(); + SketchSolver_Storage(const SketchSolver_Storage&); + SketchSolver_Storage& operator=(const SketchSolver_Storage&); - /** \brief Add new parameter to the current group - * \param[in] theParam SolveSpace parameter - * \return the ID of added parameter - */ - Slvs_hParam addParameter(const Slvs_Param& theParam); - /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added - * \param[in] theParam SolveSpace parameter - * \return the ID of updated/added parameter - */ - Slvs_hParam updateParameter(const Slvs_Param& theParam); - /** \brief Removes the parameter by its ID - * \param[in] theParamID index of parameter to be removed - * \return \c true if the parameter was successfully removed - */ - bool removeParameter(const Slvs_hParam& theParamID); - /// \brief Returns the parameter by its ID - const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const; - - /** \brief Add new entity to the current group - * \param[in] theEntity SolveSpace entity - * \return the ID of added entity - */ - Slvs_hEntity addEntity(const Slvs_Entity& theEntity); - /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added - * \param[in] theEntity SolveSpace entity - * \return the ID of updated/added entity - */ - Slvs_hEntity updateEntity(const Slvs_Entity& theEntity); - /** \brief Removes the entity by its ID. All parameters used in this entity, - * and not used in other constraints, will be removed too. - * \param[in] theEntityID index of entity to be removed - * \return \c true if the entity was successfully removed - */ - bool removeEntity(const Slvs_hEntity& theEntityID); - /// \brief Returns the entity by its ID - const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const; - - /// \brief Verifies the current point or another coincident one is fixed - /// \return the ID of the Fixed constraint or SLVS_E_UNKNOWN - Slvs_hConstraint isPointFixed(const Slvs_hEntity& thePointID) const; - - /** \brief Add new constraint to the current group - * \param[in] theConstraint SolveSpace's constraint - * \return the ID of added constraint - */ - Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint); - /** \brief Updates constraint in the current group. - * If the ID of constraint is zero, the new item will be added - * \param[in] theConstraint SolveSpace constraint - * \return the ID of updated/added constraint - */ - Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint); - /** \brief Removes the constraint by its ID. All entities and parameters depending on this - * constraint, which are not used in other constraints, will be removed too. - * \param[in] theConstraintID index of constraint to be removed - * \return \c true if the constraint was successfully removed - */ - bool removeConstraint(const Slvs_hConstraint& theConstraintID); - /// \brief Returns the constraint by its ID - const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const; - - /// \brief Attach temporary constraint to this storage. It need to make precise calculations - void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID); +public: + SketchSolver_Storage(const GroupID& theGroup) + : myGroupID(theGroup), + mySketchID(EID_UNKNOWN), + myNeedToResolve(false), + myEventsBlocked(false), + myExistArc(false) + {} + + /// \brief Change mapping between constraint from SketchPlugin and + /// a constraint applicable for corresponding solver. + /// \param theConstraint [in] original SketchPlugin constraint + /// \param theSolverConstraint [in] solver's constraints + SKETCHSOLVER_EXPORT void addConstraint(ConstraintPtr theConstraint, + ConstraintWrapperPtr theSolverConstraints); + /// \brief Change mapping between constraint from SketchPlugin and + /// the list of constraints applicable for corresponding solver. + /// \param theConstraint [in] original SketchPlugin constraint + /// \param theSolverConstraints [in] list of solver's constraints + SKETCHSOLVER_EXPORT virtual + void addConstraint(ConstraintPtr theConstraint, + std::list theSolverConstraints); + + /// \brief Convert feature to the form applicable for specific solver and map it + /// \param theFeature [in] feature to convert + /// \param theGroup [in] id of the group where the feature should be placed + /// \return \c true if the feature has been created or updated + SKETCHSOLVER_EXPORT bool update(FeaturePtr theFeature, const GroupID& theGroup = GID_UNKNOWN); + /// \brief Convert attribute to the form applicable for specific solver and map it + /// \param theFeature [in] feature to convert + /// \return \c true if the attribute has been created or updated + SKETCHSOLVER_EXPORT bool update(AttributePtr theAttribute, const GroupID& theGroup = GID_UNKNOWN); + + /// \brief Returns constraint related to corresponding constraint + SKETCHSOLVER_EXPORT + const std::list& constraint(const ConstraintPtr& theConstraint) const; + + /// \brief Returns entity related to corresponding feature + SKETCHSOLVER_EXPORT const EntityWrapperPtr& entity(const FeaturePtr& theFeature) const; + /// \brief Returns entity related to corresponding attribute + SKETCHSOLVER_EXPORT const EntityWrapperPtr& entity(const AttributePtr& theAttribute) const; + + /// \brief Return parsed sketch entity + const EntityWrapperPtr& sketch() const; + /// \brief Set parsed sketch entity. + /// Be careful, this method does not update fields of the storage specific for the solver. + /// Does not update if the sketch already exists. + void setSketch(const EntityWrapperPtr& theSketch); + + /// \brief Mark two points as coincident + virtual void addCoincidentPoints(EntityWrapperPtr theMaster, EntityWrapperPtr theSlave) = 0; + + /// \brief Shows the storage has any constraint twice + virtual bool hasDuplicatedConstraint() const = 0; + + /// \brief Removes constraint from the storage + /// \return \c true if the constraint and all its parameters are removed successfully + SKETCHSOLVER_EXPORT bool removeConstraint(ConstraintPtr theConstraint); + /// \brief Removes feature from the storage + /// \return \c true if the feature and its attributes are removed successfully; + /// \c false if the feature or any it attribute is used by remaining constraints. + SKETCHSOLVER_EXPORT bool removeEntity(FeaturePtr theFeature); + /// \brief Removes attribute from the storage + /// \return \c true if the attribute is not used by remaining features and constraints + SKETCHSOLVER_EXPORT bool removeEntity(AttributePtr theAttribute); + + /// \brief Remove all features became invalid + SKETCHSOLVER_EXPORT void removeInvalidEntities(); + + /// \brief Check whether the feature or its attributes are used by this storage + /// \param theFeature [in] feature to be checked + /// \return \c true if the feature interacts with the storage + bool isInteract(const FeaturePtr& theFeature) const; + /// \brief Check whether the attribute is used by this storage + /// \param theAttribute [in] attribute to be checked + /// \return \c true if the attribute interacts with the storage + bool isInteract(const AttributePtr& theAttribute) const; + + /// \brief Check the features is not removed + bool isConsistent() const; + + /// \brief Check the storage has constraints + bool isEmpty() const + { return myConstraintMap.empty(); } + + /// \brief Check the entity is fixed. + /// If the point is under verification, all coincident points are checked too. + SKETCHSOLVER_EXPORT bool isFixed(EntityWrapperPtr theEntity) const; /// \brief Shows the sketch should be resolved - bool isNeedToResolve() const + virtual bool isNeedToResolve() { return myNeedToResolve; } - /// \brief Changes the flag of group to be resolved void setNeedToResolve(bool theFlag) { myNeedToResolve = theFlag; } - /// \brief Returns lists of removed elements - void getRemoved(std::set& theParameters, - std::set& theEntities, - std::set& theConstraints); - - /// \brief Initialize constraint solver by the entities collected by current storage - void initializeSolver(SketchSolver_Solver& theSolver); + /// \brief Initialize solver by constraints, entities and parameters + virtual void initializeSolver(SolverPtr theSolver) = 0; + /// \brief Return list of conflicting constraints + std::set getConflictingConstraints(SolverPtr theSolver) const; + + /// \brief Update SketchPlugin features after resolving constraints + /// \param theFixedOnly [in] if \c true the fixed points will be updated only + virtual void refresh(bool theFixedOnly = false) const = 0; + + /// \brief Check if some parameters or entities are returned + /// to the current group after removing temporary constraints + virtual void verifyFixed() = 0; + + /// \brief Calculate point on theBase entity. Value theCoeff is in [0.0 .. 1.0] and + /// shows the distance from the start point. + virtual EntityWrapperPtr calculateMiddlePoint(EntityWrapperPtr theBase, + double theCoeff) = 0; + + /// \brief Block or unblock events when refreshing features + SKETCHSOLVER_EXPORT void blockEvents(bool isBlocked); + /// \brief Shows the events are blocked for the features in the storage + bool isEventsBlocked() const + { return myEventsBlocked; } + +protected: + /// \brief Change mapping feature from SketchPlugin and + /// the entity applicable for corresponding solver. + /// \param theFeature [in] original SketchPlugin feature + /// \param theSolverEntity [in] solver's entity, created outside + SKETCHSOLVER_EXPORT + void addEntity(FeaturePtr theFeature, + EntityWrapperPtr theSolverEntity); + + /// \brief Change mapping attribute of a feature and the entity applicable for corresponding solver. + /// \param theAttribute [in] original attribute + /// \param theSolverEntity [in] solver's entity, created outside + SKETCHSOLVER_EXPORT + void addEntity(AttributePtr theAttribute, + EntityWrapperPtr theSolverEntity); + + /// \brief Update constraint's data + /// \return \c true if any value is updated + virtual bool update(ConstraintWrapperPtr theConstraint) = 0; + /// \brief Update entity's data + /// \return \c true if any value is updated + virtual bool update(EntityWrapperPtr theEntity) = 0; + /// \brief Update parameter's data + /// \return \c true if the value of parameter is updated + virtual bool update(ParameterWrapperPtr theParameter) = 0; + + /// \brief Remove constraint + /// \return \c true if the constraint and all its parameters are removed successfully + SKETCHSOLVER_EXPORT virtual bool remove(ConstraintWrapperPtr theConstraint); + /// \brief Remove entity + /// \return \c true if the entity and all its parameters are removed successfully + SKETCHSOLVER_EXPORT virtual bool remove(EntityWrapperPtr theEntity); + /// \brief Remove parameter + /// \return \c true if the parameter has been removed + virtual bool remove(ParameterWrapperPtr theParameter) = 0; + + /// \brief Remove point-point coincidence + SKETCHSOLVER_EXPORT bool removeCoincidence(ConstraintWrapperPtr theConstraint); + + /// \brief Update the group for the given entity, its sub-entities and parameters + virtual void changeGroup(EntityWrapperPtr theEntity, const GroupID& theGroup) = 0; + /// \brief Update the group for the given parameter + virtual void changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup) = 0; + + /// \brief Verify the feature or any its attribute is used by constraint + SKETCHSOLVER_EXPORT bool isUsed(FeaturePtr theFeature) const; + /// \brief Verify the attribute is used by constraint + SKETCHSOLVER_EXPORT bool isUsed(AttributePtr theAttirubute) const; + + /// \brief Find arcs without corresponding entity applicable for the solver and build them + SKETCHSOLVER_EXPORT void processArcs(); private: - /// \brief Store coincident points - void addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2); - /// \brief Remove point from lists of coincidence - void removeCoincidentPoint(const Slvs_hEntity& thePoint); - -public: - /// \brief Check two points are coincident - bool isCoincident(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const; - -private: - Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters) - std::vector myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier) - Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities) - std::vector myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier) - Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints) - std::vector myConstraints; ///< list of constraints used in the current group (sorted by the identifier) - - std::vector< std::set > myCoincidentPoints; ///< lists of coincident points - Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point - - bool myNeedToResolve; ///< parameters are changed and group needs to be resolved - - std::set myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant) - std::set myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant) - std::set myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant) + /// \brief Find the normal of the sketch + EntityWrapperPtr getNormal() const; + +protected: + EntityID mySketchID; ///< identifier of the sketch + GroupID myGroupID; ///< identifier of the group, this storage belongs to + bool myNeedToResolve; ///< parameters are changed and group needs to be resolved + bool myEventsBlocked; ///< indicates that features do not send events + bool myExistArc; ///< the storage has any point of arc but not full arc, need to add it + + /// map SketchPlugin constraint to a list of solver's constraints + std::map > myConstraintMap; + /// map SketchPlugin feature to solver's entity + std::map myFeatureMap; + /// map attribute to solver's entity + std::map myAttributeMap; + + CoincidentPointsMap myCoincidentPoints; ///< lists of coincident points (first is a master point, second is a set of slaves) + + // to be able to update entities from constraints + friend class SketchSolver_ConstraintDistance; + friend class SketchSolver_ConstraintFixedArcRadius; }; typedef std::shared_ptr StoragePtr;