1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.h
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #ifndef GEOM_DISPLAYER_H
28 #define GEOM_DISPLAYER_H
30 #include "GEOM_GEOMGUI.hxx"
31 #include <GEOM_AISShape.hxx>
33 #include <SALOME_InteractiveObject.hxx>
41 class SALOME_OCCViewType;
43 #include <TopoDS_Shape.hxx>
44 #include <Quantity_Color.hxx>
45 #include <LightApp_Displayer.h>
46 #include <LightApp_Study.h>
47 #include <Aspect_TypeOfMarker.hxx>
48 #if OCC_VERSION_MAJOR >= 7
49 #include <AIS_ColorScale.hxx>
51 #include <TCollection_AsciiString.hxx>
52 #include <TColStd_MapOfInteger.hxx>
53 #include <Basics_OCCTVersion.hxx>
58 #include <SALOMEconfig.h>
59 #include CORBA_CLIENT_HEADER(GEOM_Gen)
61 #define GEOM_ALLOBJECTS -1 // Selection of all objects is activated
62 #define GEOM_PREVIEW -2 // Definition for preview selection
63 #define GEOM_ALLSHAPES -3 // Selection of all shapes is activated
64 #define GEOM_ALLGEOM -4 // Selection of all geom objects is activated
66 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
68 class LightApp_SelectionMgr;
69 class SalomeApp_Study;
70 class SalomeApp_Application;
71 class SUIT_SelectionFilter;
74 class GEOMGUI_EXPORT GEOM_Displayer : public LightApp_Displayer
79 GEOM_Displayer( SalomeApp_Study* app );
81 virtual ~GEOM_Displayer();
83 virtual bool canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const;
85 /* Display/Erase object methods */
86 void Display ( const Handle(SALOME_InteractiveObject)& theIO,
87 const bool updateViewer = true,
88 SALOME_View* theViewFrame = 0 );
90 // This overloaded Display() method can be useful for operations
91 // not using dialog boxes.
92 void Display ( GEOM::GEOM_BaseObject_ptr theObj,
93 const bool updateViewer = true );
95 void Redisplay ( const Handle(SALOME_InteractiveObject)& theIO,
96 const bool updateViewer = true,
97 const bool checkActiveViewer = true );
99 void Redisplay ( const Handle(SALOME_InteractiveObject)& theIO,
100 const bool theUpdateViewer,
101 SALOME_View* theViewFrame );
103 void Erase ( const Handle(SALOME_InteractiveObject)& theIO,
104 const bool forced = false,
105 const bool updateViewer = true,
106 SALOME_View* theViewFrame = 0 );
108 void Erase ( GEOM::GEOM_BaseObject_ptr theObj,
109 const bool forced = false,
110 const bool updateViewer = true,
111 SALOME_View* theViewFrame = 0);
113 void EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
114 const bool eraseOnlyChildren = false);
116 /* Display/Erase list of objects methods */
118 void Display ( const SALOME_ListIO& theIOList,
119 const bool updateViewer = true );
121 void Erase ( const SALOME_ListIO& theIOList,
122 const bool forced = false,
123 const bool updateViewer = true );
125 void Redisplay ( const SALOME_ListIO& theIOList,
126 const bool updateViewer = true,
127 const bool checkActiveViewer = true );
129 void Redisplay ( const SALOME_ListIO& theIOList,
130 const bool theUpdateViewer,
131 SALOME_View* theViewFrame );
133 /* Update visibility state */
134 void UpdateVisibility( SALOME_View*, const SALOME_Prs*, bool );
136 /* build presentation accordint to the current viewer type*/
137 SALOME_Prs* BuildPrs ( GEOM::GEOM_Object_ptr );
138 SALOME_Prs* BuildPrs ( const TopoDS_Shape& );
140 /* Set color for shape displaying. If it is equal -1 then default color is used.
141 Available values are from Quantity_NameOfColor enumeration */
142 void SetColor ( const int );
144 int GetColor () const;
145 bool HasColor () const;
147 double SetTransparency ( const double );
148 double UnsetTransparency();
149 double GetTransparency () const;
150 bool HasTransparency () const;
152 /* Set texture for shape displaying. */
153 void SetTexture ( const std::string& );
154 bool HasTexture () const;
155 std::string GetTexture () const;
157 /* Set width for shape displaying. If it is equal -1 then default width is used. */
158 void SetWidth ( const double );
160 double GetWidth () const;
161 bool HasWidth () const;
163 /* Set width for iso-lines displaying. If it is equal -1 then default width is used. */
164 void SetIsosWidth ( const int );
165 int GetIsosWidth () const;
166 bool HasIsosWidth () const;
168 /* Set nb iso-libes for displaying. Use -1 to set default values. */
169 int SetNbIsos( const int );
171 int GetNbIsos() const;
172 bool HasNbIsos() const;
174 /* Set color for iso-lines displaying. If it is equal -1 then default color is used.
175 Available values are from Quantity_NameOfColor enumeration */
176 int SetIsosColor ( const int );
177 int UnsetIsosColor();
178 int GetIsosColor () const;
179 bool HasIsosColor () const;
181 /* Set display mode shape displaying. If it is equal -1 then display mode is used. */
182 int SetDisplayMode( const int );
183 int GetDisplayMode() const;
184 int UnsetDisplayMode();
185 bool HasDisplayMode() const;
187 /* Sets name - for temporary objects only */
188 void SetName( const char* theName );
191 /* Reimplemented from SALOME_Displayer */
192 virtual void Update( SALOME_OCCPrs* );
193 virtual void Update( SALOME_VTKPrs* );
194 virtual void BeforeDisplay( SALOME_View*, const SALOME_OCCPrs* );
195 virtual void AfterDisplay ( SALOME_View*, const SALOME_OCCPrs* );
196 virtual void BeforeErase ( SALOME_View*, const SALOME_OCCPrs* );
197 virtual void AfterErase ( SALOME_View*, const SALOME_OCCPrs* );
199 /* This methos is used for activisation/deactivisation of objects to be displayed*/
200 void SetToActivate( const bool );
201 bool ToActivate() const;
203 /* Activate/Deactivate selection*/
204 void LocalSelection( const Handle(SALOME_InteractiveObject)&, const std::list<int> );
205 void LocalSelection( const Handle(SALOME_InteractiveObject)&, const int );
206 void LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> );
207 void LocalSelection( const SALOME_ListIO& theIOList, const int );
208 void GlobalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
209 void GlobalSelection( const TColStd_MapOfInteger&, const bool = false, const QList<int>* = 0 );
211 SalomeApp_Study* getStudy() const;
213 static SALOMEDS::Color getUniqueColor( const QList<SALOMEDS::Color>& );
214 static SALOMEDS::Color getPredefinedUniqueColor();
216 /*Get color of the geom object*/
217 static SALOMEDS::Color getColor(GEOM::GEOM_Object_var aGeomObject, bool& hasColor);
219 /* Get minimum or maximum enclosed shape type */
220 static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin );
222 /* Check if the object is a vertex or a compound of vertices */
223 static bool isCompoundOfVertices( const TopoDS_Shape& theShape );
226 /* Builds presentation of not published object */
227 virtual SALOME_Prs* buildSubshapePresentation(const TopoDS_Shape& aShape,
231 /* Update visibility and parameters of the currently selected field step's color scale */
232 void UpdateColorScale( const bool theIsRedisplayFieldSteps = false, const bool updateViewer = true );
235 /* internal methods */
236 /* Builds presentation according to the current viewer type */
237 virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 );
239 /* Sets interactive object */
240 void setIO( const Handle(SALOME_InteractiveObject)& theIO );
243 void setShape( const TopoDS_Shape& theShape );
245 /* Sets field step information */
246 void setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
247 const int theFieldDimension,
248 const QList<QVariant>& theFieldStepData,
249 const TCollection_AsciiString& theFieldStepName,
250 const double theFieldStepRangeMin,
251 const double theFieldStepRangeMax );
253 /* Resets internal data */
254 void internalReset();
256 void clearTemporary( LightApp_SelectionMgr* theSelMgr );
258 SUIT_SelectionFilter* getFilter( const int theMode );
259 SUIT_SelectionFilter* getComplexFilter( const QList<int>* );
261 Quantity_Color qColorFromResources( const QString&, const QColor& );
262 QColor colorFromResources( const QString&, const QColor& );
263 void updateShapeProperties( const Handle(GEOM_AISShape)&, bool );
264 void updateActorProperties( GEOM_Actor*, bool );
265 void updateDimensions( const Handle(SALOME_InteractiveObject)&, SALOME_OCCPrs*, const gp_Ax3& );
266 void updateShapeAnnotations( const Handle(SALOME_InteractiveObject)&, SALOME_OCCPrs*, const gp_Ax3& );
268 PropMap getObjectProperties( SalomeApp_Study*, const QString&, SALOME_View* = 0 );
269 PropMap getDefaultPropertyMap();
271 /* Methods for reading the field step information */
272 void readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep );
273 QList<QVariant> groupFieldData( const QList<QVariant>& theFieldStepData,
274 const int theFieldNbComponents,
275 const bool theIsString,
276 double& theFieldStepRangeMin,
277 double& theFieldStepRangeMax );
279 // Note: the method is copied from Aspect_ColorScale class
280 static Standard_Integer HueFromValue( const Standard_Integer aValue,
281 const Standard_Integer aMin,
282 const Standard_Integer aMax );
284 // Note: the method is copied from Aspect_ColorScale class
285 static Standard_Boolean FindColor( const Standard_Real aValue,
286 const Standard_Real aMin,
287 const Standard_Real aMax,
288 const Standard_Integer ColorsCount,
289 Quantity_Color& aColor );
292 Handle(SALOME_InteractiveObject) myIO;
293 TopoDS_Shape myShape;
294 GEOM::field_data_type myFieldDataType;
295 int myFieldDimension;
296 QList<QVariant> myFieldStepData;
297 TCollection_AsciiString myFieldStepName;
298 double myFieldStepRangeMin;
299 double myFieldStepRangeMax;
301 std::string myTexture;
303 SALOME_View* myViewFrame;
304 #if OCC_VERSION_MAJOR >= 7
305 Handle(AIS_ColorScale) myColorScale;
309 Quantity_Color myShadingColor;
317 bool myHasDisplayMode;
318 Aspect_TypeOfMarker myTypeOfMarker;
319 double myScaleOfMarker;
320 double myTransparency;
321 bool myIsRedisplayed;
324 SalomeApp_Application* myApp;
325 friend class GEOM_Swig;
328 #endif // GEOM_DISPLAYER_H