Salome HOME
Issue #1393 Angle constraint : incorrect angle displayed. solution: do not select...
[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 <GeomAPI_ICustomPrs.h>
20 #include <GeomAPI_AISObject.h>
21 #include <GeomAPI_Shape.h>
22
23 class ModuleBase_IWorkshop;
24 class XGUI_Workshop;
25
26 /**
27  * This is the module custom presentation, which manage an AIS presentation, that can be filled
28  * by a feature and visualized in the viewer additionally to usual workshop objects.
29 */
30 class PartSet_CustomPrs
31 {
32 public:
33   /// Returns yellow color
34   static const std::string OPERATION_PARAMETER_COLOR() { return "255, 255, 0"; }
35   /// Returns green color
36   static const std::string OPERATION_RESULT_COLOR() { return "0,225, 0"; }
37   /// Returns color between white and color of highlight
38   /// highlight color is equal Quantity_Color(0.5,1,1) or QColor(122, 255,255) // 188
39   static const std::string OPERATION_HIGHLIGHT_COLOR() { return "188, 255, 255"; }
40
41 public:
42   /// Constructor
43   /// \param theWorkshop a reference to workshop
44   PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop);
45   PARTSET_EXPORT virtual ~PartSet_CustomPrs() {};
46
47   /// Returns true if the presentation is active
48   /// \param theFlag an object AIS presentation type
49   bool isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
50
51   /// Initializes the operation presentation by the parameter object and display the presentation
52   /// \param theObject an operation feature source to fill the presentation
53   /// \param theFlag an object AIS presentation type
54   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
55   /// \returns true if the presentation is displayed
56   bool activate(const FeaturePtr& theObject,
57                 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
58                 const bool theUpdateViewer);
59
60   /// Initializes the operation presentation by empty object and erase the presentation
61   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
62   /// \param theFlag an object AIS presentation type
63   /// \returns true if the presentation has been displayed and now it is erased
64   bool deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
65                   const bool theUpdateViewer);
66
67   /// If the presentation is active[displayed], the shapes of the presentation is recomputed
68   /// and the presentation is redisplayed.
69   /// \param theObject an object to redisplay
70   /// \param theFlag an object AIS presentation type
71   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
72   /// \returns true if the presentation is redisplayed
73   bool redisplay(const ObjectPtr& theObject,
74                  const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
75                  const bool theUpdateViewer);
76
77   /// Nullify all internal presentations. For example, it can be useful when the viewer/context
78   /// is closed. If this is not performed and the presentation is assigned in another context,
79   /// it caused erroneus case because the presentation has linkage to the previous context.
80   void clearPrs();
81
82 private:
83   /// Creates the AIS operation presentation
84   /// \param theFlag an object AIS presentation type
85   void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
86
87   /// Gets an AIS presentation by the flag
88   /// \param theFlag an object AIS presentation type
89   /// \return the AIS prsentation
90   Handle(PartSet_OperationPrs) getPresentation(
91                             const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
92
93   //! Returns workshop
94   XGUI_Workshop* workshop() const;
95
96   /// Displays the internal presentation in the viewer of workshop
97   /// \param theFlag an object AIS presentation type
98   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
99   /// \param returns whether the presentation is displayed/redisplayed
100   bool displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
101                            const bool theUpdateViewer);
102
103   /// Erases the internal presentation from 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   void erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
107                          const bool theUpdateViewer);
108
109   /// Nullify the operation presentation. For example, it can be useful when the viewer/context
110   /// is closed. If this is not performed and the presentation is assigned in another context,
111   /// it caused erroneus case because the presentation has linkage to the previous context.
112   /// \param theFlag an object AIS presentation type
113   void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
114
115   /// Returns presentation color according to the flag
116   /// \param theFlag an object AIS presentation type
117   /// \return theShapeColor a color
118   Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
119
120 private:
121   FeaturePtr myFeature; /// Reference to a feature object
122   ModuleBase_IWorkshop* myWorkshop; /// current workshop
123   /// map of presentation type to AIS object
124   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
125   /// State whether the presentation is activated/deactivated
126   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, bool> myIsActive;
127 };
128
129 #endif