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