1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2008 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #include "OSGOFDatabase.h"
42 #include "OSGOFPrimaryRecords.h"
43 #include "OSGOpenFlightLog.h"
47 OFDatabase::OFDatabase(void) :
52 _pColorPalette (NULL
),
53 _pVertexPalette (NULL
),
54 _pTexturePalette (NULL
),
55 _pMaterialPalette(NULL
),
56 _targetUnits (VU_Meters
),
61 OFDatabase::~OFDatabase(void)
64 _pColorPalette
= NULL
;
65 _pVertexPalette
= NULL
;
66 _pTexturePalette
= NULL
;
67 _pMaterialPalette
= NULL
;
70 bool OFDatabase::read(std::istream
&is
)
72 bool returnValue
= true;
74 OFRecordHeader oRHeader
;
76 returnValue
= oRHeader
.read(is
);
78 if(returnValue
== false)
81 _pHeader
= dynamic_pointer_cast
<OFHeaderRecord
>(
82 OFHeaderRecord::create(oRHeader
, *this));
84 returnValue
= _pHeader
->read(is
);
86 if(returnValue
== false)
89 _sRecords
.push(_pHeader
);
92 _pCurrPrimary
= _pHeader
;
94 while(returnValue
== true)
96 returnValue
= oRHeader
.read(is
);
98 if(returnValue
== false)
101 if(oRHeader
.sOpCode
== OFContinuationOC
)
105 _pCurr
->readContinue(is
, oRHeader
.sLength
- 4);
109 FWARNING(("OFDatabase::read: Found ContinuationRecord, "
110 "without preceding record.\n"));
115 _pCurr
= OFRecordFactory::the()->createRecord(oRHeader
, *this);
119 returnValue
= _pCurr
->read(is
);
121 if(_pCurr
->getCategory() == OFRecord::RC_Primary
)
123 _sRecords
.top()->addChild(_pCurr
);
124 _pCurrPrimary
= _pCurr
;
126 else if(_pCurr
->getCategory() == OFRecord::RC_Ancillary
)
128 _pCurrPrimary
->addChild(_pCurr
);
133 FFATAL(("OFDatabase::read: Failed to create record for "
136 OFRecord::getOpCodeString(oRHeader
.sOpCode
)));
142 _pCurrPrimary
= NULL
;
146 if(_sRecords
.empty() != true)
148 FWARNING(("OFDatabase::read: Record stack inconsistent.\n"));
154 NodeTransitPtr
OFDatabase::convert(void)
156 NodeTransitPtr
returnValue(NULL
);
161 #ifndef OSG_OPENFLIGHT_SILENT
165 returnValue
= _pHeader
->convertToNode();
170 void OFDatabase::pushLevel(void)
172 _sRecords
.push(_pCurrPrimary
);
175 void OFDatabase::popLevel(void)
179 _pCurrPrimary
= _sRecords
.top();
182 OFDatabase::VertexUnits
OFDatabase::getTargetUnits(void) const
187 void OFDatabase::setTargetUnits(VertexUnits units
)
189 _targetUnits
= units
;
192 Real32
OFDatabase::getUnitScale(void) const
197 void OFDatabase::setUnitScale(Real32 scale
)
202 const OFColorPaletteRecord
*OFDatabase::getColorPalette(void)
204 if(_pColorPalette
== NULL
)
207 return _pColorPalette
->getRecord();
210 const OFVertexPaletteRecord
*OFDatabase::getVertexPalette(void)
212 if(_pVertexPalette
== NULL
)
215 return _pVertexPalette
->getRecord();
218 const OFTexturePaletteRecord
*OFDatabase::getTexRecord(UInt32 uiIdx
)
220 if(_pTexturePalette
== NULL
)
223 return _pTexturePalette
->getRecord(uiIdx
);
226 const OFMaterialPaletteRecord
*OFDatabase::getMatRecord(UInt32 uiIdx
)
228 if(_pMaterialPalette
== NULL
)
231 return _pMaterialPalette
->getRecord(uiIdx
);
234 void OFDatabase::addColorPaletteRecord(OFColorPaletteRecord
*pColPal
)
236 if(_pColorPalette
== NULL
)
237 _pColorPalette
= new OFColorPalette
;
239 _pColorPalette
->addRecord(pColPal
);
242 void OFDatabase::addVertexPaletteRecord(OFVertexPaletteRecord
*pVertPal
)
244 if(_pVertexPalette
== NULL
)
245 _pVertexPalette
= new OFVertexPalette
;
247 _pVertexPalette
->addRecord(pVertPal
);
250 void OFDatabase::addTexturePaletteRecord(OFTexturePaletteRecord
*pTexPal
)
252 if(_pTexturePalette
== NULL
)
253 _pTexturePalette
= new OFTexturePalette
;
255 _pTexturePalette
->addRecord(pTexPal
);
258 void OFDatabase::addMaterialPaletteRecord(OFMaterialPaletteRecord
*pMatPal
)
260 if(_pMaterialPalette
== NULL
)
261 _pMaterialPalette
= new OFMaterialPalette
;
263 _pMaterialPalette
->addRecord(pMatPal
);