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