79d89c7e16f6e8a55e7c52da9134edbc74b9bc36
[occt.git] / src / V3d / V3d.cxx
1 // Created by: GG
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 // Modified     23/02/98 : FMN ; Remplacement PI par Standard_PI
17 //              02.15.100 : JR : Clutter
18 //-Version
19 //-Design       
20 //-Warning     
21 //-References
22 //-Language     C++ 2.1
23 //-Declarations
24 // for the class
25
26 #include <Aspect_Grid.hxx>
27 #include <Aspect_Window.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
29 #include <Graphic3d_AspectLine3d.hxx>
30 #include <Graphic3d_AspectText3d.hxx>
31 #include <Graphic3d_Group.hxx>
32 #include <Graphic3d_Structure.hxx>
33 #include <Quantity_NameOfColor.hxx>
34 #include <V3d.hxx>
35 #include <V3d_View.hxx>
36 #include <V3d_Viewer.hxx>
37
38 void V3d::ArrowOfRadius(const Handle(Graphic3d_Group)& garrow,const Standard_Real X0,const Standard_Real Y0,const Standard_Real Z0,const Standard_Real Dx,const Standard_Real Dy,const Standard_Real Dz,const Standard_Real Alpha,const Standard_Real Lng)
39 {
40   Standard_Real Xc, Yc, Zc, Xi, Yi, Zi, Xj, Yj, Zj;
41   Standard_Real Xn, Yn, Zn, X, Y, Z, X1 = 0., Y1 = 0., Z1 = 0., Norme;
42   const Standard_Integer NbPoints = 10;
43
44 //      Centre du cercle base de la fleche :
45   Xc = X0 - Dx * Lng;
46   Yc = Y0 - Dy * Lng;
47   Zc = Z0 - Dz * Lng;
48
49 //      Construction d'un repere i,j pour le cercle:
50   Xn=0., Yn=0., Zn=0.;
51
52   if ( Abs(Dx) <= Abs(Dy) && Abs(Dx) <= Abs(Dz)) Xn=1.;
53   else if ( Abs(Dy) <= Abs(Dz) && Abs(Dy) <= Abs(Dx)) Yn=1.;
54   else Zn=1.;
55   Xi = Dy * Zn - Dz * Yn;
56   Yi = Dz * Xn - Dx * Zn;
57   Zi = Dx * Yn - Dy * Xn;
58
59   Norme = Sqrt ( Xi*Xi + Yi*Yi + Zi*Zi );
60   Xi= Xi / Norme; Yi = Yi / Norme; Zi = Zi/Norme;
61
62   Xj = Dy * Zi - Dz * Yi;
63   Yj = Dz * Xi - Dx * Zi;
64   Zj = Dx * Yi - Dy * Xi;
65
66   Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(3*NbPoints,NbPoints);
67
68   Standard_Integer i;
69   const Standard_Real Tg = Tan(Alpha);
70   for (i = 1; i <= NbPoints; i++)
71   {
72     const Standard_Real cosinus = Cos ( 2. * M_PI / NbPoints * (i-1) );
73     const Standard_Real sinus = Sin ( 2. * M_PI / NbPoints * (i-1) );
74
75     X = Xc + (cosinus * Xi + sinus * Xj) * Lng * Tg;
76     Y = Yc + (cosinus * Yi + sinus * Yj) * Lng * Tg;
77     Z = Zc + (cosinus * Zi + sinus * Zj) * Lng * Tg;
78
79     if(i==1) { X1=X, Y1=Y, Z1=Z; }
80     else aPrims->AddVertex(X,Y,Z);
81     aPrims->AddBound(3);
82     aPrims->AddVertex(X0,Y0,Z0);
83     aPrims->AddVertex(X,Y,Z);
84   }
85   aPrims->AddVertex(X1,Y1,Z1);
86
87   garrow->AddPrimitiveArray(aPrims);
88 }
89
90
91 void V3d::CircleInPlane(const Handle(Graphic3d_Group)& gcircle,const Standard_Real X0,const Standard_Real Y0,const Standard_Real Z0,const Standard_Real DX,const Standard_Real DY,const Standard_Real DZ,const Standard_Real Rayon)
92 {
93   Standard_Real Norme = Sqrt ( DX*DX + DY*DY + DZ*DZ );
94   if ( Norme >= 0.0001 )
95   {
96     Standard_Real VX,VY,VZ,X,Y,Z,Xn,Yn,Zn,Xi,Yi,Zi,Xj,Yj,Zj;
97
98     VX= DX/Norme; VY = DY/Norme; VZ = DZ/Norme;
99
100 //Construction of marker i,j for the circle:
101     Xn=0., Yn=0., Zn=0.;   
102     if ( Abs(VX) <= Abs(VY) && Abs(VX) <= Abs(VZ)) Xn=1.;
103     else if ( Abs(VY) <= Abs(VZ) && Abs(VY) <= Abs(VX)) Yn=1.;
104     else Zn=1.;
105     Xi = VY * Zn - VZ * Yn;
106     Yi = VZ * Xn - VX * Zn;
107     Zi = VX * Yn - VY * Xn;
108
109     Norme = Sqrt ( Xi*Xi + Yi*Yi + Zi*Zi );
110     Xi= Xi / Norme; Yi = Yi / Norme; Zi = Zi/Norme;
111
112     Xj = VY * Zi - VZ * Yi;
113     Yj = VZ * Xi - VX * Zi;
114     Zj = VX * Yi - VY * Xi;      
115
116     const Standard_Integer NFACES = 30;
117     Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NFACES+1);
118
119     Standard_Integer i = 0;
120     Standard_Real Alpha = 0.;
121     const Standard_Real Dalpha = 2. * M_PI / NFACES;
122     for (; i <= NFACES; i++, Alpha += Dalpha)
123     {
124       const Standard_Real cosinus = Cos(Alpha);
125       const Standard_Real sinus = Sin(Alpha);
126
127       X = X0 + (cosinus * Xi + sinus * Xj) * Rayon;
128       Y = Y0 + (cosinus * Yi + sinus * Yj) * Rayon;
129       Z = Z0 + (cosinus * Zi + sinus * Zj) * Rayon;
130
131       aPrims->AddVertex(X,Y,Z);
132     }
133     gcircle->AddPrimitiveArray(aPrims);
134   }
135 }
136
137
138 void V3d::SwitchViewsinWindow(const Handle(V3d_View)& aPreviousView,
139                               const Handle(V3d_View)& aNextView) {
140   aPreviousView->Viewer()->SetViewOff(aPreviousView);
141   if(!aNextView->IfWindow())
142     aNextView->SetWindow(aPreviousView->Window());
143   aNextView->Viewer()->SetViewOn(aNextView);
144     
145 }