changed: gcc8 base update
[opensg.git] / Source / System / FileIO / OSB / OSGOSBGeoPropertyConversionElement.inl
blob954d0e4d6305e82073d272e75b0e10c5a5d26d75
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *                   Copyright (C) 2006 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 OSG_BEGIN_NAMESPACE
41 /*-------------------------------------------------------------------------*/
42 /* OSBGeoPropertyConversionElement                                         */
43 /*-------------------------------------------------------------------------*/
45 /*-------------------------------------------------------------------------*/
46 /* Constructor                                                             */
48 template <class GeoPropertyTypeT>
49 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::
50     OSBGeoPropertyConversionElement(OSBRootElement *root)
51     : Inherited(root, OSGOSBHeaderVersion200)
55 /*-------------------------------------------------------------------------*/
56 /* Destructor                                                              */
58 template <class GeoPropertyTypeT>
59 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::
60     ~OSBGeoPropertyConversionElement(void)
64 /*-------------------------------------------------------------------------*/
65 /* Reading                                                                 */
67 template <class GeoPropertyTypeT>
68 void
69 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::read(
70     const std::string &typeName)
72     OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: typeName: [%s]\n",
73             typeName.c_str()));
75     BinaryReadHandler       *rh        = editRoot()->getReadHandler();
76     GeoPropertyUnrecPtrType  prop      = GeoPropertyType::create();
77     GeoPropertyFieldType    *propField = prop->editFieldPtr();
79     setContainer(prop);
81     UInt8  fcPtrType;
82     UInt16 version;
83     rh->getValue(fcPtrType);
84     rh->getValue(version  );
86     if(version > OSGOSBHeaderVersion100)
87     {
88         FWARNING(("OSBGeoPropertyConversionElement<>::read: "
89                   "Unknown version, trying to read as OpenSG 1.\n"));
90     }
92     while(true)
93     {
94         std::string    fieldName;
95         std::string    fieldTypeName;
96         UInt32         fieldSize;
97         PtrFieldListIt ptrFieldIt;
99         if(!readFieldHeader("", fieldName, fieldTypeName, fieldSize))
100         {
101             OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
102                     "Reading stopped at field: [%s].\n", fieldName.c_str()));
103             break;
104         }
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
108         // named "values"
110         if(fieldName == "positions")
111         {
112             OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
113                     "[%s] [%s] [%u]\n",
114                     fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
116             propField->copyFromBin(*rh);
117         }
118         else if(fieldName == "normals")
119         {
120             OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
121                     "[%s] [%s] [%u]\n",
122                     fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
124             propField->copyFromBin(*rh);
125         }
126         else if(fieldName == "TexCoords")
127         {
128             OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
129                     "[%s] [%s] [%u]\n",
130                     fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
132             propField->copyFromBin(*rh);
133         }
134         else if(fieldName == "colors")
135         {
136             OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
137                     "[%s] [%s] [%u]\n",
138                     fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
140             propField->copyFromBin(*rh);
141         }
142         else if(fieldName == "types")
143         {
144             OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
145                     "[%s] [%s] [%u]\n",
146                     fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
148             propField->copyFromBin(*rh);
149         }
150         else if(fieldName == "lengths")
151         {
152             OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
153                     "[%s] [%s] [%u]\n",
154                     fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
156             propField->copyFromBin(*rh);
157         }
158         else if(fieldName == "indices")
159         {
160             OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::read: "
161                     "[%s] [%s] [%u]\n",
162                     fieldName.c_str(), fieldTypeName.c_str(), fieldSize));
164             propField->copyFromBin(*rh);
165         }
166         else
167         {
168             // all other fields can be read normally
169             readFieldContent(fieldName, fieldTypeName,
170                              fieldSize, "", ptrFieldIt);
171         }
172     }
175 template <class GeoPropertyTypeT>
176 void
177 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::postRead(void)
179     OSG_OSB_LOG(("OSBGeoPropertyConversionElement<>::postRead:\n"));
182 /*-------------------------------------------------------------------------*/
183 /* Writing                                                                 */
185 template <class GeoPropertyTypeT>
186 void
187 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::preWrite(
188     FieldContainer * const fc)
190     FFATAL(("OSBGeoPropertyConversionElement<>::preWrite: "
191             "This should NEVER be called.\n"));
194 template <class GeoPropertyTypeT>
195 void
196 OSBGeoPropertyConversionElement<GeoPropertyTypeT>::write(void)
198     FFATAL(("OSBGeoPropertyConversionElement<>::preWrite: "
199             "This should NEVER be called.\n"));
202 OSG_END_NAMESPACE