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
119 cout << "The Manager " << MyId << " have " << Length << " defined views\n";
123 MyDefinedView.Clear ();
127 void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
130 cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
131 << AStructure->Identification ()
132 << ", " << OldPriority << ", " << NewPriority << ")\n";
137 // Change structure priority in all defined views
139 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
141 while (MyIterator.More ()) {
142 (MyIterator.Value ())->ChangeDisplayPriority
143 (AStructure, OldPriority, NewPriority);
145 // MyIterator.Next () is located on the next view
151 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
153 //Standard_Integer LengthD = MyDisplayedStructure.Extent() ();
155 // Even if physically the structure cannot
156 // be displayed (pb of visualisation type)
157 // it has status Displayed.
159 if (!MyDisplayedStructure.Contains(AStructure))
163 // Recompute structure in all activated views
165 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
167 while (MyIterator.More ()) {
168 (MyIterator.Value ())->ReCompute (AStructure);
170 // MyIterator.Next () is located on the next view
176 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
177 const Handle(Graphic3d_DataStructureManager)& AProjector)
180 if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
183 Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
185 Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector;
187 Standard_Integer ViewId = theView->Identification ();
189 // Even if physically the structure cannot
190 // be displayed (pb of visualisation type)
191 // it has status Displayed.
192 if (!MyDisplayedStructure.Contains(AStructure))
196 // Recompute structure in all activated views
198 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
200 while (MyIterator.More ()) {
201 if ((MyIterator.Value ())->Identification () == ViewId)
202 theView->ReCompute (AStructure);
204 // MyIterator.Next () is located on the next view
210 void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
212 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
214 while (MyIterator.More ()) {
215 (MyIterator.Value ())->Clear (AStructure, WithDestruction);
217 // MyIterator.Next () is located on the next view
223 void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
225 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
227 while (MyIterator.More ()) {
228 (MyIterator.Value ())->Connect (AMother, ADaughter);
230 // MyIterator.Next () is located on the next view
236 void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
238 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
240 while (MyIterator.More ()) {
241 (MyIterator.Value ())->Disconnect (AMother, ADaughter);
243 // MyIterator.Next () is located on the next view
249 void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) {
252 // Even if physically the structure cannot
253 // be displayed (pb of visualisation type)
254 // it has status Displayed.
256 MyDisplayedStructure.Add(AStructure);
259 // Display structure in all activated views
261 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
263 while (MyIterator.More ()) {
264 (MyIterator.Value ())->Display (AStructure);
266 // MyIterator.Next () is located on the next view
272 void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) {
275 // Even if physically the structure cannot
276 // be displayed (pb of visualisation type)
277 // it has status Displayed.
279 MyDisplayedStructure.Remove(AStructure);
284 // Erase structure in all defined views
286 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
288 while (MyIterator.More ()) {
289 (MyIterator.Value ())->Erase (AStructure);
291 // MyIterator.Next () is located on the next view
295 MyHighlightedStructure.Remove (AStructure);
296 MyVisibleStructure.Remove (AStructure);
297 MyPickStructure.Remove (AStructure);
301 void Visual3d_ViewManager::Erase () {
303 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
305 for (; it.More(); it.Next()) {
306 Handle(Graphic3d_Structure) SG = it.Key();
312 void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
314 MyHighlightedStructure.Add(AStructure);
317 // Highlight in all activated views
319 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
321 while (MyIterator.More ()) {
322 (MyIterator.Value ())->Highlight (AStructure, AMethod);
324 // MyIterator.Next () is located on the next view
330 void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
332 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
334 while (MyIterator.More ()) {
335 (MyIterator.Value ())->SetTransform (AStructure, ATrsf);
337 // MyIterator.Next () is located on the next view
343 void Visual3d_ViewManager::UnHighlight () {
345 Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
347 for (; it.More(); it.Next()) {
348 Handle(Graphic3d_Structure) SG = it.Key();
355 void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
357 MyHighlightedStructure.Remove(AStructure);
361 // UnHighlight in all activated views
363 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
365 while (MyIterator.More ()) {
366 (MyIterator.Value ())->UnHighlight (AStructure);
368 // MyIterator.Next () is located on the next view
374 void Visual3d_ViewManager::Redraw () const {
376 Standard_Integer MaxDx, MaxDy;
377 Standard_Integer Dx, Dy;
378 MaxDx = MaxDy = IntegerFirst ();
381 // Redraw all activated views
383 Standard_Integer j = MyDefinedView.Extent ();
385 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
387 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) {
388 while (MyIterator.More ()) {
389 (MyIterator.Value ())->Window ()->Size (Dx, Dy);
390 if (Dx > MaxDx) MaxDx = Dx;
391 if (Dy > MaxDy) MaxDy = Dy;
393 // MyIterator.Next () is located on the next view
396 if (! MyUnderLayer.IsNull ())
397 MyUnderLayer->SetViewport (MaxDx, MaxDy);
398 if (! MyOverLayer.IsNull ())
399 MyOverLayer->SetViewport (MaxDx, MaxDy);
402 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ())
403 MyIterator.Initialize (MyDefinedView);
404 while (MyIterator.More ()) {
405 (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer);
407 // MyIterator.Next () is located on the next view
413 void Visual3d_ViewManager::Update () const {
416 // Update all activated views
418 Standard_Integer j = MyDefinedView.Extent ();
420 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
422 while (MyIterator.More ()) {
423 (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer);
425 // MyIterator.Next () is located on the next view
431 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const {
433 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
435 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
437 while (MyIterator.More ()) {
438 if ((MyIterator.Value ())->IsActive ())
439 SG->Add (MyIterator.Value ());
441 // MyIterator.Next () is located on the next view
450 Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const {
452 Standard_Boolean Result = Standard_False;
455 // Check all activated views
457 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
459 Standard_Integer i = MyDefinedView.Extent ();
461 while ((! Result) && (MyIterator.More ())) {
462 if ((MyIterator.Value ())->IsActive ())
464 (MyIterator.Value ())->ContainsComputedStructure ();
466 // MyIterator.Next () is located on the next view
474 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const {
476 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
478 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
480 while (MyIterator.More ()) {
481 SG->Add (MyIterator.Value ());
483 // MyIterator.Next () is located on the next view
491 void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const {
493 // Convert only if the data is correct
494 Standard_Boolean Exist;
495 Graphic3d_CView TheCView;
496 //Graphic3d_Vertex Point;
498 TColStd_Array2OfReal Ori_Matrix (0,3,0,3);
499 TColStd_Array2OfReal Map_Matrix (0,3,0,3);
501 Standard_Integer Width, Height;
502 Standard_Real AX, AY, AZ;
503 Standard_Real Dx, Dy, Ratio;
505 Exist = ViewExists (AWindow, TheCView);
508 AU = AV = IntegerLast ();
511 // NKV - 11.02.08 - Use graphic driver functions
512 Standard_Boolean Result;
514 AVertex.Coord (AX, AY, AZ);
516 Result = MyGraphicDriver->ProjectRaster (TheCView,
517 Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ),
523 Standard_Real PtX, PtY, PtZ, PtT;
524 Standard_Real APX, APY, APZ;
527 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
529 Standard_Integer stop = 0;
531 while ((! stop) && (MyIterator.More ())) {
532 if (TheCView.ViewId ==
533 (MyIterator.Value ())->Identification ()) {
535 (MyIterator.Value ())->MatrixOfOrientation ();
537 (MyIterator.Value ())->MatrixOfMapping ();
541 // MyIterator.Next () is located on the next view
546 // WCS -> View Reference Coordinate Space
547 PtX = Ori_Matrix (0, 0) * AX
548 + Ori_Matrix (0, 1) * AY
549 + Ori_Matrix (0, 2) * AZ
551 PtY = Ori_Matrix (1, 0) * AX
552 + Ori_Matrix (1, 1) * AY
553 + Ori_Matrix (1, 2) * AZ
555 PtZ = Ori_Matrix (2, 0) * AX
556 + Ori_Matrix (2, 1) * AY
557 + Ori_Matrix (2, 2) * AZ
559 PtT = Ori_Matrix (3, 0) * AX
560 + Ori_Matrix (3, 1) * AY
561 + Ori_Matrix (3, 2) * AZ
564 // VRCS -> Normalized Projection Coordinate Space
565 APX = Map_Matrix (0, 0) * PtX
566 + Map_Matrix (0, 1) * PtY
567 + Map_Matrix (0, 2) * PtZ
568 + Map_Matrix (0, 3) * PtT;
569 APY = Map_Matrix (1, 0) * PtX
570 + Map_Matrix (1, 1) * PtY
571 + Map_Matrix (1, 2) * PtZ
572 + Map_Matrix (1, 3) * PtT;
573 APZ = Map_Matrix (2, 0) * PtX
574 + Map_Matrix (2, 1) * PtY
575 + Map_Matrix (2, 2) * PtZ
576 + Map_Matrix (2, 3) * PtT;
577 APT = Map_Matrix (3, 0) * PtX
578 + Map_Matrix (3, 1) * PtY
579 + Map_Matrix (3, 2) * PtZ
580 + Map_Matrix (3, 3) * PtT;
582 if (APT == 0. || stop == 0) {
583 AU = AV = IntegerLast ();
590 // NPCS -> Device Coordinate Space
591 AWindow->Size (Width, Height);
592 Dx = Standard_Real (Width);
593 Dy = Standard_Real (Height);
596 AU = Standard_Integer (APX * Dx);
597 AV = Standard_Integer (Dy - APY * Dy * Ratio);
600 AU = Standard_Integer (APX * Dx / Ratio);
601 AV = Standard_Integer (Dy - APY * Dy);
609 Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const {
611 // Convert only if the data is correct
612 Graphic3d_CView TheCView;
613 Graphic3d_Vertex Point;
615 if (! ViewExists (AWindow, TheCView))
616 Point.SetCoord (RealLast (), RealLast (), RealLast ());
618 Standard_Integer Width, Height;
619 Standard_ShortReal x, y, z;
620 Standard_Boolean Result;
622 AWindow->Size (Width, Height);
624 Result = MyGraphicDriver->UnProjectRaster (TheCView,
628 // unproject is done by UnProjectRaster
631 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
633 // unproject cannot be done by UnProjectRaster
634 // Code suspended since drivers Phigs and Pex are abandoned.
637 Standard_Real NPCX, NPCY, NPCZ;
638 Standard_Real VRCX, VRCY, VRCZ, VRCT;
639 Standard_Real WCX, WCY, WCZ, WCT;
641 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
642 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
643 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
644 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
646 Standard_Real Dx, Dy, Ratio;
647 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
650 Standard_Integer stop = 0;
652 Standard_Boolean BResult;
654 j = MyDefinedView.Extent ();
656 while ((! stop) && (MyIterator.More ())) {
657 if (TheCView.ViewId ==
658 (MyIterator.Value ())->Identification ()) {
660 (MyIterator.Value ())->MatrixOfOrientation ();
662 (MyIterator.Value ())->MatrixOfMapping ();
666 // MyIterator.Next () is located on the next view
670 // View Mapping Transformation and View Clip, inversion
671 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
673 // View Orientation Transformation, inversion
674 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
676 // (AU, AV) : Device Coordinate Space
677 // DCS -> NPCS Normalized Projection Coordinate Space
678 Dx = Standard_Real (Width);
679 Dy = Standard_Real (Height);
683 NPCX = Standard_Real (AU) / Dx;
684 NPCY = (Dy - Standard_Real (AV)) / Dx;
687 NPCX = Standard_Real (AU) / Dy;
688 NPCY = (Dy - Standard_Real (AV)) / Dy;
692 // NPCS -> VRCS View Reference Coordinate Space
693 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
695 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
696 + TMap_Matrix_Inv (0, 1) * NPCY
697 + TMap_Matrix_Inv (0, 2) * NPCZ
698 + TMap_Matrix_Inv (0, 3);
699 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
700 + TMap_Matrix_Inv (1, 1) * NPCY
701 + TMap_Matrix_Inv (1, 2) * NPCZ
702 + TMap_Matrix_Inv (1, 3);
703 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
704 + TMap_Matrix_Inv (2, 1) * NPCY
705 + TMap_Matrix_Inv (2, 2) * NPCZ
706 + TMap_Matrix_Inv (2, 3);
707 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
708 + TMap_Matrix_Inv (3, 1) * NPCY
709 + TMap_Matrix_Inv (3, 2) * NPCZ
710 + TMap_Matrix_Inv (3, 3);
712 // VRCS -> WCS World Coordinate Space
713 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
715 WCX = TOri_Matrix_Inv (0, 0) * VRCX
716 + TOri_Matrix_Inv (0, 1) * VRCY
717 + TOri_Matrix_Inv (0, 2) * VRCZ
718 + TOri_Matrix_Inv (0, 3) * VRCT;
719 WCY = TOri_Matrix_Inv (1, 0) * VRCX
720 + TOri_Matrix_Inv (1, 1) * VRCY
721 + TOri_Matrix_Inv (1, 2) * VRCZ
722 + TOri_Matrix_Inv (1, 3) * VRCT;
723 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
724 + TOri_Matrix_Inv (2, 1) * VRCY
725 + TOri_Matrix_Inv (2, 2) * VRCZ
726 + TOri_Matrix_Inv (2, 3) * VRCT;
727 WCT = TOri_Matrix_Inv (3, 0) * VRCX
728 + TOri_Matrix_Inv (3, 1) * VRCY
729 + TOri_Matrix_Inv (3, 2) * VRCZ
730 + TOri_Matrix_Inv (3, 3) * VRCT;
733 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
735 Point.SetCoord (RealLast (), RealLast (), RealLast ());
743 void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {
745 // Conversion only if the data is correct
746 Graphic3d_CView TheCView;
748 if (! ViewExists (AWindow, TheCView)) {
749 Point.SetCoord (RealLast (), RealLast (), RealLast ());
750 Proj.SetCoord (0., 0., 0.);
753 Standard_Integer Width, Height;
754 Standard_ShortReal x, y, z;
755 Standard_ShortReal dx, dy, dz;
756 Standard_Boolean Result;
758 AWindow->Size (Width, Height);
760 Result = MyGraphicDriver->UnProjectRasterWithRay (TheCView,
762 AU, AV, x, y, z, dx, dy, dz);
764 // unproject is done by UnProjectRaster
767 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
769 (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
772 // unproject cannot be done by UnProjectRaster
773 // Code is suspended since drivers Phigs are Pex abandoned.
776 Standard_Real NPCX, NPCY, NPCZ;
777 Standard_Real VRCX, VRCY, VRCZ, VRCT;
778 Standard_Real WCX, WCY, WCZ, WCT;
780 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
781 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
782 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
783 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
785 Standard_Real Dx, Dy, Ratio;
786 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
789 Standard_Integer stop = 0;
791 Standard_Boolean BResult;
793 j = MyDefinedView.Extent ();
795 while ((! stop) && (MyIterator.More ())) {
796 if (TheCView.ViewId ==
797 (MyIterator.Value ())->Identification ()) {
799 (MyIterator.Value ())->MatrixOfOrientation ();
801 (MyIterator.Value ())->MatrixOfMapping ();
805 // MyIterator.Next () is located on the next view
809 // View Mapping Transformation and View Clip, inversion
810 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
812 // View Orientation Transformation, inversion
813 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
815 // (AU, AV) : Device Coordinate Space
816 // DCS -> NPCS Normalized Projection Coordinate Space
817 Dx = Standard_Real (Width);
818 Dy = Standard_Real (Height);
822 NPCX = Standard_Real (AU) / Dx;
823 NPCY = (Dy - Standard_Real (AV)) / Dx;
826 NPCX = Standard_Real (AU) / Dy;
827 NPCY = (Dy - Standard_Real (AV)) / Dy;
831 // NPCS -> VRCS View Reference Coordinate Space
832 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
834 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
835 + TMap_Matrix_Inv (0, 1) * NPCY
836 + TMap_Matrix_Inv (0, 2) * NPCZ
837 + TMap_Matrix_Inv (0, 3);
838 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
839 + TMap_Matrix_Inv (1, 1) * NPCY
840 + TMap_Matrix_Inv (1, 2) * NPCZ
841 + TMap_Matrix_Inv (1, 3);
842 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
843 + TMap_Matrix_Inv (2, 1) * NPCY
844 + TMap_Matrix_Inv (2, 2) * NPCZ
845 + TMap_Matrix_Inv (2, 3);
846 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
847 + TMap_Matrix_Inv (3, 1) * NPCY
848 + TMap_Matrix_Inv (3, 2) * NPCZ
849 + TMap_Matrix_Inv (3, 3);
851 // VRCS -> WCS World Coordinate Space
852 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
854 WCX = TOri_Matrix_Inv (0, 0) * VRCX
855 + TOri_Matrix_Inv (0, 1) * VRCY
856 + TOri_Matrix_Inv (0, 2) * VRCZ
857 + TOri_Matrix_Inv (0, 3) * VRCT;
858 WCY = TOri_Matrix_Inv (1, 0) * VRCX
859 + TOri_Matrix_Inv (1, 1) * VRCY
860 + TOri_Matrix_Inv (1, 2) * VRCZ
861 + TOri_Matrix_Inv (1, 3) * VRCT;
862 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
863 + TOri_Matrix_Inv (2, 1) * VRCY
864 + TOri_Matrix_Inv (2, 2) * VRCZ
865 + TOri_Matrix_Inv (2, 3) * VRCT;
866 WCT = TOri_Matrix_Inv (3, 0) * VRCX
867 + TOri_Matrix_Inv (3, 1) * VRCY
868 + TOri_Matrix_Inv (3, 2) * VRCZ
869 + TOri_Matrix_Inv (3, 3) * VRCT;
872 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
874 Point.SetCoord (RealLast (), RealLast (), RealLast ());
876 // Define projection ray
879 // NPCS -> VRCS View Reference Coordinate Space
880 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
882 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
883 + TMap_Matrix_Inv (0, 1) * NPCY
884 + TMap_Matrix_Inv (0, 2) * NPCZ
885 + TMap_Matrix_Inv (0, 3);
886 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
887 + TMap_Matrix_Inv (1, 1) * NPCY
888 + TMap_Matrix_Inv (1, 2) * NPCZ
889 + TMap_Matrix_Inv (1, 3);
890 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
891 + TMap_Matrix_Inv (2, 1) * NPCY
892 + TMap_Matrix_Inv (2, 2) * NPCZ
893 + TMap_Matrix_Inv (2, 3);
894 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
895 + TMap_Matrix_Inv (3, 1) * NPCY
896 + TMap_Matrix_Inv (3, 2) * NPCZ
897 + TMap_Matrix_Inv (3, 3);
899 // VRCS -> WCS World Coordinate Space
900 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
902 WCX = TOri_Matrix_Inv (0, 0) * VRCX
903 + TOri_Matrix_Inv (0, 1) * VRCY
904 + TOri_Matrix_Inv (0, 2) * VRCZ
905 + TOri_Matrix_Inv (0, 3) * VRCT;
906 WCY = TOri_Matrix_Inv (1, 0) * VRCX
907 + TOri_Matrix_Inv (1, 1) * VRCY
908 + TOri_Matrix_Inv (1, 2) * VRCZ
909 + TOri_Matrix_Inv (1, 3) * VRCT;
910 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
911 + TOri_Matrix_Inv (2, 1) * VRCY
912 + TOri_Matrix_Inv (2, 2) * VRCZ
913 + TOri_Matrix_Inv (2, 3) * VRCT;
914 WCT = TOri_Matrix_Inv (3, 0) * VRCX
915 + TOri_Matrix_Inv (3, 1) * VRCY
916 + TOri_Matrix_Inv (3, 2) * VRCZ
917 + TOri_Matrix_Inv (3, 3) * VRCT;
920 Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
924 Proj.SetCoord (0., 0., 0.);
931 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
933 Standard_Boolean Exist = Standard_False;
935 // Parse the list of views to find
936 // a view with the specified window
937 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
938 int TheWindowIdOfView;
941 const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
942 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
944 const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
945 int TheSpecifiedWindowId = int (THEWindow->HWindow ());
948 while ((! Exist) && (MyIterator.More ())) {
950 if ( ((MyIterator.Value ())->IsDefined ()) &&
951 ((MyIterator.Value ())->IsActive ()) ) {
953 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
955 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
956 TheWindowIdOfView = int (theWindow->XWindow ());
958 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
959 TheWindowIdOfView = int (theWindow->HWindow ());
961 // Comparaison on window IDs
962 if (TheWindowIdOfView == TheSpecifiedWindowId) {
963 Exist = Standard_True;
964 TheCView = *(CALL_DEF_VIEW *)(MyIterator.Value ())->CView ();
966 } /* if ((MyIterator.Value ())->IsDefined ()) */
968 // MyIterator.Next () is located on the next view
976 void Visual3d_ViewManager::Activate () {
979 // Activates all deactivated views
981 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
983 while (MyIterator.More ()) {
984 if (! (MyIterator.Value ())->IsActive ())
985 (MyIterator.Value ())->Activate ();
987 // MyIterator.Next () is located on the next view
993 void Visual3d_ViewManager::Deactivate () {
996 // Deactivates all activated views
998 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1000 while (MyIterator.More ()) {
1001 if ((MyIterator.Value ())->IsActive ())
1002 (MyIterator.Value ())->Deactivate ();
1004 // MyIterator.Next () is located on the next view
1010 Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
1012 // Retourne the planned of definable views for the current
1013 // Visual3d_ViewManager.
1015 (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
1019 Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
1021 return (Graphic3d_StructureManager::Identification (AId));
1025 Standard_Integer Visual3d_ViewManager::Identification () const {
1027 return (Graphic3d_StructureManager::Identification ());
1031 Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {
1033 MyDefinedView.Add (AView);
1034 return (MyViewGenId.Next ());
1038 void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
1040 MyViewGenId.Free(aViewId);
1043 void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
1045 if (MyTransparency && AFlag) return;
1046 if (! MyTransparency && ! AFlag) return;
1048 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1049 while (MyIterator.More ()) {
1050 (MyIterator.Value ())->SetTransparency (AFlag);
1051 // MyIterator.Next () is located on the next view
1055 MyTransparency = AFlag;
1059 Standard_Boolean Visual3d_ViewManager::Transparency () const {
1061 return (MyTransparency);
1065 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
1067 if (MyZBufferAuto && AFlag) return;
1068 if (! MyZBufferAuto && ! AFlag) return;
1070 // if pass from False to True :
1071 // no problem, at the next view update, it
1072 // will properly ask questions to answer (SetVisualisation)
1073 // if pass from True to False :
1074 // it is necessary to modify ZBufferActivity at each view so that
1075 // zbuffer could be active only if required by context.
1076 // In this case -1 is passed so that the view ask itself the question
1077 // Note : 0 forces the desactivation, 1 forces the activation
1079 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1080 while (MyIterator.More ()) {
1081 (MyIterator.Value ())->SetZBufferActivity (-1);
1082 // MyIterator.Next () is located on the next view
1086 MyZBufferAuto = AFlag;
1090 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
1092 return (MyZBufferAuto);
1096 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
1099 cout << "Visual3d_ViewManager::SetLayer\n" << flush;
1102 if (ALayer->Type () == Aspect_TOL_OVERLAY) {
1104 if (MyOverLayer.IsNull ())
1105 cout << "MyOverLayer is defined" << endl;
1107 cout << "MyOverLayer is redefined" << endl;
1109 MyOverLayer = ALayer;
1113 if (MyUnderLayer.IsNull ())
1114 cout << "MyUnderLayer is defined" << endl;
1116 cout << "MyUnderLayer is redefined" << endl;
1118 MyUnderLayer = ALayer;
1123 const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
1125 return (MyUnderLayer);
1129 const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
1131 return (MyOverLayer);
1135 //=======================================================================
1136 //function : ChangeZLayer
1138 //=======================================================================
1140 void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1141 const Standard_Integer theLayerId)
1143 if (!myLayerIds.Contains (theLayerId))
1146 // change display layer for structure in all views
1147 if (MyDisplayedStructure.Contains (theStructure))
1149 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1150 for ( ; aViewIt.More (); aViewIt.Next ())
1151 (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
1154 // tell graphic driver to update the structure's display layer
1155 MyGraphicDriver->ChangeZLayer (
1156 (*(Graphic3d_CStructure*)theStructure->CStructure ()), theLayerId);
1159 //=======================================================================
1160 //function : GetZLayer
1162 //=======================================================================
1164 Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
1166 Graphic3d_CStructure& aStructure =
1167 (*(Graphic3d_CStructure*)theStructure->CStructure ());
1169 return MyGraphicDriver->GetZLayer (aStructure);
1172 //=======================================================================
1173 //function : AddZLayer
1175 //=======================================================================
1177 Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
1182 theLayerId = getZLayerGenId ().Next ();
1183 myLayerIds.Add (theLayerId);
1184 myLayerSeq.Append (theLayerId);
1186 catch (Aspect_IdentDefinitionError)
1188 // new index can't be generated
1189 return Standard_False;
1192 // tell all managed views to remove display layers
1193 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1194 for ( ; aViewIt.More (); aViewIt.Next ())
1195 (aViewIt.Value ())->AddZLayer (theLayerId);
1197 return Standard_True;
1200 //=======================================================================
1201 //function : RemoveZLayer
1203 //=======================================================================
1205 Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
1207 if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
1208 return Standard_False;
1210 // tell all managed views to remove display layers
1211 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1212 for ( ; aViewIt.More (); aViewIt.Next ())
1213 (aViewIt.Value ())->RemoveZLayer (theLayerId);
1215 MyGraphicDriver->UnsetZLayer (theLayerId);
1218 for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
1219 if (myLayerSeq(aIdx) == theLayerId)
1221 myLayerSeq.Remove (aIdx);
1225 myLayerIds.Remove (theLayerId);
1226 getZLayerGenId ().Free (theLayerId);
1228 return Standard_True;
1231 //=======================================================================
1232 //function : GetAllZLayers
1234 //=======================================================================
1236 void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
1238 theLayerSeq.Assign (myLayerSeq);
1241 //=======================================================================
1242 //function : getZLayerGenId
1244 //=======================================================================
1246 Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
1248 static Aspect_GenId aGenId (1, IntegerLast());