Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_UpdateCoincidence.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef PlaneGCSSolver_UpdateCoincidence_H_
22 #define PlaneGCSSolver_UpdateCoincidence_H_
23
24 #include <PlaneGCSSolver_Update.h>
25 #include <PlaneGCSSolver_EntityWrapper.h>
26
27 #include <GCS.h>
28
29 #include <map>
30
31 /** \class   PlaneGCSSolver_UpdateCoincidence
32  *  \ingroup Plugins
33  *  \brief   Send events to listeners about changing a constraint
34  */
35 class PlaneGCSSolver_UpdateCoincidence : public PlaneGCSSolver_Update
36 {
37 public:
38   PlaneGCSSolver_UpdateCoincidence(UpdaterPtr theNext = UpdaterPtr())
39     : PlaneGCSSolver_Update(theNext)
40   {}
41
42   virtual ~PlaneGCSSolver_UpdateCoincidence() {}
43
44   /// \brief Group of entities, processed by this kind of updater
45   static const std::string& GROUP()
46   {
47     static const std::string TYPE("Coincidence");
48     return TYPE;
49   }
50
51   /// \brief Attach listener
52   /// \param theObserver [in]  object which want to receive notifications
53   /// \param theType     [in]  receive notifications about changing objects
54   ///                          of theType and their derivatives
55   virtual void attach(SketchSolver_Constraint* theObserver, const std::string& theType);
56
57   /// \brief Send notification about update of the feature to all interested
58   virtual void update(const FeaturePtr& theFeature);
59
60   /// \brief Set coincidence between two given entities
61   /// \return \c true if the entities does not coincident yet
62   bool addCoincidence(const EntityWrapperPtr& theEntity1, const EntityWrapperPtr& theEntity2);
63
64   /// \brief Verifies the point is coincident to the feature
65   /// \return \c true if the point is on the feature
66   bool isPointOnEntity(const EntityWrapperPtr& thePoint, const EntityWrapperPtr& theEntity);
67
68 private:
69   /// \brief Container for collecting and operating coincident entities
70   class CoincidentEntities
71   {
72   public:
73     CoincidentEntities(const EntityWrapperPtr& theEntity1,
74                        const EntityWrapperPtr& theEntity2);
75
76     /// Verify the entity is already in the list
77     bool isExist(const EntityWrapperPtr& theEntity) const;
78     /// Verify the point is already in the list
79     bool isExist(const GCS::Point& thePoint) const;
80
81     /// Add entity to group
82     bool add(const EntityWrapperPtr& theEntity);
83
84     /// Remove entity from group
85     void remove(const EntityWrapperPtr& theEntity);
86
87     /// Merge two groups
88     void merge(const CoincidentEntities& theOther);
89
90     /// Returns any of external points
91     EntityWrapperPtr externalPoint() const;
92
93   private:
94     std::set<EntityWrapperPtr> myPoints; ///< coincident points
95     std::set<EntityWrapperPtr> myExternalPoints; //< external points coincident to other points
96     std::set<EntityWrapperPtr> myFeatures; ///< other entities containing points
97   };
98
99   /// \brief Search the group of coincidences containing given entity.
100   ///        Searches points only.
101   std::list<CoincidentEntities>::iterator findGroupOfCoincidence(const EntityWrapperPtr& theEntity);
102
103   /// \brief Add entity to group of coincidences
104   /// \reutrn \c true if the entity is added, thus the coincidence is new
105   bool addToGroupOfCoincidence(CoincidentEntities& theGroup, const EntityWrapperPtr& theEntity);
106
107 private:
108   std::list<CoincidentEntities> myCoincident; ///< list of coincidences
109 };
110
111 #endif