changed: gcc8 base update
[opensg.git] / Source / System / FileIO / OSB / OSGOSBMaterialPoolElement.cpp
blob24ef8bbc2e991019eed864bdcc716098f331426c
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2009 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include "OSGOSBMaterialPoolElement.h"
41 #include "OSGOSBRootElement.h"
43 #include "OSGGroup.h"
45 OSG_USING_NAMESPACE
47 /*-------------------------------------------------------------------------*/
48 /* OSBMaterialPoolElement */
49 /*-------------------------------------------------------------------------*/
51 /*! Reads the removed MaterialPool from an osb and converts it to a Group
52 with a ContainerCollection attachment.
55 /*-------------------------------------------------------------------------*/
56 /* Static members */
58 OSBElementRegistrationHelper<OSBMaterialPoolElement>
59 OSBMaterialPoolElement::_regHelper =
60 OSBElementRegistrationHelper<OSBMaterialPoolElement>("MaterialPool");
62 /*-------------------------------------------------------------------------*/
63 /* Constructor */
65 OSBMaterialPoolElement::OSBMaterialPoolElement(OSBRootElement *root) :
67 Inherited (root, OSGOSBHeaderVersion200),
68 _pCollection(NULL )
72 /*-------------------------------------------------------------------------*/
73 /* Destructor */
75 OSBMaterialPoolElement::~OSBMaterialPoolElement(void)
79 /*-------------------------------------------------------------------------*/
80 /* Reading */
82 void
83 OSBMaterialPoolElement::read(const std::string &typeName)
85 OSG_OSB_LOG(("OSBMaterialPoolElement::read: [%s]\n", typeName.c_str()));
87 BinaryReadHandler *rh = editRoot()->getReadHandler();
89 UInt8 ptrTypeId;
90 UInt16 version;
92 rh->getValue(ptrTypeId);
93 rh->getValue(version );
95 GroupUnrecPtr group = Group ::create();
96 _pCollection = ContainerCollection::create();
98 setContainer(group);
100 // set attachment on the Group
101 group ->addAttachment(_pCollection );
102 _pCollection->setName ("MaterialPool");
104 std::string fieldName;
105 std::string fieldTypeName;
106 UInt32 fieldSize;
107 PtrFieldListIt ptrFieldIt;
109 while(readFieldHeader("", fieldName, fieldTypeName, fieldSize))
111 if(fieldName == "materials")
113 // materials from MaterialPool need to be stored in the
114 // ContainerCollection
115 readMaterialsField();
117 else
119 // all other fields can be read directly
120 readFieldContent(fieldName, fieldTypeName,
121 fieldSize, "", ptrFieldIt);
126 void
127 OSBMaterialPoolElement::postRead(void)
129 Inherited::postRead();
132 /*-------------------------------------------------------------------------*/
133 /* Writing */
135 void
136 OSBMaterialPoolElement::preWrite(FieldContainer * const fc)
138 OSG_OSB_LOG(("OSBMaterialPoolElement::preWrite\n"));
140 preWriteFieldContainer(fc, "");
143 void
144 OSBMaterialPoolElement::write(void)
146 OSG_OSB_LOG(("OSBMaterialPoolElement::write\n"));
148 if(getContainer() == NULL)
150 FWARNING(("OSBMaterialPoolElement::write: Attempt to write NULL.\n"));
151 return;
154 BinaryWriteHandler *wh = editRoot()->getWriteHandler();
156 wh->putValue(getFCPtrType(getContainer()));
157 wh->putValue(getVersion() );
159 writeFields("", true);
162 /*! Reads MFMaterials from MaterialPool and stores the pointer ids so that
163 they get put into ContainerCollection MFContainers.
165 void
166 OSBMaterialPoolElement::readMaterialsField(void)
168 OSG_OSB_LOG(("OSBMaterialPoolElement::readMaterialsField\n"));
170 UInt32 ptrId;
171 UInt32 numElements;
172 OSBRootElement *root = editRoot();
173 BinaryReadHandler *rh = editRoot()->getReadHandler();
175 FieldDescriptionBase *contFieldDesc =
176 _pCollection->getFieldDescription("containers");
177 UInt32 contFieldId = contFieldDesc->getFieldId();
179 root->editPtrFieldList().push_back(PtrFieldInfo(_pCollection,
180 contFieldId ));
181 PtrFieldInfo &pfi = root->editPtrFieldList().back();
183 rh->getValue(numElements);
185 for(UInt32 i = 0; i < numElements; ++i)
187 rh->getValue(ptrId);
188 pfi.editIdStore().push_back(ptrId);