2 /***********************************************************************
6 Classe Visual3d_ViewManager.cxx :
8 Declaration of variables specific to visualisers
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.
29 ************************************************************************/
31 /*----------------------------------------------------------------------*/
39 /*----------------------------------------------------------------------*/
45 #include <Visual3d_ViewManager.ixx>
46 #include <Visual3d_ViewManager.pxx>
48 #include <Standard_ErrorHandler.hxx>
51 #include <Aspect_IdentDefinitionError.hxx>
53 #include <Graphic3d_GraphicDriver.hxx>
54 #include <Graphic3d_MapOfStructure.hxx>
55 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
57 #include <Visual3d_PickPath.hxx>
58 #include <Visual3d_SetIteratorOfSetOfView.hxx>
61 # include <Xw_Window.hxx>
63 # include <WNT_Window.hxx>
68 //-Global data definitions
70 // -- les vues definies
71 // MyDefinedView : SetOfView;
73 // -- le generateur d'identificateurs de vues
74 // MyViewGenId : GenId;
78 Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Aspect_GraphicDevice)& aDevice):
79 Graphic3d_StructureManager (aDevice),
81 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),
82 MyZBufferAuto (Standard_False),
83 MyTransparency (Standard_False)
85 // default layer is always presented in display layer sequence
86 // it can not be removed
88 myLayerSeq.Append (0);
90 Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver ();
92 MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
97 void Visual3d_ViewManager::Destroy () {
100 cout << "Visual3d_ViewManager::Destroy (" << MyId << ")\n" << flush;
108 void Visual3d_ViewManager::Remove () {
111 cout << "Visual3d_ViewManager::Remove (" << MyId << ")\n" << flush;
115 // Destroy all defined views
118 Standard_Integer Length = MyDefinedView.Extent ();
120 MyDefinedView.Extent ();
124 cout << "The Manager " << MyId << " have " << Length << " defined views\n";
128 MyDefinedView.Clear ();
132 void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
135 cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
136 << AStructure->Identification ()
137 << ", " << OldPriority << ", " << NewPriority << ")\n";
142 // Change structure priority in all defined views
145 Standard_Integer Length = MyDefinedView.Extent ();
147 MyDefinedView.Extent ();
149 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
151 while (MyIterator.More ()) {
152 (MyIterator.Value ())->ChangeDisplayPriority
153 (AStructure, OldPriority, NewPriority);
155 // MyIterator.Next () is located on the next view
161 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
163 //Standard_Integer LengthD = MyDisplayedStructure.Extent() ();
165 // Even if physically the structure cannot
166 // be displayed (pb of visualisation type)
167 // it has status Displayed.
169 if (!MyDisplayedStructure.Contains(AStructure))
173 // Recompute structure in all activated views
175 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
177 while (MyIterator.More ()) {
178 (MyIterator.Value ())->ReCompute (AStructure);
180 // MyIterator.Next () is located on the next view
186 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
187 const Handle(Graphic3d_DataStructureManager)& AProjector)
190 if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
193 Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
195 Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector;
197 Standard_Integer ViewId = theView->Identification ();
199 Standard_Integer indexD = 0;
201 // Even if physically the structure cannot
202 // be displayed (pb of visualisation type)
203 // it has status Displayed.
204 if (!MyDisplayedStructure.Contains(AStructure))
208 // Recompute structure in all activated views
210 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
212 while (MyIterator.More ()) {
213 if ((MyIterator.Value ())->Identification () == ViewId)
214 theView->ReCompute (AStructure);
216 // MyIterator.Next () is located on the next view
222 void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
225 Standard_Integer Length = MyDefinedView.Extent ();
227 MyDefinedView.Extent ();
229 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
231 while (MyIterator.More ()) {
232 (MyIterator.Value ())->Clear (AStructure, WithDestruction);
234 // MyIterator.Next () is located on the next view
240 void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
243 Standard_Integer Length = MyDefinedView.Extent ();
245 MyDefinedView.Extent ();
247 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
249 while (MyIterator.More ()) {
250 (MyIterator.Value ())->Connect (AMother, ADaughter);
252 // MyIterator.Next () is located on the next view
258 void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
261 Standard_Integer Length = MyDefinedView.Extent ();
263 MyDefinedView.Extent ();
265 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
267 while (MyIterator.More ()) {
268 (MyIterator.Value ())->Disconnect (AMother, ADaughter);
270 // MyIterator.Next () is located on the next view
276 void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) {
279 // Even if physically the structure cannot
280 // be displayed (pb of visualisation type)
281 // it has status Displayed.
283 MyDisplayedStructure.Add(AStructure);
286 // Display structure in all activated views
288 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
290 while (MyIterator.More ()) {
291 (MyIterator.Value ())->Display (AStructure);
293 // MyIterator.Next () is located on the next view
299 void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) {
302 // Even if physically the structure cannot
303 // be displayed (pb of visualisation type)
304 // it has status Displayed.
306 MyDisplayedStructure.Remove(AStructure);
311 // Erase structure in all defined views
314 Standard_Integer Length = MyDefinedView.Extent ();
316 MyDefinedView.Extent ();
318 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
320 while (MyIterator.More ()) {
321 (MyIterator.Value ())->Erase (AStructure);
323 // MyIterator.Next () is located on the next view
327 MyHighlightedStructure.Remove (AStructure);
328 MyVisibleStructure.Remove (AStructure);
329 MyPickStructure.Remove (AStructure);
333 void Visual3d_ViewManager::Erase () {
335 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
337 for (; it.More(); it.Next()) {
338 Handle(Graphic3d_Structure) SG = it.Key();
344 void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
346 MyHighlightedStructure.Add(AStructure);
349 // Highlight in all activated views
352 Standard_Integer Length = MyDefinedView.Extent ();
354 MyDefinedView.Extent ();
356 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
358 while (MyIterator.More ()) {
359 (MyIterator.Value ())->Highlight (AStructure, AMethod);
361 // MyIterator.Next () is located on the next view
367 void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
370 Standard_Integer Length = MyDefinedView.Extent ();
372 MyDefinedView.Extent ();
374 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
376 while (MyIterator.More ()) {
377 (MyIterator.Value ())->SetTransform (AStructure, ATrsf);
379 // MyIterator.Next () is located on the next view
385 void Visual3d_ViewManager::UnHighlight () {
387 Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
389 for (; it.More(); it.Next()) {
390 Handle(Graphic3d_Structure) SG = it.Key();
397 void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
399 MyHighlightedStructure.Remove(AStructure);
403 // UnHighlight in all activated views
406 Standard_Integer Length = MyDefinedView.Extent ();
408 MyDefinedView.Extent ();
410 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
412 while (MyIterator.More ()) {
413 (MyIterator.Value ())->UnHighlight (AStructure);
415 // MyIterator.Next () is located on the next view
421 void Visual3d_ViewManager::Redraw () const {
423 Standard_Integer MaxDx, MaxDy;
424 Standard_Integer Dx, Dy;
425 MaxDx = MaxDy = IntegerFirst ();
428 // Redraw all activated views
430 Standard_Integer j = MyDefinedView.Extent ();
432 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
434 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) {
435 while (MyIterator.More ()) {
436 (MyIterator.Value ())->Window ()->Size (Dx, Dy);
437 if (Dx > MaxDx) MaxDx = Dx;
438 if (Dy > MaxDy) MaxDy = Dy;
440 // MyIterator.Next () is located on the next view
443 if (! MyUnderLayer.IsNull ())
444 MyUnderLayer->SetViewport (MaxDx, MaxDy);
445 if (! MyOverLayer.IsNull ())
446 MyOverLayer->SetViewport (MaxDx, MaxDy);
449 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ())
450 MyIterator.Initialize (MyDefinedView);
451 while (MyIterator.More ()) {
452 (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer);
454 // MyIterator.Next () is located on the next view
460 void Visual3d_ViewManager::Update () const {
463 // Update all activated views
465 Standard_Integer j = MyDefinedView.Extent ();
467 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
469 while (MyIterator.More ()) {
470 (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer);
472 // MyIterator.Next () is located on the next view
478 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const {
480 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
483 Standard_Integer Length = MyDefinedView.Extent ();
485 MyDefinedView.Extent ();
487 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
489 while (MyIterator.More ()) {
490 if ((MyIterator.Value ())->IsActive ())
491 SG->Add (MyIterator.Value ());
493 // MyIterator.Next () is located on the next view
502 Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const {
504 Standard_Boolean Result = Standard_False;
507 // Check all activated views
509 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
511 Standard_Integer i = MyDefinedView.Extent ();
513 while ((! Result) && (MyIterator.More ())) {
514 if ((MyIterator.Value ())->IsActive ())
516 (MyIterator.Value ())->ContainsComputedStructure ();
518 // MyIterator.Next () is located on the next view
526 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const {
528 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
530 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
532 while (MyIterator.More ()) {
533 SG->Add (MyIterator.Value ());
535 // MyIterator.Next () is located on the next view
543 void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const {
545 // Convert only if the data is correct
546 Standard_Boolean Exist;
547 Graphic3d_CView TheCView;
548 //Graphic3d_Vertex Point;
550 TColStd_Array2OfReal Ori_Matrix (0,3,0,3);
551 TColStd_Array2OfReal Map_Matrix (0,3,0,3);
553 Standard_Integer Width, Height;
554 Standard_Real AX, AY, AZ;
555 Standard_Real Dx, Dy, Ratio;
557 Exist = ViewExists (AWindow, TheCView);
560 AU = AV = IntegerLast ();
563 // NKV - 11.02.08 - Use graphic driver functions
564 Standard_Boolean Result;
566 AVertex.Coord (AX, AY, AZ);
568 Result = MyGraphicDriver->ProjectRaster (TheCView,
569 Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ),
575 Standard_Real PtX, PtY, PtZ, PtT;
576 Standard_Real APX, APY, APZ;
579 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
581 Standard_Integer Length = MyDefinedView.Extent ();
583 MyDefinedView.Extent ();
586 Standard_Integer stop = 0;
588 while ((! stop) && (MyIterator.More ())) {
589 if (TheCView.ViewId ==
590 (MyIterator.Value ())->Identification ()) {
592 (MyIterator.Value ())->MatrixOfOrientation ();
594 (MyIterator.Value ())->MatrixOfMapping ();
598 // MyIterator.Next () is located on the next view
603 // WCS -> View Reference Coordinate Space
604 PtX = Ori_Matrix (0, 0) * AX
605 + Ori_Matrix (0, 1) * AY
606 + Ori_Matrix (0, 2) * AZ
608 PtY = Ori_Matrix (1, 0) * AX
609 + Ori_Matrix (1, 1) * AY
610 + Ori_Matrix (1, 2) * AZ
612 PtZ = Ori_Matrix (2, 0) * AX
613 + Ori_Matrix (2, 1) * AY
614 + Ori_Matrix (2, 2) * AZ
616 PtT = Ori_Matrix (3, 0) * AX
617 + Ori_Matrix (3, 1) * AY
618 + Ori_Matrix (3, 2) * AZ
621 // VRCS -> Normalized Projection Coordinate Space
622 APX = Map_Matrix (0, 0) * PtX
623 + Map_Matrix (0, 1) * PtY
624 + Map_Matrix (0, 2) * PtZ
625 + Map_Matrix (0, 3) * PtT;
626 APY = Map_Matrix (1, 0) * PtX
627 + Map_Matrix (1, 1) * PtY
628 + Map_Matrix (1, 2) * PtZ
629 + Map_Matrix (1, 3) * PtT;
630 APZ = Map_Matrix (2, 0) * PtX
631 + Map_Matrix (2, 1) * PtY
632 + Map_Matrix (2, 2) * PtZ
633 + Map_Matrix (2, 3) * PtT;
634 APT = Map_Matrix (3, 0) * PtX
635 + Map_Matrix (3, 1) * PtY
636 + Map_Matrix (3, 2) * PtZ
637 + Map_Matrix (3, 3) * PtT;
639 if (APT == 0. || stop == 0) {
640 AU = AV = IntegerLast ();
647 // NPCS -> Device Coordinate Space
648 AWindow->Size (Width, Height);
649 Dx = Standard_Real (Width);
650 Dy = Standard_Real (Height);
653 AU = Standard_Integer (APX * Dx);
654 AV = Standard_Integer (Dy - APY * Dy * Ratio);
657 AU = Standard_Integer (APX * Dx / Ratio);
658 AV = Standard_Integer (Dy - APY * Dy);
666 Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const {
668 // Convert only if the data is correct
669 Graphic3d_CView TheCView;
670 Graphic3d_Vertex Point;
672 if (! ViewExists (AWindow, TheCView))
673 Point.SetCoord (RealLast (), RealLast (), RealLast ());
675 Standard_Integer Width, Height;
676 Standard_ShortReal x, y, z;
677 Standard_Boolean Result;
679 AWindow->Size (Width, Height);
681 Result = MyGraphicDriver->UnProjectRaster (TheCView,
685 // unproject is done by UnProjectRaster
688 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
690 // unproject cannot be done by UnProjectRaster
691 // Code suspended since drivers Phigs and Pex are abandoned.
694 Standard_Real NPCX, NPCY, NPCZ;
695 Standard_Real VRCX, VRCY, VRCZ, VRCT;
696 Standard_Real WCX, WCY, WCZ, WCT;
698 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
699 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
700 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
701 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
703 Standard_Real Dx, Dy, Ratio;
704 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
707 Standard_Integer stop = 0;
709 Standard_Boolean BResult;
711 j = MyDefinedView.Extent ();
713 while ((! stop) && (MyIterator.More ())) {
714 if (TheCView.ViewId ==
715 (MyIterator.Value ())->Identification ()) {
717 (MyIterator.Value ())->MatrixOfOrientation ();
719 (MyIterator.Value ())->MatrixOfMapping ();
723 // MyIterator.Next () is located on the next view
727 // View Mapping Transformation and View Clip, inversion
728 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
730 // View Orientation Transformation, inversion
731 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
733 // (AU, AV) : Device Coordinate Space
734 // DCS -> NPCS Normalized Projection Coordinate Space
735 Dx = Standard_Real (Width);
736 Dy = Standard_Real (Height);
740 NPCX = Standard_Real (AU) / Dx;
741 NPCY = (Dy - Standard_Real (AV)) / Dx;
744 NPCX = Standard_Real (AU) / Dy;
745 NPCY = (Dy - Standard_Real (AV)) / Dy;
749 // NPCS -> VRCS View Reference Coordinate Space
750 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
752 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
753 + TMap_Matrix_Inv (0, 1) * NPCY
754 + TMap_Matrix_Inv (0, 2) * NPCZ
755 + TMap_Matrix_Inv (0, 3);
756 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
757 + TMap_Matrix_Inv (1, 1) * NPCY
758 + TMap_Matrix_Inv (1, 2) * NPCZ
759 + TMap_Matrix_Inv (1, 3);
760 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
761 + TMap_Matrix_Inv (2, 1) * NPCY
762 + TMap_Matrix_Inv (2, 2) * NPCZ
763 + TMap_Matrix_Inv (2, 3);
764 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
765 + TMap_Matrix_Inv (3, 1) * NPCY
766 + TMap_Matrix_Inv (3, 2) * NPCZ
767 + TMap_Matrix_Inv (3, 3);
769 // VRCS -> WCS World Coordinate Space
770 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
772 WCX = TOri_Matrix_Inv (0, 0) * VRCX
773 + TOri_Matrix_Inv (0, 1) * VRCY
774 + TOri_Matrix_Inv (0, 2) * VRCZ
775 + TOri_Matrix_Inv (0, 3) * VRCT;
776 WCY = TOri_Matrix_Inv (1, 0) * VRCX
777 + TOri_Matrix_Inv (1, 1) * VRCY
778 + TOri_Matrix_Inv (1, 2) * VRCZ
779 + TOri_Matrix_Inv (1, 3) * VRCT;
780 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
781 + TOri_Matrix_Inv (2, 1) * VRCY
782 + TOri_Matrix_Inv (2, 2) * VRCZ
783 + TOri_Matrix_Inv (2, 3) * VRCT;
784 WCT = TOri_Matrix_Inv (3, 0) * VRCX
785 + TOri_Matrix_Inv (3, 1) * VRCY
786 + TOri_Matrix_Inv (3, 2) * VRCZ
787 + TOri_Matrix_Inv (3, 3) * VRCT;
790 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
792 Point.SetCoord (RealLast (), RealLast (), RealLast ());
800 void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {
802 // Conversion only if the data is correct
803 Graphic3d_CView TheCView;
805 if (! ViewExists (AWindow, TheCView)) {
806 Point.SetCoord (RealLast (), RealLast (), RealLast ());
807 Proj.SetCoord (0., 0., 0.);
810 Standard_Integer Width, Height;
811 Standard_ShortReal x, y, z;
812 Standard_ShortReal dx, dy, dz;
813 Standard_Boolean Result;
815 AWindow->Size (Width, Height);
817 Result = MyGraphicDriver->UnProjectRasterWithRay (TheCView,
819 AU, AV, x, y, z, dx, dy, dz);
821 // unproject is done by UnProjectRaster
824 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
826 (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
829 // unproject cannot be done by UnProjectRaster
830 // Code is suspended since drivers Phigs are Pex abandoned.
833 Standard_Real NPCX, NPCY, NPCZ;
834 Standard_Real VRCX, VRCY, VRCZ, VRCT;
835 Standard_Real WCX, WCY, WCZ, WCT;
837 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
838 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
839 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
840 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
842 Standard_Real Dx, Dy, Ratio;
843 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
846 Standard_Integer stop = 0;
848 Standard_Boolean BResult;
850 j = MyDefinedView.Extent ();
852 while ((! stop) && (MyIterator.More ())) {
853 if (TheCView.ViewId ==
854 (MyIterator.Value ())->Identification ()) {
856 (MyIterator.Value ())->MatrixOfOrientation ();
858 (MyIterator.Value ())->MatrixOfMapping ();
862 // MyIterator.Next () is located on the next view
866 // View Mapping Transformation and View Clip, inversion
867 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
869 // View Orientation Transformation, inversion
870 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
872 // (AU, AV) : Device Coordinate Space
873 // DCS -> NPCS Normalized Projection Coordinate Space
874 Dx = Standard_Real (Width);
875 Dy = Standard_Real (Height);
879 NPCX = Standard_Real (AU) / Dx;
880 NPCY = (Dy - Standard_Real (AV)) / Dx;
883 NPCX = Standard_Real (AU) / Dy;
884 NPCY = (Dy - Standard_Real (AV)) / Dy;
888 // NPCS -> VRCS View Reference Coordinate Space
889 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
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);
908 // VRCS -> WCS World Coordinate Space
909 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
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;
929 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
931 Point.SetCoord (RealLast (), RealLast (), RealLast ());
933 // Define projection ray
936 // NPCS -> VRCS View Reference Coordinate Space
937 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
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);
956 // VRCS -> WCS World Coordinate Space
957 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
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;
977 Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
981 Proj.SetCoord (0., 0., 0.);
987 Visual3d_PickDescriptor Visual3d_ViewManager::Pick (const Visual3d_ContextPick& CTX, const Handle(Aspect_Window)& AWindow, const Standard_Integer AX, const Standard_Integer AY) {
989 // The marking is activated only if the data is correct
990 Standard_Boolean DoPick = Standard_False;
993 Standard_Integer Width, Height;
995 // Parse the list of views to find a
996 // view having this specified window
997 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
998 int TheWindowIdOfView;
1001 const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
1002 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
1004 const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
1005 int TheSpecifiedWindowId = int (THEWindow->HWindow ());
1008 while ((! DoPick) && (MyIterator.More ())) {
1010 if ( ((MyIterator.Value ())->IsDefined ()) &&
1011 ((MyIterator.Value ())->IsActive ()) ) {
1013 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
1015 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
1016 TheWindowIdOfView = int (theWindow->XWindow ());
1018 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
1019 TheWindowIdOfView = int (theWindow->HWindow ());
1021 // Comparision on window IDs
1022 if (TheWindowIdOfView == TheSpecifiedWindowId) {
1023 DoPick = Standard_True;
1027 int ((MyIterator.Value ())->Identification ());
1030 int ((MyIterator.Value ())->Identification ());
1032 apick.DefWindow.XWindow = TheSpecifiedWindowId;
1034 apick.DefWindow.XWindow = (HWND) TheSpecifiedWindowId;
1040 theWindow->Size (Width, Height);
1041 apick.DefWindow.dx = float (Width);
1042 apick.DefWindow.dy = float (Height);
1044 apick.Context.aperture = (float) CTX.Aperture ();
1045 apick.Context.order = int (CTX.Order ());
1046 apick.Context.depth = int (CTX.Depth ());
1049 } /* if ((MyIterator.Value ())->IsDefined ()) { */
1051 // MyIterator.Next () is located on the next view
1056 MyGraphicDriver->Pick (apick);
1058 apick.Pick.depth = 0;
1061 Standard_Integer i, j=0;
1062 Standard_Integer NbPick;
1064 Visual3d_PickDescriptor PDes (CTX);
1065 Visual3d_PickPath PPat;
1069 // For i=0 it is not a graphic structure it is a view structure
1070 // For i=1 it is the displayed graphic structure
1071 // For i=2 to apick.Pick.depth-1 it is the connected graphic structures
1072 if (apick.Pick.depth != 0) {
1073 j = apick.Pick.listid[1];
1074 if ((Graphic3d_StructureManager::Identification (j))->
1076 // Maj element number
1077 PPat.SetElementNumber (apick.Pick.listelem[1]);
1078 // Maj pick identifier
1079 PPat.SetPickIdentifier (apick.Pick.listpickid[1]);
1081 PPat.SetStructIdentifier
1082 (Graphic3d_StructureManager::Identification (j));
1084 PDes.AddPickPath (PPat);
1089 // Not very efficient, revise (CAL 22/09/95)
1090 if (apick.Pick.depth > 2) {
1091 Handle(Graphic3d_Structure) StructCur =
1092 Graphic3d_StructureManager::Identification (j);
1093 Standard_Boolean found;
1094 Graphic3d_MapOfStructure Set;
1096 for (i=2; i<apick.Pick.depth; i++) {
1097 found = Standard_False;
1098 j = apick.Pick.listid[i-1];
1100 StructCur->Descendants (Set);
1101 Graphic3d_MapIteratorOfMapOfStructure IteratorD (Set);
1103 j = apick.Pick.listid[i];
1104 while (IteratorD.More () && !found) {
1105 StructCur = IteratorD.Key ();
1106 if (StructCur->Identification () == j ) {
1107 found = Standard_True;
1108 // Maj element number
1109 PPat.SetElementNumber (apick.Pick.listelem[i]);
1110 // Maj pick identifier
1111 PPat.SetPickIdentifier (apick.Pick.listpickid[i]);
1113 PPat.SetStructIdentifier (StructCur);
1115 PDes.AddPickPath (PPat);
1118 // IteratorD.Next () is located on the next structure
1124 apick.Pick.depth = int (NbPick);
1126 MyGraphicDriver->InitPick ();
1132 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
1134 Standard_Boolean Exist = Standard_False;
1136 // Parse the list of views to find
1137 // a view with the specified window
1138 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1139 int TheWindowIdOfView;
1142 const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
1143 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
1145 const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
1146 int TheSpecifiedWindowId = int (THEWindow->HWindow ());
1149 while ((! Exist) && (MyIterator.More ())) {
1151 if ( ((MyIterator.Value ())->IsDefined ()) &&
1152 ((MyIterator.Value ())->IsActive ()) ) {
1154 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
1156 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
1157 TheWindowIdOfView = int (theWindow->XWindow ());
1159 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
1160 TheWindowIdOfView = int (theWindow->HWindow ());
1162 // Comparaison on window IDs
1163 if (TheWindowIdOfView == TheSpecifiedWindowId) {
1164 Exist = Standard_True;
1165 TheCView = *(CALL_DEF_VIEW *)(MyIterator.Value ())->CView ();
1167 } /* if ((MyIterator.Value ())->IsDefined ()) */
1169 // MyIterator.Next () is located on the next view
1177 void Visual3d_ViewManager::Activate () {
1180 // Activates all deactivated views
1182 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1185 Standard_Integer Length = MyDefinedView.Extent ();
1187 MyDefinedView.Extent ();
1190 while (MyIterator.More ()) {
1191 if (! (MyIterator.Value ())->IsActive ())
1192 (MyIterator.Value ())->Activate ();
1194 // MyIterator.Next () is located on the next view
1200 void Visual3d_ViewManager::Deactivate () {
1203 // Deactivates all activated views
1206 Standard_Integer Length = MyDefinedView.Extent ();
1208 MyDefinedView.Extent ();
1210 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1212 while (MyIterator.More ()) {
1213 if ((MyIterator.Value ())->IsActive ())
1214 (MyIterator.Value ())->Deactivate ();
1216 // MyIterator.Next () is located on the next view
1222 Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
1224 // Retourne the planned of definable views for the current
1225 // Visual3d_ViewManager.
1227 (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
1231 Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
1233 return (Graphic3d_StructureManager::Identification (AId));
1237 Standard_Integer Visual3d_ViewManager::Identification () const {
1239 return (Graphic3d_StructureManager::Identification ());
1243 Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {
1245 MyDefinedView.Add (AView);
1246 return (MyViewGenId.Next ());
1250 void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
1252 MyViewGenId.Free(aViewId);
1255 void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
1257 if (MyTransparency && AFlag) return;
1258 if (! MyTransparency && ! AFlag) return;
1260 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1261 while (MyIterator.More ()) {
1262 (MyIterator.Value ())->SetTransparency (AFlag);
1263 // MyIterator.Next () is located on the next view
1267 MyTransparency = AFlag;
1271 Standard_Boolean Visual3d_ViewManager::Transparency () const {
1273 return (MyTransparency);
1277 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
1279 if (MyZBufferAuto && AFlag) return;
1280 if (! MyZBufferAuto && ! AFlag) return;
1282 // if pass from False to True :
1283 // no problem, at the next view update, it
1284 // will properly ask questions to answer (SetVisualisation)
1285 // if pass from True to False :
1286 // it is necessary to modify ZBufferActivity at each view so that
1287 // zbuffer could be active only if required by context.
1288 // In this case -1 is passed so that the view ask itself the question
1289 // Note : 0 forces the desactivation, 1 forces the activation
1291 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1292 while (MyIterator.More ()) {
1293 (MyIterator.Value ())->SetZBufferActivity (-1);
1294 // MyIterator.Next () is located on the next view
1298 MyZBufferAuto = AFlag;
1302 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
1304 return (MyZBufferAuto);
1308 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
1311 cout << "Visual3d_ViewManager::SetLayer\n" << flush;
1314 if (ALayer->Type () == Aspect_TOL_OVERLAY) {
1316 if (MyOverLayer.IsNull ())
1317 cout << "MyOverLayer is defined" << endl;
1319 cout << "MyOverLayer is redefined" << endl;
1321 MyOverLayer = ALayer;
1325 if (MyUnderLayer.IsNull ())
1326 cout << "MyUnderLayer is defined" << endl;
1328 cout << "MyUnderLayer is redefined" << endl;
1330 MyUnderLayer = ALayer;
1335 const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
1337 return (MyUnderLayer);
1341 const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
1343 return (MyOverLayer);
1347 //=======================================================================
1348 //function : ChangeZLayer
1350 //=======================================================================
1352 void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1353 const Standard_Integer theLayerId)
1355 if (!myLayerIds.Contains (theLayerId))
1358 // change display layer for structure in all views
1359 if (MyDisplayedStructure.Contains (theStructure))
1361 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1362 for ( ; aViewIt.More (); aViewIt.Next ())
1363 (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
1366 // tell graphic driver to update the structure's display layer
1367 MyGraphicDriver->ChangeZLayer (
1368 (*(Graphic3d_CStructure*)theStructure->CStructure ()), theLayerId);
1371 //=======================================================================
1372 //function : GetZLayer
1374 //=======================================================================
1376 Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
1378 Graphic3d_CStructure& aStructure =
1379 (*(Graphic3d_CStructure*)theStructure->CStructure ());
1381 return MyGraphicDriver->GetZLayer (aStructure);
1384 //=======================================================================
1385 //function : AddZLayer
1387 //=======================================================================
1389 Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
1394 theLayerId = getZLayerGenId ().Next ();
1395 myLayerIds.Add (theLayerId);
1396 myLayerSeq.Append (theLayerId);
1398 catch (Aspect_IdentDefinitionError)
1400 // new index can't be generated
1401 return Standard_False;
1404 // tell all managed views to remove display layers
1405 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1406 for ( ; aViewIt.More (); aViewIt.Next ())
1407 (aViewIt.Value ())->AddZLayer (theLayerId);
1409 return Standard_True;
1412 //=======================================================================
1413 //function : RemoveZLayer
1415 //=======================================================================
1417 Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
1419 if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
1420 return Standard_False;
1422 // tell all managed views to remove display layers
1423 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1424 for ( ; aViewIt.More (); aViewIt.Next ())
1425 (aViewIt.Value ())->RemoveZLayer (theLayerId);
1427 MyGraphicDriver->UnsetZLayer (theLayerId);
1430 for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
1431 if (myLayerSeq(aIdx) == theLayerId)
1433 myLayerSeq.Remove (aIdx);
1437 myLayerIds.Remove (theLayerId);
1438 getZLayerGenId ().Free (theLayerId);
1440 return Standard_True;
1443 //=======================================================================
1444 //function : GetAllZLayers
1446 //=======================================================================
1448 void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
1450 theLayerSeq.Assign (myLayerSeq);
1453 //=======================================================================
1454 //function : getZLayerGenId
1456 //=======================================================================
1458 Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
1460 static Aspect_GenId aGenId (1, IntegerLast());