From b1177e902576abbd9e795a9ac86e1dc10d0ff62b Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo Date: Tue, 22 Dec 2015 08:19:05 +1100 Subject: [PATCH] Work in progress: VRML2 parser --- plugins/3d/vrml/v2/vrml2_base.cpp | 14 +++++++++++++- plugins/3d/vrml/v2/vrml2_base.h | 1 + plugins/3d/vrml/v2/vrml2_node.cpp | 6 ++++++ plugins/3d/vrml/v2/vrml2_node.h | 12 ++++++++++++ plugins/3d/vrml/v2/wrlproc.cpp | 21 +++++++++++++++++++-- 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/plugins/3d/vrml/v2/vrml2_base.cpp b/plugins/3d/vrml/v2/vrml2_base.cpp index d41b58de26..87721eb84e 100644 --- a/plugins/3d/vrml/v2/vrml2_base.cpp +++ b/plugins/3d/vrml/v2/vrml2_base.cpp @@ -206,7 +206,13 @@ bool WRL2BASE::Read( WRLPROC& proc ) if( !glob.compare( "PROTO" ) ) { - // XXX - implement + if( !proc.ReadName( glob ) || !proc.ReadName( glob ) || !proc.DiscardList() ) + { + #ifdef DEBUG + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << proc.GetError() << "\n"; + #endif + } } if( !glob.compare( "EXTERNPROTO" ) ) @@ -326,3 +332,9 @@ bool WRL2BASE::Read( WRLPROC& proc ) #warning TO BE IMPLEMENTED return false; } + + +bool WRL2BASE::isDangling( void ) +{ + return false; +} diff --git a/plugins/3d/vrml/v2/vrml2_base.h b/plugins/3d/vrml/v2/vrml2_base.h index 055a5b37fc..daae1c2eed 100644 --- a/plugins/3d/vrml/v2/vrml2_base.h +++ b/plugins/3d/vrml/v2/vrml2_base.h @@ -68,6 +68,7 @@ public: // functions inherited from WRL2NODE void unlinkChildNode( const WRL2NODE* aNode ); void unlinkRefNode( const WRL2NODE* aNode ); + bool isDangling( void ); public: WRL2BASE(); diff --git a/plugins/3d/vrml/v2/vrml2_node.cpp b/plugins/3d/vrml/v2/vrml2_node.cpp index d29a46aad0..197706b2f6 100644 --- a/plugins/3d/vrml/v2/vrml2_node.cpp +++ b/plugins/3d/vrml/v2/vrml2_node.cpp @@ -266,3 +266,9 @@ WRL2NODES WRL2NODE::getNodeTypeID( const std::string aNodeName ) return WRL2_INVALID; } + + +const char* WRL2NODE::GetError( void ) +{ + return m_error.c_str(); +} diff --git a/plugins/3d/vrml/v2/vrml2_node.h b/plugins/3d/vrml/v2/vrml2_node.h index 27bba16d1b..fda75bbf19 100644 --- a/plugins/3d/vrml/v2/vrml2_node.h +++ b/plugins/3d/vrml/v2/vrml2_node.h @@ -61,6 +61,7 @@ protected: std::string m_Name; // name to use for referencing the node by name std::list< WRL2NODE* > m_BackPointers; // nodes which hold a reference to this + std::string m_error; public: @@ -107,6 +108,15 @@ public: */ void delNodeRef( WRL2NODE* aNode ); + /** + * Function isDangling + * returns true if the object does not have a parent which is a logical + * container for the object - for example if a Shape has a parent which + * is a Base node. This function is used to determine whether an object + * should be moved to a different parent during the VRML to SG* translation. + */ + virtual bool isDangling( void ) = 0; + public: WRL2NODE(); virtual ~WRL2NODE(); @@ -157,6 +167,8 @@ public: virtual bool AddRefNode( WRL2NODE* aNode ) = 0; virtual bool AddChildNode( WRL2NODE* aNode ) = 0; + + const char* GetError( void ); }; #endif // VRML2_NODE_H diff --git a/plugins/3d/vrml/v2/wrlproc.cpp b/plugins/3d/vrml/v2/wrlproc.cpp index cece05f109..e7b54f4bbf 100644 --- a/plugins/3d/vrml/v2/wrlproc.cpp +++ b/plugins/3d/vrml/v2/wrlproc.cpp @@ -292,8 +292,25 @@ bool WRLPROC::ReadName( std::string& aName ) while( m_buf[m_linepos] > 0x20 && m_linepos < ssize ) { - if( '[' == m_buf[m_linepos] || '{' == m_buf[m_linepos] ) - return true; + if( '[' == m_buf[m_linepos] || '{' == m_buf[m_linepos] + || '.' == m_buf[m_linepos] || '#' == m_buf[m_linepos] ) + { + if( !aName.empty() ) + { + return true; + } + else + { + std::ostringstream ostr; + ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n"; + ostr << " * [INFO] failed on file '" << m_filename << "'\n"; + ostr << " * [INFO] line " << m_fileline << ", column " << m_linepos; + ostr << " -- invalid name"; + m_error = ostr.str(); + + return false; + } + } if( m_badchars.find( m_buf[m_linepos] ) != std::string::npos ) {