0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / Vrml / Vrml_Material.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
42cf5bc1 14
15#include <Standard_Type.hxx>
16#include <Vrml_Material.hxx>
7fd59977 17
92efcf78 18IMPLEMENT_STANDARD_RTTIEXT(Vrml_Material,MMgt_TShared)
19
b311480e 20Vrml_Material::Vrml_Material(const Handle(Quantity_HArray1OfColor)& aAmbientColor,
7fd59977 21 const Handle(Quantity_HArray1OfColor)& aDiffuseColor,
22 const Handle(Quantity_HArray1OfColor)& aSpecularColor,
23 const Handle(Quantity_HArray1OfColor)& aEmissiveColor,
24 const Handle(TColStd_HArray1OfReal)& aShininess,
25 const Handle(TColStd_HArray1OfReal)& aTransparency)
26{
27 myAmbientColor = aAmbientColor;
28 myDiffuseColor = aDiffuseColor;
29 mySpecularColor = aSpecularColor;
30 myEmissiveColor = aEmissiveColor;
31
32 Standard_Integer i;
33 for ( i = aShininess->Lower(); i <= aShininess->Upper(); i++ )
34 {
35 if (aShininess->Value(i) < 0. || aShininess->Value(i) > 1.)
36 {
9775fa61 37 throw Standard_Failure("The value of aShininess is out of range (0 - 1)");
7fd59977 38 }
39 }
40 myShininess = aShininess;
41
42 for ( i = aTransparency->Lower(); i <= aTransparency->Upper(); i++ )
43 {
44 if (aTransparency->Value(i) < 0. || aTransparency->Value(i) > 1.)
45 {
9775fa61 46 throw Standard_Failure("The value of aTransparency is out of range (0 - 1)");
7fd59977 47 }
48 }
49 myTransparency = aTransparency;
50}
51
52 Vrml_Material::Vrml_Material()
53{
54 Quantity_Color tmpcolor;
55// myAmbientColor = new Quantity_HArray1OfColor(1,1);
56 tmpcolor.SetValues(0.2, 0.2, 0.2, Quantity_TOC_RGB);
57 myAmbientColor = new Quantity_HArray1OfColor(1,1,tmpcolor);
58// myAmbientColor->SetValue(1, tmpcolor);
59// myDiffuseColor = new Quantity_HArray1OfColor(1,1);
60 tmpcolor.SetValues(0.8, 0.8, 0.8, Quantity_TOC_RGB);
61 myDiffuseColor = new Quantity_HArray1OfColor(1,1,tmpcolor);
62// myDiffuseColor->SetValue(1, tmpcolor);
63 mySpecularColor = new Quantity_HArray1OfColor(1,1);
64 tmpcolor.SetValues(0, 0, 0, Quantity_TOC_RGB);
65 mySpecularColor->SetValue(1, tmpcolor);
66 myEmissiveColor = new Quantity_HArray1OfColor(1,1);
67 tmpcolor.SetValues(0, 0, 0, Quantity_TOC_RGB);
68 myEmissiveColor->SetValue(1, tmpcolor);
69
70 myShininess = new TColStd_HArray1OfReal (1,1,0.2);
71 myTransparency = new TColStd_HArray1OfReal (1,1,0);
72}
73
74void Vrml_Material::SetAmbientColor(const Handle(Quantity_HArray1OfColor)& aAmbientColor)
75{
76 myAmbientColor = aAmbientColor;
77}
78
79Handle(Quantity_HArray1OfColor) Vrml_Material::AmbientColor() const
80{
81 return myAmbientColor;
82}
83
84void Vrml_Material::SetDiffuseColor(const Handle(Quantity_HArray1OfColor)& aDiffuseColor)
85{
86 myDiffuseColor = aDiffuseColor;
87}
88
89Handle(Quantity_HArray1OfColor) Vrml_Material::DiffuseColor() const
90{
91 return myDiffuseColor;
92}
93
94void Vrml_Material::SetSpecularColor(const Handle(Quantity_HArray1OfColor)& aSpecularColor)
95{
96 mySpecularColor = aSpecularColor;
97}
98
99Handle(Quantity_HArray1OfColor) Vrml_Material::SpecularColor() const
100{
101 return mySpecularColor;
102}
103
104void Vrml_Material::SetEmissiveColor(const Handle(Quantity_HArray1OfColor)& aEmissiveColor)
105{
106 myEmissiveColor = aEmissiveColor;
107}
108
109Handle(Quantity_HArray1OfColor) Vrml_Material::EmissiveColor() const
110{
111 return myEmissiveColor;
112}
113
114void Vrml_Material::SetShininess(const Handle(TColStd_HArray1OfReal)& aShininess)
115{
116 Standard_Integer i;
117 for ( i = aShininess->Lower(); i <= aShininess->Upper(); i++ )
118 {
119 if (aShininess->Value(i) < 0. || aShininess->Value(i) > 1.)
120 {
9775fa61 121 throw Standard_Failure("The value of aShininess is out of range (0 - 1)");
7fd59977 122 }
123 }
124 myShininess = aShininess;
125}
126
127Handle(TColStd_HArray1OfReal) Vrml_Material::Shininess() const
128{
129 return myShininess;
130}
131
132void Vrml_Material::SetTransparency(const Handle(TColStd_HArray1OfReal)& aTransparency)
133{
134 Standard_Integer i;
135 for ( i = aTransparency->Lower(); i <= aTransparency->Upper(); i++ )
136 {
137 if (aTransparency->Value(i) < 0. || aTransparency->Value(i) > 1.)
138 {
9775fa61 139 throw Standard_Failure("The value of aTransparency is out of range (0 - 1)");
7fd59977 140 }
141 }
142 myTransparency = aTransparency;
143}
144
145Handle(TColStd_HArray1OfReal) Vrml_Material::Transparency() const
146{
147 return myTransparency;
148}
149
150Standard_OStream& Vrml_Material::Print(Standard_OStream& anOStream) const
151{
152 Standard_Integer i;
586db386 153 anOStream << "Material {\n";
7fd59977 154
155 if ( myAmbientColor->Length() != 1 ||
156 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Red() - 0.2) > 0.0001 ||
157 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Green() - 0.2) > 0.0001 ||
158 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Blue() - 0.2) > 0.0001 )
159 {
160 anOStream << " ambientColor [\n\t";
161 for ( i = myAmbientColor->Lower(); i <= myAmbientColor->Upper(); i++ )
162 {
163 anOStream << myAmbientColor->Value(i).Red() << ' ' << myAmbientColor->Value(i).Green() << ' ' << myAmbientColor->Value(i).Blue();
164 if ( i < myAmbientColor->Length() )
586db386 165 anOStream << ",\n\t"; // ,,,,,,,,,,
7fd59977 166 }
586db386 167 anOStream << " ]\n";
7fd59977 168 }
169
170 if ( myDiffuseColor->Length() != 1 ||
171 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Red() - 0.8) > 0.0001 ||
172 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Green() - 0.8) > 0.0001 ||
173 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Blue() - 0.8) > 0.0001 )
174 {
175 anOStream << " diffuseColor [\n\t";
176 for ( i = myDiffuseColor->Lower(); i <= myDiffuseColor->Upper(); i++ )
177 {
178 anOStream << myDiffuseColor->Value(i).Red() << ' ' << myDiffuseColor->Value(i).Green() << ' ' << myDiffuseColor->Value(i).Blue();
179 if ( i < myDiffuseColor->Length() )
586db386 180 anOStream << ",\n\t";
7fd59977 181 }
586db386 182 anOStream << " ]\n";
7fd59977 183 }
184
185 if ( mySpecularColor->Length() != 1 ||
186 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Red() - 0) > 0.0001 ||
187 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Green() - 0) > 0.0001 ||
188 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Blue() - 0) > 0.0001 )
189 {
190 anOStream << " specularColor [\n\t";
191 for ( i = mySpecularColor->Lower(); i <= mySpecularColor->Upper(); i++ )
192 {
193 anOStream << mySpecularColor->Value(i).Red() << ' ' << mySpecularColor->Value(i).Green() << ' ' << mySpecularColor->Value(i).Blue();
194 if ( i < mySpecularColor->Length() )
586db386 195 anOStream << ",\n\t";
7fd59977 196 }
586db386 197 anOStream << " ]\n";
7fd59977 198 }
199
200 if ( myEmissiveColor->Length() != 1 ||
201 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Red() - 0) > 0.0001 ||
202 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Green() - 0) > 0.0001 ||
203 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Blue() - 0) > 0.0001 )
204 {
205 anOStream << " emissiveColor [\n\t";
206 for ( i = myEmissiveColor->Lower(); i <= myEmissiveColor->Upper(); i++ )
207 {
208 anOStream << myEmissiveColor->Value(i).Red() << ' ' << myEmissiveColor->Value(i).Green() << ' ' << myEmissiveColor->Value(i).Blue();
209 if ( i < myEmissiveColor->Length() )
586db386 210 anOStream << ",\n\t";
7fd59977 211 }
586db386 212 anOStream << " ]\n";
7fd59977 213 }
214
215 if ( myShininess->Length() != 1 || Abs(myShininess->Value(myShininess->Lower()) - 0.2) > 0.0001 )
216 {
217 anOStream << " shininess\t\t[ ";
218 for ( i = myShininess->Lower(); i <= myShininess->Upper(); i++ )
219 {
220 anOStream << myShininess->Value(i);
221 if ( i < myShininess->Length() )
222 anOStream << ", ";
223 }
586db386 224 anOStream << " ]\n";
7fd59977 225 }
226
227 if ( myTransparency->Length() != 1 || Abs(myTransparency->Value(myTransparency->Lower()) - 0) > 0.0001 )
228 {
229 anOStream << " transparency\t[ ";
230 for ( i = myTransparency->Lower(); i <= myTransparency->Upper(); i++ )
231 {
232 anOStream << myTransparency->Value(i);
233 if ( i < myTransparency->Length() )
234 anOStream << ", ";
235 }
586db386 236 anOStream << " ]\n";
7fd59977 237 }
586db386 238 anOStream << "}\n";
7fd59977 239
240 return anOStream;
241}
242