973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
15 | #include <Aspect_Background.hxx> |
16 | #include <Aspect_GradientBackground.hxx> |
17 | #include <Aspect_Grid.hxx> |
c357e426 |
18 | #include <Aspect_IdentDefinitionError.hxx> |
42cf5bc1 |
19 | #include <gp_Ax3.hxx> |
20 | #include <Graphic3d_AspectMarker3d.hxx> |
21 | #include <Graphic3d_GraphicDriver.hxx> |
22 | #include <Graphic3d_Group.hxx> |
23 | #include <Graphic3d_Structure.hxx> |
24 | #include <Quantity_Color.hxx> |
c357e426 |
25 | #include <Standard_ErrorHandler.hxx> |
42cf5bc1 |
26 | #include <Standard_Type.hxx> |
7fd59977 |
27 | #include <V3d.hxx> |
6942f04a |
28 | #include <V3d_BadValue.hxx> |
42cf5bc1 |
29 | #include <V3d_CircularGrid.hxx> |
30 | #include <V3d_Light.hxx> |
31 | #include <V3d_RectangularGrid.hxx> |
32 | #include <V3d_View.hxx> |
33 | #include <V3d_Viewer.hxx> |
7fd59977 |
34 | |
c357e426 |
35 | // ======================================================================== |
36 | // function : V3d_Viewer |
37 | // purpose : |
38 | // ======================================================================== |
6942f04a |
39 | V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver, |
40 | const Standard_ExtString theName, |
41 | const Standard_CString theDomain, |
42 | const Standard_Real theViewSize, |
43 | const V3d_TypeOfOrientation theViewProj, |
44 | const Quantity_NameOfColor theViewBackground, |
45 | const V3d_TypeOfVisualization theVisualization, |
46 | const V3d_TypeOfShadingModel theShadingModel, |
47 | const V3d_TypeOfUpdate theUpdateMode, |
48 | const Standard_Boolean theComputedMode, |
49 | const Standard_Boolean theDefaultComputedMode, |
50 | const V3d_TypeOfSurfaceDetail theSurfaceDetail) |
51 | :myNextCount (-1), |
52 | myDriver (theDriver), |
53 | myName (TCollection_ExtendedString (theName)), |
54 | myDomain (TCollection_AsciiString (theDomain)), |
c357e426 |
55 | myStructureManager (new Graphic3d_StructureManager (theDriver)), |
7fd59977 |
56 | MyDefinedViews(), |
57 | MyActiveViews(), |
58 | MyDefinedLights(), |
59 | MyActiveLights(), |
7fd59977 |
60 | myActiveViewsIterator(), |
61 | myDefinedViewsIterator(), |
62 | myActiveLightsIterator(), |
63 | myDefinedLightsIterator(), |
6942f04a |
64 | myComputedMode (theComputedMode), |
65 | myDefaultComputedMode (theDefaultComputedMode), |
66 | myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))), |
67 | myDisplayPlane (Standard_False), |
679ecdee |
68 | myDisplayPlaneLength (theViewSize), |
69 | myGridEcho (Standard_True), |
c357e426 |
70 | myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast()), |
71 | myZLayerGenId (1, IntegerLast()) |
7fd59977 |
72 | { |
6942f04a |
73 | SetUpdateMode (theUpdateMode); |
74 | SetDefaultViewSize (theViewSize); |
75 | SetDefaultViewProj (theViewProj); |
76 | SetDefaultBackgroundColor (theViewBackground); |
77 | SetDefaultVisualization (theVisualization); |
78 | SetDefaultShadingModel (theShadingModel); |
79 | SetDefaultSurfaceDetail (theSurfaceDetail); |
80 | SetDefaultAngle (M_PI / 2.); |
81 | SetDefaultTypeOfView (V3d_ORTHOGRAPHIC); |
7fd59977 |
82 | |
83 | Quantity_Color Color1 (Quantity_NOC_GRAY50); |
84 | Quantity_Color Color2 (Quantity_NOC_GRAY70); |
85 | // Quantity_Color White (Quantity_NOC_WHITE); |
6942f04a |
86 | myRGrid = new V3d_RectangularGrid (this, Color1, Color2); |
87 | myCGrid = new V3d_CircularGrid (this, Color1, Color2); |
7fd59977 |
88 | myGridType = Aspect_GT_Rectangular; |
89 | } |
90 | |
c357e426 |
91 | // ======================================================================== |
92 | // function : CreateView |
93 | // purpose : |
94 | // ======================================================================== |
b5ac8292 |
95 | Handle(V3d_View) V3d_Viewer::CreateView () |
96 | { |
97 | return new V3d_View(this, MyDefaultTypeOfView); |
7fd59977 |
98 | } |
99 | |
c357e426 |
100 | // ======================================================================== |
101 | // function : SetViewOn |
102 | // purpose : |
103 | // ======================================================================== |
104 | void V3d_Viewer::SetViewOn() |
105 | { |
106 | for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()) |
107 | { |
108 | SetViewOn (ActiveView()); |
109 | } |
7fd59977 |
110 | } |
111 | |
c357e426 |
112 | // ======================================================================== |
113 | // function : SetViewOff |
114 | // purpose : |
115 | // ======================================================================== |
116 | void V3d_Viewer::SetViewOff() |
117 | { |
118 | for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()) |
119 | { |
120 | SetViewOff (ActiveView()); |
121 | } |
7fd59977 |
122 | } |
123 | |
c357e426 |
124 | // ======================================================================== |
125 | // function : SetViewOn |
126 | // purpose : |
127 | // ======================================================================== |
128 | void V3d_Viewer::SetViewOn (const Handle(V3d_View)& theView) |
129 | { |
130 | Handle(Graphic3d_CView) aViewImpl = theView->View(); |
131 | if (aViewImpl->IsDefined() && !IsActive (theView)) |
132 | { |
133 | MyActiveViews.Append (theView); |
134 | aViewImpl->Activate(); |
135 | for (InitActiveLights();MoreActiveLights();NextActiveLights()) |
136 | { |
137 | theView->SetLightOn (ActiveLight()); |
138 | } |
139 | |
140 | theView->SetGrid (myPrivilegedPlane, Grid ()); |
141 | theView->SetGridActivity (Grid ()->IsActive ()); |
142 | theView->Redraw(); |
7fd59977 |
143 | } |
144 | } |
145 | |
c357e426 |
146 | // ======================================================================== |
147 | // function : SetViewOff |
148 | // purpose : |
149 | // ======================================================================== |
150 | void V3d_Viewer::SetViewOff (const Handle(V3d_View)& theView) |
151 | { |
152 | Handle(Graphic3d_CView) aViewImpl = theView->View(); |
153 | if (aViewImpl->IsDefined() && IsActive (theView)) |
154 | { |
155 | MyActiveViews.Remove (theView); |
156 | aViewImpl->Deactivate() ; |
7fd59977 |
157 | } |
158 | } |
159 | |
c357e426 |
160 | // ======================================================================== |
161 | // function : ComputedMode |
162 | // purpose : |
163 | // ======================================================================== |
164 | Standard_Boolean V3d_Viewer::ComputedMode() const |
165 | { |
7fd59977 |
166 | return myComputedMode; |
167 | } |
168 | |
c357e426 |
169 | // ======================================================================== |
170 | // function : DefaultComputedMode |
171 | // purpose : |
172 | // ======================================================================== |
173 | Standard_Boolean V3d_Viewer::DefaultComputedMode() const |
174 | { |
7fd59977 |
175 | return myDefaultComputedMode; |
176 | } |
177 | |
c357e426 |
178 | // ======================================================================== |
179 | // function : Update |
180 | // purpose : |
181 | // ======================================================================== |
679ecdee |
182 | void V3d_Viewer::Update() |
183 | { |
c357e426 |
184 | // Redraw() is still here for compatibility with old code. |
185 | // See comments, the method is deprecated - Redraw() should |
186 | // be used instead. |
187 | Redraw(); |
7fd59977 |
188 | } |
189 | |
c357e426 |
190 | // ======================================================================== |
191 | // function : Redraw |
192 | // purpose : |
193 | // ======================================================================== |
679ecdee |
194 | void V3d_Viewer::Redraw()const |
195 | { |
c357e426 |
196 | TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews); |
197 | for (; anIt.More(); anIt.Next()) |
198 | { |
199 | Handle(V3d_View)::DownCast (anIt.Value())->Redraw(); |
200 | } |
7fd59977 |
201 | } |
202 | |
c357e426 |
203 | // ======================================================================== |
204 | // function : RedrawImmediate |
205 | // purpose : |
206 | // ======================================================================== |
679ecdee |
207 | void V3d_Viewer::RedrawImmediate() const |
208 | { |
c357e426 |
209 | TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews); |
210 | for (; anIt.More(); anIt.Next()) |
211 | { |
212 | Handle(V3d_View)::DownCast (anIt.Value())->RedrawImmediate(); |
213 | } |
679ecdee |
214 | } |
215 | |
c357e426 |
216 | // ======================================================================== |
217 | // function : Invalidate |
218 | // purpose : |
219 | // ======================================================================== |
679ecdee |
220 | void V3d_Viewer::Invalidate() const |
221 | { |
c357e426 |
222 | TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews); |
223 | for (; anIt.More(); anIt.Next()) |
224 | { |
225 | Handle(V3d_View)::DownCast (anIt.Value())->Invalidate(); |
226 | } |
679ecdee |
227 | } |
228 | |
c357e426 |
229 | // ======================================================================== |
230 | // function : Remove |
231 | // purpose : |
232 | // ======================================================================== |
233 | void V3d_Viewer::Remove() |
234 | { |
235 | myStructureManager->Remove(); |
7fd59977 |
236 | } |
237 | |
c357e426 |
238 | // ======================================================================== |
239 | // function : Erase |
240 | // purpose : |
241 | // ======================================================================== |
242 | void V3d_Viewer::Erase() const |
243 | { |
244 | myStructureManager->Erase(); |
7fd59977 |
245 | } |
246 | |
c357e426 |
247 | // ======================================================================== |
248 | // function : UnHighlight |
249 | // purpose : |
250 | // ======================================================================== |
251 | void V3d_Viewer::UnHighlight() const |
252 | { |
253 | myStructureManager->UnHighlight(); |
7fd59977 |
254 | } |
255 | |
256 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) { |
257 | Standard_Real V1 = v1 ; |
258 | Standard_Real V2 = v2 ; |
259 | Standard_Real V3 = v3 ; |
260 | |
261 | if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ; |
262 | if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ; |
263 | if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ; |
264 | |
265 | Quantity_Color C(V1,V2,V3,Type) ; |
7fd59977 |
266 | SetDefaultBackgroundColor(C); |
7fd59977 |
267 | } |
268 | |
b8ddfc2f |
269 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name) |
270 | { |
7fd59977 |
271 | Quantity_Color C(Name) ; |
7fd59977 |
272 | SetDefaultBackgroundColor(C); |
7fd59977 |
273 | } |
274 | |
b8ddfc2f |
275 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color) |
276 | { |
7fd59977 |
277 | MyBackground.SetColor(Color) ; |
278 | } |
7fd59977 |
279 | |
280 | void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1, |
281 | const Quantity_NameOfColor Name2, |
282 | const Aspect_GradientFillMethod FillStyle){ |
283 | |
284 | Quantity_Color C1(Name1) ; |
285 | Quantity_Color C2(Name2) ; |
286 | MyGradientBackground.SetColors(C1, C2, FillStyle); |
287 | |
288 | } |
289 | |
290 | void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1, |
291 | const Quantity_Color& Color2, |
292 | const Aspect_GradientFillMethod FillStyle ){ |
293 | |
294 | MyGradientBackground.SetColors(Color1, Color2, FillStyle); |
295 | |
296 | } |
297 | |
298 | |
299 | void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) { |
300 | |
6942f04a |
301 | V3d_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size"); |
7fd59977 |
302 | MyViewSize = Size ; |
303 | } |
304 | |
305 | void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) { |
306 | |
307 | MyViewProj = Orientation ; |
308 | } |
309 | |
310 | void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) { |
311 | |
312 | MyVisualization = Type ; |
313 | } |
7fd59977 |
314 | |
315 | void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) { |
316 | |
317 | MyShadingModel = Type ; |
318 | } |
319 | |
320 | void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) { |
321 | |
322 | MySurfaceDetail = Type ; |
323 | } |
324 | |
325 | void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) { |
326 | MyDefaultAngle = Angle; |
327 | } |
328 | |
329 | void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) { |
330 | MyDefaultTypeOfView = Type;} |
331 | |
c357e426 |
332 | // ======================================================================== |
333 | // function : SetUpdateMode |
334 | // purpose : |
335 | // ======================================================================== |
336 | void V3d_Viewer::SetUpdateMode (const V3d_TypeOfUpdate theMode) |
337 | { |
338 | myStructureManager->SetUpdateMode (static_cast<Aspect_TypeOfUpdate> (theMode)); |
7fd59977 |
339 | } |
340 | |
b8ddfc2f |
341 | void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const |
342 | { |
7fd59977 |
343 | Quantity_Color C = DefaultBackgroundColor(); |
7fd59977 |
344 | C.Values(V1,V2,V3,Type) ; |
345 | } |
346 | |
b8ddfc2f |
347 | Quantity_Color V3d_Viewer::DefaultBackgroundColor() const |
348 | { |
7fd59977 |
349 | return MyBackground.Color() ; |
350 | } |
7fd59977 |
351 | |
b8ddfc2f |
352 | void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const |
353 | { |
7fd59977 |
354 | MyGradientBackground.Colors(Color1,Color2); |
355 | } |
356 | |
357 | Standard_Real V3d_Viewer::DefaultViewSize() const { |
358 | return MyViewSize ; |
359 | } |
360 | |
361 | V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const { |
362 | return MyViewProj ; |
363 | } |
364 | |
365 | V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const { |
366 | return MyVisualization ; |
367 | } |
368 | |
369 | V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const { |
370 | return MyShadingModel ; |
371 | } |
372 | |
373 | V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const { |
374 | return MySurfaceDetail ; |
375 | } |
376 | |
377 | Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const { |
378 | return MyDefaultAngle; |
379 | } |
380 | |
c357e426 |
381 | // ======================================================================== |
382 | // function : UpdateMode |
383 | // purpose : |
384 | // ======================================================================== |
385 | V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const |
386 | { |
387 | return static_cast<V3d_TypeOfUpdate> (myStructureManager->UpdateMode()); |
7fd59977 |
388 | } |
389 | |
390 | Standard_Boolean V3d_Viewer::IfMoreViews() const { |
391 | Standard_Boolean TheStatus = Standard_False ; |
392 | |
393 | #ifdef NEW |
c357e426 |
394 | if (MyActiveViews->Length() < myDriver->InquireViewLimit()) |
7fd59977 |
395 | #endif /*NEW*/ |
396 | TheStatus = Standard_True ; |
397 | return TheStatus ; |
398 | } |
399 | |
c357e426 |
400 | // ======================================================================== |
401 | // function : StructureManager |
402 | // purpose : |
403 | // ======================================================================== |
404 | Handle(Graphic3d_StructureManager) V3d_Viewer::StructureManager() const |
405 | { |
406 | return myStructureManager; |
7fd59977 |
407 | } |
408 | |
409 | Aspect_Background V3d_Viewer::GetBackgroundColor() const { |
410 | return MyBackground ; |
411 | } |
412 | |
413 | Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const { |
414 | return MyGradientBackground; |
415 | } |
416 | |
417 | void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) { |
418 | |
419 | MyDefinedViews.Append(TheView); |
420 | IncrCount(); |
421 | } |
422 | |
423 | void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) { |
424 | |
425 | MyActiveViews.Remove(TheView); |
426 | MyDefinedViews.Remove(TheView); |
427 | } |
428 | |
c5751993 |
429 | //======================================================================= |
c357e426 |
430 | //function : AddZLayer |
c5751993 |
431 | //purpose : |
432 | //======================================================================= |
c357e426 |
433 | Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId) |
c5751993 |
434 | { |
c357e426 |
435 | try |
436 | { |
437 | OCC_CATCH_SIGNALS |
438 | theLayerId = myZLayerGenId.Next(); |
439 | } |
440 | catch (Aspect_IdentDefinitionError) |
441 | { |
442 | // new index can't be generated |
443 | return Standard_False; |
444 | } |
445 | |
446 | myLayerIds.Add (theLayerId); |
447 | myDriver->AddZLayer (theLayerId); |
448 | |
449 | return Standard_True; |
c5751993 |
450 | } |
451 | |
452 | //======================================================================= |
c357e426 |
453 | //function : RemoveZLayer |
454 | //purpose : |
c5751993 |
455 | //======================================================================= |
c357e426 |
456 | Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId) |
c5751993 |
457 | { |
c357e426 |
458 | if (!myLayerIds.Contains (theLayerId) |
459 | || theLayerId < myZLayerGenId.Lower() |
460 | || theLayerId > myZLayerGenId.Upper()) |
461 | { |
462 | return Standard_False; |
463 | } |
464 | |
465 | myDriver->RemoveZLayer (theLayerId); |
466 | myLayerIds.Remove (theLayerId); |
467 | myZLayerGenId.Free (theLayerId); |
468 | |
469 | return Standard_True; |
c5751993 |
470 | } |
471 | |
59f45b7c |
472 | //======================================================================= |
c357e426 |
473 | //function : GetAllZLayers |
59f45b7c |
474 | //purpose : |
475 | //======================================================================= |
c357e426 |
476 | void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const |
59f45b7c |
477 | { |
c357e426 |
478 | myDriver->ZLayers (theLayerSeq); |
59f45b7c |
479 | } |
480 | |
481 | //======================================================================= |
c357e426 |
482 | //function : SetZLayerSettings |
483 | //purpose : |
59f45b7c |
484 | //======================================================================= |
c357e426 |
485 | void V3d_Viewer::SetZLayerSettings (const Standard_Integer theLayerId, const Graphic3d_ZLayerSettings& theSettings) |
59f45b7c |
486 | { |
c357e426 |
487 | myDriver->SetZLayerSettings (theLayerId, theSettings); |
59f45b7c |
488 | } |
489 | |
490 | //======================================================================= |
c357e426 |
491 | //function : ZLayerSettings |
59f45b7c |
492 | //purpose : |
493 | //======================================================================= |
c357e426 |
494 | Graphic3d_ZLayerSettings V3d_Viewer::ZLayerSettings (const Standard_Integer theLayerId) |
59f45b7c |
495 | { |
c357e426 |
496 | return myDriver->ZLayerSettings (theLayerId); |
59f45b7c |
497 | } |
6942f04a |
498 | |
499 | //======================================================================= |
500 | //function : Domain |
501 | //purpose : |
502 | //======================================================================= |
6942f04a |
503 | Standard_CString V3d_Viewer::Domain() const |
504 | { |
505 | return myDomain.ToCString(); |
506 | } |
507 | |
508 | //======================================================================= |
509 | //function : Driver |
510 | //purpose : |
511 | //======================================================================= |
6942f04a |
512 | const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const |
513 | { |
514 | return myDriver; |
515 | } |
516 | |
517 | //======================================================================= |
518 | //function : NextName |
519 | //purpose : |
520 | //======================================================================= |
6942f04a |
521 | Standard_ExtString V3d_Viewer::NextName() const |
522 | { |
523 | TCollection_ExtendedString aNextName = TCollection_ExtendedString (myName.ToExtString()); |
524 | aNextName.AssignCat (TCollection_ExtendedString (myNextCount)); |
525 | |
526 | return aNextName.ToExtString(); |
527 | } |
528 | |
529 | //======================================================================= |
530 | //function : IncrCount |
531 | //purpose : |
532 | //======================================================================= |
6942f04a |
533 | void V3d_Viewer::IncrCount() |
534 | { |
535 | myNextCount++; |
973c2be1 |
536 | } |
832ae82d |
537 | |
538 | //======================================================================= |
539 | //function : DefaultRenderingParams |
540 | //purpose : |
541 | //======================================================================= |
542 | const Graphic3d_RenderingParams& V3d_Viewer::DefaultRenderingParams() const |
543 | { |
544 | return myDefaultRenderingParams; |
545 | } |
546 | |
547 | //======================================================================= |
548 | //function : SetDefaultRenderingParams |
549 | //purpose : |
550 | //======================================================================= |
551 | void V3d_Viewer::SetDefaultRenderingParams (const Graphic3d_RenderingParams& theParams) |
552 | { |
553 | myDefaultRenderingParams = theParams; |
554 | } |