chore: KDIS datatypes
[KDIS.git] / KDIS / DataTypes / LinearSegmentParameter.cpp
blobb1f306b81a51678d5e0a0c466c83a4b0c1d15929
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 #include "./LinearSegmentParameter.h"
32 using namespace KDIS;
33 using namespace DATA_TYPE;
34 using namespace UTILS;
36 //////////////////////////////////////////////////////////////////////////
37 // public:
38 //////////////////////////////////////////////////////////////////////////
40 LinearSegmentParameter::LinearSegmentParameter() :
41 m_ui8SegNum( 0 ),
42 m_ui16Length( 0 ),
43 m_ui16Width( 0 ),
44 m_ui16Height( 0 ),
45 m_ui16Depth( 0 ),
46 m_ui32Padding( 0 )
48 m_ModificationUnion.m_ui8Modifications = 0;
51 //////////////////////////////////////////////////////////////////////////
53 LinearSegmentParameter::LinearSegmentParameter( KDataStream & stream )
55 Decode( stream );
58 //////////////////////////////////////////////////////////////////////////
60 LinearSegmentParameter::LinearSegmentParameter( KUINT8 SegNum, KUINT8 Mod, const LinearObjectAppearance & A,
61 const WorldCoordinates & Loc, const EulerAngles & Ori,
62 KUINT16 Length, KUINT16 Width, KUINT16 Height, KUINT16 Depth ) :
63 m_ui8SegNum( SegNum ),
64 m_ObjApr( A ),
65 m_Loc( Loc ),
66 m_Ori( Ori ),
67 m_ui16Length( Length ),
68 m_ui16Width( Width ),
69 m_ui16Height( Height ),
70 m_ui16Depth( Depth ),
71 m_ui32Padding( 0 )
73 m_ModificationUnion.m_ui8Modifications = Mod;
76 //////////////////////////////////////////////////////////////////////////
78 LinearSegmentParameter::~LinearSegmentParameter()
82 //////////////////////////////////////////////////////////////////////////
84 void LinearSegmentParameter::SetSegmentNumber( KUINT8 N )
86 m_ui8SegNum = N;
89 //////////////////////////////////////////////////////////////////////////
91 KUINT8 LinearSegmentParameter::GetSegmentNumber() const
93 return m_ui8SegNum;
96 //////////////////////////////////////////////////////////////////////////
98 void LinearSegmentParameter::SetModification( KUINT8 M )
100 m_ModificationUnion.m_ui8Modifications = M;
103 //////////////////////////////////////////////////////////////////////////
105 KUINT8 LinearSegmentParameter::GetModification() const
107 return m_ModificationUnion.m_ui8Modifications;
110 //////////////////////////////////////////////////////////////////////////
112 void LinearSegmentParameter::SetModificationLocation( KBOOL M /*= true*/ )
114 m_ModificationUnion.m_ui8LocBit = M;
117 //////////////////////////////////////////////////////////////////////////
119 KBOOL LinearSegmentParameter::IsModificationLocation() const
121 return m_ModificationUnion.m_ui8LocBit;
124 //////////////////////////////////////////////////////////////////////////
126 void LinearSegmentParameter::SetModificationOrientation( KBOOL M /*= true*/ )
128 m_ModificationUnion.m_ui8OriBit = M;
131 //////////////////////////////////////////////////////////////////////////
133 KBOOL LinearSegmentParameter::IsModificationOrientation() const
135 return m_ModificationUnion.m_ui8OriBit;
138 //////////////////////////////////////////////////////////////////////////
140 void LinearSegmentParameter::SetLinearObjectAppearance( const LinearObjectAppearance & L )
142 m_ObjApr = L;
145 //////////////////////////////////////////////////////////////////////////
147 const LinearObjectAppearance & LinearSegmentParameter::GetLinearObjectAppearance() const
149 return m_ObjApr;
152 //////////////////////////////////////////////////////////////////////////
154 LinearObjectAppearance & LinearSegmentParameter::GetLinearObjectAppearance()
156 return m_ObjApr;
159 //////////////////////////////////////////////////////////////////////////
161 void LinearSegmentParameter::SetLocation( const WorldCoordinates & L )
163 m_Loc = L;
166 //////////////////////////////////////////////////////////////////////////
168 const WorldCoordinates & LinearSegmentParameter::GetLocation() const
170 return m_Loc;
173 //////////////////////////////////////////////////////////////////////////
175 WorldCoordinates & LinearSegmentParameter::GetLocation()
177 return m_Loc;
180 //////////////////////////////////////////////////////////////////////////
182 void LinearSegmentParameter::SetOrientation( const EulerAngles & O )
184 m_Ori = O;
187 //////////////////////////////////////////////////////////////////////////
189 const EulerAngles & LinearSegmentParameter::GetOrientation() const
191 return m_Ori;
194 //////////////////////////////////////////////////////////////////////////
196 EulerAngles & LinearSegmentParameter::GetOrientation()
198 return m_Ori;
201 //////////////////////////////////////////////////////////////////////////
203 void LinearSegmentParameter::SetLength( KUINT16 L )
205 m_ui16Length = L;
208 //////////////////////////////////////////////////////////////////////////
210 KUINT16 LinearSegmentParameter::GetLength() const
212 return m_ui16Length;
215 //////////////////////////////////////////////////////////////////////////
217 void LinearSegmentParameter::SetWidth( KUINT16 W )
219 m_ui16Width = W;
222 //////////////////////////////////////////////////////////////////////////
224 KUINT16 LinearSegmentParameter::GetWidth() const
226 return m_ui16Width;
229 //////////////////////////////////////////////////////////////////////////
231 void LinearSegmentParameter::SetHeight( KUINT16 H )
233 m_ui16Height = H;
236 //////////////////////////////////////////////////////////////////////////
238 KUINT16 LinearSegmentParameter::GetHeight() const
240 return m_ui16Height;
243 //////////////////////////////////////////////////////////////////////////
245 void LinearSegmentParameter::SetDepth( KUINT16 D )
247 m_ui16Depth = D;
250 //////////////////////////////////////////////////////////////////////////
252 KUINT16 LinearSegmentParameter::GetDepth() const
254 return m_ui16Depth;
257 //////////////////////////////////////////////////////////////////////////
259 KString LinearSegmentParameter::GetAsString() const
261 KStringStream ss;
263 ss << "LinearSegmentParameter:\n"
264 << "\tSegment Number: " << ( KUINT16 )m_ui8SegNum << "\n"
265 << "\tModification:\n"
266 << "\t\tLocation: " << ( KUINT16 )m_ModificationUnion.m_ui8LocBit << "\n"
267 << "\t\tOrientation: " << ( KUINT16 )m_ModificationUnion.m_ui8OriBit << "\n"
268 << IndentString( m_ObjApr.GetAsString(), 1 )
269 << "\tLocation: " << m_Loc.GetAsString()
270 << "\tOrientation: " << m_Ori.GetAsString()
271 << "\tLength: " << m_ui16Length << "\n"
272 << "\tWidth: " << m_ui16Width << "\n"
273 << "\tHeight: " << m_ui16Height << "\n"
274 << "\tDepth: " << m_ui16Depth << "\n";
276 return ss.str();
279 //////////////////////////////////////////////////////////////////////////
281 void LinearSegmentParameter::Decode( KDataStream & stream )
283 if( stream.GetBufferSize() < LINEAR_SEGMENT_PARAMETER_SIZE )throw KException( __FUNCTION__, NOT_ENOUGH_DATA_IN_BUFFER );
285 stream >> m_ui8SegNum
286 >> m_ModificationUnion.m_ui8Modifications
287 >> KDIS_STREAM m_ObjApr
288 >> KDIS_STREAM m_Loc
289 >> KDIS_STREAM m_Ori
290 >> m_ui16Length
291 >> m_ui16Width
292 >> m_ui16Height
293 >> m_ui16Depth
294 >> m_ui32Padding;
297 //////////////////////////////////////////////////////////////////////////
299 KDataStream LinearSegmentParameter::Encode() const
301 KDataStream stream;
303 LinearSegmentParameter::Encode( stream );
305 return stream;
308 //////////////////////////////////////////////////////////////////////////
310 void LinearSegmentParameter::Encode( KDataStream & stream ) const
312 stream << m_ui8SegNum
313 << m_ModificationUnion.m_ui8Modifications
314 << KDIS_STREAM m_ObjApr
315 << KDIS_STREAM m_Loc
316 << KDIS_STREAM m_Ori
317 << m_ui16Length
318 << m_ui16Width
319 << m_ui16Height
320 << m_ui16Depth
321 << m_ui32Padding;
324 //////////////////////////////////////////////////////////////////////////
326 KBOOL LinearSegmentParameter::operator == ( const LinearSegmentParameter & Value ) const
328 if( m_ui8SegNum != Value.m_ui8SegNum ) return false;
329 if( m_ModificationUnion.m_ui8Modifications != Value.m_ModificationUnion.m_ui8Modifications ) return false;
330 if( m_ObjApr != Value.m_ObjApr ) return false;
331 if( m_Loc != Value.m_Loc ) return false;
332 if( m_Ori != Value.m_Ori ) return false;
333 if( m_ui16Length != Value.m_ui16Length ) return false;
334 if( m_ui16Width != Value.m_ui16Width ) return false;
335 if( m_ui16Height != Value.m_ui16Height ) return false;
336 if( m_ui16Depth != Value.m_ui16Depth ) return false;
337 return true;
340 //////////////////////////////////////////////////////////////////////////
342 KBOOL LinearSegmentParameter::operator != ( const LinearSegmentParameter & Value ) const
344 return !( *this == Value );
347 //////////////////////////////////////////////////////////////////////////