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. |
7fd59977 |
14 | |
15 | /*********************************************************************** |
16 | |
17 | FONCTION : |
18 | ---------- |
19 | Classe Visual3d_ViewManager.cxx : |
20 | |
81bba717 |
21 | Declaration of variables specific to visualisers |
7fd59977 |
22 | |
23 | HISTORIQUE DES MODIFICATIONS : |
24 | -------------------------------- |
25 | Mars 1992 : NW,JPB,CAL ; Creation. |
26 | 19-06-96 : FMN ; Suppression variables inutiles |
27 | 04-02-97 : FMN ; Suppression de PSOutput, XWDOutput ... |
28 | 06-05-97 : CAL ; Ajout du Clear sur les TOS_COMPUTED. |
29 | 19-09-97 : CAL ; Remplacement de Window->Position par Window->Size; |
30 | 24-10-97 : CAL ; Retrait de DownCast. |
31 | 20-11-97 : CAL ; Disparition de la dependance avec math |
32 | 01-12-97 : CAL ; Retrait du test IsActive sur l'Update et le Redraw |
bf75be98 |
33 | 31-12-97 : CAL ; Disparition de MathGra |
7fd59977 |
34 | 16-01-98 : CAL ; Ajout du SetTransform sur une TOS_COMPUTED |
35 | 11-03-98 : CAL ; Visual3d_ViewManager::Remove () |
36 | 20-05-98 : CAL ; Perfs. Connection entre structures COMPUTED. |
37 | 10-06-98 : CAL ; Modification des signatures de xxProjectRaster. |
38 | 10-06-98 : CAL ; Modification de la signature de ViewExists. |
39 | 01-12-98 : CAL ; S4062. Ajout des layers. |
40 | 02-12-98 : CAL ; Remove () ne detruit plus les vues. |
41 | |
42 | ************************************************************************/ |
43 | |
44 | /*----------------------------------------------------------------------*/ |
45 | /* |
81bba717 |
46 | * Constants |
7fd59977 |
47 | */ |
48 | |
49 | #define NO_DOWNCAST |
50 | #define NO_DESTROY |
51 | |
52 | /*----------------------------------------------------------------------*/ |
53 | /* |
54 | * Includes |
55 | */ |
7fd59977 |
56 | // for the class |
7fd59977 |
57 | |
59f45b7c |
58 | #include <Aspect_IdentDefinitionError.hxx> |
42cf5bc1 |
59 | #include <Aspect_Window.hxx> |
60 | #include <Graphic3d_DataStructureManager.hxx> |
7fd59977 |
61 | #include <Graphic3d_GraphicDriver.hxx> |
7fd59977 |
62 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> |
42cf5bc1 |
63 | #include <Graphic3d_MapOfStructure.hxx> |
64 | #include <Graphic3d_Structure.hxx> |
65 | #include <Standard_ErrorHandler.hxx> |
66 | #include <Standard_Type.hxx> |
67 | #include <Visual3d_Layer.hxx> |
68 | #include <Visual3d_View.hxx> |
69 | #include <Visual3d_ViewManager.hxx> |
7fd59977 |
70 | |
872f4e44 |
71 | #if defined (_WIN32) || defined(__WIN32__) |
7fd59977 |
72 | # include <WNT_Window.hxx> |
872f4e44 |
73 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
74 | # include <Cocoa_Window.hxx> |
75 | #else |
76 | # include <Xw_Window.hxx> |
ec357c5c |
77 | #include <Visual3d_View.hxx> |
872f4e44 |
78 | #endif |
7fd59977 |
79 | |
d4f1753b |
80 | // views identifiers : possible range |
81 | #define View_IDMIN 1 |
82 | #define View_IDMAX 10000 |
7fd59977 |
83 | |
dc3fe572 |
84 | Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Graphic3d_GraphicDriver)& theDriver): |
85 | Graphic3d_StructureManager (theDriver), |
7fd59977 |
86 | MyDefinedView (), |
a272ed94 |
87 | MyViewGenId (0, 31), |
a1954302 |
88 | MyZBufferAuto (Standard_False), |
89 | myZLayerGenId (1, IntegerLast()) |
7fd59977 |
90 | { |
dc3fe572 |
91 | MyGraphicDriver = theDriver; |
a1954302 |
92 | |
93 | // default layers are always presented in display layer sequence it can not be removed |
af65fb19 |
94 | Graphic3d_ZLayerSettings anUnderlaySettings; |
95 | anUnderlaySettings.Flags = 0; |
96 | anUnderlaySettings.IsImmediate = false; |
97 | myLayerIds.Add (Graphic3d_ZLayerId_BotOSD); |
98 | myLayerSeq.Append (Graphic3d_ZLayerId_BotOSD); |
99 | myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, anUnderlaySettings); |
100 | |
a1954302 |
101 | Graphic3d_ZLayerSettings aDefSettings; |
102 | aDefSettings.Flags = Graphic3d_ZLayerDepthTest |
103 | | Graphic3d_ZLayerDepthWrite; |
104 | aDefSettings.IsImmediate = false; |
105 | myLayerIds.Add (Graphic3d_ZLayerId_Default); |
106 | myLayerSeq.Append (Graphic3d_ZLayerId_Default); |
107 | myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aDefSettings); |
108 | |
109 | Graphic3d_ZLayerSettings aTopSettings; |
110 | aTopSettings.Flags = Graphic3d_ZLayerDepthTest |
111 | | Graphic3d_ZLayerDepthWrite; |
112 | aTopSettings.IsImmediate = true; |
113 | myLayerIds.Add (Graphic3d_ZLayerId_Top); |
114 | myLayerSeq.Append (Graphic3d_ZLayerId_Top); |
115 | myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aTopSettings); |
116 | |
117 | Graphic3d_ZLayerSettings aTopmostSettings; |
118 | aTopmostSettings.Flags = Graphic3d_ZLayerDepthTest |
119 | | Graphic3d_ZLayerDepthWrite |
120 | | Graphic3d_ZLayerDepthClear; |
121 | aTopmostSettings.IsImmediate = true; |
122 | myLayerIds.Add (Graphic3d_ZLayerId_Topmost); |
123 | myLayerSeq.Append (Graphic3d_ZLayerId_Topmost); |
124 | myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aTopmostSettings); |
125 | |
126 | Graphic3d_ZLayerSettings anOsdSettings; |
127 | anOsdSettings.Flags = 0; |
128 | anOsdSettings.IsImmediate = true; |
129 | myLayerIds.Add (Graphic3d_ZLayerId_TopOSD); |
130 | myLayerSeq.Append (Graphic3d_ZLayerId_TopOSD); |
131 | myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, anOsdSettings); |
7fd59977 |
132 | } |
133 | |
134 | //-Destructors |
135 | |
136 | void Visual3d_ViewManager::Destroy () { |
137 | |
7fd59977 |
138 | Remove (); |
139 | } |
140 | |
141 | //-Methods, in order |
142 | |
143 | void Visual3d_ViewManager::Remove () { |
144 | |
7fd59977 |
145 | // |
146 | // Destroy all defined views |
147 | // |
7fd59977 |
148 | |
5e27df78 |
149 | // clear all structures whilst views are alive for correct GPU memory management |
150 | MyDisplayedStructure.Clear(); |
151 | MyHighlightedStructure.Clear(); |
5e27df78 |
152 | |
153 | // clear list of managed views |
154 | MyDefinedView.Clear(); |
7fd59977 |
155 | } |
156 | |
54f7544d |
157 | void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) |
158 | { |
54f7544d |
159 | // |
160 | // Change structure priority in all defined views |
161 | // |
162 | for(int i=1; i<=MyDefinedView.Length(); i++) |
163 | { |
164 | (MyDefinedView.Value(i))->ChangeDisplayPriority(AStructure, OldPriority, NewPriority); |
165 | } |
7fd59977 |
166 | } |
167 | |
bf75be98 |
168 | void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) { |
7fd59977 |
169 | |
170 | //Standard_Integer LengthD = MyDisplayedStructure.Extent() (); |
171 | |
81bba717 |
172 | // Even if physically the structure cannot |
173 | // be displayed (pb of visualisation type) |
174 | // it has status Displayed. |
bf75be98 |
175 | |
7fd59977 |
176 | if (!MyDisplayedStructure.Contains(AStructure)) |
177 | return; |
178 | |
179 | // |
180 | // Recompute structure in all activated views |
181 | // |
54f7544d |
182 | for(int i=1; i<=MyDefinedView.Length(); i++) |
183 | { |
184 | (MyDefinedView.Value(i))->ReCompute(AStructure); |
7fd59977 |
185 | } |
7fd59977 |
186 | } |
187 | |
bf75be98 |
188 | void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure, |
189 | const Handle(Graphic3d_DataStructureManager)& AProjector) |
190 | { |
7fd59977 |
191 | |
192 | if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return; |
193 | |
194 | #ifdef DOWNCAST |
195 | Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector); |
196 | #else |
c5f3a425 |
197 | Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector); |
7fd59977 |
198 | #endif |
199 | Standard_Integer ViewId = theView->Identification (); |
200 | |
81bba717 |
201 | // Even if physically the structure cannot |
202 | // be displayed (pb of visualisation type) |
203 | // it has status Displayed. |
7fd59977 |
204 | if (!MyDisplayedStructure.Contains(AStructure)) |
205 | return; |
bf75be98 |
206 | |
7fd59977 |
207 | // |
81bba717 |
208 | // Recompute structure in all activated views |
7fd59977 |
209 | // |
54f7544d |
210 | for(int i=1; i<=MyDefinedView.Length(); i++) |
211 | { |
212 | if ((MyDefinedView.Value(i))->Identification () == ViewId) |
213 | { |
7fd59977 |
214 | theView->ReCompute (AStructure); |
54f7544d |
215 | } |
7fd59977 |
216 | } |
7fd59977 |
217 | } |
218 | |
54f7544d |
219 | void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) |
220 | { |
221 | for(int i=1; i<=MyDefinedView.Length(); i++) |
222 | { |
223 | (MyDefinedView.Value(i))->Clear(AStructure, WithDestruction); |
224 | } |
7fd59977 |
225 | } |
226 | |
54f7544d |
227 | void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) |
228 | { |
229 | for(int i=1; i<=MyDefinedView.Length(); i++) |
230 | { |
231 | (MyDefinedView.Value(i))->Connect (AMother, ADaughter); |
232 | } |
7fd59977 |
233 | } |
234 | |
54f7544d |
235 | void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) |
236 | { |
237 | for(int i=1; i<=MyDefinedView.Length(); i++) |
238 | { |
239 | (MyDefinedView.Value(i))->Disconnect (AMother, ADaughter); |
240 | } |
7fd59977 |
241 | } |
242 | |
54f7544d |
243 | void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) |
244 | { |
245 | // Even if physically the structure cannot |
81bba717 |
246 | // be displayed (pb of visualisation type) |
247 | // it has status Displayed. |
7fd59977 |
248 | |
249 | MyDisplayedStructure.Add(AStructure); |
54f7544d |
250 | |
251 | for(int i=1; i<=MyDefinedView.Length(); i++) |
252 | { |
253 | (MyDefinedView.Value(i))->Display(AStructure); |
254 | } |
7fd59977 |
255 | } |
256 | |
54f7544d |
257 | void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) |
258 | { |
259 | // Even if physically the structure cannot |
81bba717 |
260 | // be displayed (pb of visualisation type) |
261 | // it has status Displayed. |
7fd59977 |
262 | |
54f7544d |
263 | MyDisplayedStructure.Remove(AStructure); |
bf75be98 |
264 | |
54f7544d |
265 | // |
266 | // Erase structure in all defined views |
267 | // |
268 | for(int i=1; i<=MyDefinedView.Length(); i++) |
269 | { |
270 | (MyDefinedView.Value(i))->Erase (AStructure); |
271 | } |
7fd59977 |
272 | |
54f7544d |
273 | MyHighlightedStructure.Remove (AStructure); |
7fd59977 |
274 | } |
275 | |
276 | void Visual3d_ViewManager::Erase () { |
277 | |
278 | Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure); |
bf75be98 |
279 | |
7fd59977 |
280 | for (; it.More(); it.Next()) { |
281 | Handle(Graphic3d_Structure) SG = it.Key(); |
282 | SG->Erase(); |
283 | } |
284 | |
285 | } |
286 | |
54f7544d |
287 | void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) |
288 | { |
7fd59977 |
289 | MyHighlightedStructure.Add(AStructure); |
54f7544d |
290 | |
291 | // |
292 | // Highlight in all activated views |
293 | // |
294 | |
295 | for(int i=1; i<=MyDefinedView.Length(); i++) |
296 | { |
297 | (MyDefinedView.Value(i))->Highlight (AStructure, AMethod); |
298 | } |
7fd59977 |
299 | } |
300 | |
54f7544d |
301 | void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) |
302 | { |
303 | for(int i=1; i<=MyDefinedView.Length(); i++) |
304 | { |
305 | (MyDefinedView.Value(i))->SetTransform (AStructure, ATrsf); |
306 | } |
7fd59977 |
307 | } |
308 | |
309 | void Visual3d_ViewManager::UnHighlight () { |
310 | |
311 | Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure); |
bf75be98 |
312 | |
7fd59977 |
313 | for (; it.More(); it.Next()) { |
314 | Handle(Graphic3d_Structure) SG = it.Key(); |
315 | SG->UnHighlight (); |
316 | } |
317 | |
318 | |
319 | } |
320 | |
54f7544d |
321 | void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) |
322 | { |
7fd59977 |
323 | MyHighlightedStructure.Remove(AStructure); |
324 | |
54f7544d |
325 | // |
326 | // UnHighlight in all activated views |
327 | // |
7fd59977 |
328 | |
54f7544d |
329 | for(int i=1; i<=MyDefinedView.Length(); i++) |
330 | { |
331 | (MyDefinedView.Value(i))->UnHighlight (AStructure); |
332 | } |
7fd59977 |
333 | } |
334 | |
679ecdee |
335 | void Visual3d_ViewManager::Redraw() const |
336 | { |
337 | // redraw all activated views |
54f7544d |
338 | if (MyDefinedView.Length() == 0) |
679ecdee |
339 | { |
340 | return; |
341 | } |
bf75be98 |
342 | |
679ecdee |
343 | if (!MyUnderLayer.IsNull() || !MyOverLayer.IsNull()) |
344 | { |
345 | Standard_Integer aWidth = 0, aHeight = 0; |
346 | Standard_Integer aWidthMax = 0; |
347 | Standard_Integer aHeightMax = 0; |
54f7544d |
348 | |
349 | for(int i=1; i<=MyDefinedView.Length(); i++) |
679ecdee |
350 | { |
54f7544d |
351 | MyDefinedView.Value(i)->Window()->Size (aWidth, aHeight); |
679ecdee |
352 | aWidthMax = Max (aWidthMax, aWidth); |
c1c1aefa |
353 | aHeightMax = Max (aHeightMax, aHeight); |
679ecdee |
354 | } |
54f7544d |
355 | |
679ecdee |
356 | if (!MyUnderLayer.IsNull()) |
357 | { |
358 | MyUnderLayer->SetViewport (aWidthMax, aHeightMax); |
359 | } |
360 | if (!MyOverLayer.IsNull()) |
361 | { |
362 | MyOverLayer->SetViewport (aWidthMax, aHeightMax); |
363 | } |
364 | } |
7fd59977 |
365 | |
54f7544d |
366 | for(int i=1; i<=MyDefinedView.Length(); i++) |
679ecdee |
367 | { |
54f7544d |
368 | MyDefinedView.Value(i)->Redraw (MyUnderLayer, MyOverLayer); |
369 | } |
7fd59977 |
370 | } |
371 | |
679ecdee |
372 | void Visual3d_ViewManager::Update() const |
373 | { |
374 | Redraw(); |
375 | } |
7fd59977 |
376 | |
679ecdee |
377 | void Visual3d_ViewManager::RedrawImmediate() const |
378 | { |
54f7544d |
379 | if (MyDefinedView.Length() == 0) |
679ecdee |
380 | { |
381 | return; |
382 | } |
bf75be98 |
383 | |
679ecdee |
384 | // update all activated views |
54f7544d |
385 | for(int i=1; i<=MyDefinedView.Length(); i++) |
679ecdee |
386 | { |
54f7544d |
387 | MyDefinedView.Value(i)->RedrawImmediate (MyUnderLayer, MyOverLayer); |
679ecdee |
388 | } |
389 | } |
7fd59977 |
390 | |
679ecdee |
391 | void Visual3d_ViewManager::Invalidate() const |
392 | { |
54f7544d |
393 | if (MyDefinedView.Length() == 0) |
679ecdee |
394 | { |
395 | return; |
396 | } |
7fd59977 |
397 | |
679ecdee |
398 | // update all activated views |
54f7544d |
399 | for(int i=1; i<=MyDefinedView.Length(); i++) |
679ecdee |
400 | { |
54f7544d |
401 | MyDefinedView.Value(i)->Invalidate(); |
679ecdee |
402 | } |
7fd59977 |
403 | } |
404 | |
54f7544d |
405 | Handle(Visual3d_HSequenceOfView) Visual3d_ViewManager::ActivatedView () const |
406 | { |
7fd59977 |
407 | |
54f7544d |
408 | Handle(Visual3d_HSequenceOfView) SG = new Visual3d_HSequenceOfView(); |
7fd59977 |
409 | |
54f7544d |
410 | for(int i=1; i<=MyDefinedView.Length(); i++) |
411 | { |
412 | if ((MyDefinedView.Value(i))->IsActive ()) |
413 | { |
414 | SG->Append(MyDefinedView.Value(i)); |
415 | } |
416 | } |
7fd59977 |
417 | |
54f7544d |
418 | return (SG); |
7fd59977 |
419 | } |
420 | |
421 | #ifdef IMPLEMENTED |
54f7544d |
422 | Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const |
423 | { |
424 | Standard_Boolean Result = Standard_False; |
7fd59977 |
425 | |
54f7544d |
426 | // |
427 | // Check all activated views |
428 | // |
429 | for(int i=1; (!Result) && i<=MyDefinedView.Length(); i++) |
430 | { |
431 | if ((MyDefinedView.Value(i))->IsActive()) |
432 | { |
433 | Result = (MyDefinedView.Value(i))->ContainsComputedStructure(); |
434 | } |
435 | } |
7fd59977 |
436 | |
54f7544d |
437 | return Result; |
7fd59977 |
438 | } |
439 | #endif |
440 | |
a1954302 |
441 | const Visual3d_SequenceOfView& Visual3d_ViewManager::DefinedViews() const |
54f7544d |
442 | { |
a1954302 |
443 | return MyDefinedView; |
7fd59977 |
444 | } |
445 | |
54f7544d |
446 | Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const |
447 | { |
448 | Standard_Boolean Exist = Standard_False; |
7fd59977 |
449 | |
54f7544d |
450 | // Parse the list of views to find |
451 | // a view with the specified window |
7fd59977 |
452 | |
eaf5c5e0 |
453 | #if defined(_WIN32) |
872f4e44 |
454 | const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow); |
566f8441 |
455 | Aspect_Handle TheSpecifiedWindowId = THEWindow->HWindow (); |
872f4e44 |
456 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
457 | const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow); |
a2e4f780 |
458 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
459 | UIView* TheSpecifiedWindowId = THEWindow->HView(); |
460 | #else |
461 | NSView* TheSpecifiedWindowId = THEWindow->HView(); |
462 | #endif |
eaf5c5e0 |
463 | #elif defined(__ANDROID__) |
464 | int TheSpecifiedWindowId = -1; |
7fd59977 |
465 | #else |
872f4e44 |
466 | const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow); |
467 | int TheSpecifiedWindowId = int (THEWindow->XWindow ()); |
468 | #endif |
7fd59977 |
469 | |
54f7544d |
470 | for(int i=1; (!Exist) && i<=MyDefinedView.Length(); i++) |
471 | { |
472 | if ( ((MyDefinedView.Value(i))->IsDefined ()) && ((MyDefinedView.Value(i))->IsActive ()) ) |
473 | { |
474 | const Handle(Aspect_Window) AspectWindow = (MyDefinedView.Value(i))->Window(); |
7fd59977 |
475 | |
eaf5c5e0 |
476 | #if defined(_WIN32) |
54f7544d |
477 | const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow); |
478 | Aspect_Handle TheWindowIdOfView = theWindow->HWindow (); |
872f4e44 |
479 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
54f7544d |
480 | const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow); |
a2e4f780 |
481 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
482 | UIView* TheWindowIdOfView = theWindow->HView(); |
483 | #else |
484 | NSView* TheWindowIdOfView = theWindow->HView(); |
485 | #endif |
eaf5c5e0 |
486 | #elif defined(__ANDROID__) |
487 | int TheWindowIdOfView = 0; |
7fd59977 |
488 | #else |
54f7544d |
489 | const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow); |
490 | int TheWindowIdOfView = int (theWindow->XWindow ()); |
7fd59977 |
491 | #endif // WNT |
54f7544d |
492 | // Comparaison on window IDs |
493 | if (TheWindowIdOfView == TheSpecifiedWindowId) |
494 | { |
495 | Exist = Standard_True; |
496 | TheCView = *(Graphic3d_CView* )(MyDefinedView.Value(i))->CView(); |
497 | } |
498 | } |
499 | } |
7fd59977 |
500 | |
54f7544d |
501 | return (Exist); |
7fd59977 |
502 | } |
503 | |
54f7544d |
504 | void Visual3d_ViewManager::Activate () |
505 | { |
506 | // |
507 | // Activates all deactivated views |
508 | // |
509 | for(int i=1; i<=MyDefinedView.Length(); i++) |
510 | { |
511 | if (! (MyDefinedView.Value(i))->IsActive()) |
512 | { |
513 | (MyDefinedView.Value(i))->Activate(); |
514 | } |
515 | } |
7fd59977 |
516 | } |
517 | |
54f7544d |
518 | void Visual3d_ViewManager::Deactivate () |
519 | { |
520 | // |
521 | // Deactivates all activated views |
522 | // |
523 | for(int i=1; i<=MyDefinedView.Length(); i++) |
524 | { |
525 | if ((MyDefinedView.Value(i))->IsActive()) |
526 | { |
527 | (MyDefinedView.Value(i))->Deactivate(); |
528 | } |
529 | } |
7fd59977 |
530 | |
531 | } |
532 | |
533 | Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const { |
534 | |
81bba717 |
535 | // Retourne the planned of definable views for the current |
536 | // Visual3d_ViewManager. |
7fd59977 |
537 | return |
538 | (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ())); |
539 | |
540 | } |
541 | |
542 | Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const { |
543 | |
544 | return (Graphic3d_StructureManager::Identification (AId)); |
545 | |
546 | } |
547 | |
548 | Standard_Integer Visual3d_ViewManager::Identification () const { |
bf75be98 |
549 | |
7fd59977 |
550 | return (Graphic3d_StructureManager::Identification ()); |
551 | |
552 | } |
553 | |
54f7544d |
554 | Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) |
555 | { |
556 | MyDefinedView.Append(AView); |
557 | return (MyViewGenId.Next ()); |
7fd59977 |
558 | } |
559 | |
560 | void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId) |
561 | { |
54f7544d |
562 | for(int i=1; i<=MyDefinedView.Length(); i++) |
30bf45dc |
563 | { |
54f7544d |
564 | if ((MyDefinedView.Value(i))->Identification() == aViewId) |
30bf45dc |
565 | { |
30bf45dc |
566 | //remove the view from the list |
54f7544d |
567 | MyDefinedView.Remove(i); |
30bf45dc |
568 | break; |
569 | } |
30bf45dc |
570 | } |
54f7544d |
571 | |
7fd59977 |
572 | MyViewGenId.Free(aViewId); |
573 | } |
574 | |
54f7544d |
575 | void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) |
576 | { |
54f7544d |
577 | MyZBufferAuto = AFlag; |
7fd59977 |
578 | } |
579 | |
54f7544d |
580 | Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const |
581 | { |
582 | return (MyZBufferAuto); |
7fd59977 |
583 | } |
584 | |
585 | void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) { |
7fd59977 |
586 | if (ALayer->Type () == Aspect_TOL_OVERLAY) { |
7fd59977 |
587 | MyOverLayer = ALayer; |
588 | } |
589 | else { |
7fd59977 |
590 | MyUnderLayer = ALayer; |
591 | } |
592 | |
593 | } |
594 | |
595 | const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const { |
596 | |
597 | return (MyUnderLayer); |
598 | |
599 | } |
600 | |
601 | const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const { |
602 | |
603 | return (MyOverLayer); |
604 | |
605 | } |
59f45b7c |
606 | |
607 | //======================================================================= |
608 | //function : ChangeZLayer |
bf75be98 |
609 | //purpose : |
59f45b7c |
610 | //======================================================================= |
611 | |
612 | void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, |
a1954302 |
613 | const Graphic3d_ZLayerId theLayerId) |
59f45b7c |
614 | { |
a1954302 |
615 | if (!myLayerIds.Contains (theLayerId) |
616 | || !MyDisplayedStructure.Contains (theStructure)) |
617 | { |
59f45b7c |
618 | return; |
a1954302 |
619 | } |
bf75be98 |
620 | |
59f45b7c |
621 | // change display layer for structure in all views |
a1954302 |
622 | for (int aViewIter = 1; aViewIter <= MyDefinedView.Length(); ++aViewIter) |
59f45b7c |
623 | { |
a1954302 |
624 | MyDefinedView.Value (aViewIter)->ChangeZLayer (theStructure, theLayerId); |
59f45b7c |
625 | } |
59f45b7c |
626 | } |
627 | |
c5751993 |
628 | //======================================================================= |
629 | //function : SetZLayerSettings |
630 | //purpose : |
631 | //======================================================================= |
a1954302 |
632 | void Visual3d_ViewManager::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, |
c5751993 |
633 | const Graphic3d_ZLayerSettings& theSettings) |
634 | { |
635 | // tell all managed views to set zlayer settings |
54f7544d |
636 | for(int i=1; i<=MyDefinedView.Length(); i++) |
c5751993 |
637 | { |
54f7544d |
638 | (MyDefinedView.Value(i))->SetZLayerSettings (theLayerId, theSettings); |
c5751993 |
639 | } |
640 | |
641 | if (myMapOfZLayerSettings.IsBound (theLayerId)) |
642 | { |
643 | myMapOfZLayerSettings.ChangeFind (theLayerId) = theSettings; |
644 | } |
645 | else |
646 | { |
647 | myMapOfZLayerSettings.Bind (theLayerId, theSettings); |
648 | } |
649 | |
650 | } |
651 | |
652 | //======================================================================= |
653 | //function : ZLayerSettings |
654 | //purpose : |
655 | //======================================================================= |
a1954302 |
656 | Graphic3d_ZLayerSettings Visual3d_ViewManager::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) |
c5751993 |
657 | { |
658 | if (!myLayerIds.Contains (theLayerId)) |
659 | { |
660 | return Graphic3d_ZLayerSettings(); |
661 | } |
662 | |
663 | return myMapOfZLayerSettings.Find (theLayerId); |
664 | } |
665 | |
59f45b7c |
666 | //======================================================================= |
667 | //function : AddZLayer |
668 | //purpose : |
669 | //======================================================================= |
670 | |
a1954302 |
671 | Standard_Boolean Visual3d_ViewManager::AddZLayer (Graphic3d_ZLayerId& theLayerId) |
59f45b7c |
672 | { |
673 | try |
674 | { |
675 | OCC_CATCH_SIGNALS |
a1954302 |
676 | theLayerId = myZLayerGenId.Next(); |
677 | myLayerIds.Add (theLayerId); |
59f45b7c |
678 | myLayerSeq.Append (theLayerId); |
679 | } |
680 | catch (Aspect_IdentDefinitionError) |
681 | { |
682 | // new index can't be generated |
683 | return Standard_False; |
684 | } |
685 | |
c5751993 |
686 | // default z-layer settings |
687 | myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings()); |
688 | |
59f45b7c |
689 | // tell all managed views to remove display layers |
54f7544d |
690 | for(int i=1; i<=MyDefinedView.Length(); i++) |
691 | { |
692 | (MyDefinedView.Value(i))->AddZLayer(theLayerId); |
693 | } |
59f45b7c |
694 | |
695 | return Standard_True; |
696 | } |
697 | |
698 | //======================================================================= |
699 | //function : RemoveZLayer |
bf75be98 |
700 | //purpose : |
59f45b7c |
701 | //======================================================================= |
702 | |
a1954302 |
703 | Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Graphic3d_ZLayerId theLayerId) |
59f45b7c |
704 | { |
a1954302 |
705 | if (!myLayerIds.Contains (theLayerId) |
706 | || theLayerId < myZLayerGenId.Lower() |
707 | || theLayerId > myZLayerGenId.Upper()) |
708 | { |
59f45b7c |
709 | return Standard_False; |
a1954302 |
710 | } |
59f45b7c |
711 | |
712 | // tell all managed views to remove display layers |
54f7544d |
713 | for(int i=1; i<=MyDefinedView.Length(); i++) |
714 | { |
715 | (MyDefinedView.Value(i))->RemoveZLayer (theLayerId); |
716 | } |
59f45b7c |
717 | |
718 | MyGraphicDriver->UnsetZLayer (theLayerId); |
719 | |
720 | // remove index |
721 | for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++) |
c5751993 |
722 | { |
723 | if (myLayerSeq (aIdx) == theLayerId) |
59f45b7c |
724 | { |
725 | myLayerSeq.Remove (aIdx); |
726 | break; |
727 | } |
c5751993 |
728 | } |
729 | |
730 | myMapOfZLayerSettings.UnBind (theLayerId); |
59f45b7c |
731 | |
a1954302 |
732 | myLayerIds.Remove (theLayerId); |
733 | myZLayerGenId.Free (theLayerId); |
59f45b7c |
734 | |
735 | return Standard_True; |
736 | } |
737 | |
738 | //======================================================================= |
739 | //function : GetAllZLayers |
740 | //purpose : |
741 | //======================================================================= |
742 | |
743 | void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const |
744 | { |
745 | theLayerSeq.Assign (myLayerSeq); |
746 | } |
747 | |
71c4f9c6 |
748 | //======================================================================= |
749 | //function : InstallZLayers |
750 | //purpose : |
751 | //======================================================================= |
752 | |
753 | void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const |
754 | { |
54f7544d |
755 | Standard_Boolean isContainsView = Standard_False; |
756 | for(int i=1; i<=MyDefinedView.Length(); i++) |
757 | { |
758 | if(MyDefinedView.Value(i) == theView) |
759 | { |
760 | isContainsView = Standard_True; |
761 | break; |
762 | } |
763 | } |
764 | if (!isContainsView) |
71c4f9c6 |
765 | return; |
bf75be98 |
766 | |
71c4f9c6 |
767 | // erase and insert layers iteratively to provide the same layer order as |
768 | // in the view manager's sequence. This approach bases on the layer insertion |
769 | // order: the new layers are always appended to the end of the list |
770 | // inside of view, while layer remove operation doesn't affect the order. |
771 | // Starting from second layer : no need to change the default z layer. |
a1954302 |
772 | for (Standard_Integer aSeqIdx = 1; aSeqIdx <= myLayerSeq.Length(); ++aSeqIdx) |
71c4f9c6 |
773 | { |
a1954302 |
774 | const Graphic3d_ZLayerId aLayerID = myLayerSeq.Value (aSeqIdx); |
775 | const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID); |
776 | if (aLayerID < myZLayerGenId.Lower() |
777 | || aLayerID > myZLayerGenId.Upper()) |
778 | { |
779 | theView->SetZLayerSettings (aLayerID, aSettings); |
780 | continue; |
781 | } |
782 | |
783 | theView->RemoveZLayer (aLayerID); |
784 | theView->AddZLayer (aLayerID); |
785 | theView->SetZLayerSettings (aLayerID, aSettings); |
71c4f9c6 |
786 | } |
787 | } |