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 \*---------------------------------------------------------------------------*/
41 /*-------------------------------------------------------------------------*/
42 /* OSBGeoPropertyConversionElement */
43 /*-------------------------------------------------------------------------*/
45 /*-------------------------------------------------------------------------*/
48 template <class GeoPropertyTypeT>
49 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::
50 OSBGeoPropertyConversionElement(OSBRootElement *root)
51 : Inherited(root, OSGOSBHeaderVersion200)
55 /*-------------------------------------------------------------------------*/
58 template <class GeoPropertyTypeT>
59 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::
60 ~OSBGeoPropertyConversionElement(void)
64 /*-------------------------------------------------------------------------*/
67 template <class GeoPropertyTypeT>
69 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::read(
70 const std::string &typeName)
72 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: typeName: [%s]\n",
75 BinaryReadHandler *rh = editRoot()->getReadHandler();
76 GeoPropertyUnrecPtrType prop = GeoPropertyType::create();
77 GeoPropertyFieldType *propField = prop->editFieldPtr();
83 rh->getValue(fcPtrType);
84 rh->getValue(version );
86 if(version > OSGOSBHeaderVersion100)
88 FWARNING(("OSBGeoPropertyConversionElement<>::read: "
89 "Unknown version, trying to read as OpenSG 1.\n"));
94 std::string fieldName;
95 std::string fieldTypeName;
97 PtrFieldListIt ptrFieldIt;
99 if(!readFieldHeader("", fieldName, fieldTypeName, fieldSize))
101 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
102 "Reading stopped at field: [%s].\n", fieldName.c_str()));
106 // Depending on what OpenSG 1 property is read, the field holding the
107 // data has different names, while in OpenSG 2 the field is always
110 if(fieldName == "positions")
112 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
114 fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
116 propField->copyFromBin(*rh);
118 else if(fieldName == "normals")
120 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
122 fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
124 propField->copyFromBin(*rh);
126 else if(fieldName == "TexCoords")
128 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
130 fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
132 propField->copyFromBin(*rh);
134 else if(fieldName == "colors")
136 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
138 fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
140 propField->copyFromBin(*rh);
142 else if(fieldName == "types")
144 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
146 fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
148 propField->copyFromBin(*rh);
150 else if(fieldName == "lengths")
152 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
154 fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
156 propField->copyFromBin(*rh);
158 else if(fieldName == "indices")
160 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
162 fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
164 propField->copyFromBin(*rh);
168 // all other fields can be read normally
169 readFieldContent(fieldName, fieldTypeName,
170 fieldSize, "", ptrFieldIt);
175 template <class GeoPropertyTypeT>
177 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::postRead(void)
179 OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::postRead:\n"));
182 /*-------------------------------------------------------------------------*/
185 template <class GeoPropertyTypeT>
187 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::preWrite(
188 FieldContainer * const fc)
190 FFATAL(("OSBGeoPropertyConversionElement<>::preWrite: "
191 "This should NEVER be called.\n"));
194 template <class GeoPropertyTypeT>
196 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::write(void)
198 FFATAL(("OSBGeoPropertyConversionElement<>::preWrite: "
199 "This should NEVER be called.\n"));