b2af02988aadcb497eee094c25a2cadd5ede7812
[occt.git] / src / V3d / V3d_Viewer_3.cxx
1 /***********************************************************************
2  
3      FONCTION :
4      ----------
5         Classe V3d_Viewer_3.cxx :
6  
7      HISTORIQUE DES MODIFICATIONS   :
8      --------------------------------
9       00-09-92 : GG  ; Creation.
10       27-12-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
11
12      REMARQUES :
13      -----------
14  
15 ************************************************************************/
16
17 #define IMP240300       //GG 
18 //                      -> Remove the grid plane axis when it is requested.
19 //                      -> Redraw the privilegied grid plane after any change
20
21 /*----------------------------------------------------------------------*/
22 /*
23  * Includes
24  */
25
26 #include <V3d_Viewer.jxx>
27
28 #include <Graphic3d_AspectLine3d.hxx>
29 #include <Graphic3d_AspectText3d.hxx>
30 #include <gp_Dir.hxx>
31 #include <gp_Pnt.hxx>
32 #include <Graphic3d_Structure.hxx>
33 #include <Graphic3d_Group.hxx>
34
35 #include <Graphic3d_Array1OfVertex.hxx>
36
37 /*----------------------------------------------------------------------*/
38 /*
39  * Static variable
40  */
41
42 #define LOPTIM
43 #ifndef LOPTIM
44 static TCollection_AsciiString XLetter("X");
45 static TCollection_AsciiString YLetter("Y");
46 static TCollection_AsciiString ZLetter("Z");
47 #else 
48 static TCollection_AsciiString _XLetter() {
49     static TCollection_AsciiString XLetter("X");
50 return XLetter;
51 }
52 #define XLetter _XLetter()
53
54 static TCollection_AsciiString _YLetter() {
55     static TCollection_AsciiString YLetter("Y");
56 return YLetter;
57 }
58 #define YLetter _YLetter()
59
60 static TCollection_AsciiString _ZLetter() {
61     static TCollection_AsciiString ZLetter("Z");
62 return ZLetter;
63 }
64 #define ZLetter _ZLetter()
65
66 #endif // LOPTIM
67
68 /*----------------------------------------------------------------------*/
69
70 void V3d_Viewer::SetPrivilegedPlane(const gp_Ax3& aPlane) {
71   myPrivilegedPlane = aPlane;
72 #ifdef IMP240300
73   Grid()->SetDrawMode(Grid()->DrawMode());
74   for (InitActiveViews (); MoreActiveViews (); NextActiveViews ()) {
75     ActiveView ()->SetGrid (myPrivilegedPlane, Grid ());
76   }
77 #endif
78   if(myDisplayPlane) {
79     Standard_Real s = myDisplayPlaneLength;
80     DisplayPrivilegedPlane(Standard_True,s);
81 #ifdef IMP240300        
82   } else {
83     Update();
84 #else
85     Update();
86 #endif
87   }
88 }
89
90 /*----------------------------------------------------------------------*/
91 gp_Ax3  V3d_Viewer::PrivilegedPlane() const {
92   return myPrivilegedPlane;
93     
94 }
95
96 /*----------------------------------------------------------------------*/
97 void V3d_Viewer::DisplayPrivilegedPlane(const Standard_Boolean OnOff, const Quantity_Length aSize) {
98   Standard_Boolean Change =  myDisplayPlane != OnOff;
99   myDisplayPlane = OnOff;
100   myDisplayPlaneLength = aSize;
101
102   if(myDisplayPlane) {
103     if(myPlaneStructure.IsNull()) {
104       myPlaneStructure = new Graphic3d_Structure(MyViewer);
105       myPlaneStructure->SetInfiniteState(Standard_True);
106       myPlaneStructure->Display();
107     }
108     else
109       myPlaneStructure->Clear();
110     
111 //    Handle(Graphic3d_Structure) thePlaneStructure = new Graphic3d_Structure(MyViewer);
112     Handle(Graphic3d_Group) Group = new Graphic3d_Group(myPlaneStructure) ;
113
114     Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d() ;
115     LineAttrib->SetColor(Quantity_Color(Quantity_NOC_GRAY60));
116     Group->SetPrimitivesAspect(LineAttrib) ;
117
118     Handle(Graphic3d_AspectText3d) TextAttrib = new Graphic3d_AspectText3d();
119     TextAttrib->SetColor(Quantity_Color(Quantity_NOC_ROYALBLUE1));
120     Group->SetPrimitivesAspect(TextAttrib);
121     
122     Graphic3d_Array1OfVertex Points(0,1) ;
123     Standard_Real xl,yl,zl;
124     myPrivilegedPlane.Location().Coord(xl,yl,zl);
125     Points(0).SetCoord(xl,yl,zl);
126
127     Standard_Real ay,by,cy;
128
129     myPrivilegedPlane.XDirection().Coord(ay,by,cy);
130     Points(1).SetCoord(xl+myDisplayPlaneLength*ay,
131                        yl+myDisplayPlaneLength*by,
132                        zl+myDisplayPlaneLength*cy);
133     Group->Polyline(Points);
134     Group->Text(XLetter.ToCString(),Points(1),1./81.);
135
136     myPrivilegedPlane.YDirection().Coord(ay,by,cy);
137     Points(1).SetCoord(xl+myDisplayPlaneLength*ay,
138                        yl+myDisplayPlaneLength*by,
139                        zl+myDisplayPlaneLength*cy);
140     Group->Polyline(Points);
141     Group->Text(YLetter.ToCString(),Points(1),1./81.);
142     
143     myPrivilegedPlane.Direction().Coord(ay,by,cy);
144     Points(1).SetCoord(xl+myDisplayPlaneLength*ay,
145                        yl+myDisplayPlaneLength*by,
146                        zl+myDisplayPlaneLength*cy);
147     Group->Polyline(Points);
148     Group->Text(ZLetter.ToCString(),Points(1),1./81.);
149 #ifdef IMP240300
150     myPlaneStructure->Display();
151   } else {
152     if( !myPlaneStructure.IsNull() )  myPlaneStructure->Erase();
153 #endif
154   }
155   if(Change) Update();
156 }
157
158 /*----------------------------------------------------------------------*/