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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef PartSet_CustomPrs_H
22 #define PartSet_CustomPrs_H
26 #include "PartSet_OperationPrs.h"
28 #include <ModuleBase_IModule.h>
29 #include <ModelAPI_Object.h>
30 #include <ModelAPI_Result.h>
31 #include <ModelAPI_Feature.h>
33 #include <Events_Listener.h>
35 #include <GeomAPI_ICustomPrs.h>
36 #include <GeomAPI_AISObject.h>
37 #include <GeomAPI_Shape.h>
39 class ModuleBase_IWorkshop;
43 * This is the module custom presentation, which manage an AIS presentation, that can be filled
44 * by a feature and visualized in the viewer additionally to usual workshop objects.
46 class PartSet_CustomPrs : public Events_Listener
49 /// Returns yellow color
50 static const std::string OPERATION_PARAMETER_COLOR() { return "255, 255, 0"; }
51 /// Returns green color
52 static const std::string OPERATION_RESULT_COLOR() { return "0,225, 0"; }
53 /// Returns color between white and color of highlight
54 static const std::string OPERATION_HIGHLIGHT_COLOR() { return "128, 0, 0"; }
56 /// Returns color lighter than sketch feature entity : pink
57 static const std::string OPERATION_REMOVE_FEATURE_COLOR() { return "255, 174, 201"; }
60 /// \param theWorkshop a reference to workshop
61 PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop);
62 PARTSET_EXPORT virtual ~PartSet_CustomPrs() {};
64 /// Returns true if the presentation is active
65 /// \param theFlag an object AIS presentation type
66 bool isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
68 /// Initializes the operation presentation by the parameter object and display the presentation
69 /// \param theObject an operation feature source to fill the presentation
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 displayed
73 bool activate(const FeaturePtr& theObject,
74 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
75 const bool theUpdateViewer);
77 /// Initializes the operation presentation by empty object and erase the presentation
78 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
79 /// \param theFlag an object AIS presentation type
80 /// \returns true if the presentation has been displayed and now it is erased
81 bool deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
82 const bool theUpdateViewer);
84 /// If the presentation is active[displayed], the shapes of the presentation is recomputed
85 /// and the presentation is redisplayed.
86 /// \param theObject an object to redisplay
87 /// \param theFlag an object AIS presentation type
88 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
89 /// \returns true if the presentation is redisplayed
90 bool redisplay(const ObjectPtr& theObject,
91 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
92 const bool theUpdateViewer);
94 /// Nullify all internal presentations. For example, it can be useful when the viewer/context
95 /// is closed. If this is not performed and the presentation is assigned in another context,
96 /// it caused erroneus case because the presentation has linkage to the previous context.
99 //! Redefinition of Events_Listener method to listen a moment that the presentation becomes empty
100 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
103 /// Creates the AIS operation presentation
104 /// \param theFlag an object AIS presentation type
105 void initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
107 /// Gets an AIS presentation by the flag or create new if there is no a presentation by the flag
108 /// \param theFlag an object AIS presentation type
109 /// \param theToCreate a flag if a new presentation should be created
110 /// \return wrap of AIS prsentation
111 AISObjectPtr getPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
112 const bool theToCreate);
115 XGUI_Workshop* workshop() const;
117 /// Displays the internal presentation in the viewer of workshop
118 /// \param theFlag an object AIS presentation type
119 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
120 /// \param returns whether the presentation is displayed/redisplayed
121 bool displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
122 const bool theUpdateViewer);
124 /// Erases the internal presentation from the viewer of workshop
125 /// \param theFlag an object AIS presentation type
126 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
127 /// \param returns whether the presentation is erased
128 bool erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
129 const bool theUpdateViewer);
131 /// Nullify the operation presentation. For example, it can be useful when the viewer/context
132 /// is closed. If this is not performed and the presentation is assigned in another context,
133 /// it caused erroneus case because the presentation has linkage to the previous context.
134 /// \param theFlag an object AIS presentation type
135 void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
137 /// Returns presentation color according to the flag
138 /// \param theFlag an object AIS presentation type
139 /// \return theShapeColor a color
140 Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
143 bool myPresentationIsEmpty; /// Boolean state about empty presentation
144 FeaturePtr myFeature; /// Reference to a feature object
145 ModuleBase_IWorkshop* myWorkshop; /// current workshop
146 /// map of presentation type to AIS object
147 QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
148 /// State whether the presentation is activated/deactivated
149 QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, bool> myIsActive;