Salome HOME
c4078244d4c264e400481b4c14ee3384fcd10527
[modules/shaper.git] / src / PartSet / PartSet_OverconstraintListener.h
1 // Copyright (C) 2014-2023  CEA, EDF
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 PartSet_OverconstraintListener_H
21 #define PartSet_OverconstraintListener_H
22
23 #include <Events_Listener.h>
24 #include <ModelAPI_Object.h>
25
26 class ModuleBase_IWorkshop;
27 class PartSet_Module;
28
29 #include <QString>
30
31 #include <vector>
32 #include <set>
33
34 /**
35 * \ingroup GUI
36 * A class for processing overconstraint situation. It contains is a list of sketch constraints with
37 * conflicts.
38 */
39 class PartSet_OverconstraintListener : public Events_Listener
40 {
41 public:
42   /// Constructor
43   /// \param theWorkshop a current workshop to obtain AIS presentation from displayer
44   PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop);
45
46   virtual ~PartSet_OverconstraintListener() {};
47
48   /// If active state is changed, update fully defined state and sketch sub-entities color
49   /// \param theActive a state
50   void setActive(const bool& theActive);
51
52   /// Returns true if the object belongs to internal container of conflicting objects
53   /// \param theObject an object to be checked
54   /// \param theColor the output container to be filled in [red, green, blue] values
55   /// \return boolean result
56   void getCustomColor(const ObjectPtr& theObject, std::vector<int>& theColor);
57
58   /// Redefinition of Events_Listener method
59   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
60
61
62   bool isConflictingObject(const ObjectPtr& theObject) const
63   {
64     return (myConflictingObjects.find(theObject) != myConflictingObjects.end());
65   }
66
67   const std::set<ObjectPtr>& conflictingObjects() const
68   {
69     return myConflictingObjects;
70   }
71
72   const std::set<ObjectPtr>& objectsToRemove() const
73   {
74     return myObjectsToRemove;
75   }
76
77   bool isFullyConstrained() const { return myIsFullyConstrained; }
78
79 protected:
80   /// Append objects to the internal container of conflicting object, redisplay necessary objects
81   /// \param theObjects a list of new conflicting objects
82   /// \return boolean value whether the list differs from the internal list
83   bool appendConflictingObjects(const std::set<ObjectPtr>& theObjects);
84
85   /// Removes objects from internal container of conflicting object, redisplay necessary objects
86   /// \param theObjects a list of repaired objects
87   /// \return boolean value whether the list differs from the internal list
88   bool repairConflictingObjects(const std::set<ObjectPtr>& theObjects);
89
90   /// Sends update object signal for each object in the container and flush it.
91   /// \param theObjects a list of object to be redisplayed
92   void redisplayObjects(const std::set<ObjectPtr>& theObjects);
93
94 private:
95   /// Returns module
96   PartSet_Module* module() const;
97
98 #ifdef _DEBUG
99   /// Unite objects in one string information
100   /// \param theObjects a list of objects
101   /// \return a string info
102   static QString getObjectsInfo(const std::set<ObjectPtr>& theObjects);
103 #endif
104
105 private:
106   ModuleBase_IWorkshop* myWorkshop;
107   bool myIsActive; /// state if sketch is active
108   std::set<ObjectPtr> myConflictingObjects;
109   std::set<ObjectPtr> myObjectsToRemove;
110   bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0
111 };
112
113 #endif