1 // Copyright (C) 2014-2017 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<mailto: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"; }
59 /// \param theWorkshop a reference to workshop
60 PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop);
61 PARTSET_EXPORT virtual ~PartSet_CustomPrs() {};
63 /// Returns true if the presentation is active
64 /// \param theFlag an object AIS presentation type
65 bool isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
67 /// Initializes the operation presentation by the parameter object and display the presentation
68 /// \param theObject an operation feature source to fill the presentation
69 /// \param theFlag an object AIS presentation type
70 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
71 /// \returns true if the presentation is displayed
72 bool activate(const FeaturePtr& theObject,
73 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
74 const bool theUpdateViewer);
76 /// Initializes the operation presentation by empty object and erase the presentation
77 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
78 /// \param theFlag an object AIS presentation type
79 /// \returns true if the presentation has been displayed and now it is erased
80 bool deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
81 const bool theUpdateViewer);
83 /// If the presentation is active[displayed], the shapes of the presentation is recomputed
84 /// and the presentation is redisplayed.
85 /// \param theObject an object to redisplay
86 /// \param theFlag an object AIS presentation type
87 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
88 /// \returns true if the presentation is redisplayed
89 bool redisplay(const ObjectPtr& theObject,
90 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
91 const bool theUpdateViewer);
93 /// Nullify all internal presentations. For example, it can be useful when the viewer/context
94 /// is closed. If this is not performed and the presentation is assigned in another context,
95 /// it caused erroneus case because the presentation has linkage to the previous context.
98 //! Redefinition of Events_Listener method to listen a moment that the presentation becomes empty
99 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
102 /// Creates the AIS operation presentation
103 /// \param theFlag an object AIS presentation type
104 void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
106 /// Gets an AIS presentation by the flag or create new if there is no a presentation by the flag
107 /// \param theFlag an object AIS presentation type
108 /// \param theToCreate a flag if a new presentation should be created
109 /// \return wrap of AIS prsentation
110 AISObjectPtr getPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
111 const bool theToCreate);
114 XGUI_Workshop* workshop() const;
116 /// Displays the internal presentation in the viewer of workshop
117 /// \param theFlag an object AIS presentation type
118 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
119 /// \param returns whether the presentation is displayed/redisplayed
120 bool displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
121 const bool theUpdateViewer);
123 /// Erases the internal presentation from the viewer of workshop
124 /// \param theFlag an object AIS presentation type
125 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
126 /// \param returns whether the presentation is erased
127 bool erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
128 const bool theUpdateViewer);
130 /// Nullify the operation presentation. For example, it can be useful when the viewer/context
131 /// is closed. If this is not performed and the presentation is assigned in another context,
132 /// it caused erroneus case because the presentation has linkage to the previous context.
133 /// \param theFlag an object AIS presentation type
134 void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
136 /// Returns presentation color according to the flag
137 /// \param theFlag an object AIS presentation type
138 /// \return theShapeColor a color
139 Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
142 bool myPresentationIsEmpty; /// Boolean state about empty presentation
143 FeaturePtr myFeature; /// Reference to a feature object
144 ModuleBase_IWorkshop* myWorkshop; /// current workshop
145 /// map of presentation type to AIS object
146 QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
147 /// State whether the presentation is activated/deactivated
148 QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, bool> myIsActive;