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>
52 #include <Graphic3d_GraphicDriver.hxx>
53 #include <Graphic3d_MapOfStructure.hxx>
54 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
56 #include <Visual3d_PickPath.hxx>
57 #include <Visual3d_SetIteratorOfSetOfView.hxx>
60 # include <Xw_Window.hxx>
62 # include <WNT_Window.hxx>
67 //-Global data definitions
69 // -- les vues definies
70 // MyDefinedView : SetOfView;
72 // -- le generateur d'identificateurs de vues
73 // MyViewGenId : GenId;
77 Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Aspect_GraphicDevice)& aDevice):
78 Graphic3d_StructureManager (aDevice),
80 MyViewGenId (View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit ()))*(Visual3d_ViewManager::CurrentId ()-1),View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit ()))*Visual3d_ViewManager::CurrentId ()-1),
81 MyZBufferAuto (Standard_False),
82 MyTransparency (Standard_False)
85 Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver ();
87 MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
93 void Visual3d_ViewManager::Destroy () {
96 cout << "Visual3d_ViewManager::Destroy (" << MyId << ")\n" << flush;
104 void Visual3d_ViewManager::Remove () {
107 cout << "Visual3d_ViewManager::Remove (" << MyId << ")\n" << flush;
111 // Destroy all defined views
114 Standard_Integer Length = MyDefinedView.Extent ();
116 MyDefinedView.Extent ();
120 cout << "The Manager " << MyId << " have " << Length << " defined views\n";
124 MyDefinedView.Clear ();
128 void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
131 cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
132 << AStructure->Identification ()
133 << ", " << OldPriority << ", " << NewPriority << ")\n";
138 // Change structure priority in all defined views
141 Standard_Integer Length = MyDefinedView.Extent ();
143 MyDefinedView.Extent ();
145 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
147 while (MyIterator.More ()) {
148 (MyIterator.Value ())->ChangeDisplayPriority
149 (AStructure, OldPriority, NewPriority);
151 // MyIterator.Next () is located on the next view
157 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
159 //Standard_Integer LengthD = MyDisplayedStructure.Extent() ();
161 // Even if physically the structure cannot
162 // be displayed (pb of visualisation type)
163 // it has status Displayed.
165 if (!MyDisplayedStructure.Contains(AStructure))
169 // Recompute structure in all activated views
171 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
173 while (MyIterator.More ()) {
174 (MyIterator.Value ())->ReCompute (AStructure);
176 // MyIterator.Next () is located on the next view
182 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
183 const Handle(Graphic3d_DataStructureManager)& AProjector)
186 if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
189 Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
191 Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector;
193 Standard_Integer ViewId = theView->Identification ();
195 Standard_Integer indexD = 0;
197 // Even if physically the structure cannot
198 // be displayed (pb of visualisation type)
199 // it has status Displayed.
200 if (!MyDisplayedStructure.Contains(AStructure))
204 // Recompute structure in all activated views
206 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
208 while (MyIterator.More ()) {
209 if ((MyIterator.Value ())->Identification () == ViewId)
210 theView->ReCompute (AStructure);
212 // MyIterator.Next () is located on the next view
218 void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
221 Standard_Integer Length = MyDefinedView.Extent ();
223 MyDefinedView.Extent ();
225 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
227 while (MyIterator.More ()) {
228 (MyIterator.Value ())->Clear (AStructure, WithDestruction);
230 // MyIterator.Next () is located on the next view
236 void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
239 Standard_Integer Length = MyDefinedView.Extent ();
241 MyDefinedView.Extent ();
243 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
245 while (MyIterator.More ()) {
246 (MyIterator.Value ())->Connect (AMother, ADaughter);
248 // MyIterator.Next () is located on the next view
254 void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
257 Standard_Integer Length = MyDefinedView.Extent ();
259 MyDefinedView.Extent ();
261 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
263 while (MyIterator.More ()) {
264 (MyIterator.Value ())->Disconnect (AMother, ADaughter);
266 // MyIterator.Next () is located on the next view
272 void Visual3d_ViewManager::Display (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.Add(AStructure);
282 // Display structure in all activated views
284 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
286 while (MyIterator.More ()) {
287 (MyIterator.Value ())->Display (AStructure);
289 // MyIterator.Next () is located on the next view
295 void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) {
298 // Even if physically the structure cannot
299 // be displayed (pb of visualisation type)
300 // it has status Displayed.
302 MyDisplayedStructure.Remove(AStructure);
307 // Erase structure in all defined views
310 Standard_Integer Length = MyDefinedView.Extent ();
312 MyDefinedView.Extent ();
314 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
316 while (MyIterator.More ()) {
317 (MyIterator.Value ())->Erase (AStructure);
319 // MyIterator.Next () is located on the next view
323 MyHighlightedStructure.Remove (AStructure);
324 MyVisibleStructure.Remove (AStructure);
325 MyPickStructure.Remove (AStructure);
329 void Visual3d_ViewManager::Erase () {
331 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
333 for (; it.More(); it.Next()) {
334 Handle(Graphic3d_Structure) SG = it.Key();
340 void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
342 MyHighlightedStructure.Add(AStructure);
345 // Highlight in all activated views
348 Standard_Integer Length = MyDefinedView.Extent ();
350 MyDefinedView.Extent ();
352 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
354 while (MyIterator.More ()) {
355 (MyIterator.Value ())->Highlight (AStructure, AMethod);
357 // MyIterator.Next () is located on the next view
363 void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
366 Standard_Integer Length = MyDefinedView.Extent ();
368 MyDefinedView.Extent ();
370 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
372 while (MyIterator.More ()) {
373 (MyIterator.Value ())->SetTransform (AStructure, ATrsf);
375 // MyIterator.Next () is located on the next view
381 void Visual3d_ViewManager::UnHighlight () {
383 Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
385 for (; it.More(); it.Next()) {
386 Handle(Graphic3d_Structure) SG = it.Key();
393 void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
395 MyHighlightedStructure.Remove(AStructure);
399 // UnHighlight in all activated views
402 Standard_Integer Length = MyDefinedView.Extent ();
404 MyDefinedView.Extent ();
406 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
408 while (MyIterator.More ()) {
409 (MyIterator.Value ())->UnHighlight (AStructure);
411 // MyIterator.Next () is located on the next view
417 void Visual3d_ViewManager::Redraw () const {
419 Standard_Integer MaxDx, MaxDy;
420 Standard_Integer Dx, Dy;
421 MaxDx = MaxDy = IntegerFirst ();
424 // Redraw all activated views
426 Standard_Integer j = MyDefinedView.Extent ();
428 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
430 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) {
431 while (MyIterator.More ()) {
432 (MyIterator.Value ())->Window ()->Size (Dx, Dy);
433 if (Dx > MaxDx) MaxDx = Dx;
434 if (Dy > MaxDy) MaxDy = Dy;
436 // MyIterator.Next () is located on the next view
439 if (! MyUnderLayer.IsNull ())
440 MyUnderLayer->SetViewport (MaxDx, MaxDy);
441 if (! MyOverLayer.IsNull ())
442 MyOverLayer->SetViewport (MaxDx, MaxDy);
445 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ())
446 MyIterator.Initialize (MyDefinedView);
447 while (MyIterator.More ()) {
448 (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer);
450 // MyIterator.Next () is located on the next view
456 void Visual3d_ViewManager::Update () const {
459 // Update all activated views
461 Standard_Integer j = MyDefinedView.Extent ();
463 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
465 while (MyIterator.More ()) {
466 (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer);
468 // MyIterator.Next () is located on the next view
474 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const {
476 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
479 Standard_Integer Length = MyDefinedView.Extent ();
481 MyDefinedView.Extent ();
483 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
485 while (MyIterator.More ()) {
486 if ((MyIterator.Value ())->IsActive ())
487 SG->Add (MyIterator.Value ());
489 // MyIterator.Next () is located on the next view
498 Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const {
500 Standard_Boolean Result = Standard_False;
503 // Check all activated views
505 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
507 Standard_Integer i = MyDefinedView.Extent ();
509 while ((! Result) && (MyIterator.More ())) {
510 if ((MyIterator.Value ())->IsActive ())
512 (MyIterator.Value ())->ContainsComputedStructure ();
514 // MyIterator.Next () is located on the next view
522 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const {
524 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
526 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
528 while (MyIterator.More ()) {
529 SG->Add (MyIterator.Value ());
531 // MyIterator.Next () is located on the next view
539 void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const {
541 // Convert only if the data is correct
542 Standard_Boolean Exist;
543 Graphic3d_CView TheCView;
544 //Graphic3d_Vertex Point;
546 TColStd_Array2OfReal Ori_Matrix (0,3,0,3);
547 TColStd_Array2OfReal Map_Matrix (0,3,0,3);
549 Standard_Integer Width, Height;
550 Standard_Real AX, AY, AZ;
551 Standard_Real Dx, Dy, Ratio;
553 Exist = ViewExists (AWindow, TheCView);
556 AU = AV = IntegerLast ();
559 // NKV - 11.02.08 - Use graphic driver functions
560 Standard_Boolean Result;
562 AVertex.Coord (AX, AY, AZ);
564 Result = MyGraphicDriver->ProjectRaster (TheCView,
565 Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ),
571 Standard_Real PtX, PtY, PtZ, PtT;
572 Standard_Real APX, APY, APZ;
575 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
577 Standard_Integer Length = MyDefinedView.Extent ();
579 MyDefinedView.Extent ();
582 Standard_Integer stop = 0;
584 while ((! stop) && (MyIterator.More ())) {
585 if (TheCView.ViewId ==
586 (MyIterator.Value ())->Identification ()) {
588 (MyIterator.Value ())->MatrixOfOrientation ();
590 (MyIterator.Value ())->MatrixOfMapping ();
594 // MyIterator.Next () is located on the next view
599 // WCS -> View Reference Coordinate Space
600 PtX = Ori_Matrix (0, 0) * AX
601 + Ori_Matrix (0, 1) * AY
602 + Ori_Matrix (0, 2) * AZ
604 PtY = Ori_Matrix (1, 0) * AX
605 + Ori_Matrix (1, 1) * AY
606 + Ori_Matrix (1, 2) * AZ
608 PtZ = Ori_Matrix (2, 0) * AX
609 + Ori_Matrix (2, 1) * AY
610 + Ori_Matrix (2, 2) * AZ
612 PtT = Ori_Matrix (3, 0) * AX
613 + Ori_Matrix (3, 1) * AY
614 + Ori_Matrix (3, 2) * AZ
617 // VRCS -> Normalized Projection Coordinate Space
618 APX = Map_Matrix (0, 0) * PtX
619 + Map_Matrix (0, 1) * PtY
620 + Map_Matrix (0, 2) * PtZ
621 + Map_Matrix (0, 3) * PtT;
622 APY = Map_Matrix (1, 0) * PtX
623 + Map_Matrix (1, 1) * PtY
624 + Map_Matrix (1, 2) * PtZ
625 + Map_Matrix (1, 3) * PtT;
626 APZ = Map_Matrix (2, 0) * PtX
627 + Map_Matrix (2, 1) * PtY
628 + Map_Matrix (2, 2) * PtZ
629 + Map_Matrix (2, 3) * PtT;
630 APT = Map_Matrix (3, 0) * PtX
631 + Map_Matrix (3, 1) * PtY
632 + Map_Matrix (3, 2) * PtZ
633 + Map_Matrix (3, 3) * PtT;
635 if (APT == 0. || stop == 0) {
636 AU = AV = IntegerLast ();
643 // NPCS -> Device Coordinate Space
644 AWindow->Size (Width, Height);
645 Dx = Standard_Real (Width);
646 Dy = Standard_Real (Height);
649 AU = Standard_Integer (APX * Dx);
650 AV = Standard_Integer (Dy - APY * Dy * Ratio);
653 AU = Standard_Integer (APX * Dx / Ratio);
654 AV = Standard_Integer (Dy - APY * Dy);
662 Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const {
664 // Convert only if the data is correct
665 Graphic3d_CView TheCView;
666 Graphic3d_Vertex Point;
668 if (! ViewExists (AWindow, TheCView))
669 Point.SetCoord (RealLast (), RealLast (), RealLast ());
671 Standard_Integer Width, Height;
672 Standard_ShortReal x, y, z;
673 Standard_Boolean Result;
675 AWindow->Size (Width, Height);
677 Result = MyGraphicDriver->UnProjectRaster (TheCView,
681 // unproject is done by UnProjectRaster
684 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
686 // unproject cannot be done by UnProjectRaster
687 // Code suspended since drivers Phigs and Pex are abandoned.
690 Standard_Real NPCX, NPCY, NPCZ;
691 Standard_Real VRCX, VRCY, VRCZ, VRCT;
692 Standard_Real WCX, WCY, WCZ, WCT;
694 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
695 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
696 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
697 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
699 Standard_Real Dx, Dy, Ratio;
700 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
703 Standard_Integer stop = 0;
705 Standard_Boolean BResult;
707 j = MyDefinedView.Extent ();
709 while ((! stop) && (MyIterator.More ())) {
710 if (TheCView.ViewId ==
711 (MyIterator.Value ())->Identification ()) {
713 (MyIterator.Value ())->MatrixOfOrientation ();
715 (MyIterator.Value ())->MatrixOfMapping ();
719 // MyIterator.Next () is located on the next view
723 // View Mapping Transformation and View Clip, inversion
724 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
726 // View Orientation Transformation, inversion
727 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
729 // (AU, AV) : Device Coordinate Space
730 // DCS -> NPCS Normalized Projection Coordinate Space
731 Dx = Standard_Real (Width);
732 Dy = Standard_Real (Height);
736 NPCX = Standard_Real (AU) / Dx;
737 NPCY = (Dy - Standard_Real (AV)) / Dx;
740 NPCX = Standard_Real (AU) / Dy;
741 NPCY = (Dy - Standard_Real (AV)) / Dy;
745 // NPCS -> VRCS View Reference Coordinate Space
746 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
748 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
749 + TMap_Matrix_Inv (0, 1) * NPCY
750 + TMap_Matrix_Inv (0, 2) * NPCZ
751 + TMap_Matrix_Inv (0, 3);
752 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
753 + TMap_Matrix_Inv (1, 1) * NPCY
754 + TMap_Matrix_Inv (1, 2) * NPCZ
755 + TMap_Matrix_Inv (1, 3);
756 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
757 + TMap_Matrix_Inv (2, 1) * NPCY
758 + TMap_Matrix_Inv (2, 2) * NPCZ
759 + TMap_Matrix_Inv (2, 3);
760 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
761 + TMap_Matrix_Inv (3, 1) * NPCY
762 + TMap_Matrix_Inv (3, 2) * NPCZ
763 + TMap_Matrix_Inv (3, 3);
765 // VRCS -> WCS World Coordinate Space
766 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
768 WCX = TOri_Matrix_Inv (0, 0) * VRCX
769 + TOri_Matrix_Inv (0, 1) * VRCY
770 + TOri_Matrix_Inv (0, 2) * VRCZ
771 + TOri_Matrix_Inv (0, 3) * VRCT;
772 WCY = TOri_Matrix_Inv (1, 0) * VRCX
773 + TOri_Matrix_Inv (1, 1) * VRCY
774 + TOri_Matrix_Inv (1, 2) * VRCZ
775 + TOri_Matrix_Inv (1, 3) * VRCT;
776 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
777 + TOri_Matrix_Inv (2, 1) * VRCY
778 + TOri_Matrix_Inv (2, 2) * VRCZ
779 + TOri_Matrix_Inv (2, 3) * VRCT;
780 WCT = TOri_Matrix_Inv (3, 0) * VRCX
781 + TOri_Matrix_Inv (3, 1) * VRCY
782 + TOri_Matrix_Inv (3, 2) * VRCZ
783 + TOri_Matrix_Inv (3, 3) * VRCT;
786 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
788 Point.SetCoord (RealLast (), RealLast (), RealLast ());
796 void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {
798 // Conversion only if the data is correct
799 Graphic3d_CView TheCView;
801 if (! ViewExists (AWindow, TheCView)) {
802 Point.SetCoord (RealLast (), RealLast (), RealLast ());
803 Proj.SetCoord (0., 0., 0.);
806 Standard_Integer Width, Height;
807 Standard_ShortReal x, y, z;
808 Standard_ShortReal dx, dy, dz;
809 Standard_Boolean Result;
811 AWindow->Size (Width, Height);
813 Result = MyGraphicDriver->UnProjectRasterWithRay (TheCView,
815 AU, AV, x, y, z, dx, dy, dz);
817 // unproject is done by UnProjectRaster
820 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
822 (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
825 // unproject cannot be done by UnProjectRaster
826 // Code is suspended since drivers Phigs are Pex abandoned.
829 Standard_Real NPCX, NPCY, NPCZ;
830 Standard_Real VRCX, VRCY, VRCZ, VRCT;
831 Standard_Real WCX, WCY, WCZ, WCT;
833 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
834 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
835 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
836 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
838 Standard_Real Dx, Dy, Ratio;
839 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
842 Standard_Integer stop = 0;
844 Standard_Boolean BResult;
846 j = MyDefinedView.Extent ();
848 while ((! stop) && (MyIterator.More ())) {
849 if (TheCView.ViewId ==
850 (MyIterator.Value ())->Identification ()) {
852 (MyIterator.Value ())->MatrixOfOrientation ();
854 (MyIterator.Value ())->MatrixOfMapping ();
858 // MyIterator.Next () is located on the next view
862 // View Mapping Transformation and View Clip, inversion
863 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
865 // View Orientation Transformation, inversion
866 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
868 // (AU, AV) : Device Coordinate Space
869 // DCS -> NPCS Normalized Projection Coordinate Space
870 Dx = Standard_Real (Width);
871 Dy = Standard_Real (Height);
875 NPCX = Standard_Real (AU) / Dx;
876 NPCY = (Dy - Standard_Real (AV)) / Dx;
879 NPCX = Standard_Real (AU) / Dy;
880 NPCY = (Dy - Standard_Real (AV)) / Dy;
884 // NPCS -> VRCS View Reference Coordinate Space
885 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
887 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
888 + TMap_Matrix_Inv (0, 1) * NPCY
889 + TMap_Matrix_Inv (0, 2) * NPCZ
890 + TMap_Matrix_Inv (0, 3);
891 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
892 + TMap_Matrix_Inv (1, 1) * NPCY
893 + TMap_Matrix_Inv (1, 2) * NPCZ
894 + TMap_Matrix_Inv (1, 3);
895 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
896 + TMap_Matrix_Inv (2, 1) * NPCY
897 + TMap_Matrix_Inv (2, 2) * NPCZ
898 + TMap_Matrix_Inv (2, 3);
899 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
900 + TMap_Matrix_Inv (3, 1) * NPCY
901 + TMap_Matrix_Inv (3, 2) * NPCZ
902 + TMap_Matrix_Inv (3, 3);
904 // VRCS -> WCS World Coordinate Space
905 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
907 WCX = TOri_Matrix_Inv (0, 0) * VRCX
908 + TOri_Matrix_Inv (0, 1) * VRCY
909 + TOri_Matrix_Inv (0, 2) * VRCZ
910 + TOri_Matrix_Inv (0, 3) * VRCT;
911 WCY = TOri_Matrix_Inv (1, 0) * VRCX
912 + TOri_Matrix_Inv (1, 1) * VRCY
913 + TOri_Matrix_Inv (1, 2) * VRCZ
914 + TOri_Matrix_Inv (1, 3) * VRCT;
915 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
916 + TOri_Matrix_Inv (2, 1) * VRCY
917 + TOri_Matrix_Inv (2, 2) * VRCZ
918 + TOri_Matrix_Inv (2, 3) * VRCT;
919 WCT = TOri_Matrix_Inv (3, 0) * VRCX
920 + TOri_Matrix_Inv (3, 1) * VRCY
921 + TOri_Matrix_Inv (3, 2) * VRCZ
922 + TOri_Matrix_Inv (3, 3) * VRCT;
925 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
927 Point.SetCoord (RealLast (), RealLast (), RealLast ());
929 // Define projection ray
932 // NPCS -> VRCS View Reference Coordinate Space
933 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
935 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
936 + TMap_Matrix_Inv (0, 1) * NPCY
937 + TMap_Matrix_Inv (0, 2) * NPCZ
938 + TMap_Matrix_Inv (0, 3);
939 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
940 + TMap_Matrix_Inv (1, 1) * NPCY
941 + TMap_Matrix_Inv (1, 2) * NPCZ
942 + TMap_Matrix_Inv (1, 3);
943 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
944 + TMap_Matrix_Inv (2, 1) * NPCY
945 + TMap_Matrix_Inv (2, 2) * NPCZ
946 + TMap_Matrix_Inv (2, 3);
947 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
948 + TMap_Matrix_Inv (3, 1) * NPCY
949 + TMap_Matrix_Inv (3, 2) * NPCZ
950 + TMap_Matrix_Inv (3, 3);
952 // VRCS -> WCS World Coordinate Space
953 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
955 WCX = TOri_Matrix_Inv (0, 0) * VRCX
956 + TOri_Matrix_Inv (0, 1) * VRCY
957 + TOri_Matrix_Inv (0, 2) * VRCZ
958 + TOri_Matrix_Inv (0, 3) * VRCT;
959 WCY = TOri_Matrix_Inv (1, 0) * VRCX
960 + TOri_Matrix_Inv (1, 1) * VRCY
961 + TOri_Matrix_Inv (1, 2) * VRCZ
962 + TOri_Matrix_Inv (1, 3) * VRCT;
963 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
964 + TOri_Matrix_Inv (2, 1) * VRCY
965 + TOri_Matrix_Inv (2, 2) * VRCZ
966 + TOri_Matrix_Inv (2, 3) * VRCT;
967 WCT = TOri_Matrix_Inv (3, 0) * VRCX
968 + TOri_Matrix_Inv (3, 1) * VRCY
969 + TOri_Matrix_Inv (3, 2) * VRCZ
970 + TOri_Matrix_Inv (3, 3) * VRCT;
973 Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
977 Proj.SetCoord (0., 0., 0.);
983 Visual3d_PickDescriptor Visual3d_ViewManager::Pick (const Visual3d_ContextPick& CTX, const Handle(Aspect_Window)& AWindow, const Standard_Integer AX, const Standard_Integer AY) {
985 // The marking is activated only if the data is correct
986 Standard_Boolean DoPick = Standard_False;
989 Standard_Integer Width, Height;
991 // Parse the list of views to find a
992 // view having this specified window
993 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
994 int TheWindowIdOfView;
997 const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
998 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
1000 const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
1001 int TheSpecifiedWindowId = int (THEWindow->HWindow ());
1004 while ((! DoPick) && (MyIterator.More ())) {
1006 if ( ((MyIterator.Value ())->IsDefined ()) &&
1007 ((MyIterator.Value ())->IsActive ()) ) {
1009 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
1011 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
1012 TheWindowIdOfView = int (theWindow->XWindow ());
1014 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
1015 TheWindowIdOfView = int (theWindow->HWindow ());
1017 // Comparision on window IDs
1018 if (TheWindowIdOfView == TheSpecifiedWindowId) {
1019 DoPick = Standard_True;
1023 int ((MyIterator.Value ())->Identification ());
1026 int ((MyIterator.Value ())->Identification ());
1028 apick.DefWindow.XWindow = TheSpecifiedWindowId;
1030 apick.DefWindow.XWindow = (HWND) TheSpecifiedWindowId;
1036 theWindow->Size (Width, Height);
1037 apick.DefWindow.dx = float (Width);
1038 apick.DefWindow.dy = float (Height);
1040 apick.Context.aperture = (float) CTX.Aperture ();
1041 apick.Context.order = int (CTX.Order ());
1042 apick.Context.depth = int (CTX.Depth ());
1045 } /* if ((MyIterator.Value ())->IsDefined ()) { */
1047 // MyIterator.Next () is located on the next view
1052 MyGraphicDriver->Pick (apick);
1054 apick.Pick.depth = 0;
1057 Standard_Integer i, j=0;
1058 Standard_Integer NbPick;
1060 Visual3d_PickDescriptor PDes (CTX);
1061 Visual3d_PickPath PPat;
1065 // For i=0 it is not a graphic structure it is a view structure
1066 // For i=1 it is the displayed graphic structure
1067 // For i=2 to apick.Pick.depth-1 it is the connected graphic structures
1068 if (apick.Pick.depth != 0) {
1069 j = apick.Pick.listid[1];
1070 if ((Graphic3d_StructureManager::Identification (j))->
1072 // Maj element number
1073 PPat.SetElementNumber (apick.Pick.listelem[1]);
1074 // Maj pick identifier
1075 PPat.SetPickIdentifier (apick.Pick.listpickid[1]);
1077 PPat.SetStructIdentifier
1078 (Graphic3d_StructureManager::Identification (j));
1080 PDes.AddPickPath (PPat);
1085 // Not very efficient, revise (CAL 22/09/95)
1086 if (apick.Pick.depth > 2) {
1087 Handle(Graphic3d_Structure) StructCur =
1088 Graphic3d_StructureManager::Identification (j);
1089 Standard_Boolean found;
1090 Graphic3d_MapOfStructure Set;
1092 for (i=2; i<apick.Pick.depth; i++) {
1093 found = Standard_False;
1094 j = apick.Pick.listid[i-1];
1096 StructCur->Descendants (Set);
1097 Graphic3d_MapIteratorOfMapOfStructure IteratorD (Set);
1099 j = apick.Pick.listid[i];
1100 while (IteratorD.More () && !found) {
1101 StructCur = IteratorD.Key ();
1102 if (StructCur->Identification () == j ) {
1103 found = Standard_True;
1104 // Maj element number
1105 PPat.SetElementNumber (apick.Pick.listelem[i]);
1106 // Maj pick identifier
1107 PPat.SetPickIdentifier (apick.Pick.listpickid[i]);
1109 PPat.SetStructIdentifier (StructCur);
1111 PDes.AddPickPath (PPat);
1114 // IteratorD.Next () is located on the next structure
1120 apick.Pick.depth = int (NbPick);
1122 MyGraphicDriver->InitPick ();
1128 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
1130 Standard_Boolean Exist = Standard_False;
1132 // Parse the list of views to find
1133 // a view with the specified window
1134 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1135 int TheWindowIdOfView;
1138 const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
1139 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
1141 const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
1142 int TheSpecifiedWindowId = int (THEWindow->HWindow ());
1145 while ((! Exist) && (MyIterator.More ())) {
1147 if ( ((MyIterator.Value ())->IsDefined ()) &&
1148 ((MyIterator.Value ())->IsActive ()) ) {
1150 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
1152 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
1153 TheWindowIdOfView = int (theWindow->XWindow ());
1155 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
1156 TheWindowIdOfView = int (theWindow->HWindow ());
1158 // Comparaison on window IDs
1159 if (TheWindowIdOfView == TheSpecifiedWindowId) {
1160 Exist = Standard_True;
1161 TheCView = *(CALL_DEF_VIEW *)(MyIterator.Value ())->CView ();
1163 } /* if ((MyIterator.Value ())->IsDefined ()) */
1165 // MyIterator.Next () is located on the next view
1173 void Visual3d_ViewManager::Activate () {
1176 // Activates all deactivated views
1178 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1181 Standard_Integer Length = MyDefinedView.Extent ();
1183 MyDefinedView.Extent ();
1186 while (MyIterator.More ()) {
1187 if (! (MyIterator.Value ())->IsActive ())
1188 (MyIterator.Value ())->Activate ();
1190 // MyIterator.Next () is located on the next view
1196 void Visual3d_ViewManager::Deactivate () {
1199 // Deactivates all activated views
1202 Standard_Integer Length = MyDefinedView.Extent ();
1204 MyDefinedView.Extent ();
1206 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1208 while (MyIterator.More ()) {
1209 if ((MyIterator.Value ())->IsActive ())
1210 (MyIterator.Value ())->Deactivate ();
1212 // MyIterator.Next () is located on the next view
1218 Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
1220 // Retourne the planned of definable views for the current
1221 // Visual3d_ViewManager.
1223 (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
1227 Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
1229 return (Graphic3d_StructureManager::Identification (AId));
1233 Standard_Integer Visual3d_ViewManager::Identification () const {
1235 return (Graphic3d_StructureManager::Identification ());
1239 Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {
1241 MyDefinedView.Add (AView);
1242 return (MyViewGenId.Next ());
1246 void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
1248 MyViewGenId.Free(aViewId);
1251 void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
1253 if (MyTransparency && AFlag) return;
1254 if (! MyTransparency && ! AFlag) return;
1256 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1257 while (MyIterator.More ()) {
1258 (MyIterator.Value ())->SetTransparency (AFlag);
1259 // MyIterator.Next () is located on the next view
1263 MyTransparency = AFlag;
1267 Standard_Boolean Visual3d_ViewManager::Transparency () const {
1269 return (MyTransparency);
1273 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
1275 if (MyZBufferAuto && AFlag) return;
1276 if (! MyZBufferAuto && ! AFlag) return;
1278 // if pass from False to True :
1279 // no problem, at the next view update, it
1280 // will properly ask questions to answer (SetVisualisation)
1281 // if pass from True to False :
1282 // it is necessary to modify ZBufferActivity at each view so that
1283 // zbuffer could be active only if required by context.
1284 // In this case -1 is passed so that the view ask itself the question
1285 // Note : 0 forces the desactivation, 1 forces the activation
1287 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1288 while (MyIterator.More ()) {
1289 (MyIterator.Value ())->SetZBufferActivity (-1);
1290 // MyIterator.Next () is located on the next view
1294 MyZBufferAuto = AFlag;
1298 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
1300 return (MyZBufferAuto);
1304 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
1307 cout << "Visual3d_ViewManager::SetLayer\n" << flush;
1310 if (ALayer->Type () == Aspect_TOL_OVERLAY) {
1312 if (MyOverLayer.IsNull ())
1313 cout << "MyOverLayer is defined" << endl;
1315 cout << "MyOverLayer is redefined" << endl;
1317 MyOverLayer = ALayer;
1321 if (MyUnderLayer.IsNull ())
1322 cout << "MyUnderLayer is defined" << endl;
1324 cout << "MyUnderLayer is redefined" << endl;
1326 MyUnderLayer = ALayer;
1331 const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
1333 return (MyUnderLayer);
1337 const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
1339 return (MyOverLayer);