Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_CustomPrs.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_CustomPrs_H
21 #define PartSet_CustomPrs_H
22
23 #include "PartSet.h"
24
25 #include "PartSet_OperationPrs.h"
26
27 #include <ModuleBase_IModule.h>
28 #include <ModelAPI_Object.h>
29 #include <ModelAPI_Result.h>
30 #include <ModelAPI_Feature.h>
31
32 #include <Events_Listener.h>
33
34 #include <GeomAPI_ICustomPrs.h>
35 #include <GeomAPI_AISObject.h>
36 #include <GeomAPI_Shape.h>
37
38 class ModuleBase_IWorkshop;
39 class XGUI_Workshop;
40
41 /**
42  * This is the module custom presentation, which manage an AIS presentation, that can be filled
43  * by a feature and visualized in the viewer additionally to usual workshop objects.
44 */
45 class PartSet_CustomPrs : public Events_Listener
46 {
47 public:
48   /// Returns yellow color
49   static const std::string OPERATION_PARAMETER_COLOR() { return "255, 255, 0"; }
50   /// Returns green color
51   static const std::string OPERATION_RESULT_COLOR() { return "0,225, 0"; }
52   /// Returns color between white and color of highlight
53   static const std::string OPERATION_HIGHLIGHT_COLOR() { return "128, 0, 0"; }
54
55   /// Returns color lighter than sketch feature entity : pink
56   static const std::string OPERATION_REMOVE_FEATURE_COLOR() { return "255, 174, 201"; }
57
58   /// Returns color equal to default color of construction plugin : green
59   static const std::string OPERATION_SKETCH_PLANE() { return "170,255,0"; }
60 public:
61   /// Constructor
62   /// \param theWorkshop a reference to workshop
63   PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop);
64   PARTSET_EXPORT virtual ~PartSet_CustomPrs() {};
65
66   /// Returns true if the presentation is active
67   /// \param theFlag an object AIS presentation type
68   bool isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
69
70   /// Initializes the operation presentation by the parameter object and display the presentation
71   /// \param theObject an operation feature source to fill the presentation
72   /// \param theFlag an object AIS presentation type
73   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
74   /// \returns true if the presentation is displayed
75   bool activate(const FeaturePtr& theObject,
76                 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
77                 const bool theUpdateViewer);
78
79   /// Initializes the operation presentation by empty object and erase the presentation
80   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
81   /// \param theFlag an object AIS presentation type
82   /// \returns true if the presentation has been displayed and now it is erased
83   bool deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
84                   const bool theUpdateViewer);
85
86   /// If the presentation is active[displayed], the shapes of the presentation is recomputed
87   /// and the presentation is redisplayed.
88   /// \param theObject an object to redisplay
89   /// \param theFlag an object AIS presentation type
90   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
91   /// \returns true if the presentation is redisplayed
92   bool redisplay(const ObjectPtr& theObject,
93                  const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
94                  const bool theUpdateViewer);
95
96   /// Nullify all internal presentations. For example, it can be useful when the viewer/context
97   /// is closed. If this is not performed and the presentation is assigned in another context,
98   /// it caused erroneus case because the presentation has linkage to the previous context.
99   void clearPrs();
100
101   /// Disable displaying of custom mode
102   /// \param theMode a mode to disable
103   void disableCustomMode(ModuleBase_IModule::ModuleBase_CustomizeFlag theMode) {
104     myDisabledMode = theMode;
105     erasePresentation(theMode, false);
106   }
107
108   /// Enables disabled custom mode
109   void enableCustomModes() { myDisabledMode = -1; }
110
111   //! Redefinition of Events_Listener method to listen a moment that the presentation becomes empty
112   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
113
114 private:
115   /// Creates the AIS operation presentation
116   /// \param theFlag an object AIS presentation type
117   void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
118
119   /// Gets an AIS presentation by the flag or create new if there is no a presentation by the flag
120   /// \param theFlag an object AIS presentation type
121   /// \param theToCreate a flag if a new presentation should be created
122   /// \return wrap of AIS prsentation
123   AISObjectPtr getPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
124                                const bool theToCreate);
125
126   //! Returns workshop
127   XGUI_Workshop* workshop() const;
128
129   /// Displays the internal presentation in the viewer of workshop
130   /// \param theFlag an object AIS presentation type
131   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
132   /// \param returns whether the presentation is displayed/redisplayed
133   bool displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
134                            const bool theUpdateViewer);
135
136   /// Erases the internal presentation from the viewer of workshop
137   /// \param theFlag an object AIS presentation type
138   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
139   /// \param returns whether the presentation is erased
140   bool erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
141                          const bool theUpdateViewer);
142
143   /// Nullify the operation presentation. For example, it can be useful when the viewer/context
144   /// is closed. If this is not performed and the presentation is assigned in another context,
145   /// it caused erroneus case because the presentation has linkage to the previous context.
146   /// \param theFlag an object AIS presentation type
147   void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
148
149   /// Returns presentation color according to the flag
150   /// \param theFlag an object AIS presentation type
151   /// \return theShapeColor a color
152   Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
153
154   /// Removes error shapes presentation
155   void clearErrorShape();
156
157 private:
158   ModuleBase_IWorkshop* myWorkshop; /// current workshop
159   FeaturePtr myFeature; /// Reference to a feature object
160   bool myPresentationIsEmpty; /// Boolean state about empty presentation
161   /// map of presentation type to AIS object
162   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
163   /// State whether the presentation is activated/deactivated
164   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, bool> myIsActive;
165
166   int myDisabledMode;
167
168   Handle(AIS_Shape) myErrorShapes;
169 };
170
171 #endif