pcbframe.cpp 41.1 KB
Newer Older
dickelbeck's avatar
dickelbeck committed
1
/*
2
 * This program source code file is part of KiCad, a free EDA CAD application.
dickelbeck's avatar
dickelbeck committed
3
 *
4 5 6 7
 * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2013 KiCad Developers, see change_log.txt for contributors.
dickelbeck's avatar
dickelbeck committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

27 28 29 30
/**
 * @file pcbframe.cpp
 * @brief PCB editor main window implementation.
 */
31

32 33 34 35 36 37 38 39 40 41
#include <fctsys.h>
#include <appl_wxstruct.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <wxPcbStruct.h>
#include <pcbcommon.h>      // enum PCB_VISIBLE
#include <collectors.h>
#include <build_version.h>
#include <macros.h>
#include <3d_viewer.h>
42
#include <msgpanel.h>
43
#include <fp_lib_table.h>
44

45 46 47 48 49 50 51 52 53 54 55
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <drc_stuff.h>
#include <layer_widget.h>
#include <dialog_design_rules.h>
#include <class_pcb_layer_widget.h>
#include <hotkeys.h>
#include <pcbnew_config.h>
#include <module_editor_frame.h>
#include <dialog_SVG_print.h>
#include <dialog_helpers.h>
56
#include <dialog_plot.h>
57
#include <convert_from_iu.h>
58 59
#include <view/view.h>
#include <painter.h>
60

Maciej Suminski's avatar
Maciej Suminski committed
61 62 63 64 65 66 67
#include <class_track.h>
#include <class_board.h>
#include <class_module.h>
#include <worksheet_viewitem.h>
#include <ratsnest_data.h>
#include <ratsnest_viewitem.h>

68 69
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
70

71
#if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
72 73
#include <python_scripting.h>
#endif
dickelbeck's avatar
dickelbeck committed
74

75 76
#include <class_drawpanel_gal.h>

77
// Keys used in read/write config
78
#define OPTKEY_DEFAULT_LINEWIDTH_VALUE  wxT( "PlotLineWidth_mm" )
79 80 81 82 83
#define PCB_SHOW_FULL_RATSNET_OPT       wxT( "PcbFullRatsnest" )
#define PCB_MAGNETIC_PADS_OPT           wxT( "PcbMagPadOpt" )
#define PCB_MAGNETIC_TRACKS_OPT         wxT( "PcbMagTrackOpt" )
#define SHOW_MICROWAVE_TOOLS            wxT( "ShowMicrowaveTools" )
#define SHOW_LAYER_MANAGER_TOOLS        wxT( "ShowLayerManagerTools" )
84

85

86 87 88
BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
    EVT_SOCKET( ID_EDA_SOCKET_EVENT_SERV, PCB_EDIT_FRAME::OnSockRequestServer )
    EVT_SOCKET( ID_EDA_SOCKET_EVENT, PCB_EDIT_FRAME::OnSockRequest )
89

90 91
    EVT_COMBOBOX( ID_ON_ZOOM_SELECT, PCB_EDIT_FRAME::OnSelectZoom )
    EVT_COMBOBOX( ID_ON_GRID_SELECT, PCB_EDIT_FRAME::OnSelectGrid )
92

93 94
    EVT_CLOSE( PCB_EDIT_FRAME::OnCloseWindow )
    EVT_SIZE( PCB_EDIT_FRAME::OnSize )
95

96
    EVT_TOOL( ID_LOAD_FILE, PCB_EDIT_FRAME::Files_io )
97 98
    EVT_TOOL( ID_MENU_READ_BOARD_BACKUP_FILE, PCB_EDIT_FRAME::Files_io )
    EVT_TOOL( ID_MENU_RECOVER_BOARD_AUTOSAVE, PCB_EDIT_FRAME::Files_io )
99 100 101
    EVT_TOOL( ID_NEW_BOARD, PCB_EDIT_FRAME::Files_io )
    EVT_TOOL( ID_SAVE_BOARD, PCB_EDIT_FRAME::Files_io )
    EVT_TOOL( ID_OPEN_MODULE_EDITOR, PCB_EDIT_FRAME::Process_Special_Functions )
102
    EVT_TOOL( ID_OPEN_MODULE_VIEWER, PCB_EDIT_FRAME::Process_Special_Functions )
103 104

    // Menu Files:
105
    EVT_MENU( ID_MAIN_MENUBAR, PCB_EDIT_FRAME::Process_Special_Functions )
106

107 108 109
    EVT_MENU( ID_APPEND_FILE, PCB_EDIT_FRAME::Files_io )
    EVT_MENU( ID_SAVE_BOARD_AS, PCB_EDIT_FRAME::Files_io )
    EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, PCB_EDIT_FRAME::OnFileHistory )
110

111
    EVT_MENU( ID_GEN_PLOT, PCB_EDIT_FRAME::ToPlotter )
112

113 114
    EVT_MENU( ID_GEN_EXPORT_SPECCTRA, PCB_EDIT_FRAME::ExportToSpecctra )
    EVT_MENU( ID_GEN_EXPORT_FILE_GENCADFORMAT, PCB_EDIT_FRAME::ExportToGenCAD )
115
    EVT_MENU( ID_GEN_EXPORT_FILE_MODULE_REPORT, PCB_EDIT_FRAME::GenFootprintsReport )
116
    EVT_MENU( ID_GEN_EXPORT_FILE_VRML, PCB_EDIT_FRAME::OnExportVRML )
117
    EVT_MENU( ID_GEN_EXPORT_FILE_IDF3, PCB_EDIT_FRAME::ExportToIDF3 )
118

119 120
    EVT_MENU( ID_GEN_IMPORT_SPECCTRA_SESSION,PCB_EDIT_FRAME::ImportSpecctraSession )
    EVT_MENU( ID_GEN_IMPORT_SPECCTRA_DESIGN, PCB_EDIT_FRAME::ImportSpecctraDesign )
121
    EVT_MENU( ID_GEN_IMPORT_DXF_FILE, PCB_EDIT_FRAME::Process_Special_Functions )
122

123 124
    EVT_MENU( ID_MENU_ARCHIVE_NEW_MODULES, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_MENU( ID_MENU_ARCHIVE_ALL_MODULES, PCB_EDIT_FRAME::Process_Special_Functions )
125

126
    EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit )
127 128

    // menu Config
129 130

    /* Tom's hacks start */
Maciej Suminski's avatar
Maciej Suminski committed
131
    EVT_MENU ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand )
132
    EVT_TOOL ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand )
133
    /* Tom's hacks end */
134

135
    EVT_MENU( ID_PCB_DRAWINGS_WIDTHS_SETUP, PCB_EDIT_FRAME::OnConfigurePcbOptions )
