1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
20 /***********************************************************************
24 Classe Visual3d_ViewManager.cxx :
26 Declaration of variables specific to visualisers
28 HISTORIQUE DES MODIFICATIONS :
29 --------------------------------
30 Mars 1992 : NW,JPB,CAL ; Creation.
31 19-06-96 : FMN ; Suppression variables inutiles
32 04-02-97 : FMN ; Suppression de PSOutput, XWDOutput ...
33 06-05-97 : CAL ; Ajout du Clear sur les TOS_COMPUTED.
34 19-09-97 : CAL ; Remplacement de Window->Position par Window->Size;
35 24-10-97 : CAL ; Retrait de DownCast.
36 20-11-97 : CAL ; Disparition de la dependance avec math
37 01-12-97 : CAL ; Retrait du test IsActive sur l'Update et le Redraw
38 31-12-97 : CAL ; Disparition de MathGra
39 16-01-98 : CAL ; Ajout du SetTransform sur une TOS_COMPUTED
40 11-03-98 : CAL ; Visual3d_ViewManager::Remove ()
41 20-05-98 : CAL ; Perfs. Connection entre structures COMPUTED.
42 10-06-98 : CAL ; Modification des signatures de xxProjectRaster.
43 10-06-98 : CAL ; Modification de la signature de ViewExists.
44 01-12-98 : CAL ; S4062. Ajout des layers.
45 02-12-98 : CAL ; Remove () ne detruit plus les vues.
47 ************************************************************************/
49 /*----------------------------------------------------------------------*/
57 /*----------------------------------------------------------------------*/
63 #include <Visual3d_ViewManager.ixx>
64 #include <Visual3d_ViewManager.pxx>
66 #include <Standard_ErrorHandler.hxx>
69 #include <Aspect_IdentDefinitionError.hxx>
71 #include <Graphic3d_GraphicDriver.hxx>
72 #include <Graphic3d_MapOfStructure.hxx>
73 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
75 #include <Visual3d_PickPath.hxx>
76 #include <Visual3d_SetIteratorOfSetOfView.hxx>
78 #if defined (_WIN32) || defined(__WIN32__)
79 # include <WNT_Window.hxx>
80 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
81 # include <Cocoa_Window.hxx>
83 # include <Xw_Window.hxx>
88 //-Global data definitions
90 // -- les vues definies
91 // MyDefinedView : SetOfView;
93 // -- le generateur d'identificateurs de vues
94 // MyViewGenId : GenId;
98 Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Graphic3d_GraphicDriver)& theDriver):
99 Graphic3d_StructureManager (theDriver),
101 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),
102 MyZBufferAuto (Standard_False),
103 MyTransparency (Standard_False)
105 // default layer is always presented in display layer sequence
106 // it can not be removed
108 myLayerSeq.Append (0);
110 MyGraphicDriver = theDriver;
115 void Visual3d_ViewManager::Destroy () {
118 cout << "Visual3d_ViewManager::Destroy (" << MyId << ")\n" << flush;
126 void Visual3d_ViewManager::Remove () {
129 cout << "Visual3d_ViewManager::Remove (" << MyId << ")\n" << flush;
133 // Destroy all defined views
137 cout << "The Manager " << MyId << " have " << Length << " defined views\n";
141 // clear all structures whilst views are alive for correct GPU memory management
142 MyDisplayedStructure.Clear();
143 MyHighlightedStructure.Clear();
144 MyPickStructure.Clear();
146 // clear list of managed views
147 MyDefinedView.Clear();
150 void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
153 cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
154 << AStructure->Identification ()
155 << ", " << OldPriority << ", " << NewPriority << ")\n";
160 // Change structure priority in all defined views
162 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
164 while (MyIterator.More ()) {
165 (MyIterator.Value ())->ChangeDisplayPriority
166 (AStructure, OldPriority, NewPriority);
168 // MyIterator.Next () is located on the next view
174 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
176 //Standard_Integer LengthD = MyDisplayedStructure.Extent() ();
178 // Even if physically the structure cannot
179 // be displayed (pb of visualisation type)
180 // it has status Displayed.
182 if (!MyDisplayedStructure.Contains(AStructure))
186 // Recompute structure in all activated views
188 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
190 while (MyIterator.More ()) {
191 (MyIterator.Value ())->ReCompute (AStructure);
193 // MyIterator.Next () is located on the next view
199 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
200 const Handle(Graphic3d_DataStructureManager)& AProjector)
203 if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
206 Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
208 Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector;
210 Standard_Integer ViewId = theView->Identification ();
212 // Even if physically the structure cannot
213 // be displayed (pb of visualisation type)
214 // it has status Displayed.
215 if (!MyDisplayedStructure.Contains(AStructure))
219 // Recompute structure in all activated views
221 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
223 while (MyIterator.More ()) {
224 if ((MyIterator.Value ())->Identification () == ViewId)
225 theView->ReCompute (AStructure);
227 // MyIterator.Next () is located on the next view
233 void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
235 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
237 while (MyIterator.More ()) {
238 (MyIterator.Value ())->Clear (AStructure, WithDestruction);
240 // MyIterator.Next () is located on the next view
246 void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
248 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
250 while (MyIterator.More ()) {
251 (MyIterator.Value ())->Connect (AMother, ADaughter);
253 // MyIterator.Next () is located on the next view
259 void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
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
309 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
311 while (MyIterator.More ()) {
312 (MyIterator.Value ())->Erase (AStructure);
314 // MyIterator.Next () is located on the next view
318 MyHighlightedStructure.Remove (AStructure);
319 MyPickStructure.Remove (AStructure);
323 void Visual3d_ViewManager::Erase () {
325 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
327 for (; it.More(); it.Next()) {
328 Handle(Graphic3d_Structure) SG = it.Key();
334 void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
336 MyHighlightedStructure.Add(AStructure);
339 // Highlight in all activated views
341 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
343 while (MyIterator.More ()) {
344 (MyIterator.Value ())->Highlight (AStructure, AMethod);
346 // MyIterator.Next () is located on the next view
352 void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
354 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
356 while (MyIterator.More ()) {
357 (MyIterator.Value ())->SetTransform (AStructure, ATrsf);
359 // MyIterator.Next () is located on the next view
365 void Visual3d_ViewManager::UnHighlight () {
367 Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
369 for (; it.More(); it.Next()) {
370 Handle(Graphic3d_Structure) SG = it.Key();
377 void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
379 MyHighlightedStructure.Remove(AStructure);
383 // UnHighlight in all activated views
385 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
387 while (MyIterator.More ()) {
388 (MyIterator.Value ())->UnHighlight (AStructure);
390 // MyIterator.Next () is located on the next view
396 void Visual3d_ViewManager::Redraw () const {
398 Standard_Integer MaxDx, MaxDy;
399 Standard_Integer Dx, Dy;
400 MaxDx = MaxDy = IntegerFirst ();
403 // Redraw all activated views
405 Standard_Integer j = MyDefinedView.Extent ();
407 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
409 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) {
410 while (MyIterator.More ()) {
411 (MyIterator.Value ())->Window ()->Size (Dx, Dy);
412 if (Dx > MaxDx) MaxDx = Dx;
413 if (Dy > MaxDy) MaxDy = Dy;
415 // MyIterator.Next () is located on the next view
418 if (! MyUnderLayer.IsNull ())
419 MyUnderLayer->SetViewport (MaxDx, MaxDy);
420 if (! MyOverLayer.IsNull ())
421 MyOverLayer->SetViewport (MaxDx, MaxDy);
424 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ())
425 MyIterator.Initialize (MyDefinedView);
426 while (MyIterator.More ()) {
427 (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer);
429 // MyIterator.Next () is located on the next view
435 void Visual3d_ViewManager::Update () const {
438 // Update all activated views
440 Standard_Integer j = MyDefinedView.Extent ();
442 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
444 while (MyIterator.More ()) {
445 (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer);
447 // MyIterator.Next () is located on the next view
453 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const {
455 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
457 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
459 while (MyIterator.More ()) {
460 if ((MyIterator.Value ())->IsActive ())
461 SG->Add (MyIterator.Value ());
463 // MyIterator.Next () is located on the next view
472 Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const {
474 Standard_Boolean Result = Standard_False;
477 // Check all activated views
479 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
481 Standard_Integer i = MyDefinedView.Extent ();
483 while ((! Result) && (MyIterator.More ())) {
484 if ((MyIterator.Value ())->IsActive ())
486 (MyIterator.Value ())->ContainsComputedStructure ();
488 // MyIterator.Next () is located on the next view
496 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const {
498 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
500 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
502 while (MyIterator.More ()) {
503 SG->Add (MyIterator.Value ());
505 // MyIterator.Next () is located on the next view
513 void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const {
515 // Convert only if the data is correct
516 Standard_Boolean Exist;
517 Graphic3d_CView TheCView;
518 //Graphic3d_Vertex Point;
520 TColStd_Array2OfReal Ori_Matrix (0,3,0,3);
521 TColStd_Array2OfReal Map_Matrix (0,3,0,3);
523 Standard_Integer Width, Height;
524 Standard_Real AX, AY, AZ;
525 Standard_Real Dx, Dy, Ratio;
527 Exist = ViewExists (AWindow, TheCView);
530 AU = AV = IntegerLast ();
533 // NKV - 11.02.08 - Use graphic driver functions
534 Standard_Boolean Result;
536 AVertex.Coord (AX, AY, AZ);
538 Result = MyGraphicDriver->ProjectRaster (TheCView,
539 Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ),
545 Standard_Real PtX, PtY, PtZ, PtT;
546 Standard_Real APX, APY, APZ;
549 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
551 Standard_Integer stop = 0;
553 while ((! stop) && (MyIterator.More ())) {
554 if (TheCView.ViewId ==
555 (MyIterator.Value ())->Identification ()) {
557 (MyIterator.Value ())->MatrixOfOrientation ();
559 (MyIterator.Value ())->MatrixOfMapping ();
563 // MyIterator.Next () is located on the next view
568 // WCS -> View Reference Coordinate Space
569 PtX = Ori_Matrix (0, 0) * AX
570 + Ori_Matrix (0, 1) * AY
571 + Ori_Matrix (0, 2) * AZ
573 PtY = Ori_Matrix (1, 0) * AX
574 + Ori_Matrix (1, 1) * AY
575 + Ori_Matrix (1, 2) * AZ
577 PtZ = Ori_Matrix (2, 0) * AX
578 + Ori_Matrix (2, 1) * AY
579 + Ori_Matrix (2, 2) * AZ
581 PtT = Ori_Matrix (3, 0) * AX
582 + Ori_Matrix (3, 1) * AY
583 + Ori_Matrix (3, 2) * AZ
586 // VRCS -> Normalized Projection Coordinate Space
587 APX = Map_Matrix (0, 0) * PtX
588 + Map_Matrix (0, 1) * PtY
589 + Map_Matrix (0, 2) * PtZ
590 + Map_Matrix (0, 3) * PtT;
591 APY = Map_Matrix (1, 0) * PtX
592 + Map_Matrix (1, 1) * PtY
593 + Map_Matrix (1, 2) * PtZ
594 + Map_Matrix (1, 3) * PtT;
595 APZ = Map_Matrix (2, 0) * PtX
596 + Map_Matrix (2, 1) * PtY
597 + Map_Matrix (2, 2) * PtZ
598 + Map_Matrix (2, 3) * PtT;
599 APT = Map_Matrix (3, 0) * PtX
600 + Map_Matrix (3, 1) * PtY
601 + Map_Matrix (3, 2) * PtZ
602 + Map_Matrix (3, 3) * PtT;
604 if (APT == 0. || stop == 0) {
605 AU = AV = IntegerLast ();
612 // NPCS -> Device Coordinate Space
613 AWindow->Size (Width, Height);
614 Dx = Standard_Real (Width);
615 Dy = Standard_Real (Height);
618 AU = Standard_Integer (APX * Dx);
619 AV = Standard_Integer (Dy - APY * Dy * Ratio);
622 AU = Standard_Integer (APX * Dx / Ratio);
623 AV = Standard_Integer (Dy - APY * Dy);
631 Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const {
633 // Convert only if the data is correct
634 Graphic3d_CView TheCView;
635 Graphic3d_Vertex Point;
637 if (ViewExists (AWindow, TheCView))
639 Standard_Integer Width, Height;
640 Standard_ShortReal x, y, z;
641 Standard_Boolean Result;
643 AWindow->Size (Width, Height);
645 Result = MyGraphicDriver->UnProjectRaster (TheCView,
649 // unproject is done by UnProjectRaster
652 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
654 // unproject cannot be done by UnProjectRaster
655 // Code suspended since drivers Phigs and Pex are abandoned.
658 Standard_Real NPCX, NPCY, NPCZ;
659 Standard_Real VRCX, VRCY, VRCZ, VRCT;
660 Standard_Real WCX, WCY, WCZ, WCT;
662 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
663 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
664 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
665 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
667 Standard_Real Dx, Dy, Ratio;
668 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
671 Standard_Integer stop = 0;
673 Standard_Boolean BResult;
675 j = MyDefinedView.Extent ();
677 while ((! stop) && (MyIterator.More ())) {
678 if (TheCView.ViewId ==
679 (MyIterator.Value ())->Identification ()) {
681 (MyIterator.Value ())->MatrixOfOrientation ();
683 (MyIterator.Value ())->MatrixOfMapping ();
687 // MyIterator.Next () is located on the next view
691 // View Mapping Transformation and View Clip, inversion
692 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
694 // View Orientation Transformation, inversion
695 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
697 // (AU, AV) : Device Coordinate Space
698 // DCS -> NPCS Normalized Projection Coordinate Space
699 Dx = Standard_Real (Width);
700 Dy = Standard_Real (Height);
704 NPCX = Standard_Real (AU) / Dx;
705 NPCY = (Dy - Standard_Real (AV)) / Dx;
708 NPCX = Standard_Real (AU) / Dy;
709 NPCY = (Dy - Standard_Real (AV)) / Dy;
713 // NPCS -> VRCS View Reference Coordinate Space
714 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
716 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
717 + TMap_Matrix_Inv (0, 1) * NPCY
718 + TMap_Matrix_Inv (0, 2) * NPCZ
719 + TMap_Matrix_Inv (0, 3);
720 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
721 + TMap_Matrix_Inv (1, 1) * NPCY
722 + TMap_Matrix_Inv (1, 2) * NPCZ
723 + TMap_Matrix_Inv (1, 3);
724 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
725 + TMap_Matrix_Inv (2, 1) * NPCY
726 + TMap_Matrix_Inv (2, 2) * NPCZ
727 + TMap_Matrix_Inv (2, 3);
728 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
729 + TMap_Matrix_Inv (3, 1) * NPCY
730 + TMap_Matrix_Inv (3, 2) * NPCZ
731 + TMap_Matrix_Inv (3, 3);
733 // VRCS -> WCS World Coordinate Space
734 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
736 WCX = TOri_Matrix_Inv (0, 0) * VRCX
737 + TOri_Matrix_Inv (0, 1) * VRCY
738 + TOri_Matrix_Inv (0, 2) * VRCZ
739 + TOri_Matrix_Inv (0, 3) * VRCT;
740 WCY = TOri_Matrix_Inv (1, 0) * VRCX
741 + TOri_Matrix_Inv (1, 1) * VRCY
742 + TOri_Matrix_Inv (1, 2) * VRCZ
743 + TOri_Matrix_Inv (1, 3) * VRCT;
744 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
745 + TOri_Matrix_Inv (2, 1) * VRCY
746 + TOri_Matrix_Inv (2, 2) * VRCZ
747 + TOri_Matrix_Inv (2, 3) * VRCT;
748 WCT = TOri_Matrix_Inv (3, 0) * VRCX
749 + TOri_Matrix_Inv (3, 1) * VRCY
750 + TOri_Matrix_Inv (3, 2) * VRCZ
751 + TOri_Matrix_Inv (3, 3) * VRCT;
754 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
762 void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {
764 // Conversion only if the data is correct
765 Graphic3d_CView TheCView;
767 if (! ViewExists (AWindow, TheCView)) {
768 Point.SetCoord (0., 0., 0.);
769 Proj.SetCoord (0., 0., 0.);
772 Standard_Integer Width, Height;
773 Standard_ShortReal x, y, z;
774 Standard_ShortReal dx, dy, dz;
775 Standard_Boolean Result;
777 AWindow->Size (Width, Height);
779 Result = MyGraphicDriver->UnProjectRasterWithRay (TheCView,
781 AU, AV, x, y, z, dx, dy, dz);
783 // unproject is done by UnProjectRaster
786 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
788 (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
791 // unproject cannot be done by UnProjectRaster
792 // Code is suspended since drivers Phigs are Pex abandoned.
795 Standard_Real NPCX, NPCY, NPCZ;
796 Standard_Real VRCX, VRCY, VRCZ, VRCT;
797 Standard_Real WCX, WCY, WCZ, WCT;
799 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
800 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
801 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
802 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
804 Standard_Real Dx, Dy, Ratio;
805 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
808 Standard_Integer stop = 0;
810 Standard_Boolean BResult;
812 j = MyDefinedView.Extent ();
814 while ((! stop) && (MyIterator.More ())) {
815 if (TheCView.ViewId ==
816 (MyIterator.Value ())->Identification ()) {
818 (MyIterator.Value ())->MatrixOfOrientation ();
820 (MyIterator.Value ())->MatrixOfMapping ();
824 // MyIterator.Next () is located on the next view
828 // View Mapping Transformation and View Clip, inversion
829 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
831 // View Orientation Transformation, inversion
832 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
834 // (AU, AV) : Device Coordinate Space
835 // DCS -> NPCS Normalized Projection Coordinate Space
836 Dx = Standard_Real (Width);
837 Dy = Standard_Real (Height);
841 NPCX = Standard_Real (AU) / Dx;
842 NPCY = (Dy - Standard_Real (AV)) / Dx;
845 NPCX = Standard_Real (AU) / Dy;
846 NPCY = (Dy - Standard_Real (AV)) / Dy;
850 // NPCS -> VRCS View Reference Coordinate Space
851 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
853 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
854 + TMap_Matrix_Inv (0, 1) * NPCY
855 + TMap_Matrix_Inv (0, 2) * NPCZ
856 + TMap_Matrix_Inv (0, 3);
857 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
858 + TMap_Matrix_Inv (1, 1) * NPCY
859 + TMap_Matrix_Inv (1, 2) * NPCZ
860 + TMap_Matrix_Inv (1, 3);
861 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
862 + TMap_Matrix_Inv (2, 1) * NPCY
863 + TMap_Matrix_Inv (2, 2) * NPCZ
864 + TMap_Matrix_Inv (2, 3);
865 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
866 + TMap_Matrix_Inv (3, 1) * NPCY
867 + TMap_Matrix_Inv (3, 2) * NPCZ
868 + TMap_Matrix_Inv (3, 3);
870 // VRCS -> WCS World Coordinate Space
871 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
873 WCX = TOri_Matrix_Inv (0, 0) * VRCX
874 + TOri_Matrix_Inv (0, 1) * VRCY
875 + TOri_Matrix_Inv (0, 2) * VRCZ
876 + TOri_Matrix_Inv (0, 3) * VRCT;
877 WCY = TOri_Matrix_Inv (1, 0) * VRCX
878 + TOri_Matrix_Inv (1, 1) * VRCY
879 + TOri_Matrix_Inv (1, 2) * VRCZ
880 + TOri_Matrix_Inv (1, 3) * VRCT;
881 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
882 + TOri_Matrix_Inv (2, 1) * VRCY
883 + TOri_Matrix_Inv (2, 2) * VRCZ
884 + TOri_Matrix_Inv (2, 3) * VRCT;
885 WCT = TOri_Matrix_Inv (3, 0) * VRCX
886 + TOri_Matrix_Inv (3, 1) * VRCY
887 + TOri_Matrix_Inv (3, 2) * VRCZ
888 + TOri_Matrix_Inv (3, 3) * VRCT;
891 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
893 Point.SetCoord (0., 0., 0.);
895 // Define projection ray
898 // NPCS -> VRCS View Reference Coordinate Space
899 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
901 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
902 + TMap_Matrix_Inv (0, 1) * NPCY
903 + TMap_Matrix_Inv (0, 2) * NPCZ
904 + TMap_Matrix_Inv (0, 3);
905 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
906 + TMap_Matrix_Inv (1, 1) * NPCY
907 + TMap_Matrix_Inv (1, 2) * NPCZ
908 + TMap_Matrix_Inv (1, 3);
909 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
910 + TMap_Matrix_Inv (2, 1) * NPCY
911 + TMap_Matrix_Inv (2, 2) * NPCZ
912 + TMap_Matrix_Inv (2, 3);
913 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
914 + TMap_Matrix_Inv (3, 1) * NPCY
915 + TMap_Matrix_Inv (3, 2) * NPCZ
916 + TMap_Matrix_Inv (3, 3);
918 // VRCS -> WCS World Coordinate Space
919 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
921 WCX = TOri_Matrix_Inv (0, 0) * VRCX
922 + TOri_Matrix_Inv (0, 1) * VRCY
923 + TOri_Matrix_Inv (0, 2) * VRCZ
924 + TOri_Matrix_Inv (0, 3) * VRCT;
925 WCY = TOri_Matrix_Inv (1, 0) * VRCX
926 + TOri_Matrix_Inv (1, 1) * VRCY
927 + TOri_Matrix_Inv (1, 2) * VRCZ
928 + TOri_Matrix_Inv (1, 3) * VRCT;
929 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
930 + TOri_Matrix_Inv (2, 1) * VRCY
931 + TOri_Matrix_Inv (2, 2) * VRCZ
932 + TOri_Matrix_Inv (2, 3) * VRCT;
933 WCT = TOri_Matrix_Inv (3, 0) * VRCX
934 + TOri_Matrix_Inv (3, 1) * VRCY
935 + TOri_Matrix_Inv (3, 2) * VRCZ
936 + TOri_Matrix_Inv (3, 3) * VRCT;
939 Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
943 Proj.SetCoord (0., 0., 0.);
950 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
952 Standard_Boolean Exist = Standard_False;
954 // Parse the list of views to find
955 // a view with the specified window
956 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
958 #if defined(_WIN32) || defined(__WIN32__)
959 const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow);
960 int TheSpecifiedWindowId = int (THEWindow->HWindow ());
961 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
962 const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow);
963 NSView* TheSpecifiedWindowId = THEWindow->HView();
965 const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow);
966 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
969 while ((! Exist) && (MyIterator.More ())) {
971 if ( ((MyIterator.Value ())->IsDefined ()) &&
972 ((MyIterator.Value ())->IsActive ()) ) {
974 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
975 #if defined(_WIN32) || defined(__WIN32__)
976 const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow);
977 int TheWindowIdOfView = int (theWindow->HWindow ());
978 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
979 const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow);
980 NSView* TheWindowIdOfView = theWindow->HView();
982 const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow);
983 int TheWindowIdOfView = int (theWindow->XWindow ());
985 // Comparaison on window IDs
986 if (TheWindowIdOfView == TheSpecifiedWindowId) {
987 Exist = Standard_True;
988 TheCView = *(Graphic3d_CView* )(MyIterator.Value())->CView();
990 } /* if ((MyIterator.Value ())->IsDefined ()) */
992 // MyIterator.Next () is located on the next view
1000 void Visual3d_ViewManager::Activate () {
1003 // Activates all deactivated views
1005 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1007 while (MyIterator.More ()) {
1008 if (! (MyIterator.Value ())->IsActive ())
1009 (MyIterator.Value ())->Activate ();
1011 // MyIterator.Next () is located on the next view
1017 void Visual3d_ViewManager::Deactivate () {
1020 // Deactivates all activated views
1022 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1024 while (MyIterator.More ()) {
1025 if ((MyIterator.Value ())->IsActive ())
1026 (MyIterator.Value ())->Deactivate ();
1028 // MyIterator.Next () is located on the next view
1034 Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
1036 // Retourne the planned of definable views for the current
1037 // Visual3d_ViewManager.
1039 (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
1043 Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
1045 return (Graphic3d_StructureManager::Identification (AId));
1049 Standard_Integer Visual3d_ViewManager::Identification () const {
1051 return (Graphic3d_StructureManager::Identification ());
1055 Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {
1057 MyDefinedView.Add (AView);
1058 return (MyViewGenId.Next ());
1062 void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
1064 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1065 while (MyIterator.More())
1067 if ((MyIterator.Value())->Identification () == aViewId)
1069 const Handle(Visual3d_View)& theView = MyIterator.Value();
1070 //remove the view from the list
1071 MyDefinedView.Remove(theView);
1077 MyViewGenId.Free(aViewId);
1080 void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
1082 if (MyTransparency && AFlag) return;
1083 if (! MyTransparency && ! AFlag) return;
1085 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1086 while (MyIterator.More ()) {
1087 (MyIterator.Value ())->SetTransparency (AFlag);
1088 // MyIterator.Next () is located on the next view
1092 MyTransparency = AFlag;
1096 Standard_Boolean Visual3d_ViewManager::Transparency () const {
1098 return (MyTransparency);
1102 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
1104 if (MyZBufferAuto && AFlag) return;
1105 if (! MyZBufferAuto && ! AFlag) return;
1107 // if pass from False to True :
1108 // no problem, at the next view update, it
1109 // will properly ask questions to answer (SetVisualisation)
1110 // if pass from True to False :
1111 // it is necessary to modify ZBufferActivity at each view so that
1112 // zbuffer could be active only if required by context.
1113 // In this case -1 is passed so that the view ask itself the question
1114 // Note : 0 forces the desactivation, 1 forces the activation
1116 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1117 while (MyIterator.More ()) {
1118 (MyIterator.Value ())->SetZBufferActivity (-1);
1119 // MyIterator.Next () is located on the next view
1123 MyZBufferAuto = AFlag;
1127 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
1129 return (MyZBufferAuto);
1133 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
1136 cout << "Visual3d_ViewManager::SetLayer\n" << flush;
1139 if (ALayer->Type () == Aspect_TOL_OVERLAY) {
1141 if (MyOverLayer.IsNull ())
1142 cout << "MyOverLayer is defined" << endl;
1144 cout << "MyOverLayer is redefined" << endl;
1146 MyOverLayer = ALayer;
1150 if (MyUnderLayer.IsNull ())
1151 cout << "MyUnderLayer is defined" << endl;
1153 cout << "MyUnderLayer is redefined" << endl;
1155 MyUnderLayer = ALayer;
1160 const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
1162 return (MyUnderLayer);
1166 const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
1168 return (MyOverLayer);
1172 //=======================================================================
1173 //function : ChangeZLayer
1175 //=======================================================================
1177 void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1178 const Standard_Integer theLayerId)
1180 if (!myLayerIds.Contains (theLayerId))
1183 // change display layer for structure in all views
1184 if (MyDisplayedStructure.Contains (theStructure))
1186 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1187 for ( ; aViewIt.More (); aViewIt.Next ())
1188 (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
1191 // tell graphic driver to update the structure's display layer
1192 MyGraphicDriver->ChangeZLayer (
1193 (*(Graphic3d_CStructure*)theStructure->CStructure ()), theLayerId);
1196 //=======================================================================
1197 //function : GetZLayer
1199 //=======================================================================
1201 Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
1203 Graphic3d_CStructure& aStructure =
1204 (*(Graphic3d_CStructure*)theStructure->CStructure ());
1206 return MyGraphicDriver->GetZLayer (aStructure);
1209 //=======================================================================
1210 //function : AddZLayer
1212 //=======================================================================
1214 Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
1219 theLayerId = getZLayerGenId ().Next ();
1220 myLayerIds.Add (theLayerId);
1221 myLayerSeq.Append (theLayerId);
1223 catch (Aspect_IdentDefinitionError)
1225 // new index can't be generated
1226 return Standard_False;
1229 // tell all managed views to remove display layers
1230 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1231 for ( ; aViewIt.More (); aViewIt.Next ())
1232 (aViewIt.Value ())->AddZLayer (theLayerId);
1234 return Standard_True;
1237 //=======================================================================
1238 //function : RemoveZLayer
1240 //=======================================================================
1242 Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
1244 if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
1245 return Standard_False;
1247 // tell all managed views to remove display layers
1248 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1249 for ( ; aViewIt.More (); aViewIt.Next ())
1250 (aViewIt.Value ())->RemoveZLayer (theLayerId);
1252 MyGraphicDriver->UnsetZLayer (theLayerId);
1255 for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
1256 if (myLayerSeq(aIdx) == theLayerId)
1258 myLayerSeq.Remove (aIdx);
1262 myLayerIds.Remove (theLayerId);
1263 getZLayerGenId ().Free (theLayerId);
1265 return Standard_True;
1268 //=======================================================================
1269 //function : GetAllZLayers
1271 //=======================================================================
1273 void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
1275 theLayerSeq.Assign (myLayerSeq);
1278 //=======================================================================
1279 //function : getZLayerGenId
1281 //=======================================================================
1283 Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
1285 static Aspect_GenId aGenId (1, IntegerLast());
1289 //=======================================================================
1290 //function : InstallZLayers
1292 //=======================================================================
1294 void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
1296 if (!MyDefinedView.Contains (theView))
1299 // erase and insert layers iteratively to provide the same layer order as
1300 // in the view manager's sequence. This approach bases on the layer insertion
1301 // order: the new layers are always appended to the end of the list
1302 // inside of view, while layer remove operation doesn't affect the order.
1303 // Starting from second layer : no need to change the default z layer.
1304 for (Standard_Integer aSeqIdx = 2; aSeqIdx <= myLayerSeq.Length (); aSeqIdx++)
1306 Standard_Integer aLayerID = myLayerSeq.Value (aSeqIdx);
1307 theView->RemoveZLayer (aLayerID);
1308 theView->AddZLayer (aLayerID);