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.);
988 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
990 Standard_Boolean Exist = Standard_False;
992 // Parse the list of views to find
993 // a view with the specified window
994 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
995 int TheWindowIdOfView;
998 const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
999 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
1001 const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
1002 int TheSpecifiedWindowId = int (THEWindow->HWindow ());
1005 while ((! Exist) && (MyIterator.More ())) {
1007 if ( ((MyIterator.Value ())->IsDefined ()) &&
1008 ((MyIterator.Value ())->IsActive ()) ) {
1010 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
1012 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
1013 TheWindowIdOfView = int (theWindow->XWindow ());
1015 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
1016 TheWindowIdOfView = int (theWindow->HWindow ());
1018 // Comparaison on window IDs
1019 if (TheWindowIdOfView == TheSpecifiedWindowId) {
1020 Exist = Standard_True;
1021 TheCView = *(CALL_DEF_VIEW *)(MyIterator.Value ())->CView ();
1023 } /* if ((MyIterator.Value ())->IsDefined ()) */
1025 // MyIterator.Next () is located on the next view
1033 void Visual3d_ViewManager::Activate () {
1036 // Activates all deactivated views
1038 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1041 Standard_Integer Length = MyDefinedView.Extent ();
1043 MyDefinedView.Extent ();
1046 while (MyIterator.More ()) {
1047 if (! (MyIterator.Value ())->IsActive ())
1048 (MyIterator.Value ())->Activate ();
1050 // MyIterator.Next () is located on the next view
1056 void Visual3d_ViewManager::Deactivate () {
1059 // Deactivates all activated views
1062 Standard_Integer Length = MyDefinedView.Extent ();
1064 MyDefinedView.Extent ();
1066 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1068 while (MyIterator.More ()) {
1069 if ((MyIterator.Value ())->IsActive ())
1070 (MyIterator.Value ())->Deactivate ();
1072 // MyIterator.Next () is located on the next view
1078 Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
1080 // Retourne the planned of definable views for the current
1081 // Visual3d_ViewManager.
1083 (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
1087 Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
1089 return (Graphic3d_StructureManager::Identification (AId));
1093 Standard_Integer Visual3d_ViewManager::Identification () const {
1095 return (Graphic3d_StructureManager::Identification ());
1099 Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {
1101 MyDefinedView.Add (AView);
1102 return (MyViewGenId.Next ());
1106 void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
1108 MyViewGenId.Free(aViewId);
1111 void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
1113 if (MyTransparency && AFlag) return;
1114 if (! MyTransparency && ! AFlag) return;
1116 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1117 while (MyIterator.More ()) {
1118 (MyIterator.Value ())->SetTransparency (AFlag);
1119 // MyIterator.Next () is located on the next view
1123 MyTransparency = AFlag;
1127 Standard_Boolean Visual3d_ViewManager::Transparency () const {
1129 return (MyTransparency);
1133 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
1135 if (MyZBufferAuto && AFlag) return;
1136 if (! MyZBufferAuto && ! AFlag) return;
1138 // if pass from False to True :
1139 // no problem, at the next view update, it
1140 // will properly ask questions to answer (SetVisualisation)
1141 // if pass from True to False :
1142 // it is necessary to modify ZBufferActivity at each view so that
1143 // zbuffer could be active only if required by context.
1144 // In this case -1 is passed so that the view ask itself the question
1145 // Note : 0 forces the desactivation, 1 forces the activation
1147 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1148 while (MyIterator.More ()) {
1149 (MyIterator.Value ())->SetZBufferActivity (-1);
1150 // MyIterator.Next () is located on the next view
1154 MyZBufferAuto = AFlag;
1158 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
1160 return (MyZBufferAuto);
1164 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
1167 cout << "Visual3d_ViewManager::SetLayer\n" << flush;
1170 if (ALayer->Type () == Aspect_TOL_OVERLAY) {
1172 if (MyOverLayer.IsNull ())
1173 cout << "MyOverLayer is defined" << endl;
1175 cout << "MyOverLayer is redefined" << endl;
1177 MyOverLayer = ALayer;
1181 if (MyUnderLayer.IsNull ())
1182 cout << "MyUnderLayer is defined" << endl;
1184 cout << "MyUnderLayer is redefined" << endl;
1186 MyUnderLayer = ALayer;
1191 const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
1193 return (MyUnderLayer);
1197 const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
1199 return (MyOverLayer);
1203 //=======================================================================
1204 //function : ChangeZLayer
1206 //=======================================================================
1208 void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1209 const Standard_Integer theLayerId)
1211 if (!myLayerIds.Contains (theLayerId))
1214 // change display layer for structure in all views
1215 if (MyDisplayedStructure.Contains (theStructure))
1217 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1218 for ( ; aViewIt.More (); aViewIt.Next ())
1219 (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
1222 // tell graphic driver to update the structure's display layer
1223 MyGraphicDriver->ChangeZLayer (
1224 (*(Graphic3d_CStructure*)theStructure->CStructure ()), theLayerId);
1227 //=======================================================================
1228 //function : GetZLayer
1230 //=======================================================================
1232 Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
1234 Graphic3d_CStructure& aStructure =
1235 (*(Graphic3d_CStructure*)theStructure->CStructure ());
1237 return MyGraphicDriver->GetZLayer (aStructure);
1240 //=======================================================================
1241 //function : AddZLayer
1243 //=======================================================================
1245 Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
1250 theLayerId = getZLayerGenId ().Next ();
1251 myLayerIds.Add (theLayerId);
1252 myLayerSeq.Append (theLayerId);
1254 catch (Aspect_IdentDefinitionError)
1256 // new index can't be generated
1257 return Standard_False;
1260 // tell all managed views to remove display layers
1261 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1262 for ( ; aViewIt.More (); aViewIt.Next ())
1263 (aViewIt.Value ())->AddZLayer (theLayerId);
1265 return Standard_True;
1268 //=======================================================================
1269 //function : RemoveZLayer
1271 //=======================================================================
1273 Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
1275 if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
1276 return Standard_False;
1278 // tell all managed views to remove display layers
1279 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1280 for ( ; aViewIt.More (); aViewIt.Next ())
1281 (aViewIt.Value ())->RemoveZLayer (theLayerId);
1283 MyGraphicDriver->UnsetZLayer (theLayerId);
1286 for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
1287 if (myLayerSeq(aIdx) == theLayerId)
1289 myLayerSeq.Remove (aIdx);
1293 myLayerIds.Remove (theLayerId);
1294 getZLayerGenId ().Free (theLayerId);
1296 return Standard_True;
1299 //=======================================================================
1300 //function : GetAllZLayers
1302 //=======================================================================
1304 void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
1306 theLayerSeq.Assign (myLayerSeq);
1309 //=======================================================================
1310 //function : getZLayerGenId
1312 //=======================================================================
1314 Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
1316 static Aspect_GenId aGenId (1, IntegerLast());