1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef PartSet_CustomPrs_H
21 #define PartSet_CustomPrs_H
25 #include "PartSet_OperationPrs.h"
27 #include <ModuleBase_IModule.h>
28 #include <ModelAPI_Object.h>
29 #include <ModelAPI_Result.h>
30 #include <ModelAPI_Feature.h>
32 #include <Events_Listener.h>
34 #include <GeomAPI_ICustomPrs.h>
35 #include <GeomAPI_AISObject.h>
36 #include <GeomAPI_Shape.h>
38 class ModuleBase_IWorkshop;
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.
45 class PartSet_CustomPrs : public Events_Listener
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"; }
55 /// Returns color lighter than sketch feature entity : pink
56 static const std::string OPERATION_REMOVE_FEATURE_COLOR() { return "255, 174, 201"; }
58 /// Returns color equal to default color of construction plugin : green
59 static const std::string OPERATION_SKETCH_PLANE() { return "170,255,0"; }
62 /// \param theWorkshop a reference to workshop
63 PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop);
64 PARTSET_EXPORT virtual ~PartSet_CustomPrs() {};
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);
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);
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);
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);
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.
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);
108 /// Enables disabled custom mode
109 void enableCustomModes() { myDisabledMode = -1; }
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);
115 /// Creates the AIS operation presentation
116 /// \param theFlag an object AIS presentation type
117 void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
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);
127 XGUI_Workshop* workshop() const;
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);
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);
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);
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);
155 bool myPresentationIsEmpty; /// Boolean state about empty presentation
156 FeaturePtr myFeature; /// Reference to a feature object
157 ModuleBase_IWorkshop* myWorkshop; /// current workshop
158 /// map of presentation type to AIS object
159 QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
160 /// State whether the presentation is activated/deactivated
161 QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, bool> myIsActive;