zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
#ifndef __OD_GI_LIGHT_TRAITS_DATA__
#define __OD_GI_LIGHT_TRAITS_DATA__
 
#include "TD_PackPush.h"
 
#include "Gi/GiLightTraits.h"
 
/** \details
    Library: TD_Gi
    <group OdGi_Classes>
*/
class OdGiLightTraitsData
{
  bool                       m_bOn;
  double                     m_dIntensity;
  OdCmEntityColor            m_color;
  OdGiShadowParameters       m_shadowParameters;
 
protected:
  OdGiDrawable::DrawableType m_type;
 
protected:
  OdGiLightTraitsData()
    : m_bOn(false)
    , m_dIntensity(0.0)
  {}
 
public:
  bool isOn() const { return m_bOn; }
  void setOn(bool value) { m_bOn = value; }
 
  double intensity() const { return m_dIntensity; }
  void setIntensity(double dIntensity) { m_dIntensity = dIntensity; }
 
  OdCmEntityColor color() const { return m_color; }
  void setColor(const OdCmEntityColor& color) { m_color = color; }
 
  OdGiShadowParameters shadowParameters() const { return m_shadowParameters; }
  void setShadowParameters(const OdGiShadowParameters& params) { m_shadowParameters = params; }
 
  OdGiDrawable::DrawableType type() const { return m_type; }
 
  void save(OdGsFiler * pFiler) const;
  void load(OdGsFiler * pFiler);
 
  static void deleteLightTraitsData(OdGiLightTraitsData* pLightTraits);
};                          
 
inline void OdGiLightTraitsData::save(OdGsFiler *pFiler) const {
  pFiler->wrBool(isOn());
  pFiler->wrDouble(intensity());
  pFiler->wrUInt32(color().color());
  m_shadowParameters.save(pFiler);
}
 
inline void OdGiLightTraitsData::load(OdGsFiler *pFiler) {
  setOn(pFiler->rdBool());
  setIntensity(pFiler->rdDouble());
  color().setColor(pFiler->rdUInt32());
  m_shadowParameters.load(pFiler);
}
 
/** \details
    Library: TD_Gi
    <group OdGi_Classes>
*/
class OdGiPointLightTraitsData : public OdGiLightTraitsData
{
  OdGePoint3d          m_position;
  OdGiLightAttenuation m_attenuation;
  // Photometric data
  double               m_dPhysIntensity;
  OdGiColorRGB         m_lampColor;
  bool                 m_bHasTarget;
  OdGePoint3d          m_target;
 
public:
  OdGiPointLightTraitsData()
    : m_dPhysIntensity(1500.0)
    , m_lampColor(1.0, 1.0, 1.0)
    , m_bHasTarget(false)
  {
    m_type = OdGiDrawable::kPointLight;
  }
 
  OdGePoint3d position() const { return m_position; }
  void setPosition(const OdGePoint3d& pos) { m_position = pos; }
 
  OdGiLightAttenuation attenuation() const { return m_attenuation; }
  void setAttenuation(const OdGiLightAttenuation& atten) { m_attenuation = atten; }
 
  double physicalIntensity() const { return m_dPhysIntensity; }
  void setPhysicalIntensity(double intensity) { m_dPhysIntensity = intensity; }
 
  OdGiColorRGB lampColor() const { return m_lampColor; }
  void setLampColor(const OdGiColorRGB& color) { m_lampColor = color; }
 
  bool hasTarget() const { return m_bHasTarget; }
  void setHasTarget(bool bTarget) { m_bHasTarget = bTarget; }
 
  OdGePoint3d targetLocation() const { return m_target; }
  void setTargetLocation(const OdGePoint3d &loc) { m_target = loc; }
 
  inline void save(OdGsFiler *pFiler) const {
    OdGiLightTraitsData::save(pFiler);
    pFiler->wrPoint3d(position());
    attenuation().save(pFiler);
    pFiler->wrDouble(physicalIntensity());
    pFiler->wrDouble(m_lampColor.red);
    pFiler->wrDouble(m_lampColor.green);
    pFiler->wrDouble(m_lampColor.blue);
    pFiler->wrBool(hasTarget());
    pFiler->wrPoint3d(targetLocation());
  }
 
  inline void load(OdGsFiler *pFiler) {
    OdGiLightTraitsData::load(pFiler);
    pFiler->rdPoint3d(m_position);
    m_attenuation.load(pFiler);
    setPhysicalIntensity(pFiler->rdDouble());
    m_lampColor.red   = pFiler->rdDouble();
    m_lampColor.green = pFiler->rdDouble();
    m_lampColor.blue  = pFiler->rdDouble();
    setHasTarget(pFiler->rdBool());
    pFiler->rdPoint3d(m_target);
  }
};
 
