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