7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-19 09:41:41 +00:00

3D plugin debugging output fixes.

This commit is contained in:
Wayne Stambaugh 2021-07-24 13:27:35 -04:00
parent 1aadf45947
commit 728b160719
77 changed files with 2216 additions and 5157 deletions

View File

@ -47,8 +47,12 @@
// number 0 is special (the PCB board color)
#define NCOLORS 6
// log mask for wxLogTrace
#define MASK_IDF "PLUGIN_IDF"
/**
* Flag to enable IDF plugin trace output.
*
* @ingroup trace_env_vars
*/
const wxChar* const traceIdfPlugin = wxT( "KICAD_IDF_PLUGIN" );
// read and instantiate an IDF component outline
@ -357,28 +361,16 @@ static bool getOutlineModel( VRML_LAYER& model, const std::list< IDF_OUTLINE* >*
if( nvcont < 0 )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] cannot create an outline";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n * [INFO] cannot create an outline",
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
if( (*scont)->size() < 1 )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid contour: no vertices";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n * [INFO] invalid contour: no vertices",
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -394,14 +386,8 @@ static bool getOutlineModel( VRML_LAYER& model, const std::list< IDF_OUTLINE* >*
if( !addSegment( model, &lseg, nvcont, iseg ) )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] cannot add segment";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n * [BUG] cannot add segment",
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -428,14 +414,8 @@ static bool addSegment( VRML_LAYER& model, IDF_SEGMENT* seg, int icont, int iseg
{
if( iseg != 0 )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] adding a circle to an existing vertex list";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n * [INFO] adding a circle to an "
"existing vertex list", __FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -473,28 +453,16 @@ static SCENEGRAPH* vrmlToSG( VRML_LAYER& vpcb, int idxColor, SGNODE* aParent, do
if( !vpcb.Get3DTriangles( vertices, idxPlane, idxSide, top, bottom ) )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] no vertex data";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n * [INFO] no vertex data",
__FILE__, __FUNCTION__, __LINE__ );
return nullptr;
}
if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n * [BUG] index lists are not a multiple of 3 "
"(not a triangle list)", __FILE__, __FUNCTION__, __LINE__ );
return nullptr;
}
@ -603,14 +571,8 @@ static SCENEGRAPH* addOutline( IDF3_COMP_OUTLINE* outline, int idxColor, SGNODE*
if( !getOutlineModel( vpcb, outline->GetOutlines() ) )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] no valid outline data";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n * [INFO] no valid outline data",
__FILE__, __FUNCTION__, __LINE__ );
return nullptr;
}
@ -643,17 +605,9 @@ static SCENEGRAPH* loadIDFOutline( const wxString& aFileName )
if( nullptr == outline )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] Failed to read IDF data:\n";
ostr << brd.GetError() << "\n\n";
ostr << " * [INFO] no outline for file '";
ostr << aFileName << "'";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n * [INFO] Failed to read IDF data:\n%s\n"
" * [INFO] no outline for file '%s'", __FILE__, __FUNCTION__, __LINE__,
brd.GetError(), aFileName );
return nullptr;
}
@ -672,16 +626,9 @@ static SCENEGRAPH* loadIDFBoard( const wxString& aFileName )
// note: if the IDF model is defective no outline substitutes shall be made
if( !brd.ReadFile( aFileName, true ) )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] Failed to read IDF file:\n";
ostr << brd.GetError() << "\n\n";
ostr << " * [INFO] IDF file '" << aFileName.ToUTF8() << "'";
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceIdfPlugin, "%s:%s:%s\n"
"* [INFO] Error '%s' occurred reading IDF file: %s",
__FILE__, __FUNCTION__, __LINE__, brd.GetError(), aFileName );
return nullptr;
}

View File

