kicad-source/plugins/3d/vrml/v2/vrml2_base.cpp

473 lines
11 KiB
C++
Raw Normal View History

2015-12-20 18:59:26 +11:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <iostream>
#include "vrml2_base.h"
#include "vrml2_helpers.h"
2015-12-20 23:37:04 +11:00
WRL2BASE::WRL2BASE() : WRL2NODE()
2015-12-20 18:59:26 +11:00
{
2015-12-20 23:37:04 +11:00
m_Type = WRL2_BASE;
2015-12-20 18:59:26 +11:00
return;
}
WRL2BASE::~WRL2BASE()
{
std::list< WRL2NODE* >::iterator sC = m_Children.begin();
std::list< WRL2NODE* >::iterator eC = m_Children.end();
while( sC != eC )
{
(*sC)->SetParent( NULL );
delete (*sC);
++sC;
}
2015-12-20 23:37:04 +11:00
m_Children.clear();
2015-12-20 18:59:26 +11:00
return;
}
// functions inherited from WRL2NODE
bool WRL2BASE::SetParent( WRL2NODE* aParent )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
2015-12-20 23:37:04 +11:00
std::cerr << " * [BUG] attempting to set parent on WRL2BASE node\n";
2015-12-20 18:59:26 +11:00
#endif
2015-12-20 23:37:04 +11:00
return false;
2015-12-20 18:59:26 +11:00
}
WRL2NODE* WRL2BASE::FindNode( const std::string& aNodeName, const WRL2NODE *aCaller )
2015-12-20 18:59:26 +11:00
{
if( aNodeName.empty() )
2015-12-20 18:59:26 +11:00
return NULL;
if( !m_Name.compare( aNodeName ) )
return this;
FIND_NODE( aNodeName, m_Children, this );
return NULL;
}
bool WRL2BASE::AddRefNode( WRL2NODE* aNode )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] attempting to add reference node to WRL2BASE\n";
#endif
return false;
}
bool WRL2BASE::AddChildNode( WRL2NODE* aNode )
{
if( aNode->GetNodeType() == WRL2_BASE )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] attempting to add a base node to another base node\n";
#endif
return false;
}
std::list< WRL2NODE* >::iterator sC = m_Children.begin();
std::list< WRL2NODE* >::iterator eC = m_Children.end();
while( sC != eC )
{
if( *sC == aNode )
return false;
}
aNode->SetParent( this );
m_Children.push_back( aNode );
return true;
}
const char* WRL2BASE::GetName( void )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] attempting to extract name from virtual base node\n";
#endif
return NULL;
return NULL;
}
bool WRL2BASE::SetName(const char *aName)
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] attempting to set name on virtual base node\n";
#endif
return false;
}
2015-12-20 23:37:04 +11:00
void WRL2BASE::unlinkChildNode( const WRL2NODE* aNode )
{
std::list< WRL2NODE* >::iterator sL = m_Children.begin();
std::list< WRL2NODE* >::iterator eL = m_Children.end();
while( sL != eL )
{
if( *sL == aNode )
{
m_Children.erase( sL );
return;
}
++sL;
}
return;
}
void WRL2BASE::unlinkRefNode( const WRL2NODE* aNode )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] WRL2BASE was invoked to unlink a referenced node\n";
#endif
return;
}
2015-12-20 18:59:26 +11:00
bool WRL2BASE::Read( WRLPROC& proc )
{
if( proc.GetVRMLType() != VRML_V2 )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] no open file or file is not a VRML2 file\n";
#endif
return false;
}
WRL2NODE* node = NULL;
while( !readNode( proc, this, node ) );
if( proc.eof() )
return true;
return false;
}
bool WRL2BASE::isDangling( void )
{
return false;
}
bool WRL2BASE::implementUse( WRLPROC& proc, WRL2NODE* aParent )
{
if( !aParent )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] invoked with NULL parent\n";
#endif
return false;
}
std::string glob;
if( !proc.ReadName( glob ) )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
}
WRL2NODE* ref = aParent->FindNode( glob, NULL );
// return 'true' - the file may be defective but it may still be somewhat OK
if( NULL == ref )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] node '" << glob << "' not found\n";
#endif
return true;
}
if( !aParent->AddRefNode( ref ) )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] failed to add node '" << glob << "' (";
std::cerr << ref->GetNodeTypeName( ref->GetNodeType() ) << ") to parent of type ";
std::cerr << aParent->GetNodeTypeName( aParent->GetNodeType() ) << "\n";
#endif
return false;
}
return true;
}
bool WRL2BASE::implementDef( WRLPROC& proc, WRL2NODE* aParent )
{
// XXX - TO BE IMPLEMENTED
return false;
}
bool WRL2BASE::readNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
{
if( NULL == aNode )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] invalid node handle (NULL)\n";
#endif
return false;
}
if( NULL == aParent )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] invalid parent pointer (NULL)\n";
#endif
return false;
}
*aNode = NULL;
2015-12-20 18:59:26 +11:00
std::string glob;
2015-12-20 23:37:04 +11:00
bool hasComma = false;
WRL2NODES ntype;
2015-12-20 18:59:26 +11:00
if( !proc.ReadName( glob ) )
2015-12-20 18:59:26 +11:00
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
}
2015-12-20 23:37:04 +11:00
// Process node name:
// the names encountered at this point should be one of the
// built-in node names or one of:
// DEF, USE
// PROTO, EXTERNPROTO
// ROUTE
// any PROTO or EXTERNPROTO defined name
// since we do not support PROTO or EXTERNPROTO, any unmatched names are
// assumed to be defined via PROTO/EXTERNPROTO and deleted according to
// a typical pattern.
if( !glob.compare( "USE" ) )
{
if( !implementUse( aParent ) )
2015-12-20 23:37:04 +11:00
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
2015-12-20 23:37:04 +11:00
}
return true;
}
if( !glob.compare( "DEF" ) )
{
// XXX - implement
implementDef( aParent );
}
if( !glob.compare( "PROTO" ) )
{
if( !proc.ReadName( glob ) || !proc.DiscardList() )
2015-12-20 23:37:04 +11:00
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
2015-12-20 23:37:04 +11:00
}
return true;
}
if( !glob.compare( "EXTERNPROTO" ) )
{
if( !proc.ReadName( glob ) || !proc.ReadName( glob ) || !proc.DiscardList() )
2015-12-20 23:37:04 +11:00
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
2015-12-20 23:37:04 +11:00
}
return true;
}
if( !glob.compare( "ROUTE" ) )
{
if( !proc.ReadGlob( glob ) || !proc.ReadGlob( glob ) || !proc.ReadGlob( glob ) )
2015-12-20 23:37:04 +11:00
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << proc.GetError() << "\n";
#endif
return false;
2015-12-20 23:37:04 +11:00
}
return true;
}
ntype = getNodeTypeID( glob );
2015-12-20 23:37:04 +11:00
switch( ntype )
{
2015-12-20 23:37:04 +11:00
//
// items to be implemented:
//
case WRL2_APPEARANCE:
// note:
break;
2015-12-20 23:37:04 +11:00
case WRL2_BOX:
break;
2015-12-20 23:37:04 +11:00
case WRL2_COLOR:
break;
2015-12-20 23:37:04 +11:00
case WRL2_CONE:
break;
2015-12-20 23:37:04 +11:00
case WRL2_COORDINATE:
break;
2015-12-20 23:37:04 +11:00
case WRL2_CYLINDER:
break;
2015-12-20 23:37:04 +11:00
case WRL2_ELEVATIONGRID:
break;
2015-12-20 23:37:04 +11:00
case WRL2_EXTRUSION:
break;
2015-12-20 23:37:04 +11:00
case WRL2_INDEXEDFACESET:
break;
2015-12-20 23:37:04 +11:00
case WRL2_MATERIAL:
break;
2015-12-20 23:37:04 +11:00
case WRL2_NORMAL:
break;
2015-12-20 23:37:04 +11:00
case WRL2_SHAPE:
break;
2015-12-20 23:37:04 +11:00
case WRL2_SPHERE:
break;
2015-12-20 23:37:04 +11:00
case WRL2_TRANSFORM:
case WRL2_GROUP:
break;
2015-12-20 23:37:04 +11:00
//
// items not implemented or for optional future implementation:
//
case WRL2_ANCHOR:
case WRL2_AUDIOCLIP:
case WRL2_BACKGROUND:
case WRL2_BILLBOARD:
case WRL2_COLLISION:
case WRL2_COLORINTERPOLATOR:
case WRL2_COORDINATEINTERPOLATOR:
case WRL2_CYLINDERSENSOR:
case WRL2_DIRECTIONALLIGHT:
case WRL2_FOG:
case WRL2_FONTSTYLE:
case WRL2_IMAGETEXTURE:
case WRL2_INDEXEDLINESET:
case WRL2_INLINE:
case WRL2_LOD:
case WRL2_MOVIETEXTURE:
case WRL2_NAVIGATIONINFO:
case WRL2_NORMALINTERPOLATOR:
case WRL2_ORIENTATIONINTERPOLATOR:
case WRL2_PIXELTEXTURE:
case WRL2_PLANESENSOR:
case WRL2_POINTLIGHT:
case WRL2_POINTSET:
case WRL2_POSITIONINTERPOLATOR:
case WRL2_PROXIMITYSENSOR:
case WRL2_SCALARINTERPOLATOR:
case WRL2_SCRIPT:
case WRL2_SOUND:
case WRL2_SPHERESENSOR:
case WRL2_SPOTLIGHT:
case WRL2_SWITCH:
case WRL2_TEXT:
case WRL2_TEXTURECOORDINATE:
case WRL2_TEXTURETRANSFORM:
case WRL2_TIMESENSOR:
case WRL2_TOUCHSENSOR:
case WRL2_VIEWPOINT:
case WRL2_VISIBILITYSENSOR:
case WRL2_WORLDINFO:
case WRL2_INVALID:
default: // any nodes which may have been defined via PROTO/EXTERNPROTO
break;
}
2015-12-22 08:19:05 +11:00
// XXX - TO BE IMPLEMENTED
return NULL;
2015-12-22 08:19:05 +11:00
}