136
    EVT_MENU( ID_PCB_LIB_TABLE_EDIT, PCB_EDIT_FRAME::Process_Config )
137 138 139 140 141
    EVT_MENU( ID_CONFIG_SAVE, PCB_EDIT_FRAME::Process_Config )
    EVT_MENU( ID_CONFIG_READ, PCB_EDIT_FRAME::Process_Config )
    EVT_MENU_RANGE( ID_PREFERENCES_HOTKEY_START, ID_PREFERENCES_HOTKEY_END,
                    PCB_EDIT_FRAME::Process_Config )
    EVT_MENU( ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG, PCB_EDIT_FRAME::Process_Config )
142
    EVT_MENU( wxID_PREFERENCES, PCB_EDIT_FRAME::Process_Config )
143 144 145 146 147
    EVT_MENU( ID_PCB_LAYERS_SETUP, PCB_EDIT_FRAME::Process_Config )
    EVT_MENU( ID_PCB_MASK_CLEARANCE, PCB_EDIT_FRAME::Process_Config )
    EVT_MENU( ID_PCB_PAD_SETUP, PCB_EDIT_FRAME::Process_Config )
    EVT_MENU( ID_CONFIG_SAVE, PCB_EDIT_FRAME::Process_Config )
    EVT_MENU( ID_CONFIG_READ, PCB_EDIT_FRAME::Process_Config )
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
148 149
    EVT_MENU( ID_PREFRENCES_MACROS_SAVE, PCB_EDIT_FRAME::Process_Config )
    EVT_MENU( ID_PREFRENCES_MACROS_READ, PCB_EDIT_FRAME::Process_Config )
150 151 152 153
    EVT_MENU( ID_PCB_DISPLAY_OPTIONS_SETUP, PCB_EDIT_FRAME::InstallDisplayOptionsDialog )
    EVT_MENU( ID_PCB_USER_GRID_SETUP, PCB_EDIT_FRAME::Process_Special_Functions )

    EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, PCB_EDIT_FRAME::SetLanguage )
154 155

    // menu Postprocess
156
    EVT_MENU( ID_PCB_GEN_POS_MODULES_FILE, PCB_EDIT_FRAME::GenFootprintsPositionFile )
157
    EVT_MENU( ID_PCB_GEN_DRILL_FILE, PCB_EDIT_FRAME::InstallDrillFrame )
158
    EVT_MENU( ID_PCB_GEN_D356_FILE, PCB_EDIT_FRAME::GenD356File )
159 160
    EVT_MENU( ID_PCB_GEN_CMP_FILE, PCB_EDIT_FRAME::RecreateCmpFileFromBoard )
    EVT_MENU( ID_PCB_GEN_BOM_FILE_FROM_BOARD, PCB_EDIT_FRAME::RecreateBOMFileFromBoard )
161 162

    // menu Miscellaneous