@ -49,7 +49,7 @@ WRL1BASE::WRL1BASE() : WRL1NODE( nullptr )
WRL1BASE::~WRL1BASE()
{
wxLogTrace( MASK_VRML, " * [INFO] Destroying virtual base node" );
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying virtual base node." ) );
cancelDict();
}
@ -57,64 +57,27 @@ WRL1BASE::~WRL1BASE()
bool WRL1BASE::SetParent( WRL1NODE* aParent, bool /* doUnlink */ )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] attempting to set parent on WRL1BASE node";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "Attempt to set parent on WRL1BASE node." ) );
}
std::string WRL1BASE::GetName( void )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] attempting to extract name from virtual base node";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return std::string( "" );
wxCHECK_MSG( false, std::string( "" ),
wxT( "Attempt to extract name from virtual base node." ) );
}
bool WRL1BASE::SetName( const std::string& aName )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] attempting to set name on virtual base node";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "Attempt to set name on virtual base node." ) );
}
bool WRL1BASE::Read( WRLPROC& proc )
{
if( proc.GetVRMLType() != WRLVERSION::VRML_V1 )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] no open file or file is not a VRML1 file";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( proc.GetVRMLType() == WRLVERSION::VRML_V1, false,
wxT( "No open file or file is not a VRML1 file" ) );
// Note: according to the VRML1 specification, a file may contain
// only one grouping node at the top level. The following code
@ -123,20 +86,11 @@ bool WRL1BASE::Read( WRLPROC& proc )
while( proc.Peek() )
{
size_t line, column;
proc.GetFilePosData( line, column );
if( !ReadNode( proc, this, nullptr ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n * [INFO] bad file format; unexpected eof %s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
@ -144,14 +98,8 @@ bool WRL1BASE::Read( WRLPROC& proc )
if( !proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetError() );
return false;
}
@ -165,32 +113,13 @@ bool WRL1BASE::implementUse( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode
if( nullptr != aNode )
*aNode = nullptr;
if( !aParent )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invoked with NULL parent";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( aParent, false, wxT( "Invoked with invalid parent." ) );
std::string glob;
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s" ), proc.GetError() );
return false;
}
@ -200,30 +129,19 @@ bool WRL1BASE::implementUse( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode
// return 'true' - the file may be defective but it may still be somewhat OK
if( nullptr == ref )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] node '" << glob << "' not found";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n * [INFO] node '%s' not found." ),
__FILE__, __FUNCTION__, __LINE__, glob );
return true;
}
if( !aParent->AddRefNode( ref ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] failed to add node '" << glob << "' (";
ostr << ref->GetNodeTypeName( ref->GetNodeType() ) << ") to parent of type ";
ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n * [INFO] failed to add node '%s' (%s) to parent of type %s." ),
__FILE__, __FUNCTION__, __LINE__, glob,
ref->GetNodeTypeName( ref->GetNodeType() ),
aParent->GetNodeTypeName( aParent->GetNodeType() ) );
return false;
}
@ -240,40 +158,19 @@ bool WRL1BASE::implementDef( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode
if( nullptr != aNode )
*aNode = nullptr;
if( nullptr == aParent )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid parent pointer (nullptr)";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( nullptr != aParent, false, wxT( "Invalid parent pointer." ) );
std::string glob;
WRL1NODE* lnode = nullptr;
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetError() );
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
if( ReadNode( proc, aParent, &lnode ) )
{
if( nullptr != aNode )
@ -281,17 +178,9 @@ bool WRL1BASE::implementDef( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode
if( lnode && !lnode->SetName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
size_t line, column;
proc.GetFilePosData( line, column );
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad formatting (invalid name) at line";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n * [INFO] bad formatting (invalid name) %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
@ -319,34 +208,18 @@ bool WRL1BASE::ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
if( nullptr != aNode )
*aNode = nullptr;
if( nullptr == aParent )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] invalid parent pointer (NULL)";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( aParent, false, wxT( "Invalid parent pointer." ) );
std::string glob;
WRL1NODES ntype;
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
if( !proc.eof() )
{
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetError() );
}
#endif
return false;
}
@ -358,18 +231,7 @@ bool WRL1BASE::ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
if( !glob.compare( "USE" ) )
{
if( !implementUse( proc, aParent, aNode ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
return true;
}
@ -377,34 +239,14 @@ bool WRL1BASE::ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
if( !glob.compare( "DEF" ) )
{
if( !implementDef( proc, aParent, aNode ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
return true;
}
ntype = getNodeTypeID( glob );
size_t line = 0;
size_t column = 0;
proc.GetFilePosData( line, column );
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Processing node '" << glob << "' ID: " << ntype;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Processing node '%s' ID: %d." ), glob, ntype );
switch( ntype )
{
@ -479,32 +321,20 @@ bool WRL1BASE::ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
//
default:
proc.GetFilePosData( line, column );
if( !proc.DiscardNode() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] could not discard node at line " << line;
ostr << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n * [INFO] could not discard node %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
else
{
std::ostringstream ostr;
ostr << " * [INFO] discarded node '" << glob << "' at line ";
ostr << line << ", col " << column << " (currently unsupported)";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] discarded node '%s' %s (currently unsupported)." ),
glob, proc.GetFilePosition() );
}
#endif
break;
}
@ -515,18 +345,7 @@ bool WRL1BASE::ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode )
bool WRL1BASE::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
// this function makes no sense in the base node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] this method must never be invoked on a WRL1BASE object";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "This method must never be invoked on a WRL1BASE object" ) );
}
@ -709,20 +528,14 @@ bool WRL1BASE::readShapeHints( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNod
SGNODE* WRL1BASE::TranslateToSG( SGNODE* aParent, WRL1STATUS* /*sp*/ )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Translating VRML1 Base with " << m_Items.size();
ostr << " items";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Translating VRML1 Base with %ul items." ),
m_Items.size() );
if( m_Items.empty() )
return nullptr;
if( m_Items.size() == 1 )
return (*m_Items.begin())->TranslateToSG( nullptr, nullptr );
return ( *m_Items.begin() )->TranslateToSG( nullptr, nullptr );
// Note: according to the VRML1 specification, a file may contain
// only one grouping node at the top level. The following code

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -39,11 +40,27 @@ class SGNODE;
class WRL1INLINE;
/**
* WRL1BASE
* represents the top node of a VRML1 model
* Represent the top node of a VRML1 model.
*/
class WRL1BASE : public WRL1NODE
{
public:
WRL1BASE();
virtual ~WRL1BASE();
// function to read entire VRML file
bool Read( WRLPROC& proc );
// read in a VRML node
bool ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
virtual std::string GetName( void ) override;
virtual bool SetName( const std::string& aName ) override;
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool SetParent( WRL1NODE* aParent, bool doUnlink = true ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
private:
// handle cases of USE / DEF
bool implementUse( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
@ -58,25 +75,6 @@ private:
bool readFaceSet( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
bool readTransform( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
bool readShapeHints( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
public:
WRL1BASE();
virtual ~WRL1BASE();
// function to read entire VRML file
bool Read( WRLPROC& proc );
// read in a VRML node
bool ReadNode( WRLPROC& proc, WRL1NODE* aParent, WRL1NODE** aNode );
// overrides
virtual std::string GetName( void ) override;
virtual bool SetName( const std::string& aName ) override;
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool SetParent( WRL1NODE* aParent, bool doUnlink = true ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
};
#endif // VRML1_BASE_H

View File

@ -50,80 +50,44 @@ WRL1COORDS::WRL1COORDS( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1COORDS::~WRL1COORDS()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
wxLogTrace( MASK_VRML, " * [INFO] Destroying Coordinate3 node\n" );
#endif
wxLogTrace( traceVrmlPlugin, " * [INFO] Destroying Coordinate3 node." );
}
bool WRL1COORDS::AddRefNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddRefNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
}
bool WRL1COORDS::AddChildNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddChildNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
}
bool WRL1COORDS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
size_t line, column;
proc.GetFilePosData( line, column );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column << "\n";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s" ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
return false;
}
@ -139,52 +103,34 @@ bool WRL1COORDS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetError() );
return false;
}
proc.GetFilePosData( line, column );
// expecting 'point'
if( !glob.compare( "point" ) )
{
if( !proc.ReadMFVec3f( points ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid point set at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid point set %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad Coordinate at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"* [INFO] bad Coordinate %s.\n"
"* [INFO] file: '%s'." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
return false;
}
@ -208,18 +154,10 @@ bool WRL1COORDS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
return true;
}
proc.GetFilePosData( line, column );
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad Coordinate at line " << line << ", column ";
ostr << column << " (no closing brace)\n";
ostr << " * [INFO] file: '" << proc.GetFileName();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad Coordinate %s (no closing brace)." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
@ -241,12 +179,7 @@ void WRL1COORDS::GetCoords( WRLVEC3F*& aCoordList, size_t& aListSize )
SGNODE* WRL1COORDS::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
{
if( nullptr == sp )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no base data given\n" );
return nullptr;
}
wxCHECK_MSG( sp, nullptr, wxT( "Inalid base data." ) );
sp->coord = this;

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -36,26 +37,23 @@
class WRL1BASE;
class SGNODE;
/**
* WRL1COORDS
*/
class WRL1COORDS : public WRL1NODE
{
private:
std::vector< WRLVEC3F > points;
public:
WRL1COORDS( NAMEREGISTER* aDictionary );
WRL1COORDS( NAMEREGISTER* aDictionary, WRL1NODE* aParent );
virtual ~WRL1COORDS();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool AddRefNode( WRL1NODE* aNode ) override;
bool AddChildNode( WRL1NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
void GetCoords( WRLVEC3F*& aCoordList, size_t& aListSize );
private:
std::vector< WRLVEC3F > points;
};
#endif // VRML1_COORDS_H

View File

@ -54,86 +54,46 @@ WRL1FACESET::WRL1FACESET( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1FACESET::~WRL1FACESET()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Destroying IndexedFaceSet with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying IndexedFaceSet with %ul children, "
"%ul references, and %ul back pointers." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size() );
}
bool WRL1FACESET::AddRefNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddRefNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
}
bool WRL1FACESET::AddChildNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddChildNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
}
bool WRL1FACESET::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
size_t line, column;
proc.GetFilePosData( line, column );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s." ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
return false;
}
@ -151,14 +111,8 @@ bool WRL1FACESET::Read( WRLPROC& proc, WRL1BASE* aTopNode )
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetError() );
return false;
}
@ -167,23 +121,17 @@ bool WRL1FACESET::Read( WRLPROC& proc, WRL1BASE* aTopNode )
// coordIndex[]
// materialIndex[]
proc.GetFilePosData( line, column );
if( !glob.compare( "coordIndex" ) )
{
if( !proc.ReadMFInt( coordIndex ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid coordIndex at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid coordIndex %s.\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -192,17 +140,13 @@ bool WRL1FACESET::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadMFInt( matIndex ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid materialIndex at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid materialIndex %s.\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -211,17 +155,13 @@ bool WRL1FACESET::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadMFInt( normIndex ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid normalIndex at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid normalIndex %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -230,33 +170,25 @@ bool WRL1FACESET::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadMFInt( texIndex ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid textureCoordIndex at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid textureCoordIndex %s.\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad IndexedFaceSet at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid IndexedFaceSet %s.\n"
" * [INFO] file: '%s'" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName() );
return false;
}
@ -274,7 +206,7 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
// decompose into Rotate,Scale,Transform via an analytic expression.
if( !m_Parent )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no parent node\n" );
wxLogTrace( traceVrmlPlugin, " * [INFO] bad model: no parent node." );
return nullptr;
}
@ -282,7 +214,7 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
{
if( nullptr == sp )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no base data given\n" );
wxLogTrace( traceVrmlPlugin, " * [INFO] bad model: no base data given." );
return nullptr;
}
@ -290,20 +222,15 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
m_current = *sp;
if( nullptr == m_current.coord || nullptr == m_current.mat )
if( nullptr == m_current.coord )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
if( nullptr == m_current.coord )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no vertex set\n" );
}
if( nullptr == m_current.mat )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no material set\n" );
}
#endif
wxLogTrace( traceVrmlPlugin, " * [INFO] bad model: no vertex set." );
return nullptr;
}
if( nullptr == m_current.mat )
{
wxLogTrace( traceVrmlPlugin, " * [INFO] bad model: no material set." );
return nullptr;
}
@ -315,14 +242,9 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
if( coordsize < 3 || vsize < 3 )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << " * [INFO] bad model: coordsize, indexsize = " << coordsize;
ostr << ", " << vsize;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] bad model: coordsize = %ul, indexsize = %ul" ),
coordsize, vsize );
return nullptr;
}
@ -343,7 +265,8 @@ SGNODE* WRL1FACESET::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
if( matIndex.empty() )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: per face indexed but no indices\n" );
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] bad model: per face indexed but no indices" ) );
// support bad models by temporarily switching bindings
mbind = WRL1_BINDING::BIND_OVERALL;

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -36,27 +37,23 @@
class WRL1BASE;
class SGNODE;
/**
* WRL1FACESET
*/
class WRL1FACESET : public WRL1NODE
{
private:
std::vector< int > coordIndex;
std::vector< int > matIndex;
std::vector< int > normIndex;
std::vector< int > texIndex;
public:
WRL1FACESET( NAMEREGISTER* aDictionary );
WRL1FACESET( NAMEREGISTER* aDictionary, WRL1NODE* aParent );
virtual ~WRL1FACESET();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool AddRefNode( WRL1NODE* aNode ) override;
bool AddChildNode( WRL1NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
private:
std::vector< int > coordIndex;
std::vector< int > matIndex;
std::vector< int > normIndex;
std::vector< int > texIndex;
};
#endif // VRML1_FACESET_H

View File

@ -56,15 +56,10 @@ WRL1GROUP::WRL1GROUP( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1GROUP::~WRL1GROUP()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Destroying Group with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Destroying Group with %ul children, %ul references, and %ul "
"back pointers." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size() );
}
@ -72,50 +67,31 @@ bool WRL1GROUP::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( nullptr == aTopNode )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is NULL";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [BUG] aTopNode is NULL" ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s." ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
return false;
}
@ -130,19 +106,12 @@ bool WRL1GROUP::Read( WRLPROC& proc, WRL1BASE* aTopNode )
break;
}
proc.GetFilePosData( line, column );
if( !aTopNode->ReadNode( proc, this, nullptr ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
@ -158,36 +127,20 @@ bool WRL1GROUP::Read( WRLPROC& proc, WRL1BASE* aTopNode )
SGNODE* WRL1GROUP::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Translating Group with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers (total ";
ostr << m_Items.size() << " items)";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxCHECK_MSG( m_Parent, nullptr, wxT( "Group has no parent." ) );
if( !m_Parent )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] Group has no parent";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return nullptr;
}
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Translating Group with %ul children, %ul references, %ul back "
"pointers, and %ul items." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size(), m_Items.size() );
if( WRL1NODES::WRL1_BASE != m_Parent->GetNodeType() )
{
if( nullptr == sp )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no base data given\n" );
/// @todo Determine if this is a bug or can actually happen parsing a VRML file.
/// If it's a bug, this should be an assertion not a trace.
wxLogTrace( traceVrmlPlugin, " * [INFO] bad model: no base data given." );
return nullptr;
}
@ -200,20 +153,10 @@ SGNODE* WRL1GROUP::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
if( nullptr != aParent && ptype != S3D::SGTYPE_TRANSFORM )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] Group does not have a Transform parent (parent ID: ";
ostr << ptype << ")";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return nullptr;
}
wxCHECK_MSG( nullptr == aParent && ptype == S3D::SGTYPE_TRANSFORM, nullptr,
wxString::Format(
wxT(" * [BUG] Group does not have a Transform parent (parent ID: %d" ),
ptype ) );
IFSG_TRANSFORM txNode( aParent );
bool hasContent = false;

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -34,9 +35,6 @@
class WRL1BASE;
class SGNODE;
/**
* WRL1GROUP
*/
class WRL1GROUP : public WRL1NODE
{
public:
@ -44,7 +42,6 @@ public:
WRL1GROUP( NAMEREGISTER* aDictionary, WRL1NODE* aNode );
virtual ~WRL1GROUP();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
};

