0024070: OpenGL capped object-level clipping planes
[occt.git] / src / V3d / V3d_Viewer.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18/***********************************************************************
19
20 FONCTION :
21 ----------
22 Classe V3d_Viewer :
23
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 00-09-92 : GG ; Creation.
27 15-11-97 : FMN ; Ajout texture mapping
28 02-02-98 : FMN ; Mise a niveau WNT
29 23-02-98 : FMN ; Remplacement PI par Standard_PI
30 16-07-98 : CAL ; S3892. Ajout grilles 3d.
31
32************************************************************************/
33
b8ddfc2f 34//GER61351 //GG_15/12/99 Adds SetDefaultBackgroundColor() and DefaultBackgroundColor() methods
7fd59977 35
36#define IMP240100 //GG
37// Initalize grid echo fields
38
39/*----------------------------------------------------------------------*/
40/*
41 * Includes
42 */
43
44#include <V3d.hxx>
45#include <Visual3d_View.hxx>
46#include <Visual3d_Light.hxx>
47#include <V3d_Viewer.ixx>
48#include <V3d_View.hxx>
6942f04a 49#include <V3d_BadValue.hxx>
7fd59977 50#include <V3d_OrthographicView.hxx>
51#include <V3d_PerspectiveView.hxx>
7fd59977 52
53/*----------------------------------------------------------------------*/
54
55//-Constructor:
6942f04a 56V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver,
57 const Standard_ExtString theName,
58 const Standard_CString theDomain,
59 const Standard_Real theViewSize,
60 const V3d_TypeOfOrientation theViewProj,
61 const Quantity_NameOfColor theViewBackground,
62 const V3d_TypeOfVisualization theVisualization,
63 const V3d_TypeOfShadingModel theShadingModel,
64 const V3d_TypeOfUpdate theUpdateMode,
65 const Standard_Boolean theComputedMode,
66 const Standard_Boolean theDefaultComputedMode,
67 const V3d_TypeOfSurfaceDetail theSurfaceDetail)
68:myNextCount (-1),
69myDriver (theDriver),
70myName (TCollection_ExtendedString (theName)),
71myDomain (TCollection_AsciiString (theDomain)),
7fd59977 72MyDefinedViews(),
73MyActiveViews(),
74MyDefinedLights(),
75MyActiveLights(),
7fd59977 76myActiveViewsIterator(),
77myDefinedViewsIterator(),
78myActiveLightsIterator(),
79myDefinedLightsIterator(),
6942f04a 80myComputedMode (theComputedMode),
81myDefaultComputedMode (theDefaultComputedMode),
82myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))),
83myDisplayPlane (Standard_False),
84myDisplayPlaneLength (theViewSize)
7fd59977 85#ifdef IMP240100
6942f04a 86,myGridEcho (Standard_True), myGridEchoStructure(), myGridEchoGroup()
7fd59977 87#endif
88{
6942f04a 89 MyViewer = new Visual3d_ViewManager (theDriver);
7fd59977 90 // san (16/09/2010): It has been decided to turn depth test ON
91 // by default, as this is important for new font rendering
92 // (without it, there are numerous texture rendering artefacts)
93 MyViewer->SetZBufferAuto (Standard_False);
6942f04a 94 SetUpdateMode (theUpdateMode);
95 SetDefaultViewSize (theViewSize);
96 SetDefaultViewProj (theViewProj);
97 SetDefaultBackgroundColor (theViewBackground);
98 SetDefaultVisualization (theVisualization);
99 SetDefaultShadingModel (theShadingModel);
100 SetDefaultSurfaceDetail (theSurfaceDetail);
101 SetDefaultAngle (M_PI / 2.);
102 SetDefaultTypeOfView (V3d_ORTHOGRAPHIC);
7fd59977 103
104 Quantity_Color Color1 (Quantity_NOC_GRAY50);
105 Quantity_Color Color2 (Quantity_NOC_GRAY70);
106// Quantity_Color White (Quantity_NOC_WHITE);
6942f04a 107 myRGrid = new V3d_RectangularGrid (this, Color1, Color2);
108 myCGrid = new V3d_CircularGrid (this, Color1, Color2);
7fd59977 109 myGridType = Aspect_GT_Rectangular;
110}
111
112//-Methods, in order
113
114
115Handle(V3d_View) V3d_Viewer::CreateView () {
116 if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC)
117 return new V3d_OrthographicView(this);
118 else
119 return new V3d_PerspectiveView(this);
120}
121
122void V3d_Viewer::SetViewOn( ) {
123
124 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
125 SetViewOn(ActiveView());};
126}
127
128Handle(V3d_OrthographicView) V3d_Viewer::DefaultOrthographicView() {
129
130 return MyDefaultOrthographicView;
131}
132
133Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () {
134
135 return MyDefaultPerspectiveView;
136}
137
138void V3d_Viewer::SetViewOff( ) {
139
140 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
141 SetViewOff(ActiveView());};
142}
143
144void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {
145
146 Handle(Visual3d_View) MyView = TheView->View() ;
147 if( MyView->IsDefined() && !IsActive(TheView)) {
148 MyActiveViews.Append(TheView) ;
149 MyView->Activate();
150 for (InitActiveLights();MoreActiveLights();NextActiveLights()){
151 TheView->SetLightOn(ActiveLight());}
152 // Grid
153 TheView->SetGrid (myPrivilegedPlane, Grid ());
154 TheView->SetGridActivity (Grid ()->IsActive ());
155 // Update
156 MyView->Redraw() ;
157 }
158}
159
160void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
161
162 Handle(Visual3d_View) MyView =TheView->View();
163 if( MyView->IsDefined() && IsActive(TheView) ) {
164 MyActiveViews.Remove(TheView);
165 MyView->Deactivate() ;
166 }
167}
168
169Standard_Boolean V3d_Viewer::ComputedMode() const {
170 return myComputedMode;
171}
172
173Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
174 return myDefaultComputedMode;
175}
176
177void V3d_Viewer::Update() {
178
179 MyViewer->Update();
180}
181
182void V3d_Viewer::Redraw()const {
183
184 MyViewer->Redraw();
185}
186
187void V3d_Viewer::Remove() {
188
189 MyViewer->Remove();
190}
191
192void V3d_Viewer::Erase() const {
193
194 MyViewer->Erase();
195}
196
197void V3d_Viewer::UnHighlight() const {
198
199 //FMN MyViewer->UnHighlight();
200}
201
202void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
203 Standard_Real V1 = v1 ;
204 Standard_Real V2 = v2 ;
205 Standard_Real V3 = v3 ;
206
207 if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
208 if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
209 if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
210
211 Quantity_Color C(V1,V2,V3,Type) ;
7fd59977 212 SetDefaultBackgroundColor(C);
7fd59977 213}
214
b8ddfc2f 215void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name)
216{
7fd59977 217 Quantity_Color C(Name) ;
7fd59977 218 SetDefaultBackgroundColor(C);
7fd59977 219}
220
b8ddfc2f 221void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color)
222{
7fd59977 223 MyBackground.SetColor(Color) ;
224}
7fd59977 225
226void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
227 const Quantity_NameOfColor Name2,
228 const Aspect_GradientFillMethod FillStyle){
229
230 Quantity_Color C1(Name1) ;
231 Quantity_Color C2(Name2) ;
232 MyGradientBackground.SetColors(C1, C2, FillStyle);
233
234}
235
236void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1,
237 const Quantity_Color& Color2,
238 const Aspect_GradientFillMethod FillStyle ){
239
240 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
241
242}
243
244
245void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {
246
6942f04a 247 V3d_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
7fd59977 248 MyViewSize = Size ;
249}
250
251void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {
252
253 MyViewProj = Orientation ;
254}
255
256void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) {
257
258 MyVisualization = Type ;
259}
260void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
261 MyViewer->SetZBufferAuto (Automatic);
262}
263Standard_Boolean V3d_Viewer::ZBufferManagment() const {
264 return MyViewer->ZBufferAuto();
265}
266
267void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
268
269 MyShadingModel = Type ;
270}
271
272void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {
273
274 MySurfaceDetail = Type ;
275}
276
277void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
278 MyDefaultAngle = Angle;
279}
280
281void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
282 MyDefaultTypeOfView = Type;}
283
284
285void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
286
287 MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
288}
289
b8ddfc2f 290void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const
291{
7fd59977 292 Quantity_Color C = DefaultBackgroundColor();
7fd59977 293 C.Values(V1,V2,V3,Type) ;
294}
295
b8ddfc2f 296Quantity_Color V3d_Viewer::DefaultBackgroundColor() const
297{
7fd59977 298 return MyBackground.Color() ;
299}
7fd59977 300
b8ddfc2f 301void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const
302{
7fd59977 303 MyGradientBackground.Colors(Color1,Color2);
304}
305
306Standard_Real V3d_Viewer::DefaultViewSize() const {
307 return MyViewSize ;
308}
309
310V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
311 return MyViewProj ;
312}
313
314V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
315 return MyVisualization ;
316}
317
318V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
319 return MyShadingModel ;
320}
321
322V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
323 return MySurfaceDetail ;
324}
325
326Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
327 return MyDefaultAngle;
328}
329
330V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
331
332 V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
333 return Mode ;
334}
335
336Standard_Boolean V3d_Viewer::IfMoreViews() const {
337 Standard_Boolean TheStatus = Standard_False ;
338
339#ifdef NEW
340 if( MyActiveViews->Length() < Visual3d_View::Limit() )
341#endif /*NEW*/
342 TheStatus = Standard_True ;
343 return TheStatus ;
344}
345
346Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
347 return MyViewer ;
348}
349
350Aspect_Background V3d_Viewer::GetBackgroundColor() const {
351 return MyBackground ;
352}
353
354Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
355 return MyGradientBackground;
356}
357
358void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {
359
360 MyDefinedViews.Append(TheView);
361 IncrCount();
362}
363
364void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {
365
366 MyActiveViews.Remove(TheView);
367 MyDefinedViews.Remove(TheView);
368}
369
59f45b7c 370//=======================================================================
371//function : AddZLayer
372//purpose :
373//=======================================================================
374
375Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
376{
377 return MyViewer->AddZLayer (theLayerId);
378}
379
380//=======================================================================
381//function : RemoveZLayer
382//purpose :
383//=======================================================================
384
385Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
386{
387 return MyViewer->RemoveZLayer (theLayerId);
388}
389
390//=======================================================================
391//function : GetAllZLayers
392//purpose :
393//=======================================================================
394
395void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
396{
397 MyViewer->GetAllZLayers (theLayerSeq);
398}
6942f04a 399
400//=======================================================================
401//function : Domain
402//purpose :
403//=======================================================================
404
405Standard_CString V3d_Viewer::Domain() const
406{
407 return myDomain.ToCString();
408}
409
410//=======================================================================
411//function : Driver
412//purpose :
413//=======================================================================
414
415const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const
416{
417 return myDriver;
418}
419
420//=======================================================================
421//function : NextName
422//purpose :
423//=======================================================================
424
425Standard_ExtString V3d_Viewer::NextName() const
426{
427 TCollection_ExtendedString aNextName = TCollection_ExtendedString (myName.ToExtString());
428 aNextName.AssignCat (TCollection_ExtendedString (myNextCount));
429
430 return aNextName.ToExtString();
431}
432
433//=======================================================================
434//function : IncrCount
435//purpose :
436//=======================================================================
437
438void V3d_Viewer::IncrCount()
439{
440 myNextCount++;
441}