From 110b05fe78b018881bf77773da3ce199695587d7 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 20 Sep 2018 11:05:52 +0200 Subject: [PATCH] kicad2step: convert it from a wxAppConsole to a wxApp, using a wxFrame/wxPanel --- pcbnew/dialogs/dialog_export_step.cpp | 5 +- utils/kicad2step/CMakeLists.txt | 1 + utils/kicad2step/kicad2step.cpp | 240 +++++++++++++++------ utils/kicad2step/kicad2step_frame_base.cpp | 31 +++ utils/kicad2step/kicad2step_frame_base.fpb | 200 +++++++++++++++++ utils/kicad2step/kicad2step_frame_base.h | 47 ++++ utils/kicad2step/panel_kicad2step.h | 81 +++++++ utils/kicad2step/pcb/3d_resolver.cpp | 7 +- utils/kicad2step/pcb/kicadpcb.cpp | 119 +++------- utils/kicad2step/pcb/kicadpcb.h | 10 +- utils/kicad2step/pcb/oce_utils.cpp | 202 ++++++----------- utils/kicad2step/pcb/oce_utils.h | 4 +- 12 files changed, 643 insertions(+), 304 deletions(-) create mode 100644 utils/kicad2step/kicad2step_frame_base.cpp create mode 100644 utils/kicad2step/kicad2step_frame_base.fpb create mode 100644 utils/kicad2step/kicad2step_frame_base.h create mode 100644 utils/kicad2step/panel_kicad2step.h diff --git a/pcbnew/dialogs/dialog_export_step.cpp b/pcbnew/dialogs/dialog_export_step.cpp index 239c441647..ce77207afd 100644 --- a/pcbnew/dialogs/dialog_export_step.cpp +++ b/pcbnew/dialogs/dialog_export_step.cpp @@ -341,13 +341,16 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent ) { wxBusyCursor dummy; - result = wxExecute( cmdK2S, output, errors, wxEXEC_SYNC | wxEXEC_HIDE_CONSOLE ); + result = wxExecute( cmdK2S, output, errors, wxEXEC_SYNC | wxEXEC_SHOW_CONSOLE ); } // Check the output log for an indication of success, // the value returned by wxExecute is not conclusive for( auto& l : output ) { + if( !l.IsEmpty() ) + reporter.ReportTail( l, REPORTER::RPT_INFO ); + if( l.Contains( "Done" ) ) { success = true; diff --git a/utils/kicad2step/CMakeLists.txt b/utils/kicad2step/CMakeLists.txt index 3b6b4dcbd2..32204ab3ae 100644 --- a/utils/kicad2step/CMakeLists.txt +++ b/utils/kicad2step/CMakeLists.txt @@ -4,6 +4,7 @@ include_directories( SYSTEM ) set( KS2_LIB_FILES + kicad2step.cpp pcb/3d_resolver.cpp pcb/base.cpp pcb/kicadmodel.cpp diff --git a/utils/kicad2step/kicad2step.cpp b/utils/kicad2step/kicad2step.cpp index df3dc8e7a9..c11ab49c69 100644 --- a/utils/kicad2step/kicad2step.cpp +++ b/utils/kicad2step/kicad2step.cpp @@ -2,7 +2,7 @@ * This program source code file is part of kicad2mcad * * Copyright (C) 2016 Cirilo Bernardo - * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "wx/wx.h" #include #include #include @@ -30,11 +31,15 @@ #include #include #include -#include +#include // In open cascade #include "pcb/kicadpcb.h" +#include "kicad2step_frame_base.h" +#include "panel_kicad2step.h" -class KICAD2MCAD : public wxAppConsole +class KICAD2STEP_FRAME; + +class KICAD2MCAD_APP : public wxApp { public: virtual bool OnInit() override; @@ -43,23 +48,45 @@ public: virtual bool OnCmdLineParsed(wxCmdLineParser& parser) override; private: - ///> Returns file extension for the selected output format - wxString getOutputExt() const; + KICAD2MCAD_PRMS m_params; -#ifdef SUPPORTS_IGES - bool m_fmtIGES; -#endif - bool m_overwrite; - bool m_useGridOrigin; - bool m_useDrillOrigin; - bool m_includeVirtual; - wxString m_filename; - wxString m_outputFile; - double m_xOrigin; - double m_yOrigin; - double m_minDistance; +public: + PANEL_KICAD2STEP* m_Panel; + KICAD2STEP_FRAME * m_frame; }; +wxIMPLEMENT_APP(KICAD2MCAD_APP); + +class KICAD2STEP_FRAME : public KICAD2STEP_FRAME_BASE +{ +public: + KICAD2STEP_FRAME(const wxString& title); + +private: +}; + +KICAD2MCAD_PRMS::KICAD2MCAD_PRMS() +{ +#ifdef SUPPORTS_IGES + m_fmtIGES = false; +#endif + m_overwrite = false; + m_useGridOrigin = false; + m_useDrillOrigin = false; + m_includeVirtual = true; + m_xOrigin = 0.0; + m_yOrigin = 0.0; + m_minDistance = MIN_DISTANCE; + +} + +void ReportMessage( const wxString& aMessage ) +{ + KICAD2MCAD_APP& app = wxGetApp(); + app.m_Panel->AppendMessage( aMessage ); +} + + static const wxCmdLineEntryDesc cmdLineDesc[] = { { wxCMD_LINE_PARAM, NULL, NULL, _( "pcb_filename" ).mb_str(), @@ -91,30 +118,41 @@ static const wxCmdLineEntryDesc cmdLineDesc[] = }; -wxIMPLEMENT_APP_CONSOLE( KICAD2MCAD ); - - -bool KICAD2MCAD::OnInit() +bool KICAD2MCAD_APP::OnInit() { -#ifdef SUPPORTS_IGES - m_fmtIGES = false; -#endif - m_overwrite = false; - m_useGridOrigin = false; - m_useDrillOrigin = false; - m_includeVirtual = true; - m_xOrigin = 0.0; - m_yOrigin = 0.0; - m_minDistance = MIN_DISTANCE; - - if( !wxAppConsole::OnInit() ) + if( !wxApp::OnInit() ) return false; + // create the main application window + m_frame = new KICAD2STEP_FRAME("Kicad2step"); + + m_Panel = m_frame->m_panelKicad2Step; + m_Panel->m_params = m_params; + + // and show it (the frames, unlike simple controls, are not shown when + // created initially) + m_frame->Show( true ); + m_frame->Iconize( false ); + return true; } -void KICAD2MCAD::OnInitCmdLine( wxCmdLineParser& parser ) +int KICAD2MCAD_APP::OnRun() +{ + m_frame->Show(true); + m_Panel->RunConverter(); + return 0; +} + + +KICAD2STEP_FRAME::KICAD2STEP_FRAME(const wxString& title) + : KICAD2STEP_FRAME_BASE(NULL, wxID_ANY, title) +{ +} + + +void KICAD2MCAD_APP::OnInitCmdLine( wxCmdLineParser& parser ) { parser.SetDesc( cmdLineDesc ); parser.SetSwitchChars( "-" ); @@ -122,7 +160,29 @@ void KICAD2MCAD::OnInitCmdLine( wxCmdLineParser& parser ) } -bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) +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 ) +{ + m_tcMessages->AppendText( aMessage ); wxSafeYield(); +} + + +bool KICAD2MCAD_APP::OnCmdLineParsed( wxCmdLineParser& parser ) { #ifdef SUPPORTS_IGES if( parser.Found( "fmt-iges" ) ) @@ -130,16 +190,16 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) #endif if( parser.Found( "f" ) ) - m_overwrite = true; + m_params.m_overwrite = true; if( parser.Found( "grid-origin" ) ) - m_useGridOrigin = true; + m_params.m_useGridOrigin = true; if( parser.Found( "drill-origin" ) ) - m_useDrillOrigin = true; + m_params. m_useDrillOrigin = true; if( parser.Found( "no-virtual" ) ) - m_includeVirtual = false; + m_params.m_includeVirtual = false; wxString tstr; @@ -147,7 +207,7 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) { std::istringstream istr; istr.str( std::string( tstr.ToUTF8() ) ); - istr >> m_xOrigin; + istr >> m_params.m_xOrigin; if( istr.fail() ) { @@ -164,7 +224,7 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) return false; } - istr >> m_yOrigin; + istr >> m_params.m_yOrigin; if( istr.fail() ) { @@ -179,8 +239,8 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) { - m_xOrigin *= 25.4; - m_yOrigin *= 25.4; + m_params.m_xOrigin *= 25.4; + m_params.m_yOrigin *= 25.4; } else if( tunit.compare( "mm" ) ) { @@ -195,7 +255,7 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) { std::istringstream istr; istr.str( std::string( tstr.ToUTF8() ) ); - istr >> m_minDistance; + istr >> m_params.m_minDistance; if( istr.fail() ) { @@ -210,7 +270,7 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) { - m_minDistance *= 25.4; + m_params.m_minDistance *= 25.4; } else if( tunit.compare( "mm" ) ) { @@ -221,7 +281,7 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) } if( parser.Found( "o", &tstr ) ) - m_outputFile = tstr; + m_params.m_outputFile = tstr; if( parser.GetParamCount() < 1 ) @@ -230,70 +290,98 @@ bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) return false; } - m_filename = parser.GetParam( 0 ); + m_params.m_filename = parser.GetParam( 0 ); return true; } -int KICAD2MCAD::OnRun() +// 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 { - wxFileName fname( m_filename ); +public: + STREAMBUF_SWAPPER( ostream & orig, ostream & replacement ) + : m_buf( orig.rdbuf() ), m_str( orig ) + { + orig.rdbuf( replacement.rdbuf() ); + } + + ~STREAMBUF_SWAPPER() + { + m_str.rdbuf( m_buf); + } + +private: + std::streambuf * m_buf; + std::ostream & m_str; +}; + + +int PANEL_KICAD2STEP::RunConverter() +{ + wxFileName fname( m_params.m_filename ); if( !fname.FileExists() ) { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - ostr << " * no such file: '" << m_filename.ToUTF8() << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + wxMessageBox( wxString::Format( "No such file: %s", m_params.m_filename ) ); return -1; } wxFileName tfname; - if( m_outputFile.empty() ) + if( m_params.m_outputFile.empty() ) { tfname.Assign( fname.GetFullPath() ); - tfname.SetExt( getOutputExt() ); + tfname.SetExt( m_params.getOutputExt() ); } else { - tfname.Assign( m_outputFile ); + tfname.Assign( m_params.m_outputFile ); // Set the file extension if the user's requested // file name does not have an extension. if( !tfname.HasExt() ) - tfname.SetExt( getOutputExt() ); + tfname.SetExt( m_params.getOutputExt() ); } - if( tfname.FileExists() && !m_overwrite ) + if( tfname.FileExists() && !m_params.m_overwrite ) { - std::cerr << "** Output already exists. " - << "Enable the force overwrite flag to overwrite it." << std::endl; + wxMessageBox( "** Output already exists.\n" + "Enable the force overwrite flag to overwrite it." ); return -1; } wxString outfile = tfname.GetFullPath(); - KICADPCB pcb; + KICADPCB pcb( m_tcMessages ); - pcb.SetOrigin( m_xOrigin, m_yOrigin ); - pcb.SetMinDistance( m_minDistance ); + pcb.SetOrigin( m_params.m_xOrigin, m_params.m_yOrigin ); + pcb.SetMinDistance( m_params.m_minDistance ); + m_tcMessages->AppendText( wxString::Format( "Read: %s\n", m_params.m_filename ) ); - if( pcb.ReadFile( m_filename ) ) + // create the new stream to "redirect" cout's output to + std::ostringstream msgs_from_opencascade; + STREAMBUF_SWAPPER swapper(cout, msgs_from_opencascade); + + if( pcb.ReadFile( m_params.m_filename ) ) { - if( m_useDrillOrigin ) + if( m_params.m_useDrillOrigin ) pcb.UseDrillOrigin( true ); - if( m_useGridOrigin ) + if( m_params.m_useGridOrigin ) pcb.UseGridOrigin( true ); bool res; try { - pcb.ComposePCB( m_includeVirtual ); + m_tcMessages->AppendText( "Build STEP data\n" ); + pcb.ComposePCB( m_params.m_includeVirtual ); + m_tcMessages->AppendText( "Start WriteSTEP\n" ); #ifdef SUPPORTS_IGES if( m_fmtIGES ) @@ -303,25 +391,37 @@ int KICAD2MCAD::OnRun() res = pcb.WriteSTEP( outfile ); if( !res ) + { + wxMessageBox( "Error WriteSTEP" ); return -1; + } + + m_tcMessages->AppendText( wxString::Format( "Step file %s created\n", outfile ) ); } catch( const Standard_Failure& e ) { e.Print( std::cerr ); + wxMessageBox( "Error Read" ); return -1; } catch( ... ) { - std::cerr << "** (no exception information)\n"; + wxMessageBox( "(no exception information)", "Unknown error" ); return -1; } } + wxString msg; + msg << msgs_from_opencascade.str(); + m_tcMessages->AppendText( msg ); + + wxMessageBox( "End kicad2step" ); + return 0; } -wxString KICAD2MCAD::getOutputExt() const +wxString KICAD2MCAD_PRMS::getOutputExt() const { #ifdef SUPPORTS_IGES if( m_fmtIGES ) diff --git a/utils/kicad2step/kicad2step_frame_base.cpp b/utils/kicad2step/kicad2step_frame_base.cpp new file mode 100644 index 0000000000..b40c1072b9 --- /dev/null +++ b/utils/kicad2step/kicad2step_frame_base.cpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jul 11 2018) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "kicad2step_frame_base.h" + +/////////////////////////////////////////////////////////////////////////// + +KICAD2STEP_FRAME_BASE::KICAD2STEP_FRAME_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizerMain; + bSizerMain = new wxBoxSizer( wxVERTICAL ); + + m_panelKicad2Step = new PANEL_KICAD2STEP( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + bSizerMain->Add( m_panelKicad2Step, 1, wxEXPAND | wxALL, 5 ); + + + this->SetSizer( bSizerMain ); + this->Layout(); + + this->Centre( wxBOTH ); +} + +KICAD2STEP_FRAME_BASE::~KICAD2STEP_FRAME_BASE() +{ +} diff --git a/utils/kicad2step/kicad2step_frame_base.fpb b/utils/kicad2step/kicad2step_frame_base.fpb new file mode 100644 index 0000000000..cd8ee33d1a --- /dev/null +++ b/utils/kicad2step/kicad2step_frame_base.fpb @@ -0,0 +1,200 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + kicad2step_frame_base + 1000 + none + + 1 + kicad2step_frame + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + KICAD2STEP_FRAME_BASE + + 500,300 + wxDEFAULT_FRAME_STYLE + ; forward_declare; forward_declare + Kicad2step Converter + + + + wxTAB_TRAVERSAL + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bSizerMain + wxVERTICAL + none + + 5 + wxEXPAND | wxALL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_panelKicad2Step + 1 + + + public + 1 + + Resizable + 1 + + PANEL_KICAD2STEP; panel_kicad2step.h; Not forward_declare + 0 + + + + wxTAB_TRAVERSAL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/utils/kicad2step/kicad2step_frame_base.h b/utils/kicad2step/kicad2step_frame_base.h new file mode 100644 index 0000000000..404a712750 --- /dev/null +++ b/utils/kicad2step/kicad2step_frame_base.h @@ -0,0 +1,47 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jul 11 2018) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __KICAD2STEP_FRAME_BASE_H__ +#define __KICAD2STEP_FRAME_BASE_H__ + +#include +#include +#include +#include "panel_kicad2step.h" +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class KICAD2STEP_FRAME_BASE +/////////////////////////////////////////////////////////////////////////////// +class KICAD2STEP_FRAME_BASE : public wxFrame +{ + private: + + protected: + + public: + PANEL_KICAD2STEP* m_panelKicad2Step; + + KICAD2STEP_FRAME_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, + const wxString& title = _("Kicad2step Converter"), const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL ); + + ~KICAD2STEP_FRAME_BASE(); + +}; + +#endif //__KICAD2STEP_FRAME_BASE_H__ diff --git a/utils/kicad2step/panel_kicad2step.h b/utils/kicad2step/panel_kicad2step.h new file mode 100644 index 0000000000..fa01ae8fc2 --- /dev/null +++ b/utils/kicad2step/panel_kicad2step.h @@ -0,0 +1,81 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016 + * + * 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 3 + * 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-3.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 + */ + +/** + * @file panel_kicad2step.h + * declares the main PCB object + */ + +#ifndef PANEL_KICAD2STEP_H +#define PANEL_KICAD2STEP_H + +#include +#include +#include + +class KICAD2MCAD_PRMS // A small class to handle parameters of conversion +{ +public: + KICAD2MCAD_PRMS(); + + ///> Returns file extension for the selected output format + wxString getOutputExt() const; + +public: +#ifdef SUPPORTS_IGES + bool m_fmtIGES; +#endif + bool m_overwrite; + bool m_useGridOrigin; + bool m_useDrillOrigin; + bool m_includeVirtual; + wxString m_filename; + wxString m_outputFile; + double m_xOrigin; + double m_yOrigin; + double m_minDistance; + +}; + +class PANEL_KICAD2STEP: public wxPanel +{ +public: + PANEL_KICAD2STEP( wxWindow* parent, wxWindowID id = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), + long style = wxTAB_TRAVERSAL ); + + /** Run the Kicad to STEP converter + */ + int RunConverter(); + + /** Add a message to m_tcMessages + */ + void AppendMessage( const wxString& aMessage ); + + KICAD2MCAD_PRMS m_params; + +private: + wxTextCtrl* m_tcMessages; +}; + +#endif // #ifndef PANEL_KICAD2STEP_H \ No newline at end of file diff --git a/utils/kicad2step/pcb/3d_resolver.cpp b/utils/kicad2step/pcb/3d_resolver.cpp index 946ff8851c..1d96702671 100644 --- a/utils/kicad2step/pcb/3d_resolver.cpp +++ b/utils/kicad2step/pcb/3d_resolver.cpp @@ -396,10 +396,9 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) if( !( m_errflags & ERRFLG_ENVPATH ) ) { m_errflags |= ERRFLG_ENVPATH; - wxString errmsg = "[3D File Resolver] No such path; ensure the environment var is defined"; - errmsg.append( "\n" ); - errmsg.append( tname ); - wxLogMessage( "%s\n", errmsg.ToUTF8() ); + wxString errmsg = "[3D File Resolver] No such path; ensure the environment var is defined\n"; + errmsg << tname << "\n"; + ReportMessage( errmsg ); } return wxEmptyString; diff --git a/utils/kicad2step/pcb/kicadpcb.cpp b/utils/kicad2step/pcb/kicadpcb.cpp index c8ea03678a..c07a336b5e 100644 --- a/utils/kicad2step/pcb/kicadpcb.cpp +++ b/utils/kicad2step/pcb/kicadpcb.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -41,6 +42,8 @@ #include +#include + /* * GetKicadConfigPath() is taken from KiCad's common.cpp source: * Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr @@ -83,7 +86,7 @@ static wxString GetKicadConfigPath() } -KICADPCB::KICADPCB() +KICADPCB::KICADPCB( wxTextCtrl* aMessageWindow ) { wxFileName cfgdir( GetKicadConfigPath(), "" ); cfgdir.AppendDir( "3d" ); @@ -95,6 +98,7 @@ KICADPCB::KICADPCB() m_useDrillOrigin = false; m_hasGridOrigin = false; m_hasDrillOrigin = false; + m_messageWindow = aMessageWindow; } @@ -113,33 +117,30 @@ KICADPCB::~KICADPCB() } +void KICADPCB::ReportMessage( const wxString& aMessage ) +{ + m_messageWindow->AppendText( aMessage ); wxSafeYield(); +} + + bool KICADPCB::ReadFile( const wxString& aFileName ) { wxFileName fname( aFileName ); if( fname.GetExt() != "kicad_pcb" ) { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - ostr << " * expecting extension 'kicad_pcb', got '"; - ostr << fname.GetExt().ToUTF8() << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "expecting extension kicad_pcb, got %s\n", fname.GetExt() ) ); return false; } if( !fname.FileExists() ) { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - ostr << " * no such file: '" << aFileName.ToUTF8() << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "No such file: %s\n", aFileName ) ); return false; } fname.Normalize(); - m_filename = fname.GetFullPath().ToUTF8(); + m_filename = fname.GetFullPath(); m_resolver.SetProjectDir( fname.GetPath() ); try @@ -150,10 +151,7 @@ bool KICADPCB::ReadFile( const wxString& aFileName ) if( !data ) { - std::ostringstream ostr; - ostr << "* no data in file: '" << aFileName.ToUTF8() << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "No data in file: %s\n", aFileName ) ); return false; } @@ -162,19 +160,12 @@ bool KICADPCB::ReadFile( const wxString& aFileName ) } catch( std::exception& e ) { - std::ostringstream ostr; - ostr << "* error reading file: '" << aFileName.ToUTF8() << "'\n"; - ostr << " * " << e.what() << "\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "error reading file: %s\n%s\n", aFileName, e.what() ) ); return false; } catch( ... ) { - std::ostringstream ostr; - ostr << "* unexpected exception while reading file: '" << aFileName.ToUTF8() << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "unexpected exception while reading file: %s\n", aFileName ) ); return false; } @@ -186,8 +177,7 @@ bool KICADPCB::WriteSTEP( const wxString& aFileName ) { if( m_pcb ) { - std::string filename( aFileName.ToUTF8() ); - return m_pcb->WriteSTEP( filename ); + return m_pcb->WriteSTEP( aFileName ); } return false; @@ -199,8 +189,7 @@ bool KICADPCB::WriteIGES( const wxString& aFileName ) { if( m_pcb ) { - std::string filename( aFileName.ToUTF8() ); - return m_pcb->WriteIGES( filename ); + return m_pcb->WriteIGES( aFileName ); } return false; @@ -219,14 +208,6 @@ bool KICADPCB::parsePCB( SEXPR::SEXPR* data ) SEXPR::SEXPR* child = data->GetChild( 0 ); std::string name = child->GetSymbol(); - if( name != "kicad_pcb" ) - { - std::ostringstream ostr; - ostr << "* data is not a valid PCB file: '" << m_filename << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - return false; - } - bool result = true; for( size_t i = 1; i < nc && result; ++i ) @@ -235,10 +216,7 @@ bool KICADPCB::parsePCB( SEXPR::SEXPR* data ) if( !child->IsList() ) { - std::ostringstream ostr; - ostr << "* corrupt PCB file (line " << child->GetLineNumber(); - ostr << "): '" << m_filename << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); + ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n", child->GetLineNumber() ) ); return false; } @@ -263,10 +241,7 @@ bool KICADPCB::parsePCB( SEXPR::SEXPR* data ) return result; } - std::ostringstream ostr; - ostr << "* data is not a valid PCB file: '" << m_filename << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "data is not a valid PCB file: %s\n", m_filename ) ); return false; } @@ -282,10 +257,7 @@ bool KICADPCB::parseGeneral( SEXPR::SEXPR* data ) if( !child->IsList() ) { - std::ostringstream ostr; - ostr << "* corrupt PCB file (line " << child->GetLineNumber(); - ostr << "): '" << m_filename << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); + ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n", child->GetLineNumber() ) ); return false; } @@ -298,12 +270,9 @@ bool KICADPCB::parseGeneral( SEXPR::SEXPR* data ) return true; } - std::ostringstream ostr; - ostr << "* corrupt PCB file (line " << child->GetLineNumber(); - ostr << "): '" << m_filename << "'\n"; - ostr << "* no PCB thickness specified in general section\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n" + "no PCB thickness specified in general section\n", + child->GetLineNumber() ) ); return false; } @@ -320,10 +289,7 @@ bool KICADPCB::parseLayers( SEXPR::SEXPR* data ) if( !child->IsList() ) { - std::ostringstream ostr; - ostr << "* corrupt PCB file (line " << child->GetLineNumber(); - ostr << "): '" << m_filename << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); + ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n", child->GetLineNumber() ) ); return false; } std::string ref; @@ -362,10 +328,7 @@ bool KICADPCB::parseSetup( SEXPR::SEXPR* data ) if( !child->IsList() ) { - std::ostringstream ostr; - ostr << "* corrupt PCB file (line " << child->GetLineNumber(); - ostr << "): '" << m_filename << "'\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); + ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n", child->GetLineNumber() ) ); return false; } @@ -375,13 +338,8 @@ bool KICADPCB::parseSetup( SEXPR::SEXPR* data ) { if( child->GetNumberOfChildren() != 3 ) { - std::ostringstream ostr; - ostr << "* corrupt PCB file (line " << child->GetLineNumber(); - ostr << "): '" << m_filename << "'\n"; - ostr << "* grid_origin has " << child->GetNumberOfChildren(); - ostr << " children (expected: 3)\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "corrupt PCB file (line %d): grid_origin has %d children (expected: 3)\n", + child->GetLineNumber(), child->GetNumberOfChildren() ) ); return false; } @@ -393,13 +351,8 @@ bool KICADPCB::parseSetup( SEXPR::SEXPR* data ) { if( child->GetNumberOfChildren() != 3 ) { - std::ostringstream ostr; - ostr << "* corrupt PCB file (line " << child->GetLineNumber(); - ostr << "): '" << m_filename << "'\n"; - ostr << "* aux_axis_origin has " << child->GetNumberOfChildren(); - ostr << " children (expected: 3)\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "corrupt PCB file (line %d)m: aux_axis_origin has %d children (expected: 3)\n", + child->GetLineNumber(), child->GetNumberOfChildren() ) ); return false; } @@ -458,10 +411,7 @@ bool KICADPCB::ComposePCB( bool aComposeVirtual ) if( m_modules.empty() && m_curves.empty() ) { - std::ostringstream ostr; - ostr << "** " << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n"; - ostr << "* no PCB data to render\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); + ReportMessage( "Error: no PCB data to render\n" ); return false; } @@ -509,10 +459,7 @@ bool KICADPCB::ComposePCB( bool aComposeVirtual ) if( !m_pcb->CreatePCB() ) { - std::ostringstream ostr; - ostr << "** " << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n"; - ostr << "* could not create PCB solid model\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); + ReportMessage( "could not create PCB solid model\n" ); delete m_pcb; m_pcb = NULL; return false; diff --git a/utils/kicad2step/pcb/kicadpcb.h b/utils/kicad2step/pcb/kicadpcb.h index f754b30ca1..fad152bd31 100644 --- a/utils/kicad2step/pcb/kicadpcb.h +++ b/utils/kicad2step/pcb/kicadpcb.h @@ -39,6 +39,8 @@ #undef SUPPORTS_IGES #endif +extern void ReportMessage( const wxString& aMessage ); + namespace SEXPR { class SEXPR; @@ -52,7 +54,7 @@ class KICADPCB { private: S3D_RESOLVER m_resolver; - std::string m_filename; + wxString m_filename; PCBMODEL* m_pcb; DOUBLET m_origin; DOUBLET m_gridOrigin; @@ -71,6 +73,7 @@ private: double m_thickness; std::vector< KICADMODULE* > m_modules; std::vector< KICADCURVE* > m_curves; + wxTextCtrl* m_messageWindow; // to print messages bool parsePCB( SEXPR::SEXPR* data ); bool parseGeneral( SEXPR::SEXPR* data ); @@ -80,9 +83,12 @@ private: bool parseCurve( SEXPR::SEXPR* data, CURVE_TYPE aCurveType ); public: - KICADPCB(); + KICADPCB( wxTextCtrl* aMessageWindow ); virtual ~KICADPCB(); + // print aMessage to to called window + void ReportMessage( const wxString& aMessage ); + int GetLayerId( std::string& aLayerName ); void SetOrigin( double aXOrigin, double aYOrigin ) diff --git a/utils/kicad2step/pcb/oce_utils.cpp b/utils/kicad2step/pcb/oce_utils.cpp index 1556b9d243..a9d5da528f 100644 --- a/utils/kicad2step/pcb/oce_utils.cpp +++ b/utils/kicad2step/pcb/oce_utils.cpp @@ -26,8 +26,9 @@ #include #include #include +#include #include -#include +#include #include "oce_utils.h" #include "kicadpad.h" @@ -164,9 +165,9 @@ FormatType fileType( const char* aFileName ) if( !lfile.FileExists() ) { std::ostringstream ostr; -#ifdef DEBUG +#ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ +#endif /* __WXDEBUG */ ostr << " * no such file: '" << aFileName << "'\n"; wxLogMessage( "%s", ostr.str().c_str() ); @@ -257,9 +258,9 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) if( distance < m_minDistance2 ) { std::ostringstream ostr; -#ifdef DEBUG +#ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ +#endif /* __WXDEBUG */ ostr << " * rejected a zero-length " << aCurve->Describe() << "\n"; wxLogMessage( "%s", ostr.str().c_str() ); return false; @@ -276,9 +277,9 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) if( rad < m_minDistance2 ) { std::ostringstream ostr; -#ifdef DEBUG +#ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ +#endif /* __WXDEBUG */ ostr << " * rejected a zero-radius " << aCurve->Describe() << "\n"; wxLogMessage( "%s", ostr.str().c_str() ); return false; @@ -316,9 +317,9 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) if( rad < m_minDistance2 ) { std::ostringstream ostr; -#ifdef DEBUG +#ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ +#endif /* __WXDEBUG */ ostr << " * rejected an arc with equivalent end points, " << aCurve->Describe() << "\n"; wxLogMessage( "%s", ostr.str().c_str() ); @@ -422,9 +423,9 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) do { std::ostringstream ostr; -#ifdef DEBUG +#ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ +#endif /* __WXDEBUG */ ostr << " * unsupported curve type: '" << aCurve->m_form << "'\n"; wxLogMessage( "%s", ostr.str().c_str() ); } while( 0 ); @@ -584,26 +585,18 @@ bool PCBMODEL::AddComponent( const std::string& aFileName, const std::string& aR { if( aFileName.empty() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * no model defined for component '" << aRefDes << "'\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "no model defined for component %s\n", aRefDes ) ); return false; } + ReportMessage( wxString::Format( "add component %s\n", aRefDes ) ); + // first retrieve a label TDF_Label lmodel; if( !getModelLabel( aFileName, aScale, lmodel ) ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * no model for filename '" << aFileName << "'\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "no model for filename %s\n", aFileName ) ); return false; } @@ -612,12 +605,7 @@ bool PCBMODEL::AddComponent( const std::string& aFileName, const std::string& aR if( !getModelLocation( aBottom, aPosition, aRotation, aOffset, aOrientation, toploc ) ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * no location data for filename '" << aFileName << "'\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "no location data for filename %s\n", aFileName ) ); return false; } @@ -626,12 +614,7 @@ bool PCBMODEL::AddComponent( const std::string& aFileName, const std::string& aR if( llabel.IsNull() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * could not add component with filename '" << aFileName << "'\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "could not add component with filename %s\n", aFileName ) ); return false; } @@ -670,12 +653,7 @@ bool PCBMODEL::CreatePCB() if( m_curves.empty() || m_mincurve == m_curves.end() ) { m_hasPCB = true; - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * no valid board outline\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( "no valid board outline\n" ); return false; } @@ -694,13 +672,7 @@ bool PCBMODEL::CreatePCB() { if( !oln.MakeShape( board, m_thickness ) ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * could not create board extrusion\n"; - wxLogMessage( "%s", ostr.str().c_str() ); - + ReportMessage( "could not create board extrusion\n" ); return false; } } @@ -714,12 +686,7 @@ bool PCBMODEL::CreatePCB() } else { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * could not create board cutout\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( "could not create board cutout\n" ); } } @@ -751,16 +718,14 @@ bool PCBMODEL::CreatePCB() if( !added && !oln.m_curves.empty() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * could not close outline (dropping outline data with " << oln.m_curves.size() << " segments)\n"; + wxString msg; + msg.Printf( "could not close outline (dropping outline data with %d segments)\n", + oln.m_curves.size() ); for( const auto& c : oln.m_curves ) - ostr << " + " << c.Describe() << "\n"; + msg << " + " << c.Describe() << "\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( msg ); oln.Clear(); if( !m_curves.empty() ) @@ -777,12 +742,7 @@ bool PCBMODEL::CreatePCB() { if( !oln.MakeShape( board, m_thickness ) ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * could not create board extrusion\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( "could not create board extrusion\n" ); return false; } } @@ -797,11 +757,10 @@ bool PCBMODEL::CreatePCB() else { std::ostringstream ostr; -#ifdef DEBUG +#ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * could not create board cutout\n"; - wxLogMessage( "%s", ostr.str().c_str() ); +#endif /* __WXDEBUG */ + ReportMessage( "could not create board cutout\n" ); } } } @@ -840,16 +799,11 @@ bool PCBMODEL::CreatePCB() #ifdef SUPPORTS_IGES // write the assembly model in IGES format -bool PCBMODEL::WriteIGES( const std::string& aFileName ) +bool PCBMODEL::WriteIGES( const wxString& aFileName ) { if( m_pcb_label.IsNull() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * No valid PCB assembly; cannot create output file " << aFileName << "\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "No valid PCB assembly; cannot create output file %s\n", aFileName ) ); return false; } @@ -874,16 +828,11 @@ bool PCBMODEL::WriteIGES( const std::string& aFileName ) // write the assembly model in STEP format -bool PCBMODEL::WriteSTEP( const std::string& aFileName ) +bool PCBMODEL::WriteSTEP( const wxString& aFileName ) { if( m_pcb_label.IsNull() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * No valid PCB assembly; cannot create output file " << aFileName << "\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "No valid PCB assembly; cannot create output file %s\n", aFileName ) ); return false; } @@ -903,10 +852,24 @@ bool PCBMODEL::WriteSTEP( const std::string& aFileName ) hdr.SetOriginatingSystem( new TCollection_HAsciiString( "KiCad to STEP converter" ) ); hdr.SetDescriptionValue( 1, new TCollection_HAsciiString( "KiCad electronic assembly" ) ); - if( Standard_False == writer.Write( aFileName.c_str() ) ) - return false; + bool success = true; + // Creates a temporary file with a ascii7 name, because writer does not know + // unicode filenames + wxString currCWD = wxGetCwd(); + wxSetWorkingDirectory( fn.GetPath() ); + char tmpfname[] = "$tempfile$.step"; - return true; + if( Standard_False == writer.Write( tmpfname ) ) + success = false; + + if( success ) + { + wxRenameFile( tmpfname, fn.GetFullName(), true ); + } + + wxSetWorkingDirectory( currCWD ); + + return success; } @@ -934,12 +897,7 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_L case FMT_IGES: if( !readIGES( doc, aFileName.c_str() ) ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * readIGES() failed on filename '" << aFileName << "'\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "readIGES() failed on filename %s\n", aFileName ) ); return false; } break; @@ -947,12 +905,7 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_L case FMT_STEP: if( !readSTEP( doc, aFileName.c_str() ) ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * readSTEP() failed on filename '" << aFileName << "'\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "readSTEP() failed on filename %s\n", aFileName ) ); return false; } break; @@ -1024,12 +977,7 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_L if( aLabel.IsNull() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * could not transfer model data from file '" << aFileName << "'\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "could not transfer model data from file %s", aFileName ) ); return false; } @@ -1224,9 +1172,9 @@ TDF_Label PCBMODEL::transferModel( Handle( TDocStd_Document )& source, scaled_shape = brep.Shape(); } else { std::ostringstream ostr; -#ifdef DEBUG +#ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ +#endif /* __WXDEBUG */ ostr << " * failed to scale model\n"; wxLogMessage( "%s", ostr.str().c_str() ); scaled_shape = shape; @@ -1437,21 +1385,15 @@ bool OUTLINE::MakeShape( TopoDS_Shape& aShape, double aThickness ) } catch( const Standard_Failure& e ) { -#ifdef DEBUG - wxLogMessage( "Exception caught: %s", e.GetMessageString() ); -#endif /* DEBUG */ + ReportMessage( wxString::Format( "Exception caught: %s", e.GetMessageString() ) ); success = false; } if( !success ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * failed to add an edge: " << i.Describe() << "\n"; - ostr << " * last valid outline point: " << lastPoint << "\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + ReportMessage( wxString::Format( "failed to add an edge: %d\n", + "last valid outline point: %f %f\n", + i.Describe(), lastPoint.x, lastPoint.y ) ); return false; } } @@ -1461,13 +1403,7 @@ bool OUTLINE::MakeShape( TopoDS_Shape& aShape, double aThickness ) if( aShape.IsNull() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * failed to create a prismatic shape\n"; - wxLogMessage( "%s", ostr.str().c_str() ); - + ReportMessage( "failed to create a prismatic shape\n" ); return false; } @@ -1510,13 +1446,7 @@ bool OUTLINE::addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBL default: { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * unsupported curve type: " << aCurve.m_form << "\n"; - wxLogMessage( "%s", ostr.str().c_str() ); - + ReportMessage( wxString::Format( "unsupported curve type: %d\n", aCurve.m_form ) ); return false; } } @@ -1529,13 +1459,7 @@ bool OUTLINE::addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBL if( BRepBuilderAPI_DisconnectedWire == aWire->Error() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * failed to add curve\n"; - wxLogMessage( "%s", ostr.str().c_str() ); - + ReportMessage( "failed to add curve\n" ); return false; } diff --git a/utils/kicad2step/pcb/oce_utils.h b/utils/kicad2step/pcb/oce_utils.h index 52cf6711b3..a00b994266 100644 --- a/utils/kicad2step/pcb/oce_utils.h +++ b/utils/kicad2step/pcb/oce_utils.h @@ -142,11 +142,11 @@ public: #ifdef SUPPORTS_IGES // write the assembly model in IGES format - bool WriteIGES( const std::string& aFileName ); + bool WriteIGES( const wxString& aFileName ); #endif // write the assembly model in STEP format - bool WriteSTEP( const std::string& aFileName ); + bool WriteSTEP( const wxString& aFileName ); }; #endif //OCE_VIS_OCE_UTILS_H