Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / SketchSolver / SketchSolver_Storage.h
index ee27e9d14b91b80bf4900a73941e33b92f036d01..6a1b1b2e817354138c24e4c018869c10a66ff6bf 100644 (file)
 #include <ModelAPI_Feature.h>
 #include <SketchPlugin_Constraint.h>
 
+class SketchSolver_ConstraintDistance;
+class SketchSolver_ConstraintFixedArcRadius;
 typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
 
+
 /** \class   SketchSolver_Storage
  *  \ingroup Plugins
  *  \brief   Interface to map SketchPlugin features to the entities of corresponding solver.
@@ -34,7 +37,10 @@ private:
 public:
   SketchSolver_Storage(const GroupID& theGroup)
     : myGroupID(theGroup),
-      myNeedToResolve(false)
+      mySketchID(EID_UNKNOWN),
+      myNeedToResolve(false),
+      myEventsBlocked(false),
+      myExistArc(false)
   {}
 
   /// \brief Change mapping between constraint from SketchPlugin and
@@ -47,19 +53,25 @@ public:
   ///        the list of constraints applicable for corresponding solver.
   /// \param theConstraint        [in]   original SketchPlugin constraint
   /// \param theSolverConstraints [in]   list of solver's constraints
-  SKETCHSOLVER_EXPORT
+  SKETCHSOLVER_EXPORT virtual
     void addConstraint(ConstraintPtr                   theConstraint,
                        std::list<ConstraintWrapperPtr> 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
+  /// \param theForce   [in]  forced feature creation
   /// \return \c true if the feature has been created or updated
-  SKETCHSOLVER_EXPORT bool update(FeaturePtr theFeature, const GroupID& theGroup = GID_UNKNOWN);
+  SKETCHSOLVER_EXPORT bool update(FeaturePtr theFeature, 
+                                  const GroupID& theGroup = GID_UNKNOWN, bool theForce = false);
+
   /// \brief Convert attribute to the form applicable for specific solver and map it
-  /// \param theFeature [in]  feature to convert
+  /// \param theAttribute [in]  attribute to convert
+  /// \param theGroup     [in]  id of the group where the feature should be placed
+  /// \param theForce     [in]  forced feature creation
   /// \return \c true if the attribute has been created or updated
-  SKETCHSOLVER_EXPORT bool update(AttributePtr theAttribute, const GroupID& theGroup = GID_UNKNOWN);
+  SKETCHSOLVER_EXPORT bool update(AttributePtr theAttribute, 
+                                  const GroupID& theGroup = GID_UNKNOWN, bool theForce = false);
 
   /// \brief Returns constraint related to corresponding constraint
   SKETCHSOLVER_EXPORT
@@ -85,27 +97,18 @@ public:
 
   /// \brief Removes constraint from the storage
   /// \return \c true if the constraint and all its parameters are removed successfully
-  virtual bool removeConstraint(ConstraintPtr theConstraint) = 0;
+  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.
-  virtual bool removeEntity(FeaturePtr theFeature) = 0;
+  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
-  virtual bool removeEntity(AttributePtr theAttribute) = 0;
+  SKETCHSOLVER_EXPORT bool removeEntity(AttributePtr theAttribute);
 
   /// \brief Remove all features became invalid
   SKETCHSOLVER_EXPORT void removeInvalidEntities();
 
-  /// \brief Mark specified constraint as temporary
-  virtual void setTemporary(ConstraintPtr theConstraint) = 0;
-  /// \brief Returns number of temporary constraints
-  virtual size_t nbTemporary() const = 0;
-  /// \brief Remove temporary constraints
-  /// \param theNbConstraints [in]  number of temporary constraints to be deleted
-  /// \return number of remaining temporary constraints
-  virtual size_t removeTemporary(size_t theNbConstraints = 1) = 0;
-
   /// \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
@@ -118,9 +121,13 @@ public:
   /// \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.
-  bool isFixed(EntityWrapperPtr theEntity) const;
+  SKETCHSOLVER_EXPORT bool isFixed(EntityWrapperPtr theEntity) const;
 
   /// \brief Shows the sketch should be resolved
   virtual bool isNeedToResolve()
@@ -131,6 +138,8 @@ public:
 
   /// \brief Initialize solver by constraints, entities and parameters
   virtual void initializeSolver(SolverPtr theSolver) = 0;
+  /// \brief Return list of conflicting constraints
+  std::set<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;
 
   /// \brief Update SketchPlugin features after resolving constraints
   /// \param theFixedOnly [in]  if \c true the fixed points will be updated only
@@ -145,6 +154,12 @@ public:
   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.
@@ -154,7 +169,8 @@ protected:
     void addEntity(FeaturePtr       theFeature,
                    EntityWrapperPtr theSolverEntity);
 
-  /// \brief Change mapping attribute of a feature and the entity applicable for corresponding solver.
+  /// \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
@@ -163,39 +179,53 @@ protected:
 
   /// \brief Update constraint's data
   /// \return \c true if any value is updated
-  virtual bool update(ConstraintWrapperPtr& theConstraint) = 0;
+  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;
+  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;
+  virtual bool update(ParameterWrapperPtr theParameter) = 0;
 
   /// \brief Remove constraint
   /// \return \c true if the constraint and all its parameters are removed successfully
-  virtual bool remove(ConstraintWrapperPtr theConstraint) = 0;
+  SKETCHSOLVER_EXPORT virtual bool remove(ConstraintWrapperPtr theConstraint);
   /// \brief Remove entity
   /// \return \c true if the entity and all its parameters are removed successfully
-  virtual bool remove(EntityWrapperPtr theEntity) = 0;
+  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 Block or unblock events when refreshing features
-  SKETCHSOLVER_EXPORT void blockEvents(bool isBlocked) const;
+  /// \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();
+
+  /// \brief Replace entities by others
+  void replaceEntities(const std::map<EntityWrapperPtr, EntityWrapperPtr>& theChange);
 
 private:
   /// \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<ConstraintPtr, std::list<ConstraintWrapperPtr> > myConstraintMap;
@@ -204,7 +234,12 @@ protected:
   /// map attribute to solver's entity
   std::map<AttributePtr, EntityWrapperPtr>                  myAttributeMap;
 
-  CoincidentPointsMap myCoincidentPoints; ///< lists of coincident points (first is a master point, second is a set of slaves)
+  /// lists of coincident points (first is a master point, second is a set of slaves)
+  CoincidentPointsMap myCoincidentPoints; 
+
+  // to be able to update entities from constraints
+  friend class SketchSolver_ConstraintDistance;
+  friend class SketchSolver_ConstraintFixedArcRadius;
 };
 
 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;