Salome HOME
558756492fa68c7406ad86e8ab59d57bf65dd04b
[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 Verifies the entities are not coincident yet
47   /// \return \c true if the entities does not coincident
48   bool checkCoincidence(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     /// Check the coincidence is not in list yet
67     bool isNewCoincidence(const EntityWrapperPtr& theEntityExist,
68                           const EntityWrapperPtr& theOtherEntity);
69     bool isNewCoincidence(const EntityWrapperPtr& theEntityExist,
70                           const CoincidentEntities& theOtherGroup,
71                           const EntityWrapperPtr& theEntityInOtherGroup);
72
73   private:
74     bool hasExternal() const;
75
76   private:
77     /// external entity and set of entities connected to it
78     std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > myExternalAndConnected;
79   };
80
81   std::list<CoincidentEntities> myCoincident; ///< list of coincidences
82 };
83
84 #endif