diff --git a/pcbnew/dialogs/dialog_export_step.cpp b/pcbnew/dialogs/dialog_export_step.cpp index 72f41ca000..f4035c0e42 100644 --- a/pcbnew/dialogs/dialog_export_step.cpp +++ b/pcbnew/dialogs/dialog_export_step.cpp @@ -36,7 +36,6 @@ #include #include -#define OPTKEY_STEP_OVERWRITE "STEP_Overwrite" class DIALOG_EXPORT_STEP: public DIALOG_EXPORT_STEP_BASE { @@ -55,7 +54,7 @@ private: // The last preference for STEP Origin: STEP_ORG_OPT m_STEP_org_opt; bool m_noVirtual; // remember last preference for No Virtual Component - bool m_overwriteFile; // remember last preference for overwrite file + static bool m_overwriteFile; // remember last preference for overwrite file int m_OrgUnits; // remember last units for User Origin double m_XOrg; // remember last User Origin X value double m_YOrg; // remember last User Origin Y value @@ -118,6 +117,8 @@ public: } }; +bool DIALOG_EXPORT_STEP::m_overwriteFile = false; + DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath ) : DIALOG_EXPORT_STEP_BASE( aParent ) @@ -161,7 +162,6 @@ DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& m_noVirtual = cfg->m_ExportStep.no_virtual; m_cbRemoveVirtual->SetValue( m_noVirtual ); - m_config->Read( OPTKEY_STEP_OVERWRITE, &m_overwriteFile, false ); m_cbOverwriteFile->SetValue( m_overwriteFile ); m_STEP_OrgUnitChoice->SetSelection( m_OrgUnits ); diff --git a/utils/kicad2step/kicad2step.cpp b/utils/kicad2step/kicad2step.cpp index 25e29caa96..0e9da4a33a 100644 --- a/utils/kicad2step/kicad2step.cpp +++ b/utils/kicad2step/kicad2step.cpp @@ -21,7 +21,6 @@ * or you may write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - #include "wx/wx.h" #include #include @@ -31,11 +30,11 @@ #include #include #include -#include // In open cascade #include "pcb/kicadpcb.h" #include "kicad2step_frame_base.h" #include "panel_kicad2step.h" +#include // In open cascade class KICAD2STEP_FRAME; @@ -130,7 +129,7 @@ bool KICAD2MCAD_APP::OnInit() m_Panel = m_frame->m_panelKicad2Step; m_Panel->m_params = m_params; - // and show it (a wxRrame is not shown when created initially) + // and show it (a wxFrame is not shown when created initially) m_frame->Show( true ); m_frame->Iconize( false ); @@ -142,6 +141,7 @@ int KICAD2MCAD_APP::OnRun() { int diag = m_Panel->RunConverter(); wxApp::OnRun(); // Start the main loop event, to manage the main frame + return diag; } @@ -305,7 +305,7 @@ bool KICAD2MCAD_APP::OnCmdLineParsed( wxCmdLineParser& parser ) class STREAMBUF_SWAPPER { public: - STREAMBUF_SWAPPER( ostream & orig, ostream & replacement ) + STREAMBUF_SWAPPER( std::ostream & orig, std::ostream & replacement ) : m_buf( orig.rdbuf() ), m_str( orig ) { orig.rdbuf( replacement.rdbuf() ); @@ -368,8 +368,8 @@ int PANEL_KICAD2STEP::RunConverter() // msgs_from_opencascade and errors_from_opencascade std::ostringstream msgs_from_opencascade; std::ostringstream errors_from_opencascade; - STREAMBUF_SWAPPER swapper_cout(cout, msgs_from_opencascade); - STREAMBUF_SWAPPER swapper_cerr(cerr, errors_from_opencascade); + STREAMBUF_SWAPPER swapper_cout(std::cout, msgs_from_opencascade); + STREAMBUF_SWAPPER swapper_cerr(std::cerr, errors_from_opencascade); if( pcb.ReadFile( m_params.m_filename ) ) { diff --git a/utils/kicad2step/kicad2step_frame_base.cpp b/utils/kicad2step/kicad2step_frame_base.cpp index d50e1cc024..76e071bc2d 100644 --- a/utils/kicad2step/kicad2step_frame_base.cpp +++ b/utils/kicad2step/kicad2step_frame_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 11 2018) +// C++ code generated with wxFormBuilder (version Jul 10 2019) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -12,17 +12,17 @@ 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, 5 ); - - + + this->SetSizer( bSizerMain ); this->Layout(); - + this->Centre( wxBOTH ); } diff --git a/utils/kicad2step/kicad2step_frame_base.fbp b/utils/kicad2step/kicad2step_frame_base.fbp index e62302f146..a49233537c 100644 --- a/utils/kicad2step/kicad2step_frame_base.fbp +++ b/utils/kicad2step/kicad2step_frame_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ kicad2step_frame_base 1000 none + 1 kicad2step_frame @@ -25,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -45,8 +47,8 @@ KICAD2STEP_FRAME_BASE - 500,300 - wxDEFAULT_FRAME_STYLE + 644,300 + wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER ; forward_declare; forward_declare Kicad2step Converter @@ -54,54 +56,6 @@ wxTAB_TRAVERSAL 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bSizerMain @@ -162,36 +116,6 @@ wxTAB_TRAVERSAL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/utils/kicad2step/kicad2step_frame_base.h b/utils/kicad2step/kicad2step_frame_base.h index 66ddbecfe4..1f9b441d49 100644 --- a/utils/kicad2step/kicad2step_frame_base.h +++ b/utils/kicad2step/kicad2step_frame_base.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 11 2018) +// C++ code generated with wxFormBuilder (version Jul 10 2019) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __KICAD2STEP_FRAME_BASE_H__ -#define __KICAD2STEP_FRAME_BASE_H__ +#pragma once #include #include @@ -27,19 +26,18 @@ /////////////////////////////////////////////////////////////////////////////// /// Class KICAD2STEP_FRAME_BASE /////////////////////////////////////////////////////////////////////////////// -class KICAD2STEP_FRAME_BASE : public wxFrame +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( 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 ); + ~KICAD2STEP_FRAME_BASE(); - + }; -#endif //__KICAD2STEP_FRAME_BASE_H__ diff --git a/utils/kicad2step/pcb/kicadmodule.cpp b/utils/kicad2step/pcb/kicadmodule.cpp index 5fcd97a958..8b72322dbf 100644 --- a/utils/kicad2step/pcb/kicadmodule.cpp +++ b/utils/kicad2step/pcb/kicadmodule.cpp @@ -38,6 +38,7 @@ #include #include +#include KICADMODULE::KICADMODULE( KICADPCB* aParent ) { @@ -378,10 +379,17 @@ bool KICADMODULE::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver, std::string fname( resolver->ResolvePath( wxString::FromUTF8Unchecked( i->m_modelname.c_str() ) ).ToUTF8() ); - if( aPCB->AddComponent( fname, m_refdes, LAYER_BOTTOM == m_side ? true : false, - newpos, m_rotation, i->m_offset, i->m_rotation, i->m_scale ) ) - hasdata = true; - + try + { + if( aPCB->AddComponent( fname, m_refdes, LAYER_BOTTOM == m_side ? true : false, + newpos, m_rotation, i->m_offset, i->m_rotation, i->m_scale ) ) + hasdata = true; + } + catch( const Standard_Failure& e) + { + ReportMessage( wxString::Format( "could not add component %s\n>>Opencascade error: %s\n ", + m_refdes, e.GetMessageString() ) ); + } } return hasdata; diff --git a/utils/kicad2step/pcb/oce_utils.cpp b/utils/kicad2step/pcb/oce_utils.cpp index 5ea31860d5..3865e0fd51 100644 --- a/utils/kicad2step/pcb/oce_utils.cpp +++ b/utils/kicad2step/pcb/oce_utils.cpp @@ -164,13 +164,11 @@ FormatType fileType( const char* aFileName ) if( !lfile.FileExists() ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * no such file: '" << aFileName << "'\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + wxString msg; + msg.Printf( " * fileType(): no such file: %s\n", + wxString::FromUTF8Unchecked( aFileName ) ); + ReportMessage( msg ); return FMT_NONE; } @@ -257,12 +255,9 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) if( distance < m_minDistance2 ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * rejected a zero-length " << aCurve->Describe() << "\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + wxString msg; + msg.Printf( " * AddOutlineSegment() rejected a zero-length %s\n", aCurve->Describe() ); + ReportMessage( msg ); return false; } @@ -276,12 +271,9 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) if( rad < m_minDistance2 ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * rejected a zero-radius " << aCurve->Describe() << "\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + wxString msg; + msg.Printf( " * AddOutlineSegment() rejected a zero-radius %s\n", aCurve->Describe() ); + ReportMessage( msg ); return false; } @@ -316,13 +308,10 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) if( rad < m_minDistance2 ) { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * rejected an arc with equivalent end points, " - << aCurve->Describe() << "\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + wxString msg; + msg.Printf( " * AddOutlineSegment() rejected an arc with equivalent end points, %s\n", + aCurve->Describe() ); + ReportMessage( msg ); return false; } } @@ -422,12 +411,10 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) // unexpected curve type do { - 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() ); + wxString msg; + msg.Printf( " * AddOutlineSegment() unsupported curve type: %s\n", + aCurve->m_form ); + ReportMessage( msg ); } while( 0 ); return false; @@ -664,7 +651,8 @@ bool PCBMODEL::CreatePCB() oln.AddSegment( *m_mincurve ); m_curves.erase( m_mincurve ); - ReportMessage( wxString::Format( "Build board outline (%d items)\n", (int)m_curves.size() ) ); + ReportMessage( wxString::Format( "Build board outline (%d items)\n", + (int)m_curves.size() ) ); while( !m_curves.empty() ) { @@ -764,12 +752,10 @@ bool PCBMODEL::CreatePCB() } // subtract cutouts (if any) - for( const auto& i : m_cutouts ) - board = BRepAlgoAPI_Cut( board, i ); - if( m_cutouts.size() ) - ReportMessage( wxString::Format( "Build board cutout (%d holes)\n", (int)m_cutouts.size() ) ); + ReportMessage( wxString::Format( "Build board cutouts and holes (%d holes)\n", (int)m_cutouts.size() ) ); +#if 0 // First version for holes removing: very slow when having many (> 300) holes // Substract holes (cutouts) can be time consuming, so display activity // state to be sure there is no hang: int char_count = 0; @@ -791,7 +777,23 @@ bool PCBMODEL::CreatePCB() ReportMessage( wxString::Format( ". %d/%d\n", cur_count, cntmax ) ); } } +#else // Much faster than first version: group all holes and cut only once + { + BRepAlgoAPI_Cut Cut; + TopTools_ListOfShape mainbrd; + mainbrd.Append( board ); + Cut.SetArguments( mainbrd ); + TopTools_ListOfShape holelist; + + for( auto hole : m_cutouts ) + holelist.Append( hole ); + + Cut.SetTools( holelist ); + Cut.Build(); + board = Cut.Shape(); + } +#endif // push the board to the data structure ReportMessage( "\nGenerate board full shape\n" ); m_pcb_label = m_assy->AddComponent( m_assy_label, board ); @@ -827,7 +829,8 @@ bool PCBMODEL::WriteIGES( const wxString& aFileName ) { if( m_pcb_label.IsNull() ) { - ReportMessage( wxString::Format( "No valid PCB assembly; cannot create output file %s\n", aFileName ) ); + ReportMessage( wxString::Format( + "No valid PCB assembly; cannot create output file %s\n", aFileName ) ); return false; } @@ -837,7 +840,7 @@ bool PCBMODEL::WriteIGES( const wxString& aFileName ) writer.SetColorMode( Standard_True ); writer.SetNameMode( Standard_True ); IGESData_GlobalSection header = writer.Model()->GlobalSection(); - header.SetFileName( new TCollection_HAsciiString( fn.GetFullName().ToUTF8() ) ); + header.SetFileName( new TCollection_HAsciiString( fn.GetFullName().ToAscii() ) ); header.SetSendName( new TCollection_HAsciiString( "KiCad electronic assembly" ) ); header.SetAuthorName( new TCollection_HAsciiString( Interface_Static::CVal( "write.iges.header.author" ) ) ); header.SetCompanyName( new TCollection_HAsciiString( Interface_Static::CVal( "write.iges.header.company" ) ) ); @@ -869,10 +872,12 @@ bool PCBMODEL::WriteSTEP( const wxString& aFileName ) APIHeaderSection_MakeHeader hdr( writer.ChangeWriter().Model() ); wxFileName fn( aFileName ); - hdr.SetName( new TCollection_HAsciiString( fn.GetFullName().ToUTF8() ) ); + // Note: use only Ascii7 chars, non Ascii7 chars (therefore UFT8 chars) + // are creating issues in the step file + hdr.SetName( new TCollection_HAsciiString( fn.GetFullName().ToAscii() ) ); // TODO: how to control and ensure consistency with IGES? - hdr.SetAuthorValue( 1, new TCollection_HAsciiString( "An Author" ) ); - hdr.SetOrganizationValue( 1, new TCollection_HAsciiString( "A Company" ) ); + hdr.SetAuthorValue( 1, new TCollection_HAsciiString( "Pcbnew" ) ); + hdr.SetOrganizationValue( 1, new TCollection_HAsciiString( "Kicad" ) ); hdr.SetOriginatingSystem( new TCollection_HAsciiString( "KiCad to STEP converter" ) ); hdr.SetDescriptionValue( 1, new TCollection_HAsciiString( "KiCad electronic assembly" ) ); @@ -880,7 +885,11 @@ bool PCBMODEL::WriteSTEP( const wxString& aFileName ) // Creates a temporary file with a ascii7 name, because writer does not know // unicode filenames wxString currCWD = wxGetCwd(); - wxSetWorkingDirectory( fn.GetPath() ); + wxString workCWD =fn.GetPath(); + + if( !workCWD.IsEmpty() ) + wxSetWorkingDirectory( workCWD ); + char tmpfname[] = "$tempfile$.step"; if( Standard_False == writer.Write( tmpfname ) ) @@ -899,7 +908,8 @@ bool PCBMODEL::WriteSTEP( const wxString& aFileName ) bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_Label& aLabel ) { - std::string model_key = aFileName + "_" + std::to_string( aScale.x ) + "_" + std::to_string( aScale.y ) + "_" + std::to_string( aScale.z ); + std::string model_key = aFileName + "_" + std::to_string( aScale.x ) + + "_" + std::to_string( aScale.y ) + "_" + std::to_string( aScale.z ); MODEL_MAP::const_iterator mm = m_models.find( model_key ); @@ -921,7 +931,8 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_L case FMT_IGES: if( !readIGES( doc, aFileName.c_str() ) ) { - ReportMessage( wxString::Format( "readIGES() failed on filename %s\n", aFileName ) ); + ReportMessage( wxString::Format( "readIGES() failed on filename %s\n", + aFileName ) ); return false; } break; @@ -929,7 +940,8 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_L case FMT_STEP: if( !readSTEP( doc, aFileName.c_str() ) ) { - ReportMessage( wxString::Format( "readSTEP() failed on filename %s\n", aFileName ) ); + ReportMessage( wxString::Format( "readSTEP() failed on filename %s\n", + aFileName ) ); return false; } break; @@ -1001,7 +1013,7 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TRIPLET aScale, TDF_L if( aLabel.IsNull() ) { - ReportMessage( wxString::Format( "could not transfer model data from file %s", aFileName ) ); + ReportMessage( wxString::Format( "could not transfer model data from file %s\n", aFileName ) ); return false; } @@ -1192,15 +1204,14 @@ TDF_Label PCBMODEL::transferModel( Handle( TDocStd_Document )& source, brep.Perform( shape, Standard_False ); TopoDS_Shape scaled_shape; - if ( brep.IsDone() ) { + if ( brep.IsDone() ) + { scaled_shape = brep.Shape(); - } else { - std::ostringstream ostr; -#ifdef DEBUG - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; -#endif /* DEBUG */ - ostr << " * failed to scale model\n"; - wxLogMessage( "%s", ostr.str().c_str() ); + } + else + { + ReportMessage( " * transfertModel(): failed to scale model\n" ); + scaled_shape = shape; }