0026885: Visualization - drop redundant aspects from structure level
[occt.git] / src / V3d / V3d.cxx
CommitLineData
b311480e 1// Created by: GG
2// Copyright (c) 1991-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
17// 02.15.100 : JR : Clutter
7fd59977 18//-Version
7fd59977 19//-Design
7fd59977 20//-Warning
7fd59977 21//-References
7fd59977 22//-Language C++ 2.1
7fd59977 23//-Declarations
7fd59977 24// for the class
7fd59977 25
7fd59977 26#include <Aspect_Grid.hxx>
27#include <Aspect_Window.hxx>
b8ddfc2f 28#include <Graphic3d_ArrayOfPolylines.hxx>
7fd59977 29#include <Graphic3d_AspectLine3d.hxx>
30#include <Graphic3d_AspectText3d.hxx>
42cf5bc1 31#include <Graphic3d_Group.hxx>
32#include <Graphic3d_Structure.hxx>
33#include <Graphic3d_Vector.hxx>
34#include <Quantity_NameOfColor.hxx>
35#include <V3d.hxx>
36#include <V3d_View.hxx>
37#include <V3d_Viewer.hxx>
7fd59977 38
39Graphic3d_Vector V3d::GetProjAxis(const V3d_TypeOfOrientation Orientation) {
40Standard_Real Xpn=0,Ypn=0,Zpn=0 ;
41Graphic3d_Vector Vec ;
42
43 switch (Orientation) {
44 case V3d_Xpos :
45 Xpn = 1. ; Ypn = 0. ; Zpn = 0. ;
46 break ;
47 case V3d_Ypos :
48 Xpn = 0. ; Ypn = 1. ; Zpn = 0. ;
49 break ;
50 case V3d_Zpos :
51 Xpn = 0. ; Ypn = 0. ; Zpn = 1. ;
52 break ;
53 case V3d_Xneg :
54 Xpn = -1. ; Ypn = 0. ; Zpn = 0. ;
55 break ;
56 case V3d_Yneg :
57 Xpn = 0. ; Ypn = -1. ; Zpn = 0. ;
58 break ;
59 case V3d_Zneg :
60 Xpn = 0. ; Ypn = 0. ; Zpn = -1. ;
61 break ;
62 case V3d_XposYposZpos :
63 Xpn = 1. ; Ypn = 1. ; Zpn = 1. ;
64 break ;
65 case V3d_XposYposZneg :
66 Xpn = 1. ; Ypn = 1. ; Zpn = -1. ;
67 break ;
68 case V3d_XposYnegZpos :
69 Xpn = 1. ; Ypn = -1. ; Zpn = 1. ;
70 break ;
71 case V3d_XposYnegZneg :
72 Xpn = 1. ; Ypn = -1. ; Zpn = -1. ;
73 break ;
74 case V3d_XnegYposZpos :
75 Xpn = -1. ; Ypn = 1. ; Zpn = 1. ;
76 break ;
77 case V3d_XnegYposZneg :
78 Xpn = -1. ; Ypn = 1. ; Zpn = -1. ;
79 break ;
80 case V3d_XnegYnegZpos :
81 Xpn = -1. ; Ypn = -1. ; Zpn = 1. ;
82 break ;
83 case V3d_XnegYnegZneg :
84 Xpn = -1. ; Ypn = -1. ; Zpn = -1. ;
85 break ;
86 case V3d_XposYpos :
87 Xpn = 1. ; Ypn = 1. ; Zpn = 0. ;
88 break ;
89 case V3d_XposYneg :
90 Xpn = 1. ; Ypn = -1. ; Zpn = 0. ;
91 break ;
92 case V3d_XnegYpos :
93 Xpn = -1. ; Ypn = 1. ; Zpn = 0. ;
94 break ;
95 case V3d_XnegYneg :
96 Xpn = -1. ; Ypn = -1. ; Zpn = 0. ;
97 break ;
98 case V3d_XposZpos :
99 Xpn = 1. ; Ypn = 0. ; Zpn = 1. ;
100 break ;
101 case V3d_XposZneg :
102 Xpn = 1. ; Ypn = 0. ; Zpn = -1. ;
103 break ;
104 case V3d_XnegZpos :
105 Xpn = -1. ; Ypn = 0. ; Zpn = 1. ;
106 break ;
107 case V3d_XnegZneg :
108 Xpn = -1. ; Ypn = 0. ; Zpn = -1. ;
109 break ;
110 case V3d_YposZpos :
111 Xpn = 0. ; Ypn = 1. ; Zpn = 1. ;
112 break ;
113 case V3d_YposZneg :
114 Xpn = 0. ; Ypn = 1. ; Zpn = -1. ;
115 break ;
116 case V3d_YnegZpos :
117 Xpn = 0. ; Ypn = -1. ; Zpn = 1. ;
118 break ;
119 case V3d_YnegZneg :
120 Xpn = 0. ; Ypn = -1. ; Zpn = -1. ;
121 break ;
122 }
123 Vec.SetCoord(Xpn,Ypn,Zpn) ; Vec.Normalize() ;
124 return Vec ;
125}
126
b8ddfc2f 127void 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)
128{
1d47d8d0 129 Standard_Real Xc, Yc, Zc, Xi, Yi, Zi, Xj, Yj, Zj;
130 Standard_Real Xn, Yn, Zn, X, Y, Z, X1 = 0., Y1 = 0., Z1 = 0., Norme;
b8ddfc2f 131 const Standard_Integer NbPoints = 10;
7fd59977 132
133// Centre du cercle base de la fleche :
b8ddfc2f 134 Xc = X0 - Dx * Lng;
135 Yc = Y0 - Dy * Lng;
136 Zc = Z0 - Dz * Lng;
7fd59977 137
138// Construction d'un repere i,j pour le cercle:
b8ddfc2f 139 Xn=0., Yn=0., Zn=0.;
140
141 if ( Abs(Dx) <= Abs(Dy) && Abs(Dx) <= Abs(Dz)) Xn=1.;
142 else if ( Abs(Dy) <= Abs(Dz) && Abs(Dy) <= Abs(Dx)) Yn=1.;
143 else Zn=1.;
144 Xi = Dy * Zn - Dz * Yn;
145 Yi = Dz * Xn - Dx * Zn;
146 Zi = Dx * Yn - Dy * Xn;
147
148 Norme = Sqrt ( Xi*Xi + Yi*Yi + Zi*Zi );
149 Xi= Xi / Norme; Yi = Yi / Norme; Zi = Zi/Norme;
150
151 Xj = Dy * Zi - Dz * Yi;
152 Yj = Dz * Xi - Dx * Zi;
153 Zj = Dx * Yi - Dy * Xi;
154
155 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(3*NbPoints,NbPoints);
156
157 Standard_Integer i;
158 const Standard_Real Tg = Tan(Alpha);
159 for (i = 1; i <= NbPoints; i++)
160 {
161 const Standard_Real cosinus = Cos ( 2. * M_PI / NbPoints * (i-1) );
162 const Standard_Real sinus = Sin ( 2. * M_PI / NbPoints * (i-1) );
163
164 X = Xc + (cosinus * Xi + sinus * Xj) * Lng * Tg;
165 Y = Yc + (cosinus * Yi + sinus * Yj) * Lng * Tg;
166 Z = Zc + (cosinus * Zi + sinus * Zj) * Lng * Tg;
167
168 if(i==1) { X1=X, Y1=Y, Z1=Z; }
169 else aPrims->AddVertex(X,Y,Z);
170 aPrims->AddBound(3);
171 aPrims->AddVertex(X0,Y0,Z0);
172 aPrims->AddVertex(X,Y,Z);
173 }
174 aPrims->AddVertex(X1,Y1,Z1);
7fd59977 175
b8ddfc2f 176 garrow->AddPrimitiveArray(aPrims);
7fd59977 177}
178
179
b8ddfc2f 180void 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)
181{
182 Standard_Real Norme = Sqrt ( DX*DX + DY*DY + DZ*DZ );
183 if ( Norme >= 0.0001 )
184 {
185 Standard_Real VX,VY,VZ,X,Y,Z,Xn,Yn,Zn,Xi,Yi,Zi,Xj,Yj,Zj;
7fd59977 186
b8ddfc2f 187 VX= DX/Norme; VY = DY/Norme; VZ = DZ/Norme;
7fd59977 188
81bba717 189//Construction of marker i,j for the circle:
b8ddfc2f 190 Xn=0., Yn=0., Zn=0.;
191 if ( Abs(VX) <= Abs(VY) && Abs(VX) <= Abs(VZ)) Xn=1.;
192 else if ( Abs(VY) <= Abs(VZ) && Abs(VY) <= Abs(VX)) Yn=1.;
193 else Zn=1.;
194 Xi = VY * Zn - VZ * Yn;
195 Yi = VZ * Xn - VX * Zn;
196 Zi = VX * Yn - VY * Xn;
197
198 Norme = Sqrt ( Xi*Xi + Yi*Yi + Zi*Zi );
199 Xi= Xi / Norme; Yi = Yi / Norme; Zi = Zi/Norme;
200
201 Xj = VY * Zi - VZ * Yi;
202 Yj = VZ * Xi - VX * Zi;
203 Zj = VX * Yi - VY * Xi;
204
205 const Standard_Integer NFACES = 30;
206 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NFACES+1);
207
208 Standard_Integer i = 0;
209 Standard_Real Alpha = 0.;
210 const Standard_Real Dalpha = 2. * M_PI / NFACES;
211 for (; i <= NFACES; i++, Alpha += Dalpha)
212 {
213 const Standard_Real cosinus = Cos(Alpha);
214 const Standard_Real sinus = Sin(Alpha);
215
216 X = X0 + (cosinus * Xi + sinus * Xj) * Rayon;
217 Y = Y0 + (cosinus * Yi + sinus * Yj) * Rayon;
218 Z = Z0 + (cosinus * Zi + sinus * Zj) * Rayon;
219
220 aPrims->AddVertex(X,Y,Z);
221 }
222 gcircle->AddPrimitiveArray(aPrims);
223 }
7fd59977 224}
225
226
227void V3d::SwitchViewsinWindow(const Handle(V3d_View)& aPreviousView,
228 const Handle(V3d_View)& aNextView) {
229 aPreviousView->Viewer()->SetViewOff(aPreviousView);
230 if(!aNextView->IfWindow())
231 aNextView->SetWindow(aPreviousView->Window());
232 aNextView->Viewer()->SetViewOn(aNextView);
233
234}