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