2016-09-02 10:08:40 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of kicad2mcad
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
2018-09-20 09:05:52 +00:00
|
|
|
* Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-09-02 10:08:40 +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
|
|
|
|
*/
|
2018-09-20 09:05:52 +00:00
|
|
|
#include "wx/wx.h"
|
2016-09-02 10:08:40 +00:00
|
|
|
#include <wx/app.h>
|
|
|
|
#include <wx/cmdline.h>
|
|
|
|
#include <wx/log.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
2016-09-18 02:24:04 +00:00
|
|
|
#include <sstream>
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2019-04-15 17:09:27 +00:00
|
|
|
#include "pcb/kicadpcb.h"
|
2018-09-20 09:05:52 +00:00
|
|
|
#include "kicad2step_frame_base.h"
|
|
|
|
#include "panel_kicad2step.h"
|
2020-02-15 09:58:44 +00:00
|
|
|
#include <Standard_Failure.hxx> // In open cascade
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
class KICAD2STEP_FRAME;
|
|
|
|
|
|
|
|
class KICAD2MCAD_APP : public wxApp
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-04-16 07:27:22 +00:00
|
|
|
KICAD2MCAD_APP() : wxApp(), m_frame( nullptr ), m_Panel( nullptr )
|
|
|
|
{}
|
2016-09-26 06:40:12 +00:00
|
|
|
virtual bool OnInit() override;
|
|
|
|
virtual int OnRun() override;
|
|
|
|
virtual void OnInitCmdLine(wxCmdLineParser& parser) override;
|
|
|
|
virtual bool OnCmdLineParsed(wxCmdLineParser& parser) override;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
private:
|
2018-10-02 06:34:07 +00:00
|
|
|
KICAD2STEP_FRAME * m_frame;
|
2018-09-20 09:05:52 +00:00
|
|
|
KICAD2MCAD_PRMS m_params;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PANEL_KICAD2STEP* m_Panel;
|
|
|
|
};
|
|
|
|
|
|
|
|
wxIMPLEMENT_APP(KICAD2MCAD_APP);
|
|
|
|
|
|
|
|
class KICAD2STEP_FRAME : public KICAD2STEP_FRAME_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
KICAD2STEP_FRAME(const wxString& title);
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
2018-09-11 07:22:10 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
KICAD2MCAD_PRMS::KICAD2MCAD_PRMS()
|
|
|
|
{
|
2016-09-02 10:08:40 +00:00
|
|
|
#ifdef SUPPORTS_IGES
|
2018-09-20 09:05:52 +00:00
|
|
|
m_fmtIGES = false;
|
2016-09-02 10:08:40 +00:00
|
|
|
#endif
|
2018-09-20 09:05:52 +00:00
|
|
|
m_overwrite = false;
|
|
|
|
m_useGridOrigin = false;
|
|
|
|
m_useDrillOrigin = false;
|
|
|
|
m_includeVirtual = true;
|
|
|
|
m_xOrigin = 0.0;
|
|
|
|
m_yOrigin = 0.0;
|
|
|
|
m_minDistance = MIN_DISTANCE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
void ReportMessage( const wxString& aMessage )
|
|
|
|
{
|
|
|
|
KICAD2MCAD_APP& app = wxGetApp();
|
|
|
|
app.m_Panel->AppendMessage( aMessage );
|
|
|
|
}
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
static const wxCmdLineEntryDesc cmdLineDesc[] =
|
|
|
|
{
|
2016-09-22 14:50:44 +00:00
|
|
|
{ wxCMD_LINE_PARAM, NULL, NULL, _( "pcb_filename" ).mb_str(),
|
2016-09-02 10:08:40 +00:00
|
|
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_OPTION_MANDATORY },
|
2016-09-22 14:50:44 +00:00
|
|
|
{ wxCMD_LINE_OPTION, "o", "output-filename", _( "output filename" ).mb_str(),
|
2016-09-18 02:24:04 +00:00
|
|
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
|
2016-09-02 10:08:40 +00:00
|
|
|
#ifdef SUPPORTS_IGES
|
2016-09-22 14:50:44 +00:00
|
|
|
{ wxCMD_LINE_SWITCH, "fmt-iges", NULL, _("IGES output (default STEP)").mb_str(),
|
2016-09-02 10:08:40 +00:00
|
|
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
|
|
|
|
#endif
|
2016-09-22 14:50:44 +00:00
|
|
|
{ wxCMD_LINE_SWITCH, "f", "force", _( "overwrite output file" ).mb_str(),
|
2016-09-18 02:24:04 +00:00
|
|
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
|
2016-09-22 14:50:44 +00:00
|
|
|
{ wxCMD_LINE_SWITCH, NULL, "drill-origin", _( "Use Drill Origin for output origin" ).mb_str(),
|
2016-09-02 10:08:40 +00:00
|
|
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
|
2016-09-22 14:50:44 +00:00
|
|
|
{ wxCMD_LINE_SWITCH, NULL, "grid-origin", _( "Use Grid Origin for output origin" ).mb_str(),
|
2016-09-18 02:24:04 +00:00
|
|
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
|
|
|
|
{ wxCMD_LINE_OPTION, NULL, "user-origin",
|
2016-09-22 14:50:44 +00:00
|
|
|
_( "User-specified output origin ex. 1x1in, 1x1inch, 25.4x25.4mm (default mm)" ).mb_str(),
|
2016-09-18 02:24:04 +00:00
|
|
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
|
2016-09-18 00:25:10 +00:00
|
|
|
{ wxCMD_LINE_SWITCH, NULL, "no-virtual",
|
2016-09-22 14:50:44 +00:00
|
|
|
_( "exclude 3D models for components with 'virtual' attribute" ).mb_str(),
|
2016-09-18 00:25:10 +00:00
|
|
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
|
2018-06-19 08:14:10 +00:00
|
|
|
{ wxCMD_LINE_OPTION, NULL, "min-distance",
|
|
|
|
_( "Minimum distance between points to treat them as separate ones (default 0.01 mm)" ).mb_str(),
|
|
|
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
|
2016-09-22 14:50:44 +00:00
|
|
|
{ wxCMD_LINE_SWITCH, "h", NULL, _( "display this message" ).mb_str(),
|
2016-09-02 10:08:40 +00:00
|
|
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
|
2020-07-02 19:17:45 +00:00
|
|
|
{ wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 }
|
2016-09-02 10:08:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
bool KICAD2MCAD_APP::OnInit()
|
|
|
|
{
|
|
|
|
if( !wxApp::OnInit() )
|
|
|
|
return false;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
// create the main application window
|
2018-10-02 06:34:07 +00:00
|
|
|
m_frame = new KICAD2STEP_FRAME( "Kicad2step" );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
m_Panel = m_frame->m_panelKicad2Step;
|
|
|
|
m_Panel->m_params = m_params;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2020-02-15 09:58:44 +00:00
|
|
|
// and show it (a wxFrame is not shown when created initially)
|
2018-09-20 09:05:52 +00:00
|
|
|
m_frame->Show( true );
|
|
|
|
m_frame->Iconize( false );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
int KICAD2MCAD_APP::OnRun()
|
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
int diag = m_Panel->RunConverter();
|
|
|
|
wxApp::OnRun(); // Start the main loop event, to manage the main frame
|
2020-02-15 09:58:44 +00:00
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
return diag;
|
2018-09-20 09:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KICAD2STEP_FRAME::KICAD2STEP_FRAME(const wxString& title)
|
|
|
|
: KICAD2STEP_FRAME_BASE(NULL, wxID_ANY, title)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KICAD2MCAD_APP::OnInitCmdLine( wxCmdLineParser& parser )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
|
|
|
parser.SetDesc( cmdLineDesc );
|
|
|
|
parser.SetSwitchChars( "-" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
PANEL_KICAD2STEP::PANEL_KICAD2STEP( wxWindow* parent, wxWindowID id,
|
|
|
|
const wxPoint& pos, const wxSize& size, long style ):
|
|
|
|
wxPanel( parent, id, pos, size, style )
|
|
|
|
{
|
|
|
|
wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
m_tcMessages = new wxTextCtrl( this, wxID_ANY, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY );
|
|
|
|
bSizer->Add( m_tcMessages, 1, wxALL|wxEXPAND, 5 );
|
|
|
|
|
|
|
|
SetSizer( bSizer );
|
|
|
|
Layout();
|
|
|
|
bSizer->Fit( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_KICAD2STEP::AppendMessage( const wxString& aMessage )
|
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
m_tcMessages->AppendText( aMessage );
|
|
|
|
wxSafeYield();
|
2018-09-20 09:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KICAD2MCAD_APP::OnCmdLineParsed( wxCmdLineParser& parser )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
|
|
|
#ifdef SUPPORTS_IGES
|
2016-09-18 02:24:04 +00:00
|
|
|
if( parser.Found( "fmt-iges" ) )
|
2016-09-02 10:08:40 +00:00
|
|
|
m_fmtIGES = true;
|
|
|
|
#endif
|
|
|
|
|
2016-09-18 02:24:04 +00:00
|
|
|
if( parser.Found( "f" ) )
|
2018-09-20 09:05:52 +00:00
|
|
|
m_params.m_overwrite = true;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2016-09-18 02:24:04 +00:00
|
|
|
if( parser.Found( "grid-origin" ) )
|
2018-09-20 09:05:52 +00:00
|
|
|
m_params.m_useGridOrigin = true;
|
2016-09-04 07:08:56 +00:00
|
|
|
|
2016-09-18 02:24:04 +00:00
|
|
|
if( parser.Found( "drill-origin" ) )
|
2018-09-20 09:05:52 +00:00
|
|
|
m_params. m_useDrillOrigin = true;
|
2016-09-04 07:08:56 +00:00
|
|
|
|
2016-09-18 00:25:10 +00:00
|
|
|
if( parser.Found( "no-virtual" ) )
|
2018-09-20 09:05:52 +00:00
|
|
|
m_params.m_includeVirtual = false;
|
2016-09-18 00:25:10 +00:00
|
|
|
|
2016-09-18 02:24:04 +00:00
|
|
|
wxString tstr;
|
|
|
|
|
|
|
|
if( parser.Found( "user-origin", &tstr ) )
|
|
|
|
{
|
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( std::string( tstr.ToUTF8() ) );
|
2018-09-20 09:05:52 +00:00
|
|
|
istr >> m_params.m_xOrigin;
|
2016-09-18 02:24:04 +00:00
|
|
|
|
|
|
|
if( istr.fail() )
|
|
|
|
{
|
|
|
|
parser.Usage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char tmpc;
|
|
|
|
istr >> tmpc;
|
|
|
|
|
|
|
|
if( istr.fail() || ( tmpc != 'x' && tmpc != 'X' ) )
|
|
|
|
{
|
|
|
|
parser.Usage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
istr >> m_params.m_yOrigin;
|
2016-09-18 02:24:04 +00:00
|
|
|
|
|
|
|
if( istr.fail() )
|
|
|
|
{
|
|
|
|
parser.Usage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !istr.eof() )
|
|
|
|
{
|
|
|
|
std::string tunit;
|
|
|
|
istr >> tunit;
|
|
|
|
|
|
|
|
if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) )
|
|
|
|
{
|
2018-09-20 09:05:52 +00:00
|
|
|
m_params.m_xOrigin *= 25.4;
|
|
|
|
m_params.m_yOrigin *= 25.4;
|
2018-06-19 08:01:32 +00:00
|
|
|
}
|
|
|
|
else if( tunit.compare( "mm" ) )
|
|
|
|
{
|
|
|
|
parser.Usage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-19 08:14:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( parser.Found( "min-distance", &tstr ) )
|
|
|
|
{
|
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( std::string( tstr.ToUTF8() ) );
|
2018-09-20 09:05:52 +00:00
|
|
|
istr >> m_params.m_minDistance;
|
2018-06-19 08:14:10 +00:00
|
|
|
|
|
|
|
if( istr.fail() )
|
|
|
|
{
|
|
|
|
parser.Usage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !istr.eof() )
|
|
|
|
{
|
|
|
|
std::string tunit;
|
|
|
|
istr >> tunit;
|
|
|
|
|
|
|
|
if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) )
|
|
|
|
{
|
2018-09-20 09:05:52 +00:00
|
|
|
m_params.m_minDistance *= 25.4;
|
2016-09-18 02:24:04 +00:00
|
|
|
}
|
|
|
|
else if( tunit.compare( "mm" ) )
|
|
|
|
{
|
|
|
|
parser.Usage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( parser.Found( "o", &tstr ) )
|
2018-09-20 09:05:52 +00:00
|
|
|
m_params.m_outputFile = tstr;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2016-09-18 00:25:10 +00:00
|
|
|
|
|
|
|
if( parser.GetParamCount() < 1 )
|
|
|
|
{
|
|
|
|
parser.Usage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
m_params.m_filename = parser.GetParam( 0 );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
// Smart class that will swap streambufs and replace them when object goes out of scope.
|
|
|
|
// ( ensure the initial stream buffer is restored )
|
|
|
|
// see:
|
|
|
|
// https://groups.google.com/forum/#!topic/borland.public.cppbuilder.language/Uua6t3VhELA
|
|
|
|
// It is useful here to redirect for instance cout or cerr to a string stream
|
|
|
|
class STREAMBUF_SWAPPER
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-09-20 09:05:52 +00:00
|
|
|
public:
|
2020-02-15 09:58:44 +00:00
|
|
|
STREAMBUF_SWAPPER( std::ostream & orig, std::ostream & replacement )
|
2018-09-20 09:05:52 +00:00
|
|
|
: m_buf( orig.rdbuf() ), m_str( orig )
|
|
|
|
{
|
|
|
|
orig.rdbuf( replacement.rdbuf() );
|
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
~STREAMBUF_SWAPPER()
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-09-20 09:05:52 +00:00
|
|
|
m_str.rdbuf( m_buf);
|
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
private:
|
|
|
|
std::streambuf * m_buf;
|
|
|
|
std::ostream & m_str;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int PANEL_KICAD2STEP::RunConverter()
|
|
|
|
{
|
|
|
|
wxFileName fname( m_params.m_filename );
|
|
|
|
|
|
|
|
if( !fname.FileExists() )
|
|
|
|
{
|
|
|
|
wxMessageBox( wxString::Format( "No such file: %s", m_params.m_filename ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
wxFileName out_fname;
|
2016-09-18 02:24:04 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
if( m_params.m_outputFile.empty() )
|
2018-09-11 07:22:10 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
out_fname.Assign( fname.GetFullPath() );
|
|
|
|
out_fname.SetExt( m_params.getOutputExt() );
|
2018-09-11 07:22:10 +00:00
|
|
|
}
|
2016-09-18 02:24:04 +00:00
|
|
|
else
|
2018-09-11 07:22:10 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
out_fname.Assign( m_params.m_outputFile );
|
2016-09-18 02:24:04 +00:00
|
|
|
|
2018-09-11 07:22:10 +00:00
|
|
|
// Set the file extension if the user's requested
|
|
|
|
// file name does not have an extension.
|
2018-10-02 06:34:07 +00:00
|
|
|
if( !out_fname.HasExt() )
|
|
|
|
out_fname.SetExt( m_params.getOutputExt() );
|
2017-08-09 17:17:26 +00:00
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
if( out_fname.FileExists() && !m_params.m_overwrite )
|
2018-09-11 07:23:11 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
ReportMessage( "** Output already exists.\n"
|
2018-09-20 09:05:52 +00:00
|
|
|
"Enable the force overwrite flag to overwrite it." );
|
2018-09-11 07:23:11 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
wxString outfile = out_fname.GetFullPath();
|
|
|
|
KICADPCB pcb;
|
2016-09-18 02:24:04 +00:00
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
pcb.SetOrigin( m_params.m_xOrigin, m_params.m_yOrigin );
|
|
|
|
pcb.SetMinDistance( m_params.m_minDistance );
|
2018-10-02 06:34:07 +00:00
|
|
|
ReportMessage( wxString::Format( "Read: %s\n", m_params.m_filename ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
// create the new streams to "redirect" cout and cerr output to
|
|
|
|
// msgs_from_opencascade and errors_from_opencascade
|
2018-09-20 09:05:52 +00:00
|
|
|
std::ostringstream msgs_from_opencascade;
|
2018-10-02 06:34:07 +00:00
|
|
|
std::ostringstream errors_from_opencascade;
|
2020-02-15 09:58:44 +00:00
|
|
|
STREAMBUF_SWAPPER swapper_cout(std::cout, msgs_from_opencascade);
|
|
|
|
STREAMBUF_SWAPPER swapper_cerr(std::cerr, errors_from_opencascade);
|
2018-09-20 09:05:52 +00:00
|
|
|
|
|
|
|
if( pcb.ReadFile( m_params.m_filename ) )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-09-20 09:05:52 +00:00
|
|
|
if( m_params.m_useDrillOrigin )
|
2016-09-04 07:08:56 +00:00
|
|
|
pcb.UseDrillOrigin( true );
|
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
if( m_params.m_useGridOrigin )
|
2016-09-04 07:08:56 +00:00
|
|
|
pcb.UseGridOrigin( true );
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
bool res;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
ReportMessage( "Build STEP data\n" );
|
|
|
|
|
2020-10-06 14:03:08 +00:00
|
|
|
res = pcb.ComposePCB( m_params.m_includeVirtual );
|
|
|
|
|
|
|
|
if( !res )
|
|
|
|
{
|
|
|
|
ReportMessage( "\n**Error building STEP board model. Abort export **\n" );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
ReportMessage( "Write STEP file\n" );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
#ifdef SUPPORTS_IGES
|
|
|
|
if( m_fmtIGES )
|
2018-09-11 07:23:11 +00:00
|
|
|
res = pcb.WriteIGES( outfile );
|
2016-09-02 10:08:40 +00:00
|
|
|
else
|
|
|
|
#endif
|
2018-09-11 07:23:11 +00:00
|
|
|
res = pcb.WriteSTEP( outfile );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
if( !res )
|
2018-09-20 09:05:52 +00:00
|
|
|
{
|
2020-10-06 14:03:08 +00:00
|
|
|
ReportMessage( "\nError Write STEP file\n" );
|
2016-09-02 10:08:40 +00:00
|
|
|
return -1;
|
2018-09-20 09:05:52 +00:00
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
}
|
2018-07-26 12:37:44 +00:00
|
|
|
catch( const Standard_Failure& e )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
wxString err = e.GetMessageString();
|
|
|
|
wxMessageBox( err, "Export Error" );
|
|
|
|
|
|
|
|
ReportMessage( wxString::Format( "\nExport Error: %s\n", err ) );
|
|
|
|
ReportMessage( "\n*** Abort export ***\n" );
|
2016-09-02 10:08:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
2018-09-20 09:05:52 +00:00
|
|
|
wxMessageBox( "(no exception information)", "Unknown error" );
|
2018-10-02 06:34:07 +00:00
|
|
|
ReportMessage( "\nUnknown error\n*** Abort export ***\n" );
|
2016-09-02 10:08:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
wxString msgs, errs;
|
|
|
|
msgs << msgs_from_opencascade.str();
|
|
|
|
ReportMessage( msgs );
|
|
|
|
|
|
|
|
ReportMessage( wxString::Format( "\nStep file %s created\n\n", outfile ) );
|
|
|
|
|
|
|
|
errs << errors_from_opencascade.str();
|
|
|
|
ReportMessage( errs );
|
|
|
|
|
|
|
|
// Check the output log for an indication of success
|
|
|
|
bool success = msgs.Contains( "Done" );
|
2018-09-20 09:05:52 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
if( !errs.IsEmpty() ) // Any troubles?
|
|
|
|
{
|
|
|
|
if( !success )
|
|
|
|
msg = "Unable to create STEP file.\n"
|
2020-10-06 14:03:08 +00:00
|
|
|
"Check that the board has a valid outline and models.";
|
2018-10-02 06:34:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = "STEP file has been created, but there are warnings.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // No error messages: the file is expected OK
|
|
|
|
{
|
|
|
|
msg.Printf( "STEP file:\n%s\nhas been created successfully.", outfile );
|
|
|
|
}
|
|
|
|
|
|
|
|
ReportMessage( msg );
|
2018-09-20 09:05:52 +00:00
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-09-11 07:22:10 +00:00
|
|
|
|
|
|
|
|
2018-09-20 09:05:52 +00:00
|
|
|
wxString KICAD2MCAD_PRMS::getOutputExt() const
|
2018-09-11 07:22:10 +00:00
|
|
|
{
|
|
|
|
#ifdef SUPPORTS_IGES
|
|
|
|
if( m_fmtIGES )
|
|
|
|
return wxString( "igs" );
|
|
|
|
else
|
|
|
|
#endif
|
2018-10-02 06:34:07 +00:00
|
|
|
return wxString( "step" );
|
2018-09-11 07:22:10 +00:00
|
|
|
}
|