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
|
2017-03-02 22:53:49 +00:00
|
|
|
* Copyright (C) 2014-2017 Cirilo Bernardo
|
2018-01-24 13:22:43 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2021-03-16 19:15:34 +00:00
|
|
|
* Copyright (C) 2004-2021 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
|
|
|
|
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"
|
2020-11-12 20:19:22 +00:00
|
|
|
#include "board.h"
|
2020-10-04 23:34:59 +00:00
|
|
|
#include "fp_shape.h"
|
2020-11-12 20:19:22 +00:00
|
|
|
#include "footprint.h"
|
2020-10-04 23:34:59 +00:00
|
|
|
#include "pcb_text.h"
|
2020-11-12 20:19:22 +00:00
|
|
|
#include "track.h"
|
2020-11-11 23:05:59 +00:00
|
|
|
#include "zone.h"
|
2016-09-17 06:14:49 +00:00
|
|
|
#include "convert_to_biu.h"
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2020-01-15 23:32:05 +00:00
|
|
|
#include <filename_resolver.h>
|
2016-09-17 06:14:49 +00:00
|
|
|
#include "plugins/3dapi/ifsg_all.h"
|
2017-03-02 22:53:49 +00:00
|
|
|
#include "streamwrapper.h"
|
2016-09-17 06:14:49 +00:00
|
|
|
#include "vrml_layer.h"
|
2018-01-29 20:58:58 +00:00
|
|
|
#include "pcb_edit_frame.h"
|
2021-01-10 19:28:15 +00:00
|
|
|
|
|
|
|
#include <bezier_curves.h>
|
2018-03-05 20:54:10 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2019-05-16 13:46:54 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2017-12-04 18:06:47 +00:00
|
|
|
#include <zone_filler.h>
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
#include <exporter_vrml.h>
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
MODEL_VRML::MODEL_VRML() :
|
|
|
|
m_OutputPCB( (SGNODE*) NULL )
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
m_ReuseDef = true;
|
|
|
|
m_precision = 6;
|
|
|
|
m_WorldScale = 1.0;
|
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
for( int ii = 0; ii < VRML_COLOR_LAST; ++ii )
|
|
|
|
m_sgmaterial[ii] = nullptr;
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
for( unsigned i = 0; i < arrayDim( m_layer_z ); ++i )
|
|
|
|
m_layer_z[i] = 0;
|
|
|
|
|
|
|
|
m_holes.GetArcParams( m_iMaxSeg, m_arcMinLen, m_arcMaxLen );
|
|
|
|
|
|
|
|
// this default only makes sense if the output is in mm
|
|
|
|
m_brd_thickness = 1.6;
|
|
|
|
|
|
|
|
// pcb green
|
2021-03-17 13:26:26 +00:00
|
|
|
vrml_colors_list[VRML_COLOR_PCB] = VRML_COLOR(
|
2021-03-16 19:15:34 +00:00
|
|
|
0.07f, 0.3f, 0.12f, 0.01f, 0.03f, 0.01f, 0.0f, 0.0f, 0.0f, 0.8f, 0.0f, 0.02f );
|
|
|
|
// copper color
|
2021-03-17 13:26:26 +00:00
|
|
|
vrml_colors_list[VRML_COLOR_COPPER] = VRML_COLOR(
|
2021-03-16 19:15:34 +00:00
|
|
|
0.72f, 0.45f, 0.2f, 0.01f, 0.05f, 0.01f, 0.0f, 0.0f, 0.0f, 0.8f, 0.0f, 0.02f );
|
|
|
|
// silkscreen white
|
2021-03-17 13:26:26 +00:00
|
|
|
vrml_colors_list[VRML_COLOR_SILK] = VRML_COLOR(
|
2021-03-16 19:15:34 +00:00
|
|
|
0.9f, 0.9f, 0.9f, 0.1f, 0.1f, 0.1f, 0.0f, 0.0f, 0.0f, 0.9f, 0.0f, 0.02f );
|
|
|
|
// solder paste silver
|
2021-03-18 13:40:36 +00:00
|
|
|
vrml_colors_list[VRML_COLOR_PASTE] = VRML_COLOR( 0.749f, 0.756f, 0.761f, 0.749f, 0.756f, 0.761f, 0.0f,
|
2021-03-16 19:15:34 +00:00
|
|
|
0.0f, 0.0f, 0.8f, 0.0f, 0.8f );
|
2021-03-18 13:40:36 +00:00
|
|
|
// solder mask green with transparency
|
|
|
|
vrml_colors_list[VRML_COLOR_SOLDMASK] = VRML_COLOR(
|
|
|
|
0.07f, 0.3f, 0.12f, 0.01f, 0.03f, 0.01f, 0.0f, 0.0f, 0.0f, 0.8f, 0.25f, 0.02f );
|
2021-03-16 19:15:34 +00:00
|
|
|
|
|
|
|
m_plainPCB = false;
|
|
|
|
SetOffset( 0.0, 0.0 );
|
|
|
|
m_text_layer = F_Cu;
|
|
|
|
m_text_width = 1;
|
|
|
|
m_minLineWidth = MIN_VRML_LINEWIDTH;
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
MODEL_VRML::~MODEL_VRML()
|
|
|
|
{
|
|
|
|
// destroy any unassociated material appearances
|
|
|
|
for( int j = 0; j < VRML_COLOR_LAST; ++j )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2021-03-18 12:28:24 +00:00
|
|
|
if( m_sgmaterial[j] && NULL == S3D::GetSGNodeParent( m_sgmaterial[j] ) )
|
|
|
|
S3D::DestroyNode( m_sgmaterial[j] );
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
m_sgmaterial[j] = NULL;
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( !m_components.empty() )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
IFSG_TRANSFORM tmp( false );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
for( auto i : m_components )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
tmp.Attach( i );
|
|
|
|
tmp.SetParent( NULL );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
m_components.clear();
|
|
|
|
m_OutputPCB.Destroy();
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2021-03-16 19:15:34 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
bool MODEL_VRML::SetScale( double aWorldScale )
|
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
// set the scaling of the VRML world
|
2021-03-16 19:15:34 +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)" ) );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
m_OutputPCB.SetScale( aWorldScale * 2.54 );
|
2021-03-17 13:26:26 +00:00
|
|
|
m_WorldScale = aWorldScale * 2.54;
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
void MODEL_VRML::SetOffset( double aXoff, double aYoff )
|
|
|
|
{
|
|
|
|
m_tx = aXoff;
|
|
|
|
m_ty = -aYoff;
|
|
|
|
|
|
|
|
m_holes.SetVertexOffsets( aXoff, aYoff );
|
2021-03-18 12:28:24 +00:00
|
|
|
m_3D_board.SetVertexOffsets( aXoff, aYoff );
|
2021-03-16 19:15:34 +00:00
|
|
|
m_top_copper.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_bot_copper.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_top_silk.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_bot_silk.SetVertexOffsets( aXoff, aYoff );
|
2021-03-18 13:40:36 +00:00
|
|
|
m_top_paste.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_bot_paste.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_top_soldermask.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_bot_soldermask.SetVertexOffsets( aXoff, aYoff );
|
2021-03-16 19:15:34 +00:00
|
|
|
m_plated_holes.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
bool MODEL_VRML::GetLayer3D( LAYER_NUM layer, VRML_LAYER** vlayer )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
// select the VRML layer object to draw on; return true if
|
|
|
|
// a layer has been selected.
|
2014-01-06 20:14:24 +00:00
|
|
|
switch( layer )
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
case B_Cu: *vlayer = &m_bot_copper; return true;
|
|
|
|
case F_Cu: *vlayer = &m_top_copper; return true;
|
|
|
|
case B_SilkS: *vlayer = &m_bot_silk; return true;
|
|
|
|
case F_SilkS: *vlayer = &m_top_silk; return true;
|
2021-03-18 13:40:36 +00:00
|
|
|
case B_Mask: *vlayer = &m_bot_soldermask; return true;
|
|
|
|
case F_Mask: *vlayer = &m_top_soldermask; return true;
|
|
|
|
case B_Paste: *vlayer = &m_bot_paste; return true;
|
|
|
|
case F_Paste: *vlayer = &m_top_paste; return true;
|
2021-03-16 19:15:34 +00:00
|
|
|
default: return false;
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlSolderMask()
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
SHAPE_POLY_SET holes, outlines = m_pcbOutlines;
|
|
|
|
// Build the solder mask opening. the actual shape is the negative shape
|
|
|
|
PCB_LAYER_ID layer = F_Mask;
|
|
|
|
VRML_LAYER* vrmllayer = &m_top_soldermask;
|
|
|
|
|
|
|
|
for( int lcnt = 0; lcnt < 2; lcnt++ )
|
|
|
|
{
|
|
|
|
holes.RemoveAllContours();
|
|
|
|
outlines.RemoveAllContours();
|
|
|
|
outlines = m_pcbOutlines;
|
|
|
|
m_Pcb->ConvertBrdLayerToPolygonalContours( layer, holes );
|
|
|
|
|
|
|
|
outlines.BooleanSubtract( holes, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
outlines.Fracture( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
ExportVrmlPolyPolygon( vrmllayer, outlines, 0.0, wxPoint( 0, 0 ) );
|
|
|
|
|
|
|
|
layer = B_Mask;
|
|
|
|
vrmllayer = &m_bot_soldermask;
|
|
|
|
}
|
2021-03-16 19:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static var. for dealing with text
|
|
|
|
static MODEL_VRML* model_vrml;
|
|
|
|
|
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
void MODEL_VRML::write_triangle_bag( std::ostream& aOut_file, const VRML_COLOR& aColor,
|
2016-10-20 11:20:49 +00:00
|
|
|
VRML_LAYER* aLayer, bool aPlane, bool aTop,
|
|
|
|
double aTop_z, double aBottom_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] )
|
2016-10-20 11:20:49 +00:00
|
|
|
aOut_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
|
2020-12-20 18:23:50 +00:00
|
|
|
{
|
|
|
|
std::streamsize lastPrecision = aOut_file.precision();
|
2016-10-20 11:20:49 +00:00
|
|
|
aOut_file << " diffuseColor " << std::setprecision(3);
|
|
|
|
aOut_file << aColor.diffuse_red << " ";
|
|
|
|
aOut_file << aColor.diffuse_grn << " ";
|
|
|
|
aOut_file << aColor.diffuse_blu << "\n";
|
|
|
|
|
|
|
|
aOut_file << " specularColor ";
|
|
|
|
aOut_file << aColor.spec_red << " ";
|
|
|
|
aOut_file << aColor.spec_grn << " ";
|
|
|
|
aOut_file << aColor.spec_blu << "\n";
|
|
|
|
|
|
|
|
aOut_file << " emissiveColor ";
|
|
|
|
aOut_file << aColor.emit_red << " ";
|
|
|
|
aOut_file << aColor.emit_grn << " ";
|
|
|
|
aOut_file << aColor.emit_blu << "\n";
|
|
|
|
|
|
|
|
aOut_file << " ambientIntensity " << aColor.ambient << "\n";
|
|
|
|
aOut_file << " transparency " << aColor.transp << "\n";
|
|
|
|
aOut_file << " shininess " << aColor.shiny << "\n";
|
2020-12-20 18:23:50 +00:00
|
|
|
aOut_file.precision( lastPrecision );
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-10-20 11:20:49 +00:00
|
|
|
if( aPlane )
|
2021-03-17 13:26:26 +00:00
|
|
|
aLayer->WriteVertices( aTop_z, aOut_file, m_precision );
|
2014-01-06 20:14:24 +00:00
|
|
|
else
|
2021-03-17 13:26:26 +00:00
|
|
|
aLayer->Write3DVertices( aTop_z, aBottom_z, aOut_file, m_precision );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-10-20 11:20:49 +00:00
|
|
|
aOut_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
|
|
|
|
2016-10-20 11:20:49 +00:00
|
|
|
if( aPlane )
|
|
|
|
aLayer->WriteIndices( aTop, aOut_file );
|
2014-01-06 20:14:24 +00:00
|
|
|
else
|
2016-10-20 11:20:49 +00:00
|
|
|
aLayer->Write3DIndices( aOut_file );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-10-20 11:20:49 +00:00
|
|
|
aOut_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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::writeLayers( const char* aFileName,
|
2021-03-17 13:26:26 +00:00
|
|
|
OSTREAM* aOutputFile )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
|
|
|
// VRML_LAYER board;
|
2021-03-18 12:28:24 +00:00
|
|
|
m_3D_board.Tesselate( &m_holes );
|
2021-03-17 13:26:26 +00:00
|
|
|
double brdz = m_brd_thickness / 2.0
|
|
|
|
- ( Millimeter2iu( ART_OFFSET / 2.0 ) ) * m_BoardToVrmlScale;
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PCB ),
|
2021-03-18 12:28:24 +00:00
|
|
|
&m_3D_board, false, false, brdz, -brdz );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 12:28:24 +00:00
|
|
|
create_vrml_shell( m_OutputPCB, VRML_COLOR_PCB, &m_3D_board, brdz, -brdz );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_plainPCB )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
if( !m_UseInlineModelsInBrdfile )
|
|
|
|
S3D::WriteVRML( aFileName, true, m_OutputPCB.GetRawPtr(), m_ReuseDef, true );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
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
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
// VRML_LAYER m_top_copper;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_top_copper.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_COPPER ),
|
|
|
|
&m_top_copper, true, true, GetLayerZ( F_Cu ), 0 );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_COPPER, &m_top_copper,
|
|
|
|
GetLayerZ( F_Cu ), true );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
// VRML_LAYER m_top_paste;
|
|
|
|
m_top_paste.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PASTE ),
|
|
|
|
&m_top_paste, true, true,
|
2021-03-17 13:26:26 +00:00
|
|
|
GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
2016-09-17 06:14:49 +00:00
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_PASTE, &m_top_paste,
|
|
|
|
GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
|
|
|
true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// VRML_LAYER m_top_soldermask;
|
|
|
|
m_top_soldermask.Tesselate( &m_holes );
|
|
|
|
|
|
|
|
if( m_UseInlineModelsInBrdfile )
|
|
|
|
{
|
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_SOLDMASK ),
|
|
|
|
&m_top_soldermask, true, true,
|
|
|
|
GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_SOLDMASK, &m_top_soldermask,
|
2021-03-17 13:26:26 +00:00
|
|
|
GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
2016-09-17 06:14:49 +00:00
|
|
|
true );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
// VRML_LAYER m_bot_copper;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_bot_copper.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_COPPER ),
|
|
|
|
&m_bot_copper, true, false, GetLayerZ( B_Cu ), 0 );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_COPPER, &m_bot_copper,
|
|
|
|
GetLayerZ( B_Cu ), false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
// VRML_LAYER m_bot_paste;
|
|
|
|
m_bot_paste.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PASTE ),
|
|
|
|
&m_bot_paste, true, false,
|
2021-03-17 13:26:26 +00:00
|
|
|
GetLayerZ( B_Cu )
|
|
|
|
- Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
2016-09-17 06:14:49 +00:00
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_PASTE, &m_bot_paste,
|
|
|
|
GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
|
|
|
false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// VRML_LAYER m_bot_mask:
|
|
|
|
m_bot_soldermask.Tesselate( &m_holes );
|
|
|
|
|
|
|
|
if( m_UseInlineModelsInBrdfile )
|
|
|
|
{
|
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_SOLDMASK ),
|
|
|
|
&m_bot_soldermask, true, false,
|
|
|
|
GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_SOLDMASK, &m_bot_soldermask,
|
2021-03-17 13:26:26 +00:00
|
|
|
GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
2016-09-17 06:14:49 +00:00
|
|
|
false );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-16 12:02:15 +00:00
|
|
|
// VRML_LAYER PTH;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_plated_holes.Tesselate( NULL, true );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PASTE ),
|
2021-03-17 13:26:26 +00:00
|
|
|
&m_plated_holes, false, false,
|
|
|
|
GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
|
|
|
GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
create_vrml_shell( m_OutputPCB, VRML_COLOR_PASTE, &m_plated_holes,
|
2021-03-17 13:26:26 +00:00
|
|
|
GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
|
|
|
GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-06-16 12:02:15 +00:00
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
// VRML_LAYER m_top_silk;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_top_silk.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_SILK ), &m_top_silk,
|
|
|
|
true, true, GetLayerZ( F_SilkS ), 0 );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_SILK, &m_top_silk,
|
|
|
|
GetLayerZ( F_SilkS ), true );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
// VRML_LAYER m_bot_silk;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_bot_silk.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_SILK ), &m_bot_silk,
|
|
|
|
true, false, GetLayerZ( B_SilkS ), 0 );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_SILK, &m_bot_silk,
|
|
|
|
GetLayerZ( B_SilkS ), false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( !m_UseInlineModelsInBrdfile )
|
|
|
|
S3D::WriteVRML( aFileName, true, m_OutputPCB.GetRawPtr(), true, true );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ComputeLayer3D_Zpos()
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
int copper_layers = m_Pcb->GetCopperLayerCount();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
// We call it 'layer' thickness, but it's the whole board thickness!
|
2021-03-18 13:40:36 +00:00
|
|
|
m_brd_thickness = m_Pcb->GetDesignSettings().GetBoardThickness() * m_BoardToVrmlScale;
|
2021-03-16 19:15:34 +00:00
|
|
|
double half_thickness = m_brd_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
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID i = *seq;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( i < copper_layers )
|
2021-03-16 19:15:34 +00:00
|
|
|
SetLayerZ( i, half_thickness - m_brd_thickness * i / (copper_layers - 1) );
|
2010-11-27 13:09:18 +00:00
|
|
|
else
|
2021-03-16 19:15:34 +00:00
|
|
|
SetLayerZ( i, - half_thickness ); // bottom layer
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
// To avoid rounding interference, we apply an epsilon to each successive layer
|
2021-03-17 13:26:26 +00:00
|
|
|
double epsilon_z = Millimeter2iu( ART_OFFSET ) * m_BoardToVrmlScale;
|
2021-03-18 13:40:36 +00:00
|
|
|
SetLayerZ( B_Paste, -half_thickness - epsilon_z );
|
|
|
|
SetLayerZ( B_Adhes, -half_thickness - epsilon_z );
|
|
|
|
SetLayerZ( B_SilkS, -half_thickness - epsilon_z * 3 );
|
|
|
|
SetLayerZ( B_Mask, -half_thickness - epsilon_z * 2 );
|
|
|
|
SetLayerZ( F_Mask, half_thickness + epsilon_z * 2 );
|
|
|
|
SetLayerZ( F_SilkS, half_thickness + epsilon_z * 3 );
|
|
|
|
SetLayerZ( F_Adhes, half_thickness + epsilon_z );
|
|
|
|
SetLayerZ( F_Paste, half_thickness + epsilon_z );
|
2021-03-16 19:15:34 +00:00
|
|
|
SetLayerZ( Dwgs_User, half_thickness + epsilon_z * 5 );
|
|
|
|
SetLayerZ( Cmts_User, half_thickness + epsilon_z * 6 );
|
|
|
|
SetLayerZ( Eco1_User, half_thickness + epsilon_z * 7 );
|
|
|
|
SetLayerZ( Eco2_User, half_thickness + epsilon_z * 8 );
|
|
|
|
SetLayerZ( Edge_Cuts, 0 );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
void MODEL_VRML::ExportVrmlLine( LAYER_NUM layer,
|
|
|
|
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
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( !GetLayer3D( layer, &vlayer ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( width < m_minLineWidth)
|
|
|
|
width = m_minLineWidth;
|
2014-06-08 10:35:42 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
void MODEL_VRML::ExportVrmlCircle( 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
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( !GetLayer3D( layer, &vlayer ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
return;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( width < m_minLineWidth )
|
|
|
|
width = m_minLineWidth;
|
2014-06-08 10:35:42 +00:00
|
|
|
|
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
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
void MODEL_VRML::ExportVrmlArc( 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
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( !GetLayer3D( layer, &vlayer ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
return;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( width < m_minLineWidth )
|
|
|
|
width = m_minLineWidth;
|
2014-06-08 10:35:42 +00:00
|
|
|
|
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
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
void MODEL_VRML::ExportVrmlPolygon( LAYER_NUM layer, PCB_SHAPE *aOutline,
|
|
|
|
double aOrientation, wxPoint aPos )
|
2018-04-24 16:19:28 +00:00
|
|
|
{
|
|
|
|
if( aOutline->IsPolyShapeValid() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET shape = aOutline->GetPolyShape();
|
|
|
|
VRML_LAYER* vlayer;
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( !GetLayer3D( layer, &vlayer ) )
|
2018-04-24 16:19:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( aOutline->GetWidth() )
|
|
|
|
{
|
2020-09-10 23:05:20 +00:00
|
|
|
int numSegs = GetArcToSegmentCount( aOutline->GetWidth() / 2, ARC_HIGH_DEF, 360.0 );
|
2019-05-16 13:46:54 +00:00
|
|
|
shape.Inflate( aOutline->GetWidth() / 2, numSegs );
|
2018-04-24 16:19:28 +00:00
|
|
|
shape.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
}
|
|
|
|
|
|
|
|
shape.Rotate( -aOrientation, VECTOR2I( 0, 0 ) );
|
|
|
|
shape.Move( aPos );
|
|
|
|
const SHAPE_LINE_CHAIN& outline = shape.COutline( 0 );
|
|
|
|
|
|
|
|
int seg = vlayer->NewContour();
|
|
|
|
|
|
|
|
for( int j = 0; j < outline.PointCount(); j++ )
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
if( !vlayer->AddVertex( seg, outline.CPoint( j ).x * m_BoardToVrmlScale,
|
|
|
|
-outline.CPoint( j ).y * m_BoardToVrmlScale ) )
|
2018-04-24 16:19:28 +00:00
|
|
|
throw( std::runtime_error( vlayer->GetError() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
vlayer->EnsureWinding( seg, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlPolyPolygon( VRML_LAYER* aVlayer, SHAPE_POLY_SET& aOutlines,
|
|
|
|
double aOrientation, wxPoint aPos )
|
|
|
|
{
|
|
|
|
aOutlines.Rotate( -aOrientation, VECTOR2I( 0, 0 ) );
|
|
|
|
aOutlines.Move( aPos );
|
|
|
|
|
|
|
|
for( int icnt = 0; icnt < aOutlines.OutlineCount(); icnt++ )
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN& outline = aOutlines.COutline( icnt );
|
|
|
|
|
|
|
|
int seg = aVlayer->NewContour();
|
|
|
|
|
|
|
|
for( int jj = 0; jj < outline.PointCount(); jj++ )
|
|
|
|
{
|
|
|
|
if( !aVlayer->AddVertex( seg, outline.CPoint( jj ).x * m_BoardToVrmlScale,
|
|
|
|
-outline.CPoint( jj ).y * m_BoardToVrmlScale ) )
|
|
|
|
throw( std::runtime_error( aVlayer->GetError() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
aVlayer->EnsureWinding( seg, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
void MODEL_VRML::ExportVrmlDrawsegment( PCB_SHAPE* drawseg )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer = drawseg->GetLayer();
|
2021-03-17 13:26:26 +00:00
|
|
|
double w = drawseg->GetWidth() * m_BoardToVrmlScale;
|
|
|
|
double x = drawseg->GetStart().x * m_BoardToVrmlScale;
|
|
|
|
double y = drawseg->GetStart().y * m_BoardToVrmlScale;
|
|
|
|
double xf = drawseg->GetEnd().x * m_BoardToVrmlScale;
|
|
|
|
double yf = drawseg->GetEnd().y * m_BoardToVrmlScale;
|
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:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlArc( layer,
|
2021-03-17 13:26:26 +00:00
|
|
|
(double) drawseg->GetCenter().x * m_BoardToVrmlScale,
|
|
|
|
(double) drawseg->GetCenter().y * m_BoardToVrmlScale,
|
|
|
|
(double) drawseg->GetArcStart().x * m_BoardToVrmlScale,
|
|
|
|
(double) drawseg->GetArcStart().y * m_BoardToVrmlScale,
|
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.
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlArc( layer, x, y, x, y-r, w, 180.0 );
|
|
|
|
ExportVrmlArc( 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
|
|
|
|
2018-01-24 15:06:17 +00:00
|
|
|
case S_POLYGON:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlPolygon( layer, drawseg, 0.0, wxPoint( 0, 0 ) );
|
2018-01-24 15:06:17 +00:00
|
|
|
break;
|
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
case S_SEGMENT:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlLine( layer, x, y, xf, yf, w );
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
2020-06-15 19:50:20 +00:00
|
|
|
|
2021-01-10 19:28:15 +00:00
|
|
|
case S_CURVE:
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2D> output;
|
|
|
|
std::vector<VECTOR2D> pointCtrl;
|
|
|
|
|
|
|
|
pointCtrl.emplace_back( x, y );
|
2021-03-17 13:26:26 +00:00
|
|
|
pointCtrl.emplace_back( drawseg->GetBezControl1().x * m_BoardToVrmlScale,
|
|
|
|
drawseg->GetBezControl1().y * m_BoardToVrmlScale );
|
|
|
|
pointCtrl.emplace_back( drawseg->GetBezControl2().x * m_BoardToVrmlScale,
|
|
|
|
drawseg->GetBezControl2().y * m_BoardToVrmlScale );
|
2021-01-10 19:28:15 +00:00
|
|
|
pointCtrl.emplace_back( xf, yf );
|
|
|
|
|
|
|
|
BEZIER_POLY converter( pointCtrl );
|
|
|
|
converter.GetPoly( output, w );
|
|
|
|
|
|
|
|
for( size_t i = 1; i < output.size(); ++i )
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlLine( layer, output[i - 1].x, output[i - 1].y,
|
2021-01-10 19:28:15 +00:00
|
|
|
output[i].x, output[i].y, w );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
case S_RECT:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlLine( layer, x, y, xf, y, w );
|
|
|
|
ExportVrmlLine( layer, xf, y, xf, yf, w );
|
|
|
|
ExportVrmlLine( layer, xf, yf, x, yf, w );
|
|
|
|
ExportVrmlLine( layer, x, yf, x, y, w );
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
/* GRText needs a callback function to return the shape of the text to plot...
|
|
|
|
* this is for coupling the vrml_text_callback with the vrml exporter parameters
|
|
|
|
*/
|
2018-04-06 13:30:52 +00:00
|
|
|
static void vrml_text_callback( int x0, int y0, int xf, int yf, void* aData )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2016-12-30 11:39:41 +00:00
|
|
|
LAYER_NUM m_text_layer = model_vrml->m_text_layer;
|
|
|
|
int m_text_width = model_vrml->m_text_width;
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
model_vrml->ExportVrmlLine( m_text_layer,
|
2021-03-17 13:26:26 +00:00
|
|
|
x0 * model_vrml->m_BoardToVrmlScale,
|
|
|
|
y0 * model_vrml->m_BoardToVrmlScale,
|
|
|
|
xf * model_vrml->m_BoardToVrmlScale,
|
|
|
|
yf * model_vrml->m_BoardToVrmlScale,
|
|
|
|
m_text_width * model_vrml->m_BoardToVrmlScale );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
void MODEL_VRML::ExportVrmlPcbtext( PCB_TEXT* text )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxSize size = text->GetTextSize();
|
2013-03-18 19:36:07 +00:00
|
|
|
|
|
|
|
if( text->IsMirrored() )
|
2015-06-26 13:41:56 +00:00
|
|
|
size.x = -size.x;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
bool forceBold = true;
|
|
|
|
int penWidth = text->GetEffectiveTextPenWidth();
|
2019-05-31 12:15:25 +00:00
|
|
|
COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
|
2014-04-19 16:05:58 +00:00
|
|
|
|
2020-04-13 19:55:27 +00:00
|
|
|
model_vrml->m_text_layer = text->GetLayer();
|
|
|
|
model_vrml->m_text_width = penWidth;
|
|
|
|
|
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() );
|
2020-04-14 12:25:00 +00:00
|
|
|
text->GetLinePositions( 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
|
|
|
{
|
2020-04-13 19:55:27 +00:00
|
|
|
GRText( nullptr, positions[ii], color, strings_list[ii], text->GetTextAngle(), size,
|
|
|
|
text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(),
|
2020-04-18 20:04:41 +00:00
|
|
|
forceBold, vrml_text_callback );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-13 19:55:27 +00:00
|
|
|
GRText( nullptr, text->GetTextPos(), color, text->GetShownText(), text->GetTextAngle(),
|
|
|
|
size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(),
|
2020-04-18 20:04:41 +00:00
|
|
|
forceBold, vrml_text_callback );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlDrawings()
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// draw graphic items
|
2021-03-18 13:40:36 +00:00
|
|
|
for( auto drawing : m_Pcb->Drawings() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_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() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlDrawsegment( (PCB_SHAPE*) drawing );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_TEXT_T:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlPcbtext( (PCB_TEXT*) drawing );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
// board edges and cutouts
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlBoard()
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
if( !m_Pcb->GetBoardPolygonOutlines( m_pcbOutlines ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2020-11-20 13:55:10 +00:00
|
|
|
wxLogWarning( _( "Board outline is malformed. Run DRC for a full analysis." ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int seg;
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
for( int cnt = 0; cnt < m_pcbOutlines.OutlineCount(); cnt++ )
|
2015-07-14 20:23:13 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outline = m_pcbOutlines.COutline( cnt );
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
seg = m_3D_board.NewContour();
|
2014-01-06 20:14:24 +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
|
|
|
{
|
2021-03-18 12:28:24 +00:00
|
|
|
m_3D_board.AddVertex( seg, (double)outline.CPoint(j).x * m_BoardToVrmlScale,
|
2021-03-17 13:26:26 +00:00
|
|
|
-((double)outline.CPoint(j).y * m_BoardToVrmlScale ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
m_3D_board.EnsureWinding( seg, false );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
// Generate board holes from outlines:
|
|
|
|
for( int ii = 0; ii < m_pcbOutlines.HoleCount( cnt ); ii++ )
|
2017-03-22 09:58:14 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
const SHAPE_LINE_CHAIN& hole = m_pcbOutlines.Hole( cnt, ii );
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
seg = m_holes.NewContour();
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2017-03-22 09:58:14 +00:00
|
|
|
if( seg < 0 )
|
|
|
|
{
|
2020-11-20 13:55:10 +00:00
|
|
|
wxLogError( _( "VRML Export Failed: Could not add holes to contours." ) );
|
2017-03-22 09:58:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2017-03-22 09:58:14 +00:00
|
|
|
for( int j = 0; j < hole.PointCount(); j++ )
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
m_holes.AddVertex( seg, (double) hole.CPoint(j).x * m_BoardToVrmlScale,
|
|
|
|
-( (double) hole.CPoint(j).y * m_BoardToVrmlScale ) );
|
2017-03-22 09:58:14 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.EnsureWinding( seg, true );
|
2017-03-22 09:58:14 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportRoundPadstack( 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 )
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddCircle( x, -y, hole, true );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( m_plainPCB )
|
2014-12-20 16:13:51 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-12 16:39:57 +00:00
|
|
|
while( true )
|
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
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_bot_copper.AddCircle( x, -y, r );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
|
|
|
if( hole > 0 && !thru )
|
2021-03-16 19:15:34 +00:00
|
|
|
m_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
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_top_copper.AddCircle( x, -y, r );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
|
|
|
if( hole > 0 && !thru )
|
2021-03-16 19:15:34 +00:00
|
|
|
m_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlVia( const VIA* aVia )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2020-08-31 16:29:13 +00:00
|
|
|
double x, y, r, hole;
|
|
|
|
PCB_LAYER_ID top_layer, bottom_layer;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
hole = aVia->GetDrillValue() * m_BoardToVrmlScale / 2.0;
|
|
|
|
r = aVia->GetWidth() * m_BoardToVrmlScale / 2.0;
|
|
|
|
x = aVia->GetStart().x * m_BoardToVrmlScale;
|
|
|
|
y = aVia->GetStart().y * m_BoardToVrmlScale;
|
2016-12-30 11:39:41 +00:00
|
|
|
aVia->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
|
2021-03-18 13:40:36 +00:00
|
|
|
ExportRoundPadstack( x, y, r, bottom_layer, top_layer, hole );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlTracks()
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
for( TRACK* track : m_Pcb->Tracks() )
|
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
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
ExportVrmlVia( (const VIA*) track );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2021-03-16 19:15:34 +00:00
|
|
|
else if( ( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu ) && !m_plainPCB )
|
2020-04-08 15:30:20 +00:00
|
|
|
{
|
|
|
|
if( track->Type() == PCB_ARC_T )
|
|
|
|
{
|
|
|
|
ARC* arc = static_cast<ARC*>( track );
|
|
|
|
VECTOR2D center( arc->GetCenter() );
|
|
|
|
double arc_angle_degree = arc->GetAngle()/10;
|
|
|
|
|
|
|
|
// Vrml exporter does not export arcs with angle < 1.0 degree
|
|
|
|
// ( to avoid issues with vrml viewers).
|
|
|
|
// The best way is to convert them to a small straight line
|
|
|
|
if( arc_angle_degree < -1.0 || arc_angle_degree > 1.0 )
|
2020-08-22 21:17:23 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlArc( track->GetLayer(),
|
2021-03-17 13:26:26 +00:00
|
|
|
center.x * m_BoardToVrmlScale, center.y * m_BoardToVrmlScale,
|
|
|
|
arc->GetStart().x * m_BoardToVrmlScale,
|
|
|
|
arc->GetStart().y * m_BoardToVrmlScale,
|
|
|
|
arc->GetWidth() * m_BoardToVrmlScale, arc_angle_degree );
|
2020-08-22 21:17:23 +00:00
|
|
|
}
|
2020-04-08 15:30:20 +00:00
|
|
|
else
|
2020-08-22 21:17:23 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlLine( arc->GetLayer(),
|
2021-03-17 13:26:26 +00:00
|
|
|
arc->GetStart().x * m_BoardToVrmlScale,
|
|
|
|
arc->GetStart().y * m_BoardToVrmlScale,
|
|
|
|
arc->GetEnd().x * m_BoardToVrmlScale,
|
|
|
|
arc->GetEnd().y * m_BoardToVrmlScale,
|
|
|
|
arc->GetWidth() * m_BoardToVrmlScale );
|
2020-08-22 21:17:23 +00:00
|
|
|
}
|
2020-04-08 15:30:20 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-22 21:17:23 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlLine( track->GetLayer(),
|
2021-03-17 13:26:26 +00:00
|
|
|
track->GetStart().x * m_BoardToVrmlScale,
|
|
|
|
track->GetStart().y * m_BoardToVrmlScale,
|
|
|
|
track->GetEnd().x * m_BoardToVrmlScale,
|
|
|
|
track->GetEnd().y * m_BoardToVrmlScale,
|
|
|
|
track->GetWidth() * m_BoardToVrmlScale );
|
2020-08-22 21:17:23 +00:00
|
|
|
}
|
2020-04-08 15:30:20 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlZones()
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
for( ZONE* zone : m_Pcb->Zones() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
VRML_LAYER* vl;
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( !GetLayer3D( layer, &vl ) )
|
2020-06-24 02:19:08 +00:00
|
|
|
continue;
|
2013-03-18 19:36:07 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
if( !zone->IsFilled() )
|
2021-03-17 13:26:26 +00:00
|
|
|
continue;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
const SHAPE_POLY_SET& poly = zone->GetFilledPolysList( layer );
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
for( int i = 0; i < poly.OutlineCount(); i++ )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outline = poly.COutline( i );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
int seg = vl->NewContour();
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
for( int j = 0; j < outline.PointCount(); j++ )
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
if( !vl->AddVertex( seg, (double) outline.CPoint( j ).x * m_BoardToVrmlScale,
|
|
|
|
-( (double) outline.CPoint( j ).y * m_BoardToVrmlScale ) ) )
|
2020-09-21 11:32:30 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
throw( std::runtime_error( vl->GetError() ) );
|
2020-09-21 11:32:30 +00:00
|
|
|
}
|
2020-06-24 02:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vl->EnsureWinding( seg, false );
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
void MODEL_VRML::ExportVrmlFpText( FP_TEXT* item )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
if( item->IsVisible() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
wxSize size = item->GetTextSize();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
if( item->IsMirrored() )
|
2015-06-26 13:41:56 +00:00
|
|
|
size.x = -size.x; // Text is mirrored
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
bool forceBold = true;
|
|
|
|
int penWidth = item->GetEffectiveTextPenWidth();
|
2020-04-13 19:55:27 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
model_vrml->m_text_layer = item->GetLayer();
|
2020-04-13 19:55:27 +00:00
|
|
|
model_vrml->m_text_width = penWidth;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( NULL, item->GetTextPos(), BLACK, item->GetShownText(), item->GetDrawRotation(),
|
2020-04-13 19:55:27 +00:00
|
|
|
size, item->GetHorizJustify(), item->GetVertJustify(), penWidth, item->IsItalic(),
|
2020-04-18 20:04:41 +00:00
|
|
|
forceBold, vrml_text_callback );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
void MODEL_VRML::ExportVrmlFpShape( FP_SHAPE* aOutline, FOOTPRINT* aFootprint )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer = aOutline->GetLayer();
|
2021-03-17 13:26:26 +00:00
|
|
|
double x = aOutline->GetStart().x * m_BoardToVrmlScale;
|
|
|
|
double y = aOutline->GetStart().y * m_BoardToVrmlScale;
|
|
|
|
double xf = aOutline->GetEnd().x * m_BoardToVrmlScale;
|
|
|
|
double yf = aOutline->GetEnd().y * m_BoardToVrmlScale;
|
|
|
|
double w = aOutline->GetWidth() * m_BoardToVrmlScale;
|
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:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlLine( layer, x, y, xf, yf, w );
|
2014-02-15 07:39:06 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
case S_ARC:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlArc( layer, x, y, xf, yf, w, aOutline->GetAngle() / 10 );
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlCircle( 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:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlPolygon( layer, aOutline, aFootprint->GetOrientationRadians(),
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->GetPosition() );
|
2014-02-15 07:39:06 +00:00
|
|
|
break;
|
|
|
|
|
2021-01-10 19:28:15 +00:00
|
|
|
case S_CURVE:
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2D> output;
|
|
|
|
std::vector<VECTOR2D> pointCtrl;
|
|
|
|
|
|
|
|
pointCtrl.emplace_back( x, y );
|
2021-03-17 13:26:26 +00:00
|
|
|
pointCtrl.emplace_back( aOutline->GetBezControl1().x * m_BoardToVrmlScale,
|
|
|
|
aOutline->GetBezControl1().y * m_BoardToVrmlScale );
|
|
|
|
pointCtrl.emplace_back( aOutline->GetBezControl2().x * m_BoardToVrmlScale,
|
|
|
|
aOutline->GetBezControl2().y * m_BoardToVrmlScale );
|
2021-01-10 19:28:15 +00:00
|
|
|
pointCtrl.emplace_back( xf, yf );
|
|
|
|
|
|
|
|
BEZIER_POLY converter( pointCtrl );
|
|
|
|
converter.GetPoly( output, w );
|
|
|
|
|
|
|
|
for( size_t i = 1; i < output.size(); ++i )
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlLine( layer, output[i - 1].x, output[i - 1].y,
|
2021-01-10 19:28:15 +00:00
|
|
|
output[i].x, output[i].y, w );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-08-22 21:17:23 +00:00
|
|
|
case S_RECT:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlLine( layer, x, y, xf, y, w );
|
|
|
|
ExportVrmlLine( layer, xf, y, xf, yf, w );
|
|
|
|
ExportVrmlLine( layer, xf, yf, x, yf, w );
|
|
|
|
ExportVrmlLine( layer, x, yf, x, y, w );
|
2020-08-22 21:17:23 +00:00
|
|
|
break;
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlPadshape( VRML_LAYER* aTinLayer, PCB_LAYER_ID aPcbLayer, 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();
|
2021-03-17 13:26:26 +00:00
|
|
|
double pad_x = pad_pos.x * m_BoardToVrmlScale;
|
|
|
|
double pad_y = pad_pos.y * m_BoardToVrmlScale;
|
2014-01-06 20:14:24 +00:00
|
|
|
wxSize pad_delta = aPad->GetDelta();
|
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
double pad_dx = pad_delta.x * m_BoardToVrmlScale / 2.0;
|
|
|
|
double pad_dy = pad_delta.y * m_BoardToVrmlScale / 2.0;
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
double pad_w = aPad->GetSize().x * m_BoardToVrmlScale / 2.0;
|
|
|
|
double pad_h = aPad->GetSize().y * m_BoardToVrmlScale / 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;
|
|
|
|
|
2018-03-05 20:54:10 +00:00
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
2018-08-29 07:13:07 +00:00
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
2018-03-05 20:54:10 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET polySet;
|
2020-06-22 19:35:09 +00:00
|
|
|
const int corner_radius = aPad->GetRoundRectCornerRadius();
|
2021-03-18 12:28:24 +00:00
|
|
|
bool doChamfer = aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT;
|
|
|
|
double chamferRatio = doChamfer ? aPad->GetChamferRectRatio() : 0.0;
|
|
|
|
|
2020-10-13 10:55:24 +00:00
|
|
|
TransformRoundChamferedRectToPolygon( polySet, wxPoint( 0, 0 ), aPad->GetSize(), 0.0,
|
2021-03-18 12:28:24 +00:00
|
|
|
corner_radius, chamferRatio,
|
|
|
|
doChamfer ? aPad->GetChamferPositions() : 0,
|
|
|
|
ARC_HIGH_DEF, ERROR_INSIDE );
|
2018-03-05 20:54:10 +00:00
|
|
|
std::vector< wxRealPoint > cornerList;
|
2018-08-29 07:13:07 +00:00
|
|
|
// TransformRoundChamferedRectToPolygon creates only one convex polygon
|
2021-03-18 12:28:24 +00:00
|
|
|
SHAPE_LINE_CHAIN& poly = polySet.Outline( 0 );
|
2018-03-05 20:54:10 +00:00
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
cornerList.reserve( poly.PointCount() );
|
2021-03-18 12:28:24 +00:00
|
|
|
|
2018-03-05 20:54:10 +00:00
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
2019-03-23 18:26:44 +00:00
|
|
|
cornerList.emplace_back(
|
2021-03-18 12:28:24 +00:00
|
|
|
poly.CPoint( ii ).x * m_BoardToVrmlScale,
|
|
|
|
-poly.CPoint( ii ).y * m_BoardToVrmlScale );
|
2018-03-05 20:54:10 +00:00
|
|
|
|
|
|
|
// Close polygon
|
|
|
|
cornerList.push_back( cornerList[0] );
|
2021-03-18 12:28:24 +00:00
|
|
|
|
2018-03-05 20:54:10 +00:00
|
|
|
if( !aTinLayer->AddPolygon( cornerList, pad_x, -pad_y, aPad->GetOrientation() ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PAD_SHAPE_CUSTOM:
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET polySet;
|
|
|
|
std::vector< wxRealPoint > cornerList;
|
2020-08-12 21:18:13 +00:00
|
|
|
aPad->MergePrimitivesAsPolygon( &polySet, UNDEFINED_LAYER );
|
2018-03-05 20:54:10 +00:00
|
|
|
|
|
|
|
for( int cnt = 0; cnt < polySet.OutlineCount(); ++cnt )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN& poly = polySet.Outline( cnt );
|
|
|
|
cornerList.clear();
|
|
|
|
|
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
2019-03-23 18:26:44 +00:00
|
|
|
cornerList.emplace_back(
|
2021-03-17 13:26:26 +00:00
|
|
|
poly.CPoint( ii ).x * m_BoardToVrmlScale, -poly.CPoint( ii ).y * m_BoardToVrmlScale );
|
2018-03-05 20:54:10 +00:00
|
|
|
|
|
|
|
// Close polygon
|
|
|
|
cornerList.push_back( cornerList[0] );
|
|
|
|
|
|
|
|
if( !aTinLayer->AddPolygon( cornerList, pad_x, -pad_y, aPad->GetOrientation() ) )
|
|
|
|
throw( std::runtime_error( aTinLayer->GetError() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-01-11 19:16:32 +00:00
|
|
|
// Intentionally fall through and treat a rectangle as a trapezoid with no sloped sides
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2020-01-11 19:16:32 +00:00
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
2018-08-29 07:13:07 +00:00
|
|
|
{
|
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;
|
2018-08-29 07:13:07 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlPad( PAD* aPad )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
double hole_drill_w = (double) aPad->GetDrillSize().x * m_BoardToVrmlScale / 2.0;
|
|
|
|
double hole_drill_h = (double) aPad->GetDrillSize().y * m_BoardToVrmlScale / 2.0;
|
2014-10-17 23:28:12 +00:00
|
|
|
double hole_drill = std::min( hole_drill_w, hole_drill_h );
|
2021-03-17 13:26:26 +00:00
|
|
|
double hole_x = aPad->GetPosition().x * m_BoardToVrmlScale;
|
|
|
|
double hole_y = aPad->GetPosition().y * m_BoardToVrmlScale;
|
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;
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( ( aPad->GetAttribute() != PAD_ATTRIB_NPTH ) && !m_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
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0 + PLATE_OFFSET,
|
2016-09-17 06:14:49 +00:00
|
|
|
hole_drill_h * 2.0 + PLATE_OFFSET,
|
|
|
|
aPad->GetOrientation()/10.0, true, true );
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
m_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
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, hole_drill_h * 2.0,
|
2016-09-17 06:14:49 +00:00
|
|
|
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
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddCircle( hole_x, -hole_y, hole_drill + PLATE_OFFSET, true, true );
|
|
|
|
m_plated_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-06-16 12:02:15 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( m_plainPCB )
|
2014-12-20 16:13:51 +00:00
|
|
|
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
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
if( layer_mask[B_Paste] )
|
|
|
|
ExportVrmlPadshape( &m_bot_paste, B_Paste, aPad );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer_mask[B_Cu] )
|
2021-03-18 13:40:36 +00:00
|
|
|
ExportVrmlPadshape( &m_bot_copper, B_Cu, aPad );
|
|
|
|
|
|
|
|
if( layer_mask[F_Paste] )
|
|
|
|
ExportVrmlPadshape( &m_top_paste, F_Paste, aPad );
|
2018-04-24 16:19:28 +00:00
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
if( layer_mask[F_Cu] )
|
|
|
|
ExportVrmlPadshape( &m_top_copper, F_Cu, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint,
|
|
|
|
std::ostream* aOutputFile )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
if( !m_plainPCB )
|
2014-12-20 16:13:51 +00:00
|
|
|
{
|
|
|
|
// Reference and value
|
2020-11-13 01:33:30 +00:00
|
|
|
if( aFootprint->Reference().IsVisible() )
|
2021-03-17 13:26:26 +00:00
|
|
|
ExportVrmlFpText( &aFootprint->Reference() );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
if( aFootprint->Value().IsVisible() )
|
2021-03-17 13:26:26 +00:00
|
|
|
ExportVrmlFpText( &aFootprint->Value() );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Export footprint graphics
|
2019-06-02 03:55:32 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2014-12-20 16:13:51 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2021-03-17 13:26:26 +00:00
|
|
|
ExportVrmlFpText( static_cast<FP_TEXT*>( item ) );
|
2020-08-22 21:17:23 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2021-03-16 19:15:34 +00:00
|
|
|
ExportVrmlFpShape( static_cast<FP_SHAPE*>( item ), aFootprint );
|
2020-08-22 21:17:23 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2020-08-22 21:17:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-12-20 16:13:51 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export pads
|
2020-11-13 01:33:30 +00:00
|
|
|
for( PAD* pad : aFootprint->Pads() )
|
2021-03-18 13:40:36 +00:00
|
|
|
ExportVrmlPad( pad );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
bool isFlipped = aFootprint->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)
|
2020-11-13 01:33:30 +00:00
|
|
|
auto sM = aFootprint->Models().begin();
|
|
|
|
auto eM = aFootprint->Models().end();
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
wxFileName subdir( m_Subdir3DFpModels, "" );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
while( sM != eM )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-03-18 12:28:24 +00:00
|
|
|
SGNODE* mod3d = (SGNODE*) m_Cache3Dmodels->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 );
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Note here aFootprint->GetOrientation() is in 0.1 degrees, so footprint rotation
|
|
|
|
// has to be converted to radians
|
2020-11-13 01:33:30 +00:00
|
|
|
build_quat( 0, 0, 1, DECIDEG2RAD( aFootprint->GetOrientation() ), q2 );
|
2016-09-17 06:14:49 +00:00
|
|
|
compose_quat( q1, q2, q1 );
|
|
|
|
from_quat( q1, rot );
|
|
|
|
|
2017-11-08 09:56:57 +00:00
|
|
|
double offsetFactor = 1000.0f * IU_PER_MILS / 25.4f;
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// adjust 3D shape local offset position
|
2017-11-08 09:56:57 +00:00
|
|
|
// they are given in mm, so they are converted in board IU.
|
|
|
|
double offsetx = sM->m_Offset.x * offsetFactor;
|
|
|
|
double offsety = sM->m_Offset.y * offsetFactor;
|
|
|
|
double offsetz = sM->m_Offset.z * offsetFactor;
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( isFlipped )
|
|
|
|
offsetz = -offsetz;
|
|
|
|
else // In normal mode, Y axis is reversed in Pcbnew.
|
|
|
|
offsety = -offsety;
|
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
RotatePoint( &offsetx, &offsety, aFootprint->GetOrientation() );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
SGPOINT trans;
|
2021-03-17 13:26:26 +00:00
|
|
|
trans.x = ( offsetx + aFootprint->GetPosition().x ) * m_BoardToVrmlScale + m_tx;
|
|
|
|
trans.y = -( offsety + aFootprint->GetPosition().y) * m_BoardToVrmlScale - m_ty;
|
|
|
|
trans.z = (offsetz * m_BoardToVrmlScale ) + GetLayerZ( aFootprint->GetLayer() );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-18 12:28:24 +00:00
|
|
|
wxFileName srcFile = m_Cache3Dmodels->GetResolver()->ResolvePath( sM->m_Filename );
|
2016-09-17 06:14:49 +00:00
|
|
|
wxFileName dstFile;
|
2021-03-17 13:26:26 +00:00
|
|
|
dstFile.SetPath( m_Subdir3DFpModels );
|
2016-09-17 06:14:49 +00:00
|
|
|
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 )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, m_ReuseDef, true ) )
|
2014-10-17 23:28:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << "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
|
|
|
{
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << " rotation " << std::setprecision( 5 );
|
|
|
|
(*aOutputFile) << 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
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
(*aOutputFile) << " translation " << std::setprecision( m_precision );
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << trans.x << " ";
|
|
|
|
(*aOutputFile) << trans.y << " ";
|
|
|
|
(*aOutputFile) << trans.z << "\n";
|
2011-01-19 10:34:56 +00:00
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << " scale ";
|
|
|
|
(*aOutputFile) << sM->m_Scale.x << " ";
|
|
|
|
(*aOutputFile) << sM->m_Scale.y << " ";
|
|
|
|
(*aOutputFile) << sM->m_Scale.z << "\n";
|
2011-01-15 20:21:46 +00:00
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << " children [\n Inline {\n url \"";
|
2013-01-12 10:35:08 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseRelPathIn3DModelFilename )
|
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( "\\", "/" );
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << TO_UTF8( fn ) << "\"\n } ]\n";
|
|
|
|
(*aOutputFile) << " }\n";
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
IFSG_TRANSFORM* modelShape = new IFSG_TRANSFORM( m_OutputPCB.GetRawPtr() );
|
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 )
|
|
|
|
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 ) )
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_components.push_back( mod3d );
|
2016-09-17 06:14:49 +00:00
|
|
|
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();
|
2021-03-18 12:28:24 +00:00
|
|
|
bool success = true;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
MODEL_VRML model3d;
|
2014-06-08 10:35:42 +00:00
|
|
|
model_vrml = &model3d;
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.m_Pcb = GetBoard();
|
2016-10-10 23:54:32 +00:00
|
|
|
model3d.SetScale( aMMtoWRMLunit );
|
2021-03-17 13:26:26 +00:00
|
|
|
model3d.m_UseInlineModelsInBrdfile = aExport3DFiles;
|
|
|
|
model3d.m_Subdir3DFpModels = a3D_Subdir;
|
|
|
|
model3d.m_UseRelPathIn3DModelFilename = aUseRelativePaths;
|
2021-03-18 12:28:24 +00:00
|
|
|
model3d.m_Cache3Dmodels = Prj().Get3DCacheManager();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( model3d.m_UseInlineModelsInBrdfile )
|
2016-10-10 23:54:32 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
model3d.m_BoardToVrmlScale = MM_PER_IU / 2.54;
|
2016-10-10 23:54:32 +00:00
|
|
|
model3d.SetOffset( -aXRef / 2.54, aYRef / 2.54 );
|
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
else
|
2016-10-10 23:54:32 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
model3d.m_BoardToVrmlScale = MM_PER_IU;
|
2016-10-10 23:54:32 +00:00
|
|
|
model3d.SetOffset( -aXRef, aYRef );
|
|
|
|
}
|
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
|
2016-12-30 11:39:41 +00:00
|
|
|
model3d.m_plainPCB = aUsePlainPCB;
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
try
|
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
// Preliminary computation: the z value for each layer
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.ComputeLayer3D_Zpos();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// board edges and cutouts
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.ExportVrmlBoard();
|
2021-03-16 19:15:34 +00:00
|
|
|
|
|
|
|
// Drawing and text on the board
|
|
|
|
if( !aUsePlainPCB )
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.ExportVrmlSolderMask();
|
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 )
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.ExportVrmlDrawings();
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// Export vias and trackage
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.ExportVrmlTracks();
|
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 )
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.ExportVrmlZones();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( model3d.m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
// Copy fp 3D models in a folder, and link these files in
|
|
|
|
// the board .vrml file
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.ExportFp3DModelsAsLinkedFile( aFullFileName );
|
2017-03-02 22:53:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
// merge footprints in the .vrml board file
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : pcb->Footprints() )
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.ExportVrmlFootprint( footprint, NULL );
|
2017-03-02 22:53:49 +00:00
|
|
|
|
|
|
|
// write out the board and all layers
|
2021-03-18 13:40:36 +00:00
|
|
|
model3d.writeLayers( TO_UTF8( aFullFileName ), NULL );
|
2017-03-02 22:53:49 +00:00
|
|
|
}
|
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
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
success = false;
|
2014-06-08 10:35:42 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
return success;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void MODEL_VRML::ExportFp3DModelsAsLinkedFile( const wxString& aFullFileName )
|
2021-03-17 13:26:26 +00:00
|
|
|
{
|
|
|
|
// check if the 3D Subdir exists - create if not
|
|
|
|
wxFileName subdir( m_Subdir3DFpModels, "" );
|
|
|
|
|
|
|
|
if( ! subdir.DirExists() )
|
|
|
|
{
|
|
|
|
if( !wxDir::Make( subdir.GetFullPath() ) )
|
|
|
|
throw( std::runtime_error( "Could not create 3D model subdirectory" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
OPEN_OSTREAM( output_file, TO_UTF8( aFullFileName ) );
|
|
|
|
|
|
|
|
if( output_file.fail() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "Could not open file '" << TO_UTF8( aFullFileName ) << "'";
|
|
|
|
throw( std::runtime_error( ostr.str().c_str() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
output_file.imbue( std::locale::classic() );
|
|
|
|
|
|
|
|
// Begin with the usual VRML boilerplate
|
|
|
|
wxString fn = aFullFileName;
|
|
|
|
fn.Replace( "\\" , "/" );
|
|
|
|
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( m_precision );
|
|
|
|
output_file << m_WorldScale << " ";
|
|
|
|
output_file << m_WorldScale << " ";
|
|
|
|
output_file << m_WorldScale << "\n";
|
|
|
|
output_file << " children [\n";
|
|
|
|
|
|
|
|
// Export footprints
|
2021-03-18 13:40:36 +00:00
|
|
|
for( FOOTPRINT* footprint : m_Pcb->Footprints() )
|
|
|
|
ExportVrmlFootprint( footprint, &output_file );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
|
|
|
// write out the board and all layers
|
2021-03-18 13:40:36 +00:00
|
|
|
writeLayers( TO_UTF8( aFullFileName ), &output_file );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
|
|
|
// Close the outer 'transform' node
|
|
|
|
output_file << "]\n}\n";
|
|
|
|
|
|
|
|
CLOSE_STREAM( output_file );
|
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
SGNODE* MODEL_VRML::getSGColor( VRML_COLOR_INDEX colorIdx )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
if( colorIdx == -1 )
|
|
|
|
colorIdx = VRML_COLOR_PCB;
|
|
|
|
else if( colorIdx == VRML_COLOR_LAST )
|
|
|
|
return NULL;
|
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
if( m_sgmaterial[colorIdx] )
|
|
|
|
return m_sgmaterial[colorIdx];
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
IFSG_APPEARANCE vcolor( (SGNODE*) NULL );
|
2021-03-17 13:26:26 +00:00
|
|
|
VRML_COLOR* cp = &vrml_colors_list[colorIdx];
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
m_sgmaterial[colorIdx] = vcolor.GetRawPtr();
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
return m_sgmaterial[colorIdx];
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
void MODEL_VRML::create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
|
|
|
|
VRML_LAYER* layer, double top_z, bool aTopPlane )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
std::vector< double > vertices;
|
|
|
|
std::vector< int > idxPlane;
|
|
|
|
|
2019-08-02 20:12:53 +00:00
|
|
|
if( !( *layer ).Get2DTriangles( vertices, idxPlane, top_z, aTopPlane ) )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-02 20:12:53 +00:00
|
|
|
if( ( idxPlane.size() % 3 ) )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
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 )
|
2019-12-05 15:41:21 +00:00
|
|
|
vlist.emplace_back( vertices[j], vertices[j+1], vertices[j+2] );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
void MODEL_VRML::create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
|
|
|
|
VRML_LAYER* layer, double top_z, double bottom_z )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-01 03:02:11 +00:00
|
|
|
if( !( *layer ).Get3DTriangles( vertices, idxPlane, idxSide, top_z, bottom_z )
|
|
|
|
|| idxPlane.empty() || idxSide.empty() )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
|
|
|
|
{
|
2020-08-18 14:17:16 +00:00
|
|
|
throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a "
|
|
|
|
"triangle list)" ) );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< SGPOINT > vlist;
|
|
|
|
size_t nvert = vertices.size() / 3;
|
|
|
|
size_t j = 0;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < nvert; ++i, j+= 3 )
|
2019-12-05 15:41:21 +00:00
|
|
|
vlist.emplace_back( vertices[j], vertices[j+1], vertices[j+2] );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|