Redirect step export output to a pretty window

This commit is contained in:
Marek Roszko 2022-10-05 14:51:38 -04:00
parent 994274fe9f
commit aaa1d166a7
17 changed files with 412 additions and 512 deletions

View File

@ -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

View File

@ -31,7 +31,8 @@
#include <pgm_base.h>
#include <board.h>
#include <confirm.h>
#include <dialog_export_step_base.h>
#include "dialog_export_step_base.h"
#include "dialog_export_step_process.h"
#include <footprint.h>
#include <kiface_base.h>
#include <locale_io.h>
@ -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();
}

View File

@ -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!

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="15" />
<FileVersion major="1" minor="16" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
@ -52,6 +52,7 @@
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Export STEP</property>
<property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
@ -60,11 +61,11 @@
<property name="name">bSizerSTEPFile</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">protected</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxALL</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property>
<property name="name">bSizerTop</property>
<property name="orient">wxHORIZONTAL</property>
@ -197,20 +198,20 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxTOP</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property>
<property name="name">bSizer2</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxStaticBoxSizer" expanded="1">
<object class="wxStaticBoxSizer" expanded="0">
<property name="id">wxID_ANY</property>
<property name="label">Coordinates</property>
<property name="minimum_size"></property>
@ -218,11 +219,11 @@
<property name="orient">wxVERTICAL</property>
<property name="parent">1</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxRadioButton" expanded="1">
<object class="wxRadioButton" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -282,11 +283,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxRadioButton" expanded="1">
<object class="wxRadioButton" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -346,11 +347,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxRadioButton" expanded="1">
<object class="wxRadioButton" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -410,11 +411,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxRadioButton" expanded="1">
<object class="wxRadioButton" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -476,11 +477,11 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxStaticBoxSizer" expanded="1">
<object class="wxStaticBoxSizer" expanded="0">
<property name="id">wxID_ANY</property>
<property name="label">User Defined Origin</property>
<property name="minimum_size"></property>
@ -488,11 +489,11 @@
<property name="orient">wxVERTICAL</property>
<property name="parent">1</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxFlexGridSizer" expanded="1">
<object class="wxFlexGridSizer" expanded="0">
<property name="cols">2</property>
<property name="flexible_direction">wxBOTH</property>
<property name="growablecols"></property>
@ -886,11 +887,11 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxStaticBoxSizer" expanded="1">
<object class="wxStaticBoxSizer" expanded="0">
<property name="id">wxID_ANY</property>
<property name="label">Other Options</property>
<property name="minimum_size"></property>
@ -962,11 +963,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1026,11 +1027,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1090,11 +1091,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxLEFT|wxRIGHT|wxTOP</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<object class="wxStaticText" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1151,11 +1152,11 @@
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxChoice" expanded="1">
<object class="wxChoice" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1219,11 +1220,11 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property>
<property name="name">bSizer81</property>
<property name="orient">wxHORIZONTAL</property>
@ -1288,11 +1289,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALIGN_RIGHT|wxTOP|wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStdDialogButtonSizer" expanded="1">
<object class="wxStdDialogButtonSizer" expanded="0">
<property name="Apply">0</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>

View File

@ -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();
};

View File

@ -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 <wx/textctrl.h>
#include <wx/process.h>
#include <wx/log.h>
#include <wx/timer.h>
#include <wx/txtstrm.h>
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<DIALOG_EXPORT_STEP_LOG::STATE_MESSAGE>& 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<DIALOG_EXPORT_STEP_LOG::STATE_MESSAGE>& 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<ExitCode>( 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<ExitCode>( 0 );
break;
}
else if( m == DIALOG_EXPORT_STEP_LOG::STATE_MESSAGE::REQUEST_EXIT )
{
wxProcess::Kill( m_process->GetPid() );
c = reinterpret_cast<ExitCode>( 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 );
}

View File