163 164 165 166
    EVT_MENU( ID_MENU_LIST_NETS, PCB_EDIT_FRAME::ListNetsAndSelect )
    EVT_MENU( ID_PCB_GLOBAL_DELETE, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_MENU( ID_MENU_PCB_CLEAN, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_MENU( ID_MENU_PCB_SWAP_LAYERS, PCB_EDIT_FRAME::Process_Special_Functions )
167 168
    EVT_MENU( ID_MENU_PCB_RESET_TEXTMODULE_FIELDS_SIZES,
              PCB_EDIT_FRAME::OnResetModuleTextSizes )
169 170

    // Menu Help
171
    EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
172
    EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
173
    EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
174 175

    // Menu 3D Frame
176
    EVT_MENU( ID_MENU_PCB_SHOW_3D_FRAME, PCB_EDIT_FRAME::Show3D_Frame )
177

178
    // Switching canvases
179 180 181
    EVT_MENU( ID_MENU_CANVAS_DEFAULT,           PCB_EDIT_FRAME::SwitchCanvas )
    EVT_MENU( ID_MENU_CANVAS_CAIRO,             PCB_EDIT_FRAME::SwitchCanvas )
    EVT_MENU( ID_MENU_CANVAS_OPENGL,            PCB_EDIT_FRAME::SwitchCanvas )
182

183
    // Menu Get Design Rules Editor
184
    EVT_MENU( ID_MENU_PCB_SHOW_DESIGN_RULES_DIALOG, PCB_EDIT_FRAME::ShowDesignRulesEditor )
185 186

    // Horizontal toolbar
187
    EVT_TOOL( ID_TO_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions )
188
    EVT_TOOL( ID_SHEET_SET, EDA_DRAW_FRAME::Process_PageSettings )
189 190 191 192 193 194 195 196 197 198 199 200 201
    EVT_TOOL( wxID_CUT, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( wxID_COPY, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( wxID_PASTE, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( wxID_UNDO, PCB_EDIT_FRAME::GetBoardFromUndoList )
    EVT_TOOL( wxID_REDO, PCB_EDIT_FRAME::GetBoardFromRedoList )
    EVT_TOOL( wxID_PRINT, PCB_EDIT_FRAME::ToPrinter )
    EVT_TOOL( ID_GEN_PLOT_SVG, PCB_EDIT_FRAME::SVG_Print )
    EVT_TOOL( ID_GEN_PLOT, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( ID_FIND_ITEMS, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( ID_GET_NETLIST, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( ID_DRC_CONTROL, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_TOOL( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
202 203 204
    EVT_COMBOBOX( ID_TOOLBARH_PCB_SELECT_LAYER, PCB_EDIT_FRAME::Process_Special_Functions )
    EVT_COMBOBOX( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
    EVT_COMBOBOX( ID_AUX_TOOLBAR_PCB_VIA_SIZE, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
205 206
    EVT_TOOL( ID_TOOLBARH_PCB_MODE_MODULE, PCB_EDIT_FRAME::OnSelectAutoPlaceMode )
    EVT_TOOL( ID_TOOLBARH_PCB_MODE_TRACKS, PCB_EDIT_FRAME::OnSelectAutoPlaceMode )
207
    EVT_TOOL( ID_TOOLBARH_PCB_FREEROUTE_ACCESS, PCB_EDIT_FRAME::Access_to_External_Tool )
208
#ifdef KICAD_SCRIPTING_WXPYTHON
209 210
    EVT_TOOL( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, PCB_EDIT_FRAME::ScriptingConsoleEnableDisable )
#endif
211
    // Option toolbar
212
    EVT_TOOL( ID_TB_OPTIONS_DRC_OFF,
213
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
    EVT_TOOL( ID_TB_OPTIONS_SHOW_RATSNEST,
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )
    EVT_TOOL( ID_TB_OPTIONS_SHOW_MODULE_RATSNEST,
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )
    EVT_TOOL( ID_TB_OPTIONS_AUTO_DEL_TRACK,
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )
    EVT_TOOL( ID_TB_OPTIONS_SHOW_VIAS_SKETCH,
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )
    EVT_TOOL( ID_TB_OPTIONS_SHOW_TRACKS_SKETCH,
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )
    EVT_TOOL( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE,
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )
    EVT_TOOL( ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE,
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )

229
    EVT_TOOL_RANGE( ID_TB_OPTIONS_SHOW_ZONES, ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY,
230
                    PCB_EDIT_FRAME::OnSelectOptionToolbar )
231

232
    EVT_TOOL( ID_TB_OPTIONS_SHOW_MANAGE_LAYERS_VERTICAL_TOOLBAR,
233
              PCB_EDIT_FRAME::OnSelectOptionToolbar )
234

235
    // Vertical main toolbar:
236
    EVT_TOOL( ID_NO_TOOL_SELECTED, PCB_EDIT_FRAME::OnSelectTool )
237
    EVT_TOOL_RANGE( ID_PCB_HIGHLIGHT_BUTT, ID_PCB_PLACE_GRID_COORD_BUTT,
238
                    PCB_EDIT_FRAME::OnSelectTool )
239 240

    EVT_TOOL_RANGE( ID_PCB_MUWAVE_START_CMD, ID_PCB_MUWAVE_END_CMD,
241
                    PCB_EDIT_FRAME::ProcessMuWaveFunctions )
242 243

    EVT_MENU_RANGE( ID_POPUP_PCB_AUTOPLACE_START_RANGE, ID_POPUP_PCB_AUTOPLACE_END_RANGE,
244
                    PCB_EDIT_FRAME::OnPlaceOrRouteFootprints )
245

246
    EVT_MENU( ID_POPUP_PCB_REORIENT_ALL_MODULES, PCB_EDIT_FRAME::OnOrientFootprints )
247

248
    EVT_MENU_RANGE( ID_POPUP_PCB_START_RANGE, ID_POPUP_PCB_END_RANGE,
249
                    PCB_EDIT_FRAME::Process_Special_Functions )
250 251 252 253

    // Tracks and vias sizes general options
    EVT_MENU_RANGE( ID_POPUP_PCB_SELECT_WIDTH_START_RANGE,
                    ID_POPUP_PCB_SELECT_WIDTH_END_RANGE,
254
                    PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
255 256

    // popup menus
257
    EVT_MENU( ID_POPUP_PCB_DELETE_TRACKSEG, PCB_EDIT_FRAME::Process_Special_Functions )
258
    EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
259
                    PCB_EDIT_FRAME::Process_Special_Functions )
260

261
    // User interface update event handlers.
262 263 264 265 266
    EVT_UPDATE_UI( ID_SAVE_BOARD, PCB_EDIT_FRAME::OnUpdateSave )
    EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, PCB_EDIT_FRAME::OnUpdateLayerPair )
    EVT_UPDATE_UI( ID_TOOLBARH_PCB_SELECT_LAYER, PCB_EDIT_FRAME::OnUpdateLayerSelectBox )
    EVT_UPDATE_UI( ID_TB_OPTIONS_DRC_OFF, PCB_EDIT_FRAME::OnUpdateDrcEnable )
    EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_RATSNEST, PCB_EDIT_FRAME::OnUpdateShowBoardRatsnest )
267
    EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_MODULE_RATSNEST, PCB_EDIT_FRAME::OnUpdateShowModuleRatsnest )
268 269 270
    EVT_UPDATE_UI( ID_TB_OPTIONS_AUTO_DEL_TRACK, PCB_EDIT_FRAME::OnUpdateAutoDeleteTrack )
    EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_VIAS_SKETCH, PCB_EDIT_FRAME::OnUpdateViaDrawMode )
    EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_TRACKS_SKETCH, PCB_EDIT_FRAME::OnUpdateTraceDrawMode )
271
    EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE,
272
                   PCB_EDIT_FRAME::OnUpdateHighContrastDisplayMode )
273
    EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_MANAGE_LAYERS_VERTICAL_TOOLBAR,
274
                   PCB_EDIT_FRAME::OnUpdateShowLayerManager )
275
    EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE,
276
                   PCB_EDIT_FRAME::OnUpdateShowMicrowaveToolbar )
277 278 279 280 281 282
    EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, PCB_EDIT_FRAME::OnUpdateVerticalToolbar )
    EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
    EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH,
                   PCB_EDIT_FRAME::OnUpdateSelectAutoTrackWidth )
    EVT_UPDATE_UI( ID_POPUP_PCB_SELECT_AUTO_WIDTH, PCB_EDIT_FRAME::OnUpdateSelectAutoTrackWidth )
    EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_VIA_SIZE, PCB_EDIT_FRAME::OnUpdateSelectViaSize )
283 284
    EVT_UPDATE_UI( ID_TOOLBARH_PCB_MODE_MODULE, PCB_EDIT_FRAME::OnUpdateAutoPlaceModulesMode )
    EVT_UPDATE_UI( ID_TOOLBARH_PCB_MODE_TRACKS, PCB_EDIT_FRAME::OnUpdateAutoPlaceTracksMode )
285 286 287 288
    EVT_UPDATE_UI_RANGE( ID_POPUP_PCB_SELECT_WIDTH1, ID_POPUP_PCB_SELECT_WIDTH8,
                         PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
    EVT_UPDATE_UI_RANGE( ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_VIASIZE8,
                         PCB_EDIT_FRAME::OnUpdateSelectViaSize )
289
    EVT_UPDATE_UI_RANGE( ID_PCB_HIGHLIGHT_BUTT, ID_PCB_PLACE_GRID_COORD_BUTT,
290
                         PCB_EDIT_FRAME::OnUpdateVerticalToolbar )
291
    EVT_UPDATE_UI_RANGE( ID_TB_OPTIONS_SHOW_ZONES, ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY,
292
                         PCB_EDIT_FRAME::OnUpdateZoneDisplayStyle )
293
END_EVENT_TABLE()
294 295 296 297


///////****************************///////////:

298
#define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" )
299

300 301 302
PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
                                const wxPoint& pos, const wxSize& size,
                                long style ) :
303 304
    PCB_BASE_FRAME( parent, PCB_FRAME_TYPE, title, pos, size,
                    style, PCB_EDIT_FRAME_NAME )
305
{
306
    m_FrameName = PCB_EDIT_FRAME_NAME;
307 308 309 310 311
    m_showBorderAndTitleBlock = true;   // true to display sheet references
    m_showAxis = false;                 // true to display X and Y axis
    m_showOriginAxis = true;
    m_showGridAxis = true;
    m_SelTrackWidthBox = NULL;
charras's avatar
charras committed
312
    m_SelViaSizeBox = NULL;
313
    m_SelLayerBox = NULL;
314
    m_show_microwave_tools = false;
315
    m_show_layer_manager_tools = true;
316
    m_HotkeysZoomAndGridList = g_Board_Editor_Hokeys_Descr;
317
    m_hasAutoSave = true;
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
318
    m_RecordingMacros = -1;
319
    m_microWaveToolBar = NULL;
320
    m_useCmpFileForFpNames = true;
321

322 323
    m_footprintLibTable = NULL;
    m_globalFootprintTable = NULL;
324
    m_rotationAngle = 900;
325

326
#ifdef KICAD_SCRIPTING_WXPYTHON
327 328
    m_pythonPanel = NULL;
#endif
329

Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
330 331 332
    for ( int i = 0; i < 10; i++ )
        m_Macros[i].m_Record.clear();

Dick Hollenbeck's avatar
Dick Hollenbeck committed
333
    SetBoard( new BOARD() );
334

dickelbeck's avatar
dickelbeck committed
335 336 337 338 339 340 341 342 343 344 345
    // Create the PCB_LAYER_WIDGET *after* SetBoard():

    wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
    int pointSize = font.GetPointSize();
    int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );

    // printf( "pointSize:%d  80%%:%d\n", pointSize, (pointSize*8)/10 );

    if( screenHeight <= 900 )
        pointSize = (pointSize * 8) / 10;

346
    m_Layers = new PCB_LAYER_WIDGET( this, GetCanvas(), pointSize );
dickelbeck's avatar
dickelbeck committed
347

348 349
    m_drc = new DRC( this );        // these 2 objects point to each other

350 351 352
    wxIcon  icon;
    icon.CopyFromBitmap( KiBitmap( icon_pcbnew_xpm ) );
    SetIcon( icon );
353

354 355 356 357
    SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );

    // PCB drawings start in the upper left corner.
    GetScreen()->m_Center = false;
charras's avatar
charras committed
358 359 360

    // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
    // initialize parameters in m_LayersManager
361
    LoadSettings();
362 363 364 365 366 367 368 369 370 371

    // Be sure options are updated
    m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill;
    m_DisplayPadFill = DisplayOpt.DisplayPadFill;
    m_DisplayViaFill = DisplayOpt.DisplayViaFill;
    m_DisplayPadNum  = DisplayOpt.DisplayPadNum;

    m_DisplayModEdge = DisplayOpt.DisplayModEdge;
    m_DisplayModText = DisplayOpt.DisplayModText;

372 373
    SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );

