toolbars_gerber.cpp 10.8 KB
Newer Older
1 2 3
/*************************************/
/*  tool_gerber.cpp: Build tool bars */
/*************************************/
4 5

#include "fctsys.h"
6 7
#include "wx/wupdlock.h"

8
//#include "appl_wxstruct.h"
9
#include "common.h"
10
#include "macros.h"
11 12
#include "gerbview.h"
#include "bitmaps.h"
charras's avatar
charras committed
13
#include "gerbview_id.h"
14
#include "hotkeys.h"
15
#include "class_GERBER.h"
16

17 18

void WinEDA_GerberFrame::ReCreateHToolbar( void )
19
{
20
    int           layer = 0;
21
    GERBER*       gerber = NULL;
22 23 24 25
    int           ii;
    wxString      msg;

    // delete and recreate the toolbar
26
    if( m_HToolBar != NULL )
27 28
        return;

29 30 31 32
    // we create m_SelLayerTool that have a lot of items,
    // so create a wxWindowUpdateLocker is a good idea
    wxWindowUpdateLocker dummy(this);

33 34
    if( GetScreen() )
    {
35
        layer = GetScreen()->m_Active_Layer;
36
        gerber = g_GERBER_List[layer];
37 38 39
    }

    m_HToolBar = new WinEDA_Toolbar( TOOLBAR_MAIN, this, ID_H_TOOLBAR, TRUE );
40

41
    // Set up toolbar
42
    m_HToolBar->AddTool( ID_NEW_BOARD, wxEmptyString,
43
                         wxBitmap( new_xpm ),
44
                         _( "Erase all layers" ) );
45

charras's avatar
charras committed
46
    m_HToolBar->AddTool( wxID_FILE, wxEmptyString,
47
                         wxBitmap( open_xpm ),
48
                         _( "Load a new Gerber file on the current layer. Previous data will be deleted" ) );
49

50 51

    m_HToolBar->AddSeparator();
52

53
    m_HToolBar->AddTool( wxID_UNDO, wxEmptyString,
54
                         wxBitmap( undelete_xpm ),
55
                         _( "Undelete" ) );
56 57

    m_HToolBar->AddSeparator();
58
    m_HToolBar->AddTool( wxID_PRINT, wxEmptyString,
59
                         wxBitmap( print_button ),
60
                         _( "Print layers" ) );
61 62

    m_HToolBar->AddSeparator();
63
    msg = AddHotkeyName( _( "Zoom in" ), s_Gerbview_Hokeys_Descr, HK_ZOOM_IN );
64 65
    m_HToolBar->AddTool( ID_ZOOM_IN, wxEmptyString,
                         wxBitmap( zoom_in_xpm ),
66 67
                         msg );

68
    msg = AddHotkeyName( _( "Zoom out" ), s_Gerbview_Hokeys_Descr, HK_ZOOM_OUT );
69 70
    m_HToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString,
                         wxBitmap( zoom_out_xpm ),
71 72
                         msg );

73 74
    msg = AddHotkeyName( _( "Redraw view" ), s_Gerbview_Hokeys_Descr,
                         HK_ZOOM_REDRAW );
75 76
    m_HToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
                         wxBitmap( zoom_redraw_xpm ),
77 78
                         msg );

79 80
    msg = AddHotkeyName( _( "Zoom auto" ), s_Gerbview_Hokeys_Descr,
                         HK_ZOOM_AUTO );
81 82
    m_HToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
                         wxBitmap( zoom_auto_xpm ),
dickelbeck's avatar
dickelbeck committed
83
                         msg );
84 85

    m_HToolBar->AddSeparator();
86 87
    m_HToolBar->AddTool( ID_FIND_ITEMS, wxEmptyString,
                         wxBitmap( find_xpm ),
88
                         _( "Find D-codes" ) );
89 90 91 92 93 94 95 96 97 98

    wxArrayString choices;
    m_HToolBar->AddSeparator();
    for( ii = 0; ii < 32; ii++ )
    {
        wxString msg;
        msg = _( "Layer " ); msg << ii + 1;
        choices.Add( msg );
    }

