More DXF import fixes.

This commit is contained in:
Maciej Suminski 2015-08-03 21:11:59 +02:00
parent 0fbf31ef38
commit 2a93d083ee
2 changed files with 21 additions and 62 deletions

View File

@ -32,7 +32,6 @@
#include <kiface_i.h>
#include <convert_from_iu.h>
#include <class_pcb_layer_box_selector.h>
#include <class_draw_panel_gal.h>
#include <class_board.h>
#include <class_module.h>
@ -181,9 +180,7 @@ bool InvokeDXFDialogBoardImport( PCB_BASE_FRAME* aCaller )
{
const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();
PICKED_ITEMS_LIST picklist;
BOARD* board = aCaller->GetBoard();
KIGFX::VIEW* view = aCaller->GetGalCanvas()->GetView();
std::list<BOARD_ITEM*>::const_iterator it, itEnd;
for( it = list.begin(), itEnd = list.end(); it != itEnd; ++it )
@ -193,9 +190,6 @@ bool InvokeDXFDialogBoardImport( PCB_BASE_FRAME* aCaller )
ITEM_PICKER itemWrapper( item, UR_NEW );
picklist.PushItem( itemWrapper );
if( aCaller->IsGalCanvasActive() )
view->Add( item );
}
aCaller->SaveCopyInUndoList( picklist, UR_NEW, wxPoint( 0, 0 ) );
@ -216,7 +210,6 @@ bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule )
if( success )
{
const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();
KIGFX::VIEW* view = aCaller->GetGalCanvas()->GetView();
aCaller->SaveCopyInUndoList( aModule, UR_MODEDIT );
aCaller->OnModify();
@ -255,9 +248,6 @@ bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule )
wxLogDebug( wxT( "type %d currently not handled" ), item->Type() );
break;
}
if( aCaller->IsGalCanvasActive() && converted )
view->Add( converted );
}
}

View File

@ -448,52 +448,11 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
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;
KICAD_T type = (*it)->Type();
assert( type == PCB_LINE_T || type == PCB_TEXT_T );
// 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:
{
if( m_editModules )
{
converted = new EDGE_MODULE( m_board->m_Modules );
*static_cast<DRAWSEGMENT*>( converted ) = *static_cast<DRAWSEGMENT*>( item );
converted->Move( wxPoint( delta.x, delta.y ) );
preview.Add( converted );
delete item;
}
else
{
preview.Add( item );
}
break;
}
case PCB_TEXT_T:
{
if( m_editModules )
{
converted = new TEXTE_MODULE( m_board->m_Modules );
*static_cast<TEXTE_PCB*>( converted ) = *static_cast<TEXTE_PCB*>( item );
converted->Move( wxPoint( delta.x, delta.y ) );
preview.Add( converted );
delete item;
}
else
{
preview.Add( item );
}
break;
}
default:
assert( false ); // there is a type that is currently not handled here
break;
}
if( type == PCB_LINE_T || type == PCB_TEXT_T )
preview.Add( *it );
}
BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( *preview.Begin() );
@ -549,22 +508,31 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
// Place the drawing
if( m_editModules )
{
assert( m_board->m_Modules );
m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT );
m_board->m_Modules->SetLastEditTime();
for( KIGFX::VIEW_GROUP::iter it = preview.Begin(), end = preview.End(); it != end; ++it )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( *it );
m_board->m_Modules->Add( item );
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_MODULE_TEXT_T:
static_cast<TEXTE_MODULE*>( item )->SetLocalCoord();
case PCB_TEXT_T:
converted = new TEXTE_MODULE( m_board->m_Modules );
// Copy coordinates, layer, etc.
*static_cast<TEXTE_PCB*>( converted ) = *static_cast<TEXTE_PCB*>( item );
static_cast<TEXTE_MODULE*>( converted )->SetLocalCoord();
break;
case PCB_MODULE_EDGE_T:
static_cast<EDGE_MODULE*>( item )->SetLocalCoord();
case PCB_LINE_T:
converted = new EDGE_MODULE( m_board->m_Modules );
// Copy coordinates, layer, etc.
*static_cast<DRAWSEGMENT*>( converted ) = *static_cast<DRAWSEGMENT*>( item );
static_cast<EDGE_MODULE*>( converted )->SetLocalCoord();
break;
default:
@ -572,7 +540,9 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
break;
}
m_view->Add( item );
delete item;
m_board->m_Modules->Add( converted );
m_view->Add( converted );
}
}
else
@ -594,7 +564,6 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
}
m_frame->OnModify();
break;
}
}