1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 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 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGOSGSceneFileType.h"
50 #include "OSGOSGWriter.h"
52 #include "OSGOSGLoader.h"
57 /*! \class OSG::OSGSceneFileType
60 /***************************************************************************\
62 \***************************************************************************/
64 /***************************************************************************\
66 \***************************************************************************/
68 const Char8
*OSGSceneFileType::_suffixA
[] = { "osg" };
70 OSGSceneFileType
OSGSceneFileType::_the(_suffixA
,
77 /***************************************************************************\
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
83 \*-------------------------------------------------------------------------*/
85 OSGSceneFileType
&OSGSceneFileType::the(void)
90 /*-------------------------------------------------------------------------*\
92 \*-------------------------------------------------------------------------*/
94 /*-------------------------------------------------------------------------*\
96 \*-------------------------------------------------------------------------*/
98 /***************************************************************************\
100 \***************************************************************************/
102 /*-------------------------------------------------------------------------*\
104 \*-------------------------------------------------------------------------*/
106 /*------------------------------ access -----------------------------------*/
108 const Char8
*OSGSceneFileType::getName(void) const
110 return "OSG Ascii Geometry";
114 NodeTransitPtr
OSGSceneFileType::read( std::istream
&is
,
115 const Char8
*fileNameOrExtension
,
116 Resolver resolver
) const
118 FileContextAttachmentUnrecPtr
119 pFileContext
= FileContextAttachment::create();
121 pFileContext
->setResolvedName(fileNameOrExtension
);
123 OSGLoader
*_pFile
= new OSGLoader(_endNodeFunctors
, pFileContext
);
125 NodeTransitPtr returnValue
= _pFile
->scanStream(is
, resolver
);
127 if(returnValue
->getNChildren() == 1)
129 returnValue
= returnValue
->getChild(0);
132 returnValue
->addAttachment(pFileContext
);
141 FieldContainerTransitPtr
OSGSceneFileType::readContainer(
142 const Char8
*fileName
,
143 Resolver resolver
) const
147 SWARNING
<< "cannot read NULL file" << std::endl
;
148 return FieldContainerTransitPtr(NULL
);
151 FileContextAttachmentUnrecPtr
152 pFileContext
= FileContextAttachment::create();
154 pFileContext
->setResolvedName(fileName
);
156 OSGLoader
*_pFile
= new OSGLoader(_endNodeFunctors
, pFileContext
);
158 std::ifstream
is(fileName
, std::ios::binary
);
160 FieldContainerTransitPtr returnValue
=
161 _pFile
->scanStreamContainer(is
, resolver
);
163 AttachmentContainer
*pAttCnt
=
164 dynamic_cast<AttachmentContainer
*>(returnValue
.get());
168 pAttCnt
->addAttachment(pFileContext
);
178 bool OSGSceneFileType::write(Node
* const root
,
180 Char8
const * ) const
184 FFATAL(("Can not open output stream!\n"));
188 IndentOutStreamMixin
<OutStream
> iOStream(os
);
190 OSGWriter
writer(iOStream
, 4);
196 bool OSGSceneFileType::writeContainer(FieldContainer
* const pContainer
,
197 Char8
const *fileName
) const
201 SWARNING
<< "cannot write NULL file" << std::endl
;
205 std::ofstream
os(fileName
, std::ios::binary
);
207 IndentOutStreamMixin
<OutStream
> iOStream(os
);
209 OSGWriter
writer(iOStream
, 4);
211 writer
.write(pContainer
);
216 /*---------------------------- properties ---------------------------------*/
218 void OSGSceneFileType::registerEndNodeCallback(const FieldContainerType
&type
,
221 if(_endNodeFunctors
.size() <= type
.getId())
222 _endNodeFunctors
.resize(type
.getId() + 1, NULL
);
224 _endNodeFunctors
[type
.getId()] = func
;
227 /*-------------------------- your_category---------------------------------*/
229 /*-------------------------- assignment -----------------------------------*/
231 /*-------------------------- comparison -----------------------------------*/
234 /*-------------------------------------------------------------------------*\
236 \*-------------------------------------------------------------------------*/
239 /** \brief Constructor
242 OSGSceneFileType::OSGSceneFileType(const char *suffixArray
[],
243 UInt16 suffixByteCount
,
245 UInt32 overridePriority
,
247 Inherited(suffixArray
,
258 /** \brief Destructor
261 OSGSceneFileType::~OSGSceneFileType(void)
265 void OSGSceneFileType::terminate(void)
267 _endNodeFunctors
.clear();