99
    m_SelLayerBox = new WinEDAChoiceBox( m_HToolBar,
charras's avatar
charras committed
100
                                         ID_TOOLBARH_GERBVIEW_SELECT_LAYER,
101 102
                                         wxDefaultPosition, wxSize( 150, -1 ),
                                         choices );
103 104 105 106
    m_HToolBar->AddControl( m_SelLayerBox );

    m_HToolBar->AddSeparator();
    choices.Clear();
107

108
    choices.Alloc(TOOLS_MAX_COUNT+1);
109
    choices.Add( _( "No tool" ) );
110

111
    for( ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
112 113 114 115 116
    {
        wxString msg;
        msg = _( "Tool " ); msg << ii + FIRST_DCODE;
        choices.Add( msg );
    }
117 118 119 120
    m_SelLayerTool = new WinEDAChoiceBox( m_HToolBar,
                                          ID_TOOLBARH_GERBER_SELECT_TOOL,
                                          wxDefaultPosition, wxSize( 150, -1 ),
                                          choices );
121 122
    m_HToolBar->AddControl( m_SelLayerTool );

123 124 125 126
    m_TextInfo = new wxTextCtrl(m_HToolBar, wxID_ANY, wxEmptyString,
                                wxDefaultPosition, wxSize(150,-1),
                                wxTE_READONLY );
    m_HToolBar->AddControl( m_TextInfo );
127 128 129 130

    // after adding the buttons to the toolbar, must call Realize() to reflect
    // the changes
    m_HToolBar->Realize();
131 132 133
}


134
/**
135 136 137
 * Create or update the right vertical toolbar
 */
void WinEDA_GerberFrame::ReCreateVToolbar( void )
138
{
139 140
    if( m_VToolBar )
        return;
141

142 143
    wxWindowUpdateLocker dummy(this);

144
    m_VToolBar = new WinEDA_Toolbar( TOOLBAR_TOOL, this, ID_V_TOOLBAR, FALSE );
145

146
    // Set up toolbar
147
    m_VToolBar->AddTool( ID_NO_SELECT_BUTT, wxEmptyString, wxBitmap( cursor_xpm ) );
148 149
    m_VToolBar->ToggleTool( ID_NO_SELECT_BUTT, TRUE );
    m_VToolBar->AddSeparator();
charras's avatar
charras committed
150
    m_VToolBar->AddTool( ID_GERBVIEW_DELETE_ITEM_BUTT, wxEmptyString,
151 152
                         wxBitmap( delete_body_xpm ),
                         _( "Delete items" ) );
153 154

    m_VToolBar->Realize();
155 156 157
}


158
/**
159 160 161
 * Create or update the left vertical toolbar (option toolbar
 */
void WinEDA_GerberFrame::ReCreateOptToolbar( void )
162
{
163 164 165
    if( m_OptionsToolBar )
        return;

166 167
    wxWindowUpdateLocker dummy(this);

168
    // creation of tool bar options
169
    m_OptionsToolBar = new WinEDA_Toolbar( TOOLBAR_OPTION, this, ID_OPT_TOOLBAR, FALSE );
170

171
    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString,
172
                               wxBitmap( grid_xpm ),
173
                               _( "Turn grid off" ), wxITEM_CHECK );
174

175
    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLAR_COORD, wxEmptyString,
176
                               wxBitmap( polar_coord_xpm ),
177
                               _( "Turn polar coordinate on" ), wxITEM_CHECK );
178 179

    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
180
                               wxBitmap( unit_inch_xpm ),
181
                               _( "Set units to inches" ), wxITEM_CHECK );
182 183

    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
184
                               wxBitmap( unit_mm_xpm ),
185
                               _( "Set units to millimeters" ), wxITEM_CHECK );
186

187
    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
188
                               wxBitmap( cursor_shape_xpm ),
189
                               _( "Change cursor shape" ), wxITEM_CHECK );
190 191

    m_OptionsToolBar->AddSeparator();
192
    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH, wxEmptyString,
