From 4e39d09d1d5fe069412553b7d31011415a61d349 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 30 Oct 2013 13:14:45 +0100 Subject: [PATCH] Add undo command to dxf file import. Change improper use of __WXDEBUG__ to DEBUG in class_board_connected_item.cpp. --- pcbnew/class_board_connected_item.cpp | 6 +++--- pcbnew/import_dxf/dialog_dxf_import.cpp | 15 +++++++++++++ pcbnew/import_dxf/dxf2brd_items.cpp | 20 ++++++++++++------ pcbnew/import_dxf/dxf2brd_items.h | 28 +++++++++++++++++++------ 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/pcbnew/class_board_connected_item.cpp b/pcbnew/class_board_connected_item.cpp index a4ea8b150d..eaf793f9b7 100644 --- a/pcbnew/class_board_connected_item.cpp +++ b/pcbnew/class_board_connected_item.cpp @@ -123,7 +123,7 @@ int BOARD_CONNECTED_ITEM::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const } else { -#ifdef __WXDEBUG__ +#ifdef DEBUG wxLogWarning(wxT("BOARD_CONNECTED_ITEM::GetClearance():NULL netclass,type %d"), Type() ); #endif } @@ -148,7 +148,7 @@ NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const if( board == NULL ) // Should not occur { -#ifdef __WXDEBUG__ +#ifdef DEBUG wxLogWarning( wxT("BOARD_CONNECTED_ITEM::GetNetClass():NULL board,type %d"), Type() ); #endif return NULL; @@ -162,7 +162,7 @@ NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const { netclass = net->GetNetClass(); -#ifdef __WXDEBUG__ +#ifdef DEBUG if( netclass == NULL ) { wxLogWarning( wxT("BOARD_CONNECTED_ITEM::GetNetClass():NULL netclass,type %d"), Type() ); diff --git a/pcbnew/import_dxf/dialog_dxf_import.cpp b/pcbnew/import_dxf/dialog_dxf_import.cpp index 2b55fcc642..d3fe5e4d97 100644 --- a/pcbnew/import_dxf/dialog_dxf_import.cpp +++ b/pcbnew/import_dxf/dialog_dxf_import.cpp @@ -179,8 +179,23 @@ void DIALOG_DXF_IMPORT::OnOKClick( wxCommandEvent& event ) dxf_importer.SetOffset( offsetX, offsetY ); m_layer = m_SelLayerBox->GetLayerSelection(); dxf_importer.SetBrdLayer( m_layer ); + + // Read dxf file: dxf_importer.ImportDxfFile( m_dxfFilename, brd ); + // Prepare the undo list + std::vector& 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) ); + EndModal( wxID_OK ); } diff --git a/pcbnew/import_dxf/dxf2brd_items.cpp b/pcbnew/import_dxf/dxf2brd_items.cpp index 1b8b7df0c8..a077dde28b 100644 --- a/pcbnew/import_dxf/dxf2brd_items.cpp +++ b/pcbnew/import_dxf/dxf2brd_items.cpp @@ -106,8 +106,16 @@ bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile, BOARD* aBoard ) return true; } +// Add aItem the the board +// this item is also added to the list of new items +// (for undo command for instance) +void DXF2BRD_CONVERTER::appendToBoard( BOARD_ITEM * aItem ) +{ + m_brd->Add( aItem ); + m_newItemsList.push_back( aItem ); +} -/** +/* * Implementation of the method which handles layers. */ void DXF2BRD_CONVERTER::addLayer( const DRW_Layer& data ) @@ -134,7 +142,7 @@ void DXF2BRD_CONVERTER::addLine( const DRW_Line& data ) segm->SetEnd( end ); segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness : data.thickness ) ); - m_brd->Add( segm ); + appendToBoard( segm ); } @@ -154,7 +162,7 @@ void DXF2BRD_CONVERTER::addCircle( const DRW_Circle& data ) segm->SetEnd( circle_start ); segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness : data.thickness ) ); - m_brd->Add( segm ); + appendToBoard( segm ); } @@ -190,7 +198,7 @@ void DXF2BRD_CONVERTER::addArc( const DRW_Arc& data ) segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness : data.thickness ) ); - m_brd->Add( segm ); + appendToBoard( segm ); } /** @@ -289,7 +297,7 @@ void DXF2BRD_CONVERTER::addText(const DRW_Text& data) : data.thickness ) ); pcb_text->SetText( text ); - m_brd->Add( pcb_text ); + appendToBoard( pcb_text ); } @@ -389,7 +397,7 @@ void DXF2BRD_CONVERTER::addMText( const DRW_MText& data ) } #endif - m_brd->Add( pcb_text ); + appendToBoard( pcb_text ); } diff --git a/pcbnew/import_dxf/dxf2brd_items.h b/pcbnew/import_dxf/dxf2brd_items.h index c2316aa326..57680862c7 100644 --- a/pcbnew/import_dxf/dxf2brd_items.h +++ b/pcbnew/import_dxf/dxf2brd_items.h @@ -31,6 +31,7 @@ class dxfRW; class BOARD; +class BOARD_ITEM; /** * This format filter class can import and export DXF files. @@ -41,17 +42,19 @@ class BOARD; class DXF2BRD_CONVERTER : public DRW_Interface { private: + std::vector m_newItemsList; // The list of new items added + // to the board BOARD * m_brd; 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 dxf units) + double m_defaultThickness; // default line thickness for conversion (in mm) double m_Dfx2mm; // The scale factor to convert DXF units to mm // Seems DRW_Interface always converts DXF coordinates in mm // (to be confirmed) int m_brdLayer; // The board layer to place imported dfx items - int m_version; - std::string m_codePage; - dxfRW* m_dxf; + int m_version; // the dxf version, not used here + std::string m_codePage; // The code page, not used here + dxfRW* m_dxf; // the dxf reader public: DXF2BRD_CONVERTER(); @@ -67,8 +70,8 @@ public: */ void SetOffset( double aOffsetX, double aOffsetY ) { - m_xOffset =aOffsetX; - m_yOffset =aOffsetY; + m_xOffset = aOffsetX; + m_yOffset = aOffsetY; } /** @@ -79,12 +82,25 @@ public: bool ImportDxfFile( const wxString& aFile, BOARD * aBoard ); + /** + * @return the list of new BOARD_ITEM + */ + std::vector& GetItemsList() + { + return m_newItemsList; + } + private: // coordinate conversions from dxf to internal units int mapX( double aDxfCoordX ); 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