2013-01-13 16:55:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2013 Lorenzo Mercantonio
|
2016-09-23 07:55:33 +00:00
|
|
|
* Copyright (C) 2014-2016 Cirilo Bernardo
|
2013-01-13 16:55:07 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2016-07-19 17:35:25 +00:00
|
|
|
* Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-01-13 16:55:07 +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
|
|
|
|
*/
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
#include <cmath>
|
2014-06-08 10:35:42 +00:00
|
|
|
#include <exception>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iomanip>
|
2010-11-27 13:09:18 +00:00
|
|
|
#include <vector>
|
2016-09-17 06:14:49 +00:00
|
|
|
#include <wx/dir.h>
|
|
|
|
|
|
|
|
#include "3d_cache/3d_cache.h"
|
|
|
|
#include "3d_cache/3d_info.h"
|
|
|
|
#include "class_board.h"
|
|
|
|
#include "class_edge_mod.h"
|
|
|
|
#include "class_module.h"
|
|
|
|
#include "class_pcb_text.h"
|
|
|
|
#include "class_track.h"
|
|
|
|
#include "class_zone.h"
|
|
|
|
#include "convert_to_biu.h"
|
|
|
|
#include "drawtxt.h"
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "kiway.h"
|
|
|
|
#include "macros.h"
|
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "pgm_base.h"
|
|
|
|
#include "plugins/3dapi/ifsg_all.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "vrml_layer.h"
|
|
|
|
#include "wxPcbStruct.h"
|
|
|
|
#include "../../kicad/kicad.h"
|
2014-06-08 10:35:42 +00:00
|
|
|
|
|
|
|
// minimum width (mm) of a VRML line
|
|
|
|
#define MIN_VRML_LINEWIDTH 0.12
|
|
|
|
|
|
|
|
// offset for art layers, mm (silk, paste, etc)
|
2014-06-16 12:02:15 +00:00
|
|
|
#define ART_OFFSET 0.025
|
2016-09-17 06:14:49 +00:00
|
|
|
// offset for plating
|
|
|
|
#define PLATE_OFFSET 0.005
|
|
|
|
|
|
|
|
static S3D_CACHE* cache;
|
|
|
|
static bool USE_INLINES; // true to use legacy inline{} behavior
|
|
|
|
static bool USE_DEFS; // true to reuse component definitions
|
|
|
|
static bool USE_RELPATH; // true to use relative paths in VRML inline{}
|
|
|
|
static double WORLD_SCALE = 1.0; // scaling from 0.1 in to desired VRML unit
|
|
|
|
static double BOARD_SCALE; // scaling from mm to desired VRML world scale
|
|
|
|
static std::ofstream output_file; // legacy VRML output stream
|
|
|
|
static const int PRECISION = 6; // legacy precision factor (now set to 6)
|
|
|
|
static wxString SUBDIR_3D; // legacy 3D subdirectory
|
|
|
|
static wxString PROJ_DIR; // project directory
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
struct VRML_COLOR
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
float diffuse_red;
|
|
|
|
float diffuse_grn;
|
|
|
|
float diffuse_blu;
|
2013-01-13 16:55:07 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
float spec_red;
|
|
|
|
float spec_grn;
|
|
|
|
float spec_blu;
|
2013-01-13 16:55:07 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
float emit_red;
|
|
|
|
float emit_grn;
|
|
|
|
float emit_blu;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
float ambient;
|
|
|
|
float transp;
|
|
|
|
float shiny;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
VRML_COLOR()
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
// default green
|
|
|
|
diffuse_red = 0.13;
|
|
|
|
diffuse_grn = 0.81;
|
|
|
|
diffuse_blu = 0.22;
|
2016-09-17 06:14:49 +00:00
|
|
|
spec_red = 0.01;
|
|
|
|
spec_grn = 0.08;
|
|
|
|
spec_blu = 0.02;
|
2014-01-06 20:14:24 +00:00
|
|
|
emit_red = 0.0;
|
|
|
|
emit_grn = 0.0;
|
|
|
|
emit_blu = 0.0;
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
ambient = 0.8;
|
2014-01-06 20:14:24 +00:00
|
|
|
transp = 0;
|
2016-09-17 06:14:49 +00:00
|
|
|
shiny = 0.02;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
VRML_COLOR( float dr, float dg, float db,
|
|
|
|
float sr, float sg, float sb,
|
|
|
|
float er, float eg, float eb,
|
|
|
|
float am, float tr, float sh )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
diffuse_red = dr;
|
|
|
|
diffuse_grn = dg;
|
|
|
|
diffuse_blu = db;
|
|
|
|
spec_red = sr;
|
|
|
|
spec_grn = sg;
|
|
|
|
spec_blu = sb;
|
|
|
|
emit_red = er;
|
|
|
|
emit_grn = eg;
|
|
|
|
emit_blu = eb;
|
|
|
|
|
|
|
|
ambient = am;
|
|
|
|
transp = tr;
|
|
|
|
shiny = sh;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
enum VRML_COLOR_INDEX
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2016-09-23 07:55:33 +00:00
|
|
|
VRML_COLOR_NONE = -1,
|
2014-01-06 20:14:24 +00:00
|
|
|
VRML_COLOR_PCB = 0,
|
|
|
|
VRML_COLOR_TRACK,
|
|
|
|
VRML_COLOR_SILK,
|
|
|
|
VRML_COLOR_TIN,
|
|
|
|
VRML_COLOR_LAST
|
2010-11-27 13:09:18 +00:00
|
|
|
};
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
static VRML_COLOR colors[VRML_COLOR_LAST];
|
|
|
|
static SGNODE* sgmaterial[VRML_COLOR_LAST] = { NULL };
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
class MODEL_VRML
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
private:
|
2014-06-24 16:17:18 +00:00
|
|
|
double layer_z[LAYER_ID_COUNT];
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
int iMaxSeg; // max. sides to a small circle
|
2014-10-17 23:28:12 +00:00
|
|
|
double arcMinLen, arcMaxLen; // min and max lengths of an arc chord
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
public:
|
2016-09-17 06:14:49 +00:00
|
|
|
IFSG_TRANSFORM OutputPCB;
|
2014-01-06 20:14:24 +00:00
|
|
|
VRML_LAYER holes;
|
|
|
|
VRML_LAYER board;
|
|
|
|
VRML_LAYER top_copper;
|
|
|
|
VRML_LAYER bot_copper;
|
|
|
|
VRML_LAYER top_silk;
|
|
|
|
VRML_LAYER bot_silk;
|
|
|
|
VRML_LAYER top_tin;
|
|
|
|
VRML_LAYER bot_tin;
|
2014-06-16 12:02:15 +00:00
|
|
|
VRML_LAYER plated_holes;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
std::list< SGNODE* > components;
|
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
bool plainPCB;
|
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
double minLineWidth; // minimum width of a VRML line segment
|
|
|
|
int precision; // precision of output units
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
double tx; // global translation along X
|
|
|
|
double ty; // global translation along Y
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
double board_thickness; // depth of the PCB
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
LAYER_NUM s_text_layer;
|
|
|
|
int s_text_width;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
MODEL_VRML() : OutputPCB( (SGNODE*) NULL )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
for( unsigned i = 0; i < DIM( layer_z ); ++i )
|
2014-01-06 20:14:24 +00:00
|
|
|
layer_z[i] = 0;
|
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
holes.GetArcParams( iMaxSeg, arcMinLen, arcMaxLen );
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// this default only makes sense if the output is in mm
|
|
|
|
board_thickness = 1.6;
|
|
|
|
|
|
|
|
// pcb green
|
2016-09-17 06:14:49 +00:00
|
|
|
colors[ VRML_COLOR_PCB ] = VRML_COLOR( .07, .3, .12, .01, .03, .01,
|
|
|
|
0, 0, 0, 0.8, 0, 0.02 );
|
2014-01-06 20:14:24 +00:00
|
|
|
// track green
|
2016-09-17 06:14:49 +00:00
|
|
|
colors[ VRML_COLOR_TRACK ] = VRML_COLOR( .08, .5, .1, .01, .05, .01,
|
|
|
|
0, 0, 0, 0.8, 0, 0.02 );
|
2014-01-06 20:14:24 +00:00
|
|
|
// silkscreen white
|
2016-09-17 06:14:49 +00:00
|
|
|
colors[ VRML_COLOR_SILK ] = VRML_COLOR( .9, .9, .9, .1, .1, .1,
|
|
|
|
0, 0, 0, 0.9, 0, 0.02 );
|
2014-01-06 20:14:24 +00:00
|
|
|
// pad silver
|
2014-10-17 23:28:12 +00:00
|
|
|
colors[ VRML_COLOR_TIN ] = VRML_COLOR( .749, .756, .761, .749, .756, .761,
|
2014-01-06 20:14:24 +00:00
|
|
|
0, 0, 0, 0.8, 0, 0.8 );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2015-02-17 14:56:45 +00:00
|
|
|
plainPCB = false;
|
|
|
|
SetOffset( 0.0, 0.0 );
|
|
|
|
s_text_layer = F_Cu;
|
|
|
|
s_text_width = 1;
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
~MODEL_VRML()
|
|
|
|
{
|
|
|
|
// destroy any unassociated material appearances
|
|
|
|
for( int j = 0; j < VRML_COLOR_LAST; ++j )
|
|
|
|
{
|
|
|
|
if( sgmaterial[j] && NULL == S3D::GetSGNodeParent( sgmaterial[j] ) )
|
|
|
|
S3D::DestroyNode( sgmaterial[j] );
|
|
|
|
|
|
|
|
sgmaterial[j] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !components.empty() )
|
|
|
|
{
|
|
|
|
IFSG_TRANSFORM tmp( false );
|
|
|
|
|
|
|
|
for( auto i : components )
|
|
|
|
{
|
|
|
|
tmp.Attach( i );
|
|
|
|
tmp.SetParent( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
components.clear();
|
|
|
|
OutputPCB.Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
VRML_COLOR& GetColor( VRML_COLOR_INDEX aIndex )
|
|
|
|
{
|
|
|
|
return colors[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetOffset( double aXoff, double aYoff )
|
|
|
|
{
|
2014-06-16 12:02:15 +00:00
|
|
|
tx = aXoff;
|
|
|
|
ty = -aYoff;
|
|
|
|
|
|
|
|
holes.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
board.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
top_copper.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
bot_copper.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
top_silk.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
bot_silk.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
top_tin.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
bot_tin.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
plated_holes.SetVertexOffsets( aXoff, aYoff );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double GetLayerZ( LAYER_NUM aLayer )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
if( unsigned( aLayer ) >= DIM( layer_z ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return layer_z[ aLayer ];
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
void SetLayerZ( LAYER_NUM aLayer, double aValue )
|
|
|
|
{
|
|
|
|
layer_z[aLayer] = aValue;
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// set the scaling of the VRML world
|
|
|
|
bool SetScale( double aWorldScale )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
if( aWorldScale < 0.001 || aWorldScale > 10.0 )
|
|
|
|
throw( std::runtime_error( "WorldScale out of range (valid range is 0.001 to 10.0)" ) );
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// note: the KiCad SceneGraph library uses mm internally
|
|
|
|
// and scales output to VRML UNIT = 0.1 inch so that by
|
|
|
|
// default the output models are compatible with KiCad's
|
|
|
|
// expectations. This requires us to divide aWorldScale
|
|
|
|
// by 2.54 in order to generate the scaling which the
|
|
|
|
// user specified in the Export VRML GUI.
|
|
|
|
OutputPCB.SetScale( aWorldScale / 2.54 );
|
|
|
|
|
|
|
|
WORLD_SCALE = aWorldScale * 2.54;
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// XXX - Delete if no longer necessary
|
|
|
|
/*
|
2014-06-08 10:35:42 +00:00
|
|
|
double smin = arcMinLen * aWorldScale;
|
|
|
|
double smax = arcMaxLen * aWorldScale;
|
|
|
|
|
|
|
|
holes.SetArcParams( iMaxSeg, smin, smax );
|
|
|
|
board.SetArcParams( iMaxSeg, smin, smax );
|
|
|
|
top_copper.SetArcParams( iMaxSeg, smin, smax);
|
|
|
|
bot_copper.SetArcParams( iMaxSeg, smin, smax);
|
|
|
|
top_silk.SetArcParams( iMaxSeg, smin, smax );
|
|
|
|
bot_silk.SetArcParams( iMaxSeg, smin, smax );
|
|
|
|
top_tin.SetArcParams( iMaxSeg, smin, smax );
|
|
|
|
bot_tin.SetArcParams( iMaxSeg, smin, smax );
|
2014-06-16 12:02:15 +00:00
|
|
|
plated_holes.SetArcParams( iMaxSeg, smin, smax );
|
2016-09-17 06:14:49 +00:00
|
|
|
*/
|
2014-06-08 10:35:42 +00:00
|
|
|
|
|
|
|
return true;
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// static var. for dealing with text
|
2014-06-08 10:35:42 +00:00
|
|
|
static MODEL_VRML* model_vrml;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// select the VRML layer object to draw on; return true if
|
|
|
|
// a layer has been selected.
|
2014-06-08 10:35:42 +00:00
|
|
|
static bool GetLayer( MODEL_VRML& aModel, LAYER_NUM layer, VRML_LAYER** vlayer )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
switch( layer )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Cu:
|
2014-01-06 20:14:24 +00:00
|
|
|
*vlayer = &aModel.bot_copper;
|
|
|
|
break;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case F_Cu:
|
2014-01-06 20:14:24 +00:00
|
|
|
*vlayer = &aModel.top_copper;
|
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_SilkS:
|
2014-01-06 20:14:24 +00:00
|
|
|
*vlayer = &aModel.bot_silk;
|
|
|
|
break;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case F_SilkS:
|
2014-01-06 20:14:24 +00:00
|
|
|
*vlayer = &aModel.top_silk;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
return true;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
|
|
|
|
VRML_LAYER* layer, double top_z, double bottom_z );
|
|
|
|
|
|
|
|
static void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
|
|
|
|
VRML_LAYER* layer, double aHeight, bool aTopPlane );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
static void write_triangle_bag( std::ofstream& output_file, VRML_COLOR& color,
|
2014-10-17 23:28:12 +00:00
|
|
|
VRML_LAYER* layer, bool plane, bool top,
|
2016-09-17 06:14:49 +00:00
|
|
|
double top_z, double bottom_z )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
/* A lot of nodes are not required, but blender sometimes chokes
|
|
|
|
* without them */
|
|
|
|
static const char* shape_boiler[] =
|
|
|
|
{
|
|
|
|
"Transform {\n",
|
|
|
|
" children [\n",
|
|
|
|
" Group {\n",
|
|
|
|
" children [\n",
|
|
|
|
" Shape {\n",
|
|
|
|
" appearance Appearance {\n",
|
|
|
|
" material Material {\n",
|
2014-01-06 20:14:24 +00:00
|
|
|
0, // Material marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" }\n",
|
|
|
|
" }\n",
|
|
|
|
" geometry IndexedFaceSet {\n",
|
2012-06-19 19:25:41 +00:00
|
|
|
" solid TRUE\n",
|
2010-11-27 13:09:18 +00:00
|
|
|
" coord Coordinate {\n",
|
|
|
|
" point [\n",
|
2014-01-06 20:14:24 +00:00
|
|
|
0, // Coordinates marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" coordIndex [\n",
|
2014-01-06 20:14:24 +00:00
|
|
|
0, // Index marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" }\n",
|
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" ]\n",
|
|
|
|
"}\n",
|
2014-01-06 20:14:24 +00:00
|
|
|
0 // End marker
|
2010-11-27 13:09:18 +00:00
|
|
|
};
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
int marker_found = 0, lineno = 0;
|
|
|
|
|
|
|
|
while( marker_found < 4 )
|
|
|
|
{
|
|
|
|
if( shape_boiler[lineno] )
|
2014-06-08 10:35:42 +00:00
|
|
|
output_file << shape_boiler[lineno];
|
2010-11-27 13:09:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
marker_found++;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
switch( marker_found )
|
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
case 1: // Material marker
|
2014-06-08 10:35:42 +00:00
|
|
|
output_file << " diffuseColor " << std::setprecision(3);
|
|
|
|
output_file << color.diffuse_red << " ";
|
|
|
|
output_file << color.diffuse_grn << " ";
|
|
|
|
output_file << color.diffuse_blu << "\n";
|
|
|
|
|
|
|
|
output_file << " specularColor ";
|
|
|
|
output_file << color.spec_red << " ";
|
|
|
|
output_file << color.spec_grn << " ";
|
|
|
|
output_file << color.spec_blu << "\n";
|
|
|
|
|
|
|
|
output_file << " emissiveColor ";
|
|
|
|
output_file << color.emit_red << " ";
|
|
|
|
output_file << color.emit_grn << " ";
|
|
|
|
output_file << color.emit_blu << "\n";
|
|
|
|
|
|
|
|
output_file << " ambientIntensity " << color.ambient << "\n";
|
|
|
|
output_file << " transparency " << color.transp << "\n";
|
|
|
|
output_file << " shininess " << color.shiny << "\n";
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
if( plane )
|
2016-09-17 06:14:49 +00:00
|
|
|
layer->WriteVertices( top_z, output_file, PRECISION );
|
2014-01-06 20:14:24 +00:00
|
|
|
else
|
2016-09-17 06:14:49 +00:00
|
|
|
layer->Write3DVertices( top_z, bottom_z, output_file, PRECISION );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
output_file << "\n";
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
case 3:
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
if( plane )
|
|
|
|
layer->WriteIndices( top, output_file );
|
|
|
|
else
|
|
|
|
layer->Write3DIndices( output_file );
|
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
output_file << "\n";
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
lineno++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
|
|
|
// VRML_LAYER board;
|
|
|
|
aModel.board.Tesselate( &aModel.holes );
|
2014-06-08 10:35:42 +00:00
|
|
|
double brdz = aModel.board_thickness / 2.0
|
2016-09-17 06:14:49 +00:00
|
|
|
- ( Millimeter2iu( ART_OFFSET / 2.0 ) ) * BOARD_SCALE;
|
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_PCB ),
|
|
|
|
&aModel.board, false, false, brdz, -brdz );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_shell( aModel.OutputPCB, VRML_COLOR_PCB, &aModel.board, brdz, -brdz );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
if( aModel.plainPCB )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
if( !USE_INLINES )
|
|
|
|
S3D::WriteVRML( aFileName, true, aModel.OutputPCB.GetRawPtr(), USE_DEFS, true );
|
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
return;
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-12-20 16:13:51 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// VRML_LAYER top_copper;
|
|
|
|
aModel.top_copper.Tesselate( &aModel.holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TRACK ),
|
|
|
|
&aModel.top_copper, true, true,
|
|
|
|
aModel.GetLayerZ( F_Cu ), 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_plane( aModel.OutputPCB, VRML_COLOR_TRACK, &aModel.top_copper,
|
|
|
|
aModel.GetLayerZ( F_Cu ), true );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
// VRML_LAYER top_tin;
|
|
|
|
aModel.top_tin.Tesselate( &aModel.holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TIN ),
|
|
|
|
&aModel.top_tin, true, true,
|
|
|
|
aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
|
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_plane( aModel.OutputPCB, VRML_COLOR_TIN, &aModel.top_tin,
|
|
|
|
aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
|
|
|
|
true );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
// VRML_LAYER bot_copper;
|
|
|
|
aModel.bot_copper.Tesselate( &aModel.holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TRACK ),
|
|
|
|
&aModel.bot_copper, true, false,
|
|
|
|
aModel.GetLayerZ( B_Cu ), 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_plane( aModel.OutputPCB, VRML_COLOR_TRACK, &aModel.bot_copper,
|
|
|
|
aModel.GetLayerZ( B_Cu ), false );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
// VRML_LAYER bot_tin;
|
|
|
|
aModel.bot_tin.Tesselate( &aModel.holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TIN ),
|
|
|
|
&aModel.bot_tin, true, false,
|
|
|
|
aModel.GetLayerZ( B_Cu )
|
|
|
|
- Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
|
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_plane( aModel.OutputPCB, VRML_COLOR_TIN, &aModel.bot_tin,
|
|
|
|
aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
|
|
|
|
false );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-16 12:02:15 +00:00
|
|
|
// VRML_LAYER PTH;
|
|
|
|
aModel.plated_holes.Tesselate( NULL, true );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_TIN ),
|
|
|
|
&aModel.plated_holes, false, false,
|
|
|
|
aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
|
|
|
|
aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_shell( aModel.OutputPCB, VRML_COLOR_TIN, &aModel.plated_holes,
|
|
|
|
aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE,
|
|
|
|
aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE );
|
|
|
|
}
|
2014-06-16 12:02:15 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// VRML_LAYER top_silk;
|
|
|
|
aModel.top_silk.Tesselate( &aModel.holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_SILK ), &aModel.top_silk,
|
|
|
|
true, true, aModel.GetLayerZ( F_SilkS ), 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_plane( aModel.OutputPCB, VRML_COLOR_SILK, &aModel.top_silk,
|
|
|
|
aModel.GetLayerZ( F_SilkS ), true );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
// VRML_LAYER bot_silk;
|
|
|
|
aModel.bot_silk.Tesselate( &aModel.holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
write_triangle_bag( output_file, aModel.GetColor( VRML_COLOR_SILK ), &aModel.bot_silk,
|
|
|
|
true, false, aModel.GetLayerZ( B_SilkS ), 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_plane( aModel.OutputPCB, VRML_COLOR_SILK, &aModel.bot_silk,
|
|
|
|
aModel.GetLayerZ( B_SilkS ), false );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !USE_INLINES )
|
|
|
|
S3D::WriteVRML( aFileName, true, aModel.OutputPCB.GetRawPtr(), true, true );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void compute_layer_Zs( MODEL_VRML& aModel, BOARD* pcb )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
int copper_layers = pcb->GetCopperLayerCount();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
// We call it 'layer' thickness, but it's the whole board thickness!
|
2016-09-17 06:14:49 +00:00
|
|
|
aModel.board_thickness = pcb->GetDesignSettings().GetBoardThickness() * BOARD_SCALE;
|
2014-01-06 20:14:24 +00:00
|
|
|
double half_thickness = aModel.board_thickness / 2;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Compute each layer's Z value, more or less like the 3d view
|
2014-06-24 16:17:18 +00:00
|
|
|
for( LSEQ seq = LSET::AllCuMask().Seq(); seq; ++seq )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID i = *seq;
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( i < copper_layers )
|
2014-07-02 13:08:28 +00:00
|
|
|
aModel.SetLayerZ( i, half_thickness - aModel.board_thickness * i / (copper_layers - 1) );
|
2010-11-27 13:09:18 +00:00
|
|
|
else
|
2014-07-02 13:08:28 +00:00
|
|
|
aModel.SetLayerZ( i, - half_thickness ); // bottom layer
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* To avoid rounding interference, we apply an epsilon to each
|
|
|
|
* successive layer */
|
2016-09-17 06:14:49 +00:00
|
|
|
double epsilon_z = Millimeter2iu( ART_OFFSET ) * BOARD_SCALE;
|
2014-06-24 16:17:18 +00:00
|
|
|
aModel.SetLayerZ( B_Paste, -half_thickness - epsilon_z * 4 );
|
|
|
|
aModel.SetLayerZ( B_Adhes, -half_thickness - epsilon_z * 3 );
|
|
|
|
aModel.SetLayerZ( B_SilkS, -half_thickness - epsilon_z * 2 );
|
|
|
|
aModel.SetLayerZ( B_Mask, -half_thickness - epsilon_z );
|
|
|
|
aModel.SetLayerZ( F_Mask, half_thickness + epsilon_z );
|
|
|
|
aModel.SetLayerZ( F_SilkS, half_thickness + epsilon_z * 2 );
|
|
|
|
aModel.SetLayerZ( F_Adhes, half_thickness + epsilon_z * 3 );
|
|
|
|
aModel.SetLayerZ( F_Paste, half_thickness + epsilon_z * 4 );
|
|
|
|
aModel.SetLayerZ( Dwgs_User, half_thickness + epsilon_z * 5 );
|
|
|
|
aModel.SetLayerZ( Cmts_User, half_thickness + epsilon_z * 6 );
|
|
|
|
aModel.SetLayerZ( Eco1_User, half_thickness + epsilon_z * 7 );
|
|
|
|
aModel.SetLayerZ( Eco2_User, half_thickness + epsilon_z * 8 );
|
|
|
|
aModel.SetLayerZ( Edge_Cuts, 0 );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
static void export_vrml_line( MODEL_VRML& aModel, LAYER_NUM layer,
|
2014-10-17 23:28:12 +00:00
|
|
|
double startx, double starty,
|
|
|
|
double endx, double endy, double width )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
VRML_LAYER* vlayer;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( !GetLayer( aModel, layer, &vlayer ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( width < aModel.minLineWidth)
|
|
|
|
width = aModel.minLineWidth;
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
starty = -starty;
|
|
|
|
endy = -endy;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
double angle = atan2( endy - starty, endx - startx ) * 180.0 / M_PI;
|
2014-01-06 20:14:24 +00:00
|
|
|
double length = Distance( startx, starty, endx, endy ) + width;
|
|
|
|
double cx = ( startx + endx ) / 2.0;
|
|
|
|
double cy = ( starty + endy ) / 2.0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( !vlayer->AddSlot( cx, cy, length, width, angle, false ) )
|
|
|
|
throw( std::runtime_error( vlayer->GetError() ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
static void export_vrml_circle( MODEL_VRML& aModel, LAYER_NUM layer,
|
2014-10-17 23:28:12 +00:00
|
|
|
double startx, double starty,
|
|
|
|
double endx, double endy, double width )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
VRML_LAYER* vlayer;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( !GetLayer( aModel, layer, &vlayer ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
return;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( width < aModel.minLineWidth )
|
|
|
|
width = aModel.minLineWidth;
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
starty = -starty;
|
|
|
|
endy = -endy;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
double hole, radius;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
radius = Distance( startx, starty, endx, endy ) + ( width / 2);
|
|
|
|
hole = radius - width;
|
2012-06-19 19:25:41 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( !vlayer->AddCircle( startx, starty, radius, false ) )
|
|
|
|
throw( std::runtime_error( vlayer->GetError() ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
if( hole > 0.0001 )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
if( !vlayer->AddCircle( startx, starty, hole, true ) )
|
|
|
|
throw( std::runtime_error( vlayer->GetError() ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
static void export_vrml_arc( MODEL_VRML& aModel, LAYER_NUM layer,
|
2014-10-17 23:28:12 +00:00
|
|
|
double centerx, double centery,
|
|
|
|
double arc_startx, double arc_starty,
|
|
|
|
double width, double arc_angle )
|
2012-06-19 19:25:41 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
VRML_LAYER* vlayer;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( !GetLayer( aModel, layer, &vlayer ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
return;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( width < aModel.minLineWidth )
|
|
|
|
width = aModel.minLineWidth;
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
centery = -centery;
|
|
|
|
arc_starty = -arc_starty;
|
2012-06-19 19:25:41 +00:00
|
|
|
|
2015-04-27 08:55:08 +00:00
|
|
|
if( !vlayer->AddArc( centerx, centery, arc_startx, arc_starty, width, -arc_angle, false ) )
|
2014-06-08 10:35:42 +00:00
|
|
|
throw( std::runtime_error( vlayer->GetError() ) );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2012-06-19 19:25:41 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
static void export_vrml_drawsegment( MODEL_VRML& aModel, DRAWSEGMENT* drawseg )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer = drawseg->GetLayer();
|
2016-09-17 06:14:49 +00:00
|
|
|
double w = drawseg->GetWidth() * BOARD_SCALE;
|
|
|
|
double x = drawseg->GetStart().x * BOARD_SCALE;
|
|
|
|
double y = drawseg->GetStart().y * BOARD_SCALE;
|
|
|
|
double xf = drawseg->GetEnd().x * BOARD_SCALE;
|
|
|
|
double yf = drawseg->GetEnd().y * BOARD_SCALE;
|
2015-09-09 15:08:53 +00:00
|
|
|
double r = sqrt( pow( x - xf, 2 ) + pow( y - yf, 2 ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// Items on the edge layer are handled elsewhere; just return
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer == Edge_Cuts )
|
2014-01-06 20:14:24 +00:00
|
|
|
return;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
switch( drawseg->GetShape() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
case S_ARC:
|
|
|
|
export_vrml_arc( aModel, layer,
|
2016-09-17 06:14:49 +00:00
|
|
|
(double) drawseg->GetCenter().x * BOARD_SCALE,
|
|
|
|
(double) drawseg->GetCenter().y * BOARD_SCALE,
|
|
|
|
(double) drawseg->GetArcStart().x * BOARD_SCALE,
|
|
|
|
(double) drawseg->GetArcStart().y * BOARD_SCALE,
|
2014-10-17 23:28:12 +00:00
|
|
|
w, drawseg->GetAngle() / 10 );
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
case S_CIRCLE:
|
2015-09-09 15:08:53 +00:00
|
|
|
// Break circles into two 180 arcs to prevent the vrml hole from obscuring objects
|
|
|
|
// within the hole area of the circle.
|
|
|
|
export_vrml_arc( aModel, layer, x, y, x, y-r, w, 180.0 );
|
|
|
|
export_vrml_arc( aModel, layer, x, y, x, y+r, w, 180.0 );
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
default:
|
|
|
|
export_vrml_line( aModel, layer, x, y, xf, yf, w );
|
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* C++ doesn't have closures and neither continuation forms... this is
|
|
|
|
* for coupling the vrml_text_callback with the common parameters */
|
|
|
|
static void vrml_text_callback( int x0, int y0, int xf, int yf )
|
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
LAYER_NUM s_text_layer = model_vrml->s_text_layer;
|
|
|
|
int s_text_width = model_vrml->s_text_width;
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
export_vrml_line( *model_vrml, s_text_layer,
|
2016-09-17 06:14:49 +00:00
|
|
|
x0 * BOARD_SCALE, y0 * BOARD_SCALE,
|
|
|
|
xf * BOARD_SCALE, yf * BOARD_SCALE,
|
|
|
|
s_text_width * BOARD_SCALE );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
static void export_vrml_pcbtext( MODEL_VRML& aModel, TEXTE_PCB* text )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
model_vrml->s_text_layer = text->GetLayer();
|
|
|
|
model_vrml->s_text_width = text->GetThickness();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
wxSize size = text->GetSize();
|
|
|
|
|
|
|
|
if( text->IsMirrored() )
|
2015-06-26 13:41:56 +00:00
|
|
|
size.x = -size.x;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-04-19 16:05:58 +00:00
|
|
|
EDA_COLOR_T color = BLACK; // not actually used, but needed by DrawGraphicText
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( text->IsMultilineAllowed() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxArrayString strings_list;
|
|
|
|
wxStringSplit( text->GetShownText(), strings_list, '\n' );
|
2014-04-19 16:05:58 +00:00
|
|
|
std::vector<wxPoint> positions;
|
2015-01-15 20:01:53 +00:00
|
|
|
positions.reserve( strings_list.Count() );
|
|
|
|
text->GetPositionsOfLinesOfMultilineText( positions, strings_list.Count() );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxString& txt = strings_list.Item( ii );
|
2014-04-19 16:05:58 +00:00
|
|
|
DrawGraphicText( NULL, NULL, positions[ii], color,
|
|
|
|
txt, text->GetOrientation(), size,
|
|
|
|
text->GetHorizJustify(), text->GetVertJustify(),
|
|
|
|
text->GetThickness(), text->IsItalic(),
|
|
|
|
true,
|
|
|
|
vrml_text_callback );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-19 16:05:58 +00:00
|
|
|
DrawGraphicText( NULL, NULL, text->GetTextPosition(), color,
|
2014-09-13 18:15:45 +00:00
|
|
|
text->GetShownText(), text->GetOrientation(), size,
|
2014-04-19 16:05:58 +00:00
|
|
|
text->GetHorizJustify(), text->GetVertJustify(),
|
|
|
|
text->GetThickness(), text->IsItalic(),
|
|
|
|
true,
|
|
|
|
vrml_text_callback );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
static void export_vrml_drawings( MODEL_VRML& aModel, BOARD* pcb )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// draw graphic items
|
2015-09-09 15:08:53 +00:00
|
|
|
for( BOARD_ITEM* drawing = pcb->m_Drawings; drawing != 0; drawing = drawing->Next() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2015-09-09 15:08:53 +00:00
|
|
|
LAYER_ID layer = drawing->GetLayer();
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer != F_Cu && layer != B_Cu && layer != B_SilkS && layer != F_SilkS )
|
2014-01-06 20:14:24 +00:00
|
|
|
continue;
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
switch( drawing->Type() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_LINE_T:
|
2014-01-06 20:14:24 +00:00
|
|
|
export_vrml_drawsegment( aModel, (DRAWSEGMENT*) drawing );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_TEXT_T:
|
2014-01-06 20:14:24 +00:00
|
|
|
export_vrml_pcbtext( aModel, (TEXTE_PCB*) drawing );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// board edges and cutouts
|
|
|
|
static void export_vrml_board( MODEL_VRML& aModel, BOARD* pcb )
|
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
SHAPE_POLY_SET bufferPcbOutlines; // stores the board main outlines
|
|
|
|
SHAPE_POLY_SET allLayerHoles; // Contains through holes, calculated only once
|
2014-01-06 20:14:24 +00:00
|
|
|
// Build a polygon from edge cut items
|
|
|
|
wxString msg;
|
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
if( !pcb->GetBoardPolygonOutlines( bufferPcbOutlines, allLayerHoles, &msg ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2016-09-23 07:55:33 +00:00
|
|
|
msg << "\n\n" <<
|
|
|
|
_( "Unable to calculate the board outlines; fall back to using the board boundary box." );
|
2014-01-06 20:14:24 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
int seg;
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int i = 0; i < bufferPcbOutlines.OutlineCount(); i++ )
|
2015-07-14 20:23:13 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outline = bufferPcbOutlines.COutline( i );
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
seg = aModel.board.NewContour();
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int j = 0; j < outline.PointCount(); j++ )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
aModel.board.AddVertex( seg, (double)outline.CPoint(j).x * BOARD_SCALE,
|
|
|
|
-((double)outline.CPoint(j).y * BOARD_SCALE ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
aModel.board.EnsureWinding( seg, false );
|
|
|
|
}
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int i = 0; i < allLayerHoles.OutlineCount(); i++ )
|
2015-07-14 20:23:13 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outline = allLayerHoles.COutline( i );
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
seg = aModel.holes.NewContour();
|
|
|
|
|
|
|
|
if( seg < 0 )
|
|
|
|
{
|
2016-09-23 07:55:33 +00:00
|
|
|
msg << "\n\n" <<
|
|
|
|
_( "VRML Export Failed: Could not add holes to contours." );
|
2014-01-06 20:14:24 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int j = 0; j < outline.PointCount(); j++ )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
aModel.holes.AddVertex( seg, (double)outline.CPoint(j).x * BOARD_SCALE,
|
|
|
|
-((double)outline.CPoint(j).y * BOARD_SCALE ) );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aModel.holes.EnsureWinding( seg, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void export_round_padstack( MODEL_VRML& aModel, BOARD* pcb,
|
2014-10-17 23:28:12 +00:00
|
|
|
double x, double y, double r,
|
|
|
|
LAYER_NUM bottom_layer, LAYER_NUM top_layer,
|
|
|
|
double hole )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_NUM layer = top_layer;
|
|
|
|
bool thru = true;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// if not a thru hole do not put a hole in the board
|
2014-06-24 16:17:18 +00:00
|
|
|
if( top_layer != F_Cu || bottom_layer != B_Cu )
|
2014-01-06 20:14:24 +00:00
|
|
|
thru = false;
|
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( thru && hole > 0 )
|
|
|
|
aModel.holes.AddCircle( x, -y, hole, true );
|
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
if( aModel.plainPCB )
|
|
|
|
return;
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
while( 1 )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer == B_Cu )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
aModel.bot_copper.AddCircle( x, -y, r );
|
|
|
|
|
|
|
|
if( hole > 0 && !thru )
|
2014-10-17 23:28:12 +00:00
|
|
|
aModel.bot_copper.AddCircle( x, -y, hole, true );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
else if( layer == F_Cu )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
aModel.top_copper.AddCircle( x, -y, r );
|
|
|
|
|
|
|
|
if( hole > 0 && !thru )
|
|
|
|
aModel.top_copper.AddCircle( x, -y, hole, true );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
if( layer == bottom_layer )
|
|
|
|
break;
|
|
|
|
|
|
|
|
layer = bottom_layer;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
static void export_vrml_via( MODEL_VRML& aModel, BOARD* pcb, const VIA* via )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
double x, y, r, hole;
|
|
|
|
LAYER_ID top_layer, bottom_layer;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
hole = via->GetDrillValue() * BOARD_SCALE / 2.0;
|
|
|
|
r = via->GetWidth() * BOARD_SCALE / 2.0;
|
|
|
|
x = via->GetStart().x * BOARD_SCALE;
|
|
|
|
y = via->GetStart().y * BOARD_SCALE;
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
via->LayerPair( &top_layer, &bottom_layer );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// do not render a buried via
|
2014-06-24 16:17:18 +00:00
|
|
|
if( top_layer != F_Cu && bottom_layer != B_Cu )
|
2014-01-06 20:14:24 +00:00
|
|
|
return;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// Export the via padstack
|
|
|
|
export_round_padstack( aModel, pcb, x, y, r, bottom_layer, top_layer, hole );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
static void export_vrml_tracks( MODEL_VRML& aModel, BOARD* pcb )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
for( TRACK* track = pcb->m_Track; track; track = track->Next() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
if( track->Type() == PCB_VIA_T )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2014-04-25 06:00:04 +00:00
|
|
|
export_vrml_via( aModel, pcb, (const VIA*) track );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2014-12-20 16:13:51 +00:00
|
|
|
else if( ( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu )
|
|
|
|
&& !aModel.plainPCB )
|
2014-01-06 20:14:24 +00:00
|
|
|
export_vrml_line( aModel, track->GetLayer(),
|
2016-09-17 06:14:49 +00:00
|
|
|
track->GetStart().x * BOARD_SCALE,
|
|
|
|
track->GetStart().y * BOARD_SCALE,
|
|
|
|
track->GetEnd().x * BOARD_SCALE,
|
|
|
|
track->GetEnd().y * BOARD_SCALE,
|
|
|
|
track->GetWidth() * BOARD_SCALE );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
static void export_vrml_zones( MODEL_VRML& aModel, BOARD* aPcb )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
ZONE_CONTAINER* zone = aPcb->GetArea( ii );
|
|
|
|
|
|
|
|
VRML_LAYER* vl;
|
2011-08-29 03:04:59 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( !GetLayer( aModel, zone->GetLayer(), &vl ) )
|
2010-11-27 13:09:18 +00:00
|
|
|
continue;
|
2011-08-29 03:04:59 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
if( !zone->IsFilled() )
|
|
|
|
{
|
|
|
|
zone->SetFillMode( 0 ); // use filled polygons
|
|
|
|
zone->BuildFilledSolidAreasPolygons( aPcb );
|
|
|
|
}
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_POLY_SET& poly = zone->GetFilledPolysList();
|
2013-03-18 19:36:07 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int i = 0; i < poly.OutlineCount(); i++ )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outline = poly.COutline( i );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
int seg = vl->NewContour();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int j = 0; j < outline.PointCount(); j++ )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
if( !vl->AddVertex( seg, (double)outline.CPoint( j ).x * BOARD_SCALE,
|
|
|
|
-((double)outline.CPoint( j ).y * BOARD_SCALE ) ) )
|
2014-06-08 10:35:42 +00:00
|
|
|
throw( std::runtime_error( vl->GetError() ) );
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
vl->EnsureWinding( seg, false );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
static void export_vrml_text_module( TEXTE_MODULE* module )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2011-12-12 08:37:05 +00:00
|
|
|
if( module->IsVisible() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
wxSize size = module->GetSize();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( module->IsMirrored() )
|
2015-06-26 13:41:56 +00:00
|
|
|
size.x = -size.x; // Text is mirrored
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
model_vrml->s_text_layer = module->GetLayer();
|
|
|
|
model_vrml->s_text_width = module->GetThickness();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
DrawGraphicText( NULL, NULL, module->GetTextPosition(), BLACK,
|
2014-10-17 23:28:12 +00:00
|
|
|
module->GetShownText(), module->GetDrawRotation(), size,
|
|
|
|
module->GetHorizJustify(), module->GetVertJustify(),
|
|
|
|
module->GetThickness(), module->IsItalic(),
|
|
|
|
true,
|
|
|
|
vrml_text_callback );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-15 07:39:06 +00:00
|
|
|
static void export_vrml_edge_module( MODEL_VRML& aModel, EDGE_MODULE* aOutline,
|
|
|
|
double aOrientation )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer = aOutline->GetLayer();
|
2016-09-17 06:14:49 +00:00
|
|
|
double x = aOutline->GetStart().x * BOARD_SCALE;
|
|
|
|
double y = aOutline->GetStart().y * BOARD_SCALE;
|
|
|
|
double xf = aOutline->GetEnd().x * BOARD_SCALE;
|
|
|
|
double yf = aOutline->GetEnd().y * BOARD_SCALE;
|
|
|
|
double w = aOutline->GetWidth() * BOARD_SCALE;
|
2012-06-19 19:25:41 +00:00
|
|
|
|
|
|
|
switch( aOutline->GetShape() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-02-15 07:39:06 +00:00
|
|
|
case S_SEGMENT:
|
|
|
|
export_vrml_line( aModel, layer, x, y, xf, yf, w );
|
|
|
|
break;
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
case S_ARC:
|
2014-01-06 20:14:24 +00:00
|
|
|
export_vrml_arc( aModel, layer, x, y, xf, yf, w, aOutline->GetAngle() / 10 );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
2014-01-06 20:14:24 +00:00
|
|
|
export_vrml_circle( aModel, layer, x, y, xf, yf, w );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
2014-02-15 07:39:06 +00:00
|
|
|
case S_POLYGON:
|
|
|
|
{
|
|
|
|
VRML_LAYER* vl;
|
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
if( !GetLayer( aModel, layer, &vl ) )
|
2014-02-15 07:39:06 +00:00
|
|
|
break;
|
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
int nvert = aOutline->GetPolyPoints().size() - 1;
|
2014-02-15 07:39:06 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if( nvert < 3 ) break;
|
|
|
|
|
|
|
|
int seg = vl->NewContour();
|
|
|
|
|
|
|
|
if( seg < 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
while( i < nvert )
|
|
|
|
{
|
|
|
|
CPolyPt corner( aOutline->GetPolyPoints()[i] );
|
|
|
|
RotatePoint( &corner.x, &corner.y, aOrientation );
|
|
|
|
corner.x += aOutline->GetPosition().x;
|
|
|
|
corner.y += aOutline->GetPosition().y;
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
x = corner.x * BOARD_SCALE;
|
|
|
|
y = - ( corner.y * BOARD_SCALE );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
|
|
|
if( !vl->AddVertex( seg, x, y ) )
|
|
|
|
throw( std::runtime_error( vl->GetError() ) );
|
2014-02-15 07:39:06 +00:00
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
vl->EnsureWinding( seg, false );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_PAD* aPad )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
// The (maybe offset) pad position
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
wxPoint pad_pos = aPad->ShapePos();
|
2016-09-17 06:14:49 +00:00
|
|
|
double pad_x = pad_pos.x * BOARD_SCALE;
|
|
|
|
double pad_y = pad_pos.y * BOARD_SCALE;
|
2014-01-06 20:14:24 +00:00
|
|
|
wxSize pad_delta = aPad->GetDelta();
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
double pad_dx = pad_delta.x * BOARD_SCALE / 2.0;
|
|
|
|
double pad_dy = pad_delta.y * BOARD_SCALE / 2.0;
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
double pad_w = aPad->GetSize().x * BOARD_SCALE / 2.0;
|
|
|
|
double pad_h = aPad->GetSize().y * BOARD_SCALE / 2.0;
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
switch( aPad->GetShape() )
|
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_CIRCLE:
|
2014-06-08 10:35:42 +00:00
|
|
|
|
|
|
|
if( !aTinLayer->AddCircle( pad_x, -pad_y, pad_w, false ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_OVAL:
|
2014-06-08 10:35:42 +00:00
|
|
|
|
|
|
|
if( !aTinLayer->AddSlot( pad_x, -pad_y, pad_w * 2.0, pad_h * 2.0,
|
|
|
|
aPad->GetOrientation()/10.0, false ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_RECT:
|
2014-01-06 20:14:24 +00:00
|
|
|
// Just to be sure :D
|
|
|
|
pad_dx = 0;
|
|
|
|
pad_dy = 0;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
2014-10-17 23:28:12 +00:00
|
|
|
{
|
|
|
|
double coord[8] =
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2014-10-17 23:28:12 +00:00
|
|
|
-pad_w + pad_dy, -pad_h - pad_dx,
|
|
|
|
-pad_w - pad_dy, pad_h + pad_dx,
|
|
|
|
+pad_w - pad_dy, -pad_h + pad_dx,
|
|
|
|
+pad_w + pad_dy, pad_h - pad_dx
|
|
|
|
};
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
RotatePoint( &coord[i * 2], &coord[i * 2 + 1], aPad->GetOrientation() );
|
|
|
|
coord[i * 2] += pad_x;
|
|
|
|
coord[i * 2 + 1] += pad_y;
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
int lines;
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
lines = aTinLayer->NewContour();
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
if( lines < 0 )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
if( !aTinLayer->AddVertex( lines, coord[0], -coord[1] ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
if( !aTinLayer->AddVertex( lines, coord[4], -coord[5] ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
if( !aTinLayer->AddVertex( lines, coord[6], -coord[7] ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
if( !aTinLayer->AddVertex( lines, coord[2], -coord[3] ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
|
|
|
|
|
|
|
if( !aTinLayer->EnsureWinding( lines, false ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
break;
|
2014-10-17 23:28:12 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
default:
|
2014-06-08 10:35:42 +00:00
|
|
|
break;
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void export_vrml_pad( MODEL_VRML& aModel, BOARD* pcb, D_PAD* aPad )
|
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
double hole_drill_w = (double) aPad->GetDrillSize().x * BOARD_SCALE / 2.0;
|
|
|
|
double hole_drill_h = (double) aPad->GetDrillSize().y * BOARD_SCALE / 2.0;
|
2014-10-17 23:28:12 +00:00
|
|
|
double hole_drill = std::min( hole_drill_w, hole_drill_h );
|
2016-09-17 06:14:49 +00:00
|
|
|
double hole_x = aPad->GetPosition().x * BOARD_SCALE;
|
|
|
|
double hole_y = aPad->GetPosition().y * BOARD_SCALE;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export the hole on the edge layer
|
2010-11-27 13:09:18 +00:00
|
|
|
if( hole_drill > 0 )
|
|
|
|
{
|
2014-06-16 12:02:15 +00:00
|
|
|
bool pth = false;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
if( ( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
|
2014-12-20 16:13:51 +00:00
|
|
|
&& !aModel.plainPCB )
|
2014-06-16 12:02:15 +00:00
|
|
|
pth = true;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Oblong hole (slot)
|
2014-06-16 12:02:15 +00:00
|
|
|
|
|
|
|
if( pth )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
aModel.holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0 + PLATE_OFFSET,
|
|
|
|
hole_drill_h * 2.0 + PLATE_OFFSET,
|
|
|
|
aPad->GetOrientation()/10.0, true, true );
|
|
|
|
|
2014-06-16 12:02:15 +00:00
|
|
|
aModel.plated_holes.AddSlot( hole_x, -hole_y,
|
2016-09-17 06:14:49 +00:00
|
|
|
hole_drill_w * 2.0, hole_drill_h * 2.0,
|
|
|
|
aPad->GetOrientation()/10.0, true, false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aModel.holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, hole_drill_h * 2.0,
|
|
|
|
aPad->GetOrientation()/10.0, true, false );
|
|
|
|
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Drill a round hole
|
2014-06-16 12:02:15 +00:00
|
|
|
|
|
|
|
if( pth )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
aModel.holes.AddCircle( hole_x, -hole_y, hole_drill + PLATE_OFFSET, true, true );
|
2014-06-16 12:02:15 +00:00
|
|
|
aModel.plated_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aModel.holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
|
|
|
|
}
|
2014-06-16 12:02:15 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
if( aModel.plainPCB )
|
|
|
|
return;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The pad proper, on the selected layers
|
2014-06-24 16:17:18 +00:00
|
|
|
LSET layer_mask = aPad->GetLayerSet();
|
2012-02-19 04:02:19 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer_mask[B_Cu] )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
export_vrml_padshape( aModel, &aModel.bot_tin, aPad );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer_mask[F_Cu] )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
export_vrml_padshape( aModel, &aModel.top_tin, aPad );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// From axis/rot to quaternion
|
2010-11-27 13:09:18 +00:00
|
|
|
static void build_quat( double x, double y, double z, double a, double q[4] )
|
|
|
|
{
|
|
|
|
double sina = sin( a / 2 );
|
|
|
|
|
|
|
|
q[0] = x * sina;
|
|
|
|
q[1] = y * sina;
|
|
|
|
q[2] = z * sina;
|
|
|
|
q[3] = cos( a / 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// From quaternion to axis/rot
|
2010-11-27 13:09:18 +00:00
|
|
|
static void from_quat( double q[4], double rot[4] )
|
|
|
|
{
|
|
|
|
rot[3] = acos( q[3] ) * 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
for( int i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
rot[i] = q[i] / sin( rot[3] / 2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Quaternion composition
|
2010-11-27 13:09:18 +00:00
|
|
|
static void compose_quat( double q1[4], double q2[4], double qr[4] )
|
|
|
|
{
|
|
|
|
double tmp[4];
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
tmp[0] = q2[3] * q1[0] + q2[0] * q1[3] + q2[1] * q1[2] - q2[2] * q1[1];
|
|
|
|
tmp[1] = q2[3] * q1[1] + q2[1] * q1[3] + q2[2] * q1[0] - q2[0] * q1[2];
|
|
|
|
tmp[2] = q2[3] * q1[2] + q2[2] * q1[3] + q2[0] * q1[1] - q2[1] * q1[0];
|
|
|
|
tmp[3] = q2[3] * q1[3] - q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2];
|
|
|
|
|
|
|
|
qr[0] = tmp[0];
|
|
|
|
qr[1] = tmp[1];
|
|
|
|
qr[2] = tmp[2];
|
|
|
|
qr[3] = tmp[3];
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-12-20 16:13:51 +00:00
|
|
|
if( !aModel.plainPCB )
|
|
|
|
{
|
|
|
|
// Reference and value
|
|
|
|
if( aModule->Reference().IsVisible() )
|
|
|
|
export_vrml_text_module( &aModule->Reference() );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
if( aModule->Value().IsVisible() )
|
|
|
|
export_vrml_text_module( &aModule->Value() );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
// Export module edges
|
|
|
|
for( EDA_ITEM* item = aModule->GraphicalItems(); item; item = item->Next() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-12-20 16:13:51 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
export_vrml_text_module( static_cast<TEXTE_MODULE*>( item ) );
|
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
export_vrml_edge_module( aModel, static_cast<EDGE_MODULE*>( item ),
|
|
|
|
aModule->GetOrientation() );
|
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-12-20 16:13:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export pads
|
2014-01-06 20:14:24 +00:00
|
|
|
for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() )
|
|
|
|
export_vrml_pad( aModel, aPcb, pad );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
bool isFlipped = aModule->GetLayer() == B_Cu;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export the object VRML model(s)
|
2016-07-19 17:35:25 +00:00
|
|
|
std::list<S3D_INFO>::iterator sM = aModule->Models().begin();
|
|
|
|
std::list<S3D_INFO>::iterator eM = aModule->Models().end();
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
wxFileName subdir( SUBDIR_3D, "" );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
while( sM != eM )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
SGNODE* mod3d = (SGNODE*) cache->Load( sM->m_Filename );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( NULL == mod3d )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
++sM;
|
2010-11-27 13:09:18 +00:00
|
|
|
continue;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
/* Calculate 3D shape rotation:
|
|
|
|
* this is the rotation parameters, with an additional 180 deg rotation
|
|
|
|
* for footprints that are flipped
|
|
|
|
* When flipped, axis rotation is the horizontal axis (X axis)
|
|
|
|
*/
|
|
|
|
double rotx = -sM->m_Rotation.x;
|
|
|
|
double roty = -sM->m_Rotation.y;
|
|
|
|
double rotz = -sM->m_Rotation.z;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( isFlipped )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
rotx += 180.0;
|
|
|
|
roty = -roty;
|
|
|
|
rotz = -rotz;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do some quaternion munching
|
|
|
|
double q1[4], q2[4], rot[4];
|
|
|
|
build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
|
|
|
|
build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
|
|
|
|
compose_quat( q1, q2, q1 );
|
|
|
|
build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 );
|
|
|
|
compose_quat( q1, q2, q1 );
|
|
|
|
|
|
|
|
// Note here aModule->GetOrientation() is in 0.1 degrees,
|
|
|
|
// so module rotation has to be converted to radians
|
|
|
|
build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 );
|
|
|
|
compose_quat( q1, q2, q1 );
|
|
|
|
from_quat( q1, rot );
|
|
|
|
|
|
|
|
// adjust 3D shape local offset position
|
|
|
|
// they are given in inch, so they are converted in board IU.
|
|
|
|
double offsetx = sM->m_Offset.x * IU_PER_MILS * 1000.0;
|
|
|
|
double offsety = sM->m_Offset.y * IU_PER_MILS * 1000.0;
|
|
|
|
double offsetz = sM->m_Offset.z * IU_PER_MILS * 1000.0;
|
|
|
|
|
|
|
|
if( isFlipped )
|
|
|
|
offsetz = -offsetz;
|
|
|
|
else // In normal mode, Y axis is reversed in Pcbnew.
|
|
|
|
offsety = -offsety;
|
|
|
|
|
|
|
|
RotatePoint( &offsetx, &offsety, aModule->GetOrientation() );
|
|
|
|
|
|
|
|
SGPOINT trans;
|
|
|
|
trans.x = ( offsetx + aModule->GetPosition().x ) * BOARD_SCALE + aModel.tx;
|
|
|
|
trans.y = -(offsety + aModule->GetPosition().y) * BOARD_SCALE - aModel.ty;
|
|
|
|
trans.z = (offsetz * BOARD_SCALE ) + aModel.GetLayerZ( aModule->GetLayer() );
|
|
|
|
|
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
wxFileName srcFile = cache->GetResolver()->ResolvePath( sM->m_Filename );
|
|
|
|
wxFileName dstFile;
|
|
|
|
dstFile.SetPath( SUBDIR_3D );
|
|
|
|
dstFile.SetName( srcFile.GetName() );
|
|
|
|
dstFile.SetExt( "wrl" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// copy the file if necessary
|
|
|
|
wxDateTime srcModTime = srcFile.GetModificationTime();
|
|
|
|
wxDateTime destModTime = srcModTime;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
destModTime.SetToCurrent();
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( dstFile.FileExists() )
|
|
|
|
destModTime = dstFile.GetModificationTime();
|
|
|
|
|
|
|
|
if( srcModTime != destModTime )
|
|
|
|
{
|
2016-09-23 07:55:33 +00:00
|
|
|
wxLogDebug( "Copying 3D model %s to %s.",
|
2016-09-17 06:14:49 +00:00
|
|
|
GetChars( srcFile.GetFullPath() ),
|
|
|
|
GetChars( dstFile.GetFullPath() ) );
|
|
|
|
|
|
|
|
wxString fileExt = srcFile.GetExt();
|
|
|
|
fileExt.LowerCase();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// copy VRML models and use the scenegraph library to
|
|
|
|
// translate other model types
|
|
|
|
if( fileExt == "wrl" )
|
|
|
|
{
|
|
|
|
if( !wxCopyFile( srcFile.GetFullPath(), dstFile.GetFullPath() ) )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, USE_DEFS, true ) )
|
2014-10-17 23:28:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
output_file << "Transform {\n";
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// only write a rotation if it is >= 0.1 deg
|
|
|
|
if( std::abs( rot[3] ) > 0.0001745 )
|
2014-10-17 23:28:12 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
output_file << " rotation " << std::setprecision( 5 );
|
|
|
|
output_file << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
|
2014-10-17 23:28:12 +00:00
|
|
|
}
|
2011-01-15 20:21:46 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
output_file << " translation " << std::setprecision( PRECISION );
|
|
|
|
output_file << trans.x << " ";
|
|
|
|
output_file << trans.y << " ";
|
|
|
|
output_file << trans.z << "\n";
|
2011-01-19 10:34:56 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
output_file << " scale ";
|
|
|
|
output_file << sM->m_Scale.x << " ";
|
|
|
|
output_file << sM->m_Scale.y << " ";
|
|
|
|
output_file << sM->m_Scale.z << "\n";
|
2011-01-15 20:21:46 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
output_file << " children [\n Inline {\n url \"";
|
2013-01-12 10:35:08 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( USE_RELPATH )
|
2014-10-17 23:28:12 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
wxFileName tmp = dstFile;
|
2016-09-23 07:55:33 +00:00
|
|
|
tmp.SetExt( "" );
|
|
|
|
tmp.SetName( "" );
|
2014-10-17 23:28:12 +00:00
|
|
|
tmp.RemoveLastDir();
|
2016-09-17 06:14:49 +00:00
|
|
|
dstFile.MakeRelativeTo( tmp.GetPath() );
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
2014-10-17 23:28:12 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
wxString fn = dstFile.GetFullPath();
|
2016-09-23 07:55:33 +00:00
|
|
|
fn.Replace( "\\", "/" );
|
2016-09-17 06:14:49 +00:00
|
|
|
output_file << TO_UTF8( fn ) << "\"\n } ]\n";
|
|
|
|
output_file << " }\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IFSG_TRANSFORM* modelShape = new IFSG_TRANSFORM( aModel.OutputPCB.GetRawPtr() );
|
|
|
|
|
|
|
|
// only write a rotation if it is >= 0.1 deg
|
|
|
|
if( std::abs( rot[3] ) > 0.0001745 )
|
|
|
|
modelShape->SetRotation( SGVECTOR( rot[0], rot[1], rot[2] ), rot[3] );
|
|
|
|
|
|
|
|
modelShape->SetTranslation( trans );
|
|
|
|
modelShape->SetScale( SGPOINT( sM->m_Scale.x, sM->m_Scale.y, sM->m_Scale.z ) );
|
|
|
|
|
|
|
|
if( NULL == S3D::GetSGNodeParent( mod3d ) )
|
|
|
|
{
|
|
|
|
aModel.components.push_back( mod3d );
|
|
|
|
modelShape->AddChildNode( mod3d );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
modelShape->AddRefNode( mod3d );
|
|
|
|
}
|
|
|
|
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
++sM;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMtoWRMLunit,
|
|
|
|
bool aExport3DFiles, bool aUseRelativePaths,
|
2015-08-13 13:13:34 +00:00
|
|
|
bool aUsePlainPCB, const wxString& a3D_Subdir,
|
|
|
|
double aXRef, double aYRef )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
BOARD* pcb = GetBoard();
|
|
|
|
bool ok = true;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
USE_INLINES = aExport3DFiles;
|
|
|
|
USE_DEFS = true;
|
|
|
|
USE_RELPATH = aUseRelativePaths;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
cache = Prj().Get3DCacheManager();
|
|
|
|
PROJ_DIR = Prj().GetProjectPath();
|
|
|
|
SUBDIR_3D = a3D_Subdir;
|
2014-01-06 20:14:24 +00:00
|
|
|
MODEL_VRML model3d;
|
2014-06-08 10:35:42 +00:00
|
|
|
model_vrml = &model3d;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( USE_INLINES )
|
|
|
|
BOARD_SCALE = MM_PER_IU / 2.54;
|
|
|
|
else
|
|
|
|
BOARD_SCALE = MM_PER_IU;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// Set the VRML world scale factor
|
|
|
|
model3d.SetScale( aMMtoWRMLunit );
|
2014-02-03 21:39:42 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// plain PCB or else PCB with copper and silkscreen
|
|
|
|
model3d.plainPCB = aUsePlainPCB;
|
|
|
|
// board reference point
|
|
|
|
model3d.SetOffset( -aXRef, aYRef );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// locale switch for C numeric output
|
|
|
|
LOCALE_IO* toggle = NULL;
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
try
|
|
|
|
{
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// Preliminary computation: the z value for each layer
|
2016-09-17 06:14:49 +00:00
|
|
|
compute_layer_Zs(model3d, pcb);
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// board edges and cutouts
|
2016-09-17 06:14:49 +00:00
|
|
|
export_vrml_board(model3d, pcb);
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// Drawing and text on the board
|
2014-12-20 16:13:51 +00:00
|
|
|
if( !aUsePlainPCB )
|
|
|
|
export_vrml_drawings( model3d, pcb );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// Export vias and trackage
|
|
|
|
export_vrml_tracks( model3d, pcb );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// Export zone fills
|
2014-12-20 16:13:51 +00:00
|
|
|
if( !aUsePlainPCB )
|
|
|
|
export_vrml_zones( model3d, pcb);
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
// check if the 3D Subdir exists - create if not
|
|
|
|
wxFileName subdir( SUBDIR_3D, "" );
|
|
|
|
|
|
|
|
if( ! subdir.DirExists() )
|
|
|
|
{
|
|
|
|
if( !wxDir::Make( subdir.GetFullPath() ) )
|
|
|
|
throw( std::runtime_error( "Could not create 3D model subdirectory" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle = new LOCALE_IO;
|
|
|
|
output_file.open( TO_UTF8( aFullFileName ), std::ios_base::out );
|
|
|
|
|
|
|
|
// Begin with the usual VRML boilerplate
|
|
|
|
wxString fn = aFullFileName;
|
2016-09-23 07:55:33 +00:00
|
|
|
fn.Replace( "\\" , "/" );
|
2016-09-17 06:14:49 +00:00
|
|
|
output_file << "#VRML V2.0 utf8\n";
|
|
|
|
output_file << "WorldInfo {\n";
|
|
|
|
output_file << " title \"" << TO_UTF8( fn ) << " - Generated by Pcbnew\"\n";
|
|
|
|
output_file << "}\n";
|
|
|
|
output_file << "Transform {\n";
|
|
|
|
output_file << " scale " << std::setprecision( PRECISION );
|
|
|
|
output_file << WORLD_SCALE << " ";
|
|
|
|
output_file << WORLD_SCALE << " ";
|
|
|
|
output_file << WORLD_SCALE << "\n";
|
|
|
|
|
|
|
|
// board reference point
|
|
|
|
model3d.SetOffset( -aXRef, aYRef );
|
|
|
|
|
|
|
|
output_file << " children [\n";
|
|
|
|
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// Export footprints
|
|
|
|
for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() )
|
2016-09-17 06:14:49 +00:00
|
|
|
export_vrml_module( model3d, pcb, module );
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2016-06-07 12:42:42 +00:00
|
|
|
// write out the board and all layers
|
2016-09-17 06:14:49 +00:00
|
|
|
write_layers( model3d, pcb, TO_UTF8( aFullFileName ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// Close the outer 'transform' node
|
2016-09-17 06:14:49 +00:00
|
|
|
if( USE_INLINES )
|
|
|
|
output_file << "]\n}\n";
|
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
}
|
|
|
|
catch( const std::exception& e )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg << _( "IDF Export Failed:\n" ) << FROM_UTF8( e.what() );
|
|
|
|
wxMessageBox( msg );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
ok = false;
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( USE_INLINES )
|
|
|
|
{
|
|
|
|
output_file.close();
|
|
|
|
|
|
|
|
if( toggle )
|
|
|
|
delete toggle;
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
return ok;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
static SGNODE* getSGColor( VRML_COLOR_INDEX colorIdx )
|
|
|
|
{
|
|
|
|
if( colorIdx == -1 )
|
|
|
|
colorIdx = VRML_COLOR_PCB;
|
|
|
|
else if( colorIdx == VRML_COLOR_LAST )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if( sgmaterial[colorIdx] )
|
|
|
|
return sgmaterial[colorIdx];
|
|
|
|
|
|
|
|
IFSG_APPEARANCE vcolor( (SGNODE*) NULL );
|
|
|
|
VRML_COLOR* cp = &colors[colorIdx];
|
|
|
|
|
|
|
|
vcolor.SetSpecular( cp->spec_red, cp->spec_grn, cp->spec_blu );
|
|
|
|
vcolor.SetDiffuse( cp->diffuse_red, cp->diffuse_grn, cp->diffuse_blu );
|
|
|
|
vcolor.SetShininess( cp->shiny );
|
|
|
|
// NOTE: XXX - replace with a better equation; using this definition
|
|
|
|
// of ambient will not yield the best results
|
|
|
|
vcolor.SetAmbient( cp->ambient, cp->ambient, cp->ambient );
|
|
|
|
vcolor.SetTransparency( cp->transp );
|
|
|
|
|
|
|
|
sgmaterial[colorIdx] = vcolor.GetRawPtr();
|
|
|
|
|
|
|
|
return sgmaterial[colorIdx];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
|
|
|
|
VRML_LAYER* layer, double top_z, bool aTopPlane )
|
|
|
|
{
|
|
|
|
std::vector< double > vertices;
|
|
|
|
std::vector< int > idxPlane;
|
|
|
|
std::vector< int > idxSide;
|
|
|
|
|
|
|
|
if( !(*layer).Get2DTriangles( vertices, idxPlane, top_z, aTopPlane ) )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] no vertex data";
|
|
|
|
wxLogDebug( "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
|
|
|
|
wxLogDebug( "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< SGPOINT > vlist;
|
|
|
|
size_t nvert = vertices.size() / 3;
|
|
|
|
size_t j = 0;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < nvert; ++i, j+= 3 )
|
|
|
|
vlist.push_back( SGPOINT( vertices[j], vertices[j+1], vertices[j+2] ) );
|
|
|
|
|
|
|
|
// create the intermediate scenegraph
|
|
|
|
IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
|
|
|
|
IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
|
|
|
|
IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
|
|
|
|
IFSG_COORDS cp( face ); // coordinates for all faces
|
|
|
|
cp.SetCoordsList( nvert, &vlist[0] );
|
|
|
|
IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
|
|
|
|
coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
|
|
|
|
IFSG_NORMALS norms( face ); // normals for the top and bottom planes
|
|
|
|
|
|
|
|
// set the normals
|
|
|
|
if( aTopPlane )
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < nvert; ++i )
|
|
|
|
norms.AddNormal( 0.0, 0.0, 1.0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < nvert; ++i )
|
|
|
|
norms.AddNormal( 0.0, 0.0, -1.0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign a color from the palette
|
|
|
|
SGNODE* modelColor = getSGColor( colorID );
|
|
|
|
|
|
|
|
if( NULL != modelColor )
|
|
|
|
{
|
|
|
|
if( NULL == S3D::GetSGNodeParent( modelColor ) )
|
|
|
|
shape.AddChildNode( modelColor );
|
|
|
|
else
|
|
|
|
shape.AddRefNode( modelColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
|
|
|
|
VRML_LAYER* layer, double top_z, double bottom_z )
|
|
|
|
{
|
|
|
|
std::vector< double > vertices;
|
|
|
|
std::vector< int > idxPlane;
|
|
|
|
std::vector< int > idxSide;
|
|
|
|
|
|
|
|
if( top_z < bottom_z )
|
|
|
|
{
|
|
|
|
double tmp = top_z;
|
|
|
|
top_z = bottom_z;
|
|
|
|
bottom_z = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !(*layer).Get3DTriangles( vertices, idxPlane, idxSide, top_z, bottom_z ) )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] no vertex data";
|
|
|
|
wxLogDebug( "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
|
|
|
|
wxLogDebug( "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< SGPOINT > vlist;
|
|
|
|
size_t nvert = vertices.size() / 3;
|
|
|
|
size_t j = 0;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < nvert; ++i, j+= 3 )
|
|
|
|
vlist.push_back( SGPOINT( vertices[j], vertices[j+1], vertices[j+2] ) );
|
|
|
|
|
|
|
|
// create the intermediate scenegraph
|
|
|
|
IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
|
|
|
|
IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
|
|
|
|
IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
|
|
|
|
IFSG_COORDS cp( face ); // coordinates for all faces
|
|
|
|
cp.SetCoordsList( nvert, &vlist[0] );
|
|
|
|
IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
|
|
|
|
coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
|
|
|
|
IFSG_NORMALS norms( face ); // normals for the top and bottom planes
|
|
|
|
|
|
|
|
// number of TOP (and bottom) vertices
|
|
|
|
j = nvert / 2;
|
|
|
|
|
|
|
|
// set the TOP normals
|
|
|
|
for( size_t i = 0; i < j; ++i )
|
|
|
|
norms.AddNormal( 0.0, 0.0, 1.0 );
|
|
|
|
|
|
|
|
// set the BOTTOM normals
|
|
|
|
for( size_t i = 0; i < j; ++i )
|
|
|
|
norms.AddNormal( 0.0, 0.0, -1.0 );
|
|
|
|
|
|
|
|
// assign a color from the palette
|
|
|
|
SGNODE* modelColor = getSGColor( colorID );
|
|
|
|
|
|
|
|
if( NULL != modelColor )
|
|
|
|
{
|
|
|
|
if( NULL == S3D::GetSGNodeParent( modelColor ) )
|
|
|
|
shape.AddChildNode( modelColor );
|
|
|
|
else
|
|
|
|
shape.AddRefNode( modelColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a second shape describing the vertical walls of the extrusion
|
|
|
|
// using per-vertex-per-face-normals
|
|
|
|
shape.NewNode( tx0 );
|
|
|
|
shape.AddRefNode( modelColor ); // set the color to be the same as the top/bottom
|
|
|
|
face.NewNode( shape );
|
|
|
|
cp.NewNode( face ); // new vertex list
|
|
|
|
norms.NewNode( face ); // new normals list
|
|
|
|
coordIdx.NewNode( face ); // new index list
|
|
|
|
|
|
|
|
// populate the new per-face vertex list and its indices and normals
|
|
|
|
std::vector< int >::iterator sI = idxSide.begin();
|
|
|
|
std::vector< int >::iterator eI = idxSide.end();
|
|
|
|
|
|
|
|
size_t sidx = 0; // index to the new coord set
|
|
|
|
SGPOINT p1, p2, p3;
|
|
|
|
SGVECTOR vnorm;
|
|
|
|
|
|
|
|
while( sI != eI )
|
|
|
|
{
|
|
|
|
p1 = vlist[*sI];
|
|
|
|
cp.AddCoord( p1 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
p2 = vlist[*sI];
|
|
|
|
cp.AddCoord( p2 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
p3 = vlist[*sI];
|
|
|
|
cp.AddCoord( p3 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
vnorm.SetVector( S3D::CalcTriNorm( p1, p2, p3 ) );
|
|
|
|
norms.AddNormal( vnorm );
|
|
|
|
norms.AddNormal( vnorm );
|
|
|
|
norms.AddNormal( vnorm );
|
|
|
|
|
|
|
|
coordIdx.AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
coordIdx.AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
coordIdx.AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|