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

Gerbview: code cleanup and very minor fix.

parent fe6890a9
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ set(GERBVIEW_SRCS
    dcode.cpp
    dummy_functions.cpp
    draw_gerber_screen.cpp
    edit.cpp
    events_called_functions.cpp
    export_to_pcbnew.cpp
    files.cpp
    gerbview.cpp
@@ -43,6 +43,7 @@ set(GERBVIEW_SRCS
    initpcb.cpp
    locate.cpp
    menubar.cpp
    onleftclick.cpp
    onrightclick.cpp
    options.cpp
    pcbplot.cpp
+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ int GERBVIEW_FRAME::ReadDCodeDefinitionFile( const wxString& D_Code_FullFileName
    wxString msg;
    D_CODE*  dcode;
    FILE*    dest;
    int      layer = GetScreen()->m_Active_Layer;
    int      layer = getActiveLayer();
    int      type_outil;

    if( g_GERBER_List[layer] == NULL )
+1 −1
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin

        int dcode_highlight = 0;

        if( layer == m_PcbFrame->GetScreen()->m_Active_Layer )
        if( layer == ((GERBVIEW_FRAME*)m_PcbFrame)->getActiveLayer() )
            dcode_highlight = gerber->m_Selected_Tool;

        int layerdrawMode = GR_COPY;
+172 −90
Original line number Diff line number Diff line
/***************************************/
/* edit.cpp: Gerbview events functions */
/***************************************/
/**********************************************************/
/* events_called_functions.cpp: Gerbview events functions */
/**********************************************************/

#include "fctsys.h"
#include "class_drawpanel.h"
@@ -10,76 +10,109 @@
#include "appl_wxstruct.h"

#include "gerbview.h"
#include "pcbplot.h"
#include "kicad_device_context.h"
#include "gerbview_id.h"
#include "class_GERBER.h"
#include "dialog_helpers.h"
#include "class_DCodeSelectionbox.h"

/* Process the command triggered by the left button of the mouse when a tool
 * is already selected.
 */
void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
{
    BOARD_ITEM* DrawStruct = GetScreen()->GetCurItem();
    wxString    msg;

    if( GetToolId() == ID_NO_TOOL_SELECTED )
    {
        if( DrawStruct && DrawStruct->m_Flags  )
        {
            msg.Printf( wxT( "GERBVIEW_FRAME::ProcessCommand err: Struct %d, m_Flags = %X" ),
                        (unsigned) DrawStruct->Type(),
                        (unsigned) DrawStruct->m_Flags );
            DisplayError( this, msg );
        }
        else
        {
            DrawStruct = Locate( aPosition, CURSEUR_OFF_GRILLE );
            GetScreen()->SetCurItem( DrawStruct );
            if( DrawStruct == NULL )
            {
                GERBER_IMAGE* gerber = g_GERBER_List[getActiveLayer() ];
                if( gerber )
                    gerber->DisplayImageInfo( );
            }
        }
    }

    switch( GetToolId() )
    {
    case ID_NO_TOOL_SELECTED:
        break;

        if( DrawStruct == NULL )
            break;
        /* TODO:
        Delete_Item( DC, (GERBER_DRAW_ITEM*) DrawStruct );
        GetScreen()->SetCurItem( NULL );
        GetScreen()->SetModify();
        */
        break;

    default:
        DisplayError( this, wxT( "GERBVIEW_FRAME::ProcessCommand error" ) );
        break;
    }
}

// Event table:

BEGIN_EVENT_TABLE( GERBVIEW_FRAME, PCB_BASE_FRAME )
EVT_CLOSE( GERBVIEW_FRAME::OnCloseWindow )
EVT_SIZE( GERBVIEW_FRAME::OnSize )

EVT_TOOL( wxID_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_INC_LAYER_AND_APPEND_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_LOAD_DRILL_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_LOAD_DCODE_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_NEW_BOARD, GERBVIEW_FRAME::Files_io )

// Menu Files:
EVT_MENU( wxID_FILE, GERBVIEW_FRAME::Files_io )
EVT_MENU( ID_MENU_INC_LAYER_AND_APPEND_FILE, GERBVIEW_FRAME::Files_io )
EVT_MENU( ID_NEW_BOARD, GERBVIEW_FRAME::Files_io )
EVT_MENU( ID_GEN_PLOT, GERBVIEW_FRAME::ToPlotter )
EVT_MENU( ID_GERBVIEW_EXPORT_TO_PCBNEW, GERBVIEW_FRAME::ExportDataInPcbnewFormat )

EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, GERBVIEW_FRAME::OnFileHistory )

EVT_MENU( ID_EXIT, GERBVIEW_FRAME::Process_Special_Functions )

// menu Preferences
EVT_MENU_RANGE( ID_PREFERENCES_HOTKEY_START, ID_PREFERENCES_HOTKEY_END,
                GERBVIEW_FRAME::Process_Config )

EVT_MENU( ID_MENU_GERBVIEW_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
          GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_MENU( ID_GERBVIEW_OPTIONS_SETUP, GERBVIEW_FRAME::InstallGerberOptionsDialog )

EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, EDA_DRAW_FRAME::SetLanguage )

// menu Postprocess
EVT_MENU( ID_GERBVIEW_SHOW_LIST_DCODES, GERBVIEW_FRAME::Process_Special_Functions )
EVT_MENU( ID_GERBVIEW_SHOW_SOURCE, GERBVIEW_FRAME::OnShowGerberSourceFile )
EVT_MENU( ID_MENU_GERBVIEW_SELECT_PREFERED_EDITOR,
          EDA_BASE_FRAME::OnSelectPreferredEditor )

// menu Miscellaneous
EVT_MENU( ID_GERBVIEW_GLOBAL_DELETE, GERBVIEW_FRAME::Process_Special_Functions )

// Menu Help
EVT_MENU( ID_GENERAL_HELP, EDA_DRAW_FRAME::GetKicadHelp )
EVT_MENU( ID_KICAD_ABOUT, EDA_DRAW_FRAME::GetKicadAbout )

EVT_TOOL( wxID_CUT, GERBVIEW_FRAME::Process_Special_Functions )
EVT_TOOL( wxID_COPY, GERBVIEW_FRAME::Process_Special_Functions )
EVT_TOOL( wxID_PASTE, GERBVIEW_FRAME::Process_Special_Functions )
EVT_TOOL( wxID_UNDO, GERBVIEW_FRAME::Process_Special_Functions )
EVT_TOOL( wxID_PRINT, GERBVIEW_FRAME::ToPrinter )
EVT_TOOL( ID_FIND_ITEMS, GERBVIEW_FRAME::Process_Special_Functions )
EVT_KICAD_CHOICEBOX( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER,
                     GERBVIEW_FRAME::OnSelectActiveLayer )

EVT_SELECT_DCODE( ID_TOOLBARH_GERBER_SELECT_TOOL,
                  GERBVIEW_FRAME::Process_Special_Functions )

// Vertical toolbar:
EVT_TOOL( ID_NO_TOOL_SELECTED, GERBVIEW_FRAME::Process_Special_Functions )

EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
                GERBVIEW_FRAME::Process_Special_Functions )

// Option toolbar
EVT_TOOL( ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH,
          GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_LINES_SKETCH, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
          GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_DCODES, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL_RANGE( ID_TB_OPTIONS_SHOW_GBR_MODE_0, ID_TB_OPTIONS_SHOW_GBR_MODE_2,
                GERBVIEW_FRAME::OnSelectDisplayMode )

EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH,
               GERBVIEW_FRAME::OnUpdateFlashedItemsDrawMode )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_LINES_SKETCH, GERBVIEW_FRAME::OnUpdateLinesDrawMode )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH,
               GERBVIEW_FRAME::OnUpdatePolygonsDrawMode )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_DCODES, GERBVIEW_FRAME::OnUpdateShowDCodes )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
               GERBVIEW_FRAME::OnUpdateShowLayerManager )