@ -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 <wx/process.h>
#include <wx/msgqueue.h>
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<STATE_MESSAGE> m_msgQueue;
};

View File

@ -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 );
}

View File

@ -11,13 +11,13 @@
<property name="embedded_files_path">res</property>
<property name="encoding">UTF-8</property>
<property name="event_generation">connect</property>
<property name="file">kicad2step_frame_base</property>
<property name="file">dialog_export_step_process_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="image_path_wrapper_function_name"></property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">kicad2step_frame</property>
<property name="name">dialog_export_step_process</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header"></property>
@ -27,13 +27,13 @@
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_array_enum">0</property>
<property name="use_enum">0</property>
<property name="use_enum">1</property>
<property name="use_microsoft_bom">0</property>
<object class="Frame" expanded="1">
<object class="Dialog" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg">wxSYS_COLOUR_3DLIGHT</property>
<property name="center">wxBOTH</property>
<property name="bg"></property>
<property name="center"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
@ -44,30 +44,28 @@
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">KICAD2STEP_FRAME_BASE</property>
<property name="minimum_size">-1,-1</property>
<property name="name">DIALOG_EXPORT_STEP_PROCESS_BASE</property>
<property name="pos"></property>
<property name="size">644,300</property>
<property name="style">wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">; forward_declare; forward_declare</property>
<property name="title">Kicad2step Converter</property>
<property name="size">-1,-1</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">STEP Export</property>
<property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<property name="xrc_skip_sizer">1</property>
<event name="OnIdle">OnIdle</event>
<property name="window_style"></property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizerMain</property>
<property name="name">bMainSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxPanel" expanded="1">
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -98,26 +96,33 @@
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="minimum_size">450,250</property>
<property name="moveable">1</property>
<property name="name">m_panelKicad2Step</property>
<property name="name">m_textCtrlLog</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">public</property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">PANEL_KICAD2STEP; panel_kicad2step.h; Not forward_declare</property>
<property name="style">wxTE_MULTILINE|wxTE_READONLY</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
@ -134,9 +139,9 @@
<property name="Save">0</property>
<property name="Yes">0</property>
<property name="minimum_size"></property>
<property name="name">m_sdbSizer1</property>
<property name="name">m_sdbSizer</property>
<property name="permission">protected</property>
<event name="OnOKButtonClick">OnOKButtonClick</event>
<event name="OnOKButtonClick">OnButtonPlot</event>
</object>
</object>
</object>

View File

@ -10,42 +10,40 @@
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include "panel_kicad2step.h"
#include <wx/panel.h>
#include "dialog_shim.h"
#include <wx/string.h>
#include <wx/textctrl.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// 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();
};

View File

@ -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

View File

@ -38,8 +38,6 @@
#include <pgm_base.h>
#include "kicad2step.h"
#include "pcb/kicadpcb.h"
#include "kicad2step_frame_base.h"
#include "panel_kicad2step.h"
#include <Message.hxx> // OpenCascade messenger
#include <Message_PrinterOStream.hxx> // OpenCascade output messenger
#include <Standard_Failure.hxx> // In open cascade
@ -54,18 +52,6 @@
#include <Message_Messenger.hxx>
#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 );
}

View File

@ -28,8 +28,6 @@
#include <wx/string.h>
#include <import_export.h>
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;

View File

@ -1,227 +0,0 @@
/*
* This program source code file is part of kicad2mcad
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* 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 <wx/app.h>
#include <wx/cmdline.h>
#include <wx/log.h>
#include <wx/msgdlg.h>
#include <wx/string.h>
#include <wx/filename.h>
#include <sstream>
#include <iostream>
#include <regex>
#include "kicad2step.h"
#include "kicad2step_frame_base.h"
#include <Standard_Failure.hxx> // 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;
}

View File

@ -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 );
}

View File

@ -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 <wx/sizer.h>
#include <wx/textctrl.h>
#include <wx/panel.h>
#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

View File

@ -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