Refactored DXF import routines:
- DIALOG_DXF_IMPORT works with PCB_BASE_FRAME instead of PCB_EDIT_FRAME - imported items are not immediately added to a BOARD - imported items are held in a list, instead of vector - imported items are instantly visible in GAL view - added DIALOG_DXF_IMPORT::GetImportedItems() - code formatting
This commit is contained in:
parent
4ac277028b
commit
b2a601756e
|
@ -1219,8 +1219,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|||
|
||||
default:
|
||||
wxString msg;
|
||||
msg.Printf( wxT( "PCB_EDIT_FRAME::Process_Special_Functions() unknown event id %d" ),
|
||||
id );
|
||||
msg.Printf( wxT( "PCB_EDIT_FRAME::Process_Special_Functions() unknown event id %d" ), id );
|
||||
DisplayError( this, msg );
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include <convert_from_iu.h>
|
||||
#include <dialog_dxf_import_base.h>
|
||||
#include <class_pcb_layer_box_selector.h>
|
||||
#include <class_draw_panel_gal.h>
|
||||
#include <class_board.h>
|
||||
|
||||
|
||||
// Keys to store setup in config
|
||||
|
@ -43,20 +45,29 @@
|
|||
|
||||
class DIALOG_DXF_IMPORT : public DIALOG_DXF_IMPORT_BASE
|
||||
{
|
||||
private:
|
||||
PCB_EDIT_FRAME * m_parent;
|
||||
wxConfigBase* m_config; // Current config
|
||||
|
||||
static wxString m_dxfFilename;
|
||||
static int m_offsetSelection;
|
||||
static LAYER_NUM m_layer;
|
||||
|
||||
public:
|
||||
|
||||
DIALOG_DXF_IMPORT( PCB_EDIT_FRAME* aParent );
|
||||
DIALOG_DXF_IMPORT( PCB_BASE_FRAME* aParent );
|
||||
~DIALOG_DXF_IMPORT();
|
||||
|
||||
/**
|
||||
* Function GetImportedItems()
|
||||
*
|
||||
* Returns a list of items imported from a DXF file.
|
||||
*/
|
||||
const std::list<BOARD_ITEM*>& GetImportedItems() const
|
||||
{
|
||||
return m_dxfImporter.GetItemsList();
|
||||
}
|
||||
|
||||
private:
|
||||
PCB_BASE_FRAME* m_parent;
|
||||
wxConfigBase* m_config; // Current config
|
||||
DXF2BRD_CONVERTER m_dxfImporter;
|
||||
|
||||
static wxString m_dxfFilename;
|
||||
static int m_offsetSelection;
|
||||
static LAYER_NUM m_layer;
|
||||
|
||||
// Virtual event handlers
|
||||
void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
|
||||
void OnOKClick( wxCommandEvent& event );
|
||||
|
@ -70,8 +81,8 @@ int DIALOG_DXF_IMPORT::m_offsetSelection = 4;
|
|||
LAYER_NUM DIALOG_DXF_IMPORT::m_layer = Dwgs_User;
|
||||
|
||||
|
||||
DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT( PCB_EDIT_FRAME* aParent ) :
|
||||
DIALOG_DXF_IMPORT_BASE( aParent )
|
||||
DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT( PCB_BASE_FRAME* aParent )
|
||||
: DIALOG_DXF_IMPORT_BASE( aParent )
|
||||
{
|
||||
m_parent = aParent;
|
||||
m_config = Kiface().KifaceSettings();
|
||||
|
@ -130,7 +141,7 @@ void DIALOG_DXF_IMPORT::OnBrowseDxfFiles( wxCommandEvent& event )
|
|||
wxFileDialog dlg( m_parent,
|
||||
wxT( "Open File" ),
|
||||
path, m_dxfFilename,
|
||||
wxT( "dxf Files (*.dxf)|*.dxf|*.DXF" ),
|
||||
wxT( "dxf Files (*.dxf)|*.dxf" ),
|
||||
wxFD_OPEN|wxFD_FILE_MUST_EXIST );
|
||||
dlg.ShowModal();
|
||||
|
||||
|
@ -143,6 +154,7 @@ void DIALOG_DXF_IMPORT::OnBrowseDxfFiles( wxCommandEvent& event )
|
|||
m_textCtrlFileName->SetValue( fileName );
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_DXF_IMPORT::OnOKClick( wxCommandEvent& event )
|
||||
{
|
||||
m_dxfFilename = m_textCtrlFileName->GetValue();
|
||||
|
@ -173,41 +185,50 @@ void DIALOG_DXF_IMPORT::OnOKClick( wxCommandEvent& event )
|
|||
break;
|
||||
}
|
||||
|
||||
BOARD * brd = m_parent->GetBoard();
|
||||
DXF2BRD_CONVERTER dxf_importer;
|
||||
|
||||
// Set coordinates offset for import (offset is given in mm)
|
||||
dxf_importer.SetOffset( offsetX, offsetY );
|
||||
m_dxfImporter.SetOffset( offsetX, offsetY );
|
||||
m_layer = m_SelLayerBox->GetLayerSelection();
|
||||
dxf_importer.SetBrdLayer( m_layer );
|
||||
m_dxfImporter.SetBrdLayer( m_layer );
|
||||
|
||||
// Read dxf file:
|
||||
dxf_importer.ImportDxfFile( m_dxfFilename, brd );
|
||||
|
||||
// Prepare the undo list
|
||||
std::vector<BOARD_ITEM*>& list = dxf_importer.GetItemsList();
|
||||
PICKED_ITEMS_LIST picklist;
|
||||
|
||||
// Build the undo list
|
||||
for( unsigned ii = 0; ii < list.size(); ii++ )
|
||||
{
|
||||
ITEM_PICKER itemWrapper( list[ii], UR_NEW );
|
||||
picklist.PushItem( itemWrapper );
|
||||
}
|
||||
|
||||
m_parent->SaveCopyInUndoList( picklist, UR_NEW, wxPoint(0,0) );
|
||||
m_dxfImporter.ImportDxfFile( m_dxfFilename );
|
||||
|
||||
EndModal( wxID_OK );
|
||||
}
|
||||
|
||||
|
||||
bool InvokeDXFDialogImport( PCB_EDIT_FRAME* aCaller )
|
||||
bool InvokeDXFDialogImport( PCB_BASE_FRAME* aCaller )
|
||||
{
|
||||
DIALOG_DXF_IMPORT dlg( aCaller );
|
||||
bool success = dlg.ShowModal() == wxID_OK;
|
||||
bool success = ( dlg.ShowModal() == wxID_OK );
|
||||
|
||||
if( success )
|
||||
{
|
||||
// Prepare the undo list
|
||||
const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();
|
||||
PICKED_ITEMS_LIST picklist;
|
||||
|
||||
BOARD* board = aCaller->GetBoard();
|
||||
KIGFX::VIEW* view = aCaller->GetGalCanvas()->GetView();
|
||||
|
||||
// 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->Add( item );
|
||||
|
||||
ITEM_PICKER itemWrapper( item, UR_NEW );
|
||||
picklist.PushItem( itemWrapper );
|
||||
|
||||
if( aCaller->IsGalCanvasActive() )
|
||||
view->Add( item );
|
||||
}
|
||||
|
||||
aCaller->SaveCopyInUndoList( picklist, UR_NEW, wxPoint( 0, 0 ) );
|
||||
aCaller->OnModify();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@ DXF2BRD_CONVERTER::DXF2BRD_CONVERTER() : DRW_Interface()
|
|||
m_xOffset = 0.0; // X coord offset for conversion (in mm)
|
||||
m_yOffset = 0.0; // Y coord offset for conversion (in mm)
|
||||
m_Dfx2mm = 1.0; // The scale factor to convert DXF units to mm
|
||||
m_brd = NULL;
|
||||
m_version = 0;
|
||||
m_defaultThickness = 0.1;
|
||||
m_brdLayer = Dwgs_User;
|
||||
|
@ -83,10 +82,8 @@ int DXF2BRD_CONVERTER::mapDim( double aDxfValue )
|
|||
}
|
||||
|
||||
|
||||
bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile, BOARD* aBoard )
|
||||
bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile )
|
||||
{
|
||||
m_brd = aBoard;
|
||||
|
||||
dxfRW* dxf = new dxfRW( aFile.ToUTF8() );
|
||||
bool success = dxf->read( this, true );
|
||||
|
||||
|
@ -96,13 +93,6 @@ bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile, BOARD* aBoard )
|
|||
}
|
||||
|
||||
|
||||
void DXF2BRD_CONVERTER::appendToBoard( BOARD_ITEM* aItem )
|
||||
{
|
||||
m_brd->Add( aItem );
|
||||
m_newItemsList.push_back( aItem );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of the method which handles layers.
|
||||
*/
|
||||
|
@ -121,7 +111,7 @@ void DXF2BRD_CONVERTER::addLayer( const DRW_Layer& aData )
|
|||
*/
|
||||
void DXF2BRD_CONVERTER::addLine( const DRW_Line& aData )
|
||||
{
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT( m_brd );
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT;
|
||||
|
||||
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
||||
wxPoint start( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
|
||||
|
@ -129,7 +119,7 @@ void DXF2BRD_CONVERTER::addLine( const DRW_Line& aData )
|
|||
wxPoint end( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
|
||||
segm->SetEnd( end );
|
||||
segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
|
||||
appendToBoard( segm );
|
||||
m_newItemsList.push_back( segm );
|
||||
}
|
||||
|
||||
void DXF2BRD_CONVERTER::addPolyline(const DRW_Polyline& aData )
|
||||
|
@ -151,7 +141,7 @@ void DXF2BRD_CONVERTER::addPolyline(const DRW_Polyline& aData )
|
|||
continue;
|
||||
}
|
||||
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT( m_brd );
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT( NULL );
|
||||
|
||||
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
||||
segm->SetStart( startpoint );
|
||||
|
@ -159,7 +149,7 @@ void DXF2BRD_CONVERTER::addPolyline(const DRW_Polyline& aData )
|
|||
segm->SetEnd( endpoint );
|
||||
segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness
|
||||
: aData.thickness ) );
|
||||
appendToBoard( segm );
|
||||
m_newItemsList.push_back( segm );
|
||||
startpoint = endpoint;
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +174,7 @@ void DXF2BRD_CONVERTER::addLWPolyline(const DRW_LWPolyline& aData )
|
|||
continue;
|
||||
}
|
||||
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT( m_brd );
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT( NULL );
|
||||
|
||||
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
||||
segm->SetStart( startpoint );
|
||||
|
@ -192,7 +182,7 @@ void DXF2BRD_CONVERTER::addLWPolyline(const DRW_LWPolyline& aData )
|
|||
segm->SetEnd( endpoint );
|
||||
segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness
|
||||
: aData.thickness ) );
|
||||
appendToBoard( segm );
|
||||
m_newItemsList.push_back( segm );
|
||||
startpoint = endpoint;
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +192,7 @@ void DXF2BRD_CONVERTER::addLWPolyline(const DRW_LWPolyline& aData )
|
|||
*/
|
||||
void DXF2BRD_CONVERTER::addCircle( const DRW_Circle& aData )
|
||||
{
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT( m_brd );
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT;
|
||||
|
||||
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
||||
segm->SetShape( S_CIRCLE );
|
||||
|
@ -211,7 +201,7 @@ void DXF2BRD_CONVERTER::addCircle( const DRW_Circle& aData )
|
|||
wxPoint circle_start( mapX( aData.basePoint.x + aData.radious ), mapY( aData.basePoint.y ) );
|
||||
segm->SetArcStart( circle_start );
|
||||
segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
|
||||
appendToBoard( segm );
|
||||
m_newItemsList.push_back( segm );
|
||||
}
|
||||
|
||||
|
||||
|
@ -220,7 +210,7 @@ void DXF2BRD_CONVERTER::addCircle( const DRW_Circle& aData )
|
|||
*/
|
||||
void DXF2BRD_CONVERTER::addArc( const DRW_Arc& data )
|
||||
{
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT( m_brd );
|
||||
DRAWSEGMENT* segm = new DRAWSEGMENT;
|
||||
|
||||
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
||||
segm->SetShape( S_ARC );
|
||||
|
@ -249,7 +239,7 @@ void DXF2BRD_CONVERTER::addArc( const DRW_Arc& data )
|
|||
segm->SetAngle( angle );
|
||||
|
||||
segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness : data.thickness ) );
|
||||
appendToBoard( segm );
|
||||
m_newItemsList.push_back( segm );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,7 +247,7 @@ void DXF2BRD_CONVERTER::addArc( const DRW_Arc& data )
|
|||
*/
|
||||
void DXF2BRD_CONVERTER::addText( const DRW_Text& aData )
|
||||
{
|
||||
TEXTE_PCB* pcb_text = new TEXTE_PCB( m_brd );
|
||||
TEXTE_PCB* pcb_text = new TEXTE_PCB( NULL );
|
||||
pcb_text->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
||||
|
||||
wxPoint refPoint( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
|
||||
|
@ -347,7 +337,7 @@ void DXF2BRD_CONVERTER::addText( const DRW_Text& aData )
|
|||
pcb_text->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
|
||||
pcb_text->SetText( text );
|
||||
|
||||
appendToBoard( pcb_text );
|
||||
m_newItemsList.push_back( pcb_text );
|
||||
}
|
||||
|
||||
|
||||
|
@ -384,7 +374,7 @@ void DXF2BRD_CONVERTER::addMText( const DRW_MText& aData )
|
|||
text = tmp;
|
||||
}
|
||||
|
||||
TEXTE_PCB* pcb_text = new TEXTE_PCB( m_brd );
|
||||
TEXTE_PCB* pcb_text = new TEXTE_PCB( NULL );
|
||||
pcb_text->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
||||
wxPoint textpos( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
|
||||
pcb_text->SetTextPosition( textpos );
|
||||
|
@ -446,7 +436,7 @@ void DXF2BRD_CONVERTER::addMText( const DRW_MText& aData )
|
|||
}
|
||||
#endif
|
||||
|
||||
appendToBoard( pcb_text );
|
||||
m_newItemsList.push_back( pcb_text );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "drw_interface.h"
|
||||
#include "wx/wx.h"
|
||||
#include <list>
|
||||
|
||||
class BOARD;
|
||||
class BOARD_ITEM;
|
||||
|
@ -41,8 +42,7 @@ class BOARD_ITEM;
|
|||
class DXF2BRD_CONVERTER : public DRW_Interface
|
||||
{
|
||||
private:
|
||||
std::vector<BOARD_ITEM*> m_newItemsList; // The list of new items added to the board
|
||||
BOARD* m_brd;
|
||||
std::list<BOARD_ITEM*> m_newItemsList; // The list of new items added to the board
|
||||
double m_xOffset; // X coord offset for conversion (in mm)
|
||||
double m_yOffset; // Y coord offset for conversion (in mm)
|
||||
double m_defaultThickness; // default line thickness for conversion (in mm)
|
||||
|
@ -82,14 +82,13 @@ public:
|
|||
* with this filter.
|
||||
*
|
||||
* @param aFile = the full filename.
|
||||
* @param aBoard = where to store the graphical items and text
|
||||
*/
|
||||
bool ImportDxfFile( const wxString& aFile, BOARD* aBoard );
|
||||
bool ImportDxfFile( const wxString& aFile );
|
||||
|
||||
/**
|
||||
* @return the list of new BOARD_ITEM
|
||||
*/
|
||||
std::vector<BOARD_ITEM*>& GetItemsList()
|
||||
const std::list<BOARD_ITEM*>& GetItemsList() const
|
||||
{
|
||||
return m_newItemsList;
|
||||
}
|
||||
|
@ -100,11 +99,6 @@ private:
|
|||
int mapY( double aDxfCoordY );
|
||||
int mapDim( double aDxfValue );
|
||||
|
||||
// Add aItem the the board
|
||||
// this item is also added to the list of new items
|
||||
// (for undo command for instance)
|
||||
void appendToBoard( BOARD_ITEM* aItem );
|
||||
|
||||
// Methods from DRW_CreationInterface:
|
||||
// They are "call back" fonctions, called when the corresponding object
|
||||
// is read in dxf file
|
||||
|
|
|
@ -49,10 +49,11 @@ class wxSize;
|
|||
//class wxRealPoint;
|
||||
class wxString;
|
||||
|
||||
class BOARD;
|
||||
|
||||
// Often this is not used in the prototypes, since wxFrame is good enough and would
|
||||
// represent maximum information hiding.
|
||||
class PCB_EDIT_FRAME;
|
||||
class PCB_BASE_FRAME;
|
||||
class FP_LIB_TABLE;
|
||||
class BOARD;
|
||||
class PCB_PLOT_PARAMS;
|
||||
|
@ -81,13 +82,13 @@ void InvokePluginOptionsEditor( wxTopLevelWindow* aCaller, const wxString& aNick
|
|||
const wxString& aPluginType, const wxString& aOptions, wxString* aResult );
|
||||
|
||||
/**
|
||||
* Function InvokePcbLibTableEditor
|
||||
* shows the modal DIALOG_FP_LIB_TABLE for purposes of editing two lib tables.
|
||||
*
|
||||
* Function InvokeDXFDialogBoardImport
|
||||
* shows the modal DIALOG_DXF_IMPORT for importing a DXF file to a board.
|
||||
|
||||
* @param aCaller is the wxTopLevelWindow which is invoking the dialog.
|
||||
* @return true if the ilport was made.
|
||||
* @return true if the import was made.
|
||||
*/
|
||||
bool InvokeDXFDialogImport( PCB_EDIT_FRAME* aCaller );
|
||||
bool InvokeDXFDialogImport( PCB_BASE_FRAME* aCaller );
|
||||
|
||||
/**
|
||||
* Function InvokeLayerSetup
|
||||
|
|
Loading…
Reference in New Issue