7fd59977 |
1 | |
2 | /*********************************************************************** |
3 | |
4 | FONCTION : |
5 | ---------- |
6 | Classe Visual3d_ViewManager.cxx : |
7 | |
8 | Declaration des variables specifiques aux visualiseurs |
9 | |
10 | HISTORIQUE DES MODIFICATIONS : |
11 | -------------------------------- |
12 | Mars 1992 : NW,JPB,CAL ; Creation. |
13 | 19-06-96 : FMN ; Suppression variables inutiles |
14 | 04-02-97 : FMN ; Suppression de PSOutput, XWDOutput ... |
15 | 06-05-97 : CAL ; Ajout du Clear sur les TOS_COMPUTED. |
16 | 19-09-97 : CAL ; Remplacement de Window->Position par Window->Size; |
17 | 24-10-97 : CAL ; Retrait de DownCast. |
18 | 20-11-97 : CAL ; Disparition de la dependance avec math |
19 | 01-12-97 : CAL ; Retrait du test IsActive sur l'Update et le Redraw |
20 | 31-12-97 : CAL ; Disparition de MathGra |
21 | 16-01-98 : CAL ; Ajout du SetTransform sur une TOS_COMPUTED |
22 | 11-03-98 : CAL ; Visual3d_ViewManager::Remove () |
23 | 20-05-98 : CAL ; Perfs. Connection entre structures COMPUTED. |
24 | 10-06-98 : CAL ; Modification des signatures de xxProjectRaster. |
25 | 10-06-98 : CAL ; Modification de la signature de ViewExists. |
26 | 01-12-98 : CAL ; S4062. Ajout des layers. |
27 | 02-12-98 : CAL ; Remove () ne detruit plus les vues. |
28 | |
29 | ************************************************************************/ |
30 | |
31 | /*----------------------------------------------------------------------*/ |
32 | /* |
33 | * Constantes |
34 | */ |
35 | |
36 | #define NO_DOWNCAST |
37 | #define NO_DESTROY |
38 | |
39 | /*----------------------------------------------------------------------*/ |
40 | /* |
41 | * Includes |
42 | */ |
43 | |
44 | // for the class |
45 | #include <Visual3d_ViewManager.ixx> |
46 | #include <Visual3d_ViewManager.pxx> |
47 | |
48 | #include <Standard_ErrorHandler.hxx> |
49 | |
50 | #include <Aspect.hxx> |
51 | |
52 | #include <Graphic3d_GraphicDriver.hxx> |
53 | #include <Graphic3d_MapOfStructure.hxx> |
54 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> |
55 | |
56 | #include <Visual3d_PickPath.hxx> |
57 | #include <Visual3d_SetIteratorOfSetOfView.hxx> |
58 | |
59 | #ifndef WNT |
60 | # include <Xw_Window.hxx> |
61 | #else |
62 | # include <WNT_Window.hxx> |
63 | #endif // WNT |
64 | |
65 | //-Aliases |
66 | |
67 | //-Global data definitions |
68 | |
69 | // -- les vues definies |
70 | // MyDefinedView : SetOfView; |
71 | |
72 | // -- le generateur d'identificateurs de vues |
73 | // MyViewGenId : GenId; |
74 | |
75 | //-Constructors |
76 | |
77 | Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Aspect_GraphicDevice)& aDevice): |
78 | Graphic3d_StructureManager (aDevice), |
79 | MyDefinedView (), |
80 | MyViewGenId (View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit ()))*(Visual3d_ViewManager::CurrentId ()-1),View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit ()))*Visual3d_ViewManager::CurrentId ()-1), |
81 | MyZBufferAuto (Standard_False), |
82 | MyTransparency (Standard_False) |
83 | { |
84 | |
85 | Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver (); |
86 | |
87 | MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd; |
88 | |
89 | } |
90 | |
91 | //-Destructors |
92 | |
93 | void Visual3d_ViewManager::Destroy () { |
94 | |
95 | #ifdef DESTROY |
96 | cout << "Visual3d_ViewManager::Destroy (" << MyId << ")\n" << flush; |
97 | #endif |
98 | |
99 | Remove (); |
100 | } |
101 | |
102 | //-Methods, in order |
103 | |
104 | void Visual3d_ViewManager::Remove () { |
105 | |
106 | #ifdef DESTROY |
107 | cout << "Visual3d_ViewManager::Remove (" << MyId << ")\n" << flush; |
108 | #endif |
109 | |
110 | // |
111 | // Destroy all defined views |
112 | // |
113 | #ifdef DEB |
114 | Standard_Integer Length = MyDefinedView.Extent (); |
115 | #else |
116 | MyDefinedView.Extent (); |
117 | #endif |
118 | |
119 | #ifdef DESTROY |
120 | cout << "The Manager " << MyId << " have " << Length << " defined views\n"; |
121 | cout << flush; |
122 | #endif |
123 | |
124 | MyDefinedView.Clear (); |
125 | |
126 | } |
127 | |
128 | void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) { |
129 | |
130 | #ifdef TRACE |
131 | cout << "Visual3d_ViewManager::ChangeDisplayPriority (" |
132 | << AStructure->Identification () |
133 | << ", " << OldPriority << ", " << NewPriority << ")\n"; |
134 | cout << flush; |
135 | #endif |
136 | |
137 | // |
138 | // Change structure priority in all defined views |
139 | // |
140 | #ifdef DEB |
141 | Standard_Integer Length = MyDefinedView.Extent (); |
142 | #else |
143 | MyDefinedView.Extent (); |
144 | #endif |
145 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
146 | |
147 | while (MyIterator.More ()) { |
148 | (MyIterator.Value ())->ChangeDisplayPriority |
149 | (AStructure, OldPriority, NewPriority); |
150 | |
151 | // MyIterator.Next () se positionne sur la prochaine vue |
152 | MyIterator.Next (); |
153 | } |
154 | |
155 | } |
156 | |
157 | void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) { |
158 | |
159 | //Standard_Integer LengthD = MyDisplayedStructure.Extent() (); |
160 | |
161 | // Meme si physiquement la structure ne peut pas |
162 | // etre affichee (pb de type de visualisation) |
163 | // elle a le statut Displayed. |
164 | |
165 | if (!MyDisplayedStructure.Contains(AStructure)) |
166 | return; |
167 | |
168 | // |
169 | // Recompute structure in all activated views |
170 | // |
171 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
172 | |
173 | while (MyIterator.More ()) { |
174 | (MyIterator.Value ())->ReCompute (AStructure); |
175 | |
176 | // MyIterator.Next () se positionne sur la prochaine vue |
177 | MyIterator.Next (); |
178 | } |
179 | |
180 | } |
181 | |
182 | void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure, |
183 | const Handle(Graphic3d_DataStructureManager)& AProjector) |
184 | { |
185 | |
186 | if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return; |
187 | |
188 | #ifdef DOWNCAST |
189 | Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector); |
190 | #else |
191 | Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector; |
192 | #endif |
193 | Standard_Integer ViewId = theView->Identification (); |
194 | |
195 | Standard_Integer indexD = 0; |
196 | |
197 | // Meme si physiquement la structure ne peut pas |
198 | // etre affichee (pb de type de visualisation) |
199 | // elle a le statut Displayed. |
200 | if (!MyDisplayedStructure.Contains(AStructure)) |
201 | return; |
202 | |
203 | // |
204 | // Recompute structure in one activated view |
205 | // |
206 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
207 | |
208 | while (MyIterator.More ()) { |
209 | if ((MyIterator.Value ())->Identification () == ViewId) |
210 | theView->ReCompute (AStructure); |
211 | |
212 | // MyIterator.Next () se positionne sur la prochaine vue |
213 | MyIterator.Next (); |
214 | } |
215 | |
216 | } |
217 | |
218 | void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) { |
219 | |
220 | #ifdef DEB |
221 | Standard_Integer Length = MyDefinedView.Extent (); |
222 | #else |
223 | MyDefinedView.Extent (); |
224 | #endif |
225 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
226 | |
227 | while (MyIterator.More ()) { |
228 | (MyIterator.Value ())->Clear (AStructure, WithDestruction); |
229 | |
230 | // MyIterator.Next () se positionne sur la prochaine vue |
231 | MyIterator.Next (); |
232 | } |
233 | |
234 | } |
235 | |
236 | void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) { |
237 | |
238 | #ifdef DEB |
239 | Standard_Integer Length = MyDefinedView.Extent (); |
240 | #else |
241 | MyDefinedView.Extent (); |
242 | #endif |
243 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
244 | |
245 | while (MyIterator.More ()) { |
246 | (MyIterator.Value ())->Connect (AMother, ADaughter); |
247 | |
248 | // MyIterator.Next () se positionne sur la prochaine vue |
249 | MyIterator.Next (); |
250 | } |
251 | |
252 | } |
253 | |
254 | void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) { |
255 | |
256 | #ifdef DEB |
257 | Standard_Integer Length = MyDefinedView.Extent (); |
258 | #else |
259 | MyDefinedView.Extent (); |
260 | #endif |
261 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
262 | |
263 | while (MyIterator.More ()) { |
264 | (MyIterator.Value ())->Disconnect (AMother, ADaughter); |
265 | |
266 | // MyIterator.Next () se positionne sur la prochaine vue |
267 | MyIterator.Next (); |
268 | } |
269 | |
270 | } |
271 | |
272 | void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) { |
273 | |
274 | |
275 | // Meme si physiquement la structure ne peut pas |
276 | // etre affichee (pb de type de visualisation) |
277 | // elle a le statut Displayed. |
278 | |
279 | MyDisplayedStructure.Add(AStructure); |
280 | |
281 | // |
282 | // Display structure in all activated views |
283 | // |
284 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
285 | |
286 | while (MyIterator.More ()) { |
287 | (MyIterator.Value ())->Display (AStructure); |
288 | |
289 | // MyIterator.Next () se positionne sur la prochaine vue |
290 | MyIterator.Next (); |
291 | } |
292 | |
293 | } |
294 | |
295 | void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) { |
296 | |
297 | |
298 | // Meme si physiquement la structure ne pouvait pas |
299 | // etre affichee (pb de type de visualisation) |
300 | // elle avait le statut Displayed. |
301 | |
302 | MyDisplayedStructure.Remove(AStructure); |
303 | |
304 | |
305 | |
306 | // |
307 | // Erase structure in all defined views |
308 | // |
309 | #ifdef DEB |
310 | Standard_Integer Length = MyDefinedView.Extent (); |
311 | #else |
312 | MyDefinedView.Extent (); |
313 | #endif |
314 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
315 | |
316 | while (MyIterator.More ()) { |
317 | (MyIterator.Value ())->Erase (AStructure); |
318 | |
319 | // MyIterator.Next () se positionne sur la prochaine vue |
320 | MyIterator.Next (); |
321 | } |
322 | |
323 | MyHighlightedStructure.Remove (AStructure); |
324 | MyVisibleStructure.Remove (AStructure); |
325 | MyPickStructure.Remove (AStructure); |
326 | |
327 | } |
328 | |
329 | void Visual3d_ViewManager::Erase () { |
330 | |
331 | Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure); |
332 | |
333 | for (; it.More(); it.Next()) { |
334 | Handle(Graphic3d_Structure) SG = it.Key(); |
335 | SG->Erase(); |
336 | } |
337 | |
338 | } |
339 | |
340 | void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) { |
341 | |
342 | MyHighlightedStructure.Add(AStructure); |
343 | |
344 | // |
345 | // Highlight in all activated views |
346 | // |
347 | #ifdef DEB |
348 | Standard_Integer Length = MyDefinedView.Extent (); |
349 | #else |
350 | MyDefinedView.Extent (); |
351 | #endif |
352 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
353 | |
354 | while (MyIterator.More ()) { |
355 | (MyIterator.Value ())->Highlight (AStructure, AMethod); |
356 | |
357 | // MyIterator.Next () se positionne sur la prochaine vue |
358 | MyIterator.Next (); |
359 | } |
360 | |
361 | } |
362 | |
363 | void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) { |
364 | |
365 | #ifdef DEB |
366 | Standard_Integer Length = MyDefinedView.Extent (); |
367 | #else |
368 | MyDefinedView.Extent (); |
369 | #endif |
370 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
371 | |
372 | while (MyIterator.More ()) { |
373 | (MyIterator.Value ())->SetTransform (AStructure, ATrsf); |
374 | |
375 | // MyIterator.Next () se positionne sur la prochaine vue |
376 | MyIterator.Next (); |
377 | } |
378 | |
379 | } |
380 | |
381 | void Visual3d_ViewManager::UnHighlight () { |
382 | |
383 | Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure); |
384 | |
385 | for (; it.More(); it.Next()) { |
386 | Handle(Graphic3d_Structure) SG = it.Key(); |
387 | SG->UnHighlight (); |
388 | } |
389 | |
390 | |
391 | } |
392 | |
393 | void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) { |
394 | |
395 | MyHighlightedStructure.Remove(AStructure); |
396 | |
397 | |
398 | // |
399 | // UnHighlight in all activated views |
400 | // |
401 | #ifdef DEB |
402 | Standard_Integer Length = MyDefinedView.Extent (); |
403 | #else |
404 | MyDefinedView.Extent (); |
405 | #endif |
406 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
407 | |
408 | while (MyIterator.More ()) { |
409 | (MyIterator.Value ())->UnHighlight (AStructure); |
410 | |
411 | // MyIterator.Next () se positionne sur la prochaine vue |
412 | MyIterator.Next (); |
413 | } |
414 | |
415 | } |
416 | |
417 | void Visual3d_ViewManager::Redraw () const { |
418 | |
419 | Standard_Integer MaxDx, MaxDy; |
420 | Standard_Integer Dx, Dy; |
421 | MaxDx = MaxDy = IntegerFirst (); |
422 | |
423 | // |
424 | // Redraw all activated views |
425 | // |
426 | Standard_Integer j = MyDefinedView.Extent (); |
427 | if (j == 0) return; |
428 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
429 | |
430 | if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) { |
431 | while (MyIterator.More ()) { |
432 | (MyIterator.Value ())->Window ()->Size (Dx, Dy); |
433 | if (Dx > MaxDx) MaxDx = Dx; |
434 | if (Dy > MaxDy) MaxDy = Dy; |
435 | |
436 | // MyIterator.Next () se positionne sur la prochaine vue |
437 | MyIterator.Next (); |
438 | } |
439 | if (! MyUnderLayer.IsNull ()) |
440 | MyUnderLayer->SetViewport (MaxDx, MaxDy); |
441 | if (! MyOverLayer.IsNull ()) |
442 | MyOverLayer->SetViewport (MaxDx, MaxDy); |
443 | } |
444 | |
445 | if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) |
446 | MyIterator.Initialize (MyDefinedView); |
447 | while (MyIterator.More ()) { |
448 | (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer); |
449 | |
450 | // MyIterator.Next () se positionne sur la prochaine vue |
451 | MyIterator.Next (); |
452 | } |
453 | |
454 | } |
455 | |
456 | void Visual3d_ViewManager::Update () const { |
457 | |
458 | // |
459 | // Update all activated views |
460 | // |
461 | Standard_Integer j = MyDefinedView.Extent (); |
462 | if (j == 0) return; |
463 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
464 | |
465 | while (MyIterator.More ()) { |
466 | (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer); |
467 | |
468 | // MyIterator.Next () se positionne sur la prochaine vue |
469 | MyIterator.Next (); |
470 | } |
471 | |
472 | } |
473 | |
474 | Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const { |
475 | |
476 | Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView (); |
477 | |
478 | #ifdef DEB |
479 | Standard_Integer Length = MyDefinedView.Extent (); |
480 | #else |
481 | MyDefinedView.Extent (); |
482 | #endif |
483 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
484 | |
485 | while (MyIterator.More ()) { |
486 | if ((MyIterator.Value ())->IsActive ()) |
487 | SG->Add (MyIterator.Value ()); |
488 | |
489 | // MyIterator.Next () se positionne sur la prochaine vue |
490 | MyIterator.Next (); |
491 | } |
492 | |
493 | return (SG); |
494 | |
495 | } |
496 | |
497 | #ifdef IMPLEMENTED |
498 | Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const { |
499 | |
500 | Standard_Boolean Result = Standard_False; |
501 | |
502 | // |
503 | // Check all activated views |
504 | // |
505 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
506 | |
507 | Standard_Integer i = MyDefinedView.Extent (); |
508 | |
509 | while ((! Result) && (MyIterator.More ())) { |
510 | if ((MyIterator.Value ())->IsActive ()) |
511 | Result = |
512 | (MyIterator.Value ())->ContainsComputedStructure (); |
513 | |
514 | // MyIterator.Next () se positionne |
515 | // sur la prochaine vue |
516 | MyIterator.Next (); |
517 | } |
518 | |
519 | return Result; |
520 | } |
521 | #endif |
522 | |
523 | Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const { |
524 | |
525 | Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView (); |
526 | |
527 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
528 | |
529 | while (MyIterator.More ()) { |
530 | SG->Add (MyIterator.Value ()); |
531 | |
532 | // MyIterator.Next () se positionne sur la prochaine vue |
533 | MyIterator.Next (); |
534 | } |
535 | |
536 | return (SG); |
537 | |
538 | } |
539 | |
540 | void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const { |
541 | |
542 | // On convertit que si les donnees sont correctes |
543 | Standard_Boolean Exist; |
544 | Graphic3d_CView TheCView; |
545 | //Graphic3d_Vertex Point; |
546 | |
547 | TColStd_Array2OfReal Ori_Matrix (0,3,0,3); |
548 | TColStd_Array2OfReal Map_Matrix (0,3,0,3); |
549 | |
550 | Standard_Integer Width, Height; |
551 | Standard_Real AX, AY, AZ; |
552 | Standard_Real Dx, Dy, Ratio; |
553 | |
554 | Exist = ViewExists (AWindow, TheCView); |
555 | |
556 | if (! Exist) { |
557 | AU = AV = IntegerLast (); |
558 | } |
559 | else { |
560 | // NKV - 11.02.08 - Use graphic driver functions |
561 | Standard_Boolean Result; |
562 | |
563 | AVertex.Coord (AX, AY, AZ); |
564 | |
565 | Result = MyGraphicDriver->ProjectRaster (TheCView, |
566 | Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ), |
567 | AU, AV); |
568 | |
569 | // the old code |
570 | if (!Result) { |
571 | |
572 | Standard_Real PtX, PtY, PtZ, PtT; |
573 | Standard_Real APX, APY, APZ; |
574 | Standard_Real APT; |
575 | |
576 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
577 | #ifdef DEB |
578 | Standard_Integer Length = MyDefinedView.Extent (); |
579 | #else |
580 | MyDefinedView.Extent (); |
581 | #endif |
582 | |
583 | Standard_Integer stop = 0; |
584 | |
585 | while ((! stop) && (MyIterator.More ())) { |
586 | if (TheCView.ViewId == |
587 | (MyIterator.Value ())->Identification ()) { |
588 | Ori_Matrix = |
589 | (MyIterator.Value ())->MatrixOfOrientation (); |
590 | Map_Matrix = |
591 | (MyIterator.Value ())->MatrixOfMapping (); |
592 | stop = 1; |
593 | } |
594 | |
595 | // MyIterator.Next () se positionne |
596 | // sur la prochaine vue |
597 | MyIterator.Next (); |
598 | } |
599 | |
600 | |
601 | // WCS -> View Reference Coordinate Space |
602 | PtX = Ori_Matrix (0, 0) * AX |
603 | + Ori_Matrix (0, 1) * AY |
604 | + Ori_Matrix (0, 2) * AZ |
605 | + Ori_Matrix (0, 3); |
606 | PtY = Ori_Matrix (1, 0) * AX |
607 | + Ori_Matrix (1, 1) * AY |
608 | + Ori_Matrix (1, 2) * AZ |
609 | + Ori_Matrix (1, 3); |
610 | PtZ = Ori_Matrix (2, 0) * AX |
611 | + Ori_Matrix (2, 1) * AY |
612 | + Ori_Matrix (2, 2) * AZ |
613 | + Ori_Matrix (2, 3); |
614 | PtT = Ori_Matrix (3, 0) * AX |
615 | + Ori_Matrix (3, 1) * AY |
616 | + Ori_Matrix (3, 2) * AZ |
617 | + Ori_Matrix (3, 3); |
618 | |
619 | // VRCS -> Normalized Projection Coordinate Space |
620 | APX = Map_Matrix (0, 0) * PtX |
621 | + Map_Matrix (0, 1) * PtY |
622 | + Map_Matrix (0, 2) * PtZ |
623 | + Map_Matrix (0, 3) * PtT; |
624 | APY = Map_Matrix (1, 0) * PtX |
625 | + Map_Matrix (1, 1) * PtY |
626 | + Map_Matrix (1, 2) * PtZ |
627 | + Map_Matrix (1, 3) * PtT; |
628 | APZ = Map_Matrix (2, 0) * PtX |
629 | + Map_Matrix (2, 1) * PtY |
630 | + Map_Matrix (2, 2) * PtZ |
631 | + Map_Matrix (2, 3) * PtT; |
632 | APT = Map_Matrix (3, 0) * PtX |
633 | + Map_Matrix (3, 1) * PtY |
634 | + Map_Matrix (3, 2) * PtZ |
635 | + Map_Matrix (3, 3) * PtT; |
636 | |
637 | if (APT == 0. || stop == 0) { |
638 | AU = AV = IntegerLast (); |
639 | } |
640 | else { |
641 | APX /= APT; |
642 | APY /= APT; |
643 | APZ /= APT; |
644 | |
645 | // NPCS -> Device Coordinate Space |
646 | AWindow->Size (Width, Height); |
647 | Dx = Standard_Real (Width); |
648 | Dy = Standard_Real (Height); |
649 | Ratio = Dx / Dy; |
650 | if (Ratio >= 1.) { |
651 | AU = Standard_Integer (APX * Dx); |
652 | AV = Standard_Integer (Dy - APY * Dy * Ratio); |
653 | } |
654 | else { |
655 | AU = Standard_Integer (APX * Dx / Ratio); |
656 | AV = Standard_Integer (Dy - APY * Dy); |
657 | } |
658 | } |
659 | } |
660 | } |
661 | |
662 | } |
663 | |
664 | Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const { |
665 | |
666 | // On convertit que si les donnees sont correctes |
667 | Graphic3d_CView TheCView; |
668 | Graphic3d_Vertex Point; |
669 | |
670 | if (! ViewExists (AWindow, TheCView)) |
671 | Point.SetCoord (RealLast (), RealLast (), RealLast ()); |
672 | else { |
673 | Standard_Integer Width, Height; |
674 | Standard_ShortReal x, y, z; |
675 | Standard_Boolean Result; |
676 | |
677 | AWindow->Size (Width, Height); |
678 | |
679 | Result = MyGraphicDriver->UnProjectRaster (TheCView, |
680 | 0, 0, Width, Height, |
681 | AU, AV, x, y, z); |
682 | |
683 | // Le unproject est realise par UnProjectRaster |
684 | if (Result) { |
685 | Point.SetCoord |
686 | (Standard_Real (x), Standard_Real (y), Standard_Real (z)); |
687 | } |
688 | // Le unproject n'est pas realisable par UnProjectRaster |
689 | // Code a virer des que les drivers Phigs et Pex seront abandonnes. |
690 | else { |
691 | |
692 | Standard_Real NPCX, NPCY, NPCZ; |
693 | Standard_Real VRCX, VRCY, VRCZ, VRCT; |
694 | Standard_Real WCX, WCY, WCZ, WCT; |
695 | |
696 | TColStd_Array2OfReal TOri_Matrix (0,3,0,3); |
697 | TColStd_Array2OfReal TMap_Matrix (0,3,0,3); |
698 | TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3); |
699 | TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3); |
700 | |
701 | Standard_Real Dx, Dy, Ratio; |
702 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
703 | Standard_Integer j; |
704 | |
705 | Standard_Integer stop = 0; |
706 | |
707 | Standard_Boolean BResult; |
708 | |
709 | j = MyDefinedView.Extent (); |
710 | |
711 | while ((! stop) && (MyIterator.More ())) { |
712 | if (TheCView.ViewId == |
713 | (MyIterator.Value ())->Identification ()) { |
714 | TOri_Matrix = |
715 | (MyIterator.Value ())->MatrixOfOrientation (); |
716 | TMap_Matrix = |
717 | (MyIterator.Value ())->MatrixOfMapping (); |
718 | stop = 1; |
719 | } |
720 | |
721 | // MyIterator.Next () se positionne |
722 | // sur la prochaine vue |
723 | MyIterator.Next (); |
724 | } |
725 | |
726 | // View Mapping Transformation and View Clip, inversion |
727 | BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv); |
728 | |
729 | // View Orientation Transformation, inversion |
730 | BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv); |
731 | |
732 | // (AU, AV) : Device Coordinate Space |
733 | // DCS -> NPCS Normalized Projection Coordinate Space |
734 | Dx = Standard_Real (Width); |
735 | Dy = Standard_Real (Height); |
736 | Ratio = Dx / Dy; |
737 | |
738 | if (Ratio >= 1.) { |
739 | NPCX = Standard_Real (AU) / Dx; |
740 | NPCY = (Dy - Standard_Real (AV)) / Dx; |
741 | } |
742 | else { |
743 | NPCX = Standard_Real (AU) / Dy; |
744 | NPCY = (Dy - Standard_Real (AV)) / Dy; |
745 | } |
746 | NPCZ = 0.0; |
747 | |
748 | // NPCS -> VRCS View Reference Coordinate Space |
749 | // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC); |
750 | |
751 | VRCX = TMap_Matrix_Inv (0, 0) * NPCX |
752 | + TMap_Matrix_Inv (0, 1) * NPCY |
753 | + TMap_Matrix_Inv (0, 2) * NPCZ |
754 | + TMap_Matrix_Inv (0, 3); |
755 | VRCY = TMap_Matrix_Inv (1, 0) * NPCX |
756 | + TMap_Matrix_Inv (1, 1) * NPCY |
757 | + TMap_Matrix_Inv (1, 2) * NPCZ |
758 | + TMap_Matrix_Inv (1, 3); |
759 | VRCZ = TMap_Matrix_Inv (2, 0) * NPCX |
760 | + TMap_Matrix_Inv (2, 1) * NPCY |
761 | + TMap_Matrix_Inv (2, 2) * NPCZ |
762 | + TMap_Matrix_Inv (2, 3); |
763 | VRCT = TMap_Matrix_Inv (3, 0) * NPCX |
764 | + TMap_Matrix_Inv (3, 1) * NPCY |
765 | + TMap_Matrix_Inv (3, 2) * NPCZ |
766 | + TMap_Matrix_Inv (3, 3); |
767 | |
768 | // VRCS -> WCS World Coordinate Space |
769 | // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC); |
770 | |
771 | WCX = TOri_Matrix_Inv (0, 0) * VRCX |
772 | + TOri_Matrix_Inv (0, 1) * VRCY |
773 | + TOri_Matrix_Inv (0, 2) * VRCZ |
774 | + TOri_Matrix_Inv (0, 3) * VRCT; |
775 | WCY = TOri_Matrix_Inv (1, 0) * VRCX |
776 | + TOri_Matrix_Inv (1, 1) * VRCY |
777 | + TOri_Matrix_Inv (1, 2) * VRCZ |
778 | + TOri_Matrix_Inv (1, 3) * VRCT; |
779 | WCZ = TOri_Matrix_Inv (2, 0) * VRCX |
780 | + TOri_Matrix_Inv (2, 1) * VRCY |
781 | + TOri_Matrix_Inv (2, 2) * VRCZ |
782 | + TOri_Matrix_Inv (2, 3) * VRCT; |
783 | WCT = TOri_Matrix_Inv (3, 0) * VRCX |
784 | + TOri_Matrix_Inv (3, 1) * VRCY |
785 | + TOri_Matrix_Inv (3, 2) * VRCZ |
786 | + TOri_Matrix_Inv (3, 3) * VRCT; |
787 | |
788 | if (WCT != 0.) |
789 | Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT); |
790 | else |
791 | Point.SetCoord (RealLast (), RealLast (), RealLast ()); |
792 | } |
793 | } |
794 | |
795 | return (Point); |
796 | |
797 | } |
798 | |
799 | void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const { |
800 | |
801 | // On convertit que si les donnees sont correctes |
802 | Graphic3d_CView TheCView; |
803 | |
804 | if (! ViewExists (AWindow, TheCView)) { |
805 | Point.SetCoord (RealLast (), RealLast (), RealLast ()); |
806 | Proj.SetCoord (0., 0., 0.); |
807 | } |
808 | else { |
809 | Standard_Integer Width, Height; |
810 | Standard_ShortReal x, y, z; |
811 | Standard_ShortReal dx, dy, dz; |
812 | Standard_Boolean Result; |
813 | |
814 | AWindow->Size (Width, Height); |
815 | |
816 | Result = MyGraphicDriver->UnProjectRasterWithRay (TheCView, |
817 | 0, 0, Width, Height, |
818 | AU, AV, x, y, z, dx, dy, dz); |
819 | |
820 | // Le unproject est realise par UnProjectRaster |
821 | if (Result) { |
822 | Point.SetCoord |
823 | (Standard_Real (x), Standard_Real (y), Standard_Real (z)); |
824 | Proj.SetCoord |
825 | (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz)); |
826 | Proj.Normalize(); |
827 | } |
828 | // Le unproject n'est pas realisable par UnProjectRaster |
829 | // Code a virer des que les drivers Phigs et Pex seront abandonnes. |
830 | else { |
831 | |
832 | Standard_Real NPCX, NPCY, NPCZ; |
833 | Standard_Real VRCX, VRCY, VRCZ, VRCT; |
834 | Standard_Real WCX, WCY, WCZ, WCT; |
835 | |
836 | TColStd_Array2OfReal TOri_Matrix (0,3,0,3); |
837 | TColStd_Array2OfReal TMap_Matrix (0,3,0,3); |
838 | TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3); |
839 | TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3); |
840 | |
841 | Standard_Real Dx, Dy, Ratio; |
842 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
843 | Standard_Integer j; |
844 | |
845 | Standard_Integer stop = 0; |
846 | |
847 | Standard_Boolean BResult; |
848 | |
849 | j = MyDefinedView.Extent (); |
850 | |
851 | while ((! stop) && (MyIterator.More ())) { |
852 | if (TheCView.ViewId == |
853 | (MyIterator.Value ())->Identification ()) { |
854 | TOri_Matrix = |
855 | (MyIterator.Value ())->MatrixOfOrientation (); |
856 | TMap_Matrix = |
857 | (MyIterator.Value ())->MatrixOfMapping (); |
858 | stop = 1; |
859 | } |
860 | |
861 | // MyIterator.Next () se positionne |
862 | // sur la prochaine vue |
863 | MyIterator.Next (); |
864 | } |
865 | |
866 | // View Mapping Transformation and View Clip, inversion |
867 | BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv); |
868 | |
869 | // View Orientation Transformation, inversion |
870 | BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv); |
871 | |
872 | // (AU, AV) : Device Coordinate Space |
873 | // DCS -> NPCS Normalized Projection Coordinate Space |
874 | Dx = Standard_Real (Width); |
875 | Dy = Standard_Real (Height); |
876 | Ratio = Dx / Dy; |
877 | |
878 | if (Ratio >= 1.) { |
879 | NPCX = Standard_Real (AU) / Dx; |
880 | NPCY = (Dy - Standard_Real (AV)) / Dx; |
881 | } |
882 | else { |
883 | NPCX = Standard_Real (AU) / Dy; |
884 | NPCY = (Dy - Standard_Real (AV)) / Dy; |
885 | } |
886 | NPCZ = 0.0; |
887 | |
888 | // NPCS -> VRCS View Reference Coordinate Space |
889 | // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC); |
890 | |
891 | VRCX = TMap_Matrix_Inv (0, 0) * NPCX |
892 | + TMap_Matrix_Inv (0, 1) * NPCY |
893 | + TMap_Matrix_Inv (0, 2) * NPCZ |
894 | + TMap_Matrix_Inv (0, 3); |
895 | VRCY = TMap_Matrix_Inv (1, 0) * NPCX |
896 | + TMap_Matrix_Inv (1, 1) * NPCY |
897 | + TMap_Matrix_Inv (1, 2) * NPCZ |
898 | + TMap_Matrix_Inv (1, 3); |
899 | VRCZ = TMap_Matrix_Inv (2, 0) * NPCX |
900 | + TMap_Matrix_Inv (2, 1) * NPCY |
901 | + TMap_Matrix_Inv (2, 2) * NPCZ |
902 | + TMap_Matrix_Inv (2, 3); |
903 | VRCT = TMap_Matrix_Inv (3, 0) * NPCX |
904 | + TMap_Matrix_Inv (3, 1) * NPCY |
905 | + TMap_Matrix_Inv (3, 2) * NPCZ |
906 | + TMap_Matrix_Inv (3, 3); |
907 | |
908 | // VRCS -> WCS World Coordinate Space |
909 | // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC); |
910 | |
911 | WCX = TOri_Matrix_Inv (0, 0) * VRCX |
912 | + TOri_Matrix_Inv (0, 1) * VRCY |
913 | + TOri_Matrix_Inv (0, 2) * VRCZ |
914 | + TOri_Matrix_Inv (0, 3) * VRCT; |
915 | WCY = TOri_Matrix_Inv (1, 0) * VRCX |
916 | + TOri_Matrix_Inv (1, 1) * VRCY |
917 | + TOri_Matrix_Inv (1, 2) * VRCZ |
918 | + TOri_Matrix_Inv (1, 3) * VRCT; |
919 | WCZ = TOri_Matrix_Inv (2, 0) * VRCX |
920 | + TOri_Matrix_Inv (2, 1) * VRCY |
921 | + TOri_Matrix_Inv (2, 2) * VRCZ |
922 | + TOri_Matrix_Inv (2, 3) * VRCT; |
923 | WCT = TOri_Matrix_Inv (3, 0) * VRCX |
924 | + TOri_Matrix_Inv (3, 1) * VRCY |
925 | + TOri_Matrix_Inv (3, 2) * VRCZ |
926 | + TOri_Matrix_Inv (3, 3) * VRCT; |
927 | |
928 | if (WCT != 0.) |
929 | Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT); |
930 | else |
931 | Point.SetCoord (RealLast (), RealLast (), RealLast ()); |
932 | |
933 | // Define projection ray |
934 | NPCZ = 10.0; |
935 | |
936 | // NPCS -> VRCS View Reference Coordinate Space |
937 | // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC); |
938 | |
939 | VRCX = TMap_Matrix_Inv (0, 0) * NPCX |
940 | + TMap_Matrix_Inv (0, 1) * NPCY |
941 | + TMap_Matrix_Inv (0, 2) * NPCZ |
942 | + TMap_Matrix_Inv (0, 3); |
943 | VRCY = TMap_Matrix_Inv (1, 0) * NPCX |
944 | + TMap_Matrix_Inv (1, 1) * NPCY |
945 | + TMap_Matrix_Inv (1, 2) * NPCZ |
946 | + TMap_Matrix_Inv (1, 3); |
947 | VRCZ = TMap_Matrix_Inv (2, 0) * NPCX |
948 | + TMap_Matrix_Inv (2, 1) * NPCY |
949 | + TMap_Matrix_Inv (2, 2) * NPCZ |
950 | + TMap_Matrix_Inv (2, 3); |
951 | VRCT = TMap_Matrix_Inv (3, 0) * NPCX |
952 | + TMap_Matrix_Inv (3, 1) * NPCY |
953 | + TMap_Matrix_Inv (3, 2) * NPCZ |
954 | + TMap_Matrix_Inv (3, 3); |
955 | |
956 | // VRCS -> WCS World Coordinate Space |
957 | // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC); |
958 | |
959 | WCX = TOri_Matrix_Inv (0, 0) * VRCX |
960 | + TOri_Matrix_Inv (0, 1) * VRCY |
961 | + TOri_Matrix_Inv (0, 2) * VRCZ |
962 | + TOri_Matrix_Inv (0, 3) * VRCT; |
963 | WCY = TOri_Matrix_Inv (1, 0) * VRCX |
964 | + TOri_Matrix_Inv (1, 1) * VRCY |
965 | + TOri_Matrix_Inv (1, 2) * VRCZ |
966 | + TOri_Matrix_Inv (1, 3) * VRCT; |
967 | WCZ = TOri_Matrix_Inv (2, 0) * VRCX |
968 | + TOri_Matrix_Inv (2, 1) * VRCY |
969 | + TOri_Matrix_Inv (2, 2) * VRCZ |
970 | + TOri_Matrix_Inv (2, 3) * VRCT; |
971 | WCT = TOri_Matrix_Inv (3, 0) * VRCX |
972 | + TOri_Matrix_Inv (3, 1) * VRCY |
973 | + TOri_Matrix_Inv (3, 2) * VRCZ |
974 | + TOri_Matrix_Inv (3, 3) * VRCT; |
975 | |
976 | if (WCT != 0.) { |
977 | Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT); |
978 | Proj.Normalize(); |
979 | } |
980 | else |
981 | Proj.SetCoord (0., 0., 0.); |
982 | } |
983 | } |
984 | |
985 | } |
986 | |
987 | Visual3d_PickDescriptor Visual3d_ViewManager::Pick (const Visual3d_ContextPick& CTX, const Handle(Aspect_Window)& AWindow, const Standard_Integer AX, const Standard_Integer AY) { |
988 | |
989 | // On active le reperage que si les donnees sont correctes |
990 | Standard_Boolean DoPick = Standard_False; |
991 | |
992 | CALL_DEF_PICK apick; |
993 | Standard_Integer Width, Height; |
994 | |
995 | // Parcours de la liste des vues pour rechercher |
996 | // une vue ayant pour fenetre celle specifiee |
997 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
998 | int TheWindowIdOfView; |
999 | |
1000 | #ifndef WNT |
1001 | const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow; |
1002 | int TheSpecifiedWindowId = int (THEWindow->XWindow ()); |
1003 | #else |
1004 | const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow; |
1005 | int TheSpecifiedWindowId = int (THEWindow->HWindow ()); |
1006 | #endif // WNT |
1007 | |
1008 | while ((! DoPick) && (MyIterator.More ())) { |
1009 | |
1010 | if ( ((MyIterator.Value ())->IsDefined ()) && |
1011 | ((MyIterator.Value ())->IsActive ()) ) { |
1012 | |
1013 | const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window (); |
1014 | #ifndef WNT |
1015 | const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow; |
1016 | TheWindowIdOfView = int (theWindow->XWindow ()); |
1017 | #else |
1018 | const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow; |
1019 | TheWindowIdOfView = int (theWindow->HWindow ()); |
1020 | #endif // WNT |
1021 | // Comparaison sur les windows ids |
1022 | if (TheWindowIdOfView == TheSpecifiedWindowId) { |
1023 | DoPick = Standard_True; |
1024 | |
1025 | // Mise a jour |
1026 | apick.WsId = |
1027 | int ((MyIterator.Value ())->Identification ()); |
1028 | |
1029 | apick.ViewId = |
1030 | int ((MyIterator.Value ())->Identification ()); |
1031 | #ifndef WNT |
1032 | apick.DefWindow.XWindow = TheSpecifiedWindowId; |
1033 | #else |
1034 | apick.DefWindow.XWindow = (HWND) TheSpecifiedWindowId; |
1035 | #endif |
1036 | |
1037 | apick.x = int (AX); |
1038 | apick.y = int (AY); |
1039 | |
1040 | theWindow->Size (Width, Height); |
1041 | apick.DefWindow.dx = float (Width); |
1042 | apick.DefWindow.dy = float (Height); |
1043 | |
1044 | apick.Context.aperture = (float) CTX.Aperture (); |
1045 | apick.Context.order = int (CTX.Order ()); |
1046 | apick.Context.depth = int (CTX.Depth ()); |
1047 | |
1048 | } |
1049 | } /* if ((MyIterator.Value ())->IsDefined ()) { */ |
1050 | |
1051 | // MyIterator.Next () se positionne |
1052 | // sur la prochaine vue |
1053 | MyIterator.Next (); |
1054 | } |
1055 | |
1056 | if (DoPick) |
1057 | MyGraphicDriver->Pick (apick); |
1058 | else |
1059 | apick.Pick.depth = 0; |
1060 | |
1061 | // Picking : le retour |
1062 | Standard_Integer i, j=0; |
1063 | Standard_Integer NbPick; |
1064 | |
1065 | Visual3d_PickDescriptor PDes (CTX); |
1066 | Visual3d_PickPath PPat; |
1067 | |
1068 | PDes.Clear (); |
1069 | NbPick = 0; |
1070 | // For i=0 it is not a graphic structure it is a view structure |
1071 | // For i=1 it is the displayed graphic structure |
1072 | // For i=2 to apick.Pick.depth-1 it is the connected graphic structures |
1073 | if (apick.Pick.depth != 0) { |
1074 | j = apick.Pick.listid[1]; |
1075 | if ((Graphic3d_StructureManager::Identification (j))-> |
1076 | IsSelectable ()) { |
1077 | // Maj element number |
1078 | PPat.SetElementNumber (apick.Pick.listelem[1]); |
1079 | // Maj pick identifier |
1080 | PPat.SetPickIdentifier (apick.Pick.listpickid[1]); |
1081 | // Maj structure |
1082 | PPat.SetStructIdentifier |
1083 | (Graphic3d_StructureManager::Identification (j)); |
1084 | // Maj PickPath |
1085 | PDes.AddPickPath (PPat); |
1086 | NbPick++; |
1087 | } |
1088 | } |
1089 | |
1090 | // Pas tres efficace, a revoir (CAL 22/09/95) |
1091 | if (apick.Pick.depth > 2) { |
1092 | Handle(Graphic3d_Structure) StructCur = |
1093 | Graphic3d_StructureManager::Identification (j); |
1094 | Standard_Boolean found; |
1095 | Graphic3d_MapOfStructure Set; |
1096 | |
1097 | for (i=2; i<apick.Pick.depth; i++) { |
1098 | found = Standard_False; |
1099 | j = apick.Pick.listid[i-1]; |
1100 | Set.Clear (); |
1101 | StructCur->Descendants (Set); |
1102 | Graphic3d_MapIteratorOfMapOfStructure IteratorD (Set); |
1103 | |
1104 | j = apick.Pick.listid[i]; |
1105 | while (IteratorD.More () && !found) { |
1106 | StructCur = IteratorD.Key (); |
1107 | if (StructCur->Identification () == j ) { |
1108 | found = Standard_True; |
1109 | // Maj element number |
1110 | PPat.SetElementNumber (apick.Pick.listelem[i]); |
1111 | // Maj pick identifier |
1112 | PPat.SetPickIdentifier (apick.Pick.listpickid[i]); |
1113 | // Maj structure |
1114 | PPat.SetStructIdentifier (StructCur); |
1115 | // Maj PickPath |
1116 | PDes.AddPickPath (PPat); |
1117 | NbPick++; |
1118 | } |
1119 | // IteratorD.Next () se positionne |
1120 | // sur la prochaine structure |
1121 | IteratorD.Next (); |
1122 | } |
1123 | } |
1124 | } |
1125 | |
1126 | apick.Pick.depth = int (NbPick); |
1127 | |
1128 | MyGraphicDriver->InitPick (); |
1129 | |
1130 | return (PDes); |
1131 | |
1132 | } |
1133 | |
1134 | Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const { |
1135 | |
1136 | Standard_Boolean Exist = Standard_False; |
1137 | |
1138 | // Parcours de la liste des vues pour rechercher |
1139 | // une vue ayant pour fenetre celle specifiee |
1140 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
1141 | int TheWindowIdOfView; |
1142 | |
1143 | #ifndef WNT |
1144 | const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow; |
1145 | int TheSpecifiedWindowId = int (THEWindow->XWindow ()); |
1146 | #else |
1147 | const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow; |
1148 | int TheSpecifiedWindowId = int (THEWindow->HWindow ()); |
1149 | #endif // WNT |
1150 | |
1151 | while ((! Exist) && (MyIterator.More ())) { |
1152 | |
1153 | if ( ((MyIterator.Value ())->IsDefined ()) && |
1154 | ((MyIterator.Value ())->IsActive ()) ) { |
1155 | |
1156 | const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window (); |
1157 | #ifndef WNT |
1158 | const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow; |
1159 | TheWindowIdOfView = int (theWindow->XWindow ()); |
1160 | #else |
1161 | const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow; |
1162 | TheWindowIdOfView = int (theWindow->HWindow ()); |
1163 | #endif // WNT |
1164 | // Comparaison sur les windows ids |
1165 | if (TheWindowIdOfView == TheSpecifiedWindowId) { |
1166 | Exist = Standard_True; |
1167 | TheCView = *(CALL_DEF_VIEW *)(MyIterator.Value ())->CView (); |
1168 | } |
1169 | } /* if ((MyIterator.Value ())->IsDefined ()) */ |
1170 | |
1171 | // MyIterator.Next () se positionne |
1172 | // sur la prochaine vue |
1173 | MyIterator.Next (); |
1174 | } |
1175 | |
1176 | return (Exist); |
1177 | |
1178 | } |
1179 | |
1180 | void Visual3d_ViewManager::Activate () { |
1181 | |
1182 | // |
1183 | // Activates all deactivated views |
1184 | // |
1185 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
1186 | |
1187 | #ifdef DEB |
1188 | Standard_Integer Length = MyDefinedView.Extent (); |
1189 | #else |
1190 | MyDefinedView.Extent (); |
1191 | #endif |
1192 | |
1193 | while (MyIterator.More ()) { |
1194 | if (! (MyIterator.Value ())->IsActive ()) |
1195 | (MyIterator.Value ())->Activate (); |
1196 | |
1197 | // MyIterator.Next () se positionne |
1198 | // sur la prochaine vue |
1199 | MyIterator.Next (); |
1200 | } |
1201 | |
1202 | } |
1203 | |
1204 | void Visual3d_ViewManager::Deactivate () { |
1205 | |
1206 | // |
1207 | // Deactivates all activated views |
1208 | // |
1209 | #ifdef DEB |
1210 | Standard_Integer Length = MyDefinedView.Extent (); |
1211 | #else |
1212 | MyDefinedView.Extent (); |
1213 | #endif |
1214 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
1215 | |
1216 | while (MyIterator.More ()) { |
1217 | if ((MyIterator.Value ())->IsActive ()) |
1218 | (MyIterator.Value ())->Deactivate (); |
1219 | |
1220 | // MyIterator.Next () se positionne |
1221 | // sur la prochaine vue |
1222 | MyIterator.Next (); |
1223 | } |
1224 | |
1225 | } |
1226 | |
1227 | Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const { |
1228 | |
1229 | // on retourne le nombre theorique de vues definissables pour le |
1230 | // Visual3d_ViewManager courant. |
1231 | return |
1232 | (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ())); |
1233 | |
1234 | } |
1235 | |
1236 | Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const { |
1237 | |
1238 | return (Graphic3d_StructureManager::Identification (AId)); |
1239 | |
1240 | } |
1241 | |
1242 | Standard_Integer Visual3d_ViewManager::Identification () const { |
1243 | |
1244 | return (Graphic3d_StructureManager::Identification ()); |
1245 | |
1246 | } |
1247 | |
1248 | Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) { |
1249 | |
1250 | MyDefinedView.Add (AView); |
1251 | return (MyViewGenId.Next ()); |
1252 | |
1253 | } |
1254 | |
1255 | void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId) |
1256 | { |
1257 | MyViewGenId.Free(aViewId); |
1258 | } |
1259 | |
1260 | void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) { |
1261 | |
1262 | if (MyTransparency && AFlag) return; |
1263 | if (! MyTransparency && ! AFlag) return; |
1264 | |
1265 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
1266 | while (MyIterator.More ()) { |
1267 | (MyIterator.Value ())->SetTransparency (AFlag); |
1268 | // MyIterator.Next () se positionne sur la prochaine vue |
1269 | MyIterator.Next (); |
1270 | } |
1271 | |
1272 | MyTransparency = AFlag; |
1273 | |
1274 | } |
1275 | |
1276 | Standard_Boolean Visual3d_ViewManager::Transparency () const { |
1277 | |
1278 | return (MyTransparency); |
1279 | |
1280 | } |
1281 | |
1282 | void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) { |
1283 | |
1284 | if (MyZBufferAuto && AFlag) return; |
1285 | if (! MyZBufferAuto && ! AFlag) return; |
1286 | |
1287 | // si de False on passe a True : |
1288 | // pas de probleme, au prochain update de vue, celle-ci se |
1289 | // posera les bonnes questions pour reagir (SetVisualisation) |
1290 | // si de True on passe a False : |
1291 | // il faut modifier le ZBufferActivity de chaque vue pour que |
1292 | // le zbuffer ne soit actif que si le contexte le demande. |
1293 | // Dans ce cas on passe -1 pour que la vue se pose la question |
1294 | // Rappel : 0 on force la desactivation, 1 on force l'activation |
1295 | if (! AFlag) { |
1296 | Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView); |
1297 | while (MyIterator.More ()) { |
1298 | (MyIterator.Value ())->SetZBufferActivity (-1); |
1299 | // MyIterator.Next () se positionne sur la prochaine vue |
1300 | MyIterator.Next (); |
1301 | } |
1302 | } |
1303 | MyZBufferAuto = AFlag; |
1304 | |
1305 | } |
1306 | |
1307 | Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const { |
1308 | |
1309 | return (MyZBufferAuto); |
1310 | |
1311 | } |
1312 | |
1313 | void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) { |
1314 | |
1315 | #ifdef TRACE_LAYER |
1316 | cout << "Visual3d_ViewManager::SetLayer\n" << flush; |
1317 | #endif |
1318 | |
1319 | if (ALayer->Type () == Aspect_TOL_OVERLAY) { |
1320 | #ifdef TRACE_LAYER |
1321 | if (MyOverLayer.IsNull ()) |
1322 | cout << "MyOverLayer is defined" << endl; |
1323 | else |
1324 | cout << "MyOverLayer is redefined" << endl; |
1325 | #endif |
1326 | MyOverLayer = ALayer; |
1327 | } |
1328 | else { |
1329 | #ifdef TRACE_LAYER |
1330 | if (MyUnderLayer.IsNull ()) |
1331 | cout << "MyUnderLayer is defined" << endl; |
1332 | else |
1333 | cout << "MyUnderLayer is redefined" << endl; |
1334 | #endif |
1335 | MyUnderLayer = ALayer; |
1336 | } |
1337 | |
1338 | } |
1339 | |
1340 | const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const { |
1341 | |
1342 | return (MyUnderLayer); |
1343 | |
1344 | } |
1345 | |
1346 | const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const { |
1347 | |
1348 | return (MyOverLayer); |
1349 | |
1350 | } |