EVT_UPDATE_UI( ID_TOOLBARH_GERBER_SELECT_TOOL, GERBVIEW_FRAME::OnUpdateSelectDCode )
EVT_UPDATE_UI( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnUpdateLayerSelectBox )
EVT_UPDATE_UI_RANGE( ID_TB_OPTIONS_SHOW_GBR_MODE_0, ID_TB_OPTIONS_SHOW_GBR_MODE_2,
                     GERBVIEW_FRAME::OnUpdateDrawMode )

END_EVENT_TABLE()

/* Handles the selection of tools, menu, and popup menu commands.
 */
void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
{
    int           id = event.GetId();
    int        layer = GetScreen()->m_Active_Layer;
    GERBER_IMAGE*    gerber_layer = g_GERBER_List[layer];
    wxPoint    pos;

    wxGetMousePosition( &pos.x, &pos.y );

    pos.y += 20;
    GERBER_IMAGE* gerber_layer = g_GERBER_List[getActiveLayer()];

    switch( id )
    {
@@ -137,15 +170,6 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
    case ID_POPUP_CANCEL_CURRENT_COMMAND:
        break;

    case ID_TOOLBARH_GERBVIEW_SELECT_LAYER:
    {
        int layer = getActiveLayer( );
        setActiveLayer(event.GetSelection());
        if( layer != getActiveLayer( ) )
            DrawPanel->ReDraw( &dc, false );
    }
        break;

    case ID_TOOLBARH_GERBER_SELECT_TOOL:
        if( gerber_layer )
        {
@@ -162,22 +186,6 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
        Liste_D_Codes();
        break;

    case ID_GERBVIEW_SHOW_SOURCE:
        if( gerber_layer )
        {
            wxString editorname = wxGetApp().GetEditorName();
            if( !editorname.IsEmpty() )
            {
                wxFileName fn( gerber_layer->m_FileName );
                ExecuteFile( this, editorname, QuoteFullPath( fn ) );
            }
            else
            {
                wxMessageBox(_("No editor defined. Please select one") );
            }
        }
        break;

    case ID_POPUP_PLACE_BLOCK:
        GetScreen()->m_BlockLocate.m_Command = BLOCK_MOVE;
        DrawPanel->m_AutoPAN_Request = FALSE;
@@ -198,15 +206,89 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
        break;

    default:
        wxMessageBox( wxT( "GERBVIEW_FRAME::Process_Special_Functions error" ) );
        wxFAIL_MSG( wxT( "GERBVIEW_FRAME::Process_Special_Functions error" ) );
        break;
    }
}


/* Called on a double click of left mouse button.
/* Selects the active layer:
 *  - if a file is loaded, it is loaded in this layer
 *  _ this layer is displayed on top of other layers
 */
void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event )
{
    int layer = getActiveLayer();

    setActiveLayer( event.GetSelection() );
    if( layer != getActiveLayer() )
        DrawPanel->Refresh();
}


