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>
79 # include <Xw_Window.hxx>
81 # include <WNT_Window.hxx>
86 //-Global data definitions
88 // -- les vues definies
89 // MyDefinedView : SetOfView;
91 // -- le generateur d'identificateurs de vues
92 // MyViewGenId : GenId;
96 Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Aspect_GraphicDevice)& aDevice):
97 Graphic3d_StructureManager (aDevice),
99 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),
100 MyZBufferAuto (Standard_False),
101 MyTransparency (Standard_False)
103 // default layer is always presented in display layer sequence
104 // it can not be removed
106 myLayerSeq.Append (0);
108 Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver ();
110 MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
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 MyVisibleStructure.Clear();
145 MyPickStructure.Clear();
147 // clear list of managed views
148 MyDefinedView.Clear();
151 void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
154 cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
155 << AStructure->Identification ()
156 << ", " << OldPriority << ", " << NewPriority << ")\n";
161 // Change structure priority in all defined views
163 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
165 while (MyIterator.More ()) {
166 (MyIterator.Value ())->ChangeDisplayPriority
167 (AStructure, OldPriority, NewPriority);
169 // MyIterator.Next () is located on the next view
175 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
177 //Standard_Integer LengthD = MyDisplayedStructure.Extent() ();
179 // Even if physically the structure cannot
180 // be displayed (pb of visualisation type)
181 // it has status Displayed.
183 if (!MyDisplayedStructure.Contains(AStructure))
187 // Recompute structure in all activated views
189 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
191 while (MyIterator.More ()) {
192 (MyIterator.Value ())->ReCompute (AStructure);
194 // MyIterator.Next () is located on the next view
200 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
201 const Handle(Graphic3d_DataStructureManager)& AProjector)
204 if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
207 Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
209 Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector;
211 Standard_Integer ViewId = theView->Identification ();
213 // Even if physically the structure cannot
214 // be displayed (pb of visualisation type)
215 // it has status Displayed.
216 if (!MyDisplayedStructure.Contains(AStructure))
220 // Recompute structure in all activated views
222 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
224 while (MyIterator.More ()) {
225 if ((MyIterator.Value ())->Identification () == ViewId)
226 theView->ReCompute (AStructure);
228 // MyIterator.Next () is located on the next view
234 void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
236 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
238 while (MyIterator.More ()) {
239 (MyIterator.Value ())->Clear (AStructure, WithDestruction);
241 // MyIterator.Next () is located on the next view
247 void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
249 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
251 while (MyIterator.More ()) {
252 (MyIterator.Value ())->Connect (AMother, ADaughter);
254 // MyIterator.Next () is located on the next view
260 void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
262 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
264 while (MyIterator.More ()) {
265 (MyIterator.Value ())->Disconnect (AMother, ADaughter);
267 // MyIterator.Next () is located on the next view
273 void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) {
276 // Even if physically the structure cannot
277 // be displayed (pb of visualisation type)
278 // it has status Displayed.
280 MyDisplayedStructure.Add(AStructure);
283 // Display structure in all activated views
285 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
287 while (MyIterator.More ()) {
288 (MyIterator.Value ())->Display (AStructure);
290 // MyIterator.Next () is located on the next view
296 void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) {
299 // Even if physically the structure cannot
300 // be displayed (pb of visualisation type)
301 // it has status Displayed.
303 MyDisplayedStructure.Remove(AStructure);
308 // Erase structure in all defined views
310 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
312 while (MyIterator.More ()) {
313 (MyIterator.Value ())->Erase (AStructure);
315 // MyIterator.Next () is located on the next view
319 MyHighlightedStructure.Remove (AStructure);
320 MyVisibleStructure.Remove (AStructure);
321 MyPickStructure.Remove (AStructure);
325 void Visual3d_ViewManager::Erase () {
327 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
329 for (; it.More(); it.Next()) {
330 Handle(Graphic3d_Structure) SG = it.Key();
336 void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
338 MyHighlightedStructure.Add(AStructure);
341 // Highlight in all activated views
343 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
345 while (MyIterator.More ()) {
346 (MyIterator.Value ())->Highlight (AStructure, AMethod);
348 // MyIterator.Next () is located on the next view
354 void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
356 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
358 while (MyIterator.More ()) {
359 (MyIterator.Value ())->SetTransform (AStructure, ATrsf);
361 // MyIterator.Next () is located on the next view
367 void Visual3d_ViewManager::UnHighlight () {
369 Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
371 for (; it.More(); it.Next()) {
372 Handle(Graphic3d_Structure) SG = it.Key();
379 void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
381 MyHighlightedStructure.Remove(AStructure);
385 // UnHighlight in all activated views
387 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
389 while (MyIterator.More ()) {
390 (MyIterator.Value ())->UnHighlight (AStructure);
392 // MyIterator.Next () is located on the next view
398 void Visual3d_ViewManager::Redraw () const {
400 Standard_Integer MaxDx, MaxDy;
401 Standard_Integer Dx, Dy;
402 MaxDx = MaxDy = IntegerFirst ();
405 // Redraw all activated views
407 Standard_Integer j = MyDefinedView.Extent ();
409 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
411 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) {
412 while (MyIterator.More ()) {
413 (MyIterator.Value ())->Window ()->Size (Dx, Dy);
414 if (Dx > MaxDx) MaxDx = Dx;
415 if (Dy > MaxDy) MaxDy = Dy;
417 // MyIterator.Next () is located on the next view
420 if (! MyUnderLayer.IsNull ())
421 MyUnderLayer->SetViewport (MaxDx, MaxDy);
422 if (! MyOverLayer.IsNull ())
423 MyOverLayer->SetViewport (MaxDx, MaxDy);
426 if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ())
427 MyIterator.Initialize (MyDefinedView);
428 while (MyIterator.More ()) {
429 (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer);
431 // MyIterator.Next () is located on the next view
437 void Visual3d_ViewManager::Update () const {
440 // Update all activated views
442 Standard_Integer j = MyDefinedView.Extent ();
444 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
446 while (MyIterator.More ()) {
447 (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer);
449 // MyIterator.Next () is located on the next view
455 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const {
457 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
459 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
461 while (MyIterator.More ()) {
462 if ((MyIterator.Value ())->IsActive ())
463 SG->Add (MyIterator.Value ());
465 // MyIterator.Next () is located on the next view
474 Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const {
476 Standard_Boolean Result = Standard_False;
479 // Check all activated views
481 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
483 Standard_Integer i = MyDefinedView.Extent ();
485 while ((! Result) && (MyIterator.More ())) {
486 if ((MyIterator.Value ())->IsActive ())
488 (MyIterator.Value ())->ContainsComputedStructure ();
490 // MyIterator.Next () is located on the next view
498 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const {
500 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
502 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
504 while (MyIterator.More ()) {
505 SG->Add (MyIterator.Value ());
507 // MyIterator.Next () is located on the next view
515 void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const {
517 // Convert only if the data is correct
518 Standard_Boolean Exist;
519 Graphic3d_CView TheCView;
520 //Graphic3d_Vertex Point;
522 TColStd_Array2OfReal Ori_Matrix (0,3,0,3);
523 TColStd_Array2OfReal Map_Matrix (0,3,0,3);
525 Standard_Integer Width, Height;
526 Standard_Real AX, AY, AZ;
527 Standard_Real Dx, Dy, Ratio;
529 Exist = ViewExists (AWindow, TheCView);
532 AU = AV = IntegerLast ();
535 // NKV - 11.02.08 - Use graphic driver functions
536 Standard_Boolean Result;
538 AVertex.Coord (AX, AY, AZ);
540 Result = MyGraphicDriver->ProjectRaster (TheCView,
541 Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ),
547 Standard_Real PtX, PtY, PtZ, PtT;
548 Standard_Real APX, APY, APZ;
551 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
553 Standard_Integer stop = 0;
555 while ((! stop) && (MyIterator.More ())) {
556 if (TheCView.ViewId ==
557 (MyIterator.Value ())->Identification ()) {
559 (MyIterator.Value ())->MatrixOfOrientation ();
561 (MyIterator.Value ())->MatrixOfMapping ();
565 // MyIterator.Next () is located on the next view
570 // WCS -> View Reference Coordinate Space
571 PtX = Ori_Matrix (0, 0) * AX
572 + Ori_Matrix (0, 1) * AY
573 + Ori_Matrix (0, 2) * AZ
575 PtY = Ori_Matrix (1, 0) * AX
576 + Ori_Matrix (1, 1) * AY
577 + Ori_Matrix (1, 2) * AZ
579 PtZ = Ori_Matrix (2, 0) * AX
580 + Ori_Matrix (2, 1) * AY
581 + Ori_Matrix (2, 2) * AZ
583 PtT = Ori_Matrix (3, 0) * AX
584 + Ori_Matrix (3, 1) * AY
585 + Ori_Matrix (3, 2) * AZ
588 // VRCS -> Normalized Projection Coordinate Space
589 APX = Map_Matrix (0, 0) * PtX
590 + Map_Matrix (0, 1) * PtY
591 + Map_Matrix (0, 2) * PtZ
592 + Map_Matrix (0, 3) * PtT;
593 APY = Map_Matrix (1, 0) * PtX
594 + Map_Matrix (1, 1) * PtY
595 + Map_Matrix (1, 2) * PtZ
596 + Map_Matrix (1, 3) * PtT;
597 APZ = Map_Matrix (2, 0) * PtX
598 + Map_Matrix (2, 1) * PtY
599 + Map_Matrix (2, 2) * PtZ
600 + Map_Matrix (2, 3) * PtT;
601 APT = Map_Matrix (3, 0) * PtX
602 + Map_Matrix (3, 1) * PtY
603 + Map_Matrix (3, 2) * PtZ
604 + Map_Matrix (3, 3) * PtT;
606 if (APT == 0. || stop == 0) {
607 AU = AV = IntegerLast ();
614 // NPCS -> Device Coordinate Space
615 AWindow->Size (Width, Height);
616 Dx = Standard_Real (Width);
617 Dy = Standard_Real (Height);
620 AU = Standard_Integer (APX * Dx);
621 AV = Standard_Integer (Dy - APY * Dy * Ratio);
624 AU = Standard_Integer (APX * Dx / Ratio);
625 AV = Standard_Integer (Dy - APY * Dy);
633 Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const {
635 // Convert only if the data is correct
636 Graphic3d_CView TheCView;
637 Graphic3d_Vertex Point;
639 if (! ViewExists (AWindow, TheCView))
640 Point.SetCoord (RealLast (), RealLast (), RealLast ());
642 Standard_Integer Width, Height;
643 Standard_ShortReal x, y, z;
644 Standard_Boolean Result;
646 AWindow->Size (Width, Height);
648 Result = MyGraphicDriver->UnProjectRaster (TheCView,
652 // unproject is done by UnProjectRaster
655 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
657 // unproject cannot be done by UnProjectRaster
658 // Code suspended since drivers Phigs and Pex are abandoned.
661 Standard_Real NPCX, NPCY, NPCZ;
662 Standard_Real VRCX, VRCY, VRCZ, VRCT;
663 Standard_Real WCX, WCY, WCZ, WCT;
665 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
666 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
667 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
668 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
670 Standard_Real Dx, Dy, Ratio;
671 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
674 Standard_Integer stop = 0;
676 Standard_Boolean BResult;
678 j = MyDefinedView.Extent ();
680 while ((! stop) && (MyIterator.More ())) {
681 if (TheCView.ViewId ==
682 (MyIterator.Value ())->Identification ()) {
684 (MyIterator.Value ())->MatrixOfOrientation ();
686 (MyIterator.Value ())->MatrixOfMapping ();
690 // MyIterator.Next () is located on the next view
694 // View Mapping Transformation and View Clip, inversion
695 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
697 // View Orientation Transformation, inversion
698 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
700 // (AU, AV) : Device Coordinate Space
701 // DCS -> NPCS Normalized Projection Coordinate Space
702 Dx = Standard_Real (Width);
703 Dy = Standard_Real (Height);
707 NPCX = Standard_Real (AU) / Dx;
708 NPCY = (Dy - Standard_Real (AV)) / Dx;
711 NPCX = Standard_Real (AU) / Dy;
712 NPCY = (Dy - Standard_Real (AV)) / Dy;
716 // NPCS -> VRCS View Reference Coordinate Space
717 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
719 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
720 + TMap_Matrix_Inv (0, 1) * NPCY
721 + TMap_Matrix_Inv (0, 2) * NPCZ
722 + TMap_Matrix_Inv (0, 3);
723 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
724 + TMap_Matrix_Inv (1, 1) * NPCY
725 + TMap_Matrix_Inv (1, 2) * NPCZ
726 + TMap_Matrix_Inv (1, 3);
727 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
728 + TMap_Matrix_Inv (2, 1) * NPCY
729 + TMap_Matrix_Inv (2, 2) * NPCZ
730 + TMap_Matrix_Inv (2, 3);
731 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
732 + TMap_Matrix_Inv (3, 1) * NPCY
733 + TMap_Matrix_Inv (3, 2) * NPCZ
734 + TMap_Matrix_Inv (3, 3);
736 // VRCS -> WCS World Coordinate Space
737 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
739 WCX = TOri_Matrix_Inv (0, 0) * VRCX
740 + TOri_Matrix_Inv (0, 1) * VRCY
741 + TOri_Matrix_Inv (0, 2) * VRCZ
742 + TOri_Matrix_Inv (0, 3) * VRCT;
743 WCY = TOri_Matrix_Inv (1, 0) * VRCX
744 + TOri_Matrix_Inv (1, 1) * VRCY
745 + TOri_Matrix_Inv (1, 2) * VRCZ
746 + TOri_Matrix_Inv (1, 3) * VRCT;
747 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
748 + TOri_Matrix_Inv (2, 1) * VRCY
749 + TOri_Matrix_Inv (2, 2) * VRCZ
750 + TOri_Matrix_Inv (2, 3) * VRCT;
751 WCT = TOri_Matrix_Inv (3, 0) * VRCX
752 + TOri_Matrix_Inv (3, 1) * VRCY
753 + TOri_Matrix_Inv (3, 2) * VRCZ
754 + TOri_Matrix_Inv (3, 3) * VRCT;
757 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
759 Point.SetCoord (RealLast (), RealLast (), RealLast ());
767 void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {
769 // Conversion only if the data is correct
770 Graphic3d_CView TheCView;
772 if (! ViewExists (AWindow, TheCView)) {
773 Point.SetCoord (RealLast (), RealLast (), RealLast ());
774 Proj.SetCoord (0., 0., 0.);
777 Standard_Integer Width, Height;
778 Standard_ShortReal x, y, z;
779 Standard_ShortReal dx, dy, dz;
780 Standard_Boolean Result;
782 AWindow->Size (Width, Height);
784 Result = MyGraphicDriver->UnProjectRasterWithRay (TheCView,
786 AU, AV, x, y, z, dx, dy, dz);
788 // unproject is done by UnProjectRaster
791 (Standard_Real (x), Standard_Real (y), Standard_Real (z));
793 (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
796 // unproject cannot be done by UnProjectRaster
797 // Code is suspended since drivers Phigs are Pex abandoned.
800 Standard_Real NPCX, NPCY, NPCZ;
801 Standard_Real VRCX, VRCY, VRCZ, VRCT;
802 Standard_Real WCX, WCY, WCZ, WCT;
804 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
805 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
806 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
807 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
809 Standard_Real Dx, Dy, Ratio;
810 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
813 Standard_Integer stop = 0;
815 Standard_Boolean BResult;
817 j = MyDefinedView.Extent ();
819 while ((! stop) && (MyIterator.More ())) {
820 if (TheCView.ViewId ==
821 (MyIterator.Value ())->Identification ()) {
823 (MyIterator.Value ())->MatrixOfOrientation ();
825 (MyIterator.Value ())->MatrixOfMapping ();
829 // MyIterator.Next () is located on the next view
833 // View Mapping Transformation and View Clip, inversion
834 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
836 // View Orientation Transformation, inversion
837 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
839 // (AU, AV) : Device Coordinate Space
840 // DCS -> NPCS Normalized Projection Coordinate Space
841 Dx = Standard_Real (Width);
842 Dy = Standard_Real (Height);
846 NPCX = Standard_Real (AU) / Dx;
847 NPCY = (Dy - Standard_Real (AV)) / Dx;
850 NPCX = Standard_Real (AU) / Dy;
851 NPCY = (Dy - Standard_Real (AV)) / Dy;
855 // NPCS -> VRCS View Reference Coordinate Space
856 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
858 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
859 + TMap_Matrix_Inv (0, 1) * NPCY
860 + TMap_Matrix_Inv (0, 2) * NPCZ
861 + TMap_Matrix_Inv (0, 3);
862 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
863 + TMap_Matrix_Inv (1, 1) * NPCY
864 + TMap_Matrix_Inv (1, 2) * NPCZ
865 + TMap_Matrix_Inv (1, 3);
866 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
867 + TMap_Matrix_Inv (2, 1) * NPCY
868 + TMap_Matrix_Inv (2, 2) * NPCZ
869 + TMap_Matrix_Inv (2, 3);
870 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
871 + TMap_Matrix_Inv (3, 1) * NPCY
872 + TMap_Matrix_Inv (3, 2) * NPCZ
873 + TMap_Matrix_Inv (3, 3);
875 // VRCS -> WCS World Coordinate Space
876 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
878 WCX = TOri_Matrix_Inv (0, 0) * VRCX
879 + TOri_Matrix_Inv (0, 1) * VRCY
880 + TOri_Matrix_Inv (0, 2) * VRCZ
881 + TOri_Matrix_Inv (0, 3) * VRCT;
882 WCY = TOri_Matrix_Inv (1, 0) * VRCX
883 + TOri_Matrix_Inv (1, 1) * VRCY
884 + TOri_Matrix_Inv (1, 2) * VRCZ
885 + TOri_Matrix_Inv (1, 3) * VRCT;
886 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
887 + TOri_Matrix_Inv (2, 1) * VRCY
888 + TOri_Matrix_Inv (2, 2) * VRCZ
889 + TOri_Matrix_Inv (2, 3) * VRCT;
890 WCT = TOri_Matrix_Inv (3, 0) * VRCX
891 + TOri_Matrix_Inv (3, 1) * VRCY
892 + TOri_Matrix_Inv (3, 2) * VRCZ
893 + TOri_Matrix_Inv (3, 3) * VRCT;
896 Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
898 Point.SetCoord (RealLast (), RealLast (), RealLast ());
900 // Define projection ray
903 // NPCS -> VRCS View Reference Coordinate Space
904 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
906 VRCX = TMap_Matrix_Inv (0, 0) * NPCX
907 + TMap_Matrix_Inv (0, 1) * NPCY
908 + TMap_Matrix_Inv (0, 2) * NPCZ
909 + TMap_Matrix_Inv (0, 3);
910 VRCY = TMap_Matrix_Inv (1, 0) * NPCX
911 + TMap_Matrix_Inv (1, 1) * NPCY
912 + TMap_Matrix_Inv (1, 2) * NPCZ
913 + TMap_Matrix_Inv (1, 3);
914 VRCZ = TMap_Matrix_Inv (2, 0) * NPCX
915 + TMap_Matrix_Inv (2, 1) * NPCY
916 + TMap_Matrix_Inv (2, 2) * NPCZ
917 + TMap_Matrix_Inv (2, 3);
918 VRCT = TMap_Matrix_Inv (3, 0) * NPCX
919 + TMap_Matrix_Inv (3, 1) * NPCY
920 + TMap_Matrix_Inv (3, 2) * NPCZ
921 + TMap_Matrix_Inv (3, 3);
923 // VRCS -> WCS World Coordinate Space
924 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
926 WCX = TOri_Matrix_Inv (0, 0) * VRCX
927 + TOri_Matrix_Inv (0, 1) * VRCY
928 + TOri_Matrix_Inv (0, 2) * VRCZ
929 + TOri_Matrix_Inv (0, 3) * VRCT;
930 WCY = TOri_Matrix_Inv (1, 0) * VRCX
931 + TOri_Matrix_Inv (1, 1) * VRCY
932 + TOri_Matrix_Inv (1, 2) * VRCZ
933 + TOri_Matrix_Inv (1, 3) * VRCT;
934 WCZ = TOri_Matrix_Inv (2, 0) * VRCX
935 + TOri_Matrix_Inv (2, 1) * VRCY
936 + TOri_Matrix_Inv (2, 2) * VRCZ
937 + TOri_Matrix_Inv (2, 3) * VRCT;
938 WCT = TOri_Matrix_Inv (3, 0) * VRCX
939 + TOri_Matrix_Inv (3, 1) * VRCY
940 + TOri_Matrix_Inv (3, 2) * VRCZ
941 + TOri_Matrix_Inv (3, 3) * VRCT;
944 Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
948 Proj.SetCoord (0., 0., 0.);
955 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
957 Standard_Boolean Exist = Standard_False;
959 // Parse the list of views to find
960 // a view with the specified window
961 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
962 int TheWindowIdOfView;
965 const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
966 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
968 const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
969 int TheSpecifiedWindowId = int (THEWindow->HWindow ());
972 while ((! Exist) && (MyIterator.More ())) {
974 if ( ((MyIterator.Value ())->IsDefined ()) &&
975 ((MyIterator.Value ())->IsActive ()) ) {
977 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
979 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
980 TheWindowIdOfView = int (theWindow->XWindow ());
982 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
983 TheWindowIdOfView = int (theWindow->HWindow ());
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 MyViewGenId.Free(aViewId);
1067 void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
1069 if (MyTransparency && AFlag) return;
1070 if (! MyTransparency && ! AFlag) return;
1072 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1073 while (MyIterator.More ()) {
1074 (MyIterator.Value ())->SetTransparency (AFlag);
1075 // MyIterator.Next () is located on the next view
1079 MyTransparency = AFlag;
1083 Standard_Boolean Visual3d_ViewManager::Transparency () const {
1085 return (MyTransparency);
1089 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
1091 if (MyZBufferAuto && AFlag) return;
1092 if (! MyZBufferAuto && ! AFlag) return;
1094 // if pass from False to True :
1095 // no problem, at the next view update, it
1096 // will properly ask questions to answer (SetVisualisation)
1097 // if pass from True to False :
1098 // it is necessary to modify ZBufferActivity at each view so that
1099 // zbuffer could be active only if required by context.
1100 // In this case -1 is passed so that the view ask itself the question
1101 // Note : 0 forces the desactivation, 1 forces the activation
1103 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1104 while (MyIterator.More ()) {
1105 (MyIterator.Value ())->SetZBufferActivity (-1);
1106 // MyIterator.Next () is located on the next view
1110 MyZBufferAuto = AFlag;
1114 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
1116 return (MyZBufferAuto);
1120 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
1123 cout << "Visual3d_ViewManager::SetLayer\n" << flush;
1126 if (ALayer->Type () == Aspect_TOL_OVERLAY) {
1128 if (MyOverLayer.IsNull ())
1129 cout << "MyOverLayer is defined" << endl;
1131 cout << "MyOverLayer is redefined" << endl;
1133 MyOverLayer = ALayer;
1137 if (MyUnderLayer.IsNull ())
1138 cout << "MyUnderLayer is defined" << endl;
1140 cout << "MyUnderLayer is redefined" << endl;
1142 MyUnderLayer = ALayer;
1147 const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
1149 return (MyUnderLayer);
1153 const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
1155 return (MyOverLayer);
1159 //=======================================================================
1160 //function : ChangeZLayer
1162 //=======================================================================
1164 void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1165 const Standard_Integer theLayerId)
1167 if (!myLayerIds.Contains (theLayerId))
1170 // change display layer for structure in all views
1171 if (MyDisplayedStructure.Contains (theStructure))
1173 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1174 for ( ; aViewIt.More (); aViewIt.Next ())
1175 (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
1178 // tell graphic driver to update the structure's display layer
1179 MyGraphicDriver->ChangeZLayer (
1180 (*(Graphic3d_CStructure*)theStructure->CStructure ()), theLayerId);
1183 //=======================================================================
1184 //function : GetZLayer
1186 //=======================================================================
1188 Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
1190 Graphic3d_CStructure& aStructure =
1191 (*(Graphic3d_CStructure*)theStructure->CStructure ());
1193 return MyGraphicDriver->GetZLayer (aStructure);
1196 //=======================================================================
1197 //function : AddZLayer
1199 //=======================================================================
1201 Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
1206 theLayerId = getZLayerGenId ().Next ();
1207 myLayerIds.Add (theLayerId);
1208 myLayerSeq.Append (theLayerId);
1210 catch (Aspect_IdentDefinitionError)
1212 // new index can't be generated
1213 return Standard_False;
1216 // tell all managed views to remove display layers
1217 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1218 for ( ; aViewIt.More (); aViewIt.Next ())
1219 (aViewIt.Value ())->AddZLayer (theLayerId);
1221 return Standard_True;
1224 //=======================================================================
1225 //function : RemoveZLayer
1227 //=======================================================================
1229 Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
1231 if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
1232 return Standard_False;
1234 // tell all managed views to remove display layers
1235 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1236 for ( ; aViewIt.More (); aViewIt.Next ())
1237 (aViewIt.Value ())->RemoveZLayer (theLayerId);
1239 MyGraphicDriver->UnsetZLayer (theLayerId);
1242 for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
1243 if (myLayerSeq(aIdx) == theLayerId)
1245 myLayerSeq.Remove (aIdx);
1249 myLayerIds.Remove (theLayerId);
1250 getZLayerGenId ().Free (theLayerId);
1252 return Standard_True;
1255 //=======================================================================
1256 //function : GetAllZLayers
1258 //=======================================================================
1260 void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
1262 theLayerSeq.Assign (myLayerSeq);
1265 //=======================================================================
1266 //function : getZLayerGenId
1268 //=======================================================================
1270 Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
1272 static Aspect_GenId aGenId (1, IntegerLast());
1276 //=======================================================================
1277 //function : InstallZLayers
1279 //=======================================================================
1281 void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
1283 if (!MyDefinedView.Contains (theView))
1286 // erase and insert layers iteratively to provide the same layer order as
1287 // in the view manager's sequence. This approach bases on the layer insertion
1288 // order: the new layers are always appended to the end of the list
1289 // inside of view, while layer remove operation doesn't affect the order.
1290 // Starting from second layer : no need to change the default z layer.
1291 for (Standard_Integer aSeqIdx = 2; aSeqIdx <= myLayerSeq.Length (); aSeqIdx++)
1293 Standard_Integer aLayerID = myLayerSeq.Value (aSeqIdx);
1294 theView->RemoveZLayer (aLayerID);
1295 theView->AddZLayer (aLayerID);