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