Commit 629c9329 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Add undo command to dxf file import. Change improper use of __WXDEBUG__ to...

Add undo command to dxf file import. Change improper use of __WXDEBUG__ to DEBUG in class_board_connected_item.cpp.
parent 416c4461
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -123,7 +123,7 @@ int BOARD_CONNECTED_ITEM::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
    }
    }
    else
    else
    {
    {
#ifdef __WXDEBUG__
#ifdef DEBUG
        wxLogWarning(wxT("BOARD_CONNECTED_ITEM::GetClearance():NULL netclass,type %d"), Type() );
        wxLogWarning(wxT("BOARD_CONNECTED_ITEM::GetClearance():NULL netclass,type %d"), Type() );
#endif
#endif
    }
    }
@@ -148,7 +148,7 @@ NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const


    if( board == NULL )     // Should not occur
    if( board == NULL )     // Should not occur
    {
    {
#ifdef __WXDEBUG__
#ifdef DEBUG
        wxLogWarning( wxT("BOARD_CONNECTED_ITEM::GetNetClass():NULL board,type %d"), Type() );
        wxLogWarning( wxT("BOARD_CONNECTED_ITEM::GetNetClass():NULL board,type %d"), Type() );
#endif
#endif
        return NULL;
        return NULL;
@@ -162,7 +162,7 @@ NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const
    {
    {
        netclass = net->GetNetClass();
        netclass = net->GetNetClass();


#ifdef __WXDEBUG__
#ifdef DEBUG
        if( netclass == NULL )
        if( netclass == NULL )
        {
        {
            wxLogWarning( wxT("BOARD_CONNECTED_ITEM::GetNetClass():NULL netclass,type %d"), Type() );
            wxLogWarning( wxT("BOARD_CONNECTED_ITEM::GetNetClass():NULL netclass,type %d"), Type() );
+15 −0
Original line number Original line Diff line number Diff line
@@ -179,8 +179,23 @@ void DIALOG_DXF_IMPORT::OnOKClick( wxCommandEvent& event )
    dxf_importer.SetOffset( offsetX, offsetY );
    dxf_importer.SetOffset( offsetX, offsetY );
    m_layer = m_SelLayerBox->GetLayerSelection();
    m_layer = m_SelLayerBox->GetLayerSelection();
    dxf_importer.SetBrdLayer( m_layer );
    dxf_importer.SetBrdLayer( m_layer );

    // Read dxf file:
    dxf_importer.ImportDxfFile( m_dxfFilename, brd );
    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) );

    EndModal( wxID_OK );
    EndModal( wxID_OK );
}
}


+14 −6
Original line number Original line Diff line number Diff line
@@ -106,8 +106,16 @@ bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile, BOARD* aBoard )
    return true;
    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.
 * Implementation of the method which handles layers.
 */
 */
void DXF2BRD_CONVERTER::addLayer( const DRW_Layer& data )
void DXF2BRD_CONVERTER::addLayer( const DRW_Layer& data )
@@ -134,7 +142,7 @@ void DXF2BRD_CONVERTER::addLine( const DRW_Line& data )
    segm->SetEnd( end );
    segm->SetEnd( end );
    segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness
    segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness
                            : data.thickness ) );
                            : 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->SetEnd( circle_start );
    segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness
    segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness
                            : data.thickness ) );
                            : 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
    segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness
                            : data.thickness ) );
                            : data.thickness ) );
    m_brd->Add( segm );
    appendToBoard( segm );
}
}


/**
/**
@@ -289,7 +297,7 @@ void DXF2BRD_CONVERTER::addText(const DRW_Text& data)
                                    : data.thickness ) );
                                    : data.thickness ) );
    pcb_text->SetText( text );
    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
#endif


    m_brd->Add( pcb_text );
    appendToBoard( pcb_text );
}
}




+22 −6
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@


class dxfRW;
class dxfRW;
class BOARD;
class BOARD;
class BOARD_ITEM;


/**
/**
 * This format filter class can import and export DXF files.
 * This format filter class can import and export DXF files.
@@ -41,17 +42,19 @@ class BOARD;
class DXF2BRD_CONVERTER : public DRW_Interface
class DXF2BRD_CONVERTER : public DRW_Interface
{
{
private:
private:
    std::vector<BOARD_ITEM*> m_newItemsList;    // The list of new items added
                                                // to the board
    BOARD * m_brd;
    BOARD * m_brd;
    double m_xOffset;       // X coord offset for conversion (in mm)
    double m_xOffset;       // X coord offset for conversion (in mm)
    double m_yOffset;       // Y 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
    double m_Dfx2mm;        // The scale factor to convert DXF units to mm
                            // Seems DRW_Interface always converts DXF coordinates in mm
                            // Seems DRW_Interface always converts DXF coordinates in mm
                            // (to be confirmed)
                            // (to be confirmed)
    int    m_brdLayer;      // The board layer to place imported dfx items
    int    m_brdLayer;      // The board layer to place imported dfx items
    int m_version;
    int m_version;          // the dxf version, not used here
    std::string m_codePage;
    std::string m_codePage; // The code page, not used here
    dxfRW* m_dxf;
    dxfRW* m_dxf;           // the dxf reader


public:
public:
    DXF2BRD_CONVERTER();
    DXF2BRD_CONVERTER();
@@ -79,12 +82,25 @@ public:


    bool ImportDxfFile(  const wxString& aFile, BOARD * aBoard );
    bool ImportDxfFile(  const wxString& aFile, BOARD * aBoard );


    /**
     * @return the list of new BOARD_ITEM
     */
    std::vector<BOARD_ITEM*>& GetItemsList()
    {
        return m_newItemsList;
    }

private:
private:
    // coordinate conversions from dxf to internal units
    // coordinate conversions from dxf to internal units
    int mapX( double aDxfCoordX );
    int mapX( double aDxfCoordX );
    int mapY( double aDxfCoordY );
    int mapY( double aDxfCoordY );
    int mapDim( double aDxfValue );
    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:
    // Methods from DRW_CreationInterface:
    // They are "call back" fonctions, called when the corresponding object
    // They are "call back" fonctions, called when the corresponding object
    // is read in dxf file
    // is read in dxf file