/** \details
    Library: TD_Gi
    <group OdGi_Classes>
*/
class OdGiSpotLightTraitsData : public OdGiLightTraitsData
{
  OdGePoint3d          m_position, m_target;
  OdGiLightAttenuation m_attenuation;
  double               m_dHotspot, m_dFalloff;
  // Photometric data
  double               m_dPhysIntensity;
  OdGiColorRGB         m_lampColor;
 
public:
  OdGiSpotLightTraitsData()
    : m_dHotspot(0.0)
    , m_dFalloff(0.0)
    , m_dPhysIntensity(1500.0)
    , m_lampColor(1.0, 1.0, 1.0)
  {
    m_type = OdGiDrawable::kSpotLight;
  }
 
  OdGePoint3d position() const { return m_position; }
  void setPosition(const OdGePoint3d& pos) { m_position = pos; }
 
  OdGePoint3d target() const { return m_target; }
  void setTarget(const OdGePoint3d& trg) { m_target = trg; }
 
  OdGiLightAttenuation attenuation() const { return m_attenuation; }
  void setAttenuation(const OdGiLightAttenuation& atten) { m_attenuation = atten; }
 
  bool setHotspotAndFalloff(double hotSpot, double falloff);
  double hotspot() const { return m_dHotspot; }
  double falloff() const { return m_dFalloff; }
 
  double physicalIntensity() const { return m_dPhysIntensity; }
  void setPhysicalIntensity(double intensity) { m_dPhysIntensity = intensity; }
 
  OdGiColorRGB lampColor() const { return m_lampColor; }
  void setLampColor(const OdGiColorRGB& color) { m_lampColor = color; }
 
  void save(OdGsFiler *pFiler) const {
    OdGiLightTraitsData::save(pFiler);
    pFiler->wrPoint3d(position());
    pFiler->wrPoint3d(target());
    attenuation().save(pFiler);
    pFiler->wrDouble(physicalIntensity());
    pFiler->wrDouble(hotspot());
    pFiler->wrDouble(falloff());
    pFiler->wrDouble(m_lampColor.red);
    pFiler->wrDouble(m_lampColor.green);
    pFiler->wrDouble(m_lampColor.blue);
  }
 
  void load(OdGsFiler *pFiler) {
    OdGiLightTraitsData::load(pFiler);
    pFiler->rdPoint3d(m_position);
    pFiler->rdPoint3d(m_target);
    m_attenuation.load(pFiler);
    setPhysicalIntensity(pFiler->rdDouble());
    m_dHotspot        = pFiler->rdDouble();
    m_dFalloff        = pFiler->rdDouble();
    m_lampColor.red   = pFiler->rdDouble();
    m_lampColor.green = pFiler->rdDouble();
    m_lampColor.blue  = pFiler->rdDouble();
  }
};
 
/** \details
    Library: TD_Gi
    <group OdGi_Classes>
*/
inline bool OdGiSpotLightTraitsData::setHotspotAndFalloff(double hotspot, double falloff)
  if((hotspot > falloff) || 
     (hotspot < 0.0) || (falloff < 0.0) || 
     (OdaToDegree(hotspot) > 160.0) || (OdaToDegree(falloff) > 160.0))
    return false;
  m_dHotspot = hotspot;
  m_dFalloff = falloff; 
  return true;
}
 
/** \details
    Library: TD_Gi
    <group OdGi_Classes>
*/
class OdGiDistantLightTraitsData : public OdGiLightTraitsData
{
  OdGeVector3d m_direction;
  bool         m_bIsSunlight;
  // Photometric data
  double       m_dPhysIntensity;
  OdGiColorRGB m_lampColor;
  //OdGiSkyParameters m_skyParams; // Unused
 
public:
  OdGiDistantLightTraitsData()
    : m_bIsSunlight(false)
    , m_dPhysIntensity(1500.0)
    , m_lampColor(1.0, 1.0, 1.0)
  {
    m_type = OdGiDrawable::kDistantLight;
  }
 
  OdGeVector3d direction() const { return m_direction; }
  void setDirection(const OdGeVector3d& dir) { m_direction = dir; }
 
  bool isSunlight() const { return m_bIsSunlight; }
  void setSunlight(bool val) { m_bIsSunlight = val; }
 
  double physicalIntensity() const { return m_dPhysIntensity; }
  void setPhysicalIntensity(double intensity) { m_dPhysIntensity = intensity; }
 
  OdGiColorRGB lampColor() const { return m_lampColor; }
  void setLampColor(const OdGiColorRGB& color) { m_lampColor = color; }
 
  void skyParameters(OdGiSkyParameters & /*params*/) const { /*params = m_skyParams;*/ }
  void setSkyParameters(const OdGiSkyParameters & /*params*/) { /*m_skyParams = params;*/ }
 
