2015-12-20 07:59:26 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2016-04-03 00:56:41 +00:00
|
|
|
#include <wx/filename.h>
|
2016-01-11 23:12:50 +00:00
|
|
|
#include <wx/string.h>
|
2016-02-23 00:20:34 +00:00
|
|
|
#include <wx/log.h>
|
2015-12-20 07:59:26 +00:00
|
|
|
#include "wrlproc.h"
|
|
|
|
|
|
|
|
#define GETLINE do {\
|
2016-01-11 23:12:50 +00:00
|
|
|
try { \
|
|
|
|
char* cp = m_file->ReadLine(); \
|
|
|
|
if( NULL == cp ) { \
|
|
|
|
m_eof = true; \
|
|
|
|
m_buf.clear(); \
|
|
|
|
} else { \
|
|
|
|
m_buf = cp; \
|
|
|
|
m_bufpos = 0; \
|
|
|
|
} \
|
|
|
|
m_fileline = m_file->LineNumber(); \
|
|
|
|
} catch( ... ) { \
|
|
|
|
m_error = " * [INFO] input line too long"; \
|
|
|
|
m_eof = true; \
|
|
|
|
m_buf.clear(); \
|
|
|
|
} } while( 0 )
|
|
|
|
|
|
|
|
|
|
|
|
WRLPROC::WRLPROC( LINE_READER* aLineReader )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
m_fileVersion = VRML_INVALID;
|
2016-01-11 23:12:50 +00:00
|
|
|
m_eof = false;
|
|
|
|
m_fileline = 0;
|
|
|
|
m_bufpos = 0;
|
2016-04-07 01:41:52 +00:00
|
|
|
m_file = aLineReader;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( NULL == aLineReader )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
m_eof = true;
|
|
|
|
return;
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_error.clear();
|
2016-04-03 00:56:41 +00:00
|
|
|
wxString tname = m_file->GetSource();
|
|
|
|
m_filename = tname.ToUTF8();
|
|
|
|
wxFileName fn( tname );
|
|
|
|
|
|
|
|
if( fn.IsRelative() )
|
|
|
|
fn.Normalize();
|
|
|
|
|
|
|
|
m_filedir = fn.GetPathWithSep().ToUTF8();
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
m_buf.clear();
|
|
|
|
GETLINE;
|
2016-01-11 23:12:50 +00:00
|
|
|
|
|
|
|
if( m_eof )
|
|
|
|
return;
|
|
|
|
|
2016-04-05 10:32:22 +00:00
|
|
|
if( m_buf.compare( 0, 16, "#VRML V1.0 ascii" ) == 0 )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
m_fileVersion = VRML_V1;
|
|
|
|
// nothing < 0x20, and no:
|
|
|
|
// single or double quote
|
|
|
|
// backslash
|
|
|
|
// curly brace
|
|
|
|
// plus
|
|
|
|
// period
|
|
|
|
m_badchars = "\"'\\{}+.";
|
2016-01-11 23:12:50 +00:00
|
|
|
return;
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-04-05 10:32:22 +00:00
|
|
|
if( m_buf.compare( 0, 15, "#VRML V2.0 utf8" ) == 0 )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
m_fileVersion = VRML_V2;
|
|
|
|
// nothing < 0x20, and no:
|
|
|
|
// single or double quotes
|
|
|
|
// sharp (#)
|
|
|
|
// plus
|
|
|
|
// minus
|
|
|
|
// comma
|
|
|
|
// period
|
|
|
|
// square brackets []
|
|
|
|
// curly braces {}
|
|
|
|
// backslash
|
2016-01-06 05:51:29 +00:00
|
|
|
// NOTE: badchars should include '-' but due to my bad model naming scheme
|
2016-01-02 22:18:16 +00:00
|
|
|
// in the VRML model generator, I have allowed '-'. Other VRML parsers seem to
|
2016-01-04 07:10:15 +00:00
|
|
|
// accept '-'. FreeCAD produces names with '+' in them so '+' has been allowed
|
|
|
|
// as well; '+' is not even valid for VRML1.
|
2016-01-02 22:18:16 +00:00
|
|
|
//m_badchars = "'\"#,.+-[]\\{}";
|
2016-01-04 07:10:15 +00:00
|
|
|
m_badchars = "'\"#,.[]\\{}";
|
2016-01-11 23:12:50 +00:00
|
|
|
return;
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_buf.clear();
|
|
|
|
m_fileVersion = VRML_INVALID;
|
2016-01-11 23:12:50 +00:00
|
|
|
m_eof = true;
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = "not a valid VRML file: '";
|
2016-01-11 23:12:50 +00:00
|
|
|
m_error.append( m_filename );
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error.append( 1, '\'' );
|
|
|
|
m_badchars.clear();
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
return;
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
WRLPROC::~WRLPROC()
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::getRawLine( void )
|
|
|
|
{
|
|
|
|
m_error.clear();
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_bufpos >= m_buf.size() )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
|
|
|
|
if( !m_buf.empty() )
|
|
|
|
return true;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_eof )
|
2015-12-22 08:02:18 +00:00
|
|
|
return false;
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
GETLINE;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_eof && m_buf.empty() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
// strip the EOL characters
|
|
|
|
while( !m_buf.empty() && ( *m_buf.rbegin() == '\r' || *m_buf.rbegin() == '\n' ) )
|
|
|
|
m_buf.erase( --m_buf.end() );
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
if( VRML_V1 == m_fileVersion && !m_buf.empty() )
|
|
|
|
{
|
|
|
|
std::string::iterator sS = m_buf.begin();
|
|
|
|
std::string::iterator eS = m_buf.end();
|
|
|
|
|
|
|
|
while( sS != eS )
|
|
|
|
{
|
2016-04-07 01:41:52 +00:00
|
|
|
if( ((*sS) & 0x80) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
m_error = " non-ASCII character sequence in VRML1 file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
++sS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
bool WRLPROC::EatSpace( void )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_bufpos >= m_buf.size() )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
|
|
|
|
RETRY:
|
2016-01-11 23:12:50 +00:00
|
|
|
while( m_buf.empty() && !m_eof )
|
2015-12-20 07:59:26 +00:00
|
|
|
getRawLine();
|
|
|
|
|
|
|
|
// buffer may be empty if we have reached EOF or encountered IO errors
|
|
|
|
if( m_buf.empty() )
|
|
|
|
return false;
|
|
|
|
|
2016-01-08 05:51:39 +00:00
|
|
|
// eliminate leading white space (including control characters and comments)
|
2016-01-11 23:12:50 +00:00
|
|
|
while( m_bufpos < m_buf.size() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_buf[m_bufpos] > 0x20 )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_bufpos == m_buf.size() || '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
// lines consisting entirely of white space are not unusual
|
|
|
|
m_buf.clear();
|
|
|
|
goto RETRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WRLVERSION WRLPROC::GetVRMLType( void )
|
|
|
|
{
|
|
|
|
return m_fileVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
const char* WRLPROC::GetParentDir( void )
|
|
|
|
{
|
|
|
|
if( m_filedir.empty() )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return m_filedir.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadGlob( std::string& aGlob )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
aGlob.clear();
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ssize = m_buf.size();
|
|
|
|
|
2016-04-05 10:32:22 +00:00
|
|
|
while( m_bufpos < ssize && m_buf[m_bufpos] > 0x20 )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
// the comma is a special instance of blank space
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '{' == m_buf[m_bufpos] || '}' == m_buf[m_bufpos]
|
|
|
|
|| '[' == m_buf[m_bufpos] || ']' == m_buf[m_bufpos] )
|
2015-12-22 08:02:18 +00:00
|
|
|
return true;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
aGlob.append( 1, m_buf[m_bufpos++] );
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadName( std::string& aName )
|
|
|
|
{
|
|
|
|
aName.clear();
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ssize = m_buf.size();
|
|
|
|
|
2016-04-05 10:32:22 +00:00
|
|
|
while( m_bufpos < ssize && m_buf[m_bufpos] > 0x20 )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '[' == m_buf[m_bufpos] || '{' == m_buf[m_bufpos]
|
2016-05-16 07:32:15 +00:00
|
|
|
|| ']' == m_buf[m_bufpos] || '}' == m_buf[m_bufpos]
|
2016-01-11 23:12:50 +00:00
|
|
|
|| '.' == m_buf[m_bufpos] || '#' == m_buf[m_bufpos]
|
|
|
|
|| ',' == m_buf[m_bufpos] )
|
2015-12-21 21:19:05 +00:00
|
|
|
{
|
|
|
|
if( !aName.empty() )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << " * [INFO] line " << m_fileline << ", column " << m_bufpos;
|
2015-12-21 21:19:05 +00:00
|
|
|
ostr << " -- invalid name";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_badchars.find( m_buf[m_bufpos] ) != std::string::npos )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << " * [INFO] line " << m_fileline << ", column " << m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " -- invalid character in name";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( aName.empty() && m_buf[m_bufpos] >= '0' && m_buf[m_bufpos] <= '9' )
|
2016-01-02 22:18:16 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << " * [INFO] line " << m_fileline << ", column " << m_bufpos;
|
2016-01-02 22:18:16 +00:00
|
|
|
ostr << " -- name must not start with a digit";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
aName.append( 1, m_buf[m_bufpos++] );
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::DiscardNode( void )
|
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '{' != m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << " * [INFO] expecting character '{' at line " << m_fileline;
|
|
|
|
ostr << ", column " << m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = ostr.str();
|
|
|
|
|
2016-02-23 00:20:34 +00:00
|
|
|
wxLogTrace( MASK_VRML, "%s\n", m_error.c_str() );
|
2016-01-12 07:03:17 +00:00
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
size_t lvl = 1;
|
|
|
|
std::string tmp;
|
|
|
|
|
|
|
|
while( lvl > 0 )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// comments must be skipped
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
m_bufpos = 0;
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '{' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
++lvl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '}' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
--lvl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// note: if we have a ']' we must skip it and test the next non-blank character;
|
|
|
|
// this ensures that we don't miss a '}' in cases where the braces are not
|
|
|
|
// separated by space. if we had proceeded to ReadGlob() we could have had a problem.
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] || '[' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// strings are handled as a special case since they may contain
|
|
|
|
// control characters and braces
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '"' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
if( !ReadString( tmp ) )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything at this point can be read and discarded via ReadGlob()
|
|
|
|
if( !ReadGlob( tmp ) )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::DiscardList( void )
|
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '[' != m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << " * [INFO] expecting character '[' at line " << m_fileline;
|
|
|
|
ostr << ", column " << m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
size_t lvl = 1;
|
|
|
|
std::string tmp;
|
|
|
|
|
|
|
|
while( lvl > 0 )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// comments must be skipped
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
m_bufpos = 0;
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '[' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
++lvl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
--lvl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// note: if we have a '}' we must skip it and test the next non-blank character;
|
|
|
|
// this ensures that we don't miss a ']' in cases where the braces are not
|
|
|
|
// separated by space. if we had proceeded to ReadGlob() we could have had a problem.
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '}' == m_buf[m_bufpos] || '{' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// strings are handled as a special case since they may contain
|
|
|
|
// control characters and braces
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '"' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
if( !ReadString( tmp ) )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything at this point can be read and discarded via ReadGlob()
|
|
|
|
if( !ReadGlob( tmp ) )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadString( std::string& aSFString )
|
|
|
|
{
|
|
|
|
// In VRML1 a string may be unquoted provided there are no space characters
|
|
|
|
// In VRML2 all strings must be quoted
|
|
|
|
aSFString.clear();
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
// remember the line number in case of errors
|
|
|
|
size_t ifline = m_fileline;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "invalid VRML file; expecting string at line " << ifline << " but found nothing";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( VRML_V2 == m_fileVersion && '"' != m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
m_error = "invalid VRML2 file (string not quoted)";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifline = m_fileline;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '"' != m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
if( !ReadGlob( aSFString ) )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "invalid VRML1 file at lines " << ifline << "--" << m_fileline;
|
|
|
|
|
|
|
|
if( !m_error.empty() )
|
|
|
|
ostr << " : " << m_error;
|
|
|
|
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isesc = false; // true if an escape character was found
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_bufpos >= m_buf.size() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
aSFString.append( 1, '\n' );
|
|
|
|
|
|
|
|
if( !getRawLine() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "invalid VRML1 file at lines " << ifline << "--" << m_fileline;
|
|
|
|
ostr << "; could not find end of string\n";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '\\' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
if( isesc )
|
|
|
|
{
|
|
|
|
aSFString.append( 1, '\n' );
|
|
|
|
isesc = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isesc = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-22 08:59:07 +00:00
|
|
|
else if( '"' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
if( isesc )
|
|
|
|
aSFString.append( 1, '"' );
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2016-02-22 08:59:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
aSFString.append( 1, m_buf[m_bufpos] );
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
// ensure that the backslash escape cannot extend beyond the first character
|
|
|
|
isesc = false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadSFBool( bool& aSFBool )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
std::string tmp;
|
|
|
|
|
|
|
|
if( !ReadGlob( tmp ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !tmp.compare( "0" ) )
|
|
|
|
aSFBool = false;
|
|
|
|
else if( !tmp.compare( "1" ) )
|
|
|
|
aSFBool = true;
|
|
|
|
else if( !tmp.compare( "TRUE" ) )
|
|
|
|
aSFBool = true;
|
|
|
|
else if( !tmp.compare( "FALSE" ) )
|
|
|
|
aSFBool = false;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] expected one of 0, 1, TRUE, FALSE but got '" << tmp << "'\n";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
bool WRLPROC::ReadSFColor( WRLVEC3F& aSFColor )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFVec3f( aSFColor ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aSFColor.x < 0.0 || aSFColor.x > 1.0 || aSFColor.y < 0.0 || aSFColor.y > 1.0
|
|
|
|
|| aSFColor.z < 0.0 || aSFColor.z > 1.0 )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] invalid RGB value in color triplet";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
bool WRLPROC::ReadSFFloat( float& aSFFloat )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aSFFloat = 0.0;
|
|
|
|
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadGlob( tmp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( tmp );
|
|
|
|
|
|
|
|
istr >> aSFFloat;
|
|
|
|
tmp.clear();
|
|
|
|
istr >> tmp;
|
|
|
|
|
|
|
|
if( !tmp.empty() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] invalid character in SFFloat";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
bool WRLPROC::ReadSFInt( int& aSFInt32 )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aSFInt32 = 0;
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadGlob( tmp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline<< ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 12:37:04 +00:00
|
|
|
if( std::string::npos != tmp.find( "0x" ) )
|
|
|
|
{
|
2015-12-30 22:28:39 +00:00
|
|
|
// Rules: "0x" + "0-9, A-F" - VRML is case sensitive but in
|
|
|
|
// this instance we do no enforce case.
|
|
|
|
std::stringstream sstr;
|
|
|
|
sstr << std::hex << tmp;
|
|
|
|
sstr >> aSFInt32;
|
|
|
|
return true;
|
2015-12-20 12:37:04 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( tmp );
|
|
|
|
|
|
|
|
istr >> aSFInt32;
|
|
|
|
tmp.clear();
|
|
|
|
istr >> tmp;
|
|
|
|
|
|
|
|
if( !tmp.empty() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] invalid character in SFInt";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
bool WRLPROC::ReadSFRotation( WRLROTATION& aSFRotation )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aSFRotation.x = 0.0;
|
|
|
|
aSFRotation.y = 0.0;
|
|
|
|
aSFRotation.z = 1.0;
|
|
|
|
aSFRotation.w = 0.0;
|
|
|
|
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
float trot[4];
|
|
|
|
|
|
|
|
for( int i = 0; i < 4; ++i )
|
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadGlob( tmp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( tmp );
|
|
|
|
|
|
|
|
istr >> trot[i];
|
|
|
|
tmp.clear();
|
|
|
|
istr >> tmp;
|
|
|
|
|
|
|
|
if( !tmp.empty() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] invalid character in space delimited quartet";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
aSFRotation.x = trot[0];
|
|
|
|
aSFRotation.y = trot[1];
|
|
|
|
aSFRotation.z = trot[2];
|
|
|
|
aSFRotation.w = trot[3];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
bool WRLPROC::ReadSFVec2f( WRLVEC2F& aSFVec2f )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aSFVec2f.x = 0.0;
|
|
|
|
aSFVec2f.y = 0.0;
|
|
|
|
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
|
|
|
|
float tcol[2];
|
|
|
|
|
|
|
|
for( int i = 0; i < 2; ++i )
|
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadGlob( tmp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( tmp );
|
|
|
|
|
|
|
|
istr >> tcol[i];
|
|
|
|
tmp.clear();
|
|
|
|
istr >> tmp;
|
|
|
|
|
|
|
|
if( !tmp.empty() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] invalid character in space delimited pair";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
aSFVec2f.x = tcol[0];
|
|
|
|
aSFVec2f.y = tcol[1];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
bool WRLPROC::ReadSFVec3f( WRLVEC3F& aSFVec3f )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aSFVec3f.x = 0.0;
|
|
|
|
aSFVec3f.y = 0.0;
|
|
|
|
aSFVec3f.z = 0.0;
|
|
|
|
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
|
|
|
|
float tcol[3];
|
|
|
|
|
|
|
|
for( int i = 0; i < 3; ++i )
|
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadGlob( tmp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-07 04:43:32 +00:00
|
|
|
// ignore any commas
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !EatSpace() )
|
|
|
|
return false;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( tmp );
|
|
|
|
|
|
|
|
istr >> tcol[i];
|
|
|
|
tmp.clear();
|
|
|
|
istr >> tmp;
|
|
|
|
|
|
|
|
if( !tmp.empty() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] invalid character in space delimited triplet";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
aSFVec3f.x = tcol[0];
|
|
|
|
aSFVec3f.y = tcol[1];
|
|
|
|
aSFVec3f.z = tcol[2];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadMFString( std::vector< std::string >& aMFString )
|
|
|
|
{
|
|
|
|
aMFString.clear();
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
|
|
|
|
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string lstr;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_buf[m_bufpos] != '[' )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
if( !ReadString( lstr ) )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_bufpos >= m_buf.size() && !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
2016-04-03 00:56:41 +00:00
|
|
|
Pop();
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
aMFString.push_back( lstr );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
if( !ReadString( lstr ) )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
2016-04-03 00:56:41 +00:00
|
|
|
Pop();
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
aMFString.push_back( lstr );
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] problems encountered while reading list";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadMFColor( std::vector< WRLVEC3F >& aMFColor )
|
|
|
|
{
|
|
|
|
aMFColor.clear();
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
|
|
|
|
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
WRLVEC3F lcolor;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_buf[m_bufpos] != '[' )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFColor( lcolor ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2016-04-03 00:56:41 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aMFColor.push_back( lcolor );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFColor( lcolor ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMFColor.push_back( lcolor );
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadMFFloat( std::vector< float >& aMFFloat )
|
|
|
|
{
|
|
|
|
aMFFloat.clear();
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
|
|
|
|
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
float temp;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_buf[m_bufpos] != '[' )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFFloat( temp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2016-04-03 00:56:41 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aMFFloat.push_back( temp );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFFloat( temp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMFFloat.push_back( temp );
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadMFInt( std::vector< int >& aMFInt32 )
|
|
|
|
{
|
|
|
|
aMFInt32.clear();
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
|
|
|
|
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
int temp;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_buf[m_bufpos] != '[' )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFInt( temp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2016-04-03 00:56:41 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aMFInt32.push_back( temp );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFInt( temp ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMFInt32.push_back( temp );
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadMFRotation( std::vector< WRLROTATION >& aMFRotation )
|
|
|
|
{
|
|
|
|
aMFRotation.clear();
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
|
|
|
|
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
WRLROTATION lrot;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_buf[m_bufpos] != '[' )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFRotation( lrot ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2016-04-03 00:56:41 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aMFRotation.push_back( lrot );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFRotation( lrot ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMFRotation.push_back( lrot );
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadMFVec2f( std::vector< WRLVEC2F >& aMFVec2f )
|
|
|
|
{
|
|
|
|
aMFVec2f.clear();
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
|
|
|
|
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
WRLVEC2F lvec2f;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_buf[m_bufpos] != '[' )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFVec2f( lvec2f ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2016-04-03 00:56:41 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aMFVec2f.push_back( lvec2f );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFVec2f( lvec2f ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMFVec2f.push_back( lvec2f );
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::ReadMFVec3f( std::vector< WRLVEC3F >& aMFVec3f )
|
|
|
|
{
|
|
|
|
aMFVec3f.clear();
|
|
|
|
size_t fileline = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
size_t linepos = m_bufpos;
|
|
|
|
|
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
WRLVEC3F lvec3f;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if the text is the start of a comment block, clear the buffer and loop
|
2016-01-11 23:12:50 +00:00
|
|
|
if( '#' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
m_buf.clear();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_buf[m_bufpos] != '[' )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFVec3f( lvec3f ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2016-04-03 00:56:41 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
2015-12-20 07:59:26 +00:00
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
aMFVec3f.push_back( lvec3f );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !ReadSFVec3f( lvec3f ) )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] " << m_error;
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMFVec3f.push_back( lvec3f );
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
if( !EatSpace() )
|
2015-12-20 07:59:26 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed on file '" << m_filename << "'\n";
|
|
|
|
ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
|
2016-01-11 23:12:50 +00:00
|
|
|
ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
|
2015-12-20 07:59:26 +00:00
|
|
|
ostr << " * [INFO] could not check characters after the string";
|
|
|
|
m_error = ostr.str();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( !EatSpace() )
|
|
|
|
return false;
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
if( ']' == m_buf[m_bufpos] )
|
2015-12-20 07:59:26 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-03 00:56:41 +00:00
|
|
|
if( ',' == m_buf[m_bufpos] )
|
|
|
|
Pop();
|
|
|
|
|
2015-12-20 07:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
++m_bufpos;
|
2015-12-20 07:59:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-22 00:08:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::eof( void )
|
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
return m_eof;
|
2015-12-22 00:08:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string WRLPROC::GetError( void )
|
|
|
|
{
|
|
|
|
return m_error;
|
|
|
|
}
|
2015-12-22 06:02:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool WRLPROC::GetFilePosData( size_t& line, size_t& column )
|
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
2015-12-22 06:02:33 +00:00
|
|
|
{
|
|
|
|
line = 0;
|
|
|
|
column = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = m_fileline;
|
2016-01-11 23:12:50 +00:00
|
|
|
column = m_bufpos;
|
2015-12-22 06:02:33 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-30 22:28:39 +00:00
|
|
|
std::string WRLPROC::GetFileName( void )
|
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
|
|
|
{
|
|
|
|
m_error = "no open file";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::string( m_file->GetSource().ToUTF8() );
|
2015-12-30 22:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-22 06:02:33 +00:00
|
|
|
char WRLPROC::Peek( void )
|
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( !m_file )
|
2015-12-22 06:02:33 +00:00
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] no open file";
|
|
|
|
m_error = ostr.str();
|
|
|
|
return '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !EatSpace() )
|
|
|
|
{
|
|
|
|
if( m_error.empty() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] failed to read data from file\n";
|
|
|
|
m_error = ostr.str();
|
|
|
|
}
|
|
|
|
|
2016-01-01 05:05:14 +00:00
|
|
|
return '\0';
|
2015-12-22 06:02:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:12:50 +00:00
|
|
|
return m_buf[m_bufpos];
|
2015-12-22 06:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WRLPROC::Pop( void )
|
|
|
|
{
|
2016-01-11 23:12:50 +00:00
|
|
|
if( m_bufpos < m_buf.size() )
|
|
|
|
++m_bufpos;
|
2015-12-22 06:02:33 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|