0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / V3d / V3d_SpotLight.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14/***********************************************************************
7fd59977 15 FONCTION :
16 ----------
17 Classe V3d_SpotLight :
7fd59977 18 HISTORIQUE DES MODIFICATIONS :
19 --------------------------------
20 00-09-92 : GG ; Creation.
21 18-06-96 : FMN ; Ajout MyGraphicStructure1 pour sauvegarder snopick
22 30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods)
23 02.15.100 : JR : Clutter
7fd59977 24************************************************************************/
7fd59977 25/*----------------------------------------------------------------------*/
26/*
27 * Includes
28 */
29
42cf5bc1 30#include <gp_Ax1.hxx>
31#include <gp_Dir.hxx>
32#include <gp_Pnt.hxx>
33#include <gp_Trsf.hxx>
34#include <gp_Vec.hxx>
b8ddfc2f 35#include <Graphic3d_ArrayOfSegments.hxx>
7fd59977 36#include <Graphic3d_AspectLine3d.hxx>
42cf5bc1 37#include <Graphic3d_AspectMarker3d.hxx>
7fd59977 38#include <Graphic3d_AspectText3d.hxx>
42cf5bc1 39#include <Graphic3d_Group.hxx>
40#include <Graphic3d_Structure.hxx>
41#include <Graphic3d_Vector.hxx>
42#include <Graphic3d_Vertex.hxx>
43#include <Standard_Type.hxx>
44#include <TCollection_AsciiString.hxx>
45#include <V3d.hxx>
46#include <V3d_BadValue.hxx>
47#include <V3d_SpotLight.hxx>
48#include <V3d_View.hxx>
49#include <V3d_Viewer.hxx>
7fd59977 50
92efcf78 51IMPLEMENT_STANDARD_RTTIEXT(V3d_SpotLight,V3d_PositionLight)
52
c357e426 53// =======================================================================
54// function : V3d_SpotLight
55// purpose :
56// =======================================================================
57V3d_SpotLight::V3d_SpotLight (const Handle(V3d_Viewer)& theViewer,
58 const Standard_Real theX,
59 const Standard_Real theY,
60 const Standard_Real theZ,
61 const V3d_TypeOfOrientation theDirection,
87432b82 62 const Quantity_Color& theColor,
c357e426 63 const Standard_Real theConstAttenuation,
64 const Standard_Real theLinearAttenuation,
65 const Standard_Real theConcentration,
66 const Standard_Real theAngle)
67: V3d_PositionLight (theViewer)
68{
69 Graphic3d_Vector aDir = V3d::GetProjAxis (theDirection);
70 SetType (V3d_SPOT);
71 SetColor (theColor);
72 SetTarget (theX + aDir.X(), theY + aDir.Y(), theZ + aDir.Z());
73 SetPosition (theX, theY, theZ);
74 SetDirection (aDir.X(), aDir.Y(), aDir.Z());
75 SetAttenuation (theConstAttenuation, theLinearAttenuation);
76 SetConcentration (theConcentration);
77 SetAngle (theAngle);
7fd59977 78}
79
c357e426 80// =======================================================================
81// function : V3d_SpotLight
82// purpose :
83// =======================================================================
84V3d_SpotLight::V3d_SpotLight (const Handle(V3d_Viewer)& theViewer,
85 const Standard_Real theXt,
86 const Standard_Real theYt,
87 const Standard_Real theZt,
88 const Standard_Real theXp,
89 const Standard_Real theYp,
90 const Standard_Real theZp,
87432b82 91 const Quantity_Color& theColor,
c357e426 92 const Standard_Real theConstAttenuation,
93 const Standard_Real theLinearAttenuation,
94 const Standard_Real theConcentration,
95 const Standard_Real theAngle)
96: V3d_PositionLight (theViewer)
97{
98 SetType (V3d_SPOT);
99 SetColor (theColor);
100 SetTarget (theXt, theYt, theZt);
101 SetPosition (theXp, theYp, theZp);
102 SetDirection (theXt - theXp, theYt - theYp, theZt - theZp);
103 SetAttenuation (theConstAttenuation, theLinearAttenuation);
104 SetConcentration (theConcentration);
105 SetAngle (theAngle);
7fd59977 106}
107
c357e426 108// =======================================================================
109// function : SetPosition
110// purpose :
111// =======================================================================
112void V3d_SpotLight::SetPosition (const Standard_Real theXp,
113 const Standard_Real theYp,
114 const Standard_Real theZp)
115{
7c3ef2f7 116 myLight.Position.x() = theXp;
117 myLight.Position.y() = theYp;
118 myLight.Position.z() = theZp;
7fd59977 119}
120
c357e426 121// =======================================================================
122// function : SetDirection
123// purpose :
124// =======================================================================
125void V3d_SpotLight::SetDirection (const Standard_Real theVx,
126 const Standard_Real theVy,
127 const Standard_Real theVz)
128{
129 myLight.Direction.x() = static_cast<Standard_ShortReal> (theVx);
130 myLight.Direction.y() = static_cast<Standard_ShortReal> (theVy);
131 myLight.Direction.z() = static_cast<Standard_ShortReal> (theVz);
7fd59977 132}
133
c357e426 134// =======================================================================
135// function : SetDirection
136// purpose :
137// =======================================================================
138void V3d_SpotLight::SetDirection (const V3d_TypeOfOrientation theDirection)
139{
140 Graphic3d_Vector aDir = V3d::GetProjAxis (theDirection);
141 SetDirection (aDir.X(), aDir.Y(), aDir.Z());
7fd59977 142}
143
c357e426 144// =======================================================================
145// function : SetAttenuation
146// purpose :
147// =======================================================================
148void V3d_SpotLight::SetAttenuation (const Standard_Real theConstAttenuation,
149 const Standard_Real theLinearAttenuation)
150{
151 V3d_BadValue_Raise_if (theConstAttenuation < 0. ||
152 theConstAttenuation > 1. ||
153 theLinearAttenuation < 0. ||
154 theLinearAttenuation > 1 ,
155 "V3d_SpotLight::SetAttenuation, "
156 "bad coefficients");
157
158 myLight.ChangeConstAttenuation() = static_cast<Standard_ShortReal> (theConstAttenuation);
159 myLight.ChangeLinearAttenuation() = static_cast<Standard_ShortReal> (theLinearAttenuation);
7fd59977 160}
161
c357e426 162// =======================================================================
163// function : SetConcentration
164// purpose :
165// =======================================================================
166void V3d_SpotLight::SetConcentration (const Standard_Real theConcentration)
167{
168 V3d_BadValue_Raise_if (theConcentration < 0. ||
169 theConcentration > 1.,
170 "V3d_SpotLight::SetConcentration, "
171 "bad coefficient");
7fd59977 172
c357e426 173 myLight.ChangeConcentration() = static_cast<Standard_ShortReal> (theConcentration);
7fd59977 174}
175
c357e426 176// =======================================================================
177// function : SetAngle
178// purpose :
179// =======================================================================
180void V3d_SpotLight::SetAngle (const Standard_Real theAngle)
181{
182 V3d_BadValue_Raise_if (theAngle <= 0. ||
183 theAngle >= M_PI,
184 "V3d_SpotLight::SetAngle, "
185 "bad angle");
7fd59977 186
c357e426 187 myLight.ChangeAngle() = static_cast<Standard_ShortReal> (theAngle);
7fd59977 188}
189
c357e426 190// =======================================================================
191// function : Direction
192// purpose :
193// =======================================================================
194void V3d_SpotLight::Direction (Standard_Real& theVx,
195 Standard_Real& theVy,
196 Standard_Real& theVz) const
197{
198 theVx = myLight.Direction.x();
199 theVy = myLight.Direction.y();
200 theVz = myLight.Direction.z();
201}
7fd59977 202
c357e426 203// =======================================================================
204// function : Direction
205// purpose :
206// =======================================================================
207void V3d_SpotLight::Position (Standard_Real& theXp,
208 Standard_Real& theYp,
209 Standard_Real& theZp) const
210{
211 theXp = myLight.Position.x();
212 theYp = myLight.Position.y();
213 theZp = myLight.Position.z();
7fd59977 214}
215
c357e426 216// =======================================================================
217// function : Attenuation
218// purpose :
219// =======================================================================
220void V3d_SpotLight::Attenuation (Standard_Real& theConstAttenuation,
221 Standard_Real& theLinearAttenuation) const
222{
223 theConstAttenuation = myLight.ConstAttenuation();
224 theLinearAttenuation = myLight.LinearAttenuation();
7fd59977 225}
226
c357e426 227// =======================================================================
228// function : Concentration
229// purpose :
230// =======================================================================
231Standard_Real V3d_SpotLight::Concentration ()const
b8ddfc2f 232{
c357e426 233 return myLight.Concentration();
7fd59977 234}
235
c357e426 236// =======================================================================
237// function : Concentration
238// purpose :
239// =======================================================================
b8ddfc2f 240Standard_Real V3d_SpotLight::Angle()const
241{
c357e426 242 return myLight.Angle();
7fd59977 243}
244
c357e426 245// =======================================================================
246// function : Symbol
247// purpose :
248// =======================================================================
249void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& theSymbol,
b8ddfc2f 250 const Handle(V3d_View)& ) const
251{
252 Standard_Real X,Y,Z;
7fd59977 253 Standard_Real DX,DY,DZ;
7fd59977 254 this->Position(X,Y,Z);
255 this->Direction(DX,DY,DZ);
b8ddfc2f 256
c357e426 257 V3d::ArrowOfRadius(theSymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,this->Radius()/15.);
7fd59977 258}
c357e426 259
260// =======================================================================
261// function : Display
262// purpose :
263// =======================================================================
264void V3d_SpotLight::Display (const Handle(V3d_View)& theView,
265 const V3d_TypeOfRepresentation theTPres)
b8ddfc2f 266{
7fd59977 267 Graphic3d_Vertex PText ;
268 Standard_Real X,Y,Z,Rayon;
269 Standard_Real X0,Y0,Z0,VX,VY,VZ;
270 Standard_Real X1,Y1,Z1;
271 Standard_Real DXRef,DYRef,DZRef,DXini,DYini,DZini;
7fd59977 272 V3d_TypeOfRepresentation Pres;
7fd59977 273
81bba717 274// Creation of a structure slight of markable elements (position of the
275// light, and the domain of lighting represented by a circle)
276// Creation of a structure snopick of non-markable elements (target, meridian and
277// parallel).//
7fd59977 278
c357e426 279 Pres = theTPres;
280 Handle(V3d_Viewer) TheViewer = theView->Viewer();
c357e426 281 if (!myGraphicStructure.IsNull()) {
282 myGraphicStructure->Disconnect(myGraphicStructure1);
283 myGraphicStructure->Clear();
284 myGraphicStructure1->Clear();
285 if (Pres == V3d_SAMELAST) Pres = myTypeOfRepresentation;
b8ddfc2f 286 }
287 else {
288 if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE;
c357e426 289 Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->StructureManager());
290 myGraphicStructure = slight;
291 Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->StructureManager());
292 myGraphicStructure1 = snopick;
b8ddfc2f 293 }
294
b64d84be 295 Handle(Graphic3d_Group) gradius, gExtArrow, gIntArrow;
296 if (Pres == V3d_COMPLETE)
297 {
c357e426 298 gradius = myGraphicStructure->NewGroup();
299 gExtArrow = myGraphicStructure->NewGroup();
300 gIntArrow = myGraphicStructure->NewGroup();
7fd59977 301 }
c357e426 302 Handle(Graphic3d_Group) glight = myGraphicStructure->NewGroup();
7fd59977 303 Handle(Graphic3d_Group) gsphere;
b64d84be 304 if (Pres == V3d_COMPLETE
305 || Pres == V3d_PARTIAL)
306 {
c357e426 307 gsphere = myGraphicStructure->NewGroup();
b64d84be 308 }
7fd59977 309
c357e426 310 Handle(Graphic3d_Group) gnopick = myGraphicStructure1->NewGroup();
7fd59977 311
c357e426 312 X0 = myTarget.X();
313 Y0 = myTarget.Y();
314 Z0 = myTarget.Z();
7fd59977 315
81bba717 316//Display of the position of the light.
7fd59977 317
87432b82 318 const Quantity_Color Col1 = this->Color();
7fd59977 319 Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d();
320 Asp1->SetColor(Col1);
321 glight->SetPrimitivesAspect(Asp1);
c357e426 322 this->Symbol(glight,theView);
7fd59977 323
81bba717 324// Display of the reference sphere (limited by circle).
7fd59977 325
326 if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) {
327
328 Rayon = this->Radius();
c357e426 329 theView->Proj(VX,VY,VZ);
7fd59977 330 V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon);
331
81bba717 332// Display of the radius of the sphere (line + text)
7fd59977 333
334 if (Pres == V3d_COMPLETE) {
7fd59977 335 this->Position(X,Y,Z);
b8ddfc2f 336 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
337 aPrims->AddVertex(X0,Y0,Z0);
338 aPrims->AddVertex(X,Y,Z);
339 gnopick->AddPrimitiveArray(aPrims);
340 V3d::ArrowOfRadius(gExtArrow,X-.1*(X-X0),Y-.1*(Y-Y0),Z-.1*(Z-Z0),X-X0,Y-Y0,Z-Z0,M_PI/15.,Rayon/20.);
341 V3d::ArrowOfRadius(gIntArrow,X0,Y0,Z0,X0-X,Y0-Y,Z0-Z,M_PI/15.,Rayon/20.);
7fd59977 342 TCollection_AsciiString ValOfRadius(Rayon);
b8ddfc2f 343 PText.SetCoord( .5*(X0+X), .5*(Y0+Y), .5*(Z0+Z) );
7fd59977 344 gradius->Text(ValOfRadius.ToCString(),PText,0.01);
345 }
346
81bba717 347// Display of the meridian
7fd59977 348
349 Quantity_Color Col2(Quantity_NOC_GREEN);
b8ddfc2f 350 Handle(Graphic3d_AspectLine3d) Asp2 = new Graphic3d_AspectLine3d(Col2,Aspect_TOL_SOLID,1.);
7fd59977 351 gnopick->SetPrimitivesAspect(Asp2);
352
81bba717 353// Definition of the axis of the circle
c357e426 354 theView->Up(DXRef,DYRef,DZRef);
7fd59977 355 this->Position(X,Y,Z);
356 DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0;
357 VX = DYRef*DZini - DZRef*DYini;
358 VY = DZRef*DXini - DXRef*DZini;
359 VZ = DXRef*DYini - DYRef*DXini;
360
361 V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
362
81bba717 363// Display of the parallel
7fd59977 364
81bba717 365// Definition of the axis of the circle
c357e426 366 theView->Proj(VX,VY,VZ);
367 theView->Up(X1,Y1,Z1);
7fd59977 368 DXRef = VY * Z1 - VZ * Y1;
369 DYRef = VZ * X1 - VX * Z1;
370 DZRef = VX * Y1 - VY * X1;
371 this->Position(X,Y,Z);
372 DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0;
373 VX = DYRef*DZini - DZRef*DYini;
374 VY = DZRef*DXini - DXRef*DZini;
375 VZ = DXRef*DYini - DYRef*DXini;
376
377 V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon);
7fd59977 378 }
379
c357e426 380 myGraphicStructure->Connect(myGraphicStructure1,Graphic3d_TOC_DESCENDANT);
381 myTypeOfRepresentation = Pres;
382 myGraphicStructure->Display();
7fd59977 383}