374
    GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER );
375
    GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId  );
376

377
    if( m_canvas )
378
        m_canvas->SetEnableBlockCommands( true );
379

380 381 382 383 384
    ReCreateMenuBar();
    ReCreateHToolbar();
    ReCreateAuxiliaryToolbar();
    ReCreateVToolbar();
    ReCreateOptToolbar();
385

386
    ReCreateMicrowaveVToolbar();
387

388
    m_auimgr.SetManagedWindow( this );
389

390 391 392 393 394 395 396 397
    EDA_PANEINFO horiz;
    horiz.HorizontalToolbarPane();

    EDA_PANEINFO vert;
    vert.VerticalToolbarPane();

    EDA_PANEINFO mesg;
    mesg.MessageToolbarPane();
398

399
    // Create a wxAuiPaneInfo for the Layers Manager, not derived from the template.
400
    // LAYER_WIDGET is floatable, but initially docked at far right
401 402
    EDA_PANEINFO   lyrs;
    lyrs.LayersToolbarPane();
403 404
    lyrs.MinSize( m_Layers->GetBestSize() );    // updated in ReFillLayerWidget
    lyrs.BestSize( m_Layers->GetBestSize() );
405
    lyrs.Caption( _( "Visibles" ) );
406 407


408
    if( m_mainToolBar )    // The main horizontal toolbar
409
    {
410 411
        m_auimgr.AddPane( m_mainToolBar,
                          wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) );
412
    }
413

414
    if( m_auxiliaryToolBar )    // the auxiliary horizontal toolbar, that shows track and via sizes, zoom ...)
415
    {
416 417
        m_auimgr.AddPane( m_auxiliaryToolBar,
                          wxAuiPaneInfo( horiz ).Name( wxT( "m_auxiliaryToolBar" ) ).Top().Row( 1 ) );
418
    }
419

420 421 422
    if( m_microWaveToolBar )    // The auxiliary vertical right toolbar (currently microwave tools)
        m_auimgr.AddPane( m_microWaveToolBar,
                          wxAuiPaneInfo( vert ).Name( wxT( "m_microWaveToolBar" ) ).Right().Layer( 1 ).Position(1).Hide() );
423

424 425
    if( m_drawToolBar )    // The main right vertical toolbar
        m_auimgr.AddPane( m_drawToolBar,
426
                          wxAuiPaneInfo( vert ).Name( wxT( "m_VToolBar" ) ).Right().Layer( 2 ) );
427

428 429
    // Add the layer manager ( most right side of pcbframe )
    m_auimgr.AddPane( m_Layers, lyrs.Name( wxT( "m_LayersManagerToolBar" ) ).Right().Layer( 3 ) );
430

431
    if( m_optionsToolBar )    // The left vertical toolbar (fast acces display options of Pcbnew)
432
    {
433 434
        m_auimgr.AddPane( m_optionsToolBar,
                          wxAuiPaneInfo( vert ).Name( wxT( "m_optionsToolBar" ) ).Left().Layer(1) );
435

436
        m_auimgr.GetPane( wxT( "m_LayersManagerToolBar" ) ).Show( m_show_layer_manager_tools );
437
        m_auimgr.GetPane( wxT( "m_microWaveToolBar" ) ).Show( m_show_microwave_tools );
438
    }
439

440 441
    if( m_canvas )
        m_auimgr.AddPane( m_canvas,
442
                          wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() );
443

444 445
    if( GetGalCanvas() )
        m_auimgr.AddPane( (wxWindow*) GetGalCanvas(),
446 447
                          wxAuiPaneInfo().Name( wxT( "DrawFrameGal" ) ).CentrePane().Hide() );

448 449
    if( m_messagePanel )
        m_auimgr.AddPane( m_messagePanel,
450
                          wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) );
451

452

453
#ifdef KICAD_SCRIPTING_WXPYTHON
454 455 456 457 458 459
    // Add the scripting panel
    EDA_PANEINFO  pythonAuiInfo;
    pythonAuiInfo.ScriptingToolbarPane();
    pythonAuiInfo.Caption( wxT( "Python Scripting" ) );
    pythonAuiInfo.MinSize( wxSize( 200, 100 ) );
    pythonAuiInfo.BestSize( wxSize( GetClientSize().x/2, 200 ) );
460
    pythonAuiInfo.Hide();
461

462 463
    m_pythonPanel = CreatePythonShellWindow( this );
    m_auimgr.AddPane( m_pythonPanel,
464
                      pythonAuiInfo.Name( wxT( "PythonPanel" ) ).Bottom().Layer(9) );
465

466
    m_pythonPanelHidden = true;
467
#endif
468

469
    ReFillLayerWidget();        // this is near end because contents establish size
Dick Hollenbeck's avatar
Dick Hollenbeck committed
470

471
    m_Layers->ReFillRender();   // Update colors in Render after the config is read
Dick Hollenbeck's avatar
Dick Hollenbeck committed
472 473 474

    syncLayerWidgetLayer();

475
    m_auimgr.Update();
476 477 478 479 480 481

    if( m_globalFootprintTable == NULL )
    {
        try
        {
            m_globalFootprintTable = new FP_LIB_TABLE();
482 483 484 485 486 487 488 489 490 491 492 493 494

            if( !FP_LIB_TABLE::LoadGlobalTable( *m_globalFootprintTable ) )
            {
                DisplayInfoMessage( this, wxT( "You have run Pcbnew for the first time using the "
                                               "new footprint library table method for finding "
                                               "footprints.  Pcbnew has either copied the default "
                                               "table or created an empty table in your home "
                                               "folder.  You must first configure the library "
                                               "table to include all footprint libraries not "
                                               "included with KiCad.  See the \"Footprint Library "
                                               "Table\" section of the CvPcb documentation for "
                                               "more information." ) );
            }
495 496 497 498 499 500 501 502 503 504
        }
        catch( IO_ERROR ioe )
        {
            wxString msg;
            msg.Printf( _( "An error occurred attempting to load the global footprint library "
                           "table:\n\n%s" ), GetChars( ioe.errorText ) );
            DisplayError( this, msg );
        }
    }

505
    setupTools();
506 507
}

508

509
PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
510
{
511
    destroyTools();
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
512
    m_RecordingMacros = -1;
513

Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
514 515 516
    for( int i = 0; i < 10; i++ )
        m_Macros[i].m_Record.clear();

517
    delete m_drc;
518

519
    delete m_footprintLibTable;
520
    delete m_globalFootprintTable;
521 522
}

523

Maciej Suminski's avatar
Maciej Suminski committed
524 525 526 527
void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard )
{
    PCB_BASE_FRAME::SetBoard( aBoard );

528
    if( GetGalCanvas() )
Maciej Suminski's avatar
Maciej Suminski committed
529 530 531 532 533
    {
        ViewReloadBoard( aBoard );

        // update the tool manager with the new board and its view.
        if( m_toolManager )
534
        {
535 536
            m_toolManager->SetEnvironment( aBoard, GetGalCanvas()->GetView(),
                                           GetGalCanvas()->GetViewControls(), this );
537 538
            m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
        }
Maciej Suminski's avatar
Maciej Suminski committed
539 540 541 542 543 544
    }
}


void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const
{
545
    KIGFX::VIEW* view = GetGalCanvas()->GetView();
Maciej Suminski's avatar
Maciej Suminski committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
    view->Clear();

    // All of PCB drawing elements should be added to the VIEW
    // in order to be displayed

    // Load zones
    for( int i = 0; i < aBoard->GetAreaCount(); ++i )
    {
        view->Add( (KIGFX::VIEW_ITEM*) ( aBoard->GetArea( i ) ) );
    }

    // Load drawings
    for( BOARD_ITEM* drawing = aBoard->m_Drawings; drawing; drawing = drawing->Next() )
    {
        view->Add( drawing );
    }

    // Load tracks
    for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
    {
        view->Add( track );
    }

    // Load modules and its additional elements
    for( MODULE* module = aBoard->m_Modules; module; module = module->Next() )
    {
        // Load module's pads
        for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
        {
            view->Add( pad );
        }

        // Load module's drawing (mostly silkscreen)
        for( BOARD_ITEM* drawing = module->GraphicalItems().GetFirst(); drawing;
             drawing = drawing->Next() )
        {
            view->Add( drawing );
        }

        // Load module's texts (name and value)
        view->Add( &module->Reference() );
        view->Add( &module->Value() );

        // Add the module itself
        view->Add( module );
    }

    // Segzones (equivalent of ZONE_CONTAINER for legacy boards)
    for( SEGZONE* zone = aBoard->m_Zone; zone; zone = zone->Next() )
    {
        view->Add( zone );
    }

    // Add an entry for the worksheet layout
    KIGFX::WORKSHEET_VIEWITEM* worksheet = new KIGFX::WORKSHEET_VIEWITEM(
                                            std::string( aBoard->GetFileName().mb_str() ),
                                            std::string( GetScreenDesc().mb_str() ),
                                            &GetPageSettings(), &GetTitleBlock() );
    BASE_SCREEN* screen = GetScreen();
    if( screen != NULL )
    {
        worksheet->SetSheetNumber( GetScreen()->m_ScreenNumber );
        worksheet->SetSheetCount( GetScreen()->m_NumberOfScreens );
    }

    view->Add( worksheet );

    // Add an entry for the ratsnest
    RN_DATA* ratsnest = aBoard->GetRatsnest();
    ratsnest->Recalculate();
    view->Add( new KIGFX::RATSNEST_VIEWITEM( ratsnest ) );

    view->SetPanBoundary( worksheet->ViewBBox() );
    view->RecacheAllItems( true );

621 622
    if( IsGalCanvasActive() )
        GetGalCanvas()->Refresh();
Maciej Suminski's avatar
Maciej Suminski committed
623 624 625
}


626
bool PCB_EDIT_FRAME::isAutoSaveRequired() const
627
{
628
    return GetScreen()->IsSave();
629 630 631
}


632
void PCB_EDIT_FRAME::ReFillLayerWidget()
633
{
dickelbeck's avatar
dickelbeck committed
634
    m_Layers->ReFill();
635 636 637 638 639 640 641 642 643 644 645 646 647

    wxAuiPaneInfo& lyrs = m_auimgr.GetPane( m_Layers );

    wxSize bestz = m_Layers->GetBestSize();

    lyrs.MinSize( bestz );
    lyrs.BestSize( bestz );
    lyrs.FloatingSize( bestz );

    if( lyrs.IsDocked() )
        m_auimgr.Update();
    else
        m_Layers->SetSize( bestz );
648 649 650
}


651
void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event )
652
{
653
    Close( true );
654
}
655

656

657
void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
658
{
659
    m_canvas->SetAbortRequest( true );
660
    GetGalCanvas()->StopDrawing();
661

662
    if( GetScreen()->IsModify() )
663
    {
664 665
        wxString msg;
        msg.Printf( _("Save the changes in\n<%s>\nbefore closing?"),
666
                    GetChars( GetBoard()->GetFileName() ) );
667

668
        int ii = DisplayExitDialog( this, msg );
669 670 671 672 673 674 675 676 677 678
        switch( ii )
        {
        case wxID_CANCEL:
            Event.Veto();
            return;

        case wxID_NO:
            break;

        case wxID_YES:
679
            SavePcbFile( GetBoard()->GetFileName() );
680 681 682 683
            break;
        }
    }

684
    // Delete the auto save file if it exists.
685
    wxFileName fn = GetBoard()->GetFileName();
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700

    // Auto save file name is the normal file name prefixed with a '$'.
    fn.SetName( wxT( "$" ) + fn.GetName() );

    // Remove the auto save file on a normal close of Pcbnew.
    if( fn.FileExists() && !wxRemoveFile( fn.GetFullPath() ) )
    {
        wxString msg;

        msg.Printf( _( "The auto save file <%s> could not be removed!" ),
                    GetChars( fn.GetFullPath() ) );

        wxMessageBox( msg, wxGetApp().GetAppName(), wxOK | wxICON_ERROR, this );
    }

701 702 703 704
    // Delete board structs and undo/redo lists, to avoid crash on exit
    // when deleting some structs (mainly in undo/redo lists) too late
    Clear_Pcb( false );

705 706
    // do not show the window because ScreenPcb will be deleted and we do not
    // want any paint event
charras's avatar
charras committed
707
    Show( false );
708

709
    Destroy();
710 711 712
}


713
void PCB_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event )
714 715 716
{
    if( m_Draw3DFrame )
    {
717 718 719 720
        // Raising the window does not show the window on Windows if iconized.
        // This should work on any platform.
        if( m_Draw3DFrame->IsIconized() )
             m_Draw3DFrame->Iconize( false );
721

722 723 724 725 726 727
        m_Draw3DFrame->Raise();

        // Raising the window does not set the focus on Linux.  This should work on any platform.
        if( wxWindow::FindFocus() != m_Draw3DFrame )
            m_Draw3DFrame->SetFocus();

728 729 730
        return;
    }

731
    m_Draw3DFrame = new EDA_3D_FRAME( this, _( "3D Viewer" ) );
732
    m_Draw3DFrame->SetDefaultFileName( GetBoard()->GetFileName() );
733
    m_Draw3DFrame->Show( true );
734
}
735

charras's avatar
charras committed
736

Maciej Suminski's avatar
Maciej Suminski committed
737 738 739 740 741
void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable )
{
    EDA_DRAW_FRAME::UseGalCanvas( aEnable );

    ViewReloadBoard( m_Pcb );
742 743 744

    if( aEnable )
    {
745 746 747
        // Update potential changes in the ratsnest
        m_Pcb->GetRatsnest()->Recalculate();

748 749 750 751
        m_toolManager->SetEnvironment( m_Pcb, GetGalCanvas()->GetView(),
                                       GetGalCanvas()->GetViewControls(), this );
        m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
    }
Maciej Suminski's avatar
Maciej Suminski committed
752 753 754
}


755 756 757 758 759 760 761 762 763 764 765
void PCB_EDIT_FRAME::SwitchCanvas( wxCommandEvent& aEvent )
{
    int id = aEvent.GetId();

    switch( id )
    {
    case ID_MENU_CANVAS_DEFAULT:
        UseGalCanvas( false );
        break;

    case ID_MENU_CANVAS_CAIRO:
766
        GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO );
767 768 769 770
        UseGalCanvas( true );
        break;

    case ID_MENU_CANVAS_OPENGL:
771
        GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
772 773 774 775 776 777
        UseGalCanvas( true );
        break;
    }
}


778
void PCB_EDIT_FRAME::ShowDesignRulesEditor( wxCommandEvent& event )
779 780
{
    DIALOG_DESIGN_RULES dR_editor( this );
charras's avatar
charras committed
781 782 783
    int returncode = dR_editor.ShowModal();

    if( returncode == wxID_OK )     // New rules, or others changes.
784
    {
785
        ReCreateLayerBox();
786 787
        updateTraceWidthSelectBox();
        updateViaSizeSelectBox();
788
        OnModify();
789 790
    }
}
791 792


793
void PCB_EDIT_FRAME::LoadSettings()
794
{
795
    wxConfig* config = wxGetApp().GetSettings();
796 797 798 799

    if( config == NULL )
        return;

800
    // The configuration setting that used to be mixed in with the project file settings.
801 802
    wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() );

803
    PCB_BASE_FRAME::LoadSettings();
804

805 806 807 808 809 810 811
    double dtmp;
    config->Read( OPTKEY_DEFAULT_LINEWIDTH_VALUE, &dtmp, 0.1 ); // stored in mm
    if( dtmp < 0.01 )
        dtmp = 0.01;
    if( dtmp > 5.0 )
        dtmp = 5.0;
    g_DrawDefaultLineThickness = Millimeter2iu( dtmp );
812 813 814
    long tmp;
    config->Read( PCB_SHOW_FULL_RATSNET_OPT, &tmp );
    GetBoard()->SetElementVisibility(RATSNEST_VISIBLE, tmp);
815

816 817 818
    config->Read( PCB_MAGNETIC_PADS_OPT, &g_MagneticPadOption );
    config->Read( PCB_MAGNETIC_TRACKS_OPT, &g_MagneticTrackOption );
    config->Read( SHOW_MICROWAVE_TOOLS, &m_show_microwave_tools );
819
    config->Read( SHOW_LAYER_MANAGER_TOOLS, &m_show_layer_manager_tools );
820 821 822 823 824

    // WxWidgets 2.9.1 seems call setlocale( LC_NUMERIC, "" )
    // when reading doubles in config,
    // but forget to back to current locale. So we call SetLocaleTo_Default
    SetLocaleTo_Default( );
825 826 827
}


828
void PCB_EDIT_FRAME::SaveSettings()
829
{
830
    wxConfig* config = wxGetApp().GetSettings();
831 832 833 834

    if( config == NULL )
        return;

835
    // The configuration setting that used to be mixed in with the project file settings.
836 837
    wxGetApp().SaveCurrentSetupValues( GetConfigurationSettings() );

838
    PCB_BASE_FRAME::SaveSettings();
839

840 841 842
    // This value is stored in mm )
    config->Write( OPTKEY_DEFAULT_LINEWIDTH_VALUE,
                   MM_PER_IU * g_DrawDefaultLineThickness );
843 844
    long tmp = GetBoard()->IsElementVisible(RATSNEST_VISIBLE);
    config->Write( PCB_SHOW_FULL_RATSNET_OPT, tmp );
845 846
    config->Write( PCB_MAGNETIC_PADS_OPT, (long) g_MagneticPadOption );
    config->Write( PCB_MAGNETIC_TRACKS_OPT, (long) g_MagneticTrackOption );
847
    config->Write( SHOW_MICROWAVE_TOOLS, (long) m_show_microwave_tools );
848
    config->Write( SHOW_LAYER_MANAGER_TOOLS, (long)m_show_layer_manager_tools );
849
}
850

