Commit | Line | Data |
---|---|---|
7fd59977 | 1 | /*********************************************************************** |
2 | ||
3 | FONCTION : | |
4 | ---------- | |
5 | Classe V3d_SpotLight : | |
6 | ||
7 | HISTORIQUE DES MODIFICATIONS : | |
8 | -------------------------------- | |
9 | 00-09-92 : GG ; Creation. | |
10 | 18-06-96 : FMN ; Ajout MyGraphicStructure1 pour sauvegarder snopick | |
11 | 30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods) | |
12 | 02.15.100 : JR : Clutter | |
13 | ||
14 | ************************************************************************/ | |
15 | ||
16 | /*----------------------------------------------------------------------*/ | |
17 | /* | |
18 | * Includes | |
19 | */ | |
20 | ||
21 | #include <V3d.hxx> | |
22 | #include <V3d_SpotLight.ixx> | |
23 | #include <Graphic3d_Vector.hxx> | |
24 | #include <Graphic3d_Vertex.hxx> | |
25 | #include <Graphic3d_Structure.hxx> | |
26 | #include <Graphic3d_Group.hxx> | |
27 | #include <Graphic3d_Array1OfVertex.hxx> | |
28 | #include <Graphic3d_AspectMarker3d.hxx> | |
29 | #include <Graphic3d_AspectLine3d.hxx> | |
30 | #include <Graphic3d_AspectText3d.hxx> | |
31 | #include <Visual3d_Light.hxx> | |
32 | #include <Visual3d_ViewManager.hxx> | |
33 | #include <Visual3d_ContextPick.hxx> | |
34 | #include <Visual3d_PickDescriptor.hxx> | |
35 | #include <Visual3d_HSequenceOfPickPath.hxx> | |
36 | #include <Visual3d_PickPath.hxx> | |
37 | #include <gp_Dir.hxx> | |
38 | #include <gp_Ax1.hxx> | |
39 | #include <gp_Vec.hxx> | |
40 | #include <gp_Pnt.hxx> | |
41 | #include <gp_Trsf.hxx> | |
42 | #include <TCollection_AsciiString.hxx> | |
43 | ||
44 | #ifdef WNT | |
45 | # include <WNT_Window.hxx> | |
46 | #else | |
47 | # include <Xw_Window.hxx> | |
48 | #endif | |
49 | ||
50 | ||
51 | V3d_SpotLight::V3d_SpotLight(const Handle(V3d_Viewer)& VM, const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const V3d_TypeOfOrientation Direction, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2, const Standard_Real CN, const Standard_Real AN):V3d_PositionLight(VM) { | |
52 | ||
53 | Viewer_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 | |
c6541a0c | 54 | || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle"); |
7fd59977 | 55 | |
56 | Quantity_Color C(Name) ; | |
57 | Graphic3d_Vector D = V3d::GetProjAxis(Direction) ; | |
58 | Graphic3d_Vertex P(X,Y,Z) ; | |
59 | Graphic3d_Vertex T; | |
60 | ||
61 | MyType = V3d_SPOT ; | |
62 | MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ; | |
81bba717 | 63 | // The target is fixed, starting from the light position and the direction. |
7fd59977 | 64 | T.SetCoord(X + D.X(), Y + D.Y(), Z + D.Z()); |
65 | MyTarget = T; | |
66 | } | |
67 | ||
68 | V3d_SpotLight::V3d_SpotLight(const Handle(V3d_Viewer)& VM, const Standard_Real Xt, const Standard_Real Yt, const Standard_Real Zt, const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2, const Standard_Real CN, const Standard_Real AN):V3d_PositionLight(VM) { | |
69 | ||
70 | Viewer_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 | |
c6541a0c | 71 | || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle"); |
7fd59977 | 72 | |
73 | Quantity_Color C(Name) ; | |
74 | Graphic3d_Vertex T(Xt,Yt,Zt) ; | |
75 | Graphic3d_Vertex P(Xp,Yp,Zp) ; | |
76 | Graphic3d_Vector D(P,T); | |
77 | ||
78 | MyType = V3d_SPOT ; | |
79 | D.Normalize(); | |
80 | MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ; | |
81 | MyTarget = T; | |
82 | // La Structure graphique sera initialisee lors de l'affichage. | |
83 | } | |
84 | ||
85 | ||
86 | //-Methods, in order | |
87 | ||
88 | void V3d_SpotLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) { | |
89 | MyLight->SetPosition (Graphic3d_Vertex (Xp,Yp,Zp)); | |
90 | } | |
91 | ||
92 | void V3d_SpotLight::SetDirection(const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) { | |
93 | ||
94 | Graphic3d_Vector D ; | |
95 | D.SetCoord(Vx,Vy,Vz) ; D.Normalize() ; | |
96 | MyLight->SetDirection(D) ; | |
97 | } | |
98 | ||
99 | void V3d_SpotLight::SetDirection(const V3d_TypeOfOrientation Direction) { | |
100 | ||
101 | Graphic3d_Vector D = V3d::GetProjAxis(Direction) ; | |
102 | MyLight->SetDirection(D) ; | |
103 | } | |
104 | ||
105 | void V3d_SpotLight::SetAttenuation(const Standard_Real A1, const Standard_Real A2) { | |
106 | ||
107 | Viewer_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 , | |
108 | "V3d_SpotLight::SetAttenuation, bad coefficients"); | |
109 | ||
110 | MyLight->SetAttenuation1(A1) ; | |
111 | MyLight->SetAttenuation2(A2) ; | |
112 | } | |
113 | ||
114 | void V3d_SpotLight::SetConcentration(const Standard_Real C) { | |
115 | ||
116 | ||
117 | Viewer_BadValue_Raise_if( C < 0 || C > 1., | |
118 | "V3d_SpotLight::SetConcentration, bad coefficient"); | |
119 | ||
120 | MyLight->SetConcentration(C) ; | |
121 | } | |
122 | ||
123 | void V3d_SpotLight::SetAngle(const Standard_Real Angle) { | |
124 | ||
c6541a0c | 125 | Viewer_BadValue_Raise_if( Angle <= 0. || Angle >= M_PI, |
7fd59977 | 126 | "V3d_SpotLight::SetAngle, bad angle"); |
127 | MyLight->SetAngle(Angle) ; | |
128 | ||
129 | } | |
130 | ||
131 | void V3d_SpotLight::Direction(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz)const { | |
132 | ||
133 | Quantity_Color C ; | |
134 | Graphic3d_Vector D ; | |
135 | Graphic3d_Vertex P ; | |
136 | Standard_Real CN,A1,A2,AN ; | |
137 | ||
138 | MyLight->Values(C,P,D,CN,A1,A2,AN) ; | |
139 | D.Coord(Vx,Vy,Vz) ; | |
140 | } | |
141 | ||
142 | void V3d_SpotLight::Position(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const { | |
143 | ||
144 | Quantity_Color C ; | |
145 | Graphic3d_Vector D ; | |
146 | Graphic3d_Vertex P ; | |
147 | Standard_Real CN,A1,A2,AN ; | |
148 | ||
149 | MyLight->Values(C,P,D,CN,A1,A2,AN) ; | |
150 | P.Coord(Xp,Yp,Zp) ; | |
151 | } | |
152 | ||
153 | void V3d_SpotLight::Attenuation(Standard_Real& A1, Standard_Real& A2) const { | |
154 | Quantity_Color C ; | |
155 | Graphic3d_Vector D ; | |
156 | Graphic3d_Vertex P ; | |
157 | Standard_Real CN,AN ; | |
158 | ||
159 | MyLight->Values(C,P,D,CN,A1,A2,AN) ; | |
160 | } | |
161 | ||
162 | Standard_Real V3d_SpotLight::Concentration()const { | |
163 | ||
164 | Quantity_Color C ; | |
165 | Graphic3d_Vector D ; | |
166 | Graphic3d_Vertex P ; | |
167 | Standard_Real AN,A1,A2,CN ; | |
168 | ||
169 | MyLight->Values(C,P,D,CN,A1,A2,AN) ; | |
170 | return CN ; | |
171 | } | |
172 | ||
173 | Standard_Real V3d_SpotLight::Angle()const { | |
174 | ||
175 | Quantity_Color C ; | |
176 | Graphic3d_Vector D ; | |
177 | Graphic3d_Vertex P ; | |
178 | Standard_Real CN,A1,A2,AN ; | |
179 | ||
180 | MyLight->Values(C,P,D,CN,A1,A2,AN) ; | |
181 | return AN ; | |
182 | } | |
183 | ||
184 | void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, | |
185 | // const Handle(V3d_View)& aView) const { | |
186 | const Handle(V3d_View)& ) const { | |
187 | ||
188 | Standard_Real X,Y,Z,Rayon; | |
189 | Standard_Real DX,DY,DZ; | |
190 | ||
191 | this->Position(X,Y,Z); | |
192 | this->Direction(DX,DY,DZ); | |
193 | Rayon = this->Radius(); | |
c6541a0c | 194 | V3d::ArrowOfRadius(gsymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,Rayon/15.); |
7fd59977 | 195 | } |
196 | ||
197 | void V3d_SpotLight::Display( const Handle(V3d_View)& aView, | |
198 | const V3d_TypeOfRepresentation TPres) { | |
199 | ||
200 | Graphic3d_Array1OfVertex PRadius(0,1); | |
201 | Graphic3d_Vertex PText ; | |
202 | Standard_Real X,Y,Z,Rayon; | |
203 | Standard_Real X0,Y0,Z0,VX,VY,VZ; | |
204 | Standard_Real X1,Y1,Z1; | |
205 | Standard_Real DXRef,DYRef,DZRef,DXini,DYini,DZini; | |
206 | Standard_Real R1,G1,B1; | |
207 | V3d_TypeOfRepresentation Pres; | |
208 | V3d_TypeOfUpdate UpdSov; | |
209 | ||
81bba717 | 210 | // Creation of a structure slight of markable elements (position of the |
211 | // light, and the domain of lighting represented by a circle) | |
212 | // Creation of a structure snopick of non-markable elements (target, meridian and | |
213 | // parallel).// | |
7fd59977 | 214 | |
215 | Pres = TPres; | |
216 | Handle(V3d_Viewer) TheViewer = aView->Viewer(); | |
217 | UpdSov = TheViewer->UpdateMode(); | |
218 | TheViewer->SetUpdateMode(V3d_WAIT); | |
219 | if (!MyGraphicStructure.IsNull()) { | |
220 | MyGraphicStructure->Disconnect(MyGraphicStructure1); | |
221 | MyGraphicStructure->Clear(); | |
222 | MyGraphicStructure1->Clear(); | |
223 | if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation; | |
224 | } | |
225 | else { | |
226 | if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE; | |
227 | Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer()); | |
228 | MyGraphicStructure = slight; | |
229 | Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer()); | |
230 | MyGraphicStructure1 = snopick; | |
231 | } | |
232 | ||
233 | Handle(Graphic3d_Group) gradius; | |
234 | Handle(Graphic3d_Group) gExtArrow; | |
235 | Handle(Graphic3d_Group) gIntArrow; | |
236 | if (Pres == V3d_COMPLETE) { | |
237 | gradius = new Graphic3d_Group(MyGraphicStructure); | |
238 | gExtArrow = new Graphic3d_Group(MyGraphicStructure); | |
239 | gIntArrow = new Graphic3d_Group(MyGraphicStructure); | |
240 | } | |
241 | Handle(Graphic3d_Group) glight = new Graphic3d_Group(MyGraphicStructure); | |
242 | Handle(Graphic3d_Group) gsphere; | |
243 | if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) gsphere = new Graphic3d_Group(MyGraphicStructure); | |
244 | ||
245 | Handle(Graphic3d_Group) gnopick = new Graphic3d_Group(MyGraphicStructure1); | |
246 | MyGraphicStructure1->SetPick(Standard_False); | |
247 | ||
248 | X0 = MyTarget.X(); | |
249 | Y0 = MyTarget.Y(); | |
250 | Z0 = MyTarget.Z(); | |
251 | ||
81bba717 | 252 | //Display of the position of the light. |
7fd59977 | 253 | |
7fd59977 | 254 | this->Color(Quantity_TOC_RGB,R1,G1,B1); |
255 | Quantity_Color Col1(R1,G1,B1,Quantity_TOC_RGB); | |
256 | Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d(); | |
257 | Asp1->SetColor(Col1); | |
258 | glight->SetPrimitivesAspect(Asp1); | |
259 | this->Symbol(glight,aView); | |
260 | ||
81bba717 | 261 | // Display of the reference sphere (limited by circle). |
7fd59977 | 262 | |
263 | if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { | |
264 | ||
265 | Rayon = this->Radius(); | |
266 | aView->Proj(VX,VY,VZ); | |
7fd59977 | 267 | V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon); |
268 | ||
81bba717 | 269 | // Display of the radius of the sphere (line + text) |
7fd59977 | 270 | |
271 | if (Pres == V3d_COMPLETE) { | |
7fd59977 | 272 | PRadius(0).SetCoord(X0,Y0,Z0); |
273 | this->Position(X,Y,Z); | |
274 | PRadius(1).SetCoord(X,Y,Z); | |
275 | gnopick->Polyline(PRadius); | |
276 | V3d::ArrowOfRadius(gExtArrow,X-(X-X0)/10., | |
277 | Y-(Y-Y0)/10., | |
c6541a0c D |
278 | Z-(Z-Z0) / 10., X-X0, Y-Y0, Z-Z0, M_PI / 15., Rayon / 20.); |
279 | V3d::ArrowOfRadius(gIntArrow, X0, Y0, Z0, X0-X, Y0-Y, Z0-Z, M_PI / 15., Rayon / 20.); | |
7fd59977 | 280 | TCollection_AsciiString ValOfRadius(Rayon); |
281 | PText.SetCoord( (X0+X)/2., (Y0+Y)/2. , (Z0+Z)/2. ); | |
282 | gradius->Text(ValOfRadius.ToCString(),PText,0.01); | |
283 | } | |
284 | ||
81bba717 | 285 | // Display of the meridian |
7fd59977 | 286 | |
287 | Quantity_Color Col2(Quantity_NOC_GREEN); | |
288 | Handle(Graphic3d_AspectLine3d) Asp2 = new Graphic3d_AspectLine3d | |
289 | (Col2,Aspect_TOL_SOLID,1.); | |
290 | gnopick->SetPrimitivesAspect(Asp2); | |
291 | ||
81bba717 | 292 | // Definition of the axis of the circle |
7fd59977 | 293 | aView->Up(DXRef,DYRef,DZRef); |
294 | this->Position(X,Y,Z); | |
295 | DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0; | |
296 | VX = DYRef*DZini - DZRef*DYini; | |
297 | VY = DZRef*DXini - DXRef*DZini; | |
298 | VZ = DXRef*DYini - DYRef*DXini; | |
299 | ||
300 | V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon); | |
301 | ||
81bba717 | 302 | // Display of the parallel |
7fd59977 | 303 | |
81bba717 | 304 | // Definition of the axis of the circle |
7fd59977 | 305 | aView->Proj(VX,VY,VZ); |
306 | aView->Up(X1,Y1,Z1); | |
307 | DXRef = VY * Z1 - VZ * Y1; | |
308 | DYRef = VZ * X1 - VX * Z1; | |
309 | DZRef = VX * Y1 - VY * X1; | |
310 | this->Position(X,Y,Z); | |
311 | DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0; | |
312 | VX = DYRef*DZini - DZRef*DYini; | |
313 | VY = DZRef*DXini - DXRef*DZini; | |
314 | VZ = DXRef*DYini - DYRef*DXini; | |
315 | ||
316 | V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon); | |
317 | ||
318 | } | |
319 | ||
320 | MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT); | |
321 | MyTypeOfRepresentation = Pres; | |
322 | MyGraphicStructure->Display(); | |
323 | TheViewer->SetUpdateMode(UpdSov); | |
324 | } |