193
                               wxBitmap( pad_sketch_xpm ),
194
                               _( "Show spots in sketch mode" ), wxITEM_CHECK );
195

196
    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_LINES_SKETCH, wxEmptyString,
197
                               wxBitmap( showtrack_xpm ),
198
                               _( "Show lines in sketch mode" ), wxITEM_CHECK );
199

200
    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH, wxEmptyString,
201
                               wxBitmap( opt_show_polygon_xpm ),
202 203
                               _( "Show polygons in sketch mode" ),
                               wxITEM_CHECK );
204

205
    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_DCODES, wxEmptyString,
206
                               wxBitmap( show_dcodenumber_xpm ),
207
                               _( "Show dcode number" ), wxITEM_CHECK );
208

charras's avatar
charras committed
209 210 211
    // Tools to show/hide toolbars:
    m_OptionsToolBar->AddSeparator();
    m_OptionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
212 213 214 215
                               wxEmptyString,
                               wxBitmap( layers_manager_xpm ),
                               _( "Show/hide the layers manager toolbar" ),
                               wxITEM_CHECK );
charras's avatar
charras committed
216

217

charras's avatar
charras committed
218
    m_OptionsToolBar->Realize();
219
}
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319


/** Function SetToolbars()
 * Set the tools state for the toolbars, according to display options
 */
void WinEDA_GerberFrame::SetToolbars()
{
    PCB_SCREEN* screen = (PCB_SCREEN*) GetScreen();
    int     layer  = screen->m_Active_Layer;
    GERBER* gerber = g_GERBER_List[layer];

    if( m_HToolBar == NULL )
        return;

    if( GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE )
    {
        m_HToolBar->EnableTool( wxID_CUT, true );
        m_HToolBar->EnableTool( wxID_COPY, true );
    }
    else
    {
        m_HToolBar->EnableTool( wxID_CUT, false );
        m_HToolBar->EnableTool( wxID_COPY, false );
    }

    if(  m_SelLayerBox && (m_SelLayerBox->GetSelection() != screen->m_Active_Layer) )
    {
        m_SelLayerBox->SetSelection( screen->m_Active_Layer );
    }

    if( m_SelLayerTool )
    {
        if( gerber )
        {
            int sel_index;
            m_SelLayerTool->Enable( true );
            if( gerber->m_Selected_Tool < FIRST_DCODE )  // No tool selected
                sel_index = 0;
            else
                sel_index = gerber->m_Selected_Tool - FIRST_DCODE + 1;

            if( sel_index != m_SelLayerTool->GetSelection() )
            {
                m_SelLayerTool->SetSelection( sel_index );
            }
        }
        else
        {
            m_SelLayerTool->SetSelection( 0 );
            m_SelLayerTool->Enable( false );
        }
    }

    if( m_OptionsToolBar )
    {
        m_OptionsToolBar->ToggleTool(
            ID_TB_OPTIONS_SELECT_UNIT_MM,
            g_UserUnit ==
            MILLIMETRES ? true : false );
        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_INCH,
                                      g_UserUnit == INCHES ? true : false );

        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_POLAR_COORD,
                                      DisplayOpt.DisplayPolarCood );

        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_GRID,
                                      IsGridVisible() );

        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_CURSOR,
                                      m_CursorShape );

        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH,
                                      !m_DisplayPadFill );

        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_LINES_SKETCH,
                                      !m_DisplayPcbTrackFill );

        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH,
                                      g_DisplayPolygonsModeSketch == 0 ? 0 : 1 );

        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_DCODES,
                                      IsElementVisible( DCODES_VISIBLE ) );

        m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
                                      m_show_layer_manager_tools );
        if( m_show_layer_manager_tools )
            GetMenuBar()->SetLabel( ID_MENU_GERBVIEW_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
                                    _("Hide &Layers Manager" ) );
        else
            GetMenuBar()->SetLabel( ID_MENU_GERBVIEW_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
                                    _("Show &Layers Manager" ) );

    }

    DisplayUnitsMsg();

    if( m_auimgr.GetManagedWindow() )
        m_auimgr.Update();
}