diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 79fc20b730..787a73827e 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -1213,7 +1213,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_GEN_IMPORT_DXF_FILE: - InvokeDXFDialogImport( this ); + InvokeDXFDialogBoardImport( this ); m_canvas->Refresh(); break; diff --git a/pcbnew/import_dxf/dialog_dxf_import.cpp b/pcbnew/import_dxf/dialog_dxf_import.cpp index 49ab35cd79..612fba07c4 100644 --- a/pcbnew/import_dxf/dialog_dxf_import.cpp +++ b/pcbnew/import_dxf/dialog_dxf_import.cpp @@ -35,7 +35,12 @@ #include #include #include + #include +#include +#include +#include +#include // Keys to store setup in config @@ -197,7 +202,7 @@ void DIALOG_DXF_IMPORT::OnOKClick( wxCommandEvent& event ) } -bool InvokeDXFDialogImport( PCB_BASE_FRAME* aCaller ) +bool InvokeDXFDialogBoardImport( PCB_BASE_FRAME* aCaller ) { DIALOG_DXF_IMPORT dlg( aCaller ); bool success = ( dlg.ShowModal() == wxID_OK ); @@ -216,7 +221,6 @@ bool InvokeDXFDialogImport( PCB_BASE_FRAME* aCaller ) for( it = list.begin(), itEnd = list.end(); it != itEnd; ++it ) { BOARD_ITEM* item = *it; - board->Add( item ); ITEM_PICKER itemWrapper( item, UR_NEW ); @@ -232,3 +236,65 @@ bool InvokeDXFDialogImport( PCB_BASE_FRAME* aCaller ) return success; } + + +bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule ) +{ + DIALOG_DXF_IMPORT dlg( aCaller ); + bool success = ( dlg.ShowModal() == wxID_OK ); + + if( success ) + { + // Prepare the undo list + const std::list& list = dlg.GetImportedItems(); + PICKED_ITEMS_LIST picklist; + + MODULE* module = aCaller->GetBoard()->m_Modules; + KIGFX::VIEW* view = aCaller->GetGalCanvas()->GetView(); + + aCaller->SaveCopyInUndoList( module, UR_MODEDIT ); + aCaller->OnModify(); + + // Build the undo list & add items to the current view + std::list::const_iterator it, itEnd; + for( it = list.begin(), itEnd = list.end(); it != itEnd; ++it ) + { + BOARD_ITEM* item = *it; + BOARD_ITEM* converted = NULL; + + // Modules use different types for the same things, + // so we need to convert imported items to appropriate classes. + switch( item->Type() ) + { + case PCB_LINE_T: + { + converted = new EDGE_MODULE( module ); + *static_cast( converted ) = *static_cast( item ); + module->Add( converted ); + static_cast( converted )->SetLocalCoord(); + delete item; + break; + } + + case PCB_TEXT_T: + { + converted = new TEXTE_MODULE( module ); + *static_cast( converted ) = *static_cast( item ); + module->Add( module ); + static_cast( converted )->SetLocalCoord(); + delete item; + break; + } + + default: + assert( false ); // there is a type that is currently not handled here + break; + } + + if( aCaller->IsGalCanvasActive() ) + view->Add( converted ); + } + } + + return success; +} diff --git a/pcbnew/invoke_pcb_dialog.h b/pcbnew/invoke_pcb_dialog.h index 151ce609a6..5f264ca000 100644 --- a/pcbnew/invoke_pcb_dialog.h +++ b/pcbnew/invoke_pcb_dialog.h @@ -50,6 +50,7 @@ class wxSize; class wxString; class BOARD; +class MODULE; // Often this is not used in the prototypes, since wxFrame is good enough and would // represent maximum information hiding. @@ -88,7 +89,16 @@ void InvokePluginOptionsEditor( wxTopLevelWindow* aCaller, const wxString& aNick * @param aCaller is the wxTopLevelWindow which is invoking the dialog. * @return true if the import was made. */ -bool InvokeDXFDialogImport( PCB_BASE_FRAME* aCaller ); +bool InvokeDXFDialogBoardImport( PCB_BASE_FRAME* aCaller ); + +/** + * Function InvokeDXFDialogModuleImport + * shows the modal DIALOG_DXF_IMPORT for importing a DXF file.to a module. + * + * @param aCaller is the wxTopLevelWindow which is invoking the dialog. + * @return true if the import was made. + */ +bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule ); /** * Function InvokeLayerSetup diff --git a/pcbnew/menubar_modedit.cpp b/pcbnew/menubar_modedit.cpp index ffbe9a681f..418cc5c342 100644 --- a/pcbnew/menubar_modedit.cpp +++ b/pcbnew/menubar_modedit.cpp @@ -125,6 +125,13 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() _( "&Export Module" ), _( "Save current loaded module into file" ), KiBitmap( export_module_xpm ) ); + + // Import DXF File + AddMenuItem( fileMenu, ID_GEN_IMPORT_DXF_FILE, + _( "&Import DXF File" ), + _( "Import a 2D Drawing DXF file to Pcbnew on the Drawings layer" ), + KiBitmap( import_xpm ) ); + fileMenu->AppendSeparator(); // Print diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index c813011dd6..3abe8f08ad 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -777,6 +778,11 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) HandleBlockEnd( &dc ); break; + case ID_GEN_IMPORT_DXF_FILE: + InvokeDXFDialogModuleImport( this, GetBoard()->m_Modules ); + m_canvas->Refresh(); + break; + default: DisplayError( this, wxT( "FOOTPRINT_EDIT_FRAME::Process_Special_Functions error" ) ); diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 603e4e0838..f237b245e0 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -92,6 +92,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME ) EVT_TOOL( ID_MODEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_SHEET_SET, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) + EVT_TOOL( ID_GEN_IMPORT_DXF_FILE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( wxID_PRINT, FOOTPRINT_EDIT_FRAME::ToPrinter ) EVT_TOOL( ID_MODEDIT_LOAD_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_CHECK, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )