DXF files import is supported by module editor.

This commit is contained in:
Maciej Suminski 2014-07-09 15:02:56 +02:00
parent b2a601756e
commit da67880907
6 changed files with 94 additions and 4 deletions

View File

@ -1213,7 +1213,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_GEN_IMPORT_DXF_FILE: case ID_GEN_IMPORT_DXF_FILE:
InvokeDXFDialogImport( this ); InvokeDXFDialogBoardImport( this );
m_canvas->Refresh(); m_canvas->Refresh();
break; break;

View File

@ -35,7 +35,12 @@
#include <dialog_dxf_import_base.h> #include <dialog_dxf_import_base.h>
#include <class_pcb_layer_box_selector.h> #include <class_pcb_layer_box_selector.h>
#include <class_draw_panel_gal.h> #include <class_draw_panel_gal.h>
#include <class_board.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 // 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 ); DIALOG_DXF_IMPORT dlg( aCaller );
bool success = ( dlg.ShowModal() == wxID_OK ); 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 ) for( it = list.begin(), itEnd = list.end(); it != itEnd; ++it )
{ {
BOARD_ITEM* item = *it; BOARD_ITEM* item = *it;
board->Add( item ); board->Add( item );
ITEM_PICKER itemWrapper( item, UR_NEW ); ITEM_PICKER itemWrapper( item, UR_NEW );
@ -232,3 +236,65 @@ bool InvokeDXFDialogImport( PCB_BASE_FRAME* aCaller )
return success; 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;
}

View File

@ -50,6 +50,7 @@ class wxSize;
class wxString; class wxString;
class BOARD; class BOARD;
class MODULE;
// Often this is not used in the prototypes, since wxFrame is good enough and would // Often this is not used in the prototypes, since wxFrame is good enough and would
// represent maximum information hiding. // 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. * @param aCaller is the wxTopLevelWindow which is invoking the dialog.
* @return true if the import was made. * @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 * Function InvokeLayerSetup

View File

@ -125,6 +125,13 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar()
_( "&Export Module" ), _( "&Export Module" ),
_( "Save current loaded module into file" ), _( "Save current loaded module into file" ),
KiBitmap( export_module_xpm ) ); 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(); fileMenu->AppendSeparator();
// Print // Print

View File

@ -39,6 +39,7 @@
#include <kicad_device_context.h> #include <kicad_device_context.h>
#include <macros.h> #include <macros.h>
#include <pcbcommon.h> #include <pcbcommon.h>
#include <invoke_pcb_dialog.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
@ -777,6 +778,11 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
HandleBlockEnd( &dc ); HandleBlockEnd( &dc );
break; break;
case ID_GEN_IMPORT_DXF_FILE:
InvokeDXFDialogModuleImport( this, GetBoard()->m_Modules );
m_canvas->Refresh();
break;
default: default:
DisplayError( this, DisplayError( this,
wxT( "FOOTPRINT_EDIT_FRAME::Process_Special_Functions error" ) ); wxT( "FOOTPRINT_EDIT_FRAME::Process_Special_Functions error" ) );

View File

@ -92,6 +92,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
EVT_TOOL( ID_MODEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART, EVT_TOOL( ID_MODEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART,
FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( ID_MODEDIT_SHEET_SET, 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( wxID_PRINT, FOOTPRINT_EDIT_FRAME::ToPrinter )
EVT_TOOL( ID_MODEDIT_LOAD_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_LOAD_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( ID_MODEDIT_CHECK, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_CHECK, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )