Commit da678809 authored by Maciej Suminski's avatar Maciej Suminski

DXF files import is supported by module editor.

parent b2a60175
......@@ -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;
......
......@@ -35,7 +35,12 @@
#include <dialog_dxf_import_base.h>
#include <class_pcb_layer_box_selector.h>
#include <class_draw_panel_gal.h>
#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
#include <class_text_mod.h>
#include <class_pcb_text.h>
// 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<BOARD_ITEM*>& 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<BOARD_ITEM*>::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<DRAWSEGMENT*>( converted ) = *static_cast<DRAWSEGMENT*>( item );
module->Add( converted );
static_cast<EDGE_MODULE*>( converted )->SetLocalCoord();
delete item;
break;
}
case PCB_TEXT_T:
{
converted = new TEXTE_MODULE( module );
*static_cast<TEXTE_PCB*>( converted ) = *static_cast<TEXTE_PCB*>( item );
module->Add( module );
static_cast<TEXTE_MODULE*>( 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;
}
......@@ -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
......
......@@ -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
......
......@@ -39,6 +39,7 @@
#include <kicad_device_context.h>
#include <macros.h>
#include <pcbcommon.h>
#include <invoke_pcb_dialog.h>
#include <class_board.h>
#include <class_module.h>
......@@ -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" ) );
......
......@@ -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 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment