2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2014-07-30 09:01:25 +00:00
|
|
|
* Copyright (C) 2014 Mario Luzeiro <mrluzeiro@gmail.com>
|
2014-08-09 18:18:04 +00:00
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jp.charras at 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-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file 3d_struct.h
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#ifndef STRUCT_3D_H
|
|
|
|
#define STRUCT_3D_H
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <base_struct.h>
|
2014-07-30 09:01:25 +00:00
|
|
|
#include <3d_material.h>
|
|
|
|
#include <gal/opengl/glm/glm.hpp>
|
2014-08-09 18:18:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @note For historical reasons the 3D modeling unit is 0.1 inch
|
|
|
|
* 1 3Dunit = 2.54 mm = 0.1 inch = 100 mils
|
2009-11-04 20:46:53 +00:00
|
|
|
*/
|
2012-05-11 09:02:35 +00:00
|
|
|
#define UNITS3D_TO_UNITSPCB (IU_PER_MILS * 100)
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-02-17 16:32:47 +00:00
|
|
|
/**
|
|
|
|
* scaling factor for 3D shape offset ( S3D_MASTER::m_MatPosition member )
|
|
|
|
* Was in inches in legacy version, and, due to a mistake, still in inches
|
|
|
|
* in .kicad_pcb files (which are using mm)
|
|
|
|
* so this scaling convert file units (inch) to 3D units (0.1 inch), only
|
|
|
|
* for S3D_MASTER::m_MatPosition parameter
|
|
|
|
*/
|
|
|
|
#define SCALE_3D_CONV 10
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
class S3D_MASTER;
|
2012-08-21 10:45:54 +00:00
|
|
|
class STRUCT_3D_SHAPE;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-08-09 18:18:04 +00:00
|
|
|
// S3D_VERTEX manages a opengl 3D coordinate (3 float numbers: x,y,z coordinates)
|
|
|
|
// float are widely used in opengl functions.
|
|
|
|
// they are used here in coordinates which are also used in opengl functions.
|
2014-07-30 09:01:25 +00:00
|
|
|
#define S3D_VERTEX glm::vec3
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-08-09 18:18:04 +00:00
|
|
|
// S3DPOINT manages a set of 3 double values (x,y,z )
|
|
|
|
// It is used for values which are not directly used in opengl functions.
|
|
|
|
// It is used in dialogs, or when reading/writing files for instance
|
|
|
|
class S3DPOINT
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
double x, y, z;
|
|
|
|
|
|
|
|
public:
|
|
|
|
S3DPOINT()
|
|
|
|
{
|
|
|
|
x = y = z = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
S3DPOINT( double px, double py, double pz)
|
|
|
|
{
|
|
|
|
x = px;
|
|
|
|
y = py;
|
|
|
|
z = pz;
|
|
|
|
}
|
|
|
|
};
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2014-08-09 18:18:04 +00:00
|
|
|
// Master structure for a 3D footprint shape description
|
2010-12-08 20:12:46 +00:00
|
|
|
class S3D_MASTER : public EDA_ITEM
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-08-09 18:18:04 +00:00
|
|
|
S3DPOINT m_MatScale; ///< a scaling factor for the entire 3D footprint shape
|
|
|
|
S3DPOINT m_MatRotation; ///< a grotation for the entire 3D footprint shape
|
|
|
|
S3DPOINT m_MatPosition; ///< an offset for the entire 3D footprint shape
|
|
|
|
STRUCT_3D_SHAPE* m_3D_Drawings; ///< the list of basic shapes
|
|
|
|
S3D_MATERIAL* m_Materials; ///< the list of materiels used by the shapes
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-01-25 12:23:29 +00:00
|
|
|
enum FILE3D_TYPE
|
|
|
|
{
|
|
|
|
FILE3D_NONE = 0,
|
|
|
|
FILE3D_VRML,
|
|
|
|
FILE3D_IDF,
|
|
|
|
FILE3D_UNKNOWN
|
|
|
|
};
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
// Check defaults in S3D_MASTER
|
|
|
|
bool m_use_modelfile_diffuseColor;
|
|
|
|
bool m_use_modelfile_emissiveColor;
|
|
|
|
bool m_use_modelfile_specularColor;
|
|
|
|
bool m_use_modelfile_ambientIntensity;
|
|
|
|
bool m_use_modelfile_transparency;
|
|
|
|
bool m_use_modelfile_shininess;
|
|
|
|
|
2014-01-25 12:23:29 +00:00
|
|
|
private:
|
2014-08-09 18:18:04 +00:00
|
|
|
wxString m_Shape3DName; // the 3D shape filename in 3D library
|
2014-01-25 12:23:29 +00:00
|
|
|
FILE3D_TYPE m_ShapeType;
|
2014-08-09 18:18:04 +00:00
|
|
|
double m_lastTransparency; // last transparency value from
|
2014-03-09 18:43:53 +00:00
|
|
|
// last material in use
|
|
|
|
bool m_loadTransparentObjects;
|
|
|
|
bool m_loadNonTransparentObjects;
|
2014-01-25 12:23:29 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
public:
|
|
|
|
S3D_MASTER( EDA_ITEM* aParent );
|
2008-12-06 08:21:54 +00:00
|
|
|
~S3D_MASTER();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
S3D_MASTER* Next() const { return (S3D_MASTER*) Pnext; }
|
|
|
|
S3D_MASTER* Back() const { return (S3D_MASTER*) Pback; }
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2014-03-09 18:43:53 +00:00
|
|
|
// Accessors
|
|
|
|
void SetLastTransparency( double aValue ) { m_lastTransparency = aValue; }
|
|
|
|
|
|
|
|
void SetLoadTransparentObjects( bool aLoad )
|
|
|
|
{ m_loadTransparentObjects = aLoad; }
|
|
|
|
|
|
|
|
void SetLoadNonTransparentObjects( bool aLoad )
|
|
|
|
{ m_loadNonTransparentObjects = aLoad; }
|
|
|
|
|
2014-03-05 17:40:23 +00:00
|
|
|
void Insert( S3D_MATERIAL* aMaterial );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2014-03-09 18:43:53 +00:00
|
|
|
/**
|
|
|
|
* Function IsOpenGlAllowed
|
|
|
|
* @return true if opengl current list accepts a gl data
|
|
|
|
* used to filter transparent objects, which are drawn after
|
|
|
|
* non transparent objects
|
|
|
|
*/
|
|
|
|
bool IsOpenGlAllowed();
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
void Copy( S3D_MASTER* pattern );
|
2014-03-09 18:43:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ReadData
|
|
|
|
* Select the parser to read the 3D data file (vrml, x3d ...)
|
|
|
|
* and build the description objects list
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
int ReadData();
|
2014-03-09 18:43:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ObjectCoordsTo3DUnits
|
|
|
|
* @param aVertices = a list of 3D coordinates in shape units
|
|
|
|
* to convert to 3D canvas units, according to the
|
|
|
|
* footprint 3Dshape rotation, offset and scale parameters
|
|
|
|
*/
|
|
|
|
void ObjectCoordsTo3DUnits( std::vector< S3D_VERTEX >& aVertices );
|
2011-12-14 17:25:42 +00:00
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
|
|
|
|
#endif
|
2014-01-25 12:23:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Is3DType
|
|
|
|
* returns true if the argument matches the type of model referred to
|
|
|
|
* by m_Shape3DName
|
|
|
|
*/
|
|
|
|
bool Is3DType( enum FILE3D_TYPE aShapeType );
|
|
|
|
|
|
|
|
const wxString& GetShape3DName( void )
|
|
|
|
{
|
|
|
|
return m_Shape3DName;
|
|
|
|
}
|
|
|
|
|
2015-03-06 08:58:32 +00:00
|
|
|
/** Get class name
|
|
|
|
* @return string "S3D_MASTER"
|
|
|
|
*/
|
|
|
|
virtual wxString GetClass() const
|
|
|
|
{
|
|
|
|
return wxT( "S3D_MASTER" );
|
|
|
|
}
|
|
|
|
|
2014-02-08 10:44:55 +00:00
|
|
|
/**
|
|
|
|
* Function GetShape3DFullFilename
|
|
|
|
* @return the full filename of the 3D shape,
|
|
|
|
* expanding environment variable (if any ) and/or adding default 3D path
|
|
|
|
* given by environment variable KISYS3DMOD
|
|
|
|
*/
|
|
|
|
const wxString GetShape3DFullFilename();
|
|
|
|
|
2014-03-09 18:43:53 +00:00
|
|
|
/**
|
|
|
|
* Function SetShape3DName
|
|
|
|
* @param aShapeName = file name of the data file relative to the 3D shape
|
|
|
|
*
|
|
|
|
* Set the filename of the 3D shape, and depending on the file extention
|
|
|
|
* (vrl, x3d, idf ) the type of file.
|
|
|
|
*/
|
2014-01-25 12:23:29 +00:00
|
|
|
void SetShape3DName( const wxString& aShapeName );
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Describes a complex 3D */
|
2012-08-21 10:45:54 +00:00
|
|
|
class STRUCT_3D_SHAPE : public EDA_ITEM
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-08-21 10:45:54 +00:00
|
|
|
S3D_VERTEX* m_3D_Coord;
|
2008-11-24 06:53:43 +00:00
|
|
|
int* m_3D_CoordIndex;
|
|
|
|
int m_3D_Points;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
public:
|
2012-08-21 10:45:54 +00:00
|
|
|
STRUCT_3D_SHAPE( EDA_ITEM* aParent );
|
|
|
|
~STRUCT_3D_SHAPE();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
STRUCT_3D_SHAPE* Next() const { return (STRUCT_3D_SHAPE*) Pnext; }
|
|
|
|
STRUCT_3D_SHAPE* Back() const { return (STRUCT_3D_SHAPE*) Pback; }
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
|
|
|
|
#endif
|
2008-11-24 06:53:43 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/**
|
2014-08-09 18:18:04 +00:00
|
|
|
* Class S3DPOINT_VALUE_CTRL
|
|
|
|
* displays a S3DPOINT for editing (in dialogs). A S3DPOINT is a triplet of values
|
2012-08-11 12:52:13 +00:00
|
|
|
* Values can be scale, rotation, offset...
|
2008-11-24 06:53:43 +00:00
|
|
|
*/
|
2014-08-09 18:18:04 +00:00
|
|
|
class S3DPOINT_VALUE_CTRL
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
private:
|
2008-11-24 06:53:43 +00:00
|
|
|
wxTextCtrl* m_XValueCtrl, * m_YValueCtrl, * m_ZValueCtrl;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2014-08-09 18:18:04 +00:00
|
|
|
S3DPOINT_VALUE_CTRL( wxWindow* parent, wxBoxSizer* BoxSizer );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-08-09 18:18:04 +00:00
|
|
|
~S3DPOINT_VALUE_CTRL();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/**
|
|
|
|
* Function GetValue
|
2014-08-09 18:18:04 +00:00
|
|
|
* @return the 3D point in internal units.
|
2011-11-10 15:55:05 +00:00
|
|
|
*/
|
2014-08-09 18:18:04 +00:00
|
|
|
S3DPOINT GetValue();
|
|
|
|
void SetValue( S3DPOINT a3Dpoint );
|
2009-11-04 20:46:53 +00:00
|
|
|
void Enable( bool enbl );
|
|
|
|
void SetToolTip( const wxString& text );
|
2008-11-24 06:53:43 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
#endif // STRUCT_3D_H
|