Salome HOME
Issue #1664: In the Sketcher, add the function Split a segment. AttrRefAttribute...
[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   /// highlight color is equal Quantity_Color(0.5,1,1) or QColor(122, 255,255) // 188
41   static const std::string OPERATION_HIGHLIGHT_COLOR() { return "188, 255, 255"; }
42
43 public:
44   /// Constructor
45   /// \param theWorkshop a reference to workshop
46   PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop);
47   PARTSET_EXPORT virtual ~PartSet_CustomPrs() {};
48
49   /// Returns true if the presentation is active
50   /// \param theFlag an object AIS presentation type
51   bool isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
52
53   /// Initializes the operation presentation by the parameter object and display the presentation
54   /// \param theObject an operation feature source to fill the presentation
55   /// \param theFlag an object AIS presentation type
56   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
57   /// \returns true if the presentation is displayed
58   bool activate(const FeaturePtr& theObject,
59                 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
60                 const bool theUpdateViewer);
61
62   /// Initializes the operation presentation by empty object and erase the presentation
63   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
64   /// \param theFlag an object AIS presentation type
65   /// \returns true if the presentation has been displayed and now it is erased
66   bool deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
67                   const bool theUpdateViewer);
68
69   /// If the presentation is active[displayed], the shapes of the presentation is recomputed
70   /// and the presentation is redisplayed.
71   /// \param theObject an object to redisplay
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 redisplayed
75   bool redisplay(const ObjectPtr& theObject,
76                  const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
77                  const bool theUpdateViewer);
78
79   /// Nullify all internal presentations. For example, it can be useful when the viewer/context
80   /// is closed. If this is not performed and the presentation is assigned in another context,
81   /// it caused erroneus case because the presentation has linkage to the previous context.
82   void clearPrs();
83
84   //! Redefinition of Events_Listener method to listen a moment that the presentation becomes empty
85   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
86
87 private:
88   /// Creates the AIS operation presentation
89   /// \param theFlag an object AIS presentation type
90   void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
91
92   /// Gets an AIS presentation by the flag or create new if there is no a presentation by the flag
93   /// \param theFlag an object AIS presentation type
94   /// \param theToCreate a flag if a new presentation should be created
95   /// \return wrap of AIS prsentation
96   AISObjectPtr getPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
97                                const bool theToCreate);
98
99   //! Returns workshop
100   XGUI_Workshop* workshop() const;
101
102   /// Displays the internal presentation in the viewer of workshop
103   /// \param theFlag an object AIS presentation type
104   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
105   /// \param returns whether the presentation is displayed/redisplayed
106   bool displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
107                            const bool theUpdateViewer);
108
109   /// Erases the internal presentation from the viewer of workshop
110   /// \param theFlag an object AIS presentation type
111   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
112   /// \param returns whether the presentation is erased
113   bool erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
114                          const bool theUpdateViewer);
115
116   /// Nullify the operation presentation. For example, it can be useful when the viewer/context
117   /// is closed. If this is not performed and the presentation is assigned in another context,
118   /// it caused erroneus case because the presentation has linkage to the previous context.
119   /// \param theFlag an object AIS presentation type
120   void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
121
122   /// Returns presentation color according to the flag
123   /// \param theFlag an object AIS presentation type
124   /// \return theShapeColor a color
125   Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
126
127 private:
128   bool myPresentationIsEmpty; /// Boolean state about empty presentation
129   FeaturePtr myFeature; /// Reference to a feature object
130   ModuleBase_IWorkshop* myWorkshop; /// current workshop
131   /// map of presentation type to AIS object
132   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
133   /// State whether the presentation is activated/deactivated
134   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, bool> myIsActive;
135 };
136
137 #endif