Salome HOME
c945b87d5f831d6dfb1792acd3c965eb5b9b076a
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_UpdateCoincidence.h
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef PlaneGCSSolver_UpdateCoincidence_H_
21 #define PlaneGCSSolver_UpdateCoincidence_H_
22
23 #include <PlaneGCSSolver_Update.h>
24 #include <PlaneGCSSolver_EntityWrapper.h>
25
26 #include <GCS.h>
27
28 #include <map>
29
30 /** \class   PlaneGCSSolver_UpdateCoincidence
31  *  \ingroup Plugins
32  *  \brief   Send events to listeners about changing a constraint
33  */
34 class PlaneGCSSolver_UpdateCoincidence : public PlaneGCSSolver_Update
35 {
36 public:
37   PlaneGCSSolver_UpdateCoincidence(UpdaterPtr theNext = UpdaterPtr())
38     : PlaneGCSSolver_Update(theNext)
39   {}
40
41   virtual ~PlaneGCSSolver_UpdateCoincidence() {}
42
43   /// \brief Group of entities, processed by this kind of updater
44   static const std::string& GROUP()
45   {
46     static const std::string TYPE("Coincidence");
47     return TYPE;
48   }
49
50   /// \brief Attach listener
51   /// \param theObserver [in]  object which want to receive notifications
52   /// \param theType     [in]  receive notifications about changing objects
53   ///                          of theType and their derivatives
54   virtual void attach(SketchSolver_Constraint* theObserver, const std::string& theType);
55
56   /// \brief Send notification about update of the feature to all interested
57   virtual void update(const FeaturePtr& theFeature);
58
59   /// \brief Set coincidence between two given entities
60   /// \return \c true if the entities does not coincident yet
61   bool addCoincidence(const EntityWrapperPtr& theEntity1, const EntityWrapperPtr& theEntity2);
62
63   /// \brief Verifies the point is coincident to the feature
64   /// \return \c true if the point is on the feature
65   bool isPointOnEntity(const EntityWrapperPtr& thePoint, const EntityWrapperPtr& theEntity);
66
67 private:
68   /// \brief Container for collecting and operating coincident entities
69   class CoincidentEntities
70   {
71   public:
72     CoincidentEntities(const EntityWrapperPtr& theEntity1,
73                        const EntityWrapperPtr& theEntity2);
74
75     /// Verify the entity is already in the list
76     bool isExist(const EntityWrapperPtr& theEntity) const;
77     /// Verify the point is already in the list
78     bool isExist(const GCS::Point& thePoint) const;
79
80     /// Add entity to group
81     bool add(const EntityWrapperPtr& theEntity);
82
83     /// Remove entity from group
84     void remove(const EntityWrapperPtr& theEntity);
85
86     /// Merge two groups
87     void merge(const CoincidentEntities& theOther);
88
89     /// Returns any of external points
90     EntityWrapperPtr externalPoint() const;
91
92   private:
93     std::set<EntityWrapperPtr> myPoints; ///< coincident points
94     std::set<EntityWrapperPtr> myExternalPoints; //< external points coincident to other points
95     std::set<EntityWrapperPtr> myFeatures; ///< other entities containing points
96   };
97
98   /// \brief Search the group of coincidences containing given entity.
99   ///        Searches points only.
100   std::list<CoincidentEntities>::iterator findGroupOfCoincidence(const EntityWrapperPtr& theEntity);
101
102   /// \brief Add entity to group of coincidences
103   /// \reutrn \c true if the entity is added, thus the coincidence is new
104   bool addToGroupOfCoincidence(CoincidentEntities& theGroup, const EntityWrapperPtr& theEntity);
105
106 private:
107   std::list<CoincidentEntities> myCoincident; ///< list of coincidences
108 };
109
110 #endif