diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 03f00bb759..659c5d7c27 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -79,6 +79,8 @@ set( PCBNEW_DIALOGS dialogs/dialog_export_idf_base.cpp dialogs/dialog_export_step.cpp dialogs/dialog_export_step_base.cpp + dialogs/dialog_export_step_process.cpp + dialogs/dialog_export_step_process_base.cpp dialogs/dialog_export_svg.cpp dialogs/dialog_export_svg_base.cpp dialogs/dialog_export_vrml.cpp diff --git a/pcbnew/dialogs/dialog_export_step.cpp b/pcbnew/dialogs/dialog_export_step.cpp index 4932362e38..48e421326d 100644 --- a/pcbnew/dialogs/dialog_export_step.cpp +++ b/pcbnew/dialogs/dialog_export_step.cpp @@ -31,7 +31,8 @@ #include #include #include -#include +#include "dialog_export_step_base.h" +#include "dialog_export_step_process.h" #include #include #include @@ -110,6 +111,7 @@ private: double m_XOrg; // remember last User Origin X value double m_YOrg; // remember last User Origin Y value wxString m_boardPath; // path to the exported board file + wxProcess* m_process; // running conversion process static int m_toleranceLastChoice; // Store m_tolerance option during a session }; @@ -125,6 +127,7 @@ DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& m_sdbSizerCancel->SetLabel( _( "Close" ) ); m_sdbSizerOK->SetLabel( _( "Export" ) ); m_sdbSizer->Layout(); + m_process = nullptr; // Build default output file name wxString path = m_parent->GetLastPath( LAST_PATH_STEP ); @@ -467,7 +470,8 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent ) cmdK2S.Append( wxString::Format( wxT( " %c%s%c" ), quote, m_boardPath, quote ) ); wxLogTrace( traceKiCad2Step, wxT( "export step command: %s" ), cmdK2S ); - wxExecute( cmdK2S, wxEXEC_ASYNC | wxEXEC_SHOW_CONSOLE ); - aEvent.Skip(); // Close the dialog -} + DIALOG_EXPORT_STEP_LOG* log = new DIALOG_EXPORT_STEP_LOG( this, cmdK2S ); + log->ShowModal(); + Close(); +} \ No newline at end of file diff --git a/pcbnew/dialogs/dialog_export_step_base.cpp b/pcbnew/dialogs/dialog_export_step_base.cpp index 17d7e36765..7150c01ece 100644 --- a/pcbnew/dialogs/dialog_export_step_base.cpp +++ b/pcbnew/dialogs/dialog_export_step_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Apr 22 2021) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! diff --git a/pcbnew/dialogs/dialog_export_step_base.fbp b/pcbnew/dialogs/dialog_export_step_base.fbp index 5adb2d892e..cacd2ce718 100644 --- a/pcbnew/dialogs/dialog_export_step_base.fbp +++ b/pcbnew/dialogs/dialog_export_step_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -52,6 +52,7 @@ DIALOG_SHIM; dialog_shim.h Export STEP + 0 @@ -60,11 +61,11 @@ bSizerSTEPFile wxVERTICAL protected - + 10 wxEXPAND|wxALL 0 - + bSizerTop wxHORIZONTAL @@ -197,20 +198,20 @@ - + 5 wxEXPAND|wxTOP 1 - + bSizer2 wxHORIZONTAL none - + 10 wxEXPAND|wxRIGHT|wxLEFT 0 - + wxID_ANY Coordinates @@ -218,11 +219,11 @@ wxVERTICAL 1 none - + 5 wxBOTTOM|wxRIGHT 0 - + 1 1 1 @@ -282,11 +283,11 @@ - + 5 wxBOTTOM|wxRIGHT 0 - + 1 1 1 @@ -346,11 +347,11 @@ - + 5 wxBOTTOM|wxRIGHT 0 - + 1 1 1 @@ -410,11 +411,11 @@ - + 5 wxBOTTOM|wxRIGHT 0 - + 1 1 1 @@ -476,11 +477,11 @@ - + 10 wxEXPAND|wxRIGHT|wxLEFT 0 - + wxID_ANY User Defined Origin @@ -488,11 +489,11 @@ wxVERTICAL 1 none - + 5 wxEXPAND 1 - + 2 wxBOTH @@ -886,11 +887,11 @@ - + 10 wxEXPAND|wxRIGHT|wxLEFT 1 - + wxID_ANY Other Options @@ -962,11 +963,11 @@ - + 5 wxBOTTOM|wxRIGHT 0 - + 1 1 1 @@ -1026,11 +1027,11 @@ - + 5 wxBOTTOM|wxRIGHT 0 - + 1 1 1 @@ -1090,11 +1091,11 @@ - + 5 wxLEFT|wxRIGHT|wxTOP 0 - + 1 1 1 @@ -1151,11 +1152,11 @@ -1 - + 5 wxALL|wxEXPAND 0 - + 1 1 1 @@ -1219,11 +1220,11 @@ - + 10 wxEXPAND|wxTOP|wxRIGHT|wxLEFT 0 - + bSizer81 wxHORIZONTAL @@ -1288,11 +1289,11 @@ - + 5 wxALIGN_RIGHT|wxTOP|wxBOTTOM|wxRIGHT 0 - + 0 1 0 diff --git a/pcbnew/dialogs/dialog_export_step_base.h b/pcbnew/dialogs/dialog_export_step_base.h index 68b5bb3645..171ae6e963 100644 --- a/pcbnew/dialogs/dialog_export_step_base.h +++ b/pcbnew/dialogs/dialog_export_step_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Apr 22 2021) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -75,6 +75,7 @@ class DIALOG_EXPORT_STEP_BASE : public DIALOG_SHIM public: DIALOG_EXPORT_STEP_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Export STEP"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_EXPORT_STEP_BASE(); }; diff --git a/pcbnew/dialogs/dialog_export_step_process.cpp b/pcbnew/dialogs/dialog_export_step_process.cpp new file mode 100644 index 0000000000..deb65d527a --- /dev/null +++ b/pcbnew/dialogs/dialog_export_step_process.cpp @@ -0,0 +1,219 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2022 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020 New Pagodi(https://stackoverflow.com/users/6846682/new-pagodi) + * from https://stackoverflow.com/a/63289812/1522001 + * + * 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 + */ + +#include "dialog_export_step_process.h" +#include +#include +#include +#include +#include + +wxDEFINE_EVENT( wxEVT_THREAD_STDIN, wxThreadEvent ); +wxDEFINE_EVENT( wxEVT_THREAD_STDERR, wxThreadEvent ); + +/** + * This thread handles consuming the input streams from the launched process. + * And generates ui events on the main thread with the content + */ +class STDSTREAM_THREAD : public wxThread +{ +public: + STDSTREAM_THREAD( wxEvtHandler* aEventHandler, wxProcess* aProcess, + wxMessageQueue& aMsgQueue ) : + wxThread( wxTHREAD_JOINABLE ), + m_queue( aMsgQueue ) + { + m_process = aProcess; + m_handler = aEventHandler; + m_bufferSize = 1024 * 1024; + m_buffer = new char[m_bufferSize]; + } + + ~STDSTREAM_THREAD() + { + delete[] m_buffer; + delete m_process; + } + +private: + ExitCode Entry() wxOVERRIDE; + void DrainInput(); + + wxMessageQueue& m_queue; + wxEvtHandler* m_handler; + wxProcess* m_process; + char* m_buffer; + size_t m_bufferSize; +}; + + +wxThread::ExitCode STDSTREAM_THREAD::Entry() +{ + ExitCode c; + + while( 1 ) + { + // Check if termination was requested. + if( TestDestroy() ) + { + wxProcess::Kill( m_process->GetPid() ); + c = reinterpret_cast( 1 ); + break; + } + + DIALOG_EXPORT_STEP_LOG::STATE_MESSAGE m = DIALOG_EXPORT_STEP_LOG::STATE_MESSAGE::SENTINEL; + wxMessageQueueError e = m_queue.ReceiveTimeout( 10, m ); + + // Check if a message was received or we timed out. + if( e == wxMSGQUEUE_NO_ERROR ) + { + if( m == DIALOG_EXPORT_STEP_LOG::STATE_MESSAGE::PROCESS_COMPLETE ) + { + DrainInput(); + c = reinterpret_cast( 0 ); + break; + } + else if( m == DIALOG_EXPORT_STEP_LOG::STATE_MESSAGE::REQUEST_EXIT ) + { + wxProcess::Kill( m_process->GetPid() ); + c = reinterpret_cast( 1 ); + break; + } + } + else if( e == wxMSGQUEUE_TIMEOUT ) + { + DrainInput(); + } + } + + return c; +} + + +void STDSTREAM_THREAD::DrainInput() +{ + if( !m_process->IsInputOpened() ) + { + return; + } + + wxString fromInputStream, fromErrorStream; + wxInputStream* stream; + + while( m_process->IsInputAvailable() ) + { + stream = m_process->GetInputStream(); + stream->Read( m_buffer, m_bufferSize ); + fromInputStream << wxString( m_buffer, stream->LastRead() ); + } + + while( m_process->IsErrorAvailable() ) + { + stream = m_process->GetErrorStream(); + stream->Read( m_buffer, m_bufferSize ); + fromErrorStream << wxString( m_buffer, stream->LastRead() ); + } + + if( !fromInputStream.IsEmpty() ) + { + wxThreadEvent* event = new wxThreadEvent( wxEVT_THREAD_STDIN ); + event->SetString( fromInputStream ); + m_handler->QueueEvent( event ); + } + + if( !fromErrorStream.IsEmpty() ) + { + wxThreadEvent* event = new wxThreadEvent( wxEVT_THREAD_STDERR ); + event->SetString( fromErrorStream ); + m_handler->QueueEvent( event ); + } +} + + +void DIALOG_EXPORT_STEP_LOG::appendMessage( const wxString& aMessage ) +{ + m_textCtrlLog->AppendText( aMessage ); +} + + +void DIALOG_EXPORT_STEP_LOG::onProcessTerminate( wxProcessEvent& aEvent ) +{ + // We need to inform the thread that the process has died + // Since it can't receive the event from wx + if( m_stdioThread && m_stdioThread->IsRunning() ) + { + m_msgQueue.Post( STATE_MESSAGE::PROCESS_COMPLETE ); + m_stdioThread->Wait(); + delete m_stdioThread; + m_stdioThread = nullptr; + m_sdbSizerOK->Enable( true ); + } +} + +void DIALOG_EXPORT_STEP_LOG::onThreadInput( wxThreadEvent& aEvent ) +{ + m_textCtrlLog->AppendText( aEvent.GetString() ); +} + + +void DIALOG_EXPORT_STEP_LOG::onClose( wxCloseEvent& aEvent ) +{ + if( m_stdioThread && m_stdioThread->IsRunning() ) + { + m_msgQueue.Post( STATE_MESSAGE::REQUEST_EXIT ); + m_stdioThread->Wait(); + delete m_stdioThread; + } + + Destroy(); +} + + +DIALOG_EXPORT_STEP_LOG::DIALOG_EXPORT_STEP_LOG( wxWindow* aParent, wxString aStepCmd ) : + DIALOG_EXPORT_STEP_PROCESS_BASE( aParent ) +{ + m_sdbSizerOK->Enable( false ); + + m_process = new wxProcess( this ); + m_process->Redirect(); + + Bind( wxEVT_END_PROCESS, &DIALOG_EXPORT_STEP_LOG::onProcessTerminate, this ); + + Bind( wxEVT_THREAD_STDIN, &DIALOG_EXPORT_STEP_LOG::onThreadInput, this ); + Bind( wxEVT_THREAD_STDERR, &DIALOG_EXPORT_STEP_LOG::onThreadInput, this ); + Bind( wxEVT_CLOSE_WINDOW, &DIALOG_EXPORT_STEP_LOG::onClose, this ); + + m_stdioThread = new STDSTREAM_THREAD( this, m_process, m_msgQueue ); + m_stdioThread->Run(); + + if( !m_stdioThread->IsRunning() ) + { + m_textCtrlLog->AppendText( "Unable to launch stdstream thread.\n" ); + delete m_stdioThread; + return; + } + + wxExecute( aStepCmd, wxEXEC_ASYNC, m_process ); +} \ No newline at end of file diff --git a/pcbnew/dialogs/dialog_export_step_process.h b/pcbnew/dialogs/dialog_export_step_process.h new file mode 100644 index 0000000000..7ee41feed4 --- /dev/null +++ b/pcbnew/dialogs/dialog_export_step_process.h @@ -0,0 +1,54 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2022 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020 New Pagodi(https://stackoverflow.com/users/6846682/new-pagodi) + * from https://stackoverflow.com/a/63289812/1522001 + * + * 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 + */ + +#include "dialog_export_step_process_base.h" +#include +#include + +class wxProcess; +class wxThread; + +class DIALOG_EXPORT_STEP_LOG : public DIALOG_EXPORT_STEP_PROCESS_BASE +{ +public: + enum class STATE_MESSAGE : int + { + PROCESS_COMPLETE, ///< Informs the thread the process terminate event was received from wx + REQUEST_EXIT, ///< Asks the thread to exit and kill the process + SENTINEL ///< Just a dummy entry for end of list + }; + + DIALOG_EXPORT_STEP_LOG( wxWindow* aParent, wxString aStepCmd ); + +private: + void appendMessage( const wxString& aMessage ); + void onProcessTerminate( wxProcessEvent& aEvent ); + void onThreadInput( wxThreadEvent& ); + void onClose( wxCloseEvent& event ); + + wxProcess* m_process; + wxThread* m_stdioThread; + wxMessageQueue m_msgQueue; +}; \ No newline at end of file diff --git a/pcbnew/dialogs/dialog_export_step_process_base.cpp b/pcbnew/dialogs/dialog_export_step_process_base.cpp new file mode 100644 index 0000000000..a5257f8ad4 --- /dev/null +++ b/pcbnew/dialogs/dialog_export_step_process_base.cpp @@ -0,0 +1,45 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_export_step_process_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_EXPORT_STEP_PROCESS_BASE::DIALOG_EXPORT_STEP_PROCESS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize ); + + wxBoxSizer* bMainSizer; + bMainSizer = new wxBoxSizer( wxVERTICAL ); + + m_textCtrlLog = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY ); + m_textCtrlLog->SetMinSize( wxSize( 450,250 ) ); + + bMainSizer->Add( m_textCtrlLog, 0, wxALL|wxEXPAND, 5 ); + + m_sdbSizer = new wxStdDialogButtonSizer(); + m_sdbSizerOK = new wxButton( this, wxID_OK ); + m_sdbSizer->AddButton( m_sdbSizerOK ); + m_sdbSizer->Realize(); + + bMainSizer->Add( m_sdbSizer, 0, wxALL|wxEXPAND, 5 ); + + + this->SetSizer( bMainSizer ); + this->Layout(); + bMainSizer->Fit( this ); + + // Connect Events + m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXPORT_STEP_PROCESS_BASE::OnButtonPlot ), NULL, this ); +} + +DIALOG_EXPORT_STEP_PROCESS_BASE::~DIALOG_EXPORT_STEP_PROCESS_BASE() +{ + // Disconnect Events + m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXPORT_STEP_PROCESS_BASE::OnButtonPlot ), NULL, this ); + +} diff --git a/pcbnew/exporters/step/kicad2step_frame_base.fbp b/pcbnew/dialogs/dialog_export_step_process_base.fbp similarity index 76% rename from pcbnew/exporters/step/kicad2step_frame_base.fbp rename to pcbnew/dialogs/dialog_export_step_process_base.fbp index 855e91b652..57774c1e67 100644 --- a/pcbnew/exporters/step/kicad2step_frame_base.fbp +++ b/pcbnew/dialogs/dialog_export_step_process_base.fbp @@ -11,13 +11,13 @@ res UTF-8 connect - kicad2step_frame_base + dialog_export_step_process_base 1000 none 1 - kicad2step_frame + dialog_export_step_process . @@ -27,13 +27,13 @@ 1 UI 0 - 0 + 1 0 - + 0 wxAUI_MGR_DEFAULT - wxSYS_COLOUR_3DLIGHT - wxBOTH + + 1 1 @@ -44,30 +44,28 @@ 0 wxID_ANY - - KICAD2STEP_FRAME_BASE + -1,-1 + DIALOG_EXPORT_STEP_PROCESS_BASE - 644,300 - wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER - ; forward_declare; forward_declare - Kicad2step Converter + -1,-1 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + STEP Export 0 - wxTAB_TRAVERSAL - 1 - OnIdle + - bSizerMain + bMainSizer wxVERTICAL none 5 - wxEXPAND - 1 - + wxALL|wxEXPAND + 0 + 1 1 1 @@ -98,26 +96,33 @@ 0 + 0 - + 450,250 1 - m_panelKicad2Step + m_textCtrlLog 1 - public + protected 1 Resizable 1 - PANEL_KICAD2STEP; panel_kicad2step.h; Not forward_declare + wxTE_MULTILINE|wxTE_READONLY + ; ; forward_declare 0 + + wxFILTER_NONE + wxDefaultValidator + + - wxTAB_TRAVERSAL + @@ -134,9 +139,9 @@ 0 0 - m_sdbSizer1 + m_sdbSizer protected - OnOKButtonClick + OnButtonPlot diff --git a/pcbnew/exporters/step/kicad2step_frame_base.h b/pcbnew/dialogs/dialog_export_step_process_base.h similarity index 56% rename from pcbnew/exporters/step/kicad2step_frame_base.h rename to pcbnew/dialogs/dialog_export_step_process_base.h index 224a55bddd..06a60155b8 100644 --- a/pcbnew/exporters/step/kicad2step_frame_base.h +++ b/pcbnew/dialogs/dialog_export_step_process_base.h @@ -10,42 +10,40 @@ #include #include #include -#include "panel_kicad2step.h" -#include +#include "dialog_shim.h" +#include +#include #include #include #include #include -#include #include #include -#include +#include /////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// -/// Class KICAD2STEP_FRAME_BASE +/// Class DIALOG_EXPORT_STEP_PROCESS_BASE /////////////////////////////////////////////////////////////////////////////// -class KICAD2STEP_FRAME_BASE : public wxFrame +class DIALOG_EXPORT_STEP_PROCESS_BASE : public DIALOG_SHIM { private: protected: - wxStdDialogButtonSizer* m_sdbSizer1; - wxButton* m_sdbSizer1OK; + wxTextCtrl* m_textCtrlLog; + wxStdDialogButtonSizer* m_sdbSizer; + wxButton* m_sdbSizerOK; // Virtual event handlers, override them in your derived class - virtual void OnIdle( wxIdleEvent& event ) { event.Skip(); } - virtual void OnOKButtonClick( wxCommandEvent& event ) { event.Skip(); } + virtual void OnButtonPlot( wxCommandEvent& event ) { event.Skip(); } 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( 644,300 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxTAB_TRAVERSAL ); + DIALOG_EXPORT_STEP_PROCESS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("STEP Export"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); - ~KICAD2STEP_FRAME_BASE(); + ~DIALOG_EXPORT_STEP_PROCESS_BASE(); }; diff --git a/pcbnew/exporters/step/CMakeLists.txt b/pcbnew/exporters/step/CMakeLists.txt index 18262551fb..1f4f4b9e5b 100644 --- a/pcbnew/exporters/step/CMakeLists.txt +++ b/pcbnew/exporters/step/CMakeLists.txt @@ -5,7 +5,6 @@ include_directories( SYSTEM set( KS2_LIB_FILES kicad2step.cpp - kicad2step_frame_base.cpp pcb/3d_resolver.cpp pcb/base.cpp pcb/kicadmodel.cpp diff --git a/pcbnew/exporters/step/kicad2step.cpp b/pcbnew/exporters/step/kicad2step.cpp index ce700a6ffc..2513c65589 100644 --- a/pcbnew/exporters/step/kicad2step.cpp +++ b/pcbnew/exporters/step/kicad2step.cpp @@ -38,8 +38,6 @@ #include #include "kicad2step.h" #include "pcb/kicadpcb.h" -#include "kicad2step_frame_base.h" -#include "panel_kicad2step.h" #include // OpenCascade messenger #include // OpenCascade output messenger #include // In open cascade @@ -54,18 +52,6 @@ #include #endif -class KICAD2STEP_FRAME : public KICAD2STEP_FRAME_BASE -{ -public: - KICAD2STEP_FRAME( KICAD2STEP* aConverter, const wxString& title ); - -protected: - virtual void OnOKButtonClick( wxCommandEvent& aEvent ) override; - virtual void OnIdle( wxIdleEvent& aEvent ) override; - - KICAD2STEP* m_converter; - bool m_running; -}; // Horrible hack until we decouple things more @@ -142,54 +128,6 @@ KICAD2MCAD_PRMS::KICAD2MCAD_PRMS() } -KICAD2STEP_FRAME::KICAD2STEP_FRAME( KICAD2STEP* aConverter, const wxString& title ) : - KICAD2STEP_FRAME_BASE( nullptr, wxID_ANY, title ), m_converter( aConverter ), m_running( false ) -{ -} - - -void KICAD2STEP_FRAME::OnOKButtonClick( wxCommandEvent& aEvent ) -{ - Close(); -} - - -void KICAD2STEP_FRAME::OnIdle( wxIdleEvent& aEvent ) -{ - if( !m_running ) - { - m_running = true; - m_converter->DoRun(); - } -} - - -PANEL_KICAD2STEP::PANEL_KICAD2STEP( wxWindow* parent, wxWindowID id, - const wxPoint& pos, - const wxSize& size, long style ) : - wxPanel( parent, id, pos, size, style ), - m_error( false ), m_fail( false ) -{ - 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(); -} - - - wxString KICAD2MCAD_PRMS::getOutputExt() const { #ifdef SUPPORTS_IGES @@ -202,7 +140,7 @@ wxString KICAD2MCAD_PRMS::getOutputExt() const KICAD2STEP::KICAD2STEP( KICAD2MCAD_PRMS aParams ) : - m_params( aParams ), m_panel( nullptr ), m_error( false ), m_fail( false ) + m_params( aParams ), m_error( false ), m_fail( false ) { } @@ -340,37 +278,12 @@ int KICAD2STEP::Run() { k2sInstance = this; - if( m_params.m_gui ) - { - // create the main application window - KICAD2STEP_FRAME* frame = new KICAD2STEP_FRAME( this, wxT( "PCB Step Export" ) ); - - m_panel = frame->m_panelKicad2Step; - m_panel->m_params = m_params; - - Pgm().App().SetTopWindow( frame ); - - frame->Iconize( false ); - frame->Show( true ); - - return CLI::EXIT_CODES::AVOID_CLOSING; - } - else - { - int diag = DoRun(); - return diag; - } + int diag = DoRun(); + return diag; } void KICAD2STEP::ReportMessage( const wxString& aMessage ) { - if( m_params.m_gui ) - { - m_panel->AppendMessage( aMessage ); - } - else - { - wxPrintf( aMessage ); - } + wxPrintf( aMessage ); } diff --git a/pcbnew/exporters/step/kicad2step.h b/pcbnew/exporters/step/kicad2step.h index 9f9b91b569..cca9d2aba8 100644 --- a/pcbnew/exporters/step/kicad2step.h +++ b/pcbnew/exporters/step/kicad2step.h @@ -28,8 +28,6 @@ #include #include -class PANEL_KICAD2STEP; - class APIEXPORT KICAD2MCAD_PRMS // A small class to handle parameters of conversion { public: @@ -51,7 +49,6 @@ public: double m_xOrigin; double m_yOrigin; double m_minDistance; - bool m_gui; }; class APIEXPORT KICAD2STEP @@ -69,7 +66,6 @@ private: int DoRun(); KICAD2MCAD_PRMS m_params; - PANEL_KICAD2STEP* m_panel; bool m_error; bool m_fail; diff --git a/pcbnew/exporters/step/kicad2step_app.cpp b/pcbnew/exporters/step/kicad2step_app.cpp deleted file mode 100644 index 83da06e4e2..0000000000 --- a/pcbnew/exporters/step/kicad2step_app.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - * This program source code file is part of kicad2mcad - * - * Copyright (C) 2016 Cirilo Bernardo - * Copyright (C) 2016-2022 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 - * 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 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kicad2step.h" -#include "kicad2step_frame_base.h" -#include // In open cascade - -#define REGEX_QUANTITY "([\\s]*[+-]?[\\d]*[.]?[\\d]*)" -#define REGEX_DELIMITER "(?:[\\s]*x)" -#define REGEX_UNIT "([m]{2}|(?:in))" - - -class KICAD2MCAD_APP : public wxApp -{ -public: - KICAD2MCAD_APP() : wxApp(), m_converter( nullptr ) {} - - virtual bool OnInit() override; - virtual int OnRun() override; - virtual void OnInitCmdLine( wxCmdLineParser& parser ) override; - virtual bool OnCmdLineParsed( wxCmdLineParser& parser ) override; - -private: - KICAD2STEP* m_converter; - KICAD2MCAD_PRMS m_params; -}; - - -wxIMPLEMENT_APP( KICAD2MCAD_APP ); - - -static const wxCmdLineEntryDesc cmdLineDesc[] = { - { wxCMD_LINE_PARAM, NULL, NULL, _( "pcb_filename" ).mb_str(), wxCMD_LINE_VAL_STRING, - wxCMD_LINE_OPTION_MANDATORY }, - { wxCMD_LINE_OPTION, "o", "output-filename", _( "output filename" ).mb_str(), - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, - -#ifdef SUPPORTS_IGES - { wxCMD_LINE_SWITCH, "fmt-iges", NULL, _( "IGES output (default STEP)" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, -#endif - - { wxCMD_LINE_SWITCH, "f", "force", _( "overwrite output file" ).mb_str(), wxCMD_LINE_VAL_NONE, - wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, NULL, "drill-origin", _( "Use Drill Origin for output origin" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, NULL, "grid-origin", _( "Use Grid Origin for output origin" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_OPTION, NULL, "user-origin", - _( "User-specified output origin ex. 1x1in, 1x1inch, 25.4x25.4mm (default mm)" ).mb_str(), - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, NULL, "no-virtual", - _( "Exclude 3D models for components with 'virtual' attribute" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, NULL, "subst-models", - _( "Substitute STEP or IGS models with the same name in place of VRML models" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_OPTION, NULL, "min-distance", - _( "Minimum distance between points to treat them as separate ones (default 0.01mm)" ) - .mb_str(), - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, "h", NULL, _( "display this message" ).mb_str(), wxCMD_LINE_VAL_NONE, - wxCMD_LINE_OPTION_HELP }, - { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 } -}; - - -void KICAD2MCAD_APP::OnInitCmdLine( wxCmdLineParser& parser ) -{ - parser.SetDesc( cmdLineDesc ); - parser.SetSwitchChars( wxT( "-" ) ); -} - - -bool KICAD2MCAD_APP::OnInit() -{ - if( !wxApp::OnInit() ) - return false; - - // create the main application window - m_converter = new KICAD2STEP( m_params ); - - return true; -} - - -int KICAD2MCAD_APP::OnRun() -{ - int diag = m_converter->Run(); - wxApp::OnRun(); // Start the main loop event, to manage the main frame - - return diag; -} - - -bool KICAD2MCAD_APP::OnCmdLineParsed( wxCmdLineParser& parser ) -{ -#ifdef SUPPORTS_IGES - if( parser.Found( wxT( "fmt-iges" ) ) ) - m_fmtIGES = true; -#endif - - if( parser.Found( wxT( "f" ) ) ) - m_params.m_overwrite = true; - - if( parser.Found( wxT( "grid-origin" ) ) ) - m_params.m_useGridOrigin = true; - - if( parser.Found( wxT( "drill-origin" ) ) ) - m_params.m_useDrillOrigin = true; - - if( parser.Found( wxT( "no-virtual" ) ) ) - m_params.m_includeVirtual = false; - - if( parser.Found( wxT( "subst-models" ) ) ) - m_params.m_substModels = true; - - wxString tstr; - - if( parser.Found( wxT( "user-origin" ), &tstr ) ) - { - std::regex re_pattern( REGEX_QUANTITY REGEX_DELIMITER REGEX_QUANTITY REGEX_UNIT, - std::regex_constants::icase ); - std::smatch sm; - std::string str( tstr.ToUTF8() ); - std::regex_search( str, sm, re_pattern ); - m_params.m_xOrigin = atof( sm.str( 1 ).c_str() ); - m_params.m_yOrigin = atof( sm.str( 2 ).c_str() ); - - std::string tunit( sm[3] ); - - if( tunit.size() > 0 ) // No unit accepted ( default = mm ) - { - if( ( !sm.str( 1 ).compare( " " ) || !sm.str( 2 ).compare( " " ) ) || - ( sm.size() != 4 ) ) - { - parser.Usage(); - return false; - } - - // only in, inch and mm are valid: - if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) - { - m_params.m_xOrigin *= 25.4; - m_params.m_yOrigin *= 25.4; - } - else if( tunit.compare( "mm" ) ) - { - parser.Usage(); - return false; - } - } - } - - if( parser.Found( wxT( "min-distance" ), &tstr ) ) - { - std::istringstream istr; - istr.str( std::string( tstr.ToUTF8() ) ); - istr >> m_params.m_minDistance; - - if( istr.fail() ) - { - parser.Usage(); - return false; - } - - if( !istr.eof() ) - { - std::string tunit; - istr >> tunit; - - if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) - { - m_params.m_minDistance *= 25.4; - } - else if( tunit.compare( "mm" ) ) - { - parser.Usage(); - return false; - } - } - } - - if( parser.Found( wxT( "o" ), &tstr ) ) - m_params.m_outputFile = tstr; - - if( parser.GetParamCount() < 1 ) - { - parser.Usage(); - return false; - } - - m_params.m_filename = parser.GetParam( 0 ); - - return true; -} diff --git a/pcbnew/exporters/step/kicad2step_frame_base.cpp b/pcbnew/exporters/step/kicad2step_frame_base.cpp deleted file mode 100644 index b3dc61c250..0000000000 --- a/pcbnew/exporters/step/kicad2step_frame_base.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) -// 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 ); - this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); - - wxBoxSizer* bSizerMain; - bSizerMain = new wxBoxSizer( wxVERTICAL ); - - m_panelKicad2Step = new PANEL_KICAD2STEP( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - bSizerMain->Add( m_panelKicad2Step, 1, wxEXPAND, 5 ); - - m_sdbSizer1 = new wxStdDialogButtonSizer(); - m_sdbSizer1OK = new wxButton( this, wxID_OK ); - m_sdbSizer1->AddButton( m_sdbSizer1OK ); - m_sdbSizer1->Realize(); - - bSizerMain->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 5 ); - - - this->SetSizer( bSizerMain ); - this->Layout(); - - this->Centre( wxBOTH ); - - // Connect Events - this->Connect( wxEVT_IDLE, wxIdleEventHandler( KICAD2STEP_FRAME_BASE::OnIdle ) ); - m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( KICAD2STEP_FRAME_BASE::OnOKButtonClick ), NULL, this ); -} - -KICAD2STEP_FRAME_BASE::~KICAD2STEP_FRAME_BASE() -{ - // Disconnect Events - this->Disconnect( wxEVT_IDLE, wxIdleEventHandler( KICAD2STEP_FRAME_BASE::OnIdle ) ); - m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( KICAD2STEP_FRAME_BASE::OnOKButtonClick ), NULL, this ); - -} diff --git a/pcbnew/exporters/step/panel_kicad2step.h b/pcbnew/exporters/step/panel_kicad2step.h deleted file mode 100644 index 39ad4e3cb7..0000000000 --- a/pcbnew/exporters/step/panel_kicad2step.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2016 - * Copyright (C) 2021 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 - * 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 - * Declare the main PCB object. - */ - -#ifndef PANEL_KICAD2STEP_H -#define PANEL_KICAD2STEP_H - -#include -#include -#include - -#include "kicad2step.h" - -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 ); - - - /** - * Add a message to m_tcMessages. - */ - void AppendMessage( const wxString& aMessage ); - - KICAD2MCAD_PRMS m_params; - - bool m_error; - bool m_fail; - -private: - wxTextCtrl* m_tcMessages; -}; - -#endif // #ifndef PANEL_KICAD2STEP_H diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index 6383c518e2..62b23faa86 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -60,7 +60,6 @@ int PCBNEW_JOBS_HANDLER::JobExportStep( JOB* aJob ) params.m_yOrigin = aStepJob->m_yOrigin; params.m_minDistance = aStepJob->m_minDistance; params.m_substModels = aStepJob->m_substModels; - params.m_gui = aStepJob->m_gui; // we might need the lifetime of the converter to continue until frame destruction // due to the gui parameter