/* Call preferred editor to show (and edit) the gerber source file
 * loaded in the active layer
 */
void GERBVIEW_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
void GERBVIEW_FRAME::OnShowGerberSourceFile( wxCommandEvent& event )
{
    // Currently: no nothing
    int           layer = getActiveLayer();
    GERBER_IMAGE* gerber_layer = g_GERBER_List[layer];

    if( gerber_layer )
    {
        wxString editorname = wxGetApp().GetEditorName();
        if( !editorname.IsEmpty() )
        {
            wxFileName fn( gerber_layer->m_FileName );
            ExecuteFile( this, editorname, QuoteFullPath( fn ) );
        }
        else
        {
            wxMessageBox( _( "No editor defined. Please select one" ) );
        }
    }
}


/* Function OnSelectDisplayMode: called to select display mode
 * (fast display, or exact mode with stacked images or with transparency
 */
void GERBVIEW_FRAME::OnSelectDisplayMode( wxCommandEvent& event )
{
    int oldMode = GetDisplayMode();

    switch( event.GetId() )
    {
    case ID_TB_OPTIONS_SHOW_GBR_MODE_0:
        SetDisplayMode( 0 );
        break;

    case ID_TB_OPTIONS_SHOW_GBR_MODE_1:
        SetDisplayMode( 1 );
        break;

    case ID_TB_OPTIONS_SHOW_GBR_MODE_2:
        SetDisplayMode( 2 );
        break;
    }

    if( GetDisplayMode() != oldMode )
        DrawPanel->Refresh();
}


/**
 * Function SetLanguage
 * called on a language menu selection
 * Update Layer manager title and tabs texts
 */
void GERBVIEW_FRAME::SetLanguage( wxCommandEvent& event )
{
    EDA_DRAW_FRAME::SetLanguage( event );
    m_LayersManager->SetLayersManagerTabsText();
    wxAuiPaneInfo& pane_info = m_auimgr.GetPane( m_LayersManager );
    pane_info.Caption( _( "Visibles" ) );
    m_auimgr.Update();

    ReFillLayerWidget();
}
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include "gestfich.h"

#include "gerbview.h"
#include "gerbview_id.h"


/* Load a Gerber file selected from history list on current layer
Loading