2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-08-21 10:45:54 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras@wanadoo.fr
|
2011-11-10 15:55:05 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-05-22 19:08:34 +00:00
|
|
|
/**
|
|
|
|
* @file 3d_read_mesh.cpp
|
2011-11-10 15:55:05 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <appl_wxstruct.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <3d_viewer.h>
|
2012-08-26 13:59:55 +00:00
|
|
|
#include <info3d_visu.h>
|
2013-03-27 18:34:23 +00:00
|
|
|
#include "3d_struct.h"
|
|
|
|
#include "modelparsers.h"
|
2012-08-26 13:59:55 +00:00
|
|
|
|
|
|
|
// Imported function:
|
|
|
|
extern void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-03-28 16:51:22 +00:00
|
|
|
|
|
|
|
S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster,
|
|
|
|
const wxString aExtension )
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
|
|
|
if ( aExtension == wxT( "x3d" ) )
|
|
|
|
{
|
2013-03-28 16:51:22 +00:00
|
|
|
return new X3D_MODEL_PARSER( aMaster );
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
|
|
|
else if ( aExtension == wxT( "wrl" ) )
|
|
|
|
{
|
2013-03-28 16:51:22 +00:00
|
|
|
return new VRML_MODEL_PARSER( aMaster );
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
int S3D_MASTER::ReadData()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2009-04-21 17:56:27 +00:00
|
|
|
wxString FullFilename;
|
2008-01-01 07:53:29 +00:00
|
|
|
|
|
|
|
if( m_Shape3DName.IsEmpty() )
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-12-27 18:08:50 +00:00
|
|
|
wxString shape3DNname = m_Shape3DName;
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2011-12-27 18:08:50 +00:00
|
|
|
#ifdef __WINDOWS__
|
2013-03-28 16:51:22 +00:00
|
|
|
shape3DNname.Replace( wxT( "/" ), wxT( "\\" ) );
|
2011-12-27 18:08:50 +00:00
|
|
|
#else
|
2013-03-28 16:51:22 +00:00
|
|
|
shape3DNname.Replace( wxT( "\\" ), wxT( "/" ) );
|
2011-12-27 18:08:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if( wxFileName::FileExists( shape3DNname ) )
|
2011-09-17 15:31:21 +00:00
|
|
|
{
|
2011-12-27 18:08:50 +00:00
|
|
|
FullFilename = shape3DNname;
|
2013-03-28 16:51:22 +00:00
|
|
|
fn.Assign( FullFilename );
|
2011-09-17 15:31:21 +00:00
|
|
|
}
|
2009-04-21 17:56:27 +00:00
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-12-27 18:08:50 +00:00
|
|
|
fn = shape3DNname;
|
2009-04-21 17:56:27 +00:00
|
|
|
FullFilename = wxGetApp().FindLibraryPath( fn );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-21 17:56:27 +00:00
|
|
|
if( FullFilename.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-02 13:06:55 +00:00
|
|
|
wxLogDebug( wxT( "3D part library <%s> could not be found." ),
|
2011-11-10 15:55:05 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-27 18:34:23 +00:00
|
|
|
wxString extension = fn.GetExt();
|
2013-03-28 16:51:22 +00:00
|
|
|
S3D_MODEL_PARSER* parser = S3D_MODEL_PARSER::Create( this, extension );
|
|
|
|
|
|
|
|
if( parser )
|
2008-01-01 07:53:29 +00:00
|
|
|
{
|
2013-03-28 16:51:22 +00:00
|
|
|
parser->Load( FullFilename );
|
2013-03-27 18:34:23 +00:00
|
|
|
delete parser;
|
2008-01-01 07:53:29 +00:00
|
|
|
return 0;
|
2013-03-28 16:51:22 +00:00
|
|
|
}
|
|
|
|
else
|
2008-01-01 07:53:29 +00:00
|
|
|
{
|
2013-03-27 18:34:23 +00:00
|
|
|
wxLogDebug( wxT( "Unknown file type <%s>" ), GetChars( extension ) );
|
2008-01-01 07:53:29 +00:00
|
|
|
}
|
2011-09-17 15:31:21 +00:00
|
|
|
|
2008-01-01 07:53:29 +00:00
|
|
|
return -1;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
int STRUCT_3D_SHAPE::ReadData( FILE* file, int* LineNum )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-01-01 07:53:29 +00:00
|
|
|
char line[512];
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-01-01 07:53:29 +00:00
|
|
|
while( GetLine( file, line, LineNum, 512 ) )
|
|
|
|
{
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-01-01 07:53:29 +00:00
|
|
|
return -1;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|