2012-08-21 10:45:54 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-21 00:41:10 +00:00
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-08-21 10:45:54 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
/**
|
|
|
|
* @file 3d_class.cpp
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
#include "3d_viewer.h"
|
|
|
|
#include "3d_struct.h"
|
|
|
|
#include "modelparsers.h"
|
2014-03-09 18:43:53 +00:00
|
|
|
|
2014-03-05 17:40:23 +00:00
|
|
|
|
|
|
|
void S3D_MASTER::Insert( S3D_MATERIAL* aMaterial )
|
|
|
|
{
|
|
|
|
aMaterial->SetNext( m_Materials );
|
|
|
|
m_Materials = aMaterial;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
void S3D_MASTER::Copy( S3D_MASTER* pattern )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-01-25 12:23:29 +00:00
|
|
|
SetShape3DName( pattern->GetShape3DName() );
|
2008-11-24 06:53:43 +00:00
|
|
|
m_MatScale = pattern->m_MatScale;
|
|
|
|
m_MatRotation = pattern->m_MatRotation;
|
|
|
|
m_MatPosition = pattern->m_MatPosition;
|
|
|
|
m_3D_Drawings = NULL;
|
|
|
|
m_Materials = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) :
|
|
|
|
EDA_ITEM( aParent, NOT_USED )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
m_MatScale.x = m_MatScale.y = m_MatScale.z = 1.0;
|
2015-03-13 19:27:25 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
m_3D_Drawings = NULL;
|
|
|
|
m_Materials = NULL;
|
2015-03-13 19:27:25 +00:00
|
|
|
m_parser = NULL;
|
2014-01-25 12:23:29 +00:00
|
|
|
m_ShapeType = FILE3D_NONE;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
m_use_modelfile_diffuseColor = true;
|
2014-08-09 18:18:04 +00:00
|
|
|
m_use_modelfile_emissiveColor = true;
|
|
|
|
m_use_modelfile_specularColor = true;
|
|
|
|
m_use_modelfile_ambientIntensity = true;
|
2014-07-30 09:01:25 +00:00
|
|
|
m_use_modelfile_transparency = true;
|
2014-08-09 18:18:04 +00:00
|
|
|
m_use_modelfile_shininess = true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
S3D_MASTER:: ~S3D_MASTER()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-08-21 10:45:54 +00:00
|
|
|
STRUCT_3D_SHAPE* next;
|
2008-12-06 08:21:54 +00:00
|
|
|
S3D_MATERIAL* nextmat;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
for( ; m_3D_Drawings != NULL; m_3D_Drawings = next )
|
|
|
|
{
|
|
|
|
next = m_3D_Drawings->Next();
|
|
|
|
delete m_3D_Drawings;
|
2015-03-28 11:33:56 +00:00
|
|
|
m_3D_Drawings = 0;
|
2008-11-24 06:53:43 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
for( ; m_Materials != NULL; m_Materials = nextmat )
|
2008-11-24 06:53:43 +00:00
|
|
|
{
|
|
|
|
nextmat = m_Materials->Next();
|
|
|
|
delete m_Materials;
|
2015-03-28 11:33:56 +00:00
|
|
|
m_Materials = 0;
|
2008-11-24 06:53:43 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-25 12:23:29 +00:00
|
|
|
bool S3D_MASTER::Is3DType( enum FILE3D_TYPE aShapeType )
|
|
|
|
{
|
|
|
|
// type 'none' is not valid and will always return false
|
|
|
|
if( aShapeType == FILE3D_NONE )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// no one is interested if we have no file
|
|
|
|
if( m_Shape3DName.empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aShapeType == m_ShapeType )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void S3D_MASTER::SetShape3DName( const wxString& aShapeName )
|
|
|
|
{
|
|
|
|
m_ShapeType = FILE3D_NONE;
|
|
|
|
m_Shape3DName = aShapeName;
|
|
|
|
|
|
|
|
if( m_Shape3DName.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxFileName fn = m_Shape3DName;
|
2015-03-28 11:33:56 +00:00
|
|
|
m_Shape3DNameExtension = fn.GetExt();
|
2014-01-25 12:23:29 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
if( m_Shape3DNameExtension == wxT( "wrl" ) ||
|
|
|
|
m_Shape3DNameExtension == wxT( "x3d" ) )
|
2014-01-25 12:23:29 +00:00
|
|
|
m_ShapeType = FILE3D_VRML;
|
2015-03-28 11:33:56 +00:00
|
|
|
else if( m_Shape3DNameExtension == wxT( "idf" ) )
|
2014-01-25 12:23:29 +00:00
|
|
|
m_ShapeType = FILE3D_IDF;
|
|
|
|
else
|
|
|
|
m_ShapeType = FILE3D_UNKNOWN;
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Expand any environment variables embedded in footprint's m_Shape3DName field.
|
|
|
|
// To ensure compatibility with most of footprint's m_Shape3DName field,
|
|
|
|
// if the m_Shape3DName is not an absolute path the default path
|
|
|
|
// given by the environment variable KISYS3DMOD will be used
|
|
|
|
|
|
|
|
if( m_Shape3DName.StartsWith( wxT("${") ) )
|
|
|
|
m_Shape3DFullFilename = wxExpandEnvVars( m_Shape3DName );
|
|
|
|
else
|
|
|
|
m_Shape3DFullFilename = m_Shape3DName;
|
|
|
|
|
|
|
|
wxFileName fnFull( m_Shape3DFullFilename );
|
|
|
|
|
|
|
|
if( !( fnFull.IsAbsolute() || m_Shape3DFullFilename.StartsWith( wxT(".") ) ) )
|
|
|
|
{
|
|
|
|
wxString default_path;
|
|
|
|
wxGetEnv( KISYS3DMOD, &default_path );
|
|
|
|
|
|
|
|
if( !( default_path.IsEmpty() ) )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !default_path.EndsWith( wxT("/") ) && !default_path.EndsWith( wxT("\\") ) )
|
|
|
|
default_path += wxT("/");
|
|
|
|
|
|
|
|
m_Shape3DFullFilename = default_path + m_Shape3DFullFilename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-25 12:23:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
const wxString S3D_MASTER::GetShape3DFullFilename()
|
|
|
|
{
|
|
|
|
return m_Shape3DFullFilename;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString S3D_MASTER::GetShape3DExtension()
|
|
|
|
{
|
|
|
|
return m_Shape3DNameExtension;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
STRUCT_3D_SHAPE::STRUCT_3D_SHAPE( EDA_ITEM* aParent ) :
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( aParent, NOT_USED )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
m_3D_Coord = NULL;
|
2008-11-24 06:53:43 +00:00
|
|
|
m_3D_CoordIndex = NULL;
|
|
|
|
m_3D_Points = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
STRUCT_3D_SHAPE:: ~STRUCT_3D_SHAPE()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
delete m_3D_Coord;
|
|
|
|
delete m_3D_CoordIndex;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|