CFx SDK Documentation  2020SP3
GiFill.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef _OD_GIFILL_H_
25 #define _OD_GIFILL_H_
26 
27 #include "RxObject.h"
28 #include "HatchPattern.h"
29 #include "UInt8Array.h"
30 
31 #include "TD_PackPush.h"
32 
39 {
40  protected:
41  double m_dDeviation;
42  public:
44  OdGiFill();
45 
46  double deviation() const;
47  void setDeviation(double dDeviation);
48 
49  virtual void copyFrom(const OdRxObject* pSource);
50 
51  virtual bool operator ==(const OdGiFill& fill) const;
52  virtual bool operator !=(const OdGiFill& fill) const;
53 
54  virtual void saveBytes(OdUInt8Array &bytes) const;
55  virtual void loadBytes(const OdUInt8 *pBytes);
56 
57  static OdSmartPtr<OdGiFill> loadFill(const OdUInt8 *pBytes);
58  protected:
59  void pushDbl(OdUInt8Array &bytes, double dDbl) const;
60  void pushInt(OdUInt8Array &bytes, OdUInt32 nInt) const;
61  void popDbl(const OdUInt8 *&pBytes, double &dDbl) const;
62  void popInt(const OdUInt8 *&pBytes, OdUInt32 &nInt) const;
63 };
64 
69 
70 inline
72  : m_dDeviation(0.0)
73 { }
74 
75 inline
76 double OdGiFill::deviation() const
77 {
78  return m_dDeviation;
79 }
80 
81 inline
82 void OdGiFill::setDeviation(double dDeviation)
83 {
84  m_dDeviation = dDeviation;
85 }
86 
87 inline
88 void OdGiFill::copyFrom(const OdRxObject* pSource)
89 {
90  OdGiFillPtr pSrcFill = OdGiFill::cast(pSource);
91  if (!pSrcFill.isNull())
92  setDeviation(pSrcFill->deviation());
93  else
94  throw OdError(eNotApplicable);
95 }
96 
97 inline
98 bool OdGiFill::operator ==(const OdGiFill& fill) const
99 {
100  return (isA() == fill.isA()) && OdEqual(deviation(), fill.deviation());
101 }
102 
103 inline
104 bool OdGiFill::operator !=(const OdGiFill& fill) const
105 {
106  return (isA() != fill.isA()) || !OdEqual(deviation(), fill.deviation());
107 }
108 
109 inline
111 {
112  bytes.push_back(0);
113  pushDbl(bytes, m_dDeviation);
114 }
115 
116 inline
117 void OdGiFill::loadBytes(const OdUInt8 *pBytes)
118 {
119  if (*pBytes++ != 0)
120  throw OdError(eInvalidInput);
121  popDbl(pBytes, m_dDeviation);
122 }
123 
124 inline
125 void OdGiFill::pushDbl(OdUInt8Array &bytes, double dDbl) const
126 {
127  OdUInt8 nBytes[sizeof(double)];
128  ::memcpy(nBytes, &dDbl, sizeof(double));
129  bytes.insert(bytes.end(), nBytes, nBytes + sizeof(double));
130 }
131 
132 inline
133 void OdGiFill::pushInt(OdUInt8Array &bytes, OdUInt32 nInt) const
134 {
135  OdUInt8 nBytes[sizeof(OdUInt32)];
136  ::memcpy(nBytes, &nInt, sizeof(OdUInt32));
137  bytes.insert(bytes.end(), nBytes, nBytes + sizeof(OdUInt32));
138 }
139 
140 inline
141 void OdGiFill::popDbl(const OdUInt8 *&pBytes, double &dDbl) const
142 {
143  ::memcpy(&dDbl, pBytes, sizeof(double));
144  pBytes += sizeof(double);
145 }
146 
147 inline
148 void OdGiFill::popInt(const OdUInt8 *&pBytes, OdUInt32 &nInt) const
149 {
150  ::memcpy(&nInt, pBytes, sizeof(OdUInt32));
151  pBytes += sizeof(OdUInt32);
152 }
153 
160 {
161  protected:
163  bool m_isDraft;
164 
165  public:
168 
169  const OdHatchPattern &patternLines() const;
170  OdHatchPattern &patternLines();
171  void setPatternLines(const OdHatchPattern &aHatchPattern);
172 
173  virtual void copyFrom(const OdRxObject* pSource);
174 
175  virtual bool operator ==(const OdGiFill& fill) const;
176  virtual bool operator !=(const OdGiFill& fill) const;
177 
178  virtual void saveBytes(OdUInt8Array &bytes) const;
179  virtual void loadBytes(const OdUInt8 *pBytes);
180 
181  bool isDraft() const;
182  void setDraft(bool draft);
183 };
184 
189 
190 inline
192  OdGiFill(),
193  m_isDraft(false)
194 { }
195 
196 inline
198 {
199  return m_aHatchPattern;
200 }
201 
202 inline
204 {
205  return m_aHatchPattern;
206 }
207 
208 inline
210 {
211  m_aHatchPattern = aHatchPattern;
212 }
213 
214 inline
216 {
217  OdGiHatchPatternPtr pSrcFill = OdGiHatchPattern::cast(pSource);
218  if (!pSrcFill.isNull())
219  {
220  m_isDraft = pSrcFill->m_isDraft;
221  setPatternLines(pSrcFill->patternLines());
222  OdGiFill::copyFrom(pSource);
223  }
224  else
225  throw OdError(eNotApplicable);
226 }
227 
228 inline
230 {
231  if (isA() == fill.isA())
232  {
233  if (OdEqual(deviation(), fill.deviation()))
234  {
235  const OdGiHatchPattern *pSecond = static_cast<const OdGiHatchPattern*>(&fill);
236  if (patternLines().size() == pSecond->patternLines().size() &&
237  m_isDraft == pSecond->m_isDraft)
238  {
239  for (OdUInt32 nPat = 0; nPat < patternLines().size(); nPat++)
240  {
241  const OdHatchPatternLine &pl1 = patternLines().getPtr()[nPat];
242  const OdHatchPatternLine &pl2 = pSecond->patternLines().getPtr()[nPat];
243  if (!OdEqual(pl1.m_dLineAngle, pl2.m_dLineAngle) ||
244  !OdEqual(pl1.m_basePoint.x, pl2.m_basePoint.x) || !OdEqual(pl1.m_basePoint.y, pl2.m_basePoint.y) ||
246  pl1.m_dashes.size() != pl2.m_dashes.size())
247  return false;
248  for (OdUInt32 nDash = 0; nDash < pl1.m_dashes.size(); nDash++)
249  {
250  if (!OdEqual(pl1.m_dashes.getPtr()[nDash], pl2.m_dashes.getPtr()[nDash]))
251  return false;
252  }
253  }
254  return true;
255  }
256  }
257  }
258  return false;
259 }
260 
261 inline
263 {
264  return !operator ==(fill);
265 }
266 
267 inline
269 {
270  bytes.push_back(1);
271  pushInt(bytes, m_isDraft ? 1 : 0);
272  pushInt(bytes, m_aHatchPattern.size());
273  for (OdUInt32 nPat = 0; nPat < m_aHatchPattern.size(); nPat++)
274  {
275  const OdHatchPatternLine &pl = m_aHatchPattern.getPtr()[nPat];
276  pushDbl(bytes, pl.m_dLineAngle);
277  pushDbl(bytes, pl.m_basePoint.x); pushDbl(bytes, pl.m_basePoint.y);
278  pushDbl(bytes, pl.m_patternOffset.x); pushDbl(bytes, pl.m_patternOffset.y);
279  pushInt(bytes, pl.m_dashes.size());
280  for (OdUInt32 nDash = 0; nDash < pl.m_dashes.size(); nDash++)
281  pushDbl(bytes, pl.m_dashes.getPtr()[nDash]);
282  }
283  OdGiFill::saveBytes(bytes);
284 }
285 
286 inline
288 {
289  if (*pBytes++ != 1)
290  throw OdError(eInvalidInput);
291  OdUInt32 isDraft; popInt(pBytes, isDraft); m_isDraft = (isDraft == 1);
292  OdUInt32 nPats = 0; popInt(pBytes, nPats);
293  m_aHatchPattern.resize(nPats);
294  for (OdUInt32 nPat = 0; nPat < nPats; nPat++)
295  {
297  popDbl(pBytes, pl.m_dLineAngle);
298  popDbl(pBytes, pl.m_basePoint.x); popDbl(pBytes, pl.m_basePoint.y);
299  popDbl(pBytes, pl.m_patternOffset.x); popDbl(pBytes, pl.m_patternOffset.y);
300  OdUInt32 nDashes = 0; popInt(pBytes, nDashes);
301  pl.m_dashes.resize(nDashes);
302  for (OdUInt32 nDash = 0; nDash < nDashes; nDash++)
303  popDbl(pBytes, pl.m_dashes[nDash]);
304  }
305  OdGiFill::loadBytes(pBytes);
306 }
307 
308 inline
310 {
311  OdGiFillPtr pObj;
312  switch (*pBytes)
313  {
314  case 0: pObj = OdGiFill::createObject(); break;
315  case 1: pObj = OdGiHatchPattern::createObject(); break;
316  }
317  if (!pObj.isNull())
318  pObj->loadBytes(pBytes);
319  return pObj;
320 }
321 
322 inline
324 {
325  return m_isDraft;
326 }
327 
328 inline
330 {
331  m_isDraft = draft;
332 }
333 
334 
335 #include "TD_PackPop.h"
336 
337 #endif //_OD_GIFILL_H_
FIRSTDLL_EXPORT
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
OdHatchPatternLine
Definition: HatchPattern.h:42
OdEqual
bool OdEqual(double x, double y, double tol=1.e-10)
Definition: OdaDefs.h:523
OdGiFill::operator!=
virtual bool operator!=(const OdGiFill &fill) const
Definition: GiFill.h:104
OdUInt8
unsigned char OdUInt8
Definition: OdPlatformSettings.h:759
OdGeVector2d::x
double x
Definition: GeVector2d.h:453
false
false
Definition: DimVarDefs.h:165
OdGiHatchPattern::m_isDraft
bool m_isDraft
Definition: GiFill.h:163
OdGiFill::deviation
double deviation() const
Definition: GiFill.h:76
OdRxObject
Definition: RxObject.h:564
OdArray::end
iterator end()
Definition: OdArray.h:772
OdGiHatchPattern::loadBytes
virtual void loadBytes(const OdUInt8 *pBytes)
Definition: GiFill.h:287
OdGiFill::loadFill
static OdSmartPtr< OdGiFill > loadFill(const OdUInt8 *pBytes)
Definition: GiFill.h:309
OdGiHatchPatternPtr
OdSmartPtr< OdGiHatchPattern > OdGiHatchPatternPtr
Definition: GiFill.h:188
OdGiHatchPattern::copyFrom
virtual void copyFrom(const OdRxObject *pSource)
Definition: GiFill.h:215
OdGiFill::copyFrom
virtual void copyFrom(const OdRxObject *pSource)
Definition: GiFill.h:88
OdArray< OdUInt8, OdMemoryAllocator< OdUInt8 > >
OdGiFill::saveBytes
virtual void saveBytes(OdUInt8Array &bytes) const
Definition: GiFill.h:110
OdGePoint2d::y
double y
Definition: GePoint2d.h:300
OdHatchPatternLine::m_dashes
OdGeDoubleArray m_dashes
Definition: HatchPattern.h:47
TD_PackPop.h
OdGiFill
Definition: GiFill.h:39
OdHatchPatternLine::m_patternOffset
OdGeVector2d m_patternOffset
Definition: HatchPattern.h:46
RxObject.h
OdUInt32
unsigned int OdUInt32
Definition: OdPlatformSettings.h:783
OdGiHatchPattern::m_aHatchPattern
OdHatchPattern m_aHatchPattern
Definition: GiFill.h:162
OdGiFill::loadBytes
virtual void loadBytes(const OdUInt8 *pBytes)
Definition: GiFill.h:117
OdGiFill::m_dDeviation
double m_dDeviation
Definition: GiFill.h:41
OdArray::getPtr
const T * getPtr() const
Definition: OdArray.h:1102
OdRxObject::isA
virtual OdRxClass * isA() const
OdHatchPatternLine::m_dLineAngle
double m_dLineAngle
Definition: HatchPattern.h:44
OdGiHatchPattern::OdGiHatchPattern
OdGiHatchPattern()
Definition: GiFill.h:191
OdGiFill::popDbl
void popDbl(const OdUInt8 *&pBytes, double &dDbl) const
Definition: GiFill.h:141
OdSmartPtr< OdGiFill >
OdGiFill::OdGiFill
OdGiFill()
Definition: GiFill.h:71
OdDAI::operator!=
bool DAI_EXPORT operator!=(const OdDAI::OdSelect &left, const OdDAI::OdSelect &right)
OdGiHatchPattern
Definition: GiFill.h:160
OdArray::size
size_type size() const
Definition: OdArray.h:893
OdArray::resize
void resize(size_type logicalLength, const T &value)
Definition: OdArray.h:834
OdArray::insert
void insert(iterator before, const_iterator first, const_iterator afterLast)
Definition: OdArray.h:800
OdGeVector2d::y
double y
Definition: GeVector2d.h:454
OdGiHatchPattern::patternLines
const OdHatchPattern & patternLines() const
Definition: GiFill.h:197
TD_PackPush.h
OdHatchPatternLine::m_basePoint
OdGePoint2d m_basePoint
Definition: HatchPattern.h:45
OdGiHatchPattern::saveBytes
virtual void saveBytes(OdUInt8Array &bytes) const
Definition: GiFill.h:268
OdRxObject::cast
static OdRxObjectPtr cast(const OdRxObject *pointer)
Definition: RxObject.h:640
OdGiHatchPattern::isDraft
bool isDraft() const
Definition: GiFill.h:323
UInt8Array.h
OdGiFill::pushInt
void pushInt(OdUInt8Array &bytes, OdUInt32 nInt) const
Definition: GiFill.h:133
OdGiFill::ODRX_DECLARE_MEMBERS
ODRX_DECLARE_MEMBERS(OdGiFill)
OdError
Definition: OdError.h:43
OdArray::push_back
void push_back(const T &value)
Definition: OdArray.h:987
HatchPattern.h
OdDAI::operator==
bool DAI_EXPORT operator==(const OdFileDescriptionAuto &left, const OdFileDescriptionAuto &right)
OdGiFill::pushDbl
void pushDbl(OdUInt8Array &bytes, double dDbl) const
Definition: GiFill.h:125
OdGiHatchPattern::operator!=
virtual bool operator!=(const OdGiFill &fill) const
Definition: GiFill.h:262
OdRxObject::copyFrom
virtual void copyFrom(const OdRxObject *pSource)
OdGiFill::setDeviation
void setDeviation(double dDeviation)
Definition: GiFill.h:82
OdGiHatchPattern::setDraft
void setDraft(bool draft)
Definition: GiFill.h:329
OdGiFill::operator==
virtual bool operator==(const OdGiFill &fill) const
Definition: GiFill.h:98
OdGiHatchPattern::operator==
virtual bool operator==(const OdGiFill &fill) const
Definition: GiFill.h:229
OdGiFill::popInt
void popInt(const OdUInt8 *&pBytes, OdUInt32 &nInt) const
Definition: GiFill.h:148
OdGiHatchPattern::setPatternLines
void setPatternLines(const OdHatchPattern &aHatchPattern)
Definition: GiFill.h:209
OdGiHatchPattern::ODRX_DECLARE_MEMBERS
ODRX_DECLARE_MEMBERS(OdGiHatchPattern)
OdGiFillPtr
OdSmartPtr< OdGiFill > OdGiFillPtr
Definition: GiFill.h:68
OdGePoint2d::x
double x
Definition: GePoint2d.h:299