Salome HOME
Issue #1941 Split auxiliary line.
[modules/shaper.git] / src / PartSet / PartSet_CustomPrs.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_CustomPrs.hxx
4 // Created:     30 Jun 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef PartSet_CustomPrs_H
8 #define PartSet_CustomPrs_H
9
10 #include "PartSet.h"
11
12 #include "PartSet_OperationPrs.h"
13
14 #include <ModuleBase_IModule.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Result.h>
17 #include <ModelAPI_Feature.h>
18
19 #include <Events_Listener.h>
20
21 #include <GeomAPI_ICustomPrs.h>
22 #include <GeomAPI_AISObject.h>
23 #include <GeomAPI_Shape.h>
24
25 class ModuleBase_IWorkshop;
26 class XGUI_Workshop;
27
28 /**
29  * This is the module custom presentation, which manage an AIS presentation, that can be filled
30  * by a feature and visualized in the viewer additionally to usual workshop objects.
31 */
32 class PartSet_CustomPrs : public Events_Listener
33 {
34 public:
35   /// Returns yellow color
36   static const std::string OPERATION_PARAMETER_COLOR() { return "255, 255, 0"; }
37   /// Returns green color
38   static const std::string OPERATION_RESULT_COLOR() { return "0,225, 0"; }
39   /// Returns color between white and color of highlight
40   static const std::string OPERATION_HIGHLIGHT_COLOR() { return "128, 0, 0"; }
41
42 public:
43   /// Constructor
44   /// \param theWorkshop a reference to workshop
45   PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop);
46   PARTSET_EXPORT virtual ~PartSet_CustomPrs() {};
47
48   /// Returns true if the presentation is active
49   /// \param theFlag an object AIS presentation type
50   bool isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
51
52   /// Initializes the operation presentation by the parameter object and display the presentation
53   /// \param theObject an operation feature source to fill the presentation
54   /// \param theFlag an object AIS presentation type
55   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
56   /// \returns true if the presentation is displayed
57   bool activate(const FeaturePtr& theObject,
58                 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
59                 const bool theUpdateViewer);
60
61   /// Initializes the operation presentation by empty object and erase the presentation
62   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
63   /// \param theFlag an object AIS presentation type
64   /// \returns true if the presentation has been displayed and now it is erased
65   bool deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
66                   const bool theUpdateViewer);
67
68   /// If the presentation is active[displayed], the shapes of the presentation is recomputed
69   /// and the presentation is redisplayed.
70   /// \param theObject an object to redisplay
71   /// \param theFlag an object AIS presentation type
72   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
73   /// \returns true if the presentation is redisplayed
74   bool redisplay(const ObjectPtr& theObject,
75                  const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
76                  const bool theUpdateViewer);
77
78   /// Nullify all internal presentations. For example, it can be useful when the viewer/context
79   /// is closed. If this is not performed and the presentation is assigned in another context,
80   /// it caused erroneus case because the presentation has linkage to the previous context.
81   void clearPrs();
82
83   //! Redefinition of Events_Listener method to listen a moment that the presentation becomes empty
84   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
85
86 private:
87   /// Creates the AIS operation presentation
88   /// \param theFlag an object AIS presentation type
89   void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
90
91   /// Gets an AIS presentation by the flag or create new if there is no a presentation by the flag
92   /// \param theFlag an object AIS presentation type
93   /// \param theToCreate a flag if a new presentation should be created
94   /// \return wrap of AIS prsentation
95   AISObjectPtr getPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
96                                const bool theToCreate);
97
98   //! Returns workshop
99   XGUI_Workshop* workshop() const;
100
101   /// Displays the internal presentation in the viewer of workshop
102   /// \param theFlag an object AIS presentation type
103   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
104   /// \param returns whether the presentation is displayed/redisplayed
105   bool displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
106                            const bool theUpdateViewer);
107
108   /// Erases the internal presentation from the viewer of workshop
109   /// \param theFlag an object AIS presentation type
110   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
111   /// \param returns whether the presentation is erased
112   bool erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
113                          const bool theUpdateViewer);
114
115   /// Nullify the operation presentation. For example, it can be useful when the viewer/context
116   /// is closed. If this is not performed and the presentation is assigned in another context,
117   /// it caused erroneus case because the presentation has linkage to the previous context.
118   /// \param theFlag an object AIS presentation type
119   void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
120
121   /// Returns presentation color according to the flag
122   /// \param theFlag an object AIS presentation type
123   /// \return theShapeColor a color
124   Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
125
126 private:
127   bool myPresentationIsEmpty; /// Boolean state about empty presentation
128   FeaturePtr myFeature; /// Reference to a feature object
129   ModuleBase_IWorkshop* myWorkshop; /// current workshop
130   /// map of presentation type to AIS object
131   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
132   /// State whether the presentation is activated/deactivated
133   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, bool> myIsActive;
134 };
135
136 #endif