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"
51 #ifdef OSG_FLEX_USE_IOSTREAM_INPUT
55 #include "OSGScanParseLexer.h"
56 #include "OSGScanParseSkel.h"
57 #include "OSGBaseFunctions.h"
63 /*-------------------------------------------------------------------------*/
66 ScanParseSkel::ScanParseSkel(void) :
67 _bMapTypeIds (false ),
68 _szReferenceHeader(NULL
),
69 _pLexer (new OSGScanParseLexer
),
78 _tmpBitVector1 (TypeTraits
<BitVector
>::BitsClear
),
86 /*-------------------------------------------------------------------------*/
89 ScanParseSkel::~ScanParseSkel(void)
95 delete [] _szReferenceHeader
;
98 /*-------------------------------------------------------------------------*/
101 extern int OSGScanParseSkel_parse(void *);
103 #ifdef OSG_FLEX_USE_IOSTREAM_INPUT
104 void ScanParseSkel::scanStream(std::istream
&iStream
)
108 _pLexer
->switch_streams(&iStream
, 0);
109 OSGScanParseSkel_parse(this);
114 void ScanParseSkel::scanFile(const Char8
*szFilename
)
116 if(szFilename
== NULL
)
119 #ifdef OSG_FLEX_USE_IOSTREAM_INPUT
120 std::ifstream
iStream(szFilename
);
124 PNOTICE
<< "Loading Stream: " << szFilename
<< std::endl
;
131 FILE *pInFile
= fopen(szFilename
, "r");
135 PNOTICE
<< "Loading File : " << szFilename
<< std::endl
;
137 OSGScanParseSkel_in
= pInFile
;
139 OSGScanParseSkel_parse(this);
146 Int32
ScanParseSkel::lex(YYSTYPE
*lvalp
)
148 return _pLexer
->yylex(lvalp
);
151 const Char8
*ScanParseSkel::getText(void)
153 return _pLexer
->YYText();
156 void ScanParseSkel::handleError(void *pSelf
, const Char8
*szErrorText
)
158 FWARNING(("-----> %s in Line %d, read '%s'\n",
164 /*-------------------------------------------------------------------------*/
167 bool ScanParseSkel::verifyHeader(const Char8
*szHeader
)
169 bool returnValue
= true;
173 SLOG
<< "Error Null Header String Read" << std::endl
;
177 if(_szReferenceHeader
!= NULL
)
181 osgStringLen(_szReferenceHeader
)) != 0)
183 SLOG
<< "Error : Header [" << szHeader
<< "] does not "
184 << "match reference [" << _szReferenceHeader
<< "]"
192 SLOG
<< "Error Null Reference Header, Check disabled " << std::endl
;
199 bool ScanParseSkel::checkHeader(void)
204 void ScanParseSkel::beginProto(const Char8
*)
208 void ScanParseSkel::endProto(void)
212 void ScanParseSkel::endProtoInterface(void)
216 void ScanParseSkel::beginExternProto(const Char8
*)
220 void ScanParseSkel::endExternProtoInterface(void)
224 void ScanParseSkel::endExternProto(void)
228 void ScanParseSkel::beginScript(const Char8
*)
232 void ScanParseSkel::endScript(void)
236 void ScanParseSkel::beginEventInDecl (const Char8
*,
242 void ScanParseSkel::beginEventOutDecl(const Char8
*,
248 void ScanParseSkel::endEventDecl(void)
252 void ScanParseSkel::beginFieldDecl(const Char8
*,
258 void ScanParseSkel::endFieldDecl(void)
262 void ScanParseSkel::beginExposedFieldDecl(const Char8
*,
268 void ScanParseSkel::endExposedFieldDecl(void)
273 void ScanParseSkel::addExternEventInDecl (const Char8
*,
279 void ScanParseSkel::addExternEventOutDecl(const Char8
*,
285 void ScanParseSkel::addExternFieldDecl(const Char8
*,
291 void ScanParseSkel::addExternExposedFieldDecl(const Char8
*,
297 /*-------------------------------------------------------------------------*/
300 void ScanParseSkel::beginField(const Char8
*,
305 void ScanParseSkel::endField(void)
309 /*-------------------------------------------------------------------------*/
312 void ScanParseSkel::beginNode(const Char8
*szNodeTypename
,
313 const Char8
*szNodename
,
314 const BitVector bvLocalFlags
)
316 fprintf(stderr
, "Calling default begin node %s %s\n",
321 void ScanParseSkel::endNode(void)
325 void ScanParseSkel::nullNode(void)
329 void ScanParseSkel::use(const Char8
*szName
)
331 PINFO
<< "Use : " << szName
<< std::endl
;
334 void ScanParseSkel::is(const Char8
*)
338 void ScanParseSkel::profileElement(const Char8
*szProfileName
)
340 fprintf(stderr
, "PROFILE %s\n", szProfileName
);
343 void ScanParseSkel::componentElement (const Char8
*szComponentName
)
345 fprintf(stderr
, "COMPONENT %s\n", szComponentName
);
348 void ScanParseSkel::metaElement (const Char8
*szMetaKey
,
349 const Char8
*szMetaValue
)
351 fprintf(stderr
, "META %s %s\n", szMetaKey
, szMetaValue
);
354 void ScanParseSkel::importElement(const Char8
*szInlineName
,
355 const Char8
*szNodeName
,
356 const Char8
*szImportAs
)
358 fprintf(stderr
, "IMPORT %s.%s AS %s\n",
359 szInlineName
, szNodeName
, szImportAs
);
362 void ScanParseSkel::exportElement(const Char8
*szNodeName
,
363 const Char8
*szExportAs
)
365 fprintf(stderr
, "EXPORT %s AS %s\n", szNodeName
, szExportAs
);
368 /*-------------------------------------------------------------------------*/
371 void ScanParseSkel::addBufferAsStringValue(void)
373 addStringValue(_pLexer
->YYText());
376 void ScanParseSkel::addFieldValue(const Char8
*)
380 void ScanParseSkel::addBoolValue(bool b
)
382 addFieldValue(_pLexer
->YYText());
385 void ScanParseSkel::addColorValue(const Color3f
&c
)
387 addFieldValue(_tmpString1
.c_str());
390 void ScanParseSkel::addColorRGBAValue(const Color4f
&c
)
392 addFieldValue(_tmpString1
.c_str());
395 void ScanParseSkel::addDoubleValue(Real64 d
)
397 addFieldValue(_pLexer
->YYText());
400 void ScanParseSkel::addFloatValue(Real32 f
)
402 addFieldValue(_pLexer
->YYText());
405 void ScanParseSkel::addImageValue(Image
*img
)
407 UInt32 numComponents
= img
->getComponents();
408 std::ostringstream os
;
409 os
<< img
->getWidth() << ' ' << img
->getHeight() << ' ' << numComponents
;
410 addFieldValue(os
.str().c_str());
411 UInt32 numPixels
= img
->getWidth() * img
->getHeight();
413 UInt8
*data
= img
->editData();
414 for (UInt32 i
= 0; i
< numPixels
; ++i
)
417 for (UInt32 j
= 0; j
< numComponents
; ++j
)
418 pixel
= (pixel
<< 8) | *data
++;
419 os
.str(std::string());
421 addFieldValue(os
.str().c_str());
425 void ScanParseSkel::addInt32Value(Int32 i
)
427 addFieldValue(_pLexer
->YYText());
430 void ScanParseSkel::addMatrix3dValue(Real64 m00
, Real64 m10
, Real64 m20
,
431 Real64 m01
, Real64 m11
, Real64 m21
,
432 Real64 m02
, Real64 m12
, Real64 m22
)
434 addFieldValue(_tmpString1
.c_str());
437 void ScanParseSkel::addMatrix3fValue(Real32 m00
, Real32 m10
, Real32 m20
,
438 Real32 m01
, Real32 m11
, Real32 m21
,
439 Real32 m02
, Real32 m12
, Real32 m22
)
441 addFieldValue(_tmpString1
.c_str());
444 void ScanParseSkel::addMatrix4dValue(const Matrix4d
&m
)
446 addFieldValue(_tmpString1
.c_str());
449 void ScanParseSkel::addMatrix4fValue(const Matrix4f
&m
)
451 addFieldValue(_tmpString1
.c_str());
454 void ScanParseSkel::addRotationValue(const Vec3f
&axis
, Real32 angle
)
456 addFieldValue(_tmpString1
.c_str());
459 void ScanParseSkel::addStringValue(const std::string
&s
)
461 addFieldValue(s
.c_str());
464 void ScanParseSkel::addTimeValue(Time t
)
466 addFieldValue(_pLexer
->YYText());
469 void ScanParseSkel::addVec2dValue(const Vec2d
&v
)
471 addFieldValue(_tmpString1
.c_str());
474 void ScanParseSkel::addVec3iValue(const Vec3i
&v
)
476 addFieldValue(_tmpString1
.c_str());
479 void ScanParseSkel::addVec2fValue(const Vec2f
&v
)
481 addFieldValue(_tmpString1
.c_str());
484 void ScanParseSkel::addVec3dValue(const Vec3d
&v
)
486 addFieldValue(_tmpString1
.c_str());
489 void ScanParseSkel::addVec3fValue(const Vec3f
&v
)
491 addFieldValue(_tmpString1
.c_str());
494 void ScanParseSkel::addVec4dValue(const Vec4d
&v
)
496 addFieldValue(_tmpString1
.c_str());
499 void ScanParseSkel::addVec4fValue(const Vec4f
&v
)
501 addFieldValue(_tmpString1
.c_str());
504 void ScanParseSkel::addColor4iValue(const Color4ub
&c
)
506 addFieldValue(_tmpString1
.c_str());
509 void ScanParseSkel::addPnt2fValue(const Pnt2f
&p
)
511 addFieldValue(_tmpString1
.c_str());
514 void ScanParseSkel::addPnt3fValue(const Pnt3f
&p
)
516 addFieldValue(_tmpString1
.c_str());
519 void ScanParseSkel::addPnt4fValue(const Pnt4f
&p
)
521 addFieldValue(_tmpString1
.c_str());
524 void ScanParseSkel::addVec2iValue(const Vec2i
&)
526 addFieldValue(_tmpString1
.c_str());
529 void ScanParseSkel::addPlaneValue(const Plane
&p
)
531 addFieldValue(_tmpString1
.c_str());
534 void ScanParseSkel::addVolumeValue(const BoxVolume
&v
)
536 addFieldValue(_tmpString1
.c_str());
539 void ScanParseSkel::addRoute(const Char8
*,
546 /*-------------------------------------------------------------------------*/
547 /* Type Information */
549 bool ScanParseSkel::getMapFieldTypes(void)
554 Int32
ScanParseSkel::mapExtIntFieldType(const Char8
*, const Int32 iFieldType
)
559 UInt32
ScanParseSkel::getFieldType(const Char8
*)
564 OSGScanParseLexer
*ScanParseSkel::getLexer(void)
570 /*-------------------------------------------------------------------------*/
573 void ScanParseSkel::addOptions(UInt32 options
)
578 void ScanParseSkel::subOptions(UInt32 options
)
580 _options
&= ~options
;
583 UInt32
ScanParseSkel::getOptions(void) const
588 /*-------------------------------------------------------------------------*/
591 void ScanParseSkel::reset(void)
595 void ScanParseSkel::setMapTypeIds(bool bVal
)
600 void ScanParseSkel::setReferenceHeader(const Char8
*szReferenceHeader
)
602 osgStringDup(szReferenceHeader
, _szReferenceHeader
);
605 /*-------------------------------------------------------------------------*/
607 void ScanParseSkel::beginValue()
609 _tmpString1
.assign(_pLexer
->YYText(), _pLexer
->YYLeng());
612 void ScanParseSkel::appendValue()
614 _tmpString1
.push_back(' ');
615 _tmpString1
.append(_pLexer
->YYText(), _pLexer
->YYLeng());
618 void ScanParseSkel::beginImage(Int32 width
, Int32 height
, Int32 components
)
622 _image
= Image::create();
627 case 1: pixelFormat
= Image::OSG_L_PF
; break;
628 case 2: pixelFormat
= Image::OSG_LA_PF
; break;
629 case 3: pixelFormat
= Image::OSG_RGB_PF
; break;
630 case 4: pixelFormat
= Image::OSG_RGBA_PF
; break;
631 default: pixelFormat
= Image::OSG_INVALID_PF
; break;
633 _image
->set(pixelFormat
, width
, height
);
634 _imageDataPtr
= _image
->editData();
635 _pLexer
->expectImageInts(width
* height
);
638 void ScanParseSkel::addImagePixel(Int32 pixel
)
640 switch (_image
->getPixelFormat())
642 case Image::OSG_RGBA_PF
:
643 *_imageDataPtr
++ = pixel
>> 24;
645 case Image::OSG_RGB_PF
:
646 *_imageDataPtr
++ = pixel
>> 16;
648 case Image::OSG_LA_PF
:
649 *_imageDataPtr
++ = pixel
>> 8;
651 case Image::OSG_L_PF
:
652 *_imageDataPtr
++ = pixel
;
659 void ScanParseSkel::endImage()
663 addImageValue(_image
);