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
|
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2004-2013 KiCad Developers, see change_log.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
|
|
|
|
*/
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <3d_struct.h>
|
|
|
|
#include <macros.h>
|
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <class_pcb_text.h>
|
2012-11-05 20:20:34 +00:00
|
|
|
#include <convert_from_iu.h>
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cmath>
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
// Number of segments to approximate a circle per segments:
|
|
|
|
#define SEGM_COUNT_PER_360 32
|
|
|
|
// basic angle to approximate a circle per segments
|
|
|
|
static const double INC_ANGLE = M_PI*2 / SEGM_COUNT_PER_360;
|
2012-06-19 19:25:41 +00:00
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
/* helper function:
|
|
|
|
* some characters cannot be used in names,
|
|
|
|
* this function change them to "_"
|
|
|
|
*/
|
|
|
|
static void ChangeIllegalCharacters( wxString & aFileName, bool aDirSepIsIllegal );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// I use this a lot...
|
2010-11-27 13:09:18 +00:00
|
|
|
static const double PI2 = M_PI / 2;
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
struct POINT_3D
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
double x, y, z;
|
|
|
|
};
|
2013-01-13 16:55:07 +00:00
|
|
|
|
|
|
|
struct POINT_2D
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
POINT_2D( double _x = 0, double _y = 0 ) : x( _x ), y( _y )
|
2012-06-19 19:25:41 +00:00
|
|
|
{ }
|
|
|
|
double x, y;
|
2010-11-27 13:09:18 +00:00
|
|
|
};
|
2013-01-13 16:55:07 +00:00
|
|
|
|
|
|
|
// Absolutely not optimized triangle bag :D
|
|
|
|
struct TRIANGLE
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
TRIANGLE( double x1, double y1, double z1,
|
2010-11-27 13:09:18 +00:00
|
|
|
double x2, double y2, double z2,
|
|
|
|
double x3, double y3, double z3 )
|
|
|
|
{
|
|
|
|
p1.x = x1; p1.y = y1; p1.z = z1;
|
|
|
|
p2.x = x2; p2.y = y2; p2.z = z2;
|
|
|
|
p3.x = x3; p3.y = y3; p3.z = z3;
|
|
|
|
}
|
2013-01-13 16:55:07 +00:00
|
|
|
TRIANGLE() { }
|
|
|
|
POINT_3D p1, p2, p3;
|
2010-11-27 13:09:18 +00:00
|
|
|
};
|
2013-01-13 16:55:07 +00:00
|
|
|
typedef std::vector<TRIANGLE> TRIANGLEBAG;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// A flat triangle fan
|
2013-01-13 16:55:07 +00:00
|
|
|
struct FLAT_FAN
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
POINT_2D c;
|
|
|
|
std::vector<POINT_2D> pts;
|
2010-11-27 13:09:18 +00:00
|
|
|
void add( double x, double y )
|
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
pts.push_back( POINT_2D( x, y ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
void bag( int layer, bool close = true );
|
|
|
|
};
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// A flat quad ring
|
2013-01-13 16:55:07 +00:00
|
|
|
struct FLAT_RING
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
std::vector<POINT_2D> inner;
|
|
|
|
std::vector<POINT_2D> outer;
|
2010-11-27 13:09:18 +00:00
|
|
|
void add_inner( double x, double y )
|
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
inner.push_back( POINT_2D( x, y ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void add_outer( double x, double y )
|
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
outer.push_back( POINT_2D( x, y ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bag( int layer, bool close = true );
|
|
|
|
};
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// A vertical quad loop
|
2010-11-27 13:09:18 +00:00
|
|
|
struct VLoop
|
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
std::vector<POINT_2D> pts;
|
2010-11-27 13:09:18 +00:00
|
|
|
double z_top, z_bottom;
|
|
|
|
void add( double x, double y )
|
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
pts.push_back( POINT_2D( x, y ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
void bag( TRIANGLEBAG& triangles, bool close = true );
|
2010-11-27 13:09:18 +00:00
|
|
|
};
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The bags for all the layers
|
2013-01-13 16:55:07 +00:00
|
|
|
static TRIANGLEBAG layer_triangles[LAYER_COUNT];
|
|
|
|
static TRIANGLEBAG via_triangles[4];
|
2010-11-27 13:09:18 +00:00
|
|
|
static double layer_z[LAYER_COUNT];
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void bag_flat_triangle( int layer, //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
double x1, double y1,
|
|
|
|
double x2, double y2,
|
|
|
|
double x3, double y3 )
|
|
|
|
{
|
|
|
|
double z = layer_z[layer];
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
layer_triangles[layer].push_back( TRIANGLE( x1, y1, z, x2, y2, z, x3, y3, z ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
void FLAT_FAN::bag( int layer, bool close ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for( i = 0; i < pts.size() - 1; i++ )
|
2011-09-07 19:41:04 +00:00
|
|
|
bag_flat_triangle( layer, c.x, c.y, pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
if( close )
|
2011-09-07 19:41:04 +00:00
|
|
|
bag_flat_triangle( layer, c.x, c.y, pts[i].x, pts[i].y, pts[0].x, pts[0].y );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void bag_flat_quad( int layer, //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
double x1, double y1,
|
|
|
|
double x2, double y2,
|
|
|
|
double x3, double y3,
|
|
|
|
double x4, double y4 )
|
|
|
|
{
|
|
|
|
bag_flat_triangle( layer, x1, y1, x3, y3, x2, y2 );
|
|
|
|
bag_flat_triangle( layer, x2, y2, x3, y3, x4, y4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
void FLAT_RING::bag( int layer, bool close ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for( i = 0; i < inner.size() - 1; i++ )
|
|
|
|
bag_flat_quad( layer,
|
|
|
|
inner[i].x, inner[i].y,
|
|
|
|
outer[i].x, outer[i].y,
|
|
|
|
inner[i + 1].x, inner[i + 1].y,
|
|
|
|
outer[i + 1].x, outer[i + 1].y );
|
|
|
|
|
|
|
|
if( close )
|
|
|
|
bag_flat_quad( layer,
|
|
|
|
inner[i].x, inner[i].y,
|
|
|
|
outer[i].x, outer[i].y,
|
|
|
|
inner[0].x, inner[0].y,
|
|
|
|
outer[0].x, outer[0].y );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
static void bag_vquad( TRIANGLEBAG& triangles, //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
double x1, double y1, double x2, double y2,
|
|
|
|
double z1, double z2 )
|
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
triangles.push_back( TRIANGLE( x1, y1, z1,
|
2011-09-07 19:41:04 +00:00
|
|
|
x2, y2, z1,
|
|
|
|
x2, y2, z2 ) );
|
2013-01-13 16:55:07 +00:00
|
|
|
triangles.push_back( TRIANGLE( x1, y1, z1,
|
2011-09-07 19:41:04 +00:00
|
|
|
x2, y2, z2,
|
|
|
|
x1, y1, z2 ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
void VLoop::bag( TRIANGLEBAG& triangles, bool close ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for( i = 0; i < pts.size() - 1; i++ )
|
|
|
|
bag_vquad( triangles, pts[i].x, pts[i].y,
|
|
|
|
pts[i + 1].x, pts[i + 1].y,
|
|
|
|
z_top, z_bottom );
|
|
|
|
|
|
|
|
if( close )
|
|
|
|
bag_vquad( triangles, pts[i].x, pts[i].y,
|
|
|
|
pts[0].x, pts[0].y,
|
|
|
|
z_top, z_bottom );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void write_triangle_bag( FILE* output_file, int color_index, //{{{
|
2013-01-13 16:55:07 +00:00
|
|
|
const TRIANGLEBAG& triangles,
|
|
|
|
double boardIU2WRML )
|
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",
|
2012-02-19 04:02:19 +00:00
|
|
|
0, // Material marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" ambientIntensity 0.8\n",
|
|
|
|
" transparency 0.2\n",
|
|
|
|
" shininess 0.2\n",
|
|
|
|
" }\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",
|
2012-02-19 04:02:19 +00:00
|
|
|
0, // Coordinates marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" coordIndex [\n",
|
2012-02-19 04:02:19 +00:00
|
|
|
0, // Index marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" }\n",
|
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" ]\n",
|
|
|
|
"}\n",
|
2012-02-19 04:02:19 +00:00
|
|
|
0 // End marker
|
2010-11-27 13:09:18 +00:00
|
|
|
};
|
|
|
|
int marker_found = 0, lineno = 0;
|
|
|
|
|
|
|
|
while( marker_found < 4 )
|
|
|
|
{
|
|
|
|
if( shape_boiler[lineno] )
|
|
|
|
fputs( shape_boiler[lineno], output_file );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
marker_found++;
|
|
|
|
switch( marker_found )
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
case 1: // Material marker
|
2010-11-27 13:09:18 +00:00
|
|
|
fprintf( output_file,
|
|
|
|
" diffuseColor %g %g %g\n",
|
|
|
|
(double) ColorRefs[color_index].m_Red / 255.0,
|
|
|
|
(double) ColorRefs[color_index].m_Green / 255.0,
|
|
|
|
(double) ColorRefs[color_index].m_Blue / 255.0 );
|
|
|
|
fprintf( output_file,
|
|
|
|
" specularColor %g %g %g\n",
|
|
|
|
(double) ColorRefs[color_index].m_Red / 255.0,
|
|
|
|
(double) ColorRefs[color_index].m_Green / 255.0,
|
|
|
|
(double) ColorRefs[color_index].m_Blue / 255.0 );
|
|
|
|
fprintf( output_file,
|
|
|
|
" emissiveColor %g %g %g\n",
|
|
|
|
(double) ColorRefs[color_index].m_Red / 255.0,
|
|
|
|
(double) ColorRefs[color_index].m_Green / 255.0,
|
|
|
|
(double) ColorRefs[color_index].m_Blue / 255.0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Coordinates marker
|
2013-01-13 16:55:07 +00:00
|
|
|
for( TRIANGLEBAG::const_iterator i = triangles.begin();
|
2010-11-27 13:09:18 +00:00
|
|
|
i != triangles.end();
|
|
|
|
i++ )
|
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
fprintf( output_file, "%.8g %.8g %.8g\n",
|
|
|
|
i->p1.x * boardIU2WRML, -i->p1.y * boardIU2WRML,
|
|
|
|
i->p1.z * boardIU2WRML );
|
|
|
|
fprintf( output_file, "%.8g %.8g %.8g\n",
|
|
|
|
i->p2.x * boardIU2WRML, -i->p2.y * boardIU2WRML,
|
|
|
|
i->p2.z * boardIU2WRML );
|
|
|
|
fprintf( output_file, "%.8g %.8g %.8g\n",
|
|
|
|
i->p3.x * boardIU2WRML, -i->p3.y * boardIU2WRML,
|
|
|
|
i->p3.z * boardIU2WRML );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Index marker
|
|
|
|
// OK, that's sick ...
|
2010-11-27 13:09:18 +00:00
|
|
|
int j = 0;
|
2013-01-13 16:55:07 +00:00
|
|
|
for( TRIANGLEBAG::const_iterator i = triangles.begin();
|
2010-11-27 13:09:18 +00:00
|
|
|
i != triangles.end();
|
|
|
|
i++ )
|
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
fprintf( output_file, "%d %d %d -1\n", j, j + 1, j + 2 );
|
2010-11-27 13:09:18 +00:00
|
|
|
j += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lineno++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void compute_layer_Zs( BOARD* pcb ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
int copper_layers = pcb->GetCopperLayerCount( );
|
|
|
|
|
|
|
|
// We call it 'layer' thickness, but it's the whole board thickness!
|
2012-06-09 17:00:13 +00:00
|
|
|
double board_thickness = pcb->GetDesignSettings().GetBoardThickness();
|
2010-11-27 13:09:18 +00:00
|
|
|
double half_thickness = board_thickness / 2;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Compute each layer's Z value, more or less like the 3d view
|
2010-11-27 13:09:18 +00:00
|
|
|
for( int i = 0; i <= LAYER_N_FRONT; i++ )
|
|
|
|
{
|
|
|
|
if( i < copper_layers )
|
|
|
|
layer_z[i] = board_thickness * i / (copper_layers - 1) - half_thickness;
|
|
|
|
else
|
2012-02-19 04:02:19 +00:00
|
|
|
layer_z[i] = half_thickness; // The component layer...
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* To avoid rounding interference, we apply an epsilon to each
|
|
|
|
* successive layer */
|
2012-06-19 19:25:41 +00:00
|
|
|
const double epsilon_z = 1 * IU_PER_MILS; // That's 1 mils, about 1/50 mm
|
2010-11-27 13:09:18 +00:00
|
|
|
layer_z[SOLDERPASTE_N_BACK] = -half_thickness - epsilon_z * 4;
|
|
|
|
layer_z[ADHESIVE_N_BACK] = -half_thickness - epsilon_z * 3;
|
|
|
|
layer_z[SILKSCREEN_N_BACK] = -half_thickness - epsilon_z * 2;
|
|
|
|
layer_z[SOLDERMASK_N_BACK] = -half_thickness - epsilon_z;
|
|
|
|
layer_z[SOLDERMASK_N_FRONT] = half_thickness + epsilon_z;
|
|
|
|
layer_z[SILKSCREEN_N_FRONT] = half_thickness + epsilon_z * 2;
|
|
|
|
layer_z[ADHESIVE_N_FRONT] = half_thickness + epsilon_z * 3;
|
|
|
|
layer_z[SOLDERPASTE_N_FRONT] = half_thickness + epsilon_z * 4;
|
|
|
|
layer_z[DRAW_N] = half_thickness + epsilon_z * 5;
|
|
|
|
layer_z[COMMENT_N] = half_thickness + epsilon_z * 6;
|
|
|
|
layer_z[ECO1_N] = half_thickness + epsilon_z * 7;
|
|
|
|
layer_z[ECO2_N] = half_thickness + epsilon_z * 8;
|
|
|
|
layer_z[EDGE_N] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void export_vrml_line( int layer, double startx, double starty, //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
double endx, double endy, double width, int divisions )
|
|
|
|
{
|
|
|
|
double r = width / 2;
|
|
|
|
double angle = atan2( endy - starty, endx - startx );
|
|
|
|
double alpha;
|
2013-01-13 16:55:07 +00:00
|
|
|
FLAT_FAN fan;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Output the 'bone' as a triangle fan, this is the fan centre
|
2010-11-27 13:09:18 +00:00
|
|
|
fan.c.x = (startx + endx) / 2;
|
|
|
|
fan.c.y = (starty + endy) / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The 'end' side cap
|
2010-11-27 13:09:18 +00:00
|
|
|
for( alpha = angle - PI2; alpha < angle + PI2; alpha += PI2 / divisions )
|
|
|
|
fan.add( endx + r * cos( alpha ), endy + r * sin( alpha ) );
|
|
|
|
|
|
|
|
alpha = angle + PI2;
|
|
|
|
fan.add( endx + r * cos( alpha ), endy + r * sin( alpha ) );
|
2012-02-19 04:02:19 +00:00
|
|
|
// The 'start' side cap
|
2010-11-27 13:09:18 +00:00
|
|
|
for( alpha = angle + PI2; alpha < angle + 3 * PI2; alpha += PI2 / divisions )
|
|
|
|
fan.add( startx + r * cos( alpha ), starty + r * sin( alpha ) );
|
|
|
|
|
|
|
|
alpha = angle + 3 * PI2;
|
|
|
|
fan.add( startx + r * cos( alpha ), starty + r * sin( alpha ) );
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export the fan
|
2010-11-27 13:09:18 +00:00
|
|
|
fan.bag( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 19:25:41 +00:00
|
|
|
static void export_vrml_circle( int layer, double startx, double starty,
|
|
|
|
double endx, double endy, double width )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
double hole, radius;
|
2013-01-13 16:55:07 +00:00
|
|
|
FLAT_RING ring;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
radius = hypot( startx - endx, starty - endy ) + ( width / 2);
|
|
|
|
hole = radius - width;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
for( double alpha = 0; alpha < M_PI * 2; alpha += INC_ANGLE )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
ring.add_inner( startx + hole * cos( alpha ), starty + hole * sin( alpha ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
ring.add_outer( startx + radius * cos( alpha ), starty + radius * sin( alpha ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ring.bag( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
static void export_vrml_slot( TRIANGLEBAG& triangles, //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
int top_layer, int bottom_layer, double xc, double yc,
|
2012-06-19 19:25:41 +00:00
|
|
|
double dx, double dy, int orient )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
double capx, capy; // Cap center
|
2010-11-27 13:09:18 +00:00
|
|
|
VLoop loop;
|
2012-06-19 19:25:41 +00:00
|
|
|
int divisions = SEGM_COUNT_PER_360 / 2;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
loop.z_top = layer_z[top_layer];
|
|
|
|
loop.z_bottom = layer_z[bottom_layer];
|
|
|
|
double angle = orient / 1800.0 * M_PI;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( dy > dx )
|
|
|
|
{
|
|
|
|
EXCHG( dx, dy );
|
|
|
|
angle += PI2;
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The exchange above means that cutter radius is alvays dy/2
|
2010-11-27 13:09:18 +00:00
|
|
|
double r = dy / 2;
|
|
|
|
double alpha;
|
2012-02-19 04:02:19 +00:00
|
|
|
// The first side cap
|
2010-11-27 13:09:18 +00:00
|
|
|
capx = xc + cos( angle ) * dx / 2;
|
|
|
|
capy = yc + sin( angle ) * dx / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
for( alpha = angle - PI2; alpha < angle + PI2; alpha += PI2 / divisions )
|
|
|
|
loop.add( capx + r * cos( alpha ), capy + r * sin( alpha ) );
|
|
|
|
|
|
|
|
alpha = angle + PI2;
|
|
|
|
loop.add( capx + r * cos( alpha ), capy + r * sin( alpha ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The other side cap
|
2010-11-27 13:09:18 +00:00
|
|
|
capx = xc - cos( angle ) * dx / 2;
|
|
|
|
capy = yc - sin( angle ) * dx / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
for( alpha = angle + PI2; alpha < angle + 3 * PI2; alpha += PI2 / divisions )
|
|
|
|
loop.add( capx + r * cos( alpha ), capy + r * sin( alpha ) );
|
|
|
|
|
|
|
|
alpha = angle + 3 * PI2;
|
|
|
|
loop.add( capx + r * cos( alpha ), capy + r * sin( alpha ) );
|
|
|
|
loop.bag( triangles );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
static void export_vrml_hole( TRIANGLEBAG& triangles,
|
|
|
|
int top_layer, int bottom_layer,
|
2012-06-19 19:25:41 +00:00
|
|
|
double xc, double yc, double hole )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
VLoop loop;
|
|
|
|
|
|
|
|
loop.z_top = layer_z[top_layer];
|
|
|
|
loop.z_bottom = layer_z[bottom_layer];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
for( double alpha = 0; alpha < M_PI * 2; alpha += INC_ANGLE )
|
2010-11-27 13:09:18 +00:00
|
|
|
loop.add( xc + cos( alpha ) * hole, yc + sin( alpha ) * hole );
|
|
|
|
|
|
|
|
loop.bag( triangles );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 19:25:41 +00:00
|
|
|
static void export_vrml_oval_pad( int layer, double xc, double yc,
|
|
|
|
double dx, double dy, int orient )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
double capx, capy; // Cap center
|
2013-01-13 16:55:07 +00:00
|
|
|
FLAT_FAN fan;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
fan.c.x = xc;
|
|
|
|
fan.c.y = yc;
|
|
|
|
double angle = orient / 1800.0 * M_PI;
|
2012-06-19 19:25:41 +00:00
|
|
|
int divisions = SEGM_COUNT_PER_360 / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( dy > dx )
|
|
|
|
{
|
|
|
|
EXCHG( dx, dy );
|
|
|
|
angle += PI2;
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The exchange above means that cutter radius is alvays dy/2
|
2010-11-27 13:09:18 +00:00
|
|
|
double r = dy / 2;
|
|
|
|
double alpha;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The first side cap
|
2010-11-27 13:09:18 +00:00
|
|
|
capx = xc + cos( angle ) * dx / 2;
|
|
|
|
capy = yc + sin( angle ) * dx / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
for( alpha = angle - PI2; alpha < angle + PI2; alpha += PI2 / divisions )
|
|
|
|
fan.add( capx + r * cos( alpha ), capy + r * sin( alpha ) );
|
|
|
|
|
|
|
|
alpha = angle + PI2;
|
|
|
|
fan.add( capx + r * cos( alpha ), capy + r * sin( alpha ) );
|
2012-02-19 04:02:19 +00:00
|
|
|
// The other side cap
|
2010-11-27 13:09:18 +00:00
|
|
|
capx = xc - cos( angle ) * dx / 2;
|
|
|
|
capy = yc - sin( angle ) * dx / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
for( alpha = angle + PI2; alpha < angle + 3 * PI2; alpha += PI2 / divisions )
|
|
|
|
fan.add( capx + r * cos( alpha ), capy + r * sin( alpha ) );
|
|
|
|
|
|
|
|
alpha = angle + 3 * PI2;
|
|
|
|
fan.add( capx + r * cos( alpha ), capy + r * sin( alpha ) );
|
|
|
|
fan.bag( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 19:25:41 +00:00
|
|
|
static void export_vrml_arc( int layer, double centerx, double centery,
|
|
|
|
double arc_startx, double arc_starty,
|
|
|
|
double width, double arc_angle )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
FLAT_RING ring;
|
2012-06-19 19:25:41 +00:00
|
|
|
double start_angle = atan2( arc_starty - centery, arc_startx - centerx );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-06-19 19:25:41 +00:00
|
|
|
int count = KiROUND( arc_angle / 360.0 * SEGM_COUNT_PER_360 );
|
|
|
|
if( count < 0 )
|
|
|
|
count = -count;
|
|
|
|
if( count == 0 )
|
|
|
|
count = 1;
|
|
|
|
double divisions = arc_angle*M_PI/180.0 / count;
|
|
|
|
|
|
|
|
double outer_radius = hypot( arc_starty - centery, arc_startx - centerx )
|
|
|
|
+ ( width / 2);
|
|
|
|
double inner_radius = outer_radius - width;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-06-19 19:25:41 +00:00
|
|
|
double alpha = 0;
|
|
|
|
for( int ii = 0; ii <= count; alpha += divisions, ii++ )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-06-19 19:25:41 +00:00
|
|
|
double angle_rot = start_angle + alpha;
|
|
|
|
ring.add_inner( centerx + cos( angle_rot ) * inner_radius,
|
|
|
|
centery + sin( angle_rot ) * inner_radius );
|
|
|
|
ring.add_outer( centerx + cos( angle_rot ) * outer_radius,
|
|
|
|
centery + sin( angle_rot ) * outer_radius );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ring.bag( layer, false );
|
|
|
|
}
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
static void export_vrml_varc( TRIANGLEBAG& triangles,
|
2012-06-19 19:25:41 +00:00
|
|
|
int top_layer, int bottom_layer,
|
|
|
|
double centerx, double centery,
|
|
|
|
double arc_startx, double arc_starty,
|
|
|
|
double arc_angle )
|
|
|
|
{
|
|
|
|
VLoop loop;
|
|
|
|
|
|
|
|
loop.z_top = layer_z[top_layer];
|
|
|
|
loop.z_bottom = layer_z[bottom_layer];
|
|
|
|
|
|
|
|
double start_angle = atan2( arc_starty - centery, arc_startx - centerx );
|
|
|
|
double radius = hypot( arc_starty - centery, arc_startx - centerx );
|
|
|
|
|
|
|
|
int count = KiROUND( arc_angle / 360.0 * SEGM_COUNT_PER_360 );
|
|
|
|
if( count < 0 )
|
|
|
|
count = -count;
|
|
|
|
if( count == 0 )
|
|
|
|
count = 1;
|
|
|
|
double divisions = arc_angle*M_PI/180.0 / count;
|
|
|
|
|
|
|
|
double alpha = 0;
|
|
|
|
for( int ii = 0; ii <= count; alpha += divisions, ii++ )
|
|
|
|
{
|
|
|
|
double angle_rot = start_angle + alpha;
|
|
|
|
loop.add( centerx + cos( angle_rot ) * radius, centery + sin( angle_rot ) * radius );
|
|
|
|
}
|
|
|
|
|
|
|
|
loop.bag( triangles );
|
|
|
|
}
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void export_vrml_drawsegment( DRAWSEGMENT* drawseg ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
int layer = drawseg->GetLayer();
|
2011-12-14 04:29:25 +00:00
|
|
|
double w = drawseg->GetWidth();
|
|
|
|
double x = drawseg->GetStart().x;
|
|
|
|
double y = drawseg->GetStart().y;
|
|
|
|
double xf = drawseg->GetEnd().x;
|
|
|
|
double yf = drawseg->GetEnd().y;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Items on the edge layer are high, not thick
|
2010-11-27 13:09:18 +00:00
|
|
|
if( layer == EDGE_N )
|
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
switch( drawseg->GetShape() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// There is a special 'varc' primitive for this
|
2010-11-27 13:09:18 +00:00
|
|
|
case S_ARC:
|
|
|
|
export_vrml_varc( layer_triangles[layer],
|
|
|
|
FIRST_COPPER_LAYER, LAST_COPPER_LAYER,
|
2012-06-19 19:25:41 +00:00
|
|
|
x, y, xf, yf, drawseg->GetAngle()/10 );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Circles on edge are usually important holes
|
2010-11-27 13:09:18 +00:00
|
|
|
case S_CIRCLE:
|
|
|
|
export_vrml_hole( layer_triangles[layer],
|
|
|
|
FIRST_COPPER_LAYER, LAST_COPPER_LAYER, x, y,
|
2012-06-19 19:25:41 +00:00
|
|
|
hypot( xf - x, yf - y ) / 2 );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Simply a quad
|
2010-11-27 13:09:18 +00:00
|
|
|
double z_top = layer_z[FIRST_COPPER_LAYER];
|
|
|
|
double z_bottom = layer_z[LAST_COPPER_LAYER];
|
|
|
|
bag_vquad( layer_triangles[layer], x, y, xf, yf, z_top, z_bottom );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
switch( drawseg->GetShape() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
case S_ARC:
|
2012-06-19 19:25:41 +00:00
|
|
|
export_vrml_arc( layer,
|
|
|
|
(double) drawseg->GetCenter().x,
|
|
|
|
(double) drawseg->GetCenter().y,
|
|
|
|
(double) drawseg->GetArcStart().x,
|
|
|
|
(double) drawseg->GetArcStart().y,
|
|
|
|
w, drawseg->GetAngle()/10 );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
2012-06-19 19:25:41 +00:00
|
|
|
export_vrml_circle( layer, x, y, xf, yf, w );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
export_vrml_line( layer, x, y, xf, yf, w, 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* C++ doesn't have closures and neither continuation forms... this is
|
|
|
|
* for coupling the vrml_text_callback with the common parameters */
|
|
|
|
|
|
|
|
static int s_text_layer;
|
|
|
|
static int s_text_width;
|
|
|
|
static void vrml_text_callback( int x0, int y0, int xf, int yf )
|
|
|
|
{
|
|
|
|
export_vrml_line( s_text_layer, x0, y0, xf, yf, s_text_width, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
static void export_vrml_pcbtext( TEXTE_PCB* text )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Coupling by globals! Ewwww...
|
2010-11-27 13:09:18 +00:00
|
|
|
s_text_layer = text->GetLayer();
|
|
|
|
s_text_width = text->m_Thickness;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
wxSize size = text->m_Size;
|
|
|
|
if( text->m_Mirror )
|
|
|
|
NEGATE( size.x );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( text->m_MultilineAllowed )
|
|
|
|
{
|
|
|
|
wxPoint pos = text->m_Pos;
|
|
|
|
wxArrayString* list = wxStringSplit( text->m_Text, '\n' );
|
|
|
|
wxPoint offset;
|
|
|
|
|
|
|
|
offset.y = text->GetInterline();
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
RotatePoint( &offset, text->GetOrientation() );
|
2010-11-27 13:09:18 +00:00
|
|
|
for( unsigned i = 0; i<list->Count(); i++ )
|
|
|
|
{
|
|
|
|
wxString txt = list->Item( i );
|
2012-09-02 12:06:47 +00:00
|
|
|
DrawGraphicText( NULL, NULL, pos, BLACK,
|
2012-02-19 04:02:19 +00:00
|
|
|
txt, text->GetOrientation(), size,
|
2010-11-27 13:09:18 +00:00
|
|
|
text->m_HJustify, text->m_VJustify,
|
|
|
|
text->m_Thickness, text->m_Italic,
|
|
|
|
true,
|
|
|
|
vrml_text_callback );
|
|
|
|
pos += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete (list);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-02 12:06:47 +00:00
|
|
|
DrawGraphicText( NULL, NULL, text->m_Pos, BLACK,
|
2012-02-19 04:02:19 +00:00
|
|
|
text->m_Text, text->GetOrientation(), size,
|
2010-11-27 13:09:18 +00:00
|
|
|
text->m_HJustify, text->m_VJustify,
|
|
|
|
text->m_Thickness, text->m_Italic,
|
|
|
|
true,
|
|
|
|
vrml_text_callback );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void export_vrml_drawings( BOARD* pcb ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// draw graphic items
|
2010-12-08 20:12:46 +00:00
|
|
|
for( EDA_ITEM* drawing = pcb->m_Drawings; drawing != 0; drawing = drawing->Next() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
switch( drawing->Type() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_LINE_T:
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_drawsegment( (DRAWSEGMENT*) drawing );
|
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_TEXT_T:
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_pcbtext( (TEXTE_PCB*) drawing );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
static void export_round_padstack( BOARD* pcb, double x, double y,
|
|
|
|
double r,
|
2012-06-19 19:25:41 +00:00
|
|
|
int bottom_layer, int top_layer )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
int copper_layers = pcb->GetCopperLayerCount( );
|
|
|
|
|
|
|
|
for( int layer = bottom_layer; layer < copper_layers; layer++ )
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// The last layer is always the component one, unless it's single face
|
2010-11-27 13:09:18 +00:00
|
|
|
if( (layer > FIRST_COPPER_LAYER) && (layer == copper_layers - 1) )
|
|
|
|
layer = LAST_COPPER_LAYER;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( layer <= top_layer )
|
2012-06-19 19:25:41 +00:00
|
|
|
export_vrml_circle( layer, x, y, x + r / 2, y, r );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void export_vrml_via( BOARD* pcb, SEGVIA* via ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
double x, y, r, hole;
|
|
|
|
int top_layer, bottom_layer;
|
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
r = via->GetWidth() / 2;
|
2010-11-27 13:09:18 +00:00
|
|
|
hole = via->GetDrillValue() / 2;
|
2013-01-13 00:04:00 +00:00
|
|
|
x = via->GetStart().x;
|
|
|
|
y = via->GetStart().y;
|
2010-11-27 13:09:18 +00:00
|
|
|
via->ReturnLayerPair( &top_layer, &bottom_layer );
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export the via padstack
|
2012-06-19 19:25:41 +00:00
|
|
|
export_round_padstack( pcb, x, y, r, bottom_layer, top_layer );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-06-19 19:25:41 +00:00
|
|
|
// Drill a hole
|
2013-01-13 00:04:00 +00:00
|
|
|
export_vrml_hole( via_triangles[via->GetShape()], top_layer, bottom_layer, x, y, hole );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void export_vrml_tracks( BOARD* pcb ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
for( TRACK* track = pcb->m_Track; track != NULL; track = track->Next() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
if( track->Type() == PCB_VIA_T )
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_via( pcb, (SEGVIA*) track );
|
|
|
|
else
|
2013-01-13 00:04:00 +00:00
|
|
|
export_vrml_line( track->GetLayer(), track->GetStart().x, track->GetStart().y,
|
|
|
|
track->GetEnd().x, track->GetEnd().y, track->GetWidth(), 4 );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
/* not used? @todo complete
|
|
|
|
static void export_vrml_zones( BOARD* pcb )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2011-08-29 03:04:59 +00:00
|
|
|
// Export fill segments
|
2010-11-27 13:09:18 +00:00
|
|
|
for( SEGZONE* segzone = pcb->m_Zone;
|
|
|
|
segzone != 0;
|
|
|
|
segzone = segzone->Next() )
|
|
|
|
{
|
2011-08-29 03:04:59 +00:00
|
|
|
// Fill tracks are exported with low subdivisions
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segzone->Type() == PCB_ZONE_T )
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_line( segzone->GetLayer(), segzone->m_Start.x, segzone->m_Start.y,
|
|
|
|
segzone->m_End.x, segzone->m_End.y, segzone->m_Width, 1 );
|
|
|
|
}
|
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
// Export zone outlines
|
2010-11-27 13:09:18 +00:00
|
|
|
for( int i = 0; i < pcb->GetAreaCount(); i++ )
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = pcb->GetArea( i );
|
2011-08-29 03:04:59 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( ( zone->m_FilledPolysList.size() == 0 )
|
|
|
|
||( zone->m_ZoneMinThickness <= 1 ) )
|
|
|
|
continue;
|
2011-08-29 03:04:59 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
int width = zone->m_ZoneMinThickness;
|
|
|
|
if( width > 0 )
|
|
|
|
{
|
|
|
|
int imax = zone->m_FilledPolysList.size() - 1;
|
|
|
|
int layer = zone->GetLayer();
|
|
|
|
CPolyPt* firstcorner = &zone->m_FilledPolysList[0];
|
|
|
|
CPolyPt* begincorner = firstcorner;
|
2011-08-29 03:04:59 +00:00
|
|
|
|
|
|
|
// I'm not really positive about what he's doing here...
|
2010-11-27 13:09:18 +00:00
|
|
|
for( int ic = 1; ic <= imax; ic++ )
|
|
|
|
{
|
|
|
|
CPolyPt* endcorner = &zone->m_FilledPolysList[ic];
|
|
|
|
if( begincorner->utility == 0 ) // Draw only basic outlines, not extra segments
|
|
|
|
export_vrml_line( layer, begincorner->x, begincorner->y,
|
|
|
|
endcorner->x, endcorner->y, width, 1 );
|
|
|
|
if( (endcorner->end_contour) || (ic == imax) ) // the last corner of a filled area is found: draw it
|
|
|
|
{
|
|
|
|
if( endcorner->utility == 0 ) // Draw only basic outlines, not extra segments
|
|
|
|
export_vrml_line( layer, endcorner->x, endcorner->y,
|
|
|
|
firstcorner->x, firstcorner->y, width, 1 );
|
|
|
|
ic++;
|
2011-08-29 03:04:59 +00:00
|
|
|
|
|
|
|
// A new contour?
|
2010-11-27 13:09:18 +00:00
|
|
|
if( ic < imax - 1 )
|
|
|
|
begincorner = firstcorner = &zone->m_FilledPolysList[ic];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
begincorner = endcorner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-29 03:04:59 +00:00
|
|
|
*/
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +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
|
|
|
{
|
|
|
|
wxSize size = module->m_Size;
|
|
|
|
|
|
|
|
if( module->m_Mirror )
|
|
|
|
NEGATE( size.x ); // Text is mirrored
|
|
|
|
|
|
|
|
s_text_layer = module->GetLayer();
|
|
|
|
s_text_width = module->m_Thickness;
|
2012-09-02 12:06:47 +00:00
|
|
|
DrawGraphicText( NULL, NULL, module->m_Pos, BLACK,
|
2010-11-27 13:09:18 +00:00
|
|
|
module->m_Text, module->GetDrawRotation(), size,
|
|
|
|
module->m_HJustify, module->m_VJustify,
|
|
|
|
module->m_Thickness, module->m_Italic,
|
|
|
|
true,
|
|
|
|
vrml_text_callback );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 19:25:41 +00:00
|
|
|
static void export_vrml_edge_module( EDGE_MODULE* aOutline ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-06-19 19:25:41 +00:00
|
|
|
int layer = aOutline->GetLayer();
|
|
|
|
double x = aOutline->GetStart().x;
|
|
|
|
double y = aOutline->GetStart().y;
|
|
|
|
double xf = aOutline->GetEnd().x;
|
|
|
|
double yf = aOutline->GetEnd().y;
|
|
|
|
double w = aOutline->GetWidth();
|
|
|
|
|
|
|
|
switch( aOutline->GetShape() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
case S_ARC:
|
2012-06-19 19:25:41 +00:00
|
|
|
export_vrml_arc( layer, x, y, xf, yf, w, aOutline->GetAngle()/10 );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
2012-06-19 19:25:41 +00:00
|
|
|
export_vrml_circle( layer, x, y, xf, yf, w );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
export_vrml_line( layer, x, y, xf, yf, w, 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
static void export_vrml_pad( BOARD* pcb, D_PAD* aPad ) //{{{
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
double hole_drill_w = (double) aPad->GetDrillSize().x / 2;
|
|
|
|
double hole_drill_h = (double) aPad->GetDrillSize().y / 2;
|
2012-09-22 11:19:37 +00:00
|
|
|
double hole_drill = std::min( hole_drill_w, hole_drill_h );
|
2012-02-19 04:02:19 +00:00
|
|
|
double hole_x = aPad->GetPosition().x;
|
|
|
|
double hole_y = aPad->GetPosition().y;
|
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 )
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
if( aPad->GetDrillShape() == PAD_OVAL )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Oblong hole (slot)
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_slot( layer_triangles[EDGE_N],
|
|
|
|
FIRST_COPPER_LAYER, LAST_COPPER_LAYER,
|
2012-06-19 19:25:41 +00:00
|
|
|
hole_x, hole_y, hole_drill_w, hole_drill_h, aPad->GetOrientation() );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Drill a round hole
|
|
|
|
export_vrml_hole( layer_triangles[EDGE_N],
|
|
|
|
FIRST_COPPER_LAYER, LAST_COPPER_LAYER,
|
2012-06-19 19:25:41 +00:00
|
|
|
hole_x, hole_y, hole_drill );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The pad proper, on the selected layers
|
|
|
|
int layer_mask = aPad->GetLayerMask();
|
|
|
|
int copper_layers = pcb->GetCopperLayerCount( );
|
|
|
|
|
|
|
|
// The (maybe offseted) pad position
|
|
|
|
wxPoint pad_pos = aPad->ReturnShapePos();
|
|
|
|
double pad_x = pad_pos.x;
|
|
|
|
double pad_y = pad_pos.y;
|
|
|
|
wxSize pad_delta = aPad->GetDelta();
|
|
|
|
|
|
|
|
double pad_dx = pad_delta.x / 2;
|
|
|
|
double pad_dy = pad_delta.y / 2;
|
|
|
|
|
|
|
|
double pad_w = aPad->GetSize().x / 2;
|
|
|
|
double pad_h = aPad->GetSize().y / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
for( int layer = FIRST_COPPER_LAYER; layer < copper_layers; layer++ )
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// The last layer is always the component one, unless it's single face
|
2010-11-27 13:09:18 +00:00
|
|
|
if( (layer > FIRST_COPPER_LAYER) && (layer == copper_layers - 1) )
|
|
|
|
layer = LAST_COPPER_LAYER;
|
|
|
|
|
|
|
|
if( layer_mask & (1 << layer) )
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// OK, the pad is on this layer, export it
|
|
|
|
switch( aPad->GetShape() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
case PAD_CIRCLE:
|
|
|
|
export_vrml_circle( layer, pad_x, pad_y,
|
2012-06-19 19:25:41 +00:00
|
|
|
pad_x + pad_w / 2, pad_y, pad_w );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_OVAL:
|
2012-06-19 19:25:41 +00:00
|
|
|
export_vrml_oval_pad( layer, pad_x, pad_y,
|
|
|
|
pad_w * 2, pad_h * 2, aPad->GetOrientation() );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_RECT:
|
2012-02-19 04:02:19 +00:00
|
|
|
// Just to be sure :D
|
2010-11-27 13:09:18 +00:00
|
|
|
pad_dx = 0;
|
|
|
|
pad_dy = 0;
|
|
|
|
|
|
|
|
case PAD_TRAPEZOID:
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
int coord[8] =
|
|
|
|
{
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
KiROUND(-pad_w - pad_dy), KiROUND(+pad_h + pad_dx),
|
|
|
|
KiROUND(-pad_w + pad_dy), KiROUND(-pad_h - pad_dx),
|
|
|
|
KiROUND(+pad_w - pad_dy), KiROUND(+pad_h - pad_dx),
|
|
|
|
KiROUND(+pad_w + pad_dy), KiROUND(-pad_h + pad_dx),
|
2012-02-19 04:02:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
RotatePoint( &coord[i * 2], &coord[i * 2 + 1], aPad->GetOrientation() );
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
coord[i * 2] += KiROUND( pad_x );
|
|
|
|
coord[i * 2 + 1] += KiROUND( pad_y );
|
2012-02-19 04:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bag_flat_quad( layer, coord[0], coord[1],
|
|
|
|
coord[2], coord[3],
|
|
|
|
coord[4], coord[5],
|
|
|
|
coord[6], coord[7] );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
2012-02-19 04:02:19 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
default:
|
|
|
|
;
|
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];
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
|
2013-01-12 10:35:08 +00:00
|
|
|
FILE* aOutputFile,
|
|
|
|
double aVRMLModelsToBiu,
|
2013-01-13 16:55:07 +00:00
|
|
|
bool aExport3DFiles, const wxString & a3D_Subdir,
|
|
|
|
double boardIU2WRML )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Reference and value
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_text_module( aModule->m_Reference );
|
|
|
|
export_vrml_text_module( aModule->m_Value );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export module edges
|
2010-12-08 20:12:46 +00:00
|
|
|
for( EDA_ITEM* item = aModule->m_Drawings; item != NULL; item = item->Next() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_TEXT_T:
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_text_module( dynamic_cast<TEXTE_MODULE*>(item) );
|
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_EDGE_T:
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_edge_module( dynamic_cast<EDGE_MODULE*>(item) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export pads
|
|
|
|
for( D_PAD* pad = aModule->m_Pads; pad; pad = pad->Next() )
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_pad( aPcb, pad );
|
|
|
|
|
|
|
|
bool isFlipped = aModule->GetLayer() == LAYER_N_BACK;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export the object VRML model(s)
|
2011-09-07 19:41:04 +00:00
|
|
|
for( S3D_MASTER* vrmlm = aModule->m_3D_Drawings; vrmlm != 0; vrmlm = vrmlm->Next() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
wxString fname = vrmlm->m_Shape3DName;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( fname.IsEmpty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ! wxFileName::FileExists( fname ) )
|
|
|
|
{
|
|
|
|
wxFileName fn = fname;
|
|
|
|
fname = wxGetApp().FindLibraryPath( fn );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( fname.IsEmpty() ) // keep "short" name if full filemane not found
|
|
|
|
fname = vrmlm->m_Shape3DName;
|
|
|
|
}
|
|
|
|
|
|
|
|
fname.Replace(wxT("\\"), wxT("/" ) );
|
|
|
|
wxString source_fname = fname;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
if( aExport3DFiles ) // Change illegal characters in short filename
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2011-03-12 09:50:21 +00:00
|
|
|
ChangeIllegalCharacters( fname, true );
|
2010-11-27 13:09:18 +00:00
|
|
|
fname = a3D_Subdir + wxT("/") + fname;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( !wxFileExists( fname ) )
|
|
|
|
wxCopyFile( source_fname, fname );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
*/
|
2011-01-15 18:06:10 +00:00
|
|
|
double rotx = - vrmlm->m_MatRotation.x;
|
|
|
|
double roty = - vrmlm->m_MatRotation.y;
|
|
|
|
double rotz = - vrmlm->m_MatRotation.z;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if ( isFlipped )
|
2011-01-15 18:06:10 +00:00
|
|
|
{
|
|
|
|
rotx += 180.0;
|
|
|
|
NEGATE(roty);
|
|
|
|
NEGATE(rotz);
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Do some quaternion munching
|
2010-11-27 13:09:18 +00:00
|
|
|
double q1[4], q2[4], rot[4];
|
2011-01-15 18:06:10 +00:00
|
|
|
build_quat( 1, 0, 0, rotx / 180.0 * M_PI, q1 );
|
|
|
|
build_quat( 0, 1, 0, roty / 180.0 * M_PI, q2 );
|
2010-11-27 13:09:18 +00:00
|
|
|
compose_quat( q1, q2, q1 );
|
2011-01-15 18:06:10 +00:00
|
|
|
build_quat( 0, 0, 1, rotz / 180.0 * M_PI, q2 );
|
2010-11-27 13:09:18 +00:00
|
|
|
compose_quat( q1, q2, q1 );
|
2012-02-19 04:02:19 +00:00
|
|
|
// Note here aModule->GetOrientation() is in 0.1 degrees,
|
|
|
|
// so module rotation is aModule->GetOrientation() / 1800.0
|
|
|
|
build_quat( 0, 0, 1, aModule->GetOrientation() / 1800.0 * M_PI, q2 );
|
2010-11-27 13:09:18 +00:00
|
|
|
compose_quat( q1, q2, q1 );
|
|
|
|
from_quat( q1, rot );
|
|
|
|
|
|
|
|
fprintf( aOutputFile, "Transform {\n" );
|
2012-02-19 04:02:19 +00:00
|
|
|
// A null rotation would fail the acos!
|
2010-11-27 13:09:18 +00:00
|
|
|
if( rot[3] != 0.0 )
|
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
fprintf( aOutputFile, " rotation %g %g %g %g\n", rot[0], rot[1], rot[2], rot[3] );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-01-12 10:35:08 +00:00
|
|
|
// adjust 3D shape offset position
|
|
|
|
int offsetx = vrmlm->m_MatPosition.x;
|
|
|
|
int offsety = vrmlm->m_MatPosition.y;
|
|
|
|
double offsetz = vrmlm->m_MatPosition.z;
|
2011-01-15 20:21:46 +00:00
|
|
|
|
|
|
|
if ( isFlipped )
|
|
|
|
NEGATE(offsetz);
|
2011-01-19 10:34:56 +00:00
|
|
|
else // In normal mode, Y axis is reversed in Pcbnew.
|
|
|
|
NEGATE(offsety);
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
RotatePoint(&offsetx, &offsety, aModule->GetOrientation());
|
2011-01-15 20:21:46 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
fprintf( aOutputFile, " translation %g %g %g\n",
|
2013-01-13 16:55:07 +00:00
|
|
|
(double) (offsetx + aModule->m_Pos.x) * boardIU2WRML,
|
|
|
|
- (double)(offsety + aModule->m_Pos.y) * boardIU2WRML, // Y axis is reversed in Pcbnew
|
|
|
|
offsetz + layer_z[aModule->GetLayer()] * boardIU2WRML);
|
2013-01-12 10:35:08 +00:00
|
|
|
|
|
|
|
fprintf( aOutputFile, " scale %g %g %g\n",
|
|
|
|
vrmlm->m_MatScale.x * aVRMLModelsToBiu,
|
|
|
|
vrmlm->m_MatScale.y * aVRMLModelsToBiu,
|
|
|
|
vrmlm->m_MatScale.z * aVRMLModelsToBiu );
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
fprintf( aOutputFile,
|
2013-01-13 16:55:07 +00:00
|
|
|
// " children [\n Inline {\n url \"file://%s\"\n } ]\n",
|
2011-09-07 19:41:04 +00:00
|
|
|
" children [\n Inline {\n url \"%s\"\n } ]\n",
|
|
|
|
TO_UTF8( fname ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
fprintf( aOutputFile, " }\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
static void write_and_empty_triangle_bag( FILE* output_file, TRIANGLEBAG& triangles,
|
|
|
|
int color, double boardIU2WRML )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
if( !triangles.empty() )
|
|
|
|
{
|
2013-01-13 16:55:07 +00:00
|
|
|
write_triangle_bag( output_file, color, triangles, boardIU2WRML );
|
2010-11-27 13:09:18 +00:00
|
|
|
triangles.clear( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-13 16:55:07 +00:00
|
|
|
/* ExportVRML_File
|
2010-11-27 13:09:18 +00:00
|
|
|
* Creates the file(s) exporting current BOARD to a VRML file.
|
2013-01-13 16:55:07 +00:00
|
|
|
* aFullFileName = the full filename of the file to create
|
|
|
|
* aMMtoWRMLunit = the general WRML scaling factor. 1.0 to export in mm
|
2010-11-27 13:09:18 +00:00
|
|
|
* @param aExport3DFiles = true to copy 3D shapes in the subdir a3D_Subdir
|
2013-01-13 16:55:07 +00:00
|
|
|
* a3D_Subdir = sub directory where 3D shapes files are copied
|
2010-11-27 13:09:18 +00:00
|
|
|
* used only when aExport3DFiles == true
|
|
|
|
*/
|
2013-01-12 10:35:08 +00:00
|
|
|
/* Note1:
|
|
|
|
* When copying 3D shapes files, the new filename is build from
|
2010-11-27 13:09:18 +00:00
|
|
|
* the full path name, changing the separators by underscore.
|
|
|
|
* this is needed because files with the same shortname can exist in different directories
|
2013-01-12 10:35:08 +00:00
|
|
|
* Note 2:
|
|
|
|
* ExportVRML_File generates coordinates in board units (BIU) inside the file.
|
|
|
|
* (TODO: use mm inside the file)
|
|
|
|
* A general scale transform is applied to the whole file
|
|
|
|
* (1.0 to have the actual WRML unit im mm, 0.001 to have the actual WRML unit im meter
|
|
|
|
* Note 3:
|
|
|
|
* For 3D models built by a 3D modeler, the unit is 0,1 inch
|
|
|
|
* A specfic scale is applied to 3D models to convert them to BIU
|
|
|
|
*
|
2010-11-27 13:09:18 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName,
|
2013-01-12 10:35:08 +00:00
|
|
|
double aMMtoWRMLunit, bool aExport3DFiles,
|
2011-03-01 19:26:17 +00:00
|
|
|
const wxString & a3D_Subdir )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
FILE* output_file;
|
|
|
|
BOARD* pcb = GetBoard();
|
|
|
|
|
|
|
|
output_file = wxFopen( aFullFileName, wxT( "wt" ) );
|
|
|
|
if( output_file == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
|
|
|
|
SetLocaleTo_C_standard();
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Begin with the usual VRML boilerplate
|
2011-03-12 09:50:21 +00:00
|
|
|
wxString name = aFullFileName;
|
|
|
|
|
|
|
|
name.Replace(wxT("\\"), wxT("/" ) );
|
|
|
|
ChangeIllegalCharacters( name, false );
|
2010-11-27 13:09:18 +00:00
|
|
|
fprintf( output_file, "#VRML V2.0 utf8\n"
|
|
|
|
"WorldInfo {\n"
|
2011-09-30 18:15:37 +00:00
|
|
|
" title \"%s - Generated by Pcbnew\"\n"
|
2011-03-12 09:50:21 +00:00
|
|
|
"}\n", TO_UTF8( name ) );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2013-01-12 10:35:08 +00:00
|
|
|
/* The would be in BIU and not in meters, as the standard wants.
|
2010-11-27 13:09:18 +00:00
|
|
|
* It is trivial to embed everything in a transform node to
|
|
|
|
* fix it. For example here we build the world in inches...
|
|
|
|
*/
|
|
|
|
|
2013-01-12 10:35:08 +00:00
|
|
|
// Global VRML scale to export to a different scale.
|
|
|
|
// (aMMtoWRMLScale = 1.0 to export in mm)
|
|
|
|
double boardIU2WRML = aMMtoWRMLunit / MM_PER_IU;
|
2011-09-07 19:41:04 +00:00
|
|
|
fprintf( output_file, "Transform {\n" );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
/* Define the translation to have the board centre to the 2D axis origin
|
|
|
|
* more easy for rotations...
|
|
|
|
*/
|
++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
|
|
|
EDA_RECT bbbox = pcb->ComputeBoundingBox();
|
|
|
|
|
2013-01-12 10:35:08 +00:00
|
|
|
double dx = boardIU2WRML * bbbox.Centre().x;
|
|
|
|
double dy = boardIU2WRML * bbbox.Centre().y;
|
++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
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
fprintf( output_file, " translation %g %g 0.0\n", -dx, dy );
|
|
|
|
fprintf( output_file, " children [\n" );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Preliminary computation: the z value for each layer
|
2010-11-27 13:09:18 +00:00
|
|
|
compute_layer_Zs( pcb );
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Drawing and text on the board, and edges which are special
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_drawings( pcb );
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export vias and trackage
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_tracks( pcb );
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export zone fills
|
2010-11-27 13:09:18 +00:00
|
|
|
/* TODO export_vrml_zones(pcb);
|
|
|
|
*/
|
|
|
|
|
2013-01-12 10:35:08 +00:00
|
|
|
/* scaling factor to convert 3D models to board units (decimils)
|
|
|
|
* Usually we use Wings3D to create thems.
|
|
|
|
* One can consider the 3D units is 0.1 inch (2.54 mm)
|
|
|
|
* So the scaling factor from 0.1 inch to board units
|
2013-01-13 16:55:07 +00:00
|
|
|
* is 2.54 * aMMtoWRMLunit
|
2013-01-12 10:35:08 +00:00
|
|
|
*/
|
2013-01-13 16:55:07 +00:00
|
|
|
double wrml_3D_models_scaling_factor = 2.54 * aMMtoWRMLunit;
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export footprints
|
2011-09-07 19:41:04 +00:00
|
|
|
for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() )
|
2010-11-27 13:09:18 +00:00
|
|
|
export_vrml_module( pcb, module, output_file,
|
|
|
|
wrml_3D_models_scaling_factor,
|
2013-01-13 16:55:07 +00:00
|
|
|
aExport3DFiles, a3D_Subdir,
|
|
|
|
boardIU2WRML );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
/* Output the bagged triangles for each layer
|
|
|
|
* Each layer will be a separate shape */
|
|
|
|
for( int layer = 0; layer < LAYER_COUNT; layer++ )
|
|
|
|
write_and_empty_triangle_bag( output_file,
|
|
|
|
layer_triangles[layer],
|
2013-01-13 16:55:07 +00:00
|
|
|
pcb->GetLayerColor(layer),
|
|
|
|
boardIU2WRML );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Same thing for the via layers
|
2010-11-27 13:09:18 +00:00
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
write_and_empty_triangle_bag( output_file,
|
|
|
|
via_triangles[i],
|
2013-01-13 16:55:07 +00:00
|
|
|
pcb->GetVisibleElementColor( VIAS_VISIBLE + i ),
|
|
|
|
boardIU2WRML );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Close the outer 'transform' node
|
2010-11-27 13:09:18 +00:00
|
|
|
fputs( "]\n}\n", output_file );
|
|
|
|
|
|
|
|
// End of work
|
|
|
|
fclose( output_file );
|
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-12 09:50:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* some characters cannot be used in filenames,
|
|
|
|
* this function change them to "_"
|
|
|
|
*/
|
|
|
|
static void ChangeIllegalCharacters( wxString & aFileName, bool aDirSepIsIllegal )
|
|
|
|
{
|
|
|
|
if( aDirSepIsIllegal )
|
|
|
|
aFileName.Replace(wxT("/"), wxT("_" ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
aFileName.Replace(wxT(" "), wxT("_" ) );
|
|
|
|
aFileName.Replace(wxT(":"), wxT("_" ) );
|
|
|
|
}
|