View File

@ -53,92 +53,46 @@ WRL1MATBINDING::WRL1MATBINDING( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1MATBINDING::~WRL1MATBINDING()
{
wxLogTrace( MASK_VRML, " * [INFO] Destroying MaterialBinding node\n" );
wxLogTrace( traceVrmlPlugin, " * [INFO] Destroying MaterialBinding node\n" );
}
bool WRL1MATBINDING::AddRefNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddRefNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
}
bool WRL1MATBINDING::AddChildNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddChildNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
}
bool WRL1MATBINDING::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( nullptr == aTopNode )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is NULL";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
wxCHECK_MSG( aTopNode, false, wxT( "aTopNode is NULL." ) );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s." ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
return false;
}
@ -156,44 +110,30 @@ bool WRL1MATBINDING::Read( WRLPROC& proc, WRL1BASE* aTopNode )
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetError() );
return false;
}
if( glob.compare( "value" ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad MaterialBinding at line " << line << ", column ";
ostr << column << " (did not find keyword 'value')\n";
ostr << " * [INFO] file: '" << proc.GetFileName();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad MaterialBinding %s (expecting keyword 'value').\n"
" * [INFO] file: '%s'." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName() );
return false;
}
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetError() );
return false;
}
@ -208,8 +148,6 @@ bool WRL1MATBINDING::Read( WRLPROC& proc, WRL1BASE* aTopNode )
// PER_VERTEX
// PER_VERTEX_INDEXED
proc.GetFilePosData( line, column );
if( !glob.compare( "DEFAULT" ) )
{
m_binding = WRL1_BINDING::BIND_DEFAULT;
@ -244,16 +182,11 @@ bool WRL1MATBINDING::Read( WRLPROC& proc, WRL1BASE* aTopNode )
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad MaterialBinding at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad MaterialBinding %s\n"
" * [INFO] file: '%s'" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName() );
m_binding = WRL1_BINDING::BIND_OVERALL;
}
@ -265,12 +198,7 @@ bool WRL1MATBINDING::Read( WRLPROC& proc, WRL1BASE* aTopNode )
SGNODE* WRL1MATBINDING::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
{
if( nullptr == sp )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no base data given" );
return nullptr;
}
wxCHECK_MSG ( sp, nullptr, wxT( "Bad model: no base data given." ) );
sp->matbind = m_binding;

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -35,24 +36,20 @@
class WRL1BASE;
class SGNODE;
/**
* WRL1MATBINDING
*/
class WRL1MATBINDING : public WRL1NODE
{
private:
WRL1_BINDING m_binding;
public:
WRL1MATBINDING( NAMEREGISTER* aDictionary );
WRL1MATBINDING( NAMEREGISTER* aDictionary, WRL1NODE* aParent );
virtual ~WRL1MATBINDING();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool AddRefNode( WRL1NODE* aNode ) override;
bool AddChildNode( WRL1NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
private:
WRL1_BINDING m_binding;
};
#endif // VRML1_MATBINDING_H

View File

@ -55,31 +55,17 @@ WRL1MATERIAL::WRL1MATERIAL( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1MATERIAL::~WRL1MATERIAL()
{
wxLogTrace( MASK_VRML, " * [INFO] Destroying Material node" );
wxLogTrace( traceVrmlPlugin, " * [INFO] Destroying Material node." );
// destroy any orphaned color nodes
for( int i = 0; i < 2; ++i )
{
if( nullptr != colors[i] )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Destroying SGCOLOR #" << i;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
if( nullptr == S3D::GetSGNodeParent( colors[i] ) )
S3D::DestroyNode( colors[i] );
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] destroyed SGCOLOR #" << i;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] destroyed SGCOLOR #%d" ), i );
}
}
}
@ -88,85 +74,38 @@ WRL1MATERIAL::~WRL1MATERIAL()
bool WRL1MATERIAL::AddRefNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddRefNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
}
bool WRL1MATERIAL::AddChildNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddChildNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
}
bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( nullptr == aTopNode )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is nullptr";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
wxCHECK_MSG( aTopNode, false, wxT( "aTopNode is nullptr." ) );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s" ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
return false;
}
@ -184,14 +123,9 @@ bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetError() );
return false;
}
@ -204,23 +138,17 @@ bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
// specularColor
// transparency
proc.GetFilePosData( line, column );
if( !glob.compare( "specularColor" ) )
{
if( !proc.ReadMFVec3f( specularColor ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid specularColor at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid specularColor %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -229,17 +157,12 @@ bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadMFVec3f( diffuseColor ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid diffuseColor at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] invalid diffuseColor %s\n"
" * [INFO] file: '%s'\n"
" * [INFO] error: '%s'." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -248,17 +171,12 @@ bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadMFVec3f( emissiveColor ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid emissiveColor at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] invalid emissiveColor %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -267,17 +185,12 @@ bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadMFFloat( shininess ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid shininess at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid shininess at line %ul column %ul\n"
" * [INFO] file: '%s'\n"
" * [INFO] error: '%s'." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFileName(), proc.GetError() );
return false;
}
@ -286,17 +199,12 @@ bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadMFFloat( transparency ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid transparency at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid transparency at line %ul column %ul\n"
" * [INFO] file: '%s'\n"
" * [INFO] error: '%s'." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFileName(), proc.GetError() );
return false;
}
@ -305,33 +213,23 @@ bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadMFVec3f( ambientColor ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid ambientColor at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid ambientColor at line %ul column %ul\n"
" * [INFO] file: '%s'\n"
" * [INFO] error: '%s'." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFileName(), proc.GetError() );
return false;
}
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad Material at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"* [INFO] bad Material %s.\n"
"* [INFO] file: '%s'." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName() );
return false;
}
@ -343,12 +241,7 @@ bool WRL1MATERIAL::Read( WRLPROC& proc, WRL1BASE* aTopNode )
SGNODE* WRL1MATERIAL::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
{
if( nullptr == sp )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no base data given" );
return nullptr;
}
wxCHECK_MSG( sp, nullptr, wxT( "Bad model: no base data given." ) );
sp->mat = this;

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -37,12 +38,36 @@ class WRL1BASE;
class SGNODE;
class SGCOLOR;
/**
* WRL1MATERIAL
*/
class WRL1MATERIAL : public WRL1NODE
{
public:
WRL1MATERIAL( NAMEREGISTER* aDictionary );
WRL1MATERIAL( NAMEREGISTER* aDictionary, WRL1NODE* aParent );
virtual ~WRL1MATERIAL();
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool AddRefNode( WRL1NODE* aNode ) override;
bool AddChildNode( WRL1NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
/**
* Return an SGAPPEARANCE node representing the appearance for an IndexedFaceSet.
*/
SGNODE* GetAppearance( int aIndex );
/**
* Compute an SGCOLOR representing the appearance of a vertex or face.
*/
void GetColor( SGCOLOR* aColor, int aIndex );
/**
* Destroy the given color node if it does not have a parent.
*/
void Reclaim( SGNODE* aColor );
private:
void checkRange( float& aValue );
std::vector< WRLVEC3F > diffuseColor;
std::vector< WRLVEC3F > emissiveColor;
std::vector< WRLVEC3F > specularColor;
@ -51,38 +76,6 @@ private:
std::vector< float > transparency;
SGNODE* colors[2];
void checkRange( float& aValue );
public:
WRL1MATERIAL( NAMEREGISTER* aDictionary );
WRL1MATERIAL( NAMEREGISTER* aDictionary, WRL1NODE* aParent );
virtual ~WRL1MATERIAL();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool AddRefNode( WRL1NODE* aNode ) override;
bool AddChildNode( WRL1NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
/**
* Function GetAppearance
* returns an SGAPPEARANCE node representing the appearance
* for an IndexedFaceSet
*/
SGNODE* GetAppearance( int aIndex );
/**
* Function GetColor
* computes an SGCOLOR representing the appearance of a vertex or face
*/
void GetColor( SGCOLOR* aColor, int aIndex );
/**
* Function Reclaim
* will destroy the given color node if it does not have a parent
*/
void Reclaim( SGNODE* aColor );
};
#endif // VRML1_MATERIAL_H

View File

@ -88,11 +88,6 @@ typedef std::map< std::string, WRL1NODES > NODEMAP;
static NODEMAP nodenames;
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::string WRL1NODE::tabs = "";
#endif
WRL1NODE::WRL1NODE( NAMEREGISTER* aDictionary )
{
m_sgNode = nullptr;
@ -143,15 +138,10 @@ WRL1NODE::WRL1NODE( NAMEREGISTER* aDictionary )
WRL1NODE::~WRL1NODE()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] ^^ Destroying Type " << m_Type << " with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] ^^ Destroying Type %d with %ul children, %ul references, and %ul "
"back pointers." ),
m_Type, m_Children.size(), m_Refs.size(), m_BackPointers.size() );
m_Items.clear();
@ -164,30 +154,18 @@ WRL1NODE::~WRL1NODE()
std::list< WRL1NODE* >::iterator sBP = m_BackPointers.begin();
std::list< WRL1NODE* >::iterator eBP = m_BackPointers.end();
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
int acc = 0;
#endif
while( sBP != eBP )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
++acc;
do {
std::ostringstream ostr;
ostr << " * [INFO] " << tabs << "Type " << m_Type << " is Unlinking ref #";
ostr << acc;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO]%sType %d is unlinking ref #%d" ),
wxString( ' ', (size_t) std::distance( sBP, m_BackPointers.begin() ) * 2 ),
m_Type, std::distance( sBP, m_BackPointers.begin() ) );
(*sBP)->unlinkRefNode( this );
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] " << tabs << "Type " << m_Type << " has unlinked ref #";
ostr << acc;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO]%sType %d has unlinked ref #%d" ),
wxString( ' ', (size_t) std::distance( sBP, m_BackPointers.begin() ) * 2 ),
m_Type, std::distance( sBP, m_BackPointers.begin() ) );
++sBP;
}
@ -196,53 +174,23 @@ WRL1NODE::~WRL1NODE()
std::list< WRL1NODE* >::iterator sC = m_Children.begin();
std::list< WRL1NODE* >::iterator eC = m_Children.end();
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
std::string otabs = tabs;
tabs.append( " " );
#endif
while( sC != eC )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
++acc;
do {
std::ostringstream ostr;
ostr << " * [INFO] " << otabs << "Type " << m_Type << " is Deleting child #";
ostr << acc;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
(*sC)->SetParent( nullptr, false );
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] " << otabs << "Type " << m_Type << " has unlinked child #";
ostr << acc;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO]%sType %d has unlinked child #%d" ),
wxString( ' ', (size_t) std::distance( sC, m_Children.begin() ) * 2 ),
m_Type, std::distance( sC, m_Children.begin() ) );
delete *sC;
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] " << otabs << "Type " << m_Type << " has deleted child #";
ostr << acc;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( " * [INFO]%sType %d has deleted child #%d" ),
wxString( ' ', (size_t) std::distance( sC, m_Children.begin() ) * 2 ),
m_Type, std::distance( sC, m_Children.begin() ) );
++sC;
}
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
tabs = otabs;
#endif
m_Children.clear();
}
@ -288,8 +236,8 @@ void WRL1NODE::addNodeRef( WRL1NODE* aNode )
void WRL1NODE::delNodeRef( WRL1NODE* aNode )
{
std::list< WRL1NODE* >::iterator np =
std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
std::list< WRL1NODE* >::iterator np = std::find( m_BackPointers.begin(),
m_BackPointers.end(), aNode );
if( np != m_BackPointers.end() )
{
@ -297,14 +245,9 @@ void WRL1NODE::delNodeRef( WRL1NODE* aNode )
return;
}
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] delNodeRef() did not find its target";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [BUG] delNodeRef() did not find its target." ),
__FILE__, __FUNCTION__, __LINE__ );
}
@ -333,14 +276,9 @@ bool WRL1NODE::SetName( const std::string& aName )
if( isdigit( aName[0] ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid node name '" << aName << "' (begins with digit)";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] invalid node name '%s' (begins with digit)" ),
__FILE__, __FUNCTION__, __LINE__, aName );
return false;
}
@ -354,15 +292,10 @@ bool WRL1NODE::SetName( const std::string& aName )
if( std::string::npos != aName.find_first_of( BAD_CHARS1 )
|| std::string::npos != aName.find_first_of( BAD_CHARS2 ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid node name '" << aName;
ostr << "' (contains invalid character)";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid node name '%s' (contains invalid character)" ),
__FILE__, __FUNCTION__, __LINE__, aName );
return false;
}
@ -442,19 +375,9 @@ bool WRL1NODE::SetParent( WRL1NODE* aParent, bool doUnlink )
bool WRL1NODE::AddChildNode( WRL1NODE* aNode )
{
if( aNode->GetNodeType() == WRL1NODES::WRL1_BASE )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] attempting to add a base node to another node";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( aNode, false, wxT( "Invalid node pointer." ) );
wxCHECK_MSG( aNode->GetNodeType() != WRL1NODES::WRL1_BASE, false,
wxT( "Attempting to add a base node to another node." ) );
std::list< WRL1NODE* >::iterator sC = m_Children.begin();
std::list< WRL1NODE* >::iterator eC = m_Children.end();
@ -479,33 +402,9 @@ bool WRL1NODE::AddChildNode( WRL1NODE* aNode )
bool WRL1NODE::AddRefNode( WRL1NODE* aNode )
{
if( nullptr == aNode )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL passed as node pointer";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
if( aNode->GetNodeType() == WRL1NODES::WRL1_BASE )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] attempting to add a base node ref to another base node";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( aNode, false, wxT( "Invalid node pointer." ) );
wxCHECK_MSG( aNode->GetNodeType() != WRL1NODES::WRL1_BASE, false,
wxT( "Attempt to add a base node reference to another base node" ) );
// note: the VRML1 spec does not prevent the reuse of a node at
// the same level; for example a Coordinate3 node can be recalled