851

852
bool PCB_EDIT_FRAME::IsGridVisible() const
charras's avatar
charras committed
853
{
854
    return IsElementVisible( GRID_VISIBLE );
charras's avatar
charras committed
855 856
}

857

858
void PCB_EDIT_FRAME::SetGridVisibility(bool aVisible)
charras's avatar
charras committed
859
{
860
    SetElementVisibility( GRID_VISIBLE, aVisible );
charras's avatar
charras committed
861 862
}

863

864
EDA_COLOR_T PCB_EDIT_FRAME::GetGridColor() const
charras's avatar
charras committed
865 866 867 868
{
    return GetBoard()->GetVisibleElementColor( GRID_VISIBLE );
}

869

870
void PCB_EDIT_FRAME::SetGridColor(EDA_COLOR_T aColor)
charras's avatar
charras committed
871 872 873 874
{
    GetBoard()->SetVisibleElementColor( GRID_VISIBLE, aColor );
}

875

876
bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void )
877 878
{
    int copperlayercnt = GetBoard()->GetCopperLayerCount( );
879
    LAYER_NUM currLayer = getActiveLayer();
880

881
    if( !GetDesignSettings().m_MicroViasAllowed )
882 883 884 885 886 887 888 889 890 891 892 893 894 895
        return false;   // Obvious..

    if( copperlayercnt < 4 )
        return false;   // Only on multilayer boards..

    if( ( currLayer == LAYER_N_BACK )
       || ( currLayer == LAYER_N_FRONT )
       || ( currLayer == copperlayercnt - 2 )
       || ( currLayer == LAYER_N_2 ) )
        return true;

    return false;
}

896

897
void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer )
898 899
{
    // Set display settings for high contrast mode
900
    KIGFX::VIEW* view = GetGalCanvas()->GetView();
901
    KIGFX::RENDER_SETTINGS* rSettings = view->GetPainter()->GetSettings();
902

903 904 905 906 907 908
    setTopLayer( aLayer );

    rSettings->ClearActiveLayers();
    rSettings->SetActiveLayer( aLayer );

    if( IsCopperLayer( aLayer ) )
909
    {
910 911 912 913 914 915
        // Bring some other layers to the front in case of copper layers and make them colored
        // fixme do not like the idea of storing the list of layers here,
        // should be done in some other way I guess..
        LAYER_NUM layers[] = {
                GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIAS_VISIBLE ),
                ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ),
916
                ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ),
Maciej Suminski's avatar
Maciej Suminski committed
917
                ITEM_GAL_LAYER( GP_OVERLAY ), ITEM_GAL_LAYER( RATSNEST_VISIBLE )
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
        };

        for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
            rSettings->SetActiveLayer( layers[i] );

        // Pads should be shown too
        if( aLayer == FIRST_COPPER_LAYER )
        {
            rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) );
            rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) );
        }
        else if( aLayer == LAST_COPPER_LAYER )
        {
            rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) );
            rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) );
        }
    }

    view->UpdateAllLayersColor();
}


void PCB_EDIT_FRAME::setTopLayer( LAYER_NUM aLayer )
{
    // Set display settings for high contrast mode
943
    KIGFX::VIEW* view = GetGalCanvas()->GetView();
944

945 946
    view->ClearTopLayers();
    view->SetTopLayer( aLayer );
947

948 949 950 951 952 953 954 955
    if( IsCopperLayer( aLayer ) )
    {
        // Bring some other layers to the front in case of copper layers and make them colored
        // fixme do not like the idea of storing the list of layers here,
        // should be done in some other way I guess..
        LAYER_NUM layers[] = {
                GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIAS_VISIBLE ),
                ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ),
956
                ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ),
Maciej Suminski's avatar
Maciej Suminski committed
957
                ITEM_GAL_LAYER( GP_OVERLAY ), ITEM_GAL_LAYER( RATSNEST_VISIBLE ), DRAW_N
958 959 960
        };

        for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
961
        {
962
            view->SetTopLayer( layers[i] );
963
        }
964

965 966 967 968 969 970 971 972 973 974 975
        // Pads should be shown too
        if( aLayer == FIRST_COPPER_LAYER )
        {
            view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) );
            view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) );
        }
        else if( aLayer == LAST_COPPER_LAYER )
        {
            view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) );
            view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) );
        }
976
    }
977 978 979 980 981

    view->UpdateAllLayersOrder();
}


982
void PCB_EDIT_FRAME::setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate )
983 984 985 986 987 988 989 990
{
    ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;

    setHighContrastLayer( aLayer );

    if( doLayerWidgetUpdate )
        syncLayerWidgetLayer();

991 992
    if( IsGalCanvasActive() )
        GetGalCanvas()->Refresh();
993 994 995
}


Dick Hollenbeck's avatar
Dick Hollenbeck committed
996
void PCB_EDIT_FRAME::syncLayerWidgetLayer()
997
{
998
    m_Layers->SelectLayer( getActiveLayer() );
999
    m_Layers->OnLayerSelected();
1000 1001
}

1002

Dick Hollenbeck's avatar
Dick Hollenbeck committed
1003 1004 1005 1006 1007 1008
void PCB_EDIT_FRAME::syncRenderStates()
{
    m_Layers->SyncRenderStates();
}


1009 1010 1011
void PCB_EDIT_FRAME::syncLayerVisibilities()
{
    m_Layers->SyncLayerVisibilities();
1012

1013
    KIGFX::VIEW* view = GetGalCanvas()->GetView();
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
    // Load layer & elements visibility settings
    for( LAYER_NUM i = 0; i < NB_LAYERS; ++i )
    {
        view->SetLayerVisible( i, m_Pcb->IsLayerVisible( i ) );
    }

    for( LAYER_NUM i = 0; i < END_PCB_VISIBLE_LIST; ++i )
    {
        view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) );
    }
1024 1025 1026 1027 1028 1029 1030 1031

    // Enable some layers that are GAL specific
    for( LAYER_NUM i = FIRST_NETNAME_LAYER; i < LAST_NETNAME_LAYER; ++i )
    {
        view->SetLayerVisible( i, true );
    }
    view->SetLayerVisible( ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), true );
    view->SetLayerVisible( ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), true );
1032 1033 1034
}


