69184a2b785253c41e0232314263a28476cc0430
[occt.git] / src / V3d / V3d_Viewer.hxx
1 // Created on: 1992-01-17
2 // Created by: GG
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _V3d_Viewer_HeaderFile
18 #define _V3d_Viewer_HeaderFile
19
20 #include <Aspect_Background.hxx>
21 #include <Aspect_GenId.hxx>
22 #include <Aspect_GradientBackground.hxx>
23 #include <Aspect_GradientFillMethod.hxx>
24 #include <Aspect_GridDrawMode.hxx>
25 #include <Aspect_GridType.hxx>
26
27 #include <gp_Ax3.hxx>
28 #include <Graphic3d_StructureManager.hxx>
29 #include <Graphic3d_Vertex.hxx>
30 #include <Graphic3d_ZLayerSettings.hxx>
31
32 #include <Standard.hxx>
33 #include <Standard_Boolean.hxx>
34 #include <Standard_CString.hxx>
35 #include <Standard_ExtString.hxx>
36 #include <Standard_Integer.hxx>
37 #include <Standard_Real.hxx>
38 #include <Standard_Type.hxx>
39
40 #include <TColStd_MapOfInteger.hxx>
41 #include <TColStd_ListIteratorOfListOfTransient.hxx>
42 #include <TColStd_SequenceOfInteger.hxx>
43 #include <TCollection_AsciiString.hxx>
44 #include <TCollection_ExtendedString.hxx>
45
46 #include <V3d_ListOfLight.hxx>
47 #include <V3d_ListOfView.hxx>
48 #include <V3d_TypeOfOrientation.hxx>
49 #include <V3d_TypeOfShadingModel.hxx>
50 #include <V3d_TypeOfView.hxx>
51 #include <V3d_TypeOfVisualization.hxx>
52
53 #include <Quantity_Color.hxx>
54
55 class Aspect_Grid;
56 class Graphic3d_AspectMarker3d;
57 class Graphic3d_GraphicDriver;
58 class Graphic3d_Group;
59 class Graphic3d_Structure;
60 class V3d_BadValue;
61 class V3d_CircularGrid;
62 class V3d_RectangularGrid;
63 class V3d_View;
64 class Quantity_Color;
65
66 //! Defines services on Viewer type objects.
67 //! The methods of this class allow editing and
68 //! interrogation of the parameters linked to the viewer
69 //! its friend classes (View,light,plane).
70 class V3d_Viewer : public Standard_Transient
71 {
72   friend class V3d_View;
73   DEFINE_STANDARD_RTTIEXT(V3d_Viewer, Standard_Transient)
74 public:
75
76   //! Create a Viewer with the given graphic driver and with default parameters:
77   //! - View orientation: V3d_XposYnegZpos
78   //! - View background: Quantity_NOC_GRAY30
79   //! - Shading model: V3d_GOURAUD
80   Standard_EXPORT V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver);
81
82   //! Returns True if One View more can be defined in this Viewer.
83   Standard_EXPORT Standard_Boolean IfMoreViews() const;
84
85   //! Creates a view in the viewer according to its default parameters.
86   Standard_EXPORT Handle(V3d_View) CreateView();
87   
88   //! Activates all of the views of a viewer attached to a window.
89   Standard_EXPORT void SetViewOn();
90   
91   //! Activates a particular view in the Viewer.
92   //! Must be call if the Window attached to the view has been Deiconified.
93   Standard_EXPORT void SetViewOn (const Handle(V3d_View)& theView);
94
95   //! Deactivates all the views of a Viewer
96   //! attached to a window.
97   Standard_EXPORT void SetViewOff();
98   
99   //! Deactivates a particular view in the Viewer.
100   //! Must be call if the Window attached to the view
101   //! has been Iconified .
102   Standard_EXPORT void SetViewOff (const Handle(V3d_View)& theView);
103   
104   //! Deprecated, Redraw() should be used instead.
105   void Update() { Redraw(); }
106
107   //! Redraws all the views of the Viewer even if no
108   //! modification has taken place. Must be called if
109   //! all the views of the Viewer are exposed, as for
110   //! example in a global DeIconification.
111   Standard_EXPORT void Redraw() const;
112   
113   //! Updates layer of immediate presentations.
114   Standard_EXPORT void RedrawImmediate() const;
115   
116   //! Invalidates viewer content but does not redraw it.
117   Standard_EXPORT void Invalidate() const;
118   
119   //! Suppresses the Viewer.
120   Standard_EXPORT void Remove();
121
122   //! Return Graphic Driver instance.
123   const Handle(Graphic3d_GraphicDriver)& Driver() const { return myDriver; }
124
125   //! Returns the structure manager associated to this viewer.
126   Handle(Graphic3d_StructureManager) StructureManager() const { return myStructureManager; }
127
128   //! Return default Rendering Parameters.
129   //! By default these parameters are set in a new V3d_View.
130   const Graphic3d_RenderingParams& DefaultRenderingParams() const { return myDefaultRenderingParams; }
131
132   //! Set default Rendering Parameters.
133   void SetDefaultRenderingParams (const Graphic3d_RenderingParams& theParams) { myDefaultRenderingParams = theParams; }
134
135   //! Defines the default background colour of views
136   //! attached to the viewer by supplying the color object
137   void SetDefaultBackgroundColor (const Quantity_Color& theColor) { myBackground.SetColor (theColor); }
138
139   //! Returns the gradient background of the view.
140   const Aspect_GradientBackground& GetGradientBackground() const { return myGradientBackground; }
141   
142   //! Defines the default gradient background colours of views
143   //! attached to the viewer by supplying the colour objects
144   void SetDefaultBgGradientColors (const Quantity_Color& theColor1,
145                                    const Quantity_Color& theColor2,
146                                    const Aspect_GradientFillMethod theFillStyle = Aspect_GFM_HOR)
147   {
148     myGradientBackground.SetColors (theColor1, theColor2, theFillStyle);
149   }
150
151   //! Returns the default size of the view.
152   Standard_Real DefaultViewSize() const { return myViewSize; }
153
154   //! Gives a default size for the creation of views of the viewer.
155   Standard_EXPORT void SetDefaultViewSize (const Standard_Real theSize);
156
157   //! Returns the default Projection.
158   V3d_TypeOfOrientation DefaultViewProj() const { return myViewProj; }
159
160   //! Sets the default projection for creating views in the viewer.
161   void SetDefaultViewProj (const V3d_TypeOfOrientation theOrientation) { myViewProj = theOrientation; }
162
163   //! Returns the default type of Visualization.
164   V3d_TypeOfVisualization DefaultVisualization() const { return myVisualization; }
165
166   //! Gives the default visualization mode.
167   void SetDefaultVisualization (const V3d_TypeOfVisualization theType) { myVisualization = theType; }
168
169   //! Returns the default type of Shading
170   V3d_TypeOfShadingModel DefaultShadingModel() const { return myShadingModel; }
171
172   //! Gives the default type of SHADING.
173   void SetDefaultShadingModel (const V3d_TypeOfShadingModel theType) { myShadingModel = theType; }
174
175   void SetDefaultTypeOfView (const V3d_TypeOfView theType) { myDefaultTypeOfView = theType; }
176
177   //! Returns the default background colour object.
178   Quantity_Color DefaultBackgroundColor() const { return myBackground.Color(); }
179
180   //! Returns the gradient background colour objects of the view.
181   void DefaultBgGradientColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const { myGradientBackground.Colors (theColor1, theColor2); }
182
183   //! Return all Z layer ids in sequence ordered by overlay level from lowest layer to highest ( foreground ).
184   //! The first layer ID in sequence is the default layer that can't be removed.
185   Standard_EXPORT void GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const;
186
187   //! Add a new top-level Z layer to all managed views and get its ID as <theLayerId> value.
188   //! The Z layers are controlled entirely by viewer, it is not possible to add a layer to a particular view.
189   //! The method returns Standard_False if the layer can not be created.
190   //! The layer mechanism allows to display structures in higher layers in overlay of structures in lower layers.
191   Standard_EXPORT Standard_Boolean AddZLayer (Standard_Integer& theLayerId);
192
193   //! Remove Z layer with ID <theLayerId>.
194   //! Method returns Standard_False if the layer can not be removed or doesn't exists.
195   //! By default, there are always default bottom-level layer that can't be removed.
196   Standard_EXPORT Standard_Boolean RemoveZLayer (const Standard_Integer theLayerId);
197
198   //! Returns the settings of a single Z layer.
199   Standard_EXPORT Graphic3d_ZLayerSettings ZLayerSettings (const Standard_Integer theLayerId);
200
201   //! Sets the settings for a single Z layer.
202   Standard_EXPORT void SetZLayerSettings (const Standard_Integer theLayerId, const Graphic3d_ZLayerSettings& theSettings);
203
204 public:
205
206   //! Return an iterator for active views.
207   V3d_ListOfViewIterator ActiveViewIterator() const { return V3d_ListOfViewIterator (myActiveViews); }
208
209   //! Initializes an internal iterator on the active views.
210   void InitActiveViews() { myActiveViewsIterator.Initialize (myActiveViews); }
211
212   //! Returns true if there are more active view(s) to return.
213   Standard_Boolean MoreActiveViews() const { return myActiveViewsIterator.More(); }
214
215   //! Go to the next active view (if there is not, ActiveView will raise an exception)
216   void NextActiveViews() { if (!myActiveViews.IsEmpty()) myActiveViewsIterator.Next(); }
217   
218   const Handle(V3d_View)& ActiveView() const { return myActiveViewsIterator.Value(); }
219   
220   //! returns true if there is only one active view.
221   Standard_Boolean LastActiveView() const { return myActiveViews.Extent() == 1; }
222
223 public:
224
225   //! Return an iterator for defined views.
226   V3d_ListOfViewIterator DefinedViewIterator() const { return V3d_ListOfViewIterator (myDefinedViews); }
227
228   //! Initializes an internal iterator on the Defined views.
229   void InitDefinedViews() { myDefinedViewsIterator.Initialize (myDefinedViews); }
230
231   //! returns true if there are more Defined view(s) to return.
232   Standard_Boolean MoreDefinedViews() const { return myDefinedViewsIterator.More(); }
233
234   //! Go to the next Defined view (if there is not, DefinedView will raise an exception)
235   void NextDefinedViews() { if (!myDefinedViews.IsEmpty()) myDefinedViewsIterator.Next(); }
236
237   const Handle(V3d_View)& DefinedView() const { return myDefinedViewsIterator.Value(); }
238
239 public: //! @name lights management
240
241   //! Defines default lights:
242   //!  positional-light 0.3 0. 0.
243   //!  directional-light V3d_XnegYposZpos
244   //!  directional-light V3d_XnegYneg
245   //!  ambient-light
246   Standard_EXPORT void SetDefaultLights();
247
248   //! Activates MyLight in the viewer.
249   Standard_EXPORT void SetLightOn (const Handle(V3d_Light)& theLight);
250   
251   //! Activates all the lights defined in this viewer.
252   Standard_EXPORT void SetLightOn();
253   
254   //! Deactivates MyLight in this viewer.
255   Standard_EXPORT void SetLightOff (const Handle(V3d_Light)& theLight);
256   
257   //! Deactivate all the Lights defined in this viewer.
258   Standard_EXPORT void SetLightOff();
259
260   //! Adds Light in Sequence Of Lights.
261   Standard_EXPORT void AddLight (const Handle(V3d_Light)& theLight);
262
263   //! Delete Light in Sequence Of Lights.
264   Standard_EXPORT void DelLight (const Handle(V3d_Light)& theLight);
265   
266   //! Updates the lights of all the views of a viewer.
267   Standard_EXPORT void UpdateLights();
268
269   Standard_EXPORT Standard_Boolean IsGlobalLight (const Handle(V3d_Light)& TheLight) const;
270
271   //! Return an iterator for defined lights.
272   V3d_ListOfLightIterator ActiveLightIterator() const { return V3d_ListOfLightIterator (myActiveLights); }
273
274   //! Initializes an internal iteratator on the active Lights.
275   void InitActiveLights() { myActiveLightsIterator.Initialize (myActiveLights); }
276
277   //! returns true if there are more active Light(s) to return.
278   Standard_Boolean MoreActiveLights() const { return myActiveLightsIterator.More(); }
279
280   //! Go to the next active Light (if there is not, ActiveLight() will raise an exception)
281   void NextActiveLights() { myActiveLightsIterator.Next(); }
282
283   const Handle(V3d_Light)& ActiveLight() const { return myActiveLightsIterator.Value(); }
284
285 public:
286
287   //! Return an iterator for defined lights.
288   V3d_ListOfLightIterator DefinedLightIterator() const { return V3d_ListOfLightIterator (myDefinedLights); }
289
290   //! Initializes an internal iterattor on the Defined Lights.
291   void InitDefinedLights() { myDefinedLightsIterator.Initialize (myDefinedLights); }
292   
293   //! Returns true if there are more Defined Light(s) to return.
294   Standard_Boolean MoreDefinedLights() const { return myDefinedLightsIterator.More(); }
295
296   //! Go to the next Defined Light (if there is not, DefinedLight() will raise an exception)
297   void NextDefinedLights() { if (!myDefinedLights.IsEmpty()) myDefinedLightsIterator.Next(); }
298
299   const Handle(V3d_Light)& DefinedLight() const { return myDefinedLightsIterator.Value(); }
300
301 public: //! @name objects management
302
303   //! Erase all Objects in All the views.
304   Standard_EXPORT void Erase() const;
305
306   //! UnHighlight all Objects in All the views.
307   Standard_EXPORT void UnHighlight() const;
308
309 public:
310
311   //! returns true if the computed mode can be used.
312   Standard_Boolean ComputedMode() const { return myComputedMode; }
313
314   //! Set if the computed mode can be used.
315   void SetComputedMode (const Standard_Boolean theMode) { myComputedMode = theMode; }
316
317   //! returns true if by default the computed mode must be used.
318   Standard_Boolean DefaultComputedMode() const { return myDefaultComputedMode; }
319
320   //! Set if by default the computed mode must be used.
321   void SetDefaultComputedMode (const Standard_Boolean theMode) { myDefaultComputedMode = theMode; }
322
323 public: //! @name privileged plane management
324
325   const gp_Ax3& PrivilegedPlane() const { return myPrivilegedPlane; }
326
327   Standard_EXPORT void SetPrivilegedPlane (const gp_Ax3& thePlane);
328
329   Standard_EXPORT void DisplayPrivilegedPlane (const Standard_Boolean theOnOff, const Standard_Real theSize = 1);
330
331 public: //! @name grid management
332
333   //! Activates the grid in all views of <me>.
334   Standard_EXPORT void ActivateGrid (const Aspect_GridType aGridType, const Aspect_GridDrawMode aGridDrawMode);
335   
336   //! Deactivates the grid in all views of <me>.
337   Standard_EXPORT void DeactivateGrid();
338   
339   //! Show/Don't show grid echo to the hit point.
340   //! If TRUE,the grid echo will be shown at ConvertToGrid() time.
341   Standard_EXPORT void SetGridEcho (const Standard_Boolean showGrid = Standard_True);
342   
343   //! Show grid echo <aMarker> to the hit point.
344   //! Warning: When the grid echo marker is not set,
345   //! a default marker is build with the attributes:
346   //! marker type : Aspect_TOM_STAR
347   //! marker color : Quantity_NOC_GRAY90
348   //! marker size : 3.0
349   Standard_EXPORT void SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& aMarker);
350   
351   //! Returns TRUE when grid echo must be displayed at hit point.
352   Standard_Boolean GridEcho() const { return myGridEcho; }
353   
354   //! Returns Standard_True if a grid is activated in <me>.
355   Standard_EXPORT Standard_Boolean IsActive() const;
356   
357   //! Returns the defined grid in <me>.
358   Standard_EXPORT Handle(Aspect_Grid) Grid() const;
359
360   //! Returns the current grid type defined in <me>.
361   Aspect_GridType GridType() const { return myGridType; }
362   
363   //! Returns the current grid draw mode defined in <me>.
364   Standard_EXPORT Aspect_GridDrawMode GridDrawMode() const;
365   
366   //! Returns the definition of the rectangular grid.
367   Standard_EXPORT void RectangularGridValues (Standard_Real& XOrigin, Standard_Real& YOrigin, Standard_Real& XStep, Standard_Real& YStep, Standard_Real& RotationAngle) const;
368   
369   //! Sets the definition of the rectangular grid.
370   //! <XOrigin>, <YOrigin> defines the origin of the grid.
371   //! <XStep> defines the interval between 2 vertical lines.
372   //! <YStep> defines the interval between 2 horizontal lines.
373   //! <RotationAngle> defines the rotation angle of the grid.
374   Standard_EXPORT void SetRectangularGridValues (const Standard_Real XOrigin, const Standard_Real YOrigin, const Standard_Real XStep, const Standard_Real YStep, const Standard_Real RotationAngle);
375   
376   //! Returns the definition of the circular grid.
377   Standard_EXPORT void CircularGridValues (Standard_Real& XOrigin, Standard_Real& YOrigin, Standard_Real& RadiusStep, Standard_Integer& DivisionNumber, Standard_Real& RotationAngle) const;
378   
379   //! Sets the definition of the circular grid.
380   //! <XOrigin>, <YOrigin> defines the origin of the grid.
381   //! <RadiusStep> defines the interval between 2 circles.
382   //! <DivisionNumber> defines the section number of one half circle.
383   //! <RotationAngle> defines the rotation angle of the grid.
384   Standard_EXPORT void SetCircularGridValues (const Standard_Real XOrigin, const Standard_Real YOrigin, const Standard_Real RadiusStep, const Standard_Integer DivisionNumber, const Standard_Real RotationAngle);
385   
386   //! Returns the location and the size of the grid.
387   Standard_EXPORT void CircularGridGraphicValues (Standard_Real& Radius, Standard_Real& OffSet) const;
388   
389   //! Sets the location and the size of the grid.
390   //! <XSize> defines the width of the grid.
391   //! <YSize> defines the height of the grid.
392   //! <OffSet> defines the displacement along the plane normal.
393   Standard_EXPORT void SetCircularGridGraphicValues (const Standard_Real Radius, const Standard_Real OffSet);
394   
395   //! Returns the location and the size of the grid.
396   Standard_EXPORT void RectangularGridGraphicValues (Standard_Real& XSize, Standard_Real& YSize, Standard_Real& OffSet) const;
397   
398   //! Sets the location and the size of the grid.
399   //! <XSize> defines the width of the grid.
400   //! <YSize> defines the height of the grid.
401   //! <OffSet> defines the displacement along the plane normal.
402   Standard_EXPORT void SetRectangularGridGraphicValues (const Standard_Real XSize, const Standard_Real YSize, const Standard_Real OffSet);
403   
404   //! Display grid echo at requested point in the view.
405   Standard_EXPORT void ShowGridEcho (const Handle(V3d_View)& theView, const Graphic3d_Vertex& thePoint);
406
407   //! Temporarly hide grid echo.
408   Standard_EXPORT void HideGridEcho (const Handle(V3d_View)& theView);
409
410 public: //! @name deprecated methods
411
412   Standard_DEPRECATED("This constructor is deprecated")
413   Standard_EXPORT V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver,
414                               const Standard_ExtString theName,
415                               const Standard_CString theDomain = "",
416                               const Standard_Real theViewSize = 1000.0,
417                               const V3d_TypeOfOrientation theViewProj = V3d_XposYnegZpos,
418                               const Quantity_Color& theViewBackground = Quantity_NOC_GRAY30,
419                               const V3d_TypeOfVisualization theVisualization = V3d_ZBUFFER,
420                               const V3d_TypeOfShadingModel theShadingModel = V3d_GOURAUD,
421                               const Standard_Boolean theComputedMode = Standard_True,
422                               const Standard_Boolean theDefaultComputedMode = Standard_True);
423
424   //! Defines the default base colour of views attached
425   //! to the Viewer by supplying the type of colour
426   //! definition and the three component values.
427   Standard_DEPRECATED("This method is deprecated - SetDefaultBackgroundColor() taking Quantity_Color should be used instead")
428   void SetDefaultBackgroundColor (const Quantity_TypeOfColor theType,
429                                   const Standard_Real theV1,
430                                   const Standard_Real theV2,
431                                   const Standard_Real theV3)
432   {
433     Standard_Real aV1 = theV1;
434     Standard_Real aV2 = theV2;
435     Standard_Real aV3 = theV3;
436     if (aV1 < 0.0) aV1 = 0.0; else if (aV1 > 1.0) aV1 = 1.0;
437     if (aV2 < 0.0) aV2 = 0.0; else if (aV2 > 1.0) aV2 = 1.0;
438     if (aV3 < 0.0) aV3 = 0.0; else if (aV3 > 1.0) aV3 = 1.0;
439     SetDefaultBackgroundColor (Quantity_Color (aV1, aV2, aV3, theType));
440   }
441
442   Standard_DEPRECATED("This method is deprecated - DefaultBackgroundColor() without arguments should be used instead")
443   void DefaultBackgroundColor (const Quantity_TypeOfColor theType, Standard_Real& theV1, Standard_Real& theV2, Standard_Real& theV3) const
444   {
445     Quantity_Color aColor = DefaultBackgroundColor();
446     aColor.Values (theV1, theV2, theV3, theType) ;
447   }
448
449 private:
450
451   //! Returns the default background colour.
452   const Aspect_Background& GetBackgroundColor() const { return myBackground; }
453
454   //! Adds View in Sequence Of Views.
455   Standard_EXPORT void AddView (const Handle(V3d_View)& theView);
456   
457   //! Delete View in Sequence Of Views.
458   Standard_EXPORT void DelView (const Handle(V3d_View)& theView);
459   
460 private:
461
462   Handle(Graphic3d_GraphicDriver) myDriver;
463   Handle(Graphic3d_StructureManager) myStructureManager;
464   TColStd_MapOfInteger myLayerIds;
465   Aspect_GenId myZLayerGenId;
466
467   V3d_ListOfView  myDefinedViews;
468   V3d_ListOfView  myActiveViews;
469   V3d_ListOfLight myDefinedLights;
470   V3d_ListOfLight myActiveLights;
471
472   Aspect_Background myBackground;
473   Aspect_GradientBackground myGradientBackground;
474   Standard_Real myViewSize;
475   V3d_TypeOfOrientation myViewProj;
476   V3d_TypeOfVisualization myVisualization;
477   V3d_TypeOfShadingModel myShadingModel;
478   V3d_TypeOfView myDefaultTypeOfView;
479   Graphic3d_RenderingParams myDefaultRenderingParams;
480
481   V3d_ListOfView::Iterator  myActiveViewsIterator;
482   V3d_ListOfView::Iterator  myDefinedViewsIterator;
483   V3d_ListOfLight::Iterator myActiveLightsIterator;
484   V3d_ListOfLight::Iterator myDefinedLightsIterator;
485
486   Standard_Boolean myComputedMode;
487   Standard_Boolean myDefaultComputedMode;
488
489   gp_Ax3 myPrivilegedPlane;
490   Handle(Graphic3d_Structure) myPlaneStructure;
491   Standard_Boolean myDisplayPlane;
492   Standard_Real myDisplayPlaneLength;
493
494   Handle(V3d_RectangularGrid) myRGrid;
495   Handle(V3d_CircularGrid) myCGrid;
496   Aspect_GridType myGridType;
497   Standard_Boolean myGridEcho;
498   Handle(Graphic3d_Structure) myGridEchoStructure;
499   Handle(Graphic3d_Group) myGridEchoGroup;
500   Handle(Graphic3d_AspectMarker3d) myGridEchoAspect;
501   Graphic3d_Vertex myGridEchoLastVert;
502
503 };
504
505 DEFINE_STANDARD_HANDLE(V3d_Viewer, Standard_Transient)
506
507 #endif // _V3d_Viewer_HeaderFile