Work in progress: implementing VRML2 plugin
This commit is contained in:
parent
f7ea4ddb72
commit
68a512693f
|
@ -6,6 +6,13 @@ add_library( s3d_plugin_vrml MODULE
|
|||
v2/vrml2_node.cpp
|
||||
v2/vrml2_base.cpp
|
||||
v2/vrml2_transform.cpp
|
||||
v2/vrml2_shape.cpp
|
||||
v2/vrml2_appearance.cpp
|
||||
v2/vrml2_material.cpp
|
||||
v2/vrml2_faceset.cpp
|
||||
v2/vrml2_coords.cpp
|
||||
v2/vrml2_norms.cpp
|
||||
v2/vrml2_color.cpp
|
||||
)
|
||||
|
||||
target_link_libraries( s3d_plugin_vrml kicad_3dsg ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
|
||||
|
|
|
@ -0,0 +1,348 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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_appearance.h"
|
||||
|
||||
|
||||
WRL2APPEARANCE::WRL2APPEARANCE() : WRL2NODE()
|
||||
{
|
||||
material = NULL;
|
||||
texture = NULL;
|
||||
textureTransform = NULL;
|
||||
m_Type = WRL2_APPEARANCE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2APPEARANCE::WRL2APPEARANCE( WRL2NODE* aParent ) : WRL2NODE()
|
||||
{
|
||||
material = NULL;
|
||||
texture = NULL;
|
||||
textureTransform = NULL;
|
||||
m_Type = WRL2_APPEARANCE;
|
||||
m_Parent = aParent;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
m_Parent->AddChildNode( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2APPEARANCE::~WRL2APPEARANCE()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] Destroying Appearance with " << m_Children.size();
|
||||
std::cerr << " children, " << m_Refs.size() << " references and ";
|
||||
std::cerr << m_BackPointers.size() << " backpointers\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool WRL2APPEARANCE::checkNodeType( WRL2NODES aType )
|
||||
{
|
||||
switch( aType )
|
||||
{
|
||||
case WRL2_MATERIAL:
|
||||
case WRL2_IMAGETEXTURE:
|
||||
case WRL2_PIXELTEXTURE:
|
||||
case WRL2_MOVIETEXTURE:
|
||||
case WRL2_TEXTURETRANSFORM:
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2APPEARANCE::isDangling( void )
|
||||
{
|
||||
// this node is dangling unless it has a parent of type WRL2_SHAPE
|
||||
|
||||
if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_SHAPE )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2APPEARANCE::AddRefNode( WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] NULL passed for aNode\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
WRL2NODES type = aNode->GetNodeType();
|
||||
|
||||
if( !checkNodeType( type ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected child node '";
|
||||
std::cerr << aNode->GetNodeTypeName( type ) << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( WRL2_MATERIAL == type )
|
||||
{
|
||||
if( NULL != material )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple material nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
material = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
if( WRL2_TEXTURETRANSFORM == type )
|
||||
{
|
||||
if( NULL != textureTransform )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple textureTransform nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
textureTransform = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
if( NULL != texture )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple texture nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
texture = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
|
||||
bool WRL2APPEARANCE::AddChildNode( WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] NULL passed for aNode\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
WRL2NODES type = aNode->GetNodeType();
|
||||
|
||||
if( !checkNodeType( type ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected child node '";
|
||||
std::cerr << aNode->GetNodeTypeName( type ) << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( WRL2_MATERIAL == type )
|
||||
{
|
||||
if( NULL != material )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple material nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
material = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
if( WRL2_TEXTURETRANSFORM == type )
|
||||
{
|
||||
if( NULL != textureTransform )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple textureTransform nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
textureTransform = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
if( NULL != texture )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple texture nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
texture = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
|
||||
bool WRL2APPEARANCE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
if( NULL == aTopNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] aTopNode is NULL\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '{' != tok )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
|
||||
std::cerr << "' at line " << line << ", column " << column << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.Pop();
|
||||
std::string glob;
|
||||
|
||||
while( true )
|
||||
{
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
break;
|
||||
}
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// expecting one of:
|
||||
// material
|
||||
// texture
|
||||
// textureTransform
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
if( !glob.compare( "material" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read material information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "texture" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read texture information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "textureTransform" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read textureTransform information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Appearance at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
} // while( true ) -- reading contents of Appearance{}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file vrml2_appearance.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VRML2_APPEARANCE_H
|
||||
#define VRML2_APPEARANCE_H
|
||||
|
||||
#include "vrml2_node.h"
|
||||
|
||||
class WRL2BASE;
|
||||
|
||||
/**
|
||||
* Class 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 );
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
WRL2APPEARANCE();
|
||||
WRL2APPEARANCE( WRL2NODE* aParent );
|
||||
virtual ~WRL2APPEARANCE();
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool Read( WRLPROC& proc, WRL2BASE* aTopNode );
|
||||
bool AddRefNode( WRL2NODE* aNode );
|
||||
bool AddChildNode( WRL2NODE* aNode );
|
||||
};
|
||||
|
||||
#endif // VRML2_APPEARANCE_H
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
||||
* Copyright (C) 2015-2016 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
|
||||
|
@ -25,6 +25,13 @@
|
|||
|
||||
#include "vrml2_base.h"
|
||||
#include "vrml2_transform.h"
|
||||
#include "vrml2_shape.h"
|
||||
#include "vrml2_appearance.h"
|
||||
#include "vrml2_material.h"
|
||||
#include "vrml2_faceset.h"
|
||||
#include "vrml2_coords.h"
|
||||
#include "vrml2_norms.h"
|
||||
#include "vrml2_color.h"
|
||||
|
||||
|
||||
WRL2BASE::WRL2BASE() : WRL2NODE()
|
||||
|
@ -73,37 +80,6 @@ bool WRL2BASE::SetName( const std::string& aName )
|
|||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::Read( WRLPROC& proc )
|
||||
{
|
||||
if( proc.GetVRMLType() != VRML_V2 )
|
||||
|
@ -128,21 +104,15 @@ bool WRL2BASE::Read( WRLPROC& proc )
|
|||
|
||||
bool WRL2BASE::isDangling( void )
|
||||
{
|
||||
// the base node is never dangling
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::implementUse( 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 != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
if( !aParent )
|
||||
{
|
||||
|
@ -154,7 +124,6 @@ bool WRL2BASE::implementUse( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode
|
|||
return false;
|
||||
}
|
||||
|
||||
*aNode = NULL;
|
||||
std::string glob;
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
|
@ -192,7 +161,8 @@ bool WRL2BASE::implementUse( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode
|
|||
return false;
|
||||
}
|
||||
|
||||
*aNode = ref;
|
||||
if( NULL != aNode )
|
||||
*aNode = ref;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -200,15 +170,8 @@ bool WRL2BASE::implementUse( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode
|
|||
|
||||
bool WRL2BASE::implementDef( 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 != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
if( NULL == aParent )
|
||||
{
|
||||
|
@ -220,9 +183,8 @@ bool WRL2BASE::implementDef( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode
|
|||
return false;
|
||||
}
|
||||
|
||||
*aNode = NULL;
|
||||
|
||||
std::string glob;
|
||||
WRL2NODE* lnode = NULL;
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
{
|
||||
|
@ -237,9 +199,12 @@ bool WRL2BASE::implementDef( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode
|
|||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
if( ReadNode( proc, aParent, aNode ) )
|
||||
if( ReadNode( proc, aParent, &lnode ) )
|
||||
{
|
||||
if( *aNode && !(*aNode)->SetName( glob ) )
|
||||
if( NULL != aNode )
|
||||
*aNode = lnode;
|
||||
|
||||
if( lnode && !lnode->SetName( glob ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
size_t line, column;
|
||||
|
@ -251,23 +216,24 @@ bool WRL2BASE::implementDef( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
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
|
||||
// This function reads a node and stores a pointer to it in aNode.
|
||||
// A value 'true' is returned if a node is successfully read or,
|
||||
// if the node is not supported, successfully discarded. Callers
|
||||
// must always check the value of aNode when the function returns
|
||||
// 'true' since it will be NULL if the node type is not supported.
|
||||
|
||||
return false;
|
||||
}
|
||||
if( NULL != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
if( NULL == aParent )
|
||||
{
|
||||
|
@ -279,8 +245,6 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
return false;
|
||||
}
|
||||
|
||||
*aNode = NULL;
|
||||
|
||||
std::string glob;
|
||||
WRL2NODES ntype;
|
||||
|
||||
|
@ -307,6 +271,7 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
// 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( proc, aParent, aNode ) )
|
||||
|
@ -396,20 +361,9 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
// items to be implemented:
|
||||
//
|
||||
case WRL2_APPEARANCE:
|
||||
// XXX - IMPLEMENT
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
|
||||
if( !readAppearance( proc, aParent, aNode ) )
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << " * [INFO] OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
|
@ -432,20 +386,9 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
break;
|
||||
|
||||
case WRL2_COLOR:
|
||||
// XXX - IMPLEMENT
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
|
||||
if( !readColor( proc, aParent, aNode ) )
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << " * [INFO] OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
|
@ -468,20 +411,9 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
break;
|
||||
|
||||
case WRL2_COORDINATE:
|
||||
// XXX - IMPLEMENT
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
|
||||
if( !readCoords( proc, aParent, aNode ) )
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << " * [INFO] OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
|
@ -540,72 +472,30 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
break;
|
||||
|
||||
case WRL2_INDEXEDFACESET:
|
||||
// XXX - IMPLEMENT
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
|
||||
if( !readFaceSet( proc, aParent, aNode ) )
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << " * [INFO] OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
case WRL2_MATERIAL:
|
||||
// XXX - IMPLEMENT
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
|
||||
if( !readMaterial( proc, aParent, aNode ) )
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << " * [INFO] OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
case WRL2_NORMAL:
|
||||
// XXX - IMPLEMENT
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
|
||||
if( !readNorms( proc, aParent, aNode ) )
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
std::cerr << " * [INFO] OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
case WRL2_SHAPE:
|
||||
// XXX - IMPLEMENT
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
|
||||
if( !readShape( proc, aParent, aNode ) )
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << " * [INFO] OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
|
@ -629,22 +519,9 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
|
||||
case WRL2_TRANSFORM:
|
||||
case WRL2_GROUP:
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] FAIL: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
{
|
||||
std::cerr << " * [INFO] OK: discard " << glob << " node at l" << line << ", c" << column << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
//if( !readTransform( proc, aParent, aNode ) )
|
||||
// return false;
|
||||
if( !readTransform( proc, aParent, aNode ) )
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
|
@ -697,7 +574,7 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
|
||||
if( !proc.DiscardNode() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not discard node at line " << line;
|
||||
|
@ -714,6 +591,19 @@ bool WRL2BASE::ReadNode( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
|||
}
|
||||
|
||||
|
||||
bool WRL2BASE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
// this function makes no sense in the base node
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] this method must never be invoked on a WRL2BASE object\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::readTransform( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
||||
{
|
||||
if( NULL != aNode )
|
||||
|
@ -734,14 +624,141 @@ bool WRL2BASE::readTransform( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode
|
|||
}
|
||||
|
||||
|
||||
bool WRL2BASE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
bool WRL2BASE::readShape( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
||||
{
|
||||
// this function makes no sense in the base node
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] this method must never be invoked on a WRL2BASE object\n";
|
||||
#endif
|
||||
if( NULL != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
return false;
|
||||
WRL2SHAPE* np = new WRL2SHAPE( aParent );
|
||||
|
||||
if( !np->Read( proc, this ) )
|
||||
{
|
||||
delete np;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != aNode )
|
||||
*aNode = (WRL2NODE*) np;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::readAppearance( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
||||
{
|
||||
if( NULL != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
WRL2APPEARANCE* np = new WRL2APPEARANCE( aParent );
|
||||
|
||||
if( !np->Read( proc, this ) )
|
||||
{
|
||||
delete np;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != aNode )
|
||||
*aNode = (WRL2NODE*) np;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::readMaterial( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
||||
{
|
||||
if( NULL != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
WRL2MATERIAL* np = new WRL2MATERIAL( aParent );
|
||||
|
||||
if( !np->Read( proc, this ) )
|
||||
{
|
||||
delete np;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != aNode )
|
||||
*aNode = (WRL2NODE*) np;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::readFaceSet( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
||||
{
|
||||
if( NULL != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
WRL2FACESET* np = new WRL2FACESET( aParent );
|
||||
|
||||
if( !np->Read( proc, this ) )
|
||||
{
|
||||
delete np;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != aNode )
|
||||
*aNode = (WRL2NODE*) np;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::readCoords( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
||||
{
|
||||
if( NULL != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
WRL2COORDS* np = new WRL2COORDS( aParent );
|
||||
|
||||
if( !np->Read( proc, this ) )
|
||||
{
|
||||
delete np;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != aNode )
|
||||
*aNode = (WRL2NODE*) np;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::readNorms( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
||||
{
|
||||
if( NULL != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
WRL2NORMS* np = new WRL2NORMS( aParent );
|
||||
|
||||
if( !np->Read( proc, this ) )
|
||||
{
|
||||
delete np;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != aNode )
|
||||
*aNode = (WRL2NODE*) np;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2BASE::readColor( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode )
|
||||
{
|
||||
if( NULL != aNode )
|
||||
*aNode = NULL;
|
||||
|
||||
WRL2COLOR* np = new WRL2COLOR( aParent );
|
||||
|
||||
if( !np->Read( proc, this ) )
|
||||
{
|
||||
delete np;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != aNode )
|
||||
*aNode = (WRL2NODE*) np;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
||||
* Copyright (C) 2015-2016 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
|
||||
|
@ -55,18 +55,24 @@
|
|||
*/
|
||||
class WRL2BASE : public WRL2NODE
|
||||
{
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
void unlinkChildNode( const WRL2NODE* aNode );
|
||||
void unlinkRefNode( const WRL2NODE* aNode );
|
||||
bool isDangling( void );
|
||||
|
||||
private:
|
||||
// handle cases of USE / DEF
|
||||
bool implementUse( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
bool implementDef( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
|
||||
bool readTransform( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
bool readShape( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
bool readAppearance( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
bool readMaterial( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
bool readFaceSet( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
bool readCoords( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
bool readNorms( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
bool readColor( WRLPROC& proc, WRL2NODE* aParent, WRL2NODE** aNode );
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
WRL2BASE();
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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_color.h"
|
||||
|
||||
|
||||
WRL2COLOR::WRL2COLOR() : WRL2NODE()
|
||||
{
|
||||
m_Type = WRL2_COLOR;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2COLOR::WRL2COLOR( WRL2NODE* aParent ) : WRL2NODE()
|
||||
{
|
||||
m_Type = WRL2_COLOR;
|
||||
m_Parent = aParent;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
m_Parent->AddChildNode( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2COLOR::~WRL2COLOR()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] Destroying Color node\n";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2COLOR::isDangling( void )
|
||||
{
|
||||
// this node is dangling unless it has a parent of type WRL2_INDEXEDFACESET
|
||||
|
||||
if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_INDEXEDFACESET )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2COLOR::AddRefNode( WRL2NODE* aNode )
|
||||
{
|
||||
// this node may not own or reference any other node
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] AddRefNode is not applicable\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2COLOR::AddChildNode( WRL2NODE* aNode )
|
||||
{
|
||||
// this node may not own or reference any other node
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] AddChildNode is not applicable\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2COLOR::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '{' != tok )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
|
||||
std::cerr << "' at line " << line << ", column " << column << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.Pop();
|
||||
std::string glob;
|
||||
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
// expecting 'color'
|
||||
if( !glob.compare( "color" ) )
|
||||
{
|
||||
if( !proc.ReadMFVec3f( colors ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid color set at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Color at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Color at line " << line << ", column ";
|
||||
std::cerr << column << " (no closing brace)\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
||||
* Copyright (C) 2016 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
|
||||
|
@ -22,26 +22,41 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file vrml2_helpers.h
|
||||
* helper functions for VRML2 processing
|
||||
* @file vrml2_color.h
|
||||
*/
|
||||
|
||||
#ifndef VRML2_HELPERS_H
|
||||
#define VRML2_HELPERS_H
|
||||
|
||||
#ifndef VRML2_COLOR_H
|
||||
#define VRML2_COLOR_H
|
||||
|
||||
// Function to find a node object given a (non-unique) node name
|
||||
#define FIND_NODE( aName, aNodeList, aCallingNode ) do { \
|
||||
std::list< WRL2NODE* >::iterator sLA = aNodeList.begin(); \
|
||||
std::list< WRL2NODE* >::iterator eLA = aNodeList.end(); \
|
||||
WRL2NODE* psg = NULL; \
|
||||
while( sLA != eLA ) { \
|
||||
if( (WRL2NODE*)*sLA != aCallingNode ) { \
|
||||
psg = (*sLA)->FindNode( aName, this ); \
|
||||
if( NULL != psg) \
|
||||
return psg; \
|
||||
} \
|
||||
++sLA; \
|
||||
} } while ( 0 )
|
||||
#include <vector>
|
||||
|
||||
#endif // VRML2_HELPERS_H
|
||||
#include "vrml2_node.h"
|
||||
|
||||
class WRL2BASE;
|
||||
|
||||
/**
|
||||
* Class WRL2COLOR
|
||||
*/
|
||||
class WRL2COLOR : public WRL2NODE
|
||||
{
|
||||
private:
|
||||
std::vector< WRLVEC3F > colors;
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
WRL2COLOR();
|
||||
WRL2COLOR( WRL2NODE* aParent );
|
||||
virtual ~WRL2COLOR();
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool Read( WRLPROC& proc, WRL2BASE* aTopNode );
|
||||
bool AddRefNode( WRL2NODE* aNode );
|
||||
bool AddChildNode( WRL2NODE* aNode );
|
||||
};
|
||||
|
||||
#endif // VRML2_COLOR_H
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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_coords.h"
|
||||
|
||||
|
||||
WRL2COORDS::WRL2COORDS() : WRL2NODE()
|
||||
{
|
||||
m_Type = WRL2_COORDINATE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2COORDS::WRL2COORDS( WRL2NODE* aParent ) : WRL2NODE()
|
||||
{
|
||||
m_Type = WRL2_COORDINATE;
|
||||
m_Parent = aParent;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
m_Parent->AddChildNode( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2COORDS::~WRL2COORDS()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] Destroying Coordinate node\n";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2COORDS::isDangling( void )
|
||||
{
|
||||
// this node is dangling unless it has a parent of type WRL2_INDEXEDFACESET
|
||||
|
||||
if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_INDEXEDFACESET )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2COORDS::AddRefNode( WRL2NODE* aNode )
|
||||
{
|
||||
// this node may not own or reference any other node
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] AddRefNode is not applicable\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2COORDS::AddChildNode( WRL2NODE* aNode )
|
||||
{
|
||||
// this node may not own or reference any other node
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] AddChildNode is not applicable\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2COORDS::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '{' != tok )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
|
||||
std::cerr << "' at line " << line << ", column " << column << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.Pop();
|
||||
std::string glob;
|
||||
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
// expecting 'point'
|
||||
if( !glob.compare( "point" ) )
|
||||
{
|
||||
if( !proc.ReadMFVec3f( points ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid point set at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Coordinate at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Coordinate at line " << line << ", column ";
|
||||
std::cerr << column << " (no closing brace)\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file vrml2_coords.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VRML2_COORDS_H
|
||||
#define VRML2_COORDS_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "vrml2_node.h"
|
||||
|
||||
class WRL2BASE;
|
||||
|
||||
/**
|
||||
* Class WRL2COORDS
|
||||
*/
|
||||
class WRL2COORDS : public WRL2NODE
|
||||
{
|
||||
private:
|
||||
std::vector< WRLVEC3F > points;
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
WRL2COORDS();
|
||||
WRL2COORDS( WRL2NODE* aParent );
|
||||
virtual ~WRL2COORDS();
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool Read( WRLPROC& proc, WRL2BASE* aTopNode );
|
||||
bool AddRefNode( WRL2NODE* aNode );
|
||||
bool AddChildNode( WRL2NODE* aNode );
|
||||
};
|
||||
|
||||
#endif // VRML2_COORDS_H
|
|
@ -0,0 +1,560 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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_faceset.h"
|
||||
|
||||
|
||||
|
||||
WRL2FACESET::WRL2FACESET() : WRL2NODE()
|
||||
{
|
||||
setDefaults();
|
||||
m_Type = WRL2_INDEXEDFACESET;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2FACESET::WRL2FACESET( WRL2NODE* aParent ) : WRL2NODE()
|
||||
{
|
||||
setDefaults();
|
||||
m_Type = WRL2_INDEXEDFACESET;
|
||||
m_Parent = aParent;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
m_Parent->AddChildNode( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2FACESET::~WRL2FACESET()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] Destroying IndexedFaceSet with " << m_Children.size();
|
||||
std::cerr << " children, " << m_Refs.size() << " references and ";
|
||||
std::cerr << m_BackPointers.size() << " backpointers\n";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void WRL2FACESET::setDefaults( void )
|
||||
{
|
||||
color = NULL;
|
||||
coord = NULL;
|
||||
normal = NULL;
|
||||
texCoord = NULL;
|
||||
|
||||
ccw = true;
|
||||
colorPerVertex = true;
|
||||
convex = true;
|
||||
normalPerVertex = true;
|
||||
solid = true;
|
||||
|
||||
creaseAngle = 0.0;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2FACESET::checkNodeType( WRL2NODES aType )
|
||||
{
|
||||
// nodes must be one of:
|
||||
// Color
|
||||
// Coordinate
|
||||
// Normal
|
||||
// TextureCoordinate
|
||||
|
||||
switch( aType )
|
||||
{
|
||||
case WRL2_COLOR:
|
||||
case WRL2_COORDINATE:
|
||||
case WRL2_NORMAL:
|
||||
case WRL2_TEXTURECOORDINATE:
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2FACESET::isDangling( void )
|
||||
{
|
||||
// this node is dangling unless it has a parent of type WRL2_SHAPE
|
||||
|
||||
if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_SHAPE )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2FACESET::AddRefNode( WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] NULL passed for aNode\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
WRL2NODES type = aNode->GetNodeType();
|
||||
|
||||
if( !checkNodeType( type ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected child node '";
|
||||
std::cerr << aNode->GetNodeTypeName( type ) << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( WRL2_COLOR == type )
|
||||
{
|
||||
if( NULL != color )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple color nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
color = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
if( WRL2_COORDINATE == type )
|
||||
{
|
||||
if( NULL != coord )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple coordinate nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
coord = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
if( WRL2_NORMAL == type )
|
||||
{
|
||||
if( NULL != normal )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple normal nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
normal = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
if( WRL2_TEXTURECOORDINATE != type )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] unexpected code branch\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != texCoord )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple texCoord nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
texCoord = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
|
||||
bool WRL2FACESET::AddChildNode( WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] NULL passed for aNode\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
WRL2NODES type = aNode->GetNodeType();
|
||||
|
||||
if( !checkNodeType( type ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected child node '";
|
||||
std::cerr << aNode->GetNodeTypeName( type ) << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( WRL2_COLOR == type )
|
||||
{
|
||||
if( NULL != color )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple color nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
color = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
if( WRL2_COORDINATE == type )
|
||||
{
|
||||
if( NULL != coord )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple coordinate nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
coord = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
if( WRL2_NORMAL == type )
|
||||
{
|
||||
if( NULL != normal )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple normal nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
normal = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
if( WRL2_TEXTURECOORDINATE != type )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] unexpected code branch\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( NULL != texCoord )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple texCoord nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
texCoord = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool WRL2FACESET::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '{' != tok )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
|
||||
std::cerr << "' at line " << line << ", column " << column << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.Pop();
|
||||
std::string glob;
|
||||
|
||||
while( true )
|
||||
{
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
break;
|
||||
}
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// expecting one of:
|
||||
// [node]
|
||||
// color
|
||||
// coord
|
||||
// normal
|
||||
// texCoord
|
||||
// [bool]
|
||||
// ccw
|
||||
// colorPerVertex
|
||||
// convex
|
||||
// normalPerVertex
|
||||
// solid
|
||||
// [ vector<int> ]
|
||||
// colorIndex
|
||||
// coordIndex
|
||||
// normalIndex;
|
||||
// [float]
|
||||
// creaseAngle
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
if( !glob.compare( "ccw" ) )
|
||||
{
|
||||
if( !proc.ReadSFBool( ccw ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid ccw at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "colorPerVertex" ) )
|
||||
{
|
||||
if( !proc.ReadSFBool( colorPerVertex ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid colorPerVertex at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "convex" ) )
|
||||
{
|
||||
if( !proc.ReadSFBool( convex ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid convex at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "normalPerVertex" ) )
|
||||
{
|
||||
if( !proc.ReadSFBool( normalPerVertex ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid normalPerVertex at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "solid" ) )
|
||||
{
|
||||
if( !proc.ReadSFBool( solid ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid solid at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "creaseAngle" ) )
|
||||
{
|
||||
if( !proc.ReadSFFloat( creaseAngle ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid creaseAngle at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "colorIndex" ) )
|
||||
{
|
||||
if( !proc.ReadMFInt( colorIndex ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid colorIndex at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "coordIndex" ) )
|
||||
{
|
||||
if( !proc.ReadMFInt( coordIndex ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid coordIndex at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "normalIndex" ) )
|
||||
{
|
||||
if( !proc.ReadMFInt( normalIndex ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid normalIndex at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "color" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read color node information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "coord" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read coord node information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "normal" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read normal node information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "texCoord" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read texCoord node information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad IndexedFaceSet at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
} // while( true ) -- reading contents of IndexedFaceSet{}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file vrml2_faceset.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VRML2_FACESET_H
|
||||
#define VRML2_FACESET_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "vrml2_node.h"
|
||||
|
||||
class WRL2BASE;
|
||||
|
||||
/**
|
||||
* Class WRL2FACESET
|
||||
*/
|
||||
class WRL2FACESET : public WRL2NODE
|
||||
{
|
||||
private:
|
||||
WRL2NODE* color;
|
||||
WRL2NODE* coord;
|
||||
WRL2NODE* normal;
|
||||
WRL2NODE* texCoord;
|
||||
|
||||
bool ccw;
|
||||
bool colorPerVertex;
|
||||
bool convex;
|
||||
bool normalPerVertex;
|
||||
bool solid;
|
||||
|
||||
std::vector< int > colorIndex;
|
||||
std::vector< int > coordIndex;
|
||||
std::vector< int > normalIndex;
|
||||
|
||||
float creaseAngle;
|
||||
|
||||
|
||||
/**
|
||||
* Function checkNodeType
|
||||
* returns true if the node type is a valid subnode of FaceSet
|
||||
*/
|
||||
bool checkNodeType( WRL2NODES aType );
|
||||
|
||||
void setDefaults( void );
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
WRL2FACESET();
|
||||
WRL2FACESET( WRL2NODE* aParent );
|
||||
virtual ~WRL2FACESET();
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool Read( WRLPROC& proc, WRL2BASE* aTopNode );
|
||||
bool AddRefNode( WRL2NODE* aNode );
|
||||
bool AddChildNode( WRL2NODE* aNode );
|
||||
};
|
||||
|
||||
#endif // VRML2_FACESET_H
|
|
@ -0,0 +1,287 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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_material.h"
|
||||
|
||||
|
||||
WRL2MATERIAL::WRL2MATERIAL() : WRL2NODE()
|
||||
{
|
||||
setDefaults();
|
||||
m_Type = WRL2_MATERIAL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2MATERIAL::WRL2MATERIAL( WRL2NODE* aParent ) : WRL2NODE()
|
||||
{
|
||||
setDefaults();
|
||||
m_Type = WRL2_MATERIAL;
|
||||
m_Parent = aParent;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
m_Parent->AddChildNode( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2MATERIAL::~WRL2MATERIAL()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] Destroying Material node\n";
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void WRL2MATERIAL::setDefaults( void )
|
||||
{
|
||||
// default material values as per VRML2 spec
|
||||
diffuseColor.x = 0.8;
|
||||
diffuseColor.y = 0.8;
|
||||
diffuseColor.z = 0.8;
|
||||
|
||||
emissiveColor.x = 0.0;
|
||||
emissiveColor.y = 0.0;
|
||||
emissiveColor.z = 0.0;
|
||||
|
||||
specularColor = emissiveColor;
|
||||
|
||||
ambientIntensity = 0.2;
|
||||
shininess = 0.2;
|
||||
transparency = 0.0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2MATERIAL::isDangling( void )
|
||||
{
|
||||
// this node is dangling unless it has a parent of type WRL2_APPEARANCE
|
||||
|
||||
if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_APPEARANCE )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2MATERIAL::AddRefNode( WRL2NODE* aNode )
|
||||
{
|
||||
// this node may not own or reference any other node
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] AddRefNode is not applicable\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2MATERIAL::AddChildNode( WRL2NODE* aNode )
|
||||
{
|
||||
// this node may not own or reference any other node
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] AddChildNode is not applicable\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2MATERIAL::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
if( NULL == aTopNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] aTopNode is NULL\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '{' != tok )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
|
||||
std::cerr << "' at line " << line << ", column " << column << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.Pop();
|
||||
std::string glob;
|
||||
|
||||
while( true )
|
||||
{
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
break;
|
||||
}
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// expecting one of:
|
||||
// ambientIntensity
|
||||
// diffuseColor
|
||||
// emissiveColor
|
||||
// shininess
|
||||
// specularColor
|
||||
// transparency
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
if( !glob.compare( "specularColor" ) )
|
||||
{
|
||||
if( !proc.ReadSFVec3f( specularColor ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid specularColor at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "diffuseColor" ) )
|
||||
{
|
||||
if( !proc.ReadSFVec3f( diffuseColor ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid diffuseColor at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "emissiveColor" ) )
|
||||
{
|
||||
if( !proc.ReadSFVec3f( emissiveColor ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid emissiveColor at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "shininess" ) )
|
||||
{
|
||||
if( !proc.ReadSFFloat( shininess ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid shininess at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "transparency" ) )
|
||||
{
|
||||
if( !proc.ReadSFFloat( transparency ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid transparency at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "ambientIntensity" ) )
|
||||
{
|
||||
if( !proc.ReadSFFloat( ambientIntensity ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid ambientIntensity at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Material at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
} // while( true ) -- reading contents of Material{}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file vrml2_material.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VRML2_MATERIAL_H
|
||||
#define VRML2_MATERIAL_H
|
||||
|
||||
#include "vrml2_node.h"
|
||||
|
||||
class WRL2BASE;
|
||||
|
||||
/**
|
||||
* Class WRL2MATERIAL
|
||||
*/
|
||||
class WRL2MATERIAL : public WRL2NODE
|
||||
{
|
||||
private:
|
||||
WRLVEC3F diffuseColor;
|
||||
WRLVEC3F emissiveColor;
|
||||
WRLVEC3F specularColor;
|
||||
float ambientIntensity;
|
||||
float shininess;
|
||||
float transparency;
|
||||
|
||||
void setDefaults( void );
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
WRL2MATERIAL();
|
||||
WRL2MATERIAL( WRL2NODE* aParent );
|
||||
virtual ~WRL2MATERIAL();
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool Read( WRLPROC& proc, WRL2BASE* aTopNode );
|
||||
bool AddRefNode( WRL2NODE* aNode );
|
||||
bool AddChildNode( WRL2NODE* aNode );
|
||||
};
|
||||
|
||||
#endif // VRML2_MATERIAL_H
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
||||
* Copyright (C) 2015-2016 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
|
||||
|
@ -31,7 +31,6 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include "vrml2_node.h"
|
||||
#include "vrml2_helpers.h"
|
||||
|
||||
|
||||
static std::set< std::string > badNames;
|
||||
|
@ -146,8 +145,8 @@ WRL2NODE::~WRL2NODE()
|
|||
|
||||
while( sC != eC )
|
||||
{
|
||||
(*sC)->SetParent( NULL );
|
||||
delete (*sC);
|
||||
(*sC)->SetParent( NULL, false );
|
||||
delete *sC;
|
||||
++sC;
|
||||
}
|
||||
|
||||
|
@ -158,6 +157,10 @@ WRL2NODE::~WRL2NODE()
|
|||
|
||||
void WRL2NODE::addNodeRef( WRL2NODE* aNode )
|
||||
{
|
||||
// the parent node must never be added as a backpointer
|
||||
if( aNode == m_Parent )
|
||||
return;
|
||||
|
||||
std::list< WRL2NODE* >::iterator np =
|
||||
std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
|
||||
|
||||
|
@ -239,7 +242,7 @@ bool WRL2NODE::SetName( const std::string& aName )
|
|||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid node name '" << *item;
|
||||
std::cerr << " * [INFO] invalid node name '" << aName;
|
||||
std::cerr<< "' (contains invalid character)\n";
|
||||
#endif
|
||||
return false;
|
||||
|
@ -253,11 +256,14 @@ bool WRL2NODE::SetName( const std::string& aName )
|
|||
|
||||
const char* WRL2NODE::GetNodeTypeName( WRL2NODES aNodeType ) const
|
||||
{
|
||||
if( aNodeType < WRL2_BEGIN || aNodeType >= WRL2_END )
|
||||
return NULL;
|
||||
if( aNodeType < WRL2_BASE || aNodeType >= WRL2_END )
|
||||
return "*INVALID_TYPE*";
|
||||
|
||||
if( aNodeType == WRL2_BASE )
|
||||
return "*VIRTUAL_BASE*";
|
||||
|
||||
NODEMAP::iterator it = nodenames.begin();
|
||||
advance( it, aNodeType );
|
||||
advance( it, (aNodeType - WRL2_BEGIN) );
|
||||
|
||||
return it->first.c_str();
|
||||
}
|
||||
|
@ -288,18 +294,37 @@ WRL2NODE* WRL2NODE::FindNode( const std::string& aNodeName, const WRL2NODE *aCal
|
|||
if( !m_Name.compare( aNodeName ) )
|
||||
return this;
|
||||
|
||||
FIND_NODE( aNodeName, m_Children, this );
|
||||
std::list< WRL2NODE* >::iterator sLA = m_Children.begin();
|
||||
std::list< WRL2NODE* >::iterator eLA = m_Children.end();
|
||||
|
||||
WRL2NODE* psg = NULL;
|
||||
|
||||
while( sLA != eLA )
|
||||
{
|
||||
if( *sLA != aCaller )
|
||||
{
|
||||
psg = (*sLA)->FindNode( aNodeName, this );
|
||||
|
||||
if( NULL != psg)
|
||||
return psg;
|
||||
|
||||
}
|
||||
++sLA;
|
||||
}
|
||||
|
||||
if( NULL != m_Parent && aCaller != m_Parent )
|
||||
return m_Parent->FindNode( aNodeName, this );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2NODE::SetParent( WRL2NODE* aParent )
|
||||
bool WRL2NODE::SetParent( WRL2NODE* aParent, bool doUnlink )
|
||||
{
|
||||
if( aParent == m_Parent )
|
||||
return true;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
if( NULL != m_Parent && doUnlink )
|
||||
m_Parent->unlinkChildNode( this );
|
||||
|
||||
m_Parent = aParent;
|
||||
|
@ -329,6 +354,8 @@ bool WRL2NODE::AddChildNode( WRL2NODE* aNode )
|
|||
{
|
||||
if( *sC == aNode )
|
||||
return false;
|
||||
|
||||
++sC;
|
||||
}
|
||||
|
||||
aNode->SetParent( this );
|
||||
|
@ -371,3 +398,43 @@ bool WRL2NODE::AddRefNode( WRL2NODE* aNode )
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void WRL2NODE::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 WRL2NODE::unlinkRefNode( const WRL2NODE* aNode )
|
||||
{
|
||||
std::list< WRL2NODE* >::iterator sL = m_Refs.begin();
|
||||
std::list< WRL2NODE* >::iterator eL = m_Refs.end();
|
||||
|
||||
while( sL != eL )
|
||||
{
|
||||
if( *sL == aNode )
|
||||
{
|
||||
m_Refs.erase( sL );
|
||||
return;
|
||||
}
|
||||
|
||||
++sL;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
||||
* Copyright (C) 2015-2016 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
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
*
|
||||
* @param aNode is the child which is being deleted
|
||||
*/
|
||||
virtual void unlinkChildNode( const WRL2NODE* aNode ) = 0;
|
||||
void unlinkChildNode( const WRL2NODE* aNode );
|
||||
|
||||
/**
|
||||
* Function unlinkRef
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
*
|
||||
* @param aNode is the node which is being deleted
|
||||
*/
|
||||
virtual void unlinkRefNode( const WRL2NODE* aNode ) = 0;
|
||||
void unlinkRefNode( const WRL2NODE* aNode );
|
||||
|
||||
/**
|
||||
* Function addNodeRef
|
||||
|
@ -145,11 +145,12 @@ public:
|
|||
* sets the parent WRL2NODE of this object.
|
||||
*
|
||||
* @param aParent [in] is the desired parent node
|
||||
* @param doUnlink indicates that the child must be unlinked from the parent
|
||||
* @return true if the operation succeeds; false if
|
||||
* the given node is not allowed to be a parent to
|
||||
* the derived object.
|
||||
*/
|
||||
virtual bool SetParent( WRL2NODE* aParent );
|
||||
virtual bool SetParent( WRL2NODE* aParent, bool doUnlink = true );
|
||||
|
||||
virtual std::string GetName( void );
|
||||
virtual bool SetName( const std::string& aName );
|
||||
|
@ -167,7 +168,7 @@ public:
|
|||
*/
|
||||
virtual WRL2NODE* FindNode( const std::string& aNodeName, const WRL2NODE *aCaller );
|
||||
|
||||
bool AddChildNode( WRL2NODE* aNode );
|
||||
virtual bool AddChildNode( WRL2NODE* aNode );
|
||||
|
||||
virtual bool AddRefNode( WRL2NODE* aNode );
|
||||
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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_norms.h"
|
||||
|
||||
|
||||
WRL2NORMS::WRL2NORMS() : WRL2NODE()
|
||||
{
|
||||
m_Type = WRL2_NORMAL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2NORMS::WRL2NORMS( WRL2NODE* aParent ) : WRL2NODE()
|
||||
{
|
||||
m_Type = WRL2_NORMAL;
|
||||
m_Parent = aParent;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
m_Parent->AddChildNode( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2NORMS::~WRL2NORMS()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] Destroying Normal node\n";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2NORMS::isDangling( void )
|
||||
{
|
||||
// this node is dangling unless it has a parent of type WRL2_INDEXEDFACESET
|
||||
|
||||
if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_INDEXEDFACESET )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2NORMS::AddRefNode( WRL2NODE* aNode )
|
||||
{
|
||||
// this node may not own or reference any other node
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] AddRefNode is not applicable\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2NORMS::AddChildNode( WRL2NODE* aNode )
|
||||
{
|
||||
// this node may not own or reference any other node
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] AddChildNode is not applicable\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2NORMS::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '{' != tok )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
|
||||
std::cerr << "' at line " << line << ", column " << column << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.Pop();
|
||||
std::string glob;
|
||||
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
// expecting 'vector'
|
||||
if( !glob.compare( "vector" ) )
|
||||
{
|
||||
if( !proc.ReadMFVec3f( vectors ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid vector set at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Normal at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Normal at line " << line << ", column ";
|
||||
std::cerr << column << " (no closing brace)\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file vrml2_norms.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VRML2_NORMS_H
|
||||
#define VRML2_NORMS_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "vrml2_node.h"
|
||||
|
||||
class WRL2BASE;
|
||||
|
||||
/**
|
||||
* Class WRL2NORMS
|
||||
*/
|
||||
class WRL2NORMS : public WRL2NODE
|
||||
{
|
||||
private:
|
||||
std::vector< WRLVEC3F > vectors;
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
WRL2NORMS();
|
||||
WRL2NORMS( WRL2NODE* aParent );
|
||||
virtual ~WRL2NORMS();
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool Read( WRLPROC& proc, WRL2BASE* aTopNode );
|
||||
bool AddRefNode( WRL2NODE* aNode );
|
||||
bool AddChildNode( WRL2NODE* aNode );
|
||||
};
|
||||
|
||||
#endif // VRML2_NORMS_H
|
|
@ -0,0 +1,311 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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_shape.h"
|
||||
|
||||
|
||||
WRL2SHAPE::WRL2SHAPE() : WRL2NODE()
|
||||
{
|
||||
appearance = NULL;
|
||||
geometry = NULL;
|
||||
m_Type = WRL2_SHAPE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2SHAPE::WRL2SHAPE( WRL2NODE* aParent ) : WRL2NODE()
|
||||
{
|
||||
appearance = NULL;
|
||||
geometry = NULL;
|
||||
m_Type = WRL2_SHAPE;
|
||||
m_Parent = aParent;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
m_Parent->AddChildNode( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2SHAPE::~WRL2SHAPE()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] Destroying Shape with " << m_Children.size();
|
||||
std::cerr << " children, " << m_Refs.size() << " references and ";
|
||||
std::cerr << m_BackPointers.size() << " backpointers\n";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2SHAPE::isDangling( void )
|
||||
{
|
||||
// this node is dangling unless it has a parent of type WRL2_TRANSFORM
|
||||
|
||||
if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_TRANSFORM )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2SHAPE::AddRefNode( WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] NULL passed for aNode\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
WRL2NODES type = aNode->GetNodeType();
|
||||
|
||||
if( !checkNodeType( type ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected child node '";
|
||||
std::cerr << aNode->GetNodeTypeName( type ) << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( WRL2_APPEARANCE == type )
|
||||
{
|
||||
if( NULL != appearance )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple appearance nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
appearance = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
if( NULL != geometry )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple geometry nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
geometry = aNode;
|
||||
return WRL2NODE::AddRefNode( aNode );
|
||||
}
|
||||
|
||||
|
||||
bool WRL2SHAPE::AddChildNode( WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] NULL passed for aNode\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
WRL2NODES type = aNode->GetNodeType();
|
||||
|
||||
if( !checkNodeType( type ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected child node '";
|
||||
std::cerr << aNode->GetNodeTypeName( type ) << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if( WRL2_APPEARANCE == type )
|
||||
{
|
||||
if( NULL != appearance )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple appearance nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
appearance = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
if( NULL != geometry )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; multiple geometry nodes\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
geometry = aNode;
|
||||
return WRL2NODE::AddChildNode( aNode );
|
||||
}
|
||||
|
||||
|
||||
bool WRL2SHAPE::checkNodeType( WRL2NODES aType )
|
||||
{
|
||||
switch( aType )
|
||||
{
|
||||
case WRL2_APPEARANCE:
|
||||
case WRL2_BOX:
|
||||
case WRL2_CONE:
|
||||
case WRL2_CYLINDER:
|
||||
case WRL2_ELEVATIONGRID:
|
||||
case WRL2_EXTRUSION:
|
||||
case WRL2_INDEXEDFACESET:
|
||||
case WRL2_INDEXEDLINESET:
|
||||
case WRL2_POINTSET:
|
||||
case WRL2_SPHERE:
|
||||
case WRL2_TEXT:
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2SHAPE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
if( NULL == aTopNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] aTopNode is NULL\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '{' != tok )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; expecting '{' but got '" << tok;
|
||||
std::cerr << "' at line " << line << ", column " << column << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
proc.Pop();
|
||||
std::string glob;
|
||||
|
||||
while( true )
|
||||
{
|
||||
if( proc.Peek() == '}' )
|
||||
{
|
||||
proc.Pop();
|
||||
break;
|
||||
}
|
||||
|
||||
if( !proc.ReadName( glob ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << proc.GetError() << "\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// expecting one of:
|
||||
// appearance
|
||||
// geometry
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
if( !glob.compare( "appearance" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read appearance information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "geometry" ) )
|
||||
{
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] could not read geometry information\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad Shape at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
} // while( true ) -- reading contents of Shape{}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file vrml2_shape.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VRML2_SHAPE_H
|
||||
#define VRML2_SHAPE_H
|
||||
|
||||
#include "vrml2_node.h"
|
||||
|
||||
class WRL2BASE;
|
||||
|
||||
/**
|
||||
* Class WRL2SHAPE
|
||||
*/
|
||||
class WRL2SHAPE : public WRL2NODE
|
||||
{
|
||||
private:
|
||||
WRL2NODE* appearance;
|
||||
WRL2NODE* geometry;
|
||||
|
||||
/**
|
||||
* Function checkNodeType
|
||||
* returns true if the node type is an appearance or geometry class
|
||||
*/
|
||||
bool checkNodeType( WRL2NODES aType );
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
WRL2SHAPE();
|
||||
WRL2SHAPE( WRL2NODE* aParent );
|
||||
virtual ~WRL2SHAPE();
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
bool Read( WRLPROC& proc, WRL2BASE* aTopNode );
|
||||
bool AddRefNode( WRL2NODE* aNode );
|
||||
bool AddChildNode( WRL2NODE* aNode );
|
||||
};
|
||||
|
||||
#endif // VRML2_SHAPE_H
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
||||
* Copyright (C) 2015-2016 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
|
||||
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include "vrml2_base.h"
|
||||
#include "vrml2_transform.h"
|
||||
|
||||
|
||||
|
@ -37,30 +38,28 @@ WRL2TRANSFORM::WRL2TRANSFORM( WRL2NODE* aParent ) : WRL2NODE()
|
|||
{
|
||||
m_Type = WRL2_TRANSFORM;
|
||||
m_Parent = aParent;
|
||||
|
||||
if( NULL != m_Parent )
|
||||
m_Parent->AddChildNode( this );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WRL2TRANSFORM::~WRL2TRANSFORM()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << " * [INFO] Destroying Transform with " << m_Children.size();
|
||||
std::cerr << " children, " << m_Refs.size() << " references and ";
|
||||
std::cerr << m_BackPointers.size() << " backpointers\n";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void WRL2TRANSFORM::unlinkChildNode( const WRL2NODE* aNode )
|
||||
{
|
||||
// XXX - TO BE IMPLEMENTED
|
||||
}
|
||||
|
||||
void WRL2TRANSFORM::unlinkRefNode( const WRL2NODE* aNode )
|
||||
{
|
||||
// XXX - TO BE IMPLEMENTED
|
||||
}
|
||||
|
||||
|
||||
bool WRL2TRANSFORM::isDangling( void )
|
||||
{
|
||||
// XXX - TO BE IMPLEMENTED
|
||||
// a Transform node is never dangling
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -85,6 +84,15 @@ bool WRL2TRANSFORM::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
|||
* }
|
||||
*/
|
||||
|
||||
if( NULL == aTopNode )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [BUG] aTopNode is NULL\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
center.x = 0.0;
|
||||
center.y = 0.0;
|
||||
center.z = 0.0;
|
||||
|
@ -104,16 +112,20 @@ bool WRL2TRANSFORM::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
|||
scale.y = 1.0;
|
||||
scale.z = 1.0;
|
||||
|
||||
// XXX - TO BE IMPLEMENTED
|
||||
// XXX - at the moment this is half-assed code; it needs to be checked and expanded
|
||||
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( '\0' != tok )
|
||||
proc.GetFilePosData( line, column );
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '{' != tok )
|
||||
{
|
||||
|
@ -156,29 +168,82 @@ bool WRL2TRANSFORM::Read( WRLPROC& proc, WRL2BASE* aTopNode )
|
|||
// ScaleOrientation
|
||||
// translation
|
||||
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
if( !glob.compare( "center" ) )
|
||||
{
|
||||
// XXX -
|
||||
if( !proc.ReadSFVec3f( center ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid center at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "rotation" ) )
|
||||
{
|
||||
// XXX -
|
||||
if( !proc.ReadSFRotation( rotation ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid rotation at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "scale" ) )
|
||||
{
|
||||
// XXX -
|
||||
if( !proc.ReadSFVec3f( scale ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid scale at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "scaleOrientation" ) )
|
||||
{
|
||||
// XXX -
|
||||
if( !proc.ReadSFRotation( scaleOrientation ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid scaleOrientation at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "translation" ) )
|
||||
{
|
||||
// XXX -
|
||||
if( !proc.ReadSFVec3f( translation ) )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] invalid translation at line " << line << ", column ";
|
||||
std::cerr << column << "\n";
|
||||
std::cerr << " * [INFO] file: '" << proc.GetFileName() << "'\n";
|
||||
std::cerr << " * [INFO] message: '" << proc.GetError() << "'\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( !glob.compare( "children" ) )
|
||||
{
|
||||
// XXX -
|
||||
if( !readChildren( proc, aTopNode ) )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -223,3 +288,48 @@ bool WRL2TRANSFORM::AddRefNode( WRL2NODE* aNode )
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WRL2TRANSFORM::readChildren( WRLPROC& proc, WRL2BASE* aTopNode )
|
||||
{
|
||||
size_t line, column;
|
||||
proc.GetFilePosData( line, column );
|
||||
|
||||
char tok = proc.Peek();
|
||||
|
||||
if( proc.eof() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
std::cerr << " * [INFO] bad file format; unexpected eof at line ";
|
||||
std::cerr << line << ", column " << column << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if( '[' != tok )
|
||||
{
|
||||
// since there are no delimeters we expect a single child
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
proc.Pop();
|
||||
std::string glob;
|
||||
|
||||
while( true )
|
||||
{
|
||||
if( proc.Peek() == ']' )
|
||||
{
|
||||
proc.Pop();
|
||||
break;
|
||||
}
|
||||
|
||||
if( !aTopNode->ReadNode( proc, this, NULL ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
||||
* Copyright (C) 2015-2016 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
|
||||
|
@ -29,10 +29,9 @@
|
|||
#ifndef VRML2_TRANSFORM_H
|
||||
#define VRML2_TRANSFORM_H
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "vrml2_node.h"
|
||||
|
||||
#include "vrml2_base.h"
|
||||
class WRL2BASE;
|
||||
|
||||
/**
|
||||
* Class WRL2TRANSFORM
|
||||
|
@ -48,11 +47,11 @@ private:
|
|||
WRLVEC3F bboxCenter;
|
||||
WRLVEC3F bboxSize;
|
||||
|
||||
bool readChildren( WRLPROC& proc, WRL2BASE* aTopNode );
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
void unlinkChildNode( const WRL2NODE* aNode );
|
||||
void unlinkRefNode( const WRL2NODE* aNode );
|
||||
bool isDangling( void );
|
||||
|
||||
public:
|
||||
|
|
|
@ -2215,7 +2215,7 @@ char WRLPROC::Peek( void )
|
|||
m_error = ostr.str();
|
||||
}
|
||||
|
||||
return false;
|
||||
return '\0';
|
||||
}
|
||||
|
||||
return m_buf[m_linepos];
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
||||
* Copyright (C) 2015-2016 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
|
||||
|
|
Loading…
Reference in New Issue