1035 1036 1037 1038 1039 1040 1041 1042 1043
void PCB_EDIT_FRAME::unitsChangeRefresh()
{
    PCB_BASE_FRAME::unitsChangeRefresh();    // Update the grid size select box.

    updateTraceWidthSelectBox();
    updateViaSizeSelectBox();
}


1044
bool PCB_EDIT_FRAME::IsElementVisible( int aElement ) const
1045
{
1046 1047 1048 1049 1050 1051 1052 1053
    return GetBoard()->IsElementVisible( aElement );
}


void PCB_EDIT_FRAME::SetElementVisibility( int aElement, bool aNewState )
{
    GetBoard()->SetElementVisibility( aElement, aNewState );
    m_Layers->SetRenderState( aElement, aNewState );
1054 1055
}

1056

Dick Hollenbeck's avatar
Dick Hollenbeck committed
1057
void PCB_EDIT_FRAME::SetVisibleAlls()
1058
{
Dick Hollenbeck's avatar
Dick Hollenbeck committed
1059
    GetBoard()->SetVisibleAlls();
1060 1061

    for( int ii = 0; ii < PCB_VISIBLE( END_PCB_VISIBLE_LIST ); ii++ )
1062
        m_Layers->SetRenderState( ii, true );
1063
}
1064

1065

1066
void PCB_EDIT_FRAME::SetLanguage( wxCommandEvent& event )
1067
{
1068
    EDA_DRAW_FRAME::SetLanguage( event );
1069 1070
    m_Layers->SetLayersManagerTabsText();
    wxAuiPaneInfo& pane_info = m_auimgr.GetPane( m_Layers );
charras's avatar
charras committed
1071
    pane_info.Caption( _( "Visibles" ) );
1072 1073
    m_auimgr.Update();
    ReFillLayerWidget();
charras's avatar
charras committed
1074

1075 1076 1077
    FOOTPRINT_EDIT_FRAME * moduleEditFrame = FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor();
    if( moduleEditFrame )
        moduleEditFrame->EDA_DRAW_FRAME::SetLanguage( event );
1078
}
1079 1080


1081
wxString PCB_EDIT_FRAME::GetLastNetListRead()
1082 1083
{
    wxFileName absoluteFileName = m_lastNetListRead;
1084
    wxFileName pcbFileName = GetBoard()->GetFileName();
1085

1086
    if( !absoluteFileName.MakeAbsolute( pcbFileName.GetPath() ) || !absoluteFileName.FileExists() )
1087 1088 1089 1090 1091 1092 1093 1094 1095
    {
        absoluteFileName.Clear();
        m_lastNetListRead = wxEmptyString;
    }

    return absoluteFileName.GetFullPath();
}


1096
void PCB_EDIT_FRAME::SetLastNetListRead( const wxString& aLastNetListRead )
1097 1098
{
    wxFileName relativeFileName = aLastNetListRead;
1099
    wxFileName pcbFileName = GetBoard()->GetFileName();
1100 1101 1102 1103 1104 1105 1106

    if( relativeFileName.MakeRelativeTo( pcbFileName.GetPath() )
        && relativeFileName.GetFullPath() != aLastNetListRead )
    {
        m_lastNetListRead = relativeFileName.GetFullPath();
    }
}
1107

1108

1109
void PCB_EDIT_FRAME::OnModify( )
1110
{
1111
    PCB_BASE_FRAME::OnModify();
1112

1113
    if( m_Draw3DFrame )
1114
        m_Draw3DFrame->ReloadRequest();
1115 1116
}

1117

1118
void PCB_EDIT_FRAME::SVG_Print( wxCommandEvent& event )
1119 1120 1121 1122 1123
{
    DIALOG_SVG_PRINT frame( this );

    frame.ShowModal();
}
1124 1125 1126 1127 1128


void PCB_EDIT_FRAME::UpdateTitle()
{
    wxString title;
1129
    wxFileName fileName = GetBoard()->GetFileName();
1130

1131 1132
    title.Printf( wxT( "Pcbnew %s " ), GetChars( GetBuildVersion() ) );

1133 1134
    if( fileName.IsOk() && fileName.FileExists() )
    {
1135
        title << fileName.GetFullPath();
1136 1137

        if( !fileName.IsFileWritable() )
1138
            title << _( " [Read Only]" );
1139 1140 1141
    }
    else
    {
1142
        title << _( " [new file]" ) << wxT(" ") << fileName.GetFullPath();
1143 1144 1145 1146
    }

    SetTitle( title );
}
1147

1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
#ifdef KICAD_SCRIPTING_WXPYTHON
void PCB_EDIT_FRAME::ScriptingConsoleEnableDisable( wxCommandEvent& aEvent )
{
    if ( m_pythonPanelHidden )
    {
        m_auimgr.GetPane( m_pythonPanel ).Show();
        m_pythonPanelHidden = false;
    }
    else
    {
        m_auimgr.GetPane( m_pythonPanel ).Hide();
        m_pythonPanelHidden = true;
    }
1161

1162
    m_auimgr.Update();
1163

1164 1165
}
#endif
1166 1167 1168

void PCB_EDIT_FRAME::OnSelectAutoPlaceMode( wxCommandEvent& aEvent )
{
1169 1170 1171 1172 1173 1174 1175 1176 1177
    // Automatic placement of modules and tracks is a mutually exclusive operation so
    // clear the other tool if one of the two is selected.
    // Be careful: this event function is called both by the
    // ID_TOOLBARH_PCB_MODE_MODULE and the ID_TOOLBARH_PCB_MODE_TRACKS tool
    // Therefore we should avoid a race condition when deselecting one of these tools
    // inside this function (seems happen on some Linux/wxWidgets versions)
    // when the other tool is selected

    switch( aEvent.GetId() )
1178
    {
1179
        case ID_TOOLBARH_PCB_MODE_MODULE:
1180 1181 1182
            if( aEvent.IsChecked() &&
                m_mainToolBar->GetToolToggled( ID_TOOLBARH_PCB_MODE_TRACKS ) )
                m_mainToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_TRACKS, false );
1183 1184 1185
            break;

        case ID_TOOLBARH_PCB_MODE_TRACKS:
1186 1187 1188
            if( aEvent.IsChecked() &&
                m_mainToolBar->GetToolToggled( ID_TOOLBARH_PCB_MODE_MODULE ) )
                m_mainToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_MODULE, false );
1189 1190
            break;
        }
1191 1192
}

1193 1194 1195 1196 1197 1198

void PCB_EDIT_FRAME::ToPlotter( wxCommandEvent& event )
{
    DIALOG_PLOT dlg( this );
    dlg.ShowModal();
}
1199 1200 1201 1202


void PCB_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
{
1203
    wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
1204 1205 1206 1207
                  wxT( "Invalid rotation angle, defaulting to 90." ) );

    m_rotationAngle = aRotationAngle;
}