0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / Vrml / Vrml_PointLight.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <gp_Vec.hxx>
16 #include <Quantity_Color.hxx>
17 #include <Vrml_PointLight.hxx>
18
19 Vrml_PointLight::Vrml_PointLight():
20   myOnOff(Standard_True),
21   myIntensity(1)
22 {
23   gp_Vec tmpVec(0,0,1);
24   myLocation = tmpVec;
25
26   Quantity_Color tmpColor(1,1,1,Quantity_TOC_RGB);
27   myColor = tmpColor;
28 }
29
30  Vrml_PointLight::Vrml_PointLight( const Standard_Boolean aOnOff, 
31                                    const Standard_Real aIntensity, 
32                                    const Quantity_Color& aColor, 
33                                    const gp_Vec& aLocation)
34 {
35   if (aIntensity < 0. || aIntensity > 1.)
36     {
37       throw Standard_Failure("Error : Light intensity must be in the range 0.0 to 1.0, inclusive.");
38     }
39   myOnOff = aOnOff;
40   myIntensity = aIntensity;
41   myColor = aColor;
42   myLocation = aLocation;
43 }
44
45 void Vrml_PointLight::SetOnOff(const Standard_Boolean aOnOff)
46 {
47   myOnOff = aOnOff;
48 }
49
50 Standard_Boolean Vrml_PointLight::OnOff() const 
51 {
52   return myOnOff;
53 }
54
55 void Vrml_PointLight::SetIntensity(const Standard_Real aIntensity)
56 {
57   if (aIntensity < 0. || aIntensity > 1.)
58     {
59       throw Standard_Failure("Error : Light intensity must be in the range 0.0 to 1.0, inclusive.");
60     }
61   myIntensity = aIntensity;
62 }
63
64 Standard_Real Vrml_PointLight::Intensity() const 
65 {
66   return myIntensity;
67 }
68
69 void Vrml_PointLight::SetColor(const Quantity_Color& aColor)
70 {
71   myColor = aColor;
72 }
73
74 Quantity_Color Vrml_PointLight::Color() const 
75 {
76   return  myColor;
77 }
78
79 void Vrml_PointLight::SetLocation(const gp_Vec& aLocation)
80 {
81   myLocation = aLocation;
82 }
83
84 gp_Vec Vrml_PointLight::Location() const 
85 {
86   return myLocation;
87 }
88
89 Standard_OStream& Vrml_PointLight::Print(Standard_OStream& anOStream) const 
90 {
91  anOStream  << "PointLight {\n";
92
93  if ( myOnOff != Standard_True )
94    {
95     anOStream  << "    on\t\tFALSE\n";
96 //    anOStream << myOnOff << "\n";
97    }
98
99  if ( Abs(myIntensity - 1) > 0.0001 )
100    {
101     anOStream  << "    intensity\t";
102     anOStream << myIntensity << "\n";
103    }
104
105  if ( Abs(myColor.Red() - 1) > 0.0001 || 
106       Abs(myColor.Green() - 1) > 0.0001 || 
107       Abs(myColor.Blue() - 1) > 0.0001 )
108    {
109     anOStream  << "    color\t";
110     anOStream << myColor.Red() << " " << myColor.Green() << " " << myColor.Blue() << "\n";
111    }
112
113  if ( Abs(myLocation.X() - 0) > 0.0001 || 
114      Abs(myLocation.Y() - 0) > 0.0001 || 
115      Abs(myLocation.Z() - 1) > 0.0001 ) 
116    {
117     anOStream  << "    location\t";
118     anOStream << myLocation.X() << " " << myLocation.Y() << " " << myLocation.Z() << "\n";
119    }
120
121  anOStream  << "}\n";
122  return anOStream;
123 }