1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2006 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 "OSGOSBNodeElement.h"
41 #include "OSGOSBRootElement.h"
46 /*-------------------------------------------------------------------------*/
48 /*-------------------------------------------------------------------------*/
50 /*-------------------------------------------------------------------------*/
53 OSBElementRegistrationHelper
<OSBNodeElement
>
54 OSBNodeElement::_regHelper
=
55 OSBElementRegistrationHelper
<OSBNodeElement
>("Node");
57 /*-------------------------------------------------------------------------*/
60 OSBNodeElement::OSBNodeElement(OSBRootElement
*root
)
61 : Inherited(root
, OSGOSBHeaderVersion200
)
65 /*-------------------------------------------------------------------------*/
68 OSBNodeElement::~OSBNodeElement(void)
72 /*-------------------------------------------------------------------------*/
76 OSBNodeElement::read(const std::string
&typeName
)
78 OSG_OSB_LOG(("OSBNodeElement::read [%s]\n", typeName
.c_str()));
80 BinaryReadHandler
*rh
= editRoot()->getReadHandler();
84 rh
->getValue(fcPtrType
);
85 rh
->getValue(version
);
87 OSG_OSB_LOG(("OSBNodeElement::read: version: [%u]\n", version
));
89 if(fcPtrType
!= OSBCommonElement::FCPtrNode
)
91 FFATAL(("OSBNodeElement::read: fcPtrType has unexpected value.\n"));
97 NodeUnrecPtr node
= Node::create();
101 if(version
== OSGOSBHeaderVersion100
)
103 std::string fieldName
;
104 std::string fieldTypeName
;
106 PtrFieldListIt ptrFieldIt
;
108 while(readFieldHeader("", fieldName
, fieldTypeName
, fieldSize
))
110 // some fields need to be duplicated for the two replacement chunks
111 if(fieldName
== "volume")
113 // parent fields are ignored
114 UInt32 fieldType
= 0;
115 rh
->getValue(fieldType
);
125 rh
->getValue(sState
);
127 rh
->getValue(vMin
[0]);
128 rh
->getValue(vMin
[1]);
129 rh
->getValue(vMin
[2]);
130 rh
->getValue(vMax
[0]);
131 rh
->getValue(vMax
[1]);
132 rh
->getValue(vMax
[2]);
134 node
->editVolume().setState (sState
);
135 node
->editVolume().setBounds(vMin
, vMax
);
145 rh
->getValue(sState
);
147 rh
->getValue(vCenter
[0]);
148 rh
->getValue(vCenter
[1]);
149 rh
->getValue(vCenter
[2]);
150 rh
->getValue(fRadius
);
152 node
->editVolume().setState (sState
);
153 node
->editVolume().setBounds(vCenter
[0] - fRadius
,
154 vCenter
[1] - fRadius
,
155 vCenter
[2] - fRadius
,
156 vCenter
[0] + fRadius
,
157 vCenter
[1] + fRadius
,
158 vCenter
[2] + fRadius
);
164 "unknown volume type with size %d, skipping\n",
167 rh
->skip(fieldSize
- sizeof(UInt32
));
174 readFieldContent(fieldName
,
188 OSBNodeElement::postRead(void)
192 /*-------------------------------------------------------------------------*/
196 OSBNodeElement::preWrite(FieldContainer
* const fc
)
198 OSG_OSB_LOG(("OSBNodeElement::preWrite\n"));
200 preWriteFieldContainer(fc
, "");
204 OSBNodeElement::write(void)
206 OSG_OSB_LOG(("OSBNodeElement::write\n"));
208 if(getContainer() == NULL
)
210 FWARNING(("OSBNodeElement::write: Attempt to write NULL.\n"));
214 BinaryWriteHandler
*wh
= editRoot()->getWriteHandler();
216 wh
->putValue(OSBCommonElement::FCPtrNode
);
217 wh
->putValue(getVersion() );
219 const OSBRootElement
*root
= getRoot();
220 Node
*node
= dynamic_cast<Node
*>(getContainer());
221 std::string doSkipFields
= "";
223 if(node
->getVolume ().isStatic () == false &&
224 node
->getVolume ().isInfinite () == false &&
225 root
->getOptions().forceVolumeExport() == false )
227 doSkipFields
+= "'volume'";
230 writeFields(doSkipFields
, true);