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