kicad2step: convert it from a wxAppConsole to a wxApp, using a wxFrame/wxPanel

This commit is contained in:
jean-pierre charras 2018-09-20 11:05:52 +02:00
parent fdccdd5cb9
commit 110b05fe78
12 changed files with 643 additions and 304 deletions

View File

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

View File

@ -4,6 +4,7 @@ include_directories( SYSTEM
)
set( KS2_LIB_FILES
kicad2step.cpp
pcb/3d_resolver.cpp
pcb/base.cpp
pcb/kicadmodel.cpp

View File

@ -2,7 +2,7 @@
* This program source code file is part of kicad2mcad
*
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* 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 <wx/app.h>
#include <wx/cmdline.h>
#include <wx/log.h>
@ -30,11 +31,15 @@
#include <sstream>
#include <iostream>
#include <sstream>
#include <Standard_Failure.hxx>
#include <Standard_Failure.hxx> // 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 )

View File

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

View File

@ -0,0 +1,200 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="14" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
<property name="disconnect_events">1</property>
<property name="disconnect_mode">source_name</property>
<property name="disconnect_php_events">0</property>
<property name="disconnect_python_events">0</property>
<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="first_id">1000</property>
<property name="help_provider">none</property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">kicad2step_frame</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header"></property>
<property name="relative_path">1</property>
<property name="skip_lua_events">1</property>
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Frame" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
<property name="center">wxBOTH</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="event_handler">impl_virtual</property>
<property name="extra_style"></property>
<property name="fg"></property>
<property name="font"></property>
<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="pos"></property>
<property name="size">500,300</property>
<property name="style">wxDEFAULT_FRAME_STYLE</property>
<property name="subclass">; forward_declare; forward_declare</property>
<property name="title">Kicad2step Converter</property>
<property name="tooltip"></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="OnActivate"></event>
<event name="OnActivateApp"></event>
<event name="OnAuiPaneActivated"></event>
<event name="OnAuiPaneButton"></event>
<event name="OnAuiPaneClose"></event>
<event name="OnAuiPaneMaximize"></event>
<event name="OnAuiPaneRestore"></event>
<event name="OnAuiRender"></event>
<event name="OnAux1DClick"></event>
<event name="OnAux1Down"></event>
<event name="OnAux1Up"></event>
<event name="OnAux2DClick"></event>
<event name="OnAux2Down"></event>
<event name="OnAux2Up"></event>
<event name="OnChar"></event>
<event name="OnCharHook"></event>
<event name="OnClose"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnHibernate"></event>
<event name="OnIconize"></event>
<event name="OnIdle"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMaximize"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnMove"></event>
<event name="OnMoveEnd"></event>
<event name="OnMoveStart"></event>
<event name="OnMoving"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnShow"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizerMain</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 | wxALL</property>
<property name="proportion">1</property>
<object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_panelKicad2Step</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">public</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="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<event name="OnAux1DClick"></event>
<event name="OnAux1Down"></event>
<event name="OnAux1Up"></event>
<event name="OnAux2DClick"></event>
<event name="OnAux2Down"></event>
<event name="OnAux2Up"></event>
<event name="OnChar"></event>
<event name="OnCharHook"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
</object>
</wxFormBuilder_Project>

View File

@ -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 <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include "panel_kicad2step.h"
#include <wx/panel.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/frame.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// 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__

View File

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

View File

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

View File

@ -33,6 +33,7 @@
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <wx/textctrl.h>
#include <wx/utils.h>
#include <iostream>
@ -41,6 +42,8 @@
#include <string>
#include <wx/wxcrtvararg.h>
/*
* 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;

View File

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

View File

@ -26,8 +26,9 @@
#include <sstream>
#include <string>
#include <utility>
#include <wx/wx.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/filefn.h>
#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;
}

View File

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