0024610: Visualization, Visual3d_View::MinMaxValues() - skip erased objects while...
[occt.git] / src / Visual3d / Visual3d_View.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
d4f1753b 15#ifdef _WIN32
16 #include <windows.h>
7fd59977 17#endif
18
7fd59977 19#include <Visual3d_View.ixx>
7fd59977 20
7fd59977 21#include <Graphic3d_DataStructureManager.hxx>
7fd59977 22#include <Graphic3d_GraphicDriver.hxx>
d4f1753b 23#include <Graphic3d_MapOfStructure.hxx>
24#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
25#include <Graphic3d_Structure.hxx>
26#include <Graphic3d_TextureEnv.hxx>
7fd59977 27#include <Graphic3d_Vector.hxx>
28#include <Graphic3d_Vertex.hxx>
d4f1753b 29#include <Visual3d_DepthCueingDefinitionError.hxx>
7fd59977 30#include <Visual3d_Light.hxx>
54f7544d 31#include <Visual3d_HSequenceOfView.hxx>
d4f1753b 32#include <Visual3d_ZClippingDefinitionError.hxx>
33#include <OSD.hxx>
7fd59977 34#include <TColStd_HArray2OfReal.hxx>
35
d4f1753b 36#if defined(_WIN32)
4fe56619 37 #include <WNT_Window.hxx>
38#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
39 #include <Cocoa_Window.hxx>
7fd59977 40#else
4fe56619 41 #include <Xw_Window.hxx>
42#endif
7fd59977 43
44#include <float.h>
45
d4f1753b 46// =======================================================================
47// function : Visual3d_View
48// purpose :
49// =======================================================================
50Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& theMgr)
51: myViewManager (theMgr.operator->()),
52 myIsInComputedMode (Standard_False),
53 myAutoZFitIsOn (Standard_True),
6bc6a6fc 54 myAutoZFitScaleFactor (1.0),
d4f1753b 55 myStructuresUpdated (Standard_True)
7fd59977 56{
d4f1753b 57 MyCView.ViewId = theMgr->Identification (this);
58 MyCView.Active = 0;
59 MyCView.IsDeleted = 0;
60 MyCView.WsId = -1;
61 MyCView.DefWindow.IsDefined = 0;
62 MyCView.Context.NbActiveLight = 0;
63 MyCView.Context.ZBufferActivity = -1;
7fd59977 64
d4f1753b 65 MyCView.Backfacing = 0;
66 MyCView.ptrUnderLayer = 0;
67 MyCView.ptrOverLayer = 0;
68 MyCView.GContext = 0;
69 MyCView.GDisplayCB = 0;
70 MyCView.GClientData = 0;
7fd59977 71
d4f1753b 72 myGraphicDriver = myViewManager->GraphicDriver();
7fd59977 73}
74
d4f1753b 75// =======================================================================
76// function : SetWindow
77// purpose :
78// =======================================================================
79void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow,
80 const Aspect_RenderingContext theContext,
81 const Aspect_GraphicCallbackProc& theDisplayCB,
82 const Standard_Address theClientData)
7fd59977 83{
d4f1753b 84 if (IsDeleted())
85 {
86 return;
87 }
88 else if (IsDefined())
89 {
7fd59977 90 Visual3d_ViewDefinitionError::Raise ("Window already defined");
d4f1753b 91 }
7fd59977 92
d4f1753b 93 MyCView.GContext = theContext;
94 MyCView.GDisplayCB = theDisplayCB;
95 MyCView.GClientData = theClientData;
96 SetWindow (theWindow);
7fd59977 97}
7fd59977 98
d4f1753b 99// =======================================================================
100// function : SetWindow
101// purpose :
102// =======================================================================
4fe56619 103void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
104{
d4f1753b 105 if (IsDeleted())
106 {
107 return;
108 }
109 else if (IsDefined())
b5ac8292 110 {
111 Visual3d_ViewDefinitionError::Raise ("Window already defined");
112 }
4fe56619 113
b5ac8292 114 MyWindow = theWindow;
115 MyCView.WsId = MyCView.ViewId;
116 MyCView.DefWindow.IsDefined = 1;
d4f1753b 117#if defined(_WIN32)
4fe56619 118 const Handle(WNT_Window) aWin = Handle(WNT_Window)::DownCast (theWindow);
119 MyCView.DefWindow.XWindow = (HWND )(aWin->HWindow());
120 MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow());
121 WNT_WindowData* aWinData = (WNT_WindowData* )GetWindowLongPtr ((HWND )(aWin->HWindow()), GWLP_USERDATA);
122 aWinData->WNT_WDriver_Ptr = (void* )this;
d4f1753b 123 aWinData->WNT_VMgr = myViewManager;
4fe56619 124#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
125 const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow);
126 MyCView.DefWindow.XWindow = (Aspect_Drawable )aWin->HView();
127 MyCView.DefWindow.XParentWindow = NULL;
128 //MyCView.DefWindow.XParentWindow = aWin->HParentWindow();
7fd59977 129#else
4fe56619 130 const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow);
131 MyCView.DefWindow.XWindow = aWin->XWindow();
ed97f43c 132 //MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
7fd59977 133#endif
7fd59977 134
d4f1753b 135 Standard_Integer Width, Height;
136 theWindow->Size (Width, Height);
137 MyCView.DefWindow.dx = float(Width);
138 MyCView.DefWindow.dy = float(Height);
7fd59977 139
d4f1753b 140 Standard_Real R, G, B;
141 MyBackground = MyWindow->Background ();
142 MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
143 MyCView.DefWindow.Background.r = float (R);
144 MyCView.DefWindow.Background.g = float (G);
145 MyCView.DefWindow.Background.b = float (B);
7fd59977 146
d4f1753b 147 UpdateView();
148 if (!myGraphicDriver->View (MyCView))
149 {
150 Visual3d_ViewDefinitionError::Raise ("Association failed");
151 }
7fd59977 152
d4f1753b 153 MyGradientBackground = MyWindow->GradientBackground();
154 SetGradientBackground(MyGradientBackground,1);
71c4f9c6 155
d4f1753b 156 Standard_Boolean AWait = Standard_False; // => immediate update
157 myGraphicDriver->SetVisualisation (MyCView);
158 myGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn());
159 myGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn());
160 myGraphicDriver->ClipLimit (MyCView, AWait);
161 myGraphicDriver->Environment (MyCView);
7fd59977 162
d4f1753b 163 // Make view manager z layer list consistent with the view's list.
164 myViewManager->InstallZLayers (this);
7fd59977 165
d4f1753b 166 // Update planses of model clipping
167 UpdatePlanes();
7fd59977 168
d4f1753b 169 // Update light sources
170 UpdateLights();
7fd59977 171
d4f1753b 172 // Association view-window does not cause the display
173 // of structures that can be displayed in the new view.
174 // In fact, association view-window is done, but the
175 // display is produced only if the view is activated (Activate).
176 SetRatio();
7fd59977 177}
178
d4f1753b 179// =======================================================================
180// function : Window
181// purpose :
182// =======================================================================
183Handle(Aspect_Window) Visual3d_View::Window() const
184{
185 if (!IsDefined())
186 {
187 Visual3d_ViewDefinitionError::Raise ("Window not defined");
188 }
189 return MyWindow;
7fd59977 190}
191
d4f1753b 192// =======================================================================
193// function : IsDefined
194// purpose :
195// =======================================================================
196Standard_Boolean Visual3d_View::IsDefined() const
197{
198 return MyCView.DefWindow.IsDefined != 0;
7fd59977 199}
200
d4f1753b 201// =======================================================================
202// function : IsDeleted
203// purpose :
204// =======================================================================
205Standard_Boolean Visual3d_View::IsDeleted() const
206{
207 return MyCView.IsDeleted != 0;
7fd59977 208}
209
d4f1753b 210// =======================================================================
211// function : Destroy
212// purpose :
213// =======================================================================
214void Visual3d_View::Destroy()
215{
216 // Since myViewManager can be already destroyed,
217 // avoid attempts to access it in SetBackground()
218 myViewManager = NULL;
219 Remove();
7fd59977 220}
221
d4f1753b 222// =======================================================================
223// function : Remove
224// purpose :
225// =======================================================================
226void Visual3d_View::Remove()
227{
228 if (IsDeleted()
229 || !IsDefined())
230 {
231 return;
232 }
7fd59977 233
d4f1753b 234 myStructsToCompute.Clear();
235 myStructsComputed .Clear();
236 myStructsDisplayed.Clear();
7fd59977 237
d4f1753b 238 Aspect_GradientBackground aBlackGrad;
239 SetBackground (Aspect_Background (Quantity_NOC_BLACK));
240 SetGradientBackground (aBlackGrad, Standard_False);
7fd59977 241
d4f1753b 242 if (myViewManager != NULL)
243 {
244 myViewManager->UnIdentification (MyCView.ViewId);
245 }
7fd59977 246
d4f1753b 247 myGraphicDriver->RemoveView (MyCView);
bd92cc2a 248
d4f1753b 249 MyCView.WsId = -1;
250 MyCView.IsDeleted = 1;
251 MyCView.DefWindow.IsDefined = 0;
7fd59977 252
d4f1753b 253 MyWindow.Nullify();
7fd59977 254}
255
d4f1753b 256// =======================================================================
257// function : Resized
258// purpose :
259// =======================================================================
260void Visual3d_View::Resized()
261{
262 if (IsDeleted())
263 {
264 return;
265 }
266 else if (!IsDefined())
267 {
268 Visual3d_ViewDefinitionError::Raise ("Window not defined");
269 }
270 MyWindow->DoResize();
271 SetRatio();
7fd59977 272}
273
d4f1753b 274// =======================================================================
275// function : SetRatio
276// purpose :
277// =======================================================================
b5ac8292 278void Visual3d_View::SetRatio()
279{
280 if (IsDeleted())
281 {
282 return;
283 }
7fd59977 284
d4f1753b 285 const Aspect_TypeOfUpdate anUpdateMode = myViewManager->UpdateMode();
286 myViewManager->SetUpdateMode (Aspect_TOU_WAIT);
7fd59977 287
b5ac8292 288 Standard_Integer aWidth, aHeight;
b5ac8292 289 MyWindow->Size (aWidth, aHeight);
d4f1753b 290 if (aWidth > 0 && aHeight > 0)
b5ac8292 291 {
292 Standard_Real aRatio = (Standard_Real)aWidth / (Standard_Real)aHeight;
7fd59977 293
b5ac8292 294 MyCView.DefWindow.dx = Standard_ShortReal (aWidth);
295 MyCView.DefWindow.dy = Standard_ShortReal (aHeight);
7fd59977 296
d4f1753b 297 myGraphicDriver->RatioWindow (MyCView);
7fd59977 298
b5ac8292 299 // Update camera aspect
d4f1753b 300 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
b5ac8292 301 if (!aCamera.IsNull())
302 {
303 aCamera->SetAspect (aRatio);
304 }
7fd59977 305
b5ac8292 306 if (!myDefaultCamera.IsNull())
307 {
308 myDefaultCamera->SetAspect (aRatio);
309 }
310 }
7fd59977 311
d4f1753b 312 myViewManager->SetUpdateMode (anUpdateMode);
313 Update (anUpdateMode);
7fd59977 314}
315
d4f1753b 316// =======================================================================
317// function : UpdateLights
318// purpose :
319// =======================================================================
12381341 320void Visual3d_View::UpdateLights()
321{
322 if (IsDeleted()
323 || !IsDefined())
324 {
325 return;
326 }
7fd59977 327
12381341 328 if (MyContext.Model() == Visual3d_TOM_NONE)
329 {
330 // activate only a white ambient light
331 Graphic3d_CLight aCLight;
332 aCLight.Type = Visual3d_TOLS_AMBIENT;
333 aCLight.IsHeadlight = Standard_False;
334 aCLight.Color.r() = aCLight.Color.g() = aCLight.Color.b() = 1.0f;
7fd59977 335
7fd59977 336 MyCView.Context.NbActiveLight = 1;
12381341 337 MyCView.Context.ActiveLight = &aCLight;
d4f1753b 338 myGraphicDriver->SetLight (MyCView);
12381341 339 MyCView.Context.ActiveLight = NULL;
340 return;
7fd59977 341 }
7fd59977 342
12381341 343 MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(),
d4f1753b 344 myGraphicDriver->InquireLightLimit());
12381341 345 if (MyCView.Context.NbActiveLight < 1)
346 {
d4f1753b 347 myGraphicDriver->SetLight (MyCView);
12381341 348 return;
349 }
7fd59977 350
12381341 351 // parcing of light sources
352 MyCView.Context.ActiveLight = new Graphic3d_CLight[MyCView.Context.NbActiveLight];
353 for (Standard_Integer aLightIter = 0; aLightIter < MyCView.Context.NbActiveLight; ++aLightIter)
354 {
355 MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight();
356 }
d4f1753b 357 myGraphicDriver->SetLight (MyCView);
12381341 358 delete[] MyCView.Context.ActiveLight;
359 MyCView.Context.ActiveLight = NULL;
7fd59977 360}
361
d4f1753b 362// =======================================================================
363// function : UpdatePlanes
364// purpose :
365// =======================================================================
51b10cd4 366void Visual3d_View::UpdatePlanes()
4269bd1b 367{
51b10cd4 368 MyCView.Context.ClipPlanes = MyContext.ClipPlanes();
4269bd1b 369 if (IsDeleted() || !IsDefined())
51b10cd4 370 {
4269bd1b 371 return;
51b10cd4 372 }
7fd59977 373
d4f1753b 374 myGraphicDriver->SetClipPlanes (MyCView);
7fd59977 375}
376
d4f1753b 377// =======================================================================
378// function : SetBackground
379// purpose :
380// =======================================================================
381void Visual3d_View::SetBackground (const Aspect_Background& theBack)
382{
383 if (IsDeleted())
384 {
385 return;
386 }
387 else if (!IsDefined())
388 {
389 Visual3d_ViewDefinitionError::Raise ("Window not defined");
390 }
7fd59977 391
d4f1753b 392 // At this level, only GL can update the background.
393 // It is not necessary to call MyWindow->SetBackground (ABack); as
394 // this method starts update of window background by X
395 // (if the windowing is X)
7fd59977 396
d4f1753b 397 Standard_Real R, G, B;
398 MyBackground = theBack;
399 MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
400 MyCView.DefWindow.Background.r = float (R);
401 MyCView.DefWindow.Background.g = float (G);
402 MyCView.DefWindow.Background.b = float (B);
7fd59977 403
d4f1753b 404 myGraphicDriver->Background (MyCView);
7fd59977 405
d4f1753b 406 if (myViewManager != NULL)
407 {
408 Update (myViewManager->UpdateMode());
409 }
7fd59977 410}
411
d4f1753b 412// =======================================================================
413// function : SetGradientBackground
414// purpose :
415// =======================================================================
416void Visual3d_View::SetGradientBackground (const Aspect_GradientBackground& theBack,
417 const Standard_Boolean theToUpdate)
7fd59977 418{
d4f1753b 419 if (IsDeleted())
420 {
421 return;
422 }
423 else if (!IsDefined())
424 {
7fd59977 425 Visual3d_ViewDefinitionError::Raise ("Window not defined");
d4f1753b 426 }
7fd59977 427
d4f1753b 428 MyGradientBackground = theBack;
429 Quantity_Color aCol1, aCol2;
430 MyGradientBackground.Colors (aCol1, aCol2);
431 myGraphicDriver->GradientBackground (MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
7fd59977 432
d4f1753b 433 if (theToUpdate)
6bc6a6fc 434 {
435 Update (Aspect_TOU_ASAP);
436 }
d4f1753b 437 else if (myViewManager != NULL)
6bc6a6fc 438 {
d4f1753b 439 Update (myViewManager->UpdateMode());
6bc6a6fc 440 }
7fd59977 441}
442
d4f1753b 443// =======================================================================
444// function : SetBackgroundImage
445// purpose :
446// =======================================================================
447void Visual3d_View::SetBackgroundImage (const Standard_CString theFileName,
448 const Aspect_FillMethod theFillStyle,
449 const Standard_Boolean theToUpdate)
7fd59977 450{
6bc6a6fc 451 if (IsDeleted())
452 {
7fd59977 453 return;
6bc6a6fc 454 }
455 if (!IsDefined())
456 {
7fd59977 457 Visual3d_ViewDefinitionError::Raise ("Window not defined");
6bc6a6fc 458 }
7fd59977 459
d4f1753b 460 myGraphicDriver->BackgroundImage (theFileName, MyCView, theFillStyle);
7fd59977 461
d4f1753b 462 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
7fd59977 463}
464
d4f1753b 465// =======================================================================
466// function : SetBgImageStyle
467// purpose :
468// =======================================================================
469void Visual3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle,
470 const Standard_Boolean theToUpdate)
7fd59977 471{
6bc6a6fc 472 if (IsDeleted())
473 {
7fd59977 474 return;
6bc6a6fc 475 }
476 if (!IsDefined())
477 {
7fd59977 478 Visual3d_ViewDefinitionError::Raise ("Window not defined");
6bc6a6fc 479 }
7fd59977 480
d4f1753b 481 myGraphicDriver->SetBgImageStyle (MyCView, theFillStyle);
7fd59977 482
d4f1753b 483 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
7fd59977 484}
485
d4f1753b 486// =======================================================================
487// function : Background
488// purpose :
489// =======================================================================
490Aspect_Background Visual3d_View::Background() const
491{
492 return MyBackground;
7fd59977 493}
494
d4f1753b 495// =======================================================================
496// function : SetBgGradientStyle
497// purpose :
498// =======================================================================
499void Visual3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle,
500 const Standard_Boolean theToUpdate)
7fd59977 501{
6bc6a6fc 502 if (IsDeleted())
503 {
7fd59977 504 return;
6bc6a6fc 505 }
d4f1753b 506 else if (!IsDefined())
6bc6a6fc 507 {
7fd59977 508 Visual3d_ViewDefinitionError::Raise ("Window not defined");
6bc6a6fc 509 }
7fd59977 510
d4f1753b 511 myGraphicDriver->SetBgGradientStyle (MyCView, theFillStyle);
7fd59977 512
d4f1753b 513 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
7fd59977 514}
515
d4f1753b 516// =======================================================================
517// function : GradientBackground
518// purpose :
519// =======================================================================
520Aspect_GradientBackground Visual3d_View::GradientBackground() const
521{
522 return MyGradientBackground;
7fd59977 523}
524
b5ac8292 525// =======================================================================
526// function : DefaultCamera
527// purpose :
528// =======================================================================
529const Handle(Graphic3d_Camera)& Visual3d_View::DefaultCamera() const
530{
531 return myDefaultCamera;
7fd59977 532}
533
b5ac8292 534// =======================================================================
535// function : Camera
536// purpose :
537// =======================================================================
d4f1753b 538const Handle(Graphic3d_Camera)& Visual3d_View::Camera() const
539{
540 return MyCView.Context.Camera;
541}
7fd59977 542
b5ac8292 543// =======================================================================
544// function : SetCamera
545// purpose :
546// =======================================================================
547void Visual3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
548{
549 MyCView.Context.Camera = theCamera;
7fd59977 550
d4f1753b 551 myGraphicDriver->SetCamera (MyCView);
7fd59977 552
d4f1753b 553 Update (myViewManager->UpdateMode());
7fd59977 554}
555
b5ac8292 556// =======================================================================
557// function : SetViewOrientationDefault
558// purpose :
559// =======================================================================
d4f1753b 560void Visual3d_View::SetViewOrientationDefault()
b5ac8292 561{
562 if (myDefaultCamera.IsNull())
563 {
564 myDefaultCamera = new Graphic3d_Camera();
565 }
7fd59977 566
b5ac8292 567 myDefaultCamera->CopyOrientationData (MyCView.Context.Camera);
7fd59977 568}
569
b5ac8292 570// =======================================================================
571// function : ViewOrientationReset
572// purpose :
573// =======================================================================
d4f1753b 574void Visual3d_View::ViewOrientationReset()
b5ac8292 575{
576 if (IsDeleted())
577 {
578 return;
579 }
7fd59977 580
b5ac8292 581 if (!myDefaultCamera.IsNull())
582 {
583 MyCView.Context.Camera->CopyOrientationData (myDefaultCamera);
584 }
7fd59977 585
d4f1753b 586 Update (myViewManager->UpdateMode());
7fd59977 587}
588
b5ac8292 589// =======================================================================
590// function : SetViewMappingDefault
591// purpose :
592// =======================================================================
593void Visual3d_View::SetViewMappingDefault()
594{
595 if (myDefaultCamera.IsNull())
596 {
597 myDefaultCamera = new Graphic3d_Camera();
598 }
599 myDefaultCamera->CopyMappingData (MyCView.Context.Camera);
7fd59977 600}
601
b5ac8292 602// =======================================================================
603// function : ViewMappingReset
604// purpose :
605// =======================================================================
d4f1753b 606void Visual3d_View::ViewMappingReset()
b5ac8292 607{
d4f1753b 608 if (IsDeleted())
b5ac8292 609 {
610 return;
611 }
7fd59977 612
b5ac8292 613 if (!myDefaultCamera.IsNull())
614 {
615 MyCView.Context.Camera->CopyMappingData (myDefaultCamera);
616 }
7fd59977 617
d4f1753b 618 Update (myViewManager->UpdateMode());
7fd59977 619}
620
d4f1753b 621// =======================================================================
622// function : SetContext
623// purpose :
624// =======================================================================
625void Visual3d_View::SetContext (const Visual3d_ContextView& theViewCtx)
626{
627 if (IsDeleted())
628 {
629 return;
630 }
7fd59977 631
d4f1753b 632 // To manage display only in case of change of visualisation mode
633 const bool isVisModeChanged = theViewCtx.Visualization() != MyContext.Visualization();
634 const bool isModelChanged = theViewCtx.Model() != MyContext.Model();
7fd59977 635
d4f1753b 636 // To manage antialiasing only in case of change
637 const Standard_Boolean anAliasingModeOld = MyContext.AliasingIsOn();
638 const Standard_Boolean anAliasingModeNew = theViewCtx.AliasingIsOn();
7fd59977 639
d4f1753b 640 // To manage the depth cueing only in case of change
641 const Standard_Boolean aDepthCueingModeOld = MyContext.DepthCueingIsOn();
642 const Standard_Boolean aDepthCueingModeNew = theViewCtx.DepthCueingIsOn();
7fd59977 643
d4f1753b 644 const Standard_Real aDepthCueingFrontPlaneOld = MyContext.DepthCueingFrontPlane();
645 const Standard_Real aDepthCueingFrontPlaneNew = theViewCtx.DepthCueingFrontPlane();
646 const Standard_Real aDepthCueingBackPlaneOld = MyContext.DepthCueingBackPlane();
647 const Standard_Real aDepthCueingBackPlaneNew = theViewCtx.DepthCueingBackPlane();
7fd59977 648
d4f1753b 649 // To manage the Zclipping only in case of change
650 const Standard_Boolean aFrontZClippingModeOld = MyContext.FrontZClippingIsOn();
651 const Standard_Boolean aFrontZClippingModeNew = theViewCtx.FrontZClippingIsOn();
652 const Standard_Boolean aBackZClippingModeOld = MyContext.BackZClippingIsOn();
653 const Standard_Boolean aBackZClippingModeNew = theViewCtx.BackZClippingIsOn();
7fd59977 654
d4f1753b 655 const Standard_Real aZClippingFrontPlaneOld = MyContext.ZClippingFrontPlane();
656 const Standard_Real aZClippingFrontPlaneNew = theViewCtx.ZClippingFrontPlane();
657 const Standard_Real aZClippingBackPlaneOld = MyContext.ZClippingBackPlane();
658 const Standard_Real aZClippingBackPlaneNew = theViewCtx.ZClippingBackPlane();
7fd59977 659
d4f1753b 660 const bool isTextEnvChanged = theViewCtx.TextureEnv() != MyContext.TextureEnv();
661 const bool isSurfDetailChanged = theViewCtx.SurfaceDetail() != MyContext.SurfaceDetail();
7fd59977 662
d4f1753b 663 MyContext = theViewCtx;
7fd59977 664
d4f1753b 665 UpdateView();
7fd59977 666
d4f1753b 667 Standard_Boolean toWait = Standard_False; // => immediate update
668 if (IsDefined())
669 {
670 // management of visualization modes and types of shading.
671 if (isVisModeChanged
672 || isModelChanged)
673 {
674 myGraphicDriver->SetVisualisation (MyCView);
675 }
7fd59977 676
d4f1753b 677 // management of antialiasing
678 if (anAliasingModeOld != anAliasingModeNew)
679 {
680 myGraphicDriver->AntiAliasing (MyCView, anAliasingModeNew);
681 }
7fd59977 682
d4f1753b 683 // management of depth_cueing
684 if (aDepthCueingModeOld != aDepthCueingModeNew
685 || aDepthCueingFrontPlaneOld != aDepthCueingFrontPlaneNew
686 || aDepthCueingBackPlaneOld != aDepthCueingBackPlaneNew)
687 {
688 if (aDepthCueingModeNew
689 && aDepthCueingBackPlaneNew >= aDepthCueingFrontPlaneNew)
690 {
691 Visual3d_DepthCueingDefinitionError::Raise ("Bad value for DepthCueingPlanes position");
692 }
693 myGraphicDriver->DepthCueing (MyCView, aDepthCueingModeNew);
694 }
7fd59977 695
d4f1753b 696 // management of Zclipping
697 if (aFrontZClippingModeOld != aFrontZClippingModeNew
698 || aBackZClippingModeOld != aBackZClippingModeNew
699 || aZClippingFrontPlaneOld != aZClippingFrontPlaneNew
700 || aZClippingBackPlaneOld != aZClippingBackPlaneNew)
701 {
702 if (aBackZClippingModeNew
703 && aFrontZClippingModeNew
704 && aZClippingBackPlaneNew >= aZClippingFrontPlaneNew)
705 {
706 Visual3d_ZClippingDefinitionError::Raise ("Bad value for ZClippingPlanes position");
707 }
7fd59977 708
d4f1753b 709 myGraphicDriver->ClipLimit (MyCView, toWait);
710 }
7fd59977 711
d4f1753b 712 // management of textures
713 if (isTextEnvChanged
714 || isSurfDetailChanged)
715 {
716 myGraphicDriver->Environment (MyCView);
717 }
7fd59977 718
d4f1753b 719 UpdatePlanes(); // Update of planes of model clipping
720 UpdateLights(); // Update of light sources
721 }
7fd59977 722
d4f1753b 723 if (isVisModeChanged)
724 {
725 // Change of context =>
726 // Remove structures that cannot be displayed in the new visualisation mode.
727 // It is not necessary to warn ViewManager as this structure should not disappear from
728 // the list of structures displayed in it.
729 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructs;
730 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
731 {
732 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
733 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
734 if (anAnswer == Visual3d_TOA_NO
735 || anAnswer == Visual3d_TOA_COMPUTE)
736 {
737 aStructs.Append (aStruct);
738 }
739 }
740 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
741 {
742 Erase (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
743 }
744 aStructs.Clear();
745
746 // Change of context =>
747 // Display structures that can be displayed with the new visualisation mode.
748 // All structures with status Displayed are removed from the ViewManager
749 // and displayed in the view directly, if the structure is not already
750 // displayed and if the view accepts it in its context.
751 Graphic3d_MapOfStructure aMapDisplayed;
752 myViewManager->DisplayedStructures (aMapDisplayed);
753 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aMapDisplayed); aStructIter.More(); aStructIter.Next())
754 {
755 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
756 if (IsDisplayed (aStruct))
757 {
758 continue;
759 }
7fd59977 760
d4f1753b 761 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
762 if (anAnswer == Visual3d_TOA_YES
763 || anAnswer == Visual3d_TOA_COMPUTE)
764 {
765 aStructs.Append (aStruct);
766 }
767 }
7fd59977 768
d4f1753b 769 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
770 {
771 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
772 }
773 }
7fd59977 774
d4f1753b 775 Update (myViewManager->UpdateMode());
7fd59977 776}
777
d4f1753b 778// =======================================================================
779// function : Context
780// purpose :
781// =======================================================================
782const Visual3d_ContextView& Visual3d_View::Context() const
783{
784 return MyContext;
7fd59977 785}
786
d4f1753b 787// =======================================================================
788// function : DisplayedStructures
789// purpose :
790// =======================================================================
791void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
792{
793 if (IsDeleted())
794 {
795 return;
7fd59977 796 }
797
d4f1753b 798 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
799 {
800 theStructures.Add (aStructIter.Key());
801 }
7fd59977 802}
803
d4f1753b 804// =======================================================================
805// function : Activate
806// purpose :
807// =======================================================================
808void Visual3d_View::Activate()
809{
810 if (IsDeleted())
811 {
812 return;
813 }
814 else if (!IsDefined())
815 {
816 Visual3d_ViewDefinitionError::Raise ("Window not defined");
817 }
7fd59977 818
d4f1753b 819 if (!IsActive())
820 {
821 myGraphicDriver->ActivateView (MyCView);
822 myGraphicDriver->Background (MyCView);
823 myGraphicDriver->Transparency (MyCView, myViewManager->Transparency());
824
825 MyCView.Active = 1;
826
827 // Activation of a new view =>
828 // Display structures that can be displayed in this new view.
829 // All structures with status
830 // Displayed in ViewManager are returned and displayed in
831 // the view directly, if the structure is not already
832 // displayed and if the view accepts it in its context.
833 Graphic3d_MapOfStructure aDisplayedStructs;
834 myViewManager->DisplayedStructures (aDisplayedStructs);
835 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
836 {
837 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
838 if (IsDisplayed (aStruct))
839 {
840 continue;
841 }
7fd59977 842
d4f1753b 843 // If the structure can be displayed in the new context of the view, it is displayed.
844 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
845 if (anAnswer == Visual3d_TOA_YES
846 || anAnswer == Visual3d_TOA_COMPUTE)
847 {
848 Display (aStruct, Aspect_TOU_WAIT);
849 }
850 }
851 }
7fd59977 852
d4f1753b 853 // If the activation/desactivation of ZBuffer should be automatic
854 // depending on the presence or absence of facets.
855 if (myViewManager->ZBufferAuto())
856 {
857 const Standard_Boolean containsFacet = ContainsFacet();
858 const Standard_Boolean hasZBuffer = ZBufferIsActivated();
859 if (containsFacet && !hasZBuffer)
860 {
861 SetZBufferActivity (1); // If the view contains facets and if ZBuffer is not active
862 }
863 else if (!containsFacet && hasZBuffer)
864 {
865 SetZBufferActivity (0); // If the view does not contain facets and if ZBuffer is active
866 }
867 }
7fd59977 868
d4f1753b 869 Update (myViewManager->UpdateMode());
7fd59977 870}
871
d4f1753b 872// =======================================================================
873// function : IsActive
874// purpose :
875// =======================================================================
876Standard_Boolean Visual3d_View::IsActive() const
877{
878 return !IsDeleted()
879 && MyCView.Active;
7fd59977 880}
881
d4f1753b 882// =======================================================================
883// function : Deactivate
884// purpose :
885// =======================================================================
886void Visual3d_View::Deactivate()
887{
888 if (IsDeleted())
889 {
890 return;
891 }
892 else if (!IsDefined())
893 {
894 Visual3d_ViewDefinitionError::Raise ("Window not defined");
895 }
7fd59977 896
d4f1753b 897 if (IsActive())
898 {
899 myGraphicDriver->DeactivateView (MyCView);
900
901 // Deactivation of a view =>
902 // Removal of structures displayed in this view.
903 // All structures with status
904 // Displayed in ViewManager are returned and removed from
905 // the view directly, if the structure is not already
906 // displayed and if the view accepts it in its context.
907 Graphic3d_MapOfStructure aDisplayedStructs;
908 myViewManager->DisplayedStructures (aDisplayedStructs);
909 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
910 {
911 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
912 if (IsDisplayed (aStruct))
913 {
914 continue;
915 }
7fd59977 916
d4f1753b 917 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
918 if (anAnswer == Visual3d_TOA_YES
919 || anAnswer == Visual3d_TOA_COMPUTE)
920 {
921 Erase (aStruct, Aspect_TOU_WAIT);
922 }
923 }
7fd59977 924
d4f1753b 925 Update (myViewManager->UpdateMode());
926 MyCView.Active = 0; // No action currently possible in the view
927 }
7fd59977 928}
929
d4f1753b 930// =======================================================================
931// function : Redraw
932// purpose :
933// =======================================================================
679ecdee 934void Visual3d_View::Redraw()
935{
d4f1753b 936 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
7fd59977 937}
938
d4f1753b 939// =======================================================================
940// function : Redraw
941// purpose :
942// =======================================================================
679ecdee 943void Visual3d_View::Redraw (const Standard_Integer theX,
944 const Standard_Integer theY,
945 const Standard_Integer theWidth,
946 const Standard_Integer theHeight)
947{
d4f1753b 948 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(),
679ecdee 949 theX, theY, theWidth, theHeight);
7fd59977 950}
951
d4f1753b 952// =======================================================================
953// function : Redraw
954// purpose :
955// =======================================================================
679ecdee 956void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
957 const Handle(Visual3d_Layer)& theOverLayer)
958{
959 Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
960}
7fd59977 961
d4f1753b 962// =======================================================================
963// function : Redraw
964// purpose :
965// =======================================================================
679ecdee 966void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
967 const Handle(Visual3d_Layer)& theOverLayer,
968 const Standard_Integer theX,
969 const Standard_Integer theY,
970 const Standard_Integer theWidth,
971 const Standard_Integer theHeight)
972{
973 if (IsDeleted()
974 || !IsDefined()
975 || !IsActive()
976 || !MyWindow->IsMapped())
977 {
978 return;
979 }
7fd59977 980
a89742cf 981 Aspect_CLayer2d anOverCLayer, anUnderCLayer;
982 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
983 if (!theOverLayer .IsNull()) anOverCLayer = theOverLayer ->CLayer();
984 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
7fd59977 985
a89742cf 986 for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
679ecdee 987 {
d4f1753b 988 if (myGraphicDriver->IsDeviceLost())
679ecdee 989 {
d4f1753b 990 myViewManager->RecomputeStructures();
991 myViewManager->RecomputeStructures (myImmediateStructures);
992 myGraphicDriver->ResetDeviceLostFlag();
679ecdee 993 }
a89742cf 994
995 // set up Z buffer state before redrawing
d4f1753b 996 if (myViewManager->ZBufferAuto())
679ecdee 997 {
a89742cf 998 const Standard_Boolean hasFacet = ContainsFacet();
999 const Standard_Boolean hasZBuffer = ZBufferIsActivated();
1000 // if the view contains facets and if ZBuffer is not active
1001 if (hasFacet && !hasZBuffer)
1002 {
1003 SetZBufferActivity (1);
1004 }
1005 // if the view contains only facets and if ZBuffer is active
1006 if (!hasFacet && hasZBuffer)
1007 {
1008 SetZBufferActivity (0);
1009 }
679ecdee 1010 }
7fd59977 1011
6bc6a6fc 1012 if (myStructuresUpdated)
1013 {
1014 AutoZFit();
1015 myStructuresUpdated = Standard_False;
1016 }
1017
d4f1753b 1018 myGraphicDriver->Redraw (MyCView, anUnderCLayer, anOverCLayer, theX, theY, theWidth, theHeight);
1019 if (!myGraphicDriver->IsDeviceLost())
a89742cf 1020 {
1021 return;
1022 }
1023 }
7fd59977 1024}
1025
d4f1753b 1026// =======================================================================
1027// function : RedrawImmediate
1028// purpose :
1029// =======================================================================
679ecdee 1030void Visual3d_View::RedrawImmediate()
1031{
d4f1753b 1032 RedrawImmediate (myViewManager->UnderLayer(), myViewManager->OverLayer());
679ecdee 1033}
7fd59977 1034
d4f1753b 1035// =======================================================================
1036// function : RedrawImmediate
1037// purpose :
1038// =======================================================================
679ecdee 1039void Visual3d_View::RedrawImmediate (const Handle(Visual3d_Layer)& theUnderLayer,
1040 const Handle(Visual3d_Layer)& theOverLayer)
1041{
1042 if (IsDeleted()
1043 || !IsDefined()
1044 || !IsActive()
1045 || !MyWindow->IsMapped())
1046 {
1047 return;
1048 }
7fd59977 1049
679ecdee 1050 Aspect_CLayer2d anOverCLayer, anUnderCLayer;
1051 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
1052 if (!theOverLayer .IsNull()) anOverCLayer = theOverLayer ->CLayer();
1053 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
d4f1753b 1054 myGraphicDriver->RedrawImmediate (MyCView, anUnderCLayer, anOverCLayer);
679ecdee 1055}
7fd59977 1056
d4f1753b 1057// =======================================================================
1058// function : Invalidate
1059// purpose :
1060// =======================================================================
679ecdee 1061void Visual3d_View::Invalidate()
1062{
d4f1753b 1063 myGraphicDriver->Invalidate (MyCView);
7fd59977 1064}
1065
d4f1753b 1066// =======================================================================
1067// function : Update
1068// purpose :
1069// =======================================================================
6bc6a6fc 1070void Visual3d_View::Update (Aspect_TypeOfUpdate theUpdateMode)
b5ac8292 1071{
6bc6a6fc 1072 myStructuresUpdated = Standard_True;
6bc6a6fc 1073 if (theUpdateMode == Aspect_TOU_ASAP)
1074 {
d4f1753b 1075 Compute();
1076 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
6bc6a6fc 1077 }
7fd59977 1078}
1079
d4f1753b 1080// =======================================================================
1081// function : Update
1082// purpose :
1083// =======================================================================
679ecdee 1084void Visual3d_View::Update (const Handle(Visual3d_Layer)& theUnderLayer,
1085 const Handle(Visual3d_Layer)& theOverLayer)
1086{
d4f1753b 1087 Compute();
6bc6a6fc 1088 myStructuresUpdated = Standard_True;
679ecdee 1089 Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
7fd59977 1090}
1091
d4f1753b 1092// ========================================================================
1093// function : SetAutoZFitMode
1094// purpose :
1095// ========================================================================
1096void Visual3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
1097 const Standard_Real theScaleFactor)
6bc6a6fc 1098{
1099 Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
1100 myAutoZFitScaleFactor = theScaleFactor;
1101 myAutoZFitIsOn = theIsOn;
1102}
1103
d4f1753b 1104// ========================================================================
1105// function : AutoZFitMode
1106// purpose :
1107// ========================================================================
6bc6a6fc 1108Standard_Boolean Visual3d_View::AutoZFitMode() const
1109{
1110 return myAutoZFitIsOn;
1111}
1112
d4f1753b 1113// ========================================================================
1114// function : AutoZFitScaleFactor
1115// purpose :
1116// ========================================================================
1117Standard_Real Visual3d_View::AutoZFitScaleFactor() const
6bc6a6fc 1118{
1119 return myAutoZFitScaleFactor;
1120}
1121
d4f1753b 1122// ========================================================================
1123// function : AutoZFit
1124// purpose :
1125// ========================================================================
6bc6a6fc 1126void Visual3d_View::AutoZFit()
1127{
1128 if (!AutoZFitMode())
1129 {
1130 return;
1131 }
1132
1133 ZFitAll (myAutoZFitScaleFactor);
1134}
1135
d4f1753b 1136// ========================================================================
1137// function : ZFitAll
1138// purpose :
1139// ========================================================================
6bc6a6fc 1140void Visual3d_View::ZFitAll (const Standard_Real theScaleFactor)
1141{
1142 Standard_Real aMinMax[6]; // applicative min max boundaries
1143 MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2],
1144 aMinMax[3], aMinMax[4], aMinMax[5],
1145 Standard_False);
1146
1147 Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag).
1148 MinMaxValues (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
1149 aGraphicBB[3], aGraphicBB[4], aGraphicBB[5],
1150 Standard_True);
1151
1152 Bnd_Box aMinMaxBox;
1153 Bnd_Box aGraphicBox;
1154
1155 aMinMaxBox.Update (aMinMax[0], aMinMax[1], aMinMax[2],
1156 aMinMax[3], aMinMax[4], aMinMax[5]);
1157
1158 aGraphicBox.Update (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
1159 aGraphicBB[3], aGraphicBB[4], aGraphicBB[5]);
1160
1161 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1162 aCamera->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
1163}
1164
d4f1753b 1165// ========================================================================
1166// function : AcceptDisplay
1167// purpose :
1168// ========================================================================
1169Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& theStruct) const
1170{
1171 const Visual3d_TypeOfVisualization ViewType = MyContext.Visualization();
1172 switch (theStruct->Visual())
1173 {
1174 case Graphic3d_TOS_ALL:
1175 {
1176 return Visual3d_TOA_YES; // The structure accepts any type of view
1177 }
1178 case Graphic3d_TOS_SHADING:
1179 {
1180 return ViewType == Visual3d_TOV_SHADING
1181 ? Visual3d_TOA_YES
1182 : Visual3d_TOA_NO;
1183 }
1184 case Graphic3d_TOS_WIREFRAME:
1185 {
1186 return ViewType == Visual3d_TOV_WIREFRAME
1187 ? Visual3d_TOA_YES
1188 : Visual3d_TOA_NO;
1189 }
1190 case Graphic3d_TOS_COMPUTED:
1191 {
1192 return (ViewType == Visual3d_TOV_SHADING || ViewType == Visual3d_TOV_WIREFRAME)
1193 ? Visual3d_TOA_COMPUTE
1194 : Visual3d_TOA_NO;
1195 }
1196 }
1197 return Visual3d_TOA_NO;
7fd59977 1198}
1199
d4f1753b 1200// ========================================================================
1201// function : ChangeDisplayPriority
1202// purpose :
1203// ========================================================================
1204void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStruct,
1205 const Standard_Integer /*theOldPriority*/,
1206 const Standard_Integer theNewPriority)
1207{
1208 if (IsDeleted()
1209 || !IsDefined()
1210 || !IsActive()
1211 || !IsDisplayed (theStruct))
1212 {
1213 return;
1214 }
7fd59977 1215
d4f1753b 1216 if (!myIsInComputedMode)
1217 {
1218 myGraphicDriver->ChangePriority (*theStruct->CStructure(), MyCView, theNewPriority);
1219 return;
1220 }
7fd59977 1221
d4f1753b 1222 const Standard_Integer anIndex = IsComputed (theStruct);
1223 const Graphic3d_CStructure& aCStruct = anIndex != 0
1224 ? *(myStructsComputed.Value (anIndex)->CStructure())
1225 : *theStruct->CStructure();
1226 myGraphicDriver->ChangePriority (aCStruct, MyCView, theNewPriority);
7fd59977 1227}
1228
d4f1753b 1229// ========================================================================
1230// function : Clear
1231// purpose :
1232// ========================================================================
1233void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& theStruct,
1234 const Standard_Boolean theWithDestruction)
1235{
1236 const Standard_Integer anIndex = IsComputed (theStruct);
1237 if (anIndex != 0)
1238 {
1239 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
1240 aCompStruct->GraphicClear (theWithDestruction);
1241 aCompStruct->SetHLRValidation (Standard_False);
1242 }
7fd59977 1243}
1244
d4f1753b 1245// ========================================================================
1246// function : Connect
1247// purpose :
1248// ========================================================================
1249void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& theMother,
1250 const Handle(Graphic3d_Structure)& theDaughter)
1251{
1252 Standard_Integer anIndexM = IsComputed (theMother);
1253 Standard_Integer anIndexD = IsComputed (theDaughter);
1254 if (anIndexM != 0
1255 && anIndexD != 0)
1256 {
1257 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1258 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1259 aStructM->GraphicConnect (aStructD);
1260 }
7fd59977 1261}
1262
d4f1753b 1263// ========================================================================
1264// function : Disconnect
1265// purpose :
1266// ========================================================================
1267void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& theMother,
1268 const Handle(Graphic3d_Structure)& theDaughter)
1269{
1270 Standard_Integer anIndexM = IsComputed (theMother);
1271 Standard_Integer anIndexD = IsComputed (theDaughter);
1272 if (anIndexM != 0
1273 && anIndexD != 0)
1274 {
1275 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1276 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1277 aStructM->GraphicDisconnect (aStructD);
1278 }
7fd59977 1279}
1280
d4f1753b 1281// ========================================================================
1282// function : DisplayImmediate
1283// purpose :
1284// ========================================================================
679ecdee 1285Standard_Boolean Visual3d_View::DisplayImmediate (const Handle(Graphic3d_Structure)& theStructure,
1286 const Standard_Boolean theIsSingleView)
1287{
1288 if (!myImmediateStructures.Add (theStructure))
1289 {
1290 return Standard_False;
1291 }
1292
1293 if (theIsSingleView)
1294 {
d4f1753b 1295 Handle(Visual3d_HSequenceOfView) aViews = myViewManager->DefinedView();
54f7544d 1296
1297 for (int i=1;i<=aViews->Length();i++)
679ecdee 1298 {
54f7544d 1299 if (aViews->Value(i).Access() != this)
679ecdee 1300 {
54f7544d 1301 aViews->Value(i)->EraseImmediate (theStructure);
679ecdee 1302 }
1303 }
1304 }
1305
d4f1753b 1306 myGraphicDriver->DisplayImmediateStructure (MyCView, *theStructure->CStructure());
679ecdee 1307 return Standard_True;
1308}
1309
d4f1753b 1310// ========================================================================
1311// function : EraseImmediate
1312// purpose :
1313// ========================================================================
679ecdee 1314Standard_Boolean Visual3d_View::EraseImmediate (const Handle(Graphic3d_Structure)& theStructure)
1315{
1316 const Standard_Boolean isErased = myImmediateStructures.Remove (theStructure);
1317 if (isErased)
1318 {
d4f1753b 1319 myGraphicDriver->EraseImmediateStructure (MyCView, *theStructure->CStructure());
679ecdee 1320 }
1321
1322 return isErased;
1323}
1324
d4f1753b 1325// ========================================================================
1326// function : ClearImmediate
1327// purpose :
1328// ========================================================================
679ecdee 1329Standard_Boolean Visual3d_View::ClearImmediate()
1330{
1331 if (myImmediateStructures.IsEmpty())
1332 {
1333 return Standard_False;
1334 }
1335
1336 for (Graphic3d_MapIteratorOfMapOfStructure anIter (myImmediateStructures); anIter.More(); anIter.Next())
1337 {
d4f1753b 1338 myGraphicDriver->EraseImmediateStructure (MyCView, *anIter.Key()->CStructure());
679ecdee 1339 }
1340 myImmediateStructures.Clear();
1341 return Standard_True;
1342}
1343
d4f1753b 1344// ========================================================================
1345// function : Display
1346// purpose :
1347// ========================================================================
1348void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct)
1349{
1350 Display (theStruct, myViewManager->UpdateMode());
7fd59977 1351}
1352
d4f1753b 1353// ========================================================================
1354// function : Display
1355// purpose :
1356// ========================================================================
1357void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct,
1358 const Aspect_TypeOfUpdate theUpdateMode)
1359{
1360 if (IsDeleted()
1361 || !IsDefined()
1362 || !IsActive())
1363 {
1364 return;
1365 }
7fd59977 1366
d4f1753b 1367 // If Display on a structure present in the list of calculated structures while it is not
1368 // or more, of calculated type =>
1369 // - removes it as well as the associated old computed
1370 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
1371 Standard_Integer anIndex = IsComputed (theStruct);
1372 if (anIndex != 0
1373 && theStruct->Visual() != Graphic3d_TOS_COMPUTED)
1374 {
1375 myStructsToCompute.Remove (anIndex);
1376 myStructsComputed .Remove (anIndex);
1377 anIndex = 0;
1378 }
7fd59977 1379
d4f1753b 1380 Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1381 if (anAnswer == Visual3d_TOA_NO)
1382 {
1383 return;
1384 }
7fd59977 1385
d4f1753b 1386 if (!ComputedMode())
1387 {
1388 anAnswer = Visual3d_TOA_YES;
1389 }
7fd59977 1390
d4f1753b 1391 if (anAnswer == Visual3d_TOA_YES)
1392 {
1393 if (IsDisplayed (theStruct))
1394 {
1395 return;
1396 }
7fd59977 1397
d4f1753b 1398 theStruct->CalculateBoundBox();
1399 myGraphicDriver->DisplayStructure (MyCView, *theStruct->CStructure(), theStruct->DisplayPriority());
1400 myStructsDisplayed.Add (theStruct);
1401 Update (theUpdateMode);
1402 return;
1403 }
1404 else if (anAnswer != Visual3d_TOA_COMPUTE)
1405 {
1406 return;
1407 }
7fd59977 1408
d4f1753b 1409 if (anIndex != 0)
1410 {
1411 // Already computed, is COMPUTED still valid?
1412 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
1413 if (anOldStruct->HLRValidation())
1414 {
1415 // Case COMPUTED valid
1416 // to be displayed
1417 if (!IsDisplayed (theStruct))
1418 {
1419 myStructsDisplayed.Add (theStruct);
1420 myGraphicDriver->DisplayStructure (MyCView, *anOldStruct->CStructure(), theStruct->DisplayPriority());
1421 Update (theUpdateMode);
1422 }
1423 return;
1424 }
1425 else
1426 {
1427 // Case COMPUTED invalid
1428 // Is there another valid representation?
1429 // Find in the sequence of already calculated structures
1430 // 1/ Structure having the same Owner as <AStructure>
1431 // 2/ That is not <AStructure>
1432 // 3/ The COMPUTED which of is valid
1433 const Standard_Integer aNewIndex = HaveTheSameOwner (theStruct);
1434 if (aNewIndex != 0)
1435 {
1436 // Case of COMPUTED invalid, WITH a valid of replacement
1437 // to be displayed
1438 if (!IsDisplayed (theStruct))
de75ed09 1439 {
d4f1753b 1440 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
1441 myStructsComputed.SetValue (anIndex, aNewStruct);
1442 myStructsDisplayed.Add (theStruct);
1443 myGraphicDriver->DisplayStructure (MyCView, *aNewStruct->CStructure(), theStruct->DisplayPriority());
1444 Update (theUpdateMode);
de75ed09 1445 }
d4f1753b 1446 return;
1447 }
1448 else
1449 {
1450 // Case COMPUTED invalid, WITHOUT a valid of replacement
1451 // COMPUTED is removed if displayed
1452 if (IsDisplayed (theStruct))
1453 {
1454 myGraphicDriver->EraseStructure (MyCView, *anOldStruct->CStructure());
7fd59977 1455 }
d4f1753b 1456 }
1457 }
1458 }
7fd59977 1459
d4f1753b 1460 // Compute + Validation
1461 Handle(Graphic3d_Structure) aStruct;
1462 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1463 theStruct->Transform (aTrsf);
1464 if (anIndex != 0)
1465 {
1466 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
1467 for (Standard_Integer ii = 0; ii <= 3; ++ii)
1468 {
1469 for (Standard_Integer jj = 0; jj <= 3; ++jj)
1470 {
1471 anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0);
1472 }
1473 }
7fd59977 1474
d4f1753b 1475 aStruct = myStructsComputed.Value (anIndex);
1476 aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
1477 if (theStruct->IsTransformed())
1478 {
1479 theStruct->Compute (this, aTrsf, aStruct);
1480 }
1481 else
1482 {
1483 theStruct->Compute (this, aStruct);
1484 }
1485 }
1486 else
1487 {
1488 aStruct = theStruct->IsTransformed()
1489 ? theStruct->Compute (this, aTrsf)
1490 : theStruct->Compute (this);
1491 }
7fd59977 1492
d4f1753b 1493 aStruct->SetHLRValidation (Standard_True);
7fd59977 1494
d4f1753b 1495 // TOCOMPUTE and COMPUTED associated to sequences are added
1496 myStructsToCompute.Append (theStruct);
1497 myStructsComputed .Append (aStruct);
7fd59977 1498
d4f1753b 1499 // The previous are removed if necessary
1500 if (anIndex != 0)
1501 {
1502 myStructsToCompute.Remove (anIndex);
1503 myStructsComputed .Remove (anIndex);
1504 }
7fd59977 1505
d4f1753b 1506 // Of which type will be the computed?
1507 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
1508 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
1509 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
1510 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
1511 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
1512 if (!toComputeShading && !toComputeWireframe)
1513 {
1514 anAnswer = Visual3d_TOA_NO;
1515 }
1516 else
1517 {
1518 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
1519 anAnswer = AcceptDisplay (aStruct);
1520 }
7fd59977 1521
d4f1753b 1522 if (theStruct->IsHighlighted())
1523 {
1524 aStruct->SetHighlightColor (theStruct->HighlightColor());
1525 aStruct->GraphicHighlight (Aspect_TOHM_COLOR);
1526 }
7fd59977 1527
d4f1753b 1528 // It is displayed only if the calculated structure
1529 // has a proper type corresponding to the one of the view.
1530 if (anAnswer != Visual3d_TOA_NO)
1531 {
1532 if (!IsDisplayed (theStruct))
1533 {
1534 myStructsDisplayed.Add (theStruct);
1535 }
1536 myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), theStruct->DisplayPriority());
1537 Update (theUpdateMode);
1538 }
7fd59977 1539}
1540
d4f1753b 1541// ========================================================================
1542// function : Erase
1543// purpose :
1544// ========================================================================
1545void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct)
1546{
1547 if (!IsDeleted())
1548 {
1549 Erase (theStruct, myViewManager->UpdateMode());
1550 }
7fd59977 1551}
1552
d4f1753b 1553// ========================================================================
1554// function : Erase
1555// purpose :
1556// ========================================================================
1557void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct,
1558 const Aspect_TypeOfUpdate theUpdateMode)
1559{
1560 if (IsDeleted()
1561 || !IsDisplayed (theStruct))
1562 {
1563 return;
1564 }
7fd59977 1565
d4f1753b 1566 Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1567 if (!ComputedMode())
1568 {
1569 anAnswer = Visual3d_TOA_YES;
1570 }
7fd59977 1571
d4f1753b 1572 if (anAnswer != Visual3d_TOA_COMPUTE)
1573 {
1574 myGraphicDriver->EraseStructure (MyCView, *theStruct->CStructure());
1575 }
1576 else if (anAnswer == Visual3d_TOA_COMPUTE
1577 && myIsInComputedMode)
1578 {
1579 const Standard_Integer anIndex = IsComputed (theStruct);
1580 if (anIndex != 0)
1581 {
1582 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1583 myGraphicDriver->EraseStructure (MyCView, *aCompStruct->CStructure());
1584 }
1585 }
1586 myStructsDisplayed.Remove (theStruct);
1587 Update (theUpdateMode);
7fd59977 1588}
1589
d4f1753b 1590// ========================================================================
1591// function : Highlight
1592// purpose :
1593// ========================================================================
1594void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& theStruct,
1595 const Aspect_TypeOfHighlightMethod theMethod)
1596{
1597 const Standard_Integer anIndex = IsComputed (theStruct);
1598 if (anIndex != 0)
1599 {
1600 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1601 aCompStruct->SetHighlightColor (theStruct->HighlightColor());
1602 aCompStruct->GraphicHighlight (theMethod);
1603 }
7fd59977 1604}
1605
d4f1753b 1606// ========================================================================
1607// function : SetTransform
1608// purpose :
1609// ========================================================================
1610void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& theStruct,
1611 const TColStd_Array2OfReal& theTrsf)
1612{
1613 const Standard_Integer anIndex = IsComputed (theStruct);
1614 if (anIndex != 0)
1615 {
1616 // Test is somewhat light !
1617 // trsf is transferred only if it is :
1618 // a translation
1619 // a scale
1620 if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0
1621 || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0
1622 || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0)
1623 {
1624 ReCompute (theStruct);
1625 }
1626 else
1627 {
1628 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1629 aCompStruct->GraphicTransform (theTrsf);
1630 }
1631 }
7fd59977 1632
d4f1753b 1633 theStruct->CalculateBoundBox();
1634 if (!theStruct->IsMutable()
1635 && !theStruct->CStructure()->IsForHighlight
1636 && !theStruct->CStructure()->IsInfinite)
1637 {
1638 const Standard_Integer aLayerId = theStruct->GetZLayer();
1639 myGraphicDriver->InvalidateBVHData (MyCView, aLayerId);
1640 }
7fd59977 1641}
1642
d4f1753b 1643// ========================================================================
1644// function : UnHighlight
1645// purpose :
1646// ========================================================================
1647void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& theStruct)
1648{
1649 Standard_Integer anIndex = IsComputed (theStruct);
1650 if (anIndex != 0)
1651 {
1652 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1653 aCompStruct->GraphicUnHighlight();
1654 }
7fd59977 1655}
1656
d4f1753b 1657// ========================================================================
1658// function : IsComputed
1659// purpose :
1660// ========================================================================
1661Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& theStruct) const
1662{
1663 const Standard_Integer aStructId = theStruct->Identification();
1664 const Standard_Integer aNbStructs = myStructsToCompute.Length();
1665 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
1666 {
1667 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
1668 if (aStruct->Identification() == aStructId)
1669 {
1670 return aStructIter;
1671 }
1672 }
1673 return 0;
7fd59977 1674}
1675
d4f1753b 1676// ========================================================================
1677// function : IsDisplayed
1678// purpose :
1679// ========================================================================
1680Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& theStruct) const
1681{
1682 return !IsDeleted()
1683 && myStructsDisplayed.Contains (theStruct);
7fd59977 1684}
7fd59977 1685
d4f1753b 1686// ========================================================================
1687// function : ContainsFacet
1688// purpose :
1689// ========================================================================
1690Standard_Boolean Visual3d_View::ContainsFacet() const
1691{
1692 return ContainsFacet (myStructsDisplayed);
7fd59977 1693}
1694
d4f1753b 1695// ========================================================================
1696// function : ContainsFacet
1697// purpose :
1698// ========================================================================
1699Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
1700{
1701 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
1702 {
1703 if (aStructIter.Key()->ContainsFacet())
1704 {
1705 return Standard_True;
1706 }
1707 }
1708 return Standard_False;
7fd59977 1709}
1710
d4f1753b 1711// ========================================================================
1712// function : MinMaxValues
1713// purpose :
1714// ========================================================================
197ac94e 1715void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
1716 Standard_Real& theYMin,
1717 Standard_Real& theZMin,
1718 Standard_Real& theXMax,
1719 Standard_Real& theYMax,
1720 Standard_Real& theZMax,
1721 const Standard_Boolean theToIgnoreInfiniteFlag) const
1722{
d4f1753b 1723 MinMaxValues (myStructsDisplayed,
197ac94e 1724 theXMin, theYMin, theZMin,
1725 theXMax, theYMax, theZMax,
1726 theToIgnoreInfiniteFlag);
7fd59977 1727}
1728
d4f1753b 1729// ========================================================================
1730// function : MinMaxValues
1731// purpose :
1732// ========================================================================
197ac94e 1733void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
1734 Standard_Real& theXMin,
1735 Standard_Real& theYMin,
1736 Standard_Real& theZMin,
1737 Standard_Real& theXMax,
1738 Standard_Real& theYMax,
1739 Standard_Real& theZMax,
1740 const Standard_Boolean theToIgnoreInfiniteFlag) const
1741{
1742 if (theSet.IsEmpty ())
1743 {
1744 theXMin = RealFirst();
1745 theYMin = RealFirst();
1746 theZMin = RealFirst();
7fd59977 1747
197ac94e 1748 theXMax = RealLast();
1749 theYMax = RealLast();
1750 theZMax = RealLast();
7fd59977 1751 }
197ac94e 1752 else
1753 {
1754 Standard_Real aXm, aYm, aZm, aXM, aYM, aZM;
1755 Graphic3d_MapIteratorOfMapOfStructure anIterator (theSet);
7fd59977 1756
197ac94e 1757 theXMin = RealLast();
1758 theYMin = RealLast();
1759 theZMin = RealLast();
7fd59977 1760
197ac94e 1761 theXMax = RealFirst ();
1762 theYMax = RealFirst ();
1763 theZMax = RealFirst ();
7fd59977 1764
197ac94e 1765 for (anIterator.Initialize (theSet); anIterator.More(); anIterator.Next())
1766 {
1767 const Handle(Graphic3d_Structure)& aStructure = anIterator.Key();
7fd59977 1768
aeb722e3 1769 if (!aStructure->IsVisible())
1770 continue;
1771
197ac94e 1772 if (aStructure->IsInfinite() && !theToIgnoreInfiniteFlag)
1773 {
7fd59977 1774 //XMin, YMin .... ZMax are initialized by means of infinite line data
197ac94e 1775 aStructure->MinMaxValues (aXm, aYm, aZm, aXM, aYM, aZM, Standard_False);
1776 if (aXm != RealFirst() && aXm < theXMin)
1777 {
1778 theXMin = aXm;
1779 }
1780 if (aYm != RealFirst() && aYm < theYMin)
1781 {
1782 theYMin = aYm;
1783 }
1784 if (aZm != RealFirst() && aZm < theZMin)
1785 {
1786 theZMin = aZm;
1787 }
1788 if (aXM != RealLast() && aXM > theXMax)
1789 {
1790 theXMax = aXM;
1791 }
1792 if (aYM != RealLast() && aYM > theYMax)
1793 {
1794 theYMax = aYM;
1795 }
1796 if (aZM != RealLast() && aZM > theZMax)
1797 {
1798 theZMax = aZM;
1799 }
7fd59977 1800 }
197ac94e 1801
bf75be98 1802 // Only non-empty and non-infinite structures
81bba717 1803 // are taken into account for calculation of MinMax
197ac94e 1804 if ((!aStructure->IsInfinite() || theToIgnoreInfiniteFlag) && !aStructure->IsEmpty())
1805 {
1806 aStructure->MinMaxValues (aXm, aYm, aZm, aXM, aYM, aZM, theToIgnoreInfiniteFlag);
1807
1808 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
1809 //"FitAll" operation ignores object with transform persitence parameter
1810 if(aStructure->TransformPersistenceMode() == Graphic3d_TMF_None )
1811 {
1812 theXMin = Min (aXm, theXMin);
1813 theYMin = Min (aYm, theYMin);
1814 theZMin = Min (aZm, theZMin);
1815 theXMax = Max (aXM, theXMax);
1816 theYMax = Max (aYM, theYMax);
1817 theZMax = Max (aZM, theZMax);
7fd59977 1818 }
197ac94e 1819 }
7fd59977 1820 }
1821
81bba717 1822 // The following cases are relevant
1823 // For exemple if all structures are empty or infinite
197ac94e 1824 if (theXMax < theXMin) { aXm = theXMin; theXMin = theXMax; theXMax = aXm; }
1825 if (theYMax < theYMin) { aYm = theYMin; theYMin = theYMax; theYMax = aYm; }
1826 if (theZMax < theZMin) { aZm = theZMin; theZMin = theZMax; theZMax = aZm; }
7fd59977 1827 }
7fd59977 1828}
1829
d4f1753b 1830// ========================================================================
1831// function : MinMaxValues
1832// purpose :
1833// ========================================================================
197ac94e 1834void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
1835 Standard_Real& theYMin,
1836 Standard_Real& theXMax,
1837 Standard_Real& theYMax,
1838 const Standard_Boolean theToIgnoreInfiniteFlag) const
1839{
d4f1753b 1840 MinMaxValues (myStructsDisplayed,
197ac94e 1841 theXMin, theYMin,
1842 theXMax, theYMax,
1843 theToIgnoreInfiniteFlag);
7fd59977 1844}
1845
d4f1753b 1846// ========================================================================
1847// function : MinMaxValues
1848// purpose :
1849// ========================================================================
197ac94e 1850void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
1851 Standard_Real& theXMin,
1852 Standard_Real& theYMin,
1853 Standard_Real& theXMax,
1854 Standard_Real& theYMax,
1855 const Standard_Boolean theToIgnoreInfiniteFlag) const
1856{
1857 Standard_Real aXm, aYm, aZm, aXM, aYM, aZM;
1858 Standard_Real aXp, aYp, aZp;
7fd59977 1859
197ac94e 1860 MinMaxValues (theSet, aXm, aYm, aZm, aXM, aYM, aZM, theToIgnoreInfiniteFlag);
7fd59977 1861
197ac94e 1862 Projects (aXm, aYm, aZm, aXp, aYp, aZp);
1863 theXMin = aXp;
1864 theYMin = aYp;
7fd59977 1865
197ac94e 1866 Projects (aXM, aYM, aZM, aXp, aYp, aZp);
1867 theXMax = aXp;
1868 theYMax = aYp;
7fd59977 1869
197ac94e 1870 if (theXMax < theXMin) { aXp = theXMax; theXMax = theXMin; theXMin = aXp; }
1871 if (theYMax < theYMin) { aYp = theYMax; theYMax = theYMin; theYMin = aYp; }
7fd59977 1872}
1873
d4f1753b 1874// =======================================================================
1875// function : NumberOfDisplayedStructures
1876// purpose :
1877// =======================================================================
1878Standard_Integer Visual3d_View::NumberOfDisplayedStructures() const
1879{
1880 return myStructsDisplayed.Extent();
7fd59977 1881}
1882
d4f1753b 1883// =======================================================================
1884// function : Projects
1885// purpose :
1886// =======================================================================
197ac94e 1887void Visual3d_View::Projects (const Standard_Real theX,
1888 const Standard_Real theY,
1889 const Standard_Real theZ,
1890 Standard_Real& thePX,
1891 Standard_Real& thePY,
1892 Standard_Real& thePZ) const
b5ac8292 1893{
197ac94e 1894 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
7fd59977 1895
197ac94e 1896 gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
1897 Standard_Real aXSize = aViewSpaceDimensions.X();
1898 Standard_Real aYSize = aViewSpaceDimensions.Y();
1899 Standard_Real aZSize = aViewSpaceDimensions.Z();
7fd59977 1900
197ac94e 1901 gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
7fd59977 1902
197ac94e 1903 // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
1904 thePX = aPoint.X() * aXSize * 0.5;
1905 thePY = aPoint.Y() * aYSize * 0.5;
1906 thePZ = aPoint.Z() * aZSize * 0.5;
7fd59977 1907}
1908
d4f1753b 1909// =======================================================================
1910// function : Identification
1911// purpose :
1912// =======================================================================
1913Standard_Integer Visual3d_View::Identification() const
1914{
1915 return MyCView.ViewId;
7fd59977 1916}
1917
d4f1753b 1918// =======================================================================
1919// function : ZBufferIsActivated
1920// purpose :
1921// =======================================================================
1922Standard_Boolean Visual3d_View::ZBufferIsActivated() const
1923{
1924 if (IsDeleted()
1925 || !IsDefined()
1926 || !IsActive())
1927 {
1928 return Standard_False;
1929 }
7fd59977 1930
d4f1753b 1931 if (MyCView.Context.ZBufferActivity == -1)
1932 {
1933 // not forced by the programmer => depends on the type of visualisation
1934 return MyContext.Visualization () == Visual3d_TOV_SHADING;
1935 }
1936 return MyCView.Context.ZBufferActivity != 0; // 0 or 1 => forced by the programmer
1937}
7fd59977 1938
d4f1753b 1939// =======================================================================
1940// function : SetTransparency
1941// purpose :
1942// =======================================================================
1943void Visual3d_View::SetTransparency (const Standard_Boolean theActivity)
1944{
1945 if (IsDeleted()
1946 || !IsDefined()
1947 || !IsActive())
1948 {
1949 return;
1950 }
7fd59977 1951
d4f1753b 1952 myGraphicDriver->Transparency (MyCView, theActivity);
1953}
7fd59977 1954
d4f1753b 1955// =======================================================================
1956// function : SetZBufferActivity
1957// purpose :
1958// =======================================================================
1959void Visual3d_View::SetZBufferActivity (const Standard_Integer theActivity)
1960{
1961 if (IsDeleted()
1962 || MyCView.Context.ZBufferActivity == theActivity
1963 || !IsDefined()
1964 || !IsActive())
1965 {
1966 return;
1967 }
7fd59977 1968
d4f1753b 1969 MyCView.Context.ZBufferActivity = theActivity;
1970 myGraphicDriver->SetVisualisation (MyCView);
7fd59977 1971}
1972
d4f1753b 1973// =======================================================================
1974// function : UpdateView
1975// purpose :
1976// =======================================================================
1977void Visual3d_View::UpdateView()
1978{
1979 MyCView.Context.Aliasing = MyContext.AliasingIsOn();
1980 MyCView.Context.BackZClipping = MyContext.BackZClippingIsOn();
1981 MyCView.Context.FrontZClipping = MyContext.FrontZClippingIsOn();
1982 MyCView.Context.DepthCueing = MyContext.DepthCueingIsOn();
7fd59977 1983
d4f1753b 1984 MyCView.Context.ZClipFrontPlane = float (MyContext.ZClippingFrontPlane());
1985 MyCView.Context.ZClipBackPlane = float (MyContext.ZClippingBackPlane());
1986 MyCView.Context.DepthFrontPlane = float (MyContext.DepthCueingFrontPlane());
1987 MyCView.Context.DepthBackPlane = float (MyContext.DepthCueingBackPlane());
7fd59977 1988
d4f1753b 1989 MyCView.Context.Model = MyContext.Model();
1990 MyCView.Context.Visualization = MyContext.Visualization();
7fd59977 1991
d4f1753b 1992 MyCView.Context.TextureEnv = MyContext.TextureEnv();
1993 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
7fd59977 1994}
1995
d4f1753b 1996// =======================================================================
1997// function : Compute
1998// purpose :
1999// =======================================================================
2000void Visual3d_View::Compute()
2001{
2002 // force HLRValidation to False on all structures calculated in the view
2003 const Standard_Integer aNbCompStructs = myStructsComputed.Length();
2004 for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
2005 {
2006 myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
2007 }
7fd59977 2008
d4f1753b 2009 if (!ComputedMode())
2010 {
2011 return;
2012 }
7fd59977 2013
d4f1753b 2014 // Change of orientation or of projection type =>
2015 // Remove structures that were calculated for the previous orientation.
2016 // Recalculation of new structures.
2017 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
2018 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
2019 {
2020 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStructIter.Key());
2021 if (anAnswer == Visual3d_TOA_COMPUTE)
2022 {
2023 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
2024 }
2025 }
7fd59977 2026
d4f1753b 2027 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
2028 {
2029 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
2030 }
7fd59977 2031}
2032
d4f1753b 2033// =======================================================================
2034// function : ReCompute
2035// purpose :
2036// =======================================================================
2037void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
2038{
2039 theStruct->CalculateBoundBox();
2040 if (!theStruct->IsMutable()
2041 && !theStruct->CStructure()->IsForHighlight
2042 && !theStruct->CStructure()->IsInfinite)
2043 {
2044 const Standard_Integer aLayerId = theStruct->DisplayPriority();
2045 myGraphicDriver->InvalidateBVHData(MyCView, aLayerId);
2046 }
7fd59977 2047
d4f1753b 2048 if (!ComputedMode()
2049 || IsDeleted()
2050 || !IsDefined()
2051 || !IsActive()
2052 || !MyWindow->IsMapped()
2053 || !theStruct->IsDisplayed())
2054 {
2055 return;
2056 }
7fd59977 2057
d4f1753b 2058 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
2059 if (anAnswer != Visual3d_TOA_COMPUTE)
2060 {
2061 return;
2062 }
7fd59977 2063
d4f1753b 2064 const Standard_Integer anIndex = IsComputed (theStruct);
2065 if (anIndex == 0)
2066 {
2067 return;
2068 }
7fd59977 2069
d4f1753b 2070 // compute + validation
2071 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
2072 for (Standard_Integer aRow = 0; aRow <= 3; ++aRow)
2073 {
2074 for (Standard_Integer aCol = 0; aCol <= 3; ++aCol)
2075 {
2076 anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0);
2077 }
2078 }
2079 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
2080 theStruct->Transform (aTrsf);
2081
2082 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
2083 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
2084 aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
2085 theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct)
2086 : theStruct->Compute (this, aCompStruct);
2087 aCompStruct->SetHLRValidation (Standard_True);
2088
2089 // of which type will be the computed?
2090 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
2091 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
2092 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
2093 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
2094 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
2095 if (toComputeWireframe)
2096 {
2097 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
2098 }
2099 else if (toComputeShading)
2100 {
2101 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
2102 }
7fd59977 2103
d4f1753b 2104 if (theStruct->IsHighlighted())
2105 {
2106 aCompStruct->SetHighlightColor (theStruct->HighlightColor());
2107 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2108 }
7fd59977 2109
d4f1753b 2110 // The previous calculation is removed and the new one is dislayed
2111 myGraphicDriver->EraseStructure (MyCView, *aCompStructOld->CStructure());
2112 myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), theStruct->DisplayPriority());
7fd59977 2113
d4f1753b 2114 // why not just replace existing items?
2115 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
2116 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
7fd59977 2117
d4f1753b 2118 // hlhsr and the new associated compute are added
2119 myStructsToCompute.Append (theStruct);
2120 myStructsComputed .Append (aCompStruct);
7fd59977 2121
d4f1753b 2122 // hlhsr and the new associated compute are removed
2123 myStructsToCompute.Remove (anIndex);
2124 myStructsComputed .Remove (anIndex);
2125}
7fd59977 2126
d4f1753b 2127// =======================================================================
2128// function : GraphicDriver
2129// purpose :
2130// =======================================================================
2131const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver() const
2132{
2133 return myGraphicDriver;
7fd59977 2134}
2135
d4f1753b 2136// =======================================================================
2137// function : HaveTheSameOwner
2138// purpose :
2139// =======================================================================
2140Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStruct) const
2141{
2142 // Find in the sequence of already calculated structures
2143 // 1/ Structure with the same Owner as <AStructure>
2144 // 2/ Which is not <AStructure>
2145 // 3/ COMPUTED which of is valid
2146 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
2147 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
2148 {
2149 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
2150 if (aStructToComp->Owner() == theStruct->Owner()
2151 && aStructToComp->Identification() != theStruct->Identification())
2152 {
2153 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
2154 if (aStructComp->HLRValidation())
2155 {
2156 return aStructIter;
2157 }
2158 }
2159 }
2160 return 0;
2161}
b7cd4ba7 2162
d4f1753b 2163// =======================================================================
2164// function : CView
2165// purpose :
2166// =======================================================================
2167Standard_Address Visual3d_View::CView() const
2168{
2169 return Standard_Address (&MyCView);
2170}
7fd59977 2171
d4f1753b 2172// =======================================================================
2173// function : ZBufferTriedronSetup
2174// purpose :
2175// =======================================================================
2176void Visual3d_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor,
2177 const Quantity_NameOfColor theYColor,
2178 const Quantity_NameOfColor theZColor,
2179 const Standard_Real theSizeRatio,
2180 const Standard_Real theAxisDiametr,
2181 const Standard_Integer theNbFacettes)
2182{
2183 myGraphicDriver->ZBufferTriedronSetup (theXColor, theYColor, theZColor,
2184 theSizeRatio, theAxisDiametr, theNbFacettes);
2185}
7fd59977 2186
d4f1753b 2187// =======================================================================
2188// function : TriedronDisplay
2189// purpose :
2190// =======================================================================
2191void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
2192 const Quantity_NameOfColor theColor,
2193 const Standard_Real theScale,
2194 const Standard_Boolean theAsWireframe)
2195{
2196 myGraphicDriver->TriedronDisplay (MyCView, thePosition, theColor, theScale, theAsWireframe);
7fd59977 2197}
2198
d4f1753b 2199// =======================================================================
2200// function : TriedronErase
2201// purpose :
2202// =======================================================================
2203void Visual3d_View::TriedronErase()
2204{
2205 myGraphicDriver->TriedronErase (MyCView);
7fd59977 2206}
2207
d4f1753b 2208// =======================================================================
2209// function : TriedronEcho
2210// purpose :
2211// =======================================================================
2212void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType)
2213{
2214 myGraphicDriver->TriedronEcho (MyCView, theType);
7fd59977 2215}
2216
d4f1753b 2217static Standard_Boolean checkFloat (const Standard_Real theValue)
2218{
2219 return theValue > -FLT_MAX
2220 && theValue < FLT_MAX;
7fd59977 2221}
2222
d4f1753b 2223static void SetMinMaxValuesCallback (Visual3d_View* theView)
7fd59977 2224{
d4f1753b 2225 Graphic3d_Vec3d aMin, aMax;
2226 theView->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2227 aMax.x(), aMax.y(), aMax.z());
2228 if (checkFloat (aMin.x()) && checkFloat (aMin.y()) && checkFloat (aMin.z())
2229 && checkFloat (aMax.x()) && checkFloat (aMax.y()) && checkFloat (aMax.z()))
2230 {
2231 const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver();
2232 aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.x(), (Standard_ShortReal )aMin.y(), (Standard_ShortReal )aMin.z(),
2233 (Standard_ShortReal )aMax.x(), (Standard_ShortReal )aMax.y(), (Standard_ShortReal )aMax.z());
2234 }
7fd59977 2235}
2236
d4f1753b 2237// =======================================================================
2238// function : GetGraduatedTrihedron
2239// purpose :
2240// =======================================================================
2241Standard_Boolean Visual3d_View::GetGraduatedTrihedron (TCollection_ExtendedString& theXName,
2242 TCollection_ExtendedString& theYName,
2243 TCollection_ExtendedString& theZName,
2244 Standard_Boolean& theToDrawXName,
2245 Standard_Boolean& theToDrawYName,
2246 Standard_Boolean& theToDrawZName,
2247 Standard_Boolean& theToDrawXValues,
2248 Standard_Boolean& theToDrawYValues,
2249 Standard_Boolean& theToDrawZValues,
2250 Standard_Boolean& theToDrawGrid,
2251 Standard_Boolean& theToDrawAxes,
2252 Standard_Integer& theNbX,
2253 Standard_Integer& theNbY,
2254 Standard_Integer& theNbZ,
2255 Standard_Integer& theXOffset,
2256 Standard_Integer& theYOffset,
2257 Standard_Integer& theZOffset,
2258 Standard_Integer& theXAxisOffset,
2259 Standard_Integer& theYAxisOffset,
2260 Standard_Integer& theZAxisOffset,
2261 Standard_Boolean& theToDrawXTickMarks,
2262 Standard_Boolean& theToDrawYTickMarks,
2263 Standard_Boolean& theToDrawZTickMarks,
2264 Standard_Integer& theXTickMarkLength,
2265 Standard_Integer& theYTickMarkLength,
2266 Standard_Integer& theZTickMarkLength,
2267 Quantity_Color& theGridColor,
2268 Quantity_Color& theXNameColor,
2269 Quantity_Color& theYNameColor,
2270 Quantity_Color& theZNameColor,
2271 Quantity_Color& theXColor,
2272 Quantity_Color& theYColor,
2273 Quantity_Color& theZColor,
2274 TCollection_AsciiString& theFontOfNames,
2275 Font_FontAspect& theStyleOfNames,
2276 Standard_Integer& theSizeOfNames,
2277 TCollection_AsciiString& theFontOfValues,
2278 Font_FontAspect& theStyleOfValues,
2279 Standard_Integer& theSizeOfValues) const
7fd59977 2280{
d4f1753b 2281 if (!MyGTrihedron.ptrVisual3dView)
2282 {
2283 return Standard_False;
2284 }
7fd59977 2285
d4f1753b 2286 theXName = MyGTrihedron.xname;
2287 theYName = MyGTrihedron.yname;
2288 theZName = MyGTrihedron.zname;
2289 theToDrawXName = MyGTrihedron.xdrawname;
2290 theToDrawYName = MyGTrihedron.ydrawname;
2291 theToDrawZName = MyGTrihedron.zdrawname;
2292 theToDrawXValues = MyGTrihedron.xdrawvalues;
2293 theToDrawYValues = MyGTrihedron.ydrawvalues;
2294 theToDrawZValues = MyGTrihedron.zdrawvalues;
2295 theToDrawGrid = MyGTrihedron.drawgrid;
2296 theToDrawAxes = MyGTrihedron.drawaxes;
2297 theNbX = MyGTrihedron.nbx;
2298 theNbY = MyGTrihedron.nby;
2299 theNbZ = MyGTrihedron.nbz;
2300 theXOffset = MyGTrihedron.xoffset;
2301 theYOffset = MyGTrihedron.yoffset;
2302 theZOffset = MyGTrihedron.zoffset;
2303 theXAxisOffset = MyGTrihedron.xaxisoffset;
2304 theYAxisOffset = MyGTrihedron.yaxisoffset;
2305 theZAxisOffset = MyGTrihedron.zaxisoffset;
2306 theToDrawXTickMarks = MyGTrihedron.xdrawtickmarks;
2307 theToDrawYTickMarks = MyGTrihedron.ydrawtickmarks;
2308 theToDrawZTickMarks = MyGTrihedron.zdrawtickmarks;
2309 theXTickMarkLength = MyGTrihedron.xtickmarklength;
2310 theYTickMarkLength = MyGTrihedron.ytickmarklength;
2311 theZTickMarkLength = MyGTrihedron.ztickmarklength;
2312 theGridColor = MyGTrihedron.gridcolor;
2313 theXNameColor = MyGTrihedron.xnamecolor;
2314 theYNameColor = MyGTrihedron.ynamecolor;
2315 theZNameColor = MyGTrihedron.znamecolor;
2316 theXColor = MyGTrihedron.xcolor;
2317 theYColor = MyGTrihedron.ycolor;
2318 theZColor = MyGTrihedron.zcolor;
2319 theFontOfNames = MyGTrihedron.fontOfNames;
2320 theStyleOfNames = MyGTrihedron.styleOfNames;
2321 theSizeOfNames = MyGTrihedron.sizeOfNames;
2322 theFontOfValues = MyGTrihedron.fontOfValues;
2323 theStyleOfValues = MyGTrihedron.styleOfValues;
2324 theSizeOfValues = MyGTrihedron.sizeOfValues;
2325 return Standard_True;
7fd59977 2326}
2327
d4f1753b 2328// =======================================================================
2329// function : GraduatedTrihedronDisplay
2330// purpose :
2331// =======================================================================
2332void Visual3d_View::GraduatedTrihedronDisplay (const TCollection_ExtendedString& theXName,
2333 const TCollection_ExtendedString& theYName,
2334 const TCollection_ExtendedString& theZName,
2335 const Standard_Boolean theToDrawXName,
2336 const Standard_Boolean theToDrawYName,
2337 const Standard_Boolean theToDrawZName,
2338 const Standard_Boolean theToDrawXValues,
2339 const Standard_Boolean theToDrawYValues,
2340 const Standard_Boolean theToDrawZValues,
2341 const Standard_Boolean theToDrawGrid,
2342 const Standard_Boolean theToDrawAxes,
2343 const Standard_Integer theNbX,
2344 const Standard_Integer theNbY,
2345 const Standard_Integer theNbZ,
2346 const Standard_Integer theXOffset,
2347 const Standard_Integer theYOffset,
2348 const Standard_Integer theZOffset,
2349 const Standard_Integer theXAxisOffset,
2350 const Standard_Integer theYAxisOffset,
2351 const Standard_Integer theZAxisOffset,
2352 const Standard_Boolean theToDrawXTickMarks,
2353 const Standard_Boolean theToDrawYTickMarks,
2354 const Standard_Boolean theToDrawZTickMarks,
2355 const Standard_Integer theXTickMarkLength,
2356 const Standard_Integer theYTickMarkLength,
2357 const Standard_Integer theZTickMarkLength,
2358 const Quantity_Color& theGridColor,
2359 const Quantity_Color& theXNameColor,
2360 const Quantity_Color& theYNameColor,
2361 const Quantity_Color& theZNameColor,
2362 const Quantity_Color& theXColor,
2363 const Quantity_Color& theYColor,
2364 const Quantity_Color& theZColor,
2365 const TCollection_AsciiString& theFontOfNames,
2366 const Font_FontAspect theStyleOfNames,
2367 const Standard_Integer theSizeOfNames,
2368 const TCollection_AsciiString& theFontOfValues,
2369 const Font_FontAspect theStyleOfValues,
2370 const Standard_Integer theSizeOfValues)
2371{
2372 MyGTrihedron.xname = theXName;
2373 MyGTrihedron.yname = theYName;
2374 MyGTrihedron.zname = theZName;
2375 MyGTrihedron.xdrawname = theToDrawXName;
2376 MyGTrihedron.ydrawname = theToDrawYName;
2377 MyGTrihedron.zdrawname = theToDrawZName;
2378 MyGTrihedron.xdrawvalues = theToDrawXValues;
2379 MyGTrihedron.ydrawvalues = theToDrawYValues;
2380 MyGTrihedron.zdrawvalues = theToDrawZValues;
2381 MyGTrihedron.drawgrid = theToDrawGrid;
2382 MyGTrihedron.drawaxes = theToDrawAxes;
2383 MyGTrihedron.nbx = theNbX;
2384 MyGTrihedron.nby = theNbY;
2385 MyGTrihedron.nbz = theNbZ;
2386 MyGTrihedron.xoffset = theXOffset;
2387 MyGTrihedron.yoffset = theYOffset;
2388 MyGTrihedron.zoffset = theZOffset;
2389 MyGTrihedron.xaxisoffset = theXAxisOffset;
2390 MyGTrihedron.yaxisoffset = theYAxisOffset;
2391 MyGTrihedron.zaxisoffset = theZAxisOffset;
2392 MyGTrihedron.xdrawtickmarks = theToDrawXTickMarks;
2393 MyGTrihedron.ydrawtickmarks = theToDrawYTickMarks;
2394 MyGTrihedron.zdrawtickmarks = theToDrawZTickMarks;
2395 MyGTrihedron.xtickmarklength = theXTickMarkLength;
2396 MyGTrihedron.ytickmarklength = theYTickMarkLength;
2397 MyGTrihedron.ztickmarklength = theZTickMarkLength;
2398 MyGTrihedron.gridcolor = theGridColor;
2399 MyGTrihedron.xnamecolor = theXNameColor;
2400 MyGTrihedron.ynamecolor = theYNameColor;
2401 MyGTrihedron.znamecolor = theZNameColor;
2402 MyGTrihedron.xcolor = theXColor;
2403 MyGTrihedron.ycolor = theYColor;
2404 MyGTrihedron.zcolor = theZColor;
2405 MyGTrihedron.fontOfNames = theFontOfNames;
2406 MyGTrihedron.styleOfNames = theStyleOfNames;
2407 MyGTrihedron.sizeOfNames = theSizeOfNames;
2408 MyGTrihedron.fontOfValues = theFontOfValues;
2409 MyGTrihedron.styleOfValues = theStyleOfValues;
2410 MyGTrihedron.sizeOfValues = theSizeOfValues;
2411
2412 MyGTrihedron.ptrVisual3dView = this;
2413 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
2414 myGraphicDriver->GraduatedTrihedronDisplay (MyCView, MyGTrihedron);
7fd59977 2415}
2416
d4f1753b 2417// =======================================================================
2418// function : GraduatedTrihedronErase
2419// purpose :
2420// =======================================================================
7fd59977 2421void Visual3d_View::GraduatedTrihedronErase()
2422{
d4f1753b 2423 MyGTrihedron.ptrVisual3dView = NULL;
2424 myGraphicDriver->GraduatedTrihedronErase (MyCView);
7fd59977 2425}
2426
d4f1753b 2427// =======================================================================
2428// function : UnderLayer
2429// purpose :
2430// =======================================================================
2431const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer() const
2432{
2433 return myViewManager->UnderLayer();
7fd59977 2434}
2435
d4f1753b 2436// =======================================================================
2437// function : OverLayer
2438// purpose :
2439// =======================================================================
2440const Handle(Visual3d_Layer)& Visual3d_View::OverLayer() const
2441{
2442 return myViewManager->OverLayer();
7fd59977 2443}
2444
d4f1753b 2445// =======================================================================
2446// function : LightLimit
2447// purpose :
2448// =======================================================================
2449Standard_Integer Visual3d_View::LightLimit() const
2450{
2451 return myGraphicDriver->InquireLightLimit();
7fd59977 2452}
2453
d4f1753b 2454// =======================================================================
2455// function : PlaneLimit
2456// purpose :
2457// =======================================================================
2458Standard_Integer Visual3d_View::PlaneLimit() const
2459{
2460 return myGraphicDriver->InquirePlaneLimit();
7fd59977 2461}
2462
d4f1753b 2463// =======================================================================
2464// function : ViewManager
2465// purpose :
2466// =======================================================================
bf75be98 2467Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
2468{
d4f1753b 2469 return myViewManager;
7fd59977 2470}
7fd59977 2471
d4f1753b 2472// =======================================================================
2473// function : SetComputedMode
2474// purpose :
2475// =======================================================================
2476void Visual3d_View::SetComputedMode (const Standard_Boolean theMode)
de75ed09 2477{
d4f1753b 2478 if (( theMode && myIsInComputedMode)
2479 || (!theMode && !myIsInComputedMode))
de75ed09 2480 {
2481 return;
2482 }
7fd59977 2483
d4f1753b 2484 myIsInComputedMode = theMode;
2485 if (!myIsInComputedMode)
2486 {
2487 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
2488 {
2489 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
2490 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2491 if (anAnswer != Visual3d_TOA_COMPUTE)
2492 {
2493 continue;
2494 }
7fd59977 2495
d4f1753b 2496 const Standard_Integer anIndex = IsComputed (aStruct);
2497 if (anIndex != 0)
2498 {
2499 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
2500 myGraphicDriver->EraseStructure (MyCView, *aStructComp->CStructure());
2501 myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), aStruct->DisplayPriority());
2502 }
2503 }
2504 return;
2505 }
7fd59977 2506
d4f1753b 2507 for (Graphic3d_MapIteratorOfMapOfStructure aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
2508 {
2509 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
2510 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2511 if (anAnswer != Visual3d_TOA_COMPUTE)
2512 {
2513 continue;
2514 }
7fd59977 2515
d4f1753b 2516 const Standard_Integer anIndex = IsComputed (aStruct);
2517 if (anIndex != 0)
2518 {
2519 myGraphicDriver->EraseStructure (MyCView, *aStruct->CStructure());
2520 myGraphicDriver->DisplayStructure (MyCView, *(myStructsComputed.Value (anIndex)->CStructure()), aStruct->DisplayPriority());
7fd59977 2521
d4f1753b 2522 Display (aStruct, Aspect_TOU_WAIT);
2523 if (aStruct->IsHighlighted())
2524 {
2525 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
2526 if (!aCompStruct->IsHighlighted())
2527 {
2528 aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2529 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2530 }
2531 }
2532 }
2533 else
2534 {
2535 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
2536 aStruct->Transform (aTrsf);
2537 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this);
2538 aCompStruct->SetHLRValidation (Standard_True);
2539
2540 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
2541 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
2542 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
2543 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
2544 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
2545 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
2546 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
2547
2548 if (aStruct->IsHighlighted())
2549 {
2550 aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2551 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2552 }
7fd59977 2553
d4f1753b 2554 Standard_Boolean hasResult = Standard_False;
2555 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
2556 const Standard_Integer aStructId = aStruct->Identification();
2557 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
2558 {
2559 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
2560 {
2561 hasResult = Standard_True;
2562 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
2563 break;
2564 }
2565 }
7fd59977 2566
d4f1753b 2567 if (!hasResult)
2568 {
2569 myStructsToCompute.Append (aStruct);
2570 myStructsComputed .Append (aCompStruct);
2571 }
7fd59977 2572
d4f1753b 2573 myGraphicDriver->EraseStructure (MyCView, *aStruct->CStructure());
2574 myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), aStruct->DisplayPriority());
2575 }
2576 }
2577 Update (myViewManager->UpdateMode());
2578}
7fd59977 2579
d4f1753b 2580// =======================================================================
2581// function : ComputedMode
2582// purpose :
2583// =======================================================================
2584Standard_Boolean Visual3d_View::ComputedMode() const
2585{
2586 return myIsInComputedMode;
2587}
7fd59977 2588
d4f1753b 2589// =======================================================================
2590// function : SetBackFacingModel
2591// purpose :
2592// =======================================================================
2593void Visual3d_View::SetBackFacingModel (const Visual3d_TypeOfBackfacingModel theModel)
2594{
2595 switch (theModel)
2596 {
2597 default:
2598 case Visual3d_TOBM_AUTOMATIC:
2599 MyCView.Backfacing = 0;
2600 break;
2601 case Visual3d_TOBM_FORCE:
2602 MyCView.Backfacing = 1;
2603 break;
2604 case Visual3d_TOBM_DISABLE:
2605 MyCView.Backfacing = -1;
2606 break;
2607 }
2608 myGraphicDriver->SetBackFacingModel (MyCView);
2609}
7fd59977 2610
d4f1753b 2611// =======================================================================
2612// function : BackFacingModel
2613// purpose :
2614// =======================================================================
2615Visual3d_TypeOfBackfacingModel Visual3d_View::BackFacingModel() const
2616{
2617 switch (MyCView.Backfacing)
2618 {
2619 case 0: return Visual3d_TOBM_AUTOMATIC;
2620 case 1: return Visual3d_TOBM_FORCE;
2621 }
2622 return Visual3d_TOBM_DISABLE;
2623}
7fd59977 2624
d4f1753b 2625// =======================================================================
2626// function : EnableDepthTest
2627// purpose :
2628// =======================================================================
2629void Visual3d_View::EnableDepthTest (const Standard_Boolean theToEnable) const
7fd59977 2630{
d4f1753b 2631 myGraphicDriver->SetDepthTestEnabled (MyCView, theToEnable);
7fd59977 2632}
2633
d4f1753b 2634// =======================================================================
2635// function : IsDepthTestEnabled
2636// purpose :
2637// =======================================================================
7fd59977 2638Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
2639{
d4f1753b 2640 return myGraphicDriver->IsDepthTestEnabled (MyCView);
7fd59977 2641}
2642
d4f1753b 2643// =======================================================================
2644// function : ReadDepths
2645// purpose :
2646// =======================================================================
2647void Visual3d_View::ReadDepths (const Standard_Integer theX,
2648 const Standard_Integer theY,
2649 const Standard_Integer theWidth,
2650 const Standard_Integer theHeight,
2651 const Standard_Address theBuffer) const
7fd59977 2652{
d4f1753b 2653 myGraphicDriver->ReadDepths (MyCView, theX, theY, theWidth, theHeight, theBuffer);
7fd59977 2654}
2655
d4f1753b 2656// =======================================================================
2657// function : FBOCreate
2658// purpose :
2659// =======================================================================
7fd59977 2660Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
2661 const Standard_Integer theHeight)
2662{
d4f1753b 2663 return myGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
7fd59977 2664}
2665
d4f1753b 2666// =======================================================================
2667// function : FBORelease
2668// purpose :
2669// =======================================================================
7fd59977 2670void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
2671{
d4f1753b 2672 myGraphicDriver->FBORelease( MyCView, theFBOPtr );
7fd59977 2673}
2674
d4f1753b 2675// =======================================================================
2676// function : FBOGetDimensions
2677// purpose :
2678// =======================================================================
7fd59977 2679void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
2680 Standard_Integer& theWidth, Standard_Integer& theHeight,
2681 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
2682{
d4f1753b 2683 myGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
7fd59977 2684 theWidth, theHeight,
2685 theWidthMax, theHeightMax );
2686}
2687
d4f1753b 2688// =======================================================================
2689// function : FBOChangeViewport
2690// purpose :
2691// =======================================================================
7fd59977 2692void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
2693 const Standard_Integer theWidth, const Standard_Integer theHeight)
2694{
d4f1753b 2695 myGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
7fd59977 2696 theWidth, theHeight );
2697}
2698
d4f1753b 2699// =======================================================================
2700// function : BufferDump
2701// purpose :
2702// =======================================================================
692613e5 2703Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
2704 const Graphic3d_BufferType& theBufferType)
7fd59977 2705{
d4f1753b 2706 return myGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
7fd59977 2707}
2708
d4f1753b 2709// =======================================================================
2710// function : EnableGLLight
2711// purpose :
2712// =======================================================================
7fd59977 2713void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
2714{
d4f1753b 2715 myGraphicDriver->SetGLLightEnabled( MyCView, enable );
7fd59977 2716}
2717
d4f1753b 2718// =======================================================================
2719// function : IsGLLightEnabled
2720// purpose :
2721// =======================================================================
7fd59977 2722Standard_Boolean Visual3d_View::IsGLLightEnabled() const
2723{
d4f1753b 2724 return myGraphicDriver->IsGLLightEnabled( MyCView );
7fd59977 2725}
2726
d4f1753b 2727// =======================================================================
2728// function : Export
2729// purpose :
2730// =======================================================================
5cedc27f
K
2731Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
2732 const Graphic3d_ExportFormat theFormat,
2733 const Graphic3d_SortType theSortType,
2734 const Standard_Real thePrecision,
2735 const Standard_Address theProgressBarFunc,
2736 const Standard_Address theProgressObject) const
7fd59977 2737{
d4f1753b 2738 Handle(Visual3d_Layer) anUnderLayer = myViewManager->UnderLayer();
2739 Handle(Visual3d_Layer) anOverLayer = myViewManager->OverLayer();
7fd59977 2740
5cedc27f
K
2741 Aspect_CLayer2d anOverCLayer;
2742 Aspect_CLayer2d anUnderCLayer;
2743 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
7fd59977 2744
5cedc27f
K
2745 if (!anOverLayer.IsNull())
2746 anOverCLayer = anOverLayer->CLayer();
2747 if (!anUnderLayer.IsNull())
2748 anUnderCLayer = anUnderLayer->CLayer();
7fd59977 2749
5cedc27f
K
2750 Standard_Integer aWidth, aHeight;
2751 Window()->Size (aWidth, aHeight);
7fd59977 2752
d4f1753b 2753 return myGraphicDriver->Export (theFileName, theFormat, theSortType,
5cedc27f
K
2754 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
2755 thePrecision, theProgressBarFunc, theProgressObject);
7fd59977 2756}
59f45b7c 2757
d4f1753b 2758// =======================================================================
2759// function : SetZLayerSettings
2760// purpose :
2761// =======================================================================
c5751993 2762void Visual3d_View::SetZLayerSettings (const Standard_Integer theLayerId,
2763 const Graphic3d_ZLayerSettings& theSettings)
2764{
d4f1753b 2765 myGraphicDriver->SetZLayerSettings (MyCView, theLayerId, theSettings);
c5751993 2766}
2767
d4f1753b 2768// =======================================================================
2769// function : AddZLayer
2770// purpose :
2771// =======================================================================
59f45b7c 2772void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
2773{
d4f1753b 2774 myGraphicDriver->AddZLayer (MyCView, theLayerId);
59f45b7c 2775}
2776
d4f1753b 2777// =======================================================================
2778// function : RemoveZLayer
2779// purpose :
2780// =======================================================================
59f45b7c 2781void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
2782{
d4f1753b 2783 myGraphicDriver->RemoveZLayer (MyCView, theLayerId);
59f45b7c 2784}
2785
d4f1753b 2786// =======================================================================
2787// function : ChangeZLayer
2788// purpose :
2789// =======================================================================
59f45b7c 2790void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
2791 const Standard_Integer theLayerId)
2792{
d4f1753b 2793 myGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), MyCView, theLayerId);
2794}
2795
2796// =======================================================================
2797// function : Print
2798// purpose :
2799// =======================================================================
2800Standard_Boolean Visual3d_View::Print (const Aspect_Handle thePrintDC,
2801 const Standard_Boolean theToShowBackground,
2802 const Standard_CString theFilename,
2803 const Aspect_PrintAlgo thePrintAlgorithm,
2804 const Standard_Real theScaleFactor) const
2805{
2806 return Print (myViewManager->UnderLayer(),
2807 myViewManager->OverLayer(),
2808 thePrintDC, theToShowBackground,
2809 theFilename, thePrintAlgorithm,
2810 theScaleFactor);
2811}
2812
2813// =======================================================================
2814// function : Print
2815// purpose :
2816// =======================================================================
2817Standard_Boolean Visual3d_View::Print (const Handle(Visual3d_Layer)& theUnderLayer,
2818 const Handle(Visual3d_Layer)& theOverLayer,
2819 const Aspect_Handle thePrintDC,
2820 const Standard_Boolean theToShowBackground,
2821 const Standard_CString theFilename,
2822 const Aspect_PrintAlgo thePrintAlgorithm,
2823 const Standard_Real theScaleFactor) const
2824{
2825 if (IsDeleted()
2826 || !IsDefined()
2827 || !IsActive()
2828 || !MyWindow->IsMapped())
2829 {
2830 return Standard_False;
2831 }
2832
2833 Aspect_CLayer2d anOverCLayer;
2834 Aspect_CLayer2d anUnderCLayer;
2835 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2836 if (!theOverLayer.IsNull()) anOverCLayer = theOverLayer->CLayer();
2837 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
2838 return myGraphicDriver->Print (MyCView, anUnderCLayer, anOverCLayer,
2839 thePrintDC, theToShowBackground, theFilename,
2840 thePrintAlgorithm, theScaleFactor);
59f45b7c 2841}