Salome HOME
Issues #2150 and #2151: Frequently appeared "Conflicting constraints" message for...
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_UpdateCoincidence.h
1 // Copyright (C) 2017-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_UpdateCoincidence.h
4 // Created: 17 Feb 2017
5 // Author:  Artem ZHIDKOV
6
7 #ifndef PlaneGCSSolver_UpdateCoincidence_H_
8 #define PlaneGCSSolver_UpdateCoincidence_H_
9
10 #include <PlaneGCSSolver_Update.h>
11 #include <PlaneGCSSolver_EntityWrapper.h>
12
13 #include <GCS.h>
14
15 #include <map>
16
17 /** \class   PlaneGCSSolver_UpdateCoincidence
18  *  \ingroup Plugins
19  *  \brief   Send events to listeners about changing a constraint
20  */
21 class PlaneGCSSolver_UpdateCoincidence : public PlaneGCSSolver_Update
22 {
23 public:
24   PlaneGCSSolver_UpdateCoincidence(UpdaterPtr theNext = UpdaterPtr())
25     : PlaneGCSSolver_Update(theNext)
26   {}
27
28   virtual ~PlaneGCSSolver_UpdateCoincidence() {}
29
30   /// \brief Group of entities, processed by this kind of updater
31   static const std::string& GROUP()
32   {
33     static const std::string TYPE("Coincidence");
34     return TYPE;
35   }
36
37   /// \brief Attach listener
38   /// \param theObserver [in]  object which want to receive notifications
39   /// \param theType     [in]  receive notifications about changing objects
40   ///                          of theType and their derivatives
41   virtual void attach(SketchSolver_Constraint* theObserver, const std::string& theType);
42
43   /// \brief Send notification about update of the feature to all interested
44   virtual void update(const FeaturePtr& theFeature);
45
46   /// \brief Set coincidence between two given entities
47   /// \return \c true if the entities does not coincident yet
48   bool addCoincidence(const EntityWrapperPtr& theEntity1, const EntityWrapperPtr& theEntity2);
49
50   /// \brief Verifies the point is coincident to the feature
51   /// \return \c true if the point is on the feature
52   bool isPointOnEntity(const EntityWrapperPtr& thePoint, const EntityWrapperPtr& theEntity);
53
54 private:
55   /// \brief Container for collecting and operating coincident entities
56   class CoincidentEntities
57   {
58   public:
59     CoincidentEntities(const EntityWrapperPtr& theEntity1,
60                        const EntityWrapperPtr& theEntity2);
61
62     /// Verify the entity is already in the list
63     bool isExist(const EntityWrapperPtr& theEntity) const;
64     /// Verify the point is already in the list
65     bool isExist(const GCS::Point& thePoint) const;
66
67     /// Add entity to group
68     bool add(const EntityWrapperPtr& theEntity);
69
70     /// Remove entity from group
71     void remove(const EntityWrapperPtr& theEntity);
72
73     /// Merge two groups
74     void merge(const CoincidentEntities& theOther);
75
76   private:
77     std::set<EntityWrapperPtr> myPoints; ///< coincident points
78     std::set<EntityWrapperPtr> myExternalPoints; //< external points coincident to other points
79     std::set<EntityWrapperPtr> myFeatures; ///< other entities containing points
80   };
81
82   /// \brief Search the group of coincidences containing given entity.
83   ///        Searches points only.
84   std::list<CoincidentEntities>::iterator findGroupOfCoincidence(const EntityWrapperPtr& theEntity);
85
86   /// \brief Add entity to group of coincidences
87   /// \reutrn \c true if the entity is added, thus the coincidence is new
88   bool addToGroupOfCoincidence(CoincidentEntities& theGroup, const EntityWrapperPtr& theEntity);
89
90 private:
91   std::list<CoincidentEntities> myCoincident; ///< list of coincidences
92 };
93
94 #endif