  void save(OdGsFiler *pFiler) const {
    OdGiLightTraitsData::save(pFiler);
    pFiler->wrVector3d(direction());
    pFiler->wrBool(isSunlight());
    pFiler->wrDouble(physicalIntensity());
    pFiler->wrDouble(m_lampColor.red);
    pFiler->wrDouble(m_lampColor.green);
    pFiler->wrDouble(m_lampColor.blue);
  }
 
  void load(OdGsFiler *pFiler) {
    OdGiLightTraitsData::load(pFiler);
    pFiler->rdVector3d(m_direction);
    setSunlight(pFiler->rdBool());
    setPhysicalIntensity(pFiler->rdDouble());
    m_lampColor.red   = pFiler->rdDouble();
    m_lampColor.green = pFiler->rdDouble();
    m_lampColor.blue  = pFiler->rdDouble();
  }
};
 
/** \details
    Library: TD_Gi
    <group OdGi_Classes>
*/
class OdGiWebLightTraitsData : public OdGiPointLightTraitsData
{
  OdString                        m_webFile;
  OdGeVector3d                    m_webRotate;
  double                          m_dFlux;
  OdGiWebLightTraits::WebFileType m_webFileType;
  OdGiWebLightTraits::WebSymmetry m_webSymmetry;
  bool                            m_bHorzAng90to270;
 
public:
  OdGiWebLightTraitsData()
    : OdGiPointLightTraitsData()
    , m_dFlux(0.0)
    , m_webFileType(OdGiWebLightTraits::kTypeA)
    , m_webSymmetry(OdGiWebLightTraits::kNoSymmetry)
    , m_bHorzAng90to270(false)
  {
    m_type = OdGiDrawable::kWebLight;
  }
 
  const OdString &webFile() const { return m_webFile; }
  void setWebFile(const OdString &fileName) { m_webFile = fileName; }
 
  const OdGeVector3d& webRotation() const { return m_webRotate; }
  void setWebRotation(const OdGeVector3d& rot) { m_webRotate = rot; }
 
  double webFlux() const { return m_dFlux; }
  void setWebFlux(double flux) { m_dFlux = flux; }
 
  OdGiWebLightTraits::WebFileType webFileType() const { return m_webFileType; }
  void setWebFileType(OdGiWebLightTraits::WebFileType type) { m_webFileType = type; }
 
  OdGiWebLightTraits::WebSymmetry webSymmetry() const { return m_webSymmetry; }
  void setWebSymmetry(OdGiWebLightTraits::WebSymmetry sym) { m_webSymmetry = sym; }
 
  bool webHorzAng90to270() const { return m_bHorzAng90to270; }
  void setWebHorzAng90to270(bool bHA) { m_bHorzAng90to270 = bHA; }
 
  inline void save(OdGsFiler *pFiler) const {
    OdGiPointLightTraitsData::save(pFiler);
    pFiler->wrString(webFile());
    pFiler->wrVector3d(webRotation());
    pFiler->wrDouble(webFlux());
    pFiler->wrUInt8((OdUInt8)webFileType());
    pFiler->wrUInt8((OdUInt8)webSymmetry());
    pFiler->wrBool(webHorzAng90to270());
  }
 
  inline void load(OdGsFiler *pFiler) {
    OdGiPointLightTraitsData::load(pFiler);
    pFiler->rdString(m_webFile);
    pFiler->rdVector3d(m_webRotate);
    setWebFlux(pFiler->rdDouble());
    setWebFileType((OdGiWebLightTraits::WebFileType)pFiler->rdUInt8());
    setWebSymmetry((OdGiWebLightTraits::WebSymmetry)pFiler->rdUInt8());
    setWebHorzAng90to270(pFiler->rdBool());
  }
};
 
inline void OdGiLightTraitsData::deleteLightTraitsData(OdGiLightTraitsData* pLightTraits)
{
  switch(pLightTraits->type())
  {
  case OdGiDrawable::kDistantLight:
    delete static_cast<OdGiDistantLightTraitsData*>(pLightTraits);
    break;
  case OdGiDrawable::kPointLight:
    delete static_cast<OdGiPointLightTraitsData*>(pLightTraits);
    break;
  case OdGiDrawable::kSpotLight:
    delete static_cast<OdGiSpotLightTraitsData*>(pLightTraits);
    break;
  case OdGiDrawable::kWebLight:
    delete static_cast<OdGiWebLightTraitsData*>(pLightTraits);
    break;
  default:
    {
      ODA_FAIL_ONCE();
    }
    break;
  }
}
 
#include "TD_PackPop.h"
 
#endif // __OD_GI_LIGHT_TRAITS_DATA__