View File

@ -24,7 +24,7 @@
/**
* @file vrmlv1_node.h
* defines the base class for VRML1.0 nodes
* Define the base class for VRML1.0 nodes.
*/
@ -43,16 +43,16 @@
class WRL1NODE;
// a class to hold the dictionary of node DEFs
// The dictionary of node DEFs
class NAMEREGISTER
{
private:
std::map< std::string, WRL1NODE* > reg;
public:
bool AddName( const std::string& aName, WRL1NODE* aNode );
bool DelName( const std::string& aName, WRL1NODE* aNode );
WRL1NODE* FindName( const std::string& aName );
private:
std::map< std::string, WRL1NODE* > reg;
};
@ -62,10 +62,28 @@ class WRL1COORDS;
class SGNODE;
// current settings which may affect all subsequent nodes
// during translation / rendering
// current settings which may affect all subsequent nodes during translation / rendering
struct WRL1STATUS
{
WRL1STATUS()
{
Init();
return;
}
void Init()
{
mat = nullptr;
matbind = WRL1_BINDING::BIND_OVERALL;
norm = nullptr;
normbind = WRL1_BINDING::BIND_DEFAULT;
coord = nullptr;
txmatrix = glm::scale( glm::mat4( 1.0 ), glm::vec3( 1.0 ) );
order = WRL1_ORDER::ORD_UNKNOWN;
creaseLimit = 0.878f;
return;
}
// material
WRL1MATERIAL* mat;
@ -89,38 +107,15 @@ struct WRL1STATUS
// cos( creaseAngle ) defines a boundary for normals smoothing
float creaseLimit;
WRL1STATUS()
{
Init();
return;
}
void Init()
{
mat = nullptr;
matbind = WRL1_BINDING::BIND_OVERALL;
norm = nullptr;
normbind = WRL1_BINDING::BIND_DEFAULT;
coord = nullptr;
txmatrix = glm::scale( glm::mat4( 1.0 ), glm::vec3( 1.0 ) );
order = WRL1_ORDER::ORD_UNKNOWN;
creaseLimit = 0.878f;
return;
}
};
/**
* The base class of all VRML1 nodes
* The base class of all VRML1 nodes.
*/
class WRL1NODE
{
public:
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
static std::string tabs;
#endif
// cancel the dictionary pointer; for internal use only
void cancelDict( void );
@ -163,7 +158,6 @@ public:
*/
void delNodeRef( WRL1NODE* aNode );
public:
WRL1NODE( NAMEREGISTER* aDictionary );
virtual ~WRL1NODE();

View File

@ -50,66 +50,34 @@ WRL1SEPARATOR::WRL1SEPARATOR( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1SEPARATOR::~WRL1SEPARATOR()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Destroying Separator with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Destroying Separator with %ul children %ul references, and %ul "
"back pointers." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size() );
}
bool WRL1SEPARATOR::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( nullptr == aTopNode )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is NULL";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s." ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
return false;
}
@ -124,19 +92,11 @@ bool WRL1SEPARATOR::Read( WRLPROC& proc, WRL1BASE* aTopNode )
break;
}
proc.GetFilePosData( line, column );
if( !aTopNode->ReadNode( proc, this, nullptr ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
@ -152,30 +112,12 @@ bool WRL1SEPARATOR::Read( WRLPROC& proc, WRL1BASE* aTopNode )
SGNODE* WRL1SEPARATOR::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Translating Separator with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers (total ";
ostr << m_Items.size() << " items)";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxCHECK_MSG( m_Parent, nullptr, wxT( "Separator has no parent." ) );
if( !m_Parent )
{
#ifdef DEBUG
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] Separator has no parent";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return nullptr;
}
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Translating Separator with %ul children, %ul references, and "
"%ul back pointers (%ul total items)." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size(), m_Items.size() );
if( sp != nullptr )
m_current = *sp;
@ -184,20 +126,9 @@ SGNODE* WRL1SEPARATOR::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
if( nullptr != aParent && ptype != S3D::SGTYPE_TRANSFORM )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] Separator does not have a Transform parent (parent ID: ";
ostr << ptype << ")";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return nullptr;
}
wxCHECK_MSG( aParent && ( ptype == S3D::SGTYPE_TRANSFORM ), nullptr,
wxString::Format( wxT( "Separator does not have a Transform parent (parent "
"ID: %d)." ), ptype ) );
IFSG_TRANSFORM txNode( aParent );
bool hasContent = false;

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -34,9 +35,6 @@
class WRL1BASE;
class SGNODE;
/**
* WRL1SEPARATOR
*/
class WRL1SEPARATOR : public WRL1NODE
{
public:
@ -44,7 +42,6 @@ public:
WRL1SEPARATOR( NAMEREGISTER* aDictionary, WRL1NODE* aNode );
virtual ~WRL1SEPARATOR();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
};

View File

@ -56,92 +56,47 @@ WRL1SHAPEHINTS::WRL1SHAPEHINTS( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1SHAPEHINTS::~WRL1SHAPEHINTS()
{
wxLogTrace( MASK_VRML, " * [INFO] Destroying ShapeHints node\n" );
wxLogTrace( traceVrmlPlugin, " * [INFO] Destroying ShapeHints node." );
}
bool WRL1SHAPEHINTS::AddRefNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddRefNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
}
bool WRL1SHAPEHINTS::AddChildNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddChildNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
}
bool WRL1SHAPEHINTS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( nullptr == aTopNode )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is NULL";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s.\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition(),
proc.GetError() );
return false;
}
@ -159,14 +114,9 @@ bool WRL1SHAPEHINTS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
return false;
}
@ -181,36 +131,33 @@ bool WRL1SHAPEHINTS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
return false;
}
if( !glob.compare( "UNKNOWN_ORDERING" ) )
{
m_order = WRL1_ORDER::ORD_UNKNOWN;
}
else if( !glob.compare( "CLOCKWISE" ) )
{
m_order = WRL1_ORDER::ORD_CLOCKWISE;
}
else if( !glob.compare( "COUNTERCLOCKWISE" ) )
{
m_order = WRL1_ORDER::ORD_CCW;
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad ShapeHints at line " << line << ", column ";
ostr << column << " (invalid value '" << glob << "')\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad ShapeHints %s (invalid value '%s')\n"
" * [INFO] file: '%s'" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), glob,
proc.GetFileName() );
return false;
}
@ -219,14 +166,9 @@ bool WRL1SHAPEHINTS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
return false;
}
@ -239,14 +181,9 @@ bool WRL1SHAPEHINTS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
return false;
}
@ -261,14 +198,9 @@ bool WRL1SHAPEHINTS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
if( !proc.ReadSFFloat( tmp ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
return false;
}
@ -282,16 +214,12 @@ bool WRL1SHAPEHINTS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad ShapeHints at line " << line << ", column ";
ostr << column << " (unexpected keyword '" << glob << "')\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad ShapeHints %s (unexpected keyword '%s')\n"
" * [INFO] file: '%s'" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), glob,
proc.GetFileName() );
return false;
}
@ -305,13 +233,7 @@ SGNODE* WRL1SHAPEHINTS::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
{
// note: this is not fully implemented since it is unlikely we shall
// ever make use of the fields shapeType, faceType, and creaseAngle
if( nullptr == sp )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no base data given\n" );
return nullptr;
}
wxCHECK_MSG( sp, nullptr, wxT( "Invalid base data." ) );
sp->order = m_order;
sp->creaseLimit = cosf(m_crease);

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -35,25 +36,21 @@
class WRL1BASE;
class SGNODE;
/**
* WRL1SHAPEHINTS
*/
class WRL1SHAPEHINTS : public WRL1NODE
{
private:
WRL1_ORDER m_order; // vertex order
float m_crease; // VRML creaseAngle
public:
WRL1SHAPEHINTS( NAMEREGISTER* aDictionary );
WRL1SHAPEHINTS( NAMEREGISTER* aDictionary, WRL1NODE* aParent );
virtual ~WRL1SHAPEHINTS();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool AddRefNode( WRL1NODE* aNode ) override;
bool AddChildNode( WRL1NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
private:
WRL1_ORDER m_order; // vertex order
float m_crease; // VRML creaseAngle
};
#endif // VRML1_SHAPEHINTS_H

View File

@ -53,15 +53,10 @@ WRL1SWITCH::WRL1SWITCH( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
WRL1SWITCH::~WRL1SWITCH()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Destroying Switch with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Destroying Switch node with %ul children, %ul"
"references, and %ul back pointers." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size() );
}
@ -76,52 +71,27 @@ bool WRL1SWITCH::Read( WRLPROC& proc, WRL1BASE* aTopNode )
* }
*/
if( nullptr == aTopNode )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is NULL";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s.\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition(),
proc.GetError() );
return false;
}
@ -142,14 +112,9 @@ bool WRL1SWITCH::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
return false;
}
@ -158,17 +123,13 @@ bool WRL1SWITCH::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadSFInt( whichChild ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid whichChild at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d"
" * [INFO] invalid whichChild %s (invalid value '%s')\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), glob,
proc.GetFileName(), proc.GetError() );
return false;
}
@ -176,33 +137,22 @@ bool WRL1SWITCH::Read( WRLPROC& proc, WRL1BASE* aTopNode )
continue;
}
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid Switch at line " << line << ", column ";
ostr << column << " (expected 'whichChild')\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] invalid Switch %s (unexpected 'whichChild')\n"
" * [INFO] file: '%s'" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName() );
return false;
}
proc.GetFilePosData( line, column );
if( !aTopNode->ReadNode( proc, this, nullptr ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s."),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
@ -218,16 +168,10 @@ bool WRL1SWITCH::Read( WRLPROC& proc, WRL1BASE* aTopNode )
SGNODE* WRL1SWITCH::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Translating Switch with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers (total ";
ostr << m_Items.size() << " items)";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Translating Switch node with %ul children, %ul"
"references, and %ul back pointers (%ul total items)." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size(), m_Items.size() );
if( m_Items.empty() )
return nullptr;

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -34,22 +35,18 @@
class WRL1BASE;
class SGNODE;
/**
* WRL1SWITCH
*/
class WRL1SWITCH : public WRL1NODE
{
private:
int whichChild;
public:
WRL1SWITCH( NAMEREGISTER* aDictionary );
WRL1SWITCH( NAMEREGISTER* aDictionary, WRL1NODE* aNode );
virtual ~WRL1SWITCH();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
private:
int whichChild;
};
#endif // VRML1_SWITCH_H

View File

@ -34,7 +34,6 @@
WRL1TRANSFORM::WRL1TRANSFORM( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
{
m_Type = WRL1NODES::WRL1_TRANSFORM;
return;
}
@ -46,22 +45,15 @@ WRL1TRANSFORM::WRL1TRANSFORM( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
if( nullptr != m_Parent )
m_Parent->AddChildNode( this );
return;
}
WRL1TRANSFORM::~WRL1TRANSFORM()
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Destroying Transform with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Destroying Transform node with %ul children, %ul"
"references, and %ul back pointers." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size() );
}
@ -79,19 +71,7 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
* }
*/
if( nullptr == aTopNode )
{
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is NULL";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
center.x = 0.0;
center.y = 0.0;
@ -110,38 +90,23 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
scale.y = 1.0;
scale.z = 1.0;
size_t line, column;
proc.GetFilePosData( line, column );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s." ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
return false;
}
@ -159,14 +124,9 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
return false;
}
@ -178,23 +138,16 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
// ScaleOrientation
// translation
proc.GetFilePosData( line, column );
if( !glob.compare( "center" ) )
{
if( !proc.ReadSFVec3f( center ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid center at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
" * [INFO] invalid center %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -208,17 +161,12 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadSFRotation( rotation ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid rotation at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
" * [INFO] invalid rotation %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -227,17 +175,12 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadSFVec3f( scale ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid scale at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
" * [INFO] invalid scale %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -246,17 +189,12 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadSFRotation( scaleOrientation ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid scaleOrientation at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
" * [INFO] invalid scaleOrientation %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -265,17 +203,12 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
{
if( !proc.ReadSFVec3f( translation ) )
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] invalid translation at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
ostr << " * [INFO] message: '" << proc.GetError() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
" * [INFO] invalid translation %s\n"
" * [INFO] file: '%s'\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName(), proc.GetError() );
return false;
}
@ -287,16 +220,11 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
}
else
{
#if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad Transform at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
" * [INFO] invalid Transform %s\n"
" * [INFO] file: '%s'" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName() );
return false;
}
@ -309,34 +237,14 @@ bool WRL1TRANSFORM::Read( WRLPROC& proc, WRL1BASE* aTopNode )
bool WRL1TRANSFORM::AddRefNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddRefNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable" ) );
}
bool WRL1TRANSFORM::AddChildNode( WRL1NODE* aNode )
{
// this node may not own or reference any other node
#ifdef DEBUG_VRML1
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] AddChildNode is not applicable";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
}
@ -348,12 +256,7 @@ SGNODE* WRL1TRANSFORM::TranslateToSG( SGNODE* aParent, WRL1STATUS* sp )
if( WRL1NODES::WRL1_BASE == m_Parent->GetNodeType() )
return nullptr;
if( nullptr == sp )
{
wxLogTrace( MASK_VRML, " * [INFO] bad model: no base data given" );
return nullptr;
}
wxCHECK_MSG( sp, nullptr, wxT( "Bad model: no base data given" ) );
// rotation
float rX, rY, rZ, rW;

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -34,28 +35,24 @@
class WRL1BASE;
class SGNODE;
/**
* WRL1TRANSFORM
*/
class WRL1TRANSFORM : public WRL1NODE
{
public:
WRL1TRANSFORM( NAMEREGISTER* aDictionary );
WRL1TRANSFORM( NAMEREGISTER* aDictionary, WRL1NODE* aNode );
virtual ~WRL1TRANSFORM();
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool AddRefNode( WRL1NODE* aNode ) override;
bool AddChildNode( WRL1NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
private:
WRLVEC3F center;
WRLVEC3F scale;
WRLVEC3F translation;
WRLROTATION rotation;
WRLROTATION scaleOrientation;
public:
WRL1TRANSFORM( NAMEREGISTER* aDictionary );
WRL1TRANSFORM( NAMEREGISTER* aDictionary, WRL1NODE* aNode );
virtual ~WRL1TRANSFORM();
// functions inherited from WRL1NODE
bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) override;
bool AddRefNode( WRL1NODE* aNode ) override;
bool AddChildNode( WRL1NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) override;
};
#endif // VRML1_TRANSFORM_H

View File

@ -56,15 +56,10 @@ WRL2APPEARANCE::WRL2APPEARANCE( WRL2NODE* aParent ) : WRL2NODE()
WRL2APPEARANCE::~WRL2APPEARANCE()
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Destroying Appearance with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Destroying Appearance node with %ul children, %ul"
"references, and %ul back pointers." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size() );
}
@ -91,7 +86,6 @@ bool WRL2APPEARANCE::checkNodeType( WRL2NODES aType )
bool WRL2APPEARANCE::isDangling( void )
{
// this node is dangling unless it has a parent of type WRL2_SHAPE
if( nullptr == m_Parent || m_Parent->GetNodeType() != WRL2NODES::WRL2_SHAPE )
return true;
@ -101,33 +95,16 @@ bool WRL2APPEARANCE::isDangling( void )
bool WRL2APPEARANCE::AddRefNode( WRL2NODE* aNode )
{
if( nullptr == aNode )
{
#ifdef DEBUG_VRML2
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL passed for aNode";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
WRL2NODES type = aNode->GetNodeType();
if( !checkNodeType( type ) )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected child node '";
ostr << aNode->GetNodeTypeName( type ) << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected child node '%s'." ),
__FILE__, __FUNCTION__, __LINE__, aNode->GetNodeTypeName( type ) );
return false;
}
@ -136,14 +113,10 @@ bool WRL2APPEARANCE::AddRefNode( WRL2NODE* aNode )
{
if( nullptr != material )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; multiple material nodes";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; multiple material nodes." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -156,14 +129,10 @@ bool WRL2APPEARANCE::AddRefNode( WRL2NODE* aNode )
{
if( nullptr != textureTransform )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; multiple textureTransform nodes";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; multiple textureTransform nodes." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -174,14 +143,10 @@ bool WRL2APPEARANCE::AddRefNode( WRL2NODE* aNode )
if( nullptr != texture )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; multiple texture nodes";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; multiple texture nodes." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -193,33 +158,16 @@ bool WRL2APPEARANCE::AddRefNode( WRL2NODE* aNode )
bool WRL2APPEARANCE::AddChildNode( WRL2NODE* aNode )
{
if( nullptr == aNode )
{
#ifdef DEBUG_VRML2
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] NULL passed for aNode";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
WRL2NODES type = aNode->GetNodeType();
if( !checkNodeType( type ) )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected child node '";
ostr << aNode->GetNodeTypeName( type ) << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected child node '%s'." ),
__FILE__, __FUNCTION__, __LINE__, aNode->GetNodeTypeName( type ) );
return false;
}
@ -228,14 +176,10 @@ bool WRL2APPEARANCE::AddChildNode( WRL2NODE* aNode )
{
if( nullptr != material )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; multiple material nodes";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; multiple material nodes." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -248,14 +192,10 @@ bool WRL2APPEARANCE::AddChildNode( WRL2NODE* aNode )
{
if( nullptr != textureTransform )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; multiple textureTransform nodes";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; multiple textureTransform nodes." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -266,14 +206,10 @@ bool WRL2APPEARANCE::AddChildNode( WRL2NODE* aNode )
if( nullptr != texture )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; multiple texture nodes";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; multiple texture nodes." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -285,52 +221,25 @@ bool WRL2APPEARANCE::AddChildNode( WRL2NODE* aNode )
bool WRL2APPEARANCE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
{
if( nullptr == aTopNode )
{
#ifdef DEBUG_VRML2
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] aTopNode is NULL";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
return false;
}
size_t line, column;
proc.GetFilePosData( line, column );
wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
char tok = proc.Peek();
if( proc.eof() )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; unexpected eof at line ";
ostr << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad file format; unexpected eof %s." ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
return false;
}
if( '{' != tok )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << proc.GetError() << "\n";
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
ostr << "' at line " << line << ", column " << column;
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] bad file format; expecting '{' but got '%s' %s." ),
__FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
return false;
}
@ -348,14 +257,9 @@ bool WRL2APPEARANCE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
if( !proc.ReadName( glob ) )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << proc.GetError();
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
"%s" ),
__FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
return false;
}
@ -365,20 +269,14 @@ bool WRL2APPEARANCE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
// texture
// textureTransform
proc.GetFilePosData( line, column );
if( !glob.compare( "material" ) )
{
if( !aTopNode->ReadNode( proc, this, nullptr ) )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] could not read material information";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] could not read material information." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -387,14 +285,10 @@ bool WRL2APPEARANCE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
{
if( !aTopNode->ReadNode( proc, this, nullptr ) )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] could not read texture information";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] could not read texture information." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
@ -403,30 +297,21 @@ bool WRL2APPEARANCE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
{
if( !aTopNode->ReadNode( proc, this, nullptr ) )
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] could not read textureTransform information";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( "%s:%s:%d\n"
" * [INFO] could not read textureTransform information." ),
__FILE__, __FUNCTION__, __LINE__ );
return false;
}
}
else
{
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [INFO] bad Appearance at line " << line << ", column ";
ostr << column << "\n";
ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
" * [INFO] bad Appearance %s.\n"
" * [INFO] file: '%s'" ),
__FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
proc.GetFileName() );
return false;
}
@ -443,30 +328,14 @@ SGNODE* WRL2APPEARANCE::TranslateToSG( SGNODE* aParent )
S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
if( nullptr != aParent && ptype != S3D::SGTYPE_SHAPE )
{
#ifdef DEBUG_VRML2
do {
std::ostringstream ostr;
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
ostr << " * [BUG] Appearance does not have a Shape parent (parent ID: ";
ostr << ptype << ")";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxCHECK_MSG( aParent && ( ptype == S3D::SGTYPE_SHAPE ), nullptr,
wxString::Format( wxT( " * [BUG] Appearance does not have a Shape parent "
"(parent ID: %d)." ), ptype ) );
return nullptr;
}
#if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 2 )
do {
std::ostringstream ostr;
ostr << " * [INFO] Translating Appearance with " << m_Children.size();
ostr << " children, " << m_Refs.size() << " references and ";
ostr << m_BackPointers.size() << " backpointers";
wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
} while( 0 );
#endif
wxLogTrace( traceVrmlPlugin,
wxT( " * [INFO] Translating Appearance node with %ul children, %ul"
"references, and %ul back pointers." ),
m_Children.size(), m_Refs.size(), m_BackPointers.size() );
if( m_sgNode )
{
@ -494,6 +363,7 @@ SGNODE* WRL2APPEARANCE::TranslateToSG( SGNODE* aParent )
matNode.SetEmissive( 0.0f, 0.0f, 0.0f );
matNode.SetSpecular( 0.65f, 0.65f, 0.65f );
matNode.SetDiffuse( 0.65f, 0.65f, 0.65f );
// default ambient
matNode.SetShininess( 0.2f );
matNode.SetTransparency( 0.0f );

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -34,41 +35,32 @@
class WRL2BASE;
class SGNODE;
/**
* WRL2APPEARANCE
*/
class WRL2APPEARANCE : public WRL2NODE
{
private:
WRL2NODE* material;
WRL2NODE* texture;
WRL2NODE* textureTransform;
/**
* Function checkNodeType
* returns true if the node type is a material description class
*/
bool checkNodeType( WRL2NODES aType );
// overloads
void unlinkChildNode( const WRL2NODE* aNode ) override;
void unlinkRefNode( const WRL2NODE* aNode ) override;
public:
// functions inherited from WRL2NODE
bool isDangling( void ) override;
public:
WRL2APPEARANCE();
WRL2APPEARANCE( WRL2NODE* aParent );
virtual ~WRL2APPEARANCE();
// functions inherited from WRL2NODE
bool Read( WRLPROC& proc, WRL2BASE* aTopNode ) override;
bool AddRefNode( WRL2NODE* aNode ) override;
bool AddChildNode( WRL2NODE* aNode ) override;
SGNODE* TranslateToSG( SGNODE* aParent ) override;
bool isDangling( void ) override;
private:
/**
* Return true if the node type is a material description class.
*/
bool checkNodeType( WRL2NODES aType );
void unlinkChildNode( const WRL2NODE* aNode ) override;
void unlinkRefNode( const WRL2NODE* aNode ) override;
WRL2NODE* material;
WRL2NODE* texture;
WRL2NODE* textureTransform;
};
#endif // VRML2_APPEARANCE_H

Some files were not shown because too many files have changed in this diff Show More