Salome HOME
Middle point decrease 2 DoF (issue #1625)
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Storage.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_Storage.h
4 // Created: 14 Dec 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef PlaneGCSSolver_Storage_H_
8 #define PlaneGCSSolver_Storage_H_
9
10 #include <PlaneGCSSolver_Defs.h>
11
12 #include <SketchSolver.h>
13 #include <SketchSolver_Storage.h>
14 #include <SketchSolver_ISolver.h>
15
16 /** \class   PlaneGCSSolver_Storage
17  *  \ingroup Plugins
18  *  \brief   Contains all necessary data in PlaneGCS format to solve a single group of constraints
19  */
20 class PlaneGCSSolver_Storage : public SketchSolver_Storage
21 {
22 public:
23   PlaneGCSSolver_Storage(const GroupID& theGroup);
24
25 // =============   Inherited from SketchSolver_Storage   =============
26
27   /// \brief Change mapping between constraint from SketchPlugin and
28   ///        the list of constraints applicable for corresponding solver.
29   ///        Derived here to update point-point coincidence.
30   /// \param theConstraint        [in]   original SketchPlugin constraint
31   /// \param theSolverConstraints [in]   list of solver's constraints
32   virtual void addConstraint(ConstraintPtr                   theConstraint,
33                              std::list<ConstraintWrapperPtr> theSolverConstraints);
34
35   /// \brief Update constraint's data
36   /// \return \c true if any value is updated
37   virtual bool update(ConstraintWrapperPtr theConstraint);
38   /// \brief Update entity's data
39   /// \return \c true if any value is updated
40   virtual bool update(EntityWrapperPtr theEntity);
41   /// \brief Update parameter's data
42   /// \return \c true if the value of parameter is updated
43   virtual bool update(ParameterWrapperPtr theParameter);
44
45   /// \brief Update SketchPlugin features after resolving constraints
46   /// \param theFixedOnly [in]  if \c true the fixed points will be updated only
47   virtual void refresh(bool theFixedOnly = false) const;
48
49   /// \brief Check if some parameters or entities are returned
50   ///        to the current group after removing temporary constraints
51   virtual void verifyFixed();
52
53   /// \brief Mark two points as coincident
54   virtual void addCoincidentPoints(EntityWrapperPtr theMaster, EntityWrapperPtr theSlave);
55
56   /// \brief Shows the storage has the same constraint twice
57   virtual bool hasDuplicatedConstraint() const
58   { return false; }
59
60   /// \brief Calculate point on theBase entity. Value theCoeff is in [0.0 .. 1.0] and
61   ///        shows the distance from the start point.
62   virtual EntityWrapperPtr calculateMiddlePoint(EntityWrapperPtr theBase, double theCoeff);
63
64   /// \brief Initialize solver by constraints, entities and parameters
65   virtual void initializeSolver(SolverPtr theSolver);
66
67 protected:
68   /// \brief Remove constraint
69   /// \return \c true if the constraint and all its parameters are removed successfully
70   virtual bool remove(ConstraintWrapperPtr theConstraint);
71   /// \brief Remove entity
72   /// \return \c true if the entity and all its parameters are removed successfully
73   virtual bool remove(EntityWrapperPtr theEntity);
74   /// \brief Remove parameter
75   /// \return \c true if the parameter has been removed
76   virtual bool remove(ParameterWrapperPtr theParameter);
77
78   /// \brief Update the group for the given entity, its sub-entities and parameters
79   virtual void changeGroup(EntityWrapperPtr theEntity, const GroupID& theGroup);
80   /// \brief Update the group for the given parameter
81   virtual void changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup);
82
83
84 // =============   Own methods   =============
85
86   /// \brief Move parameters of the entity to the constants
87   void makeConstant(const EntityWrapperPtr& theEntity);
88   /// \brief Move parameters of the entity to the variables
89   void makeVariable(const EntityWrapperPtr& theEntity);
90
91 private:
92   /// \brief Move parameters of the entity from the list of variables to the list of constants
93   ///        and vice versa
94   /// \param theEntity [in]  entity to be changed
95   /// \param theFrom   [out] source list
96   /// \param theTo     [out] destination list
97   void toggleEntity(const EntityWrapperPtr& theEntity, GCS::VEC_pD& theFrom, GCS::VEC_pD& theTo);
98
99   /// \brief Create additional constraints for correct processing of arcs
100   /// \param theArc [in]  updated arc
101   void processArc(const EntityWrapperPtr& theArc);
102
103   /// \brief Adjust parameters of points coincident with the given
104   void updateCoincident(const EntityWrapperPtr& thePoint);
105
106   /// \brief Verifies the constraint should not be added into the solver
107   ///
108   /// This is a workaround method to avoid some kinds of conflicting constraints:
109   ///   * symmetric of two points placed on the mirror line (do not add perpendicular constraint)
110   bool isRedundant(GCSConstraintPtr theCheckedConstraint,
111                    ConstraintWrapperPtr theParentConstraint,
112                    std::list<std::set<double*> >& theCoincidentPoints) const;
113
114 private:
115   GCS::VEC_pD                      myParameters;         ///< list of parameters
116   GCS::VEC_pD                      myConst;              ///< list of constants
117   EntityID                         myEntityLastID;       ///< identifier of last added entity
118   ConstraintID                     myConstraintLastID;   ///< identifier of last added constraint
119
120   std::map<EntityWrapperPtr, std::vector<GCSConstraintPtr> >
121                                    myArcConstraintMap;   ///< additional constraints for correct processing of the arcs
122
123   std::list<GCSConstraintPtr>      myRemovedConstraints; ///< list of removed constraints to notify solver
124 };
125
126 #endif