Salome HOME
49390f0ee7752b11f9eeee9389fb9512e664c3de
[modules/shaper.git] / src / PartSet / PartSet_OverconstraintListener.h
1 // Copyright (C) 2014-2020  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 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   bool isFullyConstrained() const { return myIsFullyConstrained; }
68
69 protected:
70   /// Append objects to the internal container of conflicting object, redisplay necessary objects
71   /// \param theObjects a list of new conflicting objects
72   /// \return boolean value whether the list differs from the internal list
73   bool appendConflictingObjects(const std::set<ObjectPtr>& theObjects);
74
75   /// Removes objects from internal container of conflicting object, redisplay necessary objects
76   /// \param theObjects a list of repaired objects
77   /// \return boolean value whether the list differs from the internal list
78   bool repairConflictingObjects(const std::set<ObjectPtr>& theObjects);
79
80   /// Sends update object signal for each object in the container and flush it.
81   /// \param theObjects a list of object to be redisplayed
82   void redisplayObjects(const std::set<ObjectPtr>& theObjects);
83
84 private:
85   /// Returns module
86   PartSet_Module* module() const;
87
88 #ifdef _DEBUG
89   /// Unite objects in one string information
90   /// \param theObjects a list of objects
91   /// \return a string info
92   static QString getObjectsInfo(const std::set<ObjectPtr>& theObjects);
93 #endif
94
95 private:
96   ModuleBase_IWorkshop* myWorkshop;
97   bool myIsActive; /// state if sketch is active
98   std::set<ObjectPtr> myConflictingObjects;
99   bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0
100 };
101
102 #endif