You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2555 lines
87 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
5 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright (C) 2013-2023 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software: you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation, either version 3 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include <advanced_config.h>
  23. #include <kiface_base.h>
  24. #include <kiway.h>
  25. #include <pgm_base.h>
  26. #include <pcb_edit_frame.h>
  27. #include <3d_viewer/eda_3d_viewer_frame.h>
  28. #include <fp_lib_table.h>
  29. #include <bitmaps.h>
  30. #include <confirm.h>
  31. #include <trace_helpers.h>
  32. #include <pcbnew_id.h>
  33. #include <pcbnew_settings.h>
  34. #include <pcb_layer_box_selector.h>
  35. #include <footprint_edit_frame.h>
  36. #include <dialog_plot.h>
  37. #include <dialog_find.h>
  38. #include <dialog_footprint_properties.h>
  39. #include <dialogs/dialog_exchange_footprints.h>
  40. #include <dialogs/dialog_net_inspector.h>
  41. #include <dialog_board_setup.h>
  42. #include <invoke_pcb_dialog.h>
  43. #include <board.h>
  44. #include <pcb_group.h>
  45. #include <board_design_settings.h>
  46. #include <footprint.h>
  47. #include <drawing_sheet/ds_proxy_view_item.h>
  48. #include <connectivity/connectivity_data.h>
  49. #include <wildcards_and_files_ext.h>
  50. #include <pcb_draw_panel_gal.h>
  51. #include <functional>
  52. #include <pcb_painter.h>
  53. #include <project/project_file.h>
  54. #include <project/project_local_settings.h>
  55. #include <python_scripting.h>
  56. #include <settings/common_settings.h>
  57. #include <settings/settings_manager.h>
  58. #include <tool/tool_manager.h>
  59. #include <tool/tool_dispatcher.h>
  60. #include <tool/action_toolbar.h>
  61. #include <tool/common_control.h>
  62. #include <tool/common_tools.h>
  63. #include <tool/properties_tool.h>
  64. #include <tool/selection.h>
  65. #include <tool/zoom_tool.h>
  66. #include <tools/pcb_selection_tool.h>
  67. #include <tools/pcb_picker_tool.h>
  68. #include <tools/pcb_point_editor.h>
  69. #include <tools/edit_tool.h>
  70. #include <tools/group_tool.h>
  71. #include <tools/drc_tool.h>
  72. #include <tools/global_edit_tool.h>
  73. #include <tools/convert_tool.h>
  74. #include <tools/drawing_tool.h>
  75. #include <tools/pcb_control.h>
  76. #include <tools/board_editor_control.h>
  77. #include <tools/board_inspection_tool.h>
  78. #include <tools/pcb_editor_conditions.h>
  79. #include <tools/pcb_viewer_tools.h>
  80. #include <tools/board_reannotate_tool.h>
  81. #include <tools/placement_tool.h>
  82. #include <tools/pad_tool.h>
  83. #include <microwave/microwave_tool.h>
  84. #include <tools/position_relative_tool.h>
  85. #include <tools/zone_filler_tool.h>
  86. #include <tools/pcb_actions.h>
  87. #include <router/router_tool.h>
  88. #include <router/length_tuner_tool.h>
  89. #include <autorouter/autoplace_tool.h>
  90. #include <python/scripting/pcb_scripting_tool.h>
  91. #include <gestfich.h>
  92. #include <executable_names.h>
  93. #include <netlist_reader/netlist_reader.h>
  94. #include <wx/socket.h>
  95. #include <wx/wupdlock.h>
  96. #include <dialog_drc.h> // for DIALOG_DRC_WINDOW_NAME definition
  97. #include <ratsnest/ratsnest_view_item.h>
  98. #include <widgets/appearance_controls.h>
  99. #include <widgets/pcb_search_pane.h>
  100. #include <widgets/wx_infobar.h>
  101. #include <widgets/panel_selection_filter.h>
  102. #include <widgets/pcb_properties_panel.h>
  103. #include <widgets/wx_aui_utils.h>
  104. #include <kiplatform/app.h>
  105. #include <profile.h>
  106. #include <view/wx_view_controls.h>
  107. #include <footprint_viewer_frame.h>
  108. #include <action_plugin.h>
  109. #include "../scripting/python_scripting.h"
  110. #include <wx/filedlg.h>
  111. using namespace std::placeholders;
  112. #define INSPECT_DRC_ERROR_DIALOG_NAME wxT( "InspectDrcErrorDialog" )
  113. #define INSPECT_CLEARANCE_DIALOG_NAME wxT( "InspectClearanceDialog" )
  114. #define INSPECT_CONSTRAINTS_DIALOG_NAME wxT( "InspectConstraintsDialog" )
  115. #define FOOTPRINT_DIFF_DIALOG_NAME wxT( "FootprintDiffDialog" )
  116. BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
  117. EVT_SOCKET( ID_EDA_SOCKET_EVENT_SERV, PCB_EDIT_FRAME::OnSockRequestServer )
  118. EVT_SOCKET( ID_EDA_SOCKET_EVENT, PCB_EDIT_FRAME::OnSockRequest )
  119. EVT_CHOICE( ID_ON_ZOOM_SELECT, PCB_EDIT_FRAME::OnSelectZoom )
  120. EVT_CHOICE( ID_ON_GRID_SELECT, PCB_EDIT_FRAME::OnSelectGrid )
  121. EVT_SIZE( PCB_EDIT_FRAME::OnSize )
  122. EVT_TOOL( ID_MENU_RECOVER_BOARD_AUTOSAVE, PCB_EDIT_FRAME::Files_io )
  123. // Menu Files:
  124. EVT_MENU( ID_MAIN_MENUBAR, PCB_EDIT_FRAME::Process_Special_Functions )
  125. EVT_MENU( ID_IMPORT_NON_KICAD_BOARD, PCB_EDIT_FRAME::Files_io )
  126. EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, PCB_EDIT_FRAME::OnFileHistory )
  127. EVT_MENU( ID_FILE_LIST_CLEAR, PCB_EDIT_FRAME::OnClearFileHistory )
  128. EVT_MENU( ID_GEN_EXPORT_FILE_GENCADFORMAT, PCB_EDIT_FRAME::ExportToGenCAD )
  129. EVT_MENU( ID_GEN_EXPORT_FILE_VRML, PCB_EDIT_FRAME::OnExportVRML )
  130. EVT_MENU( ID_GEN_EXPORT_FILE_IDF3, PCB_EDIT_FRAME::OnExportIDF3 )
  131. EVT_MENU( ID_GEN_EXPORT_FILE_STEP, PCB_EDIT_FRAME::OnExportSTEP )
  132. EVT_MENU( ID_GEN_EXPORT_FILE_HYPERLYNX, PCB_EDIT_FRAME::OnExportHyperlynx )
  133. EVT_MENU( ID_MENU_EXPORT_FOOTPRINTS_TO_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions )
  134. EVT_MENU( ID_MENU_EXPORT_FOOTPRINTS_TO_NEW_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions )
  135. EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit )
  136. EVT_MENU( wxID_CLOSE, PCB_EDIT_FRAME::OnQuit )
  137. // menu Config
  138. EVT_MENU( ID_GRID_SETTINGS, PCB_EDIT_FRAME::OnGridSettings )
  139. // menu Postprocess
  140. EVT_MENU( ID_PCB_GEN_CMP_FILE, PCB_EDIT_FRAME::RecreateCmpFileFromBoard )
  141. // Horizontal toolbar
  142. EVT_TOOL( ID_GEN_PLOT_SVG, PCB_EDIT_FRAME::ExportSVG )
  143. EVT_TOOL( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
  144. EVT_COMBOBOX( ID_TOOLBARH_PCB_SELECT_LAYER, PCB_EDIT_FRAME::Process_Special_Functions )
  145. EVT_CHOICE( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
  146. EVT_CHOICE( ID_AUX_TOOLBAR_PCB_VIA_SIZE, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
  147. // Tracks and vias sizes general options
  148. EVT_MENU_RANGE( ID_POPUP_PCB_SELECT_WIDTH_START_RANGE, ID_POPUP_PCB_SELECT_WIDTH_END_RANGE,
  149. PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
  150. // User interface update event handlers.
  151. EVT_UPDATE_UI( ID_TOOLBARH_PCB_SELECT_LAYER, PCB_EDIT_FRAME::OnUpdateLayerSelectBox )
  152. EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
  153. EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_VIA_SIZE, PCB_EDIT_FRAME::OnUpdateSelectViaSize )
  154. EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH, PCB_EDIT_FRAME::OnUpdateSelectAutoWidth )
  155. EVT_UPDATE_UI_RANGE( ID_POPUP_PCB_SELECT_WIDTH1, ID_POPUP_PCB_SELECT_WIDTH8,
  156. PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
  157. EVT_UPDATE_UI_RANGE( ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_VIASIZE8,
  158. PCB_EDIT_FRAME::OnUpdateSelectViaSize )
  159. // Drop files event
  160. EVT_DROP_FILES( PCB_EDIT_FRAME::OnDropFiles )
  161. END_EVENT_TABLE()
  162. PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  163. PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, _( "PCB Editor" ),
  164. wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE,
  165. PCB_EDIT_FRAME_NAME ),
  166. m_exportNetlistAction( nullptr ),
  167. m_findDialog( nullptr ),
  168. m_inspectDrcErrorDlg( nullptr ),
  169. m_inspectClearanceDlg( nullptr ),
  170. m_inspectConstraintsDlg( nullptr ),
  171. m_footprintDiffDlg( nullptr ),
  172. m_netInspectorDlg( nullptr )
  173. {
  174. m_maximizeByDefault = true;
  175. m_showBorderAndTitleBlock = true; // true to display sheet references
  176. m_SelTrackWidthBox = nullptr;
  177. m_SelViaSizeBox = nullptr;
  178. m_SelLayerBox = nullptr;
  179. m_show_layer_manager_tools = true;
  180. m_supportsAutoSave = true;
  181. m_probingSchToPcb = false;
  182. m_show_search = false;
  183. // We don't know what state board was in when it was last saved, so we have to
  184. // assume dirty
  185. m_ZoneFillsDirty = true;
  186. m_aboutTitle = _HKI( "KiCad PCB Editor" );
  187. // Must be created before the menus are created.
  188. if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist )
  189. m_exportNetlistAction = new TOOL_ACTION( "pcbnew.EditorControl.exportNetlist",
  190. AS_GLOBAL, 0, "", _( "Netlist..." ),
  191. _( "Export netlist used to update schematics" ) );
  192. // Create GAL canvas
  193. auto canvas = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
  194. GetGalDisplayOptions(),
  195. EDA_DRAW_PANEL_GAL::GAL_FALLBACK );
  196. SetCanvas( canvas );
  197. SetBoard( new BOARD() );
  198. wxIcon icon;
  199. wxIconBundle icon_bundle;
  200. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew ) );
  201. icon_bundle.AddIcon( icon );
  202. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_32 ) );
  203. icon_bundle.AddIcon( icon );
  204. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_16 ) );
  205. icon_bundle.AddIcon( icon );
  206. SetIcons( icon_bundle );
  207. // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
  208. // initialize parameters in m_LayersManager
  209. LoadSettings( config() );
  210. SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU( pcbIUScale.IU_PER_MILS ) ) );
  211. // PCB drawings start in the upper left corner.
  212. GetScreen()->m_Center = false;
  213. setupTools();
  214. setupUIConditions();
  215. ReCreateMenuBar();
  216. ReCreateHToolbar();
  217. ReCreateAuxiliaryToolbar();
  218. ReCreateVToolbar();
  219. ReCreateOptToolbar();
  220. m_propertiesPanel = new PCB_PROPERTIES_PANEL( this, this );
  221. float proportion = GetPcbNewSettings()->m_AuiPanels.properties_splitter_proportion;
  222. m_propertiesPanel->SetSplitterProportion( proportion );
  223. m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this );
  224. m_appearancePanel = new APPEARANCE_CONTROLS( this, GetCanvas() );
  225. m_searchPane = new PCB_SEARCH_PANE( this );
  226. m_auimgr.SetManagedWindow( this );
  227. CreateInfoBar();
  228. unsigned int auiFlags = wxAUI_MGR_DEFAULT;
  229. #if !defined( _WIN32 )
  230. // Windows cannot redraw the UI fast enough during a live resize and may lead to all kinds
  231. // of graphical glitches.
  232. auiFlags |= wxAUI_MGR_LIVE_RESIZE;
  233. #endif
  234. m_auimgr.SetFlags( auiFlags );
  235. // Rows; layers 4 - 6
  236. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( wxS( "MainToolbar" ) )
  237. .Top().Layer( 6 ) );
  238. m_auimgr.AddPane( m_auxiliaryToolBar, EDA_PANE().HToolbar().Name( wxS( "AuxToolbar" ) )
  239. .Top().Layer( 5 ) );
  240. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( wxS( "MsgPanel" ) )
  241. .Bottom().Layer( 6 ) );
  242. // Columns; layers 1 - 3
  243. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( wxS( "OptToolbar" ) )
  244. .Left().Layer( 3 ) );
  245. m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( wxS( "ToolsToolbar" ) )
  246. .Right().Layer( 3 ) );
  247. m_auimgr.AddPane( m_appearancePanel, EDA_PANE().Name( wxS( "LayersManager" ) )
  248. .Right().Layer( 4 )
  249. .Caption( _( "Appearance" ) ).PaneBorder( false )
  250. .MinSize( 180, -1 ).BestSize( 180, -1 ) );
  251. m_auimgr.AddPane( m_selectionFilterPanel, EDA_PANE().Name( wxS( "SelectionFilter" ) )
  252. .Right().Layer( 4 ).Position( 2 )
  253. .Caption( _( "Selection Filter" ) ).PaneBorder( false )
  254. .MinSize( 180, -1 ).BestSize( 180, -1 ) );
  255. m_auimgr.AddPane( m_propertiesPanel, EDA_PANE().Name( PropertiesPaneName() )
  256. .Left().Layer( 5 ).Caption( _( "Properties" ) )
  257. .PaneBorder( false ).MinSize( 240, -1 ).BestSize( 300, -1 ) );
  258. // Center
  259. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( wxS( "DrawFrame" ) )
  260. .Center() );
  261. m_auimgr.AddPane( m_searchPane, EDA_PANE()
  262. .Name( SearchPaneName() )
  263. .Bottom()
  264. .Caption( _( "Search" ) )
  265. .PaneBorder( false )
  266. .MinSize( 180, -1 )
  267. .BestSize( 180, -1 )
  268. .FloatingSize( 480, 200 )
  269. .CloseButton( true )
  270. .DestroyOnClose( false ) );
  271. m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
  272. m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools );
  273. m_auimgr.GetPane( PropertiesPaneName() ).Show( GetPcbNewSettings()->m_AuiPanels.show_properties );
  274. m_auimgr.GetPane( SearchPaneName() ).Show( m_show_search );
  275. // The selection filter doesn't need to grow in the vertical direction when docked
  276. m_auimgr.GetPane( "SelectionFilter" ).dock_proportion = 0;
  277. FinishAUIInitialization();
  278. if( PCBNEW_SETTINGS* settings = dynamic_cast<PCBNEW_SETTINGS*>( config() ) )
  279. {
  280. if( settings->m_AuiPanels.right_panel_width > 0 )
  281. {
  282. wxAuiPaneInfo& layersManager = m_auimgr.GetPane( wxS( "LayersManager" ) );
  283. SetAuiPaneSize( m_auimgr, layersManager, settings->m_AuiPanels.right_panel_width, -1 );
  284. }
  285. if( settings->m_AuiPanels.properties_panel_width > 0 && m_propertiesPanel )
  286. {
  287. wxAuiPaneInfo& propertiesPanel = m_auimgr.GetPane( PropertiesPaneName() );
  288. SetAuiPaneSize( m_auimgr, propertiesPanel,
  289. settings->m_AuiPanels.properties_panel_width, -1 );
  290. }
  291. if( settings->m_AuiPanels.search_panel_height > 0
  292. && ( settings->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_TOP
  293. || settings->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_BOTTOM ) )
  294. {
  295. wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
  296. searchPane.Direction( settings->m_AuiPanels.search_panel_dock_direction );
  297. SetAuiPaneSize( m_auimgr, searchPane, -1, settings->m_AuiPanels.search_panel_height );
  298. }
  299. else if( settings->m_AuiPanels.search_panel_width > 0
  300. && ( settings->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_LEFT
  301. || settings->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_RIGHT ) )
  302. {
  303. wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
  304. searchPane.Direction( settings->m_AuiPanels.search_panel_dock_direction );
  305. SetAuiPaneSize( m_auimgr, searchPane, settings->m_AuiPanels.search_panel_width, -1 );
  306. }
  307. m_appearancePanel->SetTabIndex( settings->m_AuiPanels.appearance_panel_tab );
  308. }
  309. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
  310. // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
  311. // to calculate the wrong zoom size. See PCB_EDIT_FRAME::onSize().
  312. Bind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
  313. // Redraw netnames (so that they fall within the current viewport) after the viewport
  314. // has stopped changing. Redrawing them without the timer moves them smoothly with scrolling,
  315. // making it look like the tracks are being dragged -- which we don't want.
  316. m_redrawNetnamesTimer.SetOwner( this );
  317. Connect( wxEVT_TIMER, wxTimerEventHandler( PCB_EDIT_FRAME::redrawNetnames ), nullptr, this );
  318. Bind( wxEVT_IDLE,
  319. [this]( wxIdleEvent& aEvent )
  320. {
  321. if( GetCanvas()->GetView()->GetViewport() != m_lastViewport )
  322. {
  323. m_lastViewport = GetCanvas()->GetView()->GetViewport();
  324. m_redrawNetnamesTimer.StartOnce( 500 );
  325. }
  326. // Do not forget to pass the Idle event to other clients:
  327. aEvent.Skip();
  328. } );
  329. resolveCanvasType();
  330. setupUnits( config() );
  331. // Ensure the Python interpreter is up to date with its environment variables
  332. PythonSyncEnvironmentVariables();
  333. PythonSyncProjectName();
  334. // Sync action plugins in case they changed since the last time the frame opened
  335. GetToolManager()->RunAction( PCB_ACTIONS::pluginsReload, true );
  336. GetCanvas()->SwitchBackend( m_canvasType );
  337. ActivateGalCanvas();
  338. // Default shutdown reason until a file is loaded
  339. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New PCB file is unsaved" ) );
  340. // disable Export STEP item if kicad2step does not exist
  341. wxString strK2S = Pgm().GetExecutablePath();
  342. #ifdef __WXMAC__
  343. if( strK2S.Find( wxT( "pcbnew.app" ) ) != wxNOT_FOUND )
  344. {
  345. // On macOS, we have standalone applications inside the main bundle, so we handle that here:
  346. strK2S += wxT( "../../" );
  347. }
  348. strK2S += wxT( "Contents/MacOS/" );
  349. #endif
  350. wxFileName appK2S( strK2S, wxT( "kicad2step" ) );
  351. #ifdef _WIN32
  352. appK2S.SetExt( wxT( "exe" ) );
  353. #endif
  354. // Ensure the window is on top
  355. Raise();
  356. // if( !appK2S.FileExists() )
  357. // GetMenuBar()->FindItem( ID_GEN_EXPORT_FILE_STEP )->Enable( false );
  358. // AUI doesn't refresh properly on wxMac after changes in eb7dc6dd, so force it to
  359. #ifdef __WXMAC__
  360. if( Kiface().IsSingle() )
  361. {
  362. CallAfter( [&]()
  363. {
  364. m_appearancePanel->OnBoardChanged();
  365. } );
  366. }
  367. #endif
  368. // Register a call to update the toolbar sizes. It can't be done immediately because
  369. // it seems to require some sizes calculated that aren't yet (at least on GTK).
  370. CallAfter( [&]()
  371. {
  372. // Ensure the controls on the toolbars all are correctly sized
  373. UpdateToolbarControlSizes();
  374. } );
  375. if( ADVANCED_CFG::GetCfg().m_ShowEventCounters )
  376. {
  377. m_eventCounterTimer = new wxTimer( this );
  378. Bind( wxEVT_TIMER,
  379. [&]( wxTimerEvent& aEvent )
  380. {
  381. GetCanvas()->m_PaintEventCounter->Show();
  382. GetCanvas()->m_PaintEventCounter->Reset();
  383. KIGFX::WX_VIEW_CONTROLS* vc =
  384. static_cast<KIGFX::WX_VIEW_CONTROLS*>( GetCanvas()->GetViewControls() );
  385. vc->m_MotionEventCounter->Show();
  386. vc->m_MotionEventCounter->Reset();
  387. },
  388. m_eventCounterTimer->GetId() );
  389. m_eventCounterTimer->Start( 1000 );
  390. }
  391. Bind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &PCB_EDIT_FRAME::onCloseModelessBookReporterDialogs,
  392. this );
  393. Bind( EDA_EVT_CLOSE_NET_INSPECTOR_DIALOG, &PCB_EDIT_FRAME::onCloseNetInspectorDialog, this );
  394. Bind( EDA_EVT_UNITS_CHANGED, &PCB_EDIT_FRAME::onUnitsChanged, this );
  395. m_acceptedExts.emplace( KiCadPcbFileExtension, &PCB_ACTIONS::ddAppendBoard );
  396. m_acceptedExts.emplace( LegacyPcbFileExtension, &PCB_ACTIONS::ddAppendBoard );
  397. DragAcceptFiles( true );
  398. }
  399. PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
  400. {
  401. if( ADVANCED_CFG::GetCfg().m_ShowEventCounters )
  402. {
  403. // Stop the timer during destruction early to avoid potential event race conditions (that
  404. // do happen on windows)
  405. m_eventCounterTimer->Stop();
  406. delete m_eventCounterTimer;
  407. }
  408. // Shutdown all running tools
  409. if( m_toolManager )
  410. m_toolManager->ShutdownAllTools();
  411. if( GetBoard() )
  412. GetBoard()->RemoveAllListeners();
  413. delete m_selectionFilterPanel;
  414. delete m_appearancePanel;
  415. delete m_exportNetlistAction;
  416. delete m_propertiesPanel;
  417. }
  418. void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard, bool aBuildConnectivity,
  419. PROGRESS_REPORTER* aReporter )
  420. {
  421. if( m_pcb )
  422. m_pcb->ClearProject();
  423. PCB_BASE_EDIT_FRAME::SetBoard( aBoard, aReporter );
  424. aBoard->SetProject( &Prj() );
  425. if( aBuildConnectivity )
  426. aBoard->BuildConnectivity();
  427. // reload the drawing-sheet
  428. SetPageSettings( aBoard->GetPageSettings() );
  429. }
  430. BOARD_ITEM_CONTAINER* PCB_EDIT_FRAME::GetModel() const
  431. {
  432. return m_pcb;
  433. }
  434. void PCB_EDIT_FRAME::redrawNetnames( wxTimerEvent& aEvent )
  435. {
  436. bool needs_refresh = false;
  437. // Don't stomp on the auto-save timer event.
  438. if( aEvent.GetId() == ID_AUTO_SAVE_TIMER )
  439. {
  440. aEvent.Skip();
  441. return;
  442. }
  443. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
  444. if( !cfg || cfg->m_Display.m_NetNames < 2 )
  445. return;
  446. KIGFX::VIEW* view = GetCanvas()->GetView();
  447. double scale = view->GetScale();
  448. for( PCB_TRACK* track : GetBoard()->Tracks() )
  449. {
  450. double lod = track->ViewGetLOD( GetNetnameLayer( track->GetLayer() ), view );
  451. if( lod < scale )
  452. continue;
  453. if( lod != track->GetCachedLOD() || scale != track->GetCachedScale() )
  454. {
  455. view->Update( track, KIGFX::REPAINT );
  456. needs_refresh = true;
  457. track->SetCachedLOD( lod );
  458. track->SetCachedScale( scale );
  459. }
  460. }
  461. if( needs_refresh )
  462. GetCanvas()->Refresh();
  463. }
  464. void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
  465. {
  466. PCB_BASE_FRAME::SetPageSettings( aPageSettings );
  467. // Prepare drawing-sheet template
  468. DS_PROXY_VIEW_ITEM* drawingSheet = new DS_PROXY_VIEW_ITEM( pcbIUScale,
  469. &m_pcb->GetPageSettings(),
  470. m_pcb->GetProject(),
  471. &m_pcb->GetTitleBlock(),
  472. &m_pcb->GetProperties() );
  473. drawingSheet->SetSheetName( std::string( GetScreenDesc().mb_str() ) );
  474. drawingSheet->SetSheetPath( std::string( GetFullScreenDesc().mb_str() ) );
  475. // A board is not like a schematic having a main page and sub sheets.
  476. // So for the drawing sheet, use only the first page option to display items
  477. drawingSheet->SetIsFirstPage( true );
  478. BASE_SCREEN* screen = GetScreen();
  479. if( screen != nullptr )
  480. {
  481. drawingSheet->SetPageNumber(TO_UTF8( screen->GetPageNumber() ) );
  482. drawingSheet->SetSheetCount( screen->GetPageCount() );
  483. }
  484. if( BOARD* board = GetBoard() )
  485. drawingSheet->SetFileName( TO_UTF8( board->GetFileName() ) );
  486. // PCB_DRAW_PANEL_GAL takes ownership of the drawing-sheet
  487. GetCanvas()->SetDrawingSheet( drawingSheet );
  488. }
  489. bool PCB_EDIT_FRAME::IsContentModified() const
  490. {
  491. return GetScreen() && GetScreen()->IsContentModified();
  492. }
  493. SELECTION& PCB_EDIT_FRAME::GetCurrentSelection()
  494. {
  495. return m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
  496. }
  497. void PCB_EDIT_FRAME::setupTools()
  498. {
  499. // Create the manager and dispatcher & route draw panel events to the dispatcher
  500. m_toolManager = new TOOL_MANAGER;
  501. m_toolManager->SetEnvironment( m_pcb, GetCanvas()->GetView(),
  502. GetCanvas()->GetViewControls(), config(), this );
  503. m_actions = new PCB_ACTIONS();
  504. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  505. // Register tools
  506. m_toolManager->RegisterTool( new COMMON_CONTROL );
  507. m_toolManager->RegisterTool( new COMMON_TOOLS );
  508. m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
  509. m_toolManager->RegisterTool( new ZOOM_TOOL );
  510. m_toolManager->RegisterTool( new PCB_PICKER_TOOL );
  511. m_toolManager->RegisterTool( new ROUTER_TOOL );
  512. m_toolManager->RegisterTool( new LENGTH_TUNER_TOOL );
  513. m_toolManager->RegisterTool( new EDIT_TOOL );
  514. m_toolManager->RegisterTool( new GLOBAL_EDIT_TOOL );
  515. m_toolManager->RegisterTool( new PAD_TOOL );
  516. m_toolManager->RegisterTool( new DRAWING_TOOL );
  517. m_toolManager->RegisterTool( new PCB_POINT_EDITOR );
  518. m_toolManager->RegisterTool( new PCB_CONTROL );
  519. m_toolManager->RegisterTool( new BOARD_EDITOR_CONTROL );
  520. m_toolManager->RegisterTool( new BOARD_INSPECTION_TOOL );
  521. m_toolManager->RegisterTool( new BOARD_REANNOTATE_TOOL );
  522. m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL );
  523. m_toolManager->RegisterTool( new MICROWAVE_TOOL );
  524. m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL );
  525. m_toolManager->RegisterTool( new ZONE_FILLER_TOOL );
  526. m_toolManager->RegisterTool( new AUTOPLACE_TOOL );
  527. m_toolManager->RegisterTool( new DRC_TOOL );
  528. m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
  529. m_toolManager->RegisterTool( new CONVERT_TOOL );
  530. m_toolManager->RegisterTool( new GROUP_TOOL );
  531. m_toolManager->RegisterTool( new SCRIPTING_TOOL );
  532. m_toolManager->RegisterTool( new PROPERTIES_TOOL );
  533. m_toolManager->InitTools();
  534. for( TOOL_BASE* tool : m_toolManager->Tools() )
  535. {
  536. if( PCB_TOOL_BASE* pcbTool = dynamic_cast<PCB_TOOL_BASE*>( tool ) )
  537. pcbTool->SetIsBoardEditor( true );
  538. }
  539. // Run the selection tool, it is supposed to be always active
  540. m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
  541. }
  542. void PCB_EDIT_FRAME::setupUIConditions()
  543. {
  544. PCB_BASE_EDIT_FRAME::setupUIConditions();
  545. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  546. PCB_EDITOR_CONDITIONS cond( this );
  547. auto undoCond =
  548. [ this ] (const SELECTION& aSel )
  549. {
  550. DRAWING_TOOL* drawingTool = m_toolManager->GetTool<DRAWING_TOOL>();
  551. if( drawingTool && drawingTool->GetDrawingMode() != DRAWING_TOOL::MODE::NONE )
  552. return true;
  553. ROUTER_TOOL* routerTool = m_toolManager->GetTool<ROUTER_TOOL>();
  554. if( routerTool && routerTool->RoutingInProgress() )
  555. return true;
  556. return GetUndoCommandCount() > 0;
  557. };
  558. wxASSERT( mgr );
  559. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  560. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  561. mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  562. mgr->SetConditions( ACTIONS::undo, ENABLE( undoCond ) );
  563. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  564. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  565. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  566. mgr->SetConditions( ACTIONS::togglePolarCoords, CHECK( cond.PolarCoordinates() ) );
  567. mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  568. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  569. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  570. mgr->SetConditions( ACTIONS::cut, ENABLE( cond.HasItems() ) );
  571. mgr->SetConditions( ACTIONS::copy, ENABLE( cond.HasItems() ) );
  572. mgr->SetConditions( ACTIONS::paste,
  573. ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
  574. mgr->SetConditions( ACTIONS::pasteSpecial,
  575. ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
  576. mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );
  577. mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
  578. mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );
  579. mgr->SetConditions( PCB_ACTIONS::group, ENABLE( SELECTION_CONDITIONS::MoreThan( 1 ) ) );
  580. mgr->SetConditions( PCB_ACTIONS::ungroup, ENABLE( SELECTION_CONDITIONS::HasType( PCB_GROUP_T ) ) );
  581. mgr->SetConditions( PCB_ACTIONS::lock, ENABLE( PCB_SELECTION_CONDITIONS::HasUnlockedItems ) );
  582. mgr->SetConditions( PCB_ACTIONS::unlock, ENABLE( PCB_SELECTION_CONDITIONS::HasLockedItems ) );
  583. mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) );
  584. mgr->SetConditions( PCB_ACTIONS::viaDisplayMode, CHECK( !cond.ViaFillDisplay() ) );
  585. mgr->SetConditions( PCB_ACTIONS::trackDisplayMode, CHECK( !cond.TrackFillDisplay() ) );
  586. mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) );
  587. mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) );
  588. if( SCRIPTING::IsWxAvailable() )
  589. mgr->SetConditions( PCB_ACTIONS::showPythonConsole, CHECK( cond.ScriptingConsoleVisible() ) );
  590. auto enableZoneControlCondition =
  591. [this] ( const SELECTION& )
  592. {
  593. return GetBoard() && GetBoard()->GetVisibleElements().Contains( LAYER_ZONES )
  594. && GetDisplayOptions().m_ZoneOpacity > 0.0;
  595. };
  596. mgr->SetConditions( PCB_ACTIONS::zoneDisplayFilled,
  597. ENABLE( enableZoneControlCondition )
  598. .Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FILLED ) ) );
  599. mgr->SetConditions( PCB_ACTIONS::zoneDisplayOutline,
  600. ENABLE( enableZoneControlCondition )
  601. .Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE ) ) );
  602. mgr->SetConditions( PCB_ACTIONS::zoneDisplayFractured,
  603. ENABLE( enableZoneControlCondition )
  604. .Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FRACTURE_BORDERS ) ) );
  605. mgr->SetConditions( PCB_ACTIONS::zoneDisplayTriangulated,
  606. ENABLE( enableZoneControlCondition )
  607. .Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ) ) );
  608. mgr->SetConditions( ACTIONS::toggleBoundingBoxes, CHECK( cond.BoundingBoxes() ) );
  609. auto constrainedDrawingModeCond =
  610. [this]( const SELECTION& )
  611. {
  612. return GetPcbNewSettings()->m_Use45DegreeLimit;
  613. };
  614. auto enableBoardSetupCondition =
  615. [this] ( const SELECTION& )
  616. {
  617. DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
  618. return !( tool && tool->IsDRCDialogShown() );
  619. };
  620. auto boardFlippedCond =
  621. [this]( const SELECTION& )
  622. {
  623. return GetCanvas() && GetCanvas()->GetView()->IsMirroredX();
  624. };
  625. auto layerManagerCond =
  626. [this] ( const SELECTION& )
  627. {
  628. return LayerManagerShown();
  629. };
  630. auto propertiesCond =
  631. [this] ( const SELECTION& )
  632. {
  633. return PropertiesShown();
  634. };
  635. auto searchPaneCond =
  636. [this] ( const SELECTION& )
  637. {
  638. return m_auimgr.GetPane( SearchPaneName() ).IsShown();
  639. };
  640. auto highContrastCond =
  641. [this] ( const SELECTION& )
  642. {
  643. return GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL;
  644. };
  645. auto globalRatsnestCond =
  646. [this] (const SELECTION& )
  647. {
  648. return GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest;
  649. };
  650. auto curvedRatsnestCond =
  651. [this] (const SELECTION& )
  652. {
  653. return GetPcbNewSettings()->m_Display.m_DisplayRatsnestLinesCurved;
  654. };
  655. auto netHighlightCond =
  656. [this]( const SELECTION& )
  657. {
  658. KIGFX::RENDER_SETTINGS* settings = GetCanvas()->GetView()->GetPainter()->GetSettings();
  659. return !settings->GetHighlightNetCodes().empty();
  660. };
  661. auto enableNetHighlightCond =
  662. [this]( const SELECTION& )
  663. {
  664. BOARD_INSPECTION_TOOL* tool = m_toolManager->GetTool<BOARD_INSPECTION_TOOL>();
  665. return tool && tool->IsNetHighlightSet();
  666. };
  667. mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( constrainedDrawingModeCond ) );
  668. mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastCond ) );
  669. mgr->SetConditions( PCB_ACTIONS::flipBoard, CHECK( boardFlippedCond ) );
  670. mgr->SetConditions( PCB_ACTIONS::showLayersManager, CHECK( layerManagerCond ) );
  671. mgr->SetConditions( PCB_ACTIONS::showRatsnest, CHECK( globalRatsnestCond ) );
  672. mgr->SetConditions( PCB_ACTIONS::ratsnestLineMode, CHECK( curvedRatsnestCond ) );
  673. mgr->SetConditions( PCB_ACTIONS::toggleNetHighlight, CHECK( netHighlightCond )
  674. .Enable( enableNetHighlightCond ) );
  675. mgr->SetConditions( PCB_ACTIONS::boardSetup, ENABLE( enableBoardSetupCondition ) );
  676. mgr->SetConditions( PCB_ACTIONS::showProperties, CHECK( propertiesCond ) );
  677. mgr->SetConditions( PCB_ACTIONS::showSearch, CHECK( searchPaneCond ) );
  678. auto isArcKeepCenterMode =
  679. [this]( const SELECTION& )
  680. {
  681. return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
  682. };
  683. auto isArcKeepEndpointMode =
  684. [this]( const SELECTION& )
  685. {
  686. return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
  687. };
  688. mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepCenter, CHECK( isArcKeepCenterMode ) );
  689. mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepEndpoint, CHECK( isArcKeepEndpointMode ) );
  690. auto isHighlightMode =
  691. [this]( const SELECTION& )
  692. {
  693. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  694. return tool && tool->GetRouterMode() == PNS::RM_MarkObstacles;
  695. };
  696. auto isShoveMode =
  697. [this]( const SELECTION& )
  698. {
  699. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  700. return tool && tool->GetRouterMode() == PNS::RM_Shove;
  701. };
  702. auto isWalkaroundMode =
  703. [this]( const SELECTION& )
  704. {
  705. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  706. return tool && tool->GetRouterMode() == PNS::RM_Walkaround;
  707. };
  708. mgr->SetConditions( PCB_ACTIONS::routerHighlightMode, CHECK( isHighlightMode ) );
  709. mgr->SetConditions( PCB_ACTIONS::routerShoveMode, CHECK( isShoveMode ) );
  710. mgr->SetConditions( PCB_ACTIONS::routerWalkaroundMode, CHECK( isWalkaroundMode ) );
  711. auto haveNetCond =
  712. [] ( const SELECTION& aSel )
  713. {
  714. for( EDA_ITEM* item : aSel )
  715. {
  716. if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
  717. {
  718. if( bci->GetNetCode() > 0 )
  719. return true;
  720. }
  721. }
  722. return false;
  723. };
  724. mgr->SetConditions( PCB_ACTIONS::showNetInRatsnest, ENABLE( haveNetCond ) );
  725. mgr->SetConditions( PCB_ACTIONS::hideNetInRatsnest, ENABLE( haveNetCond ) );
  726. mgr->SetConditions( PCB_ACTIONS::highlightNet, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  727. mgr->SetConditions( PCB_ACTIONS::highlightNetSelection, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  728. mgr->SetConditions( PCB_ACTIONS::selectNet,
  729. ENABLE( SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ) );
  730. mgr->SetConditions( PCB_ACTIONS::deselectNet,
  731. ENABLE( SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ) );
  732. mgr->SetConditions( PCB_ACTIONS::selectUnconnected,
  733. ENABLE( SELECTION_CONDITIONS::OnlyTypes( { PCB_FOOTPRINT_T, PCB_PAD_T, PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ) );
  734. mgr->SetConditions( PCB_ACTIONS::selectSameSheet,
  735. ENABLE( SELECTION_CONDITIONS::OnlyTypes( { PCB_FOOTPRINT_T } ) ) );
  736. mgr->SetConditions( PCB_ACTIONS::selectOnSchematic,
  737. ENABLE( SELECTION_CONDITIONS::HasTypes( { PCB_PAD_T, PCB_FOOTPRINT_T, PCB_GROUP_T } ) ) );
  738. SELECTION_CONDITION singleZoneCond = SELECTION_CONDITIONS::Count( 1 )
  739. && SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T } );
  740. SELECTION_CONDITION zoneMergeCond = SELECTION_CONDITIONS::MoreThan( 1 )
  741. && SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T } );
  742. mgr->SetConditions( PCB_ACTIONS::zoneDuplicate, ENABLE( singleZoneCond ) );
  743. mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) );
  744. mgr->SetConditions( PCB_ACTIONS::drawSimilarZone, ENABLE( singleZoneCond ) );
  745. mgr->SetConditions( PCB_ACTIONS::zoneMerge, ENABLE( zoneMergeCond ) );
  746. mgr->SetConditions( PCB_ACTIONS::zoneFill, ENABLE( SELECTION_CONDITIONS::MoreThan( 0 ) ) );
  747. mgr->SetConditions( PCB_ACTIONS::zoneUnfill, ENABLE( SELECTION_CONDITIONS::MoreThan( 0 ) ) );
  748. mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( cond.Get45degMode() ) );
  749. #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
  750. // These tools can be used at any time to inspect the board
  751. CURRENT_TOOL( ACTIONS::zoomTool );
  752. CURRENT_TOOL( ACTIONS::measureTool );
  753. CURRENT_TOOL( ACTIONS::selectionTool );
  754. CURRENT_TOOL( PCB_ACTIONS::localRatsnestTool );
  755. auto isDRCIdle =
  756. [this] ( const SELECTION& )
  757. {
  758. DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
  759. return !( tool && tool->IsDRCRunning() );
  760. };
  761. #define CURRENT_EDIT_TOOL( action ) \
  762. mgr->SetConditions( action, ACTION_CONDITIONS().Check( cond.CurrentTool( action ) ) \
  763. .Enable( isDRCIdle ) )
  764. // These tools edit the board, so they must be disabled during some operations
  765. CURRENT_EDIT_TOOL( ACTIONS::deleteTool );
  766. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeFootprint );
  767. CURRENT_EDIT_TOOL( PCB_ACTIONS::routeSingleTrack);
  768. CURRENT_EDIT_TOOL( PCB_ACTIONS::routeDiffPair );
  769. CURRENT_EDIT_TOOL( PCB_ACTIONS::routerTuneDiffPair );
  770. CURRENT_EDIT_TOOL( PCB_ACTIONS::routerTuneDiffPairSkew );
  771. CURRENT_EDIT_TOOL( PCB_ACTIONS::routerTuneSingleTrace );
  772. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawVia );
  773. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawZone );
  774. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRuleArea );
  775. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawLine );
  776. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRectangle );
  777. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawCircle );
  778. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawArc );
  779. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawPolygon );
  780. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeImage );
  781. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeText );
  782. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawTextBox );
  783. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawAlignedDimension );
  784. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawOrthogonalDimension );
  785. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawCenterDimension );
  786. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRadialDimension );
  787. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawLeader );
  788. CURRENT_EDIT_TOOL( PCB_ACTIONS::drillOrigin );
  789. CURRENT_EDIT_TOOL( PCB_ACTIONS::gridSetOrigin );
  790. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateLine );
  791. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateGap );
  792. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateStub );
  793. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateStubArc );
  794. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateFunctionShape );
  795. #undef CURRENT_TOOL
  796. #undef CURRENT_EDIT_TOOL
  797. #undef ENABLE
  798. #undef CHECK
  799. }
  800. void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event )
  801. {
  802. if( event.GetId() == wxID_EXIT )
  803. Kiway().OnKiCadExit();
  804. if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
  805. Close( false );
  806. }
  807. void PCB_EDIT_FRAME::RecordDRCExclusions()
  808. {
  809. BOARD_DESIGN_SETTINGS& bds = GetBoard()->GetDesignSettings();
  810. bds.m_DrcExclusions.clear();
  811. for( PCB_MARKER* marker : GetBoard()->Markers() )
  812. {
  813. if( marker->IsExcluded() )
  814. bds.m_DrcExclusions.insert( marker->Serialize() );
  815. }
  816. }
  817. void PCB_EDIT_FRAME::ResolveDRCExclusions( bool aCreateMarkers )
  818. {
  819. BOARD_COMMIT commit( this );
  820. for( PCB_MARKER* marker : GetBoard()->ResolveDRCExclusions( aCreateMarkers ) )
  821. {
  822. if( marker->GetMarkerType() == MARKER_BASE::MARKER_DRAWING_SHEET )
  823. marker->GetRCItem()->SetItems( GetCanvas()->GetDrawingSheet() );
  824. commit.Add( marker );
  825. }
  826. commit.Push( wxEmptyString, SKIP_UNDO | SKIP_SET_DIRTY );
  827. for( PCB_MARKER* marker : GetBoard()->Markers() )
  828. {
  829. if( marker->GetSeverity() == RPT_SEVERITY_EXCLUSION )
  830. GetCanvas()->GetView()->Update( marker );
  831. }
  832. GetBoard()->UpdateRatsnestExclusions();
  833. }
  834. bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
  835. {
  836. // Shutdown blocks must be determined and vetoed as early as possible
  837. if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
  838. && IsContentModified() )
  839. {
  840. return false;
  841. }
  842. ZONE_FILLER_TOOL* zoneFillerTool = m_toolManager->GetTool<ZONE_FILLER_TOOL>();
  843. if( zoneFillerTool->IsBusy() )
  844. {
  845. wxBell();
  846. if( wxWindow* reporter = dynamic_cast<wxWindow*>( zoneFillerTool->GetProgressReporter() ) )
  847. reporter->ShowWithEffect( wxSHOW_EFFECT_EXPAND );
  848. return false;
  849. }
  850. if( Kiface().IsSingle() )
  851. {
  852. auto* fpEditor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
  853. if( fpEditor && !fpEditor->Close() ) // Can close footprint editor?
  854. return false;
  855. auto* fpViewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false );
  856. if( fpViewer && !fpViewer->Close() ) // Can close footprint viewer?
  857. return false;
  858. fpViewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER_MODAL, false );
  859. if( fpViewer && !fpViewer->Close() ) // Can close modal footprint viewer?
  860. return false;
  861. }
  862. else
  863. {
  864. auto* fpEditor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
  865. if( fpEditor && fpEditor->IsCurrentFPFromBoard() )
  866. {
  867. if( !fpEditor->CanCloseFPFromBoard( true ) )
  868. return false;
  869. }
  870. }
  871. if( IsContentModified() )
  872. {
  873. wxFileName fileName = GetBoard()->GetFileName();
  874. wxString msg = _( "Save changes to '%s' before closing?" );
  875. if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
  876. [&]() -> bool
  877. {
  878. return Files_io_from_id( ID_SAVE_BOARD );
  879. } ) )
  880. {
  881. return false;
  882. }
  883. }
  884. return PCB_BASE_EDIT_FRAME::canCloseWindow( aEvent );
  885. }
  886. void PCB_EDIT_FRAME::doCloseWindow()
  887. {
  888. // On Windows 7 / 32 bits, on OpenGL mode only, Pcbnew crashes
  889. // when closing this frame if a footprint was selected, and the footprint editor called
  890. // to edit this footprint, and when closing pcbnew if this footprint is still selected
  891. // See https://bugs.launchpad.net/kicad/+bug/1655858
  892. // I think this is certainly a OpenGL event fired after frame deletion, so this workaround
  893. // avoid the crash (JPC)
  894. GetCanvas()->SetEvtHandlerEnabled( false );
  895. GetCanvas()->StopDrawing();
  896. // Clean up mode-less dialogs.
  897. Unbind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER,
  898. &PCB_EDIT_FRAME::onCloseModelessBookReporterDialogs, this );
  899. Unbind( EDA_EVT_CLOSE_NET_INSPECTOR_DIALOG, &PCB_EDIT_FRAME::onCloseNetInspectorDialog, this );
  900. Unbind( EDA_EVT_UNITS_CHANGED, &PCB_EDIT_FRAME::onUnitsChanged, this );
  901. wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
  902. if( open_dlg )
  903. open_dlg->Close( true );
  904. if( m_findDialog )
  905. {
  906. m_findDialog->Destroy();
  907. m_findDialog = nullptr;
  908. }
  909. if( m_inspectDrcErrorDlg )
  910. {
  911. m_inspectDrcErrorDlg->Destroy();
  912. m_inspectDrcErrorDlg = nullptr;
  913. }
  914. if( m_inspectClearanceDlg )
  915. {
  916. m_inspectClearanceDlg->Destroy();
  917. m_inspectClearanceDlg = nullptr;
  918. }
  919. if( m_inspectConstraintsDlg )
  920. {
  921. m_inspectConstraintsDlg->Destroy();
  922. m_inspectConstraintsDlg = nullptr;
  923. }
  924. if( m_footprintDiffDlg )
  925. {
  926. m_footprintDiffDlg->Destroy();
  927. m_footprintDiffDlg = nullptr;
  928. }
  929. if( m_netInspectorDlg )
  930. {
  931. RemoveBoardChangeListener( m_netInspectorDlg );
  932. m_netInspectorDlg->Destroy();
  933. m_netInspectorDlg = nullptr;
  934. }
  935. // Delete the auto save file if it exists.
  936. wxFileName fn = GetBoard()->GetFileName();
  937. // Auto save file name is the normal file name prefixed with 'GetAutoSaveFilePrefix()'.
  938. fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
  939. // When the auto save feature does not have write access to the board file path, it falls
  940. // back to a platform specific user temporary file path.
  941. if( !fn.IsOk() || !fn.IsDirWritable() )
  942. fn.SetPath( wxFileName::GetTempDir() );
  943. wxLogTrace( traceAutoSave, wxT( "Deleting auto save file <" ) + fn.GetFullPath() + wxT( ">" ) );
  944. // Remove the auto save file on a normal close of Pcbnew.
  945. if( fn.FileExists() && !wxRemoveFile( fn.GetFullPath() ) )
  946. {
  947. wxLogTrace( traceAutoSave, wxT( "The auto save file could not be removed!" ) );
  948. }
  949. // Make sure local settings are persisted
  950. SaveProjectLocalSettings();
  951. // Do not show the layer manager during closing to avoid flicker
  952. // on some platforms (Windows) that generate useless redraw of items in
  953. // the Layer Manager
  954. if( m_show_layer_manager_tools )
  955. {
  956. m_auimgr.GetPane( wxS( "LayersManager" ) ).Show( false );
  957. m_auimgr.GetPane( wxS( "TabbedPanel" ) ).Show( false );
  958. }
  959. // Unlink the old project if needed
  960. GetBoard()->ClearProject();
  961. // Delete board structs and undo/redo lists, to avoid crash on exit
  962. // when deleting some structs (mainly in undo/redo lists) too late
  963. Clear_Pcb( false, true );
  964. // do not show the window because ScreenPcb will be deleted and we do not
  965. // want any paint event
  966. Show( false );
  967. PCB_BASE_EDIT_FRAME::doCloseWindow();
  968. }
  969. void PCB_EDIT_FRAME::ActivateGalCanvas()
  970. {
  971. PCB_BASE_EDIT_FRAME::ActivateGalCanvas();
  972. GetCanvas()->UpdateColors();
  973. GetCanvas()->Refresh();
  974. }
  975. void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage )
  976. {
  977. std::unique_lock<std::mutex> dialogLock( DIALOG_BOARD_SETUP::g_Mutex, std::try_to_lock );
  978. // One DIALOG_BOARD_SETUP dialog at a time.
  979. if( !dialogLock.owns_lock() )
  980. return;
  981. // Make sure everything's up-to-date
  982. GetBoard()->BuildListOfNets();
  983. DIALOG_BOARD_SETUP dlg( this );
  984. if( !aInitialPage.IsEmpty() )
  985. dlg.SetInitialPage( aInitialPage, wxEmptyString );
  986. if( dlg.ShowQuasiModal() == wxID_OK )
  987. {
  988. GetBoard()->SynchronizeNetsAndNetClasses( true );
  989. // We don't know if anything was modified, so err on the side of requiring a save
  990. OnModify();
  991. Kiway().CommonSettingsChanged( false, true );
  992. PCBNEW_SETTINGS* settings = GetPcbNewSettings();
  993. static LSET maskAndPasteLayers = LSET( 4, F_Mask, F_Paste, B_Mask, B_Paste );
  994. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  995. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  996. {
  997. if( dynamic_cast<PCB_TRACK*>( aItem ) )
  998. {
  999. if( settings->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS )
  1000. return KIGFX::REPAINT;
  1001. }
  1002. else if( dynamic_cast<PAD*>( aItem ) )
  1003. {
  1004. if( settings->m_Display.m_PadClearance )
  1005. return KIGFX::REPAINT;
  1006. // Note: KIGFX::REPAINT isn't enough for things that go from invisible
  1007. // to visible as they won't be found in the view layer's itemset for
  1008. // re-painting.
  1009. if( ( GetBoard()->GetVisibleLayers() & maskAndPasteLayers ).any() )
  1010. return KIGFX::ALL;
  1011. }
  1012. EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
  1013. if( text && text->HasTextVars() )
  1014. {
  1015. text->ClearRenderCache();
  1016. text->ClearBoundingBoxCache();
  1017. return KIGFX::GEOMETRY | KIGFX::REPAINT;
  1018. }
  1019. return 0;
  1020. } );
  1021. GetCanvas()->Refresh();
  1022. UpdateUserInterface();
  1023. ReCreateAuxiliaryToolbar();
  1024. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  1025. //this event causes the routing tool to reload its design rules information
  1026. TOOL_EVENT toolEvent( TC_COMMAND, TA_MODEL_CHANGE, AS_ACTIVE );
  1027. toolEvent.SetHasPosition( false );
  1028. m_toolManager->ProcessEvent( toolEvent );
  1029. }
  1030. GetCanvas()->SetFocus();
  1031. }
  1032. void PCB_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  1033. {
  1034. PCB_BASE_FRAME::LoadSettings( aCfg );
  1035. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  1036. wxASSERT( cfg );
  1037. if( cfg )
  1038. {
  1039. m_show_layer_manager_tools = cfg->m_AuiPanels.show_layer_manager;
  1040. m_show_search = cfg->m_AuiPanels.show_search;
  1041. }
  1042. }
  1043. void PCB_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  1044. {
  1045. PCB_BASE_FRAME::SaveSettings( aCfg );
  1046. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  1047. wxASSERT( cfg );
  1048. if( cfg )
  1049. {
  1050. cfg->m_AuiPanels.show_layer_manager = m_show_layer_manager_tools;
  1051. cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
  1052. cfg->m_AuiPanels.appearance_panel_tab = m_appearancePanel->GetTabIndex();
  1053. if( m_propertiesPanel )
  1054. {
  1055. cfg->m_AuiPanels.show_properties = m_propertiesPanel->IsShownOnScreen();
  1056. cfg->m_AuiPanels.properties_panel_width = m_propertiesPanel->GetSize().x;
  1057. cfg->m_AuiPanels.properties_splitter_proportion =
  1058. m_propertiesPanel->SplitterProportion();
  1059. }
  1060. // ensure m_show_search is up to date (the pane can be closed)
  1061. wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
  1062. m_show_search = searchPaneInfo.IsShown();
  1063. cfg->m_AuiPanels.show_search = m_show_search;
  1064. cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
  1065. cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
  1066. cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
  1067. }
  1068. }
  1069. EDA_ANGLE PCB_EDIT_FRAME::GetRotationAngle() const
  1070. {
  1071. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( config() );
  1072. return cfg ? cfg->m_RotationAngle : ANGLE_90;
  1073. }
  1074. COLOR4D PCB_EDIT_FRAME::GetGridColor()
  1075. {
  1076. return GetColorSettings()->GetColor( LAYER_GRID );
  1077. }
  1078. void PCB_EDIT_FRAME::SetGridColor( const COLOR4D& aColor )
  1079. {
  1080. GetColorSettings()->SetColor( LAYER_GRID, aColor );
  1081. GetCanvas()->GetGAL()->SetGridColor( aColor );
  1082. }
  1083. void PCB_EDIT_FRAME::SetActiveLayer( PCB_LAYER_ID aLayer )
  1084. {
  1085. PCB_LAYER_ID oldLayer = GetActiveLayer();
  1086. if( oldLayer == aLayer )
  1087. return;
  1088. PCB_BASE_FRAME::SetActiveLayer( aLayer );
  1089. m_appearancePanel->OnLayerChanged();
  1090. m_toolManager->RunAction( PCB_ACTIONS::layerChanged ); // notify other tools
  1091. GetCanvas()->SetFocus(); // allow capture of hotkeys
  1092. GetCanvas()->SetHighContrastLayer( aLayer );
  1093. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  1094. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  1095. {
  1096. BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( aItem );
  1097. if( !item )
  1098. return 0;
  1099. // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible
  1100. // as they won't be found in the view layer's itemset for re-painting.
  1101. if( GetDisplayOptions().m_ContrastModeDisplay == HIGH_CONTRAST_MODE::HIDDEN )
  1102. {
  1103. if( item->IsOnLayer( oldLayer, true ) || item->IsOnLayer( aLayer, true ) )
  1104. return KIGFX::ALL;
  1105. }
  1106. if( item->Type() == PCB_VIA_T )
  1107. {
  1108. PCB_VIA* via = static_cast<PCB_VIA*>( item );
  1109. // Vias on a restricted layer set must be redrawn when the active layer
  1110. // is changed
  1111. if( via->GetViaType() == VIATYPE::BLIND_BURIED
  1112. || via->GetViaType() == VIATYPE::MICROVIA )
  1113. {
  1114. return KIGFX::REPAINT;
  1115. }
  1116. }
  1117. else if( item->Type() == PCB_PAD_T )
  1118. {
  1119. PAD* pad = static_cast<PAD*>( item );
  1120. // Clearances could be layer-dependent so redraw them when the active layer
  1121. // is changed
  1122. if( GetPcbNewSettings()->m_Display.m_PadClearance )
  1123. {
  1124. // Round-corner rects are expensive to draw, but are mostly found on
  1125. // SMD pads which only need redrawing on an active-to-not-active
  1126. // switch.
  1127. if( pad->GetAttribute() == PAD_ATTRIB::SMD )
  1128. {
  1129. if( ( oldLayer == F_Cu || aLayer == F_Cu ) && pad->IsOnLayer( F_Cu ) )
  1130. return KIGFX::REPAINT;
  1131. if( ( oldLayer == B_Cu || aLayer == B_Cu ) && pad->IsOnLayer( B_Cu ) )
  1132. return KIGFX::REPAINT;
  1133. }
  1134. else if( pad->IsOnLayer( oldLayer ) || pad->IsOnLayer( aLayer ) )
  1135. {
  1136. return KIGFX::REPAINT;
  1137. }
  1138. }
  1139. }
  1140. else if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
  1141. {
  1142. PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
  1143. // Clearances could be layer-dependent so redraw them when the active layer
  1144. // is changed
  1145. if( GetPcbNewSettings()->m_Display.m_TrackClearance )
  1146. {
  1147. // Tracks aren't particularly expensive to draw, but it's an easy check.
  1148. if( track->IsOnLayer( oldLayer ) || track->IsOnLayer( aLayer ) )
  1149. return KIGFX::REPAINT;
  1150. }
  1151. }
  1152. return 0;
  1153. } );
  1154. GetCanvas()->Refresh();
  1155. }
  1156. void PCB_EDIT_FRAME::onBoardLoaded()
  1157. {
  1158. // JEY TODO: move this global to the board
  1159. ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
  1160. layerEnum.Choices().Clear();
  1161. layerEnum.Undefined( UNDEFINED_LAYER );
  1162. for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
  1163. {
  1164. // Canonical name
  1165. layerEnum.Map( *seq, LSET::Name( *seq ) );
  1166. // User name
  1167. layerEnum.Map( *seq, GetBoard()->GetLayerName( *seq ) );
  1168. }
  1169. DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
  1170. try
  1171. {
  1172. drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
  1173. }
  1174. catch( PARSE_ERROR& )
  1175. {
  1176. // Not sure this is the best place to tell the user their rules are buggy, so
  1177. // we'll stay quiet for now. Feel free to revisit this decision....
  1178. }
  1179. UpdateTitle();
  1180. wxFileName fn = GetBoard()->GetFileName();
  1181. // Display a warning that the file is read only
  1182. if( fn.FileExists() && !fn.IsFileWritable() )
  1183. {
  1184. m_infoBar->RemoveAllButtons();
  1185. m_infoBar->AddCloseButton();
  1186. m_infoBar->ShowMessage( _( "Board file is read only." ),
  1187. wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
  1188. }
  1189. ReCreateLayerBox();
  1190. // Sync layer and item visibility
  1191. GetCanvas()->SyncLayersVisibility( m_pcb );
  1192. SetElementVisibility( LAYER_RATSNEST, GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest );
  1193. m_appearancePanel->OnBoardChanged();
  1194. // Apply saved display state to the appearance panel after it has been set up
  1195. PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
  1196. m_appearancePanel->ApplyLayerPreset( localSettings.m_ActiveLayerPreset );
  1197. if( GetBoard()->GetDesignSettings().IsLayerEnabled( localSettings.m_ActiveLayer ) )
  1198. SetActiveLayer( localSettings.m_ActiveLayer );
  1199. // Updates any auto dimensions and the auxiliary toolbar tracks/via sizes
  1200. unitsChangeRefresh();
  1201. // Display the loaded board:
  1202. Zoom_Automatique( false );
  1203. // Invalidate painting as loading the DRC engine will cause clearances to become valid
  1204. GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
  1205. Refresh();
  1206. SetMsgPanel( GetBoard() );
  1207. SetStatusText( wxEmptyString );
  1208. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "PCB file changes are unsaved" ) );
  1209. }
  1210. void PCB_EDIT_FRAME::OnDisplayOptionsChanged()
  1211. {
  1212. m_appearancePanel->UpdateDisplayOptions();
  1213. }
  1214. bool PCB_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const
  1215. {
  1216. return GetBoard()->IsElementVisible( aElement );
  1217. }
  1218. void PCB_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
  1219. {
  1220. // Force the RATSNEST visible
  1221. if( aElement == LAYER_RATSNEST )
  1222. GetCanvas()->GetView()->SetLayerVisible( aElement, true );
  1223. else
  1224. GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
  1225. GetBoard()->SetElementVisibility( aElement, aNewState );
  1226. }
  1227. void PCB_EDIT_FRAME::ShowChangedLanguage()
  1228. {
  1229. // call my base class
  1230. PCB_BASE_EDIT_FRAME::ShowChangedLanguage();
  1231. m_auimgr.GetPane( m_appearancePanel ).Caption( _( "Appearance" ) );
  1232. m_auimgr.GetPane( m_selectionFilterPanel ).Caption( _( "Selection Filter" ) );
  1233. m_auimgr.GetPane( m_propertiesPanel ).Caption( _( "Properties" ) );
  1234. m_auimgr.Update();
  1235. m_appearancePanel->OnLanguageChanged();
  1236. m_selectionFilterPanel->OnLanguageChanged();
  1237. m_propertiesPanel->OnLanguageChanged();
  1238. UpdateTitle();
  1239. }
  1240. wxString PCB_EDIT_FRAME::GetLastPath( LAST_PATH_TYPE aType )
  1241. {
  1242. PROJECT_FILE& project = Prj().GetProjectFile();
  1243. if( project.m_PcbLastPath[ aType ].IsEmpty() )
  1244. return wxEmptyString;
  1245. wxFileName absoluteFileName = project.m_PcbLastPath[ aType ];
  1246. wxFileName pcbFileName = GetBoard()->GetFileName();
  1247. absoluteFileName.MakeAbsolute( pcbFileName.GetPath() );
  1248. return absoluteFileName.GetFullPath();
  1249. }
  1250. void PCB_EDIT_FRAME::SetLastPath( LAST_PATH_TYPE aType, const wxString& aLastPath )
  1251. {
  1252. PROJECT_FILE& project = Prj().GetProjectFile();
  1253. wxFileName relativeFileName = aLastPath;
  1254. wxFileName pcbFileName = GetBoard()->GetFileName();
  1255. relativeFileName.MakeRelativeTo( pcbFileName.GetPath() );
  1256. if( relativeFileName.GetFullPath() != project.m_PcbLastPath[ aType ] )
  1257. {
  1258. project.m_PcbLastPath[ aType ] = relativeFileName.GetFullPath();
  1259. OnModify();
  1260. }
  1261. }
  1262. void PCB_EDIT_FRAME::OnModify()
  1263. {
  1264. PCB_BASE_FRAME::OnModify();
  1265. Update3DView( true, GetPcbNewSettings()->m_Display.m_Live3DRefresh );
  1266. if( !GetTitle().StartsWith( wxT( "*" ) ) )
  1267. UpdateTitle();
  1268. m_ZoneFillsDirty = true;
  1269. }
  1270. void PCB_EDIT_FRAME::HardRedraw()
  1271. {
  1272. Update3DView( true, true );
  1273. }
  1274. void PCB_EDIT_FRAME::ExportSVG( wxCommandEvent& event )
  1275. {
  1276. InvokeExportSVG( this, GetBoard() );
  1277. }
  1278. void PCB_EDIT_FRAME::UpdateTitle()
  1279. {
  1280. wxFileName fn = GetBoard()->GetFileName();
  1281. bool readOnly = false;
  1282. bool unsaved = false;
  1283. if( fn.IsOk() && fn.FileExists() )
  1284. readOnly = !fn.IsFileWritable();
  1285. else
  1286. unsaved = true;
  1287. wxString title;
  1288. if( IsContentModified() )
  1289. title = wxT( "*" );
  1290. title += fn.GetName();
  1291. if( readOnly )
  1292. title += wxS( " " ) + _( "[Read Only]" );
  1293. if( unsaved )
  1294. title += wxS( " " ) + _( "[Unsaved]" );
  1295. title += wxT( " \u2014 " ) + _( "PCB Editor" );
  1296. SetTitle( title );
  1297. }
  1298. void PCB_EDIT_FRAME::UpdateUserInterface()
  1299. {
  1300. // Update the layer manager and other widgets from the board setup
  1301. // (layer and items visibility, colors ...)
  1302. // Rebuild list of nets (full ratsnest rebuild)
  1303. GetBoard()->BuildConnectivity();
  1304. // Update info shown by the horizontal toolbars
  1305. ReCreateLayerBox();
  1306. LSET activeLayers = GetBoard()->GetEnabledLayers();
  1307. if( !activeLayers.test( GetActiveLayer() ) )
  1308. SetActiveLayer( activeLayers.Seq().front() );
  1309. m_SelLayerBox->SetLayerSelection( GetActiveLayer() );
  1310. ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
  1311. layerEnum.Choices().Clear();
  1312. layerEnum.Undefined( UNDEFINED_LAYER );
  1313. for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
  1314. {
  1315. // Canonical name
  1316. layerEnum.Map( *seq, LSET::Name( *seq ) );
  1317. // User name
  1318. layerEnum.Map( *seq, GetBoard()->GetLayerName( *seq ) );
  1319. }
  1320. // Sync visibility with canvas
  1321. for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
  1322. GetCanvas()->GetView()->SetLayerVisible( layer, GetBoard()->IsLayerVisible( layer ) );
  1323. // Stackup and/or color theme may have changed
  1324. m_appearancePanel->OnBoardChanged();
  1325. }
  1326. void PCB_EDIT_FRAME::SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType )
  1327. {
  1328. // switches currently used canvas (Cairo / OpenGL).
  1329. PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
  1330. }
  1331. void PCB_EDIT_FRAME::ShowFindDialog()
  1332. {
  1333. if( !m_findDialog )
  1334. {
  1335. m_findDialog = new DIALOG_FIND( this );
  1336. m_findDialog->SetCallback( std::bind( &PCB_SELECTION_TOOL::FindItem,
  1337. m_toolManager->GetTool<PCB_SELECTION_TOOL>(), _1 ) );
  1338. }
  1339. wxString findString;
  1340. PCB_SELECTION& selection = m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
  1341. if( selection.Size() == 1 )
  1342. {
  1343. EDA_ITEM* front = selection.Front();
  1344. switch( front->Type() )
  1345. {
  1346. case PCB_FOOTPRINT_T:
  1347. findString = UnescapeString( static_cast<FOOTPRINT*>( front )->GetValue() );
  1348. break;
  1349. case PCB_FIELD_T:
  1350. case PCB_TEXT_T:
  1351. findString = UnescapeString( static_cast<PCB_TEXT*>( front )->GetText() );
  1352. if( findString.Contains( wxT( "\n" ) ) )
  1353. findString = findString.Before( '\n' );
  1354. break;
  1355. default:
  1356. break;
  1357. }
  1358. }
  1359. m_findDialog->Preload( findString );
  1360. m_findDialog->Show( true );
  1361. }
  1362. void PCB_EDIT_FRAME::FindNext( bool reverse )
  1363. {
  1364. if( !m_findDialog )
  1365. ShowFindDialog();
  1366. m_findDialog->FindNext( reverse );
  1367. }
  1368. void PCB_EDIT_FRAME::ToPlotter( int aID )
  1369. {
  1370. PCB_PLOT_PARAMS plotSettings = GetPlotSettings();
  1371. switch( aID )
  1372. {
  1373. case ID_GEN_PLOT_GERBER:
  1374. plotSettings.SetFormat( PLOT_FORMAT::GERBER );
  1375. break;
  1376. case ID_GEN_PLOT_DXF:
  1377. plotSettings.SetFormat( PLOT_FORMAT::DXF );
  1378. break;
  1379. case ID_GEN_PLOT_HPGL:
  1380. plotSettings.SetFormat( PLOT_FORMAT::HPGL );
  1381. break;
  1382. case ID_GEN_PLOT_PDF:
  1383. plotSettings.SetFormat( PLOT_FORMAT::PDF );
  1384. break;
  1385. case ID_GEN_PLOT_PS:
  1386. plotSettings.SetFormat( PLOT_FORMAT::POST );
  1387. break;
  1388. case ID_GEN_PLOT:
  1389. /* keep the previous setup */
  1390. break;
  1391. default:
  1392. wxFAIL_MSG( wxT( "ToPlotter(): unexpected plot type" ) ); break;
  1393. break;
  1394. }
  1395. SetPlotSettings( plotSettings );
  1396. DIALOG_PLOT dlg( this );
  1397. dlg.ShowQuasiModal( );
  1398. }
  1399. int PCB_EDIT_FRAME::TestStandalone()
  1400. {
  1401. if( Kiface().IsSingle() )
  1402. return 0;
  1403. // Update PCB requires a netlist. Therefore the schematic editor must be running
  1404. // If this is not the case, open the schematic editor
  1405. KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, true );
  1406. // If Kiway() cannot create the eeschema frame, it shows a error message, and
  1407. // frame is null
  1408. if( !frame )
  1409. return -1;
  1410. if( !frame->IsShown() )
  1411. {
  1412. wxFileName fn( Prj().GetProjectPath(), Prj().GetProjectName(),
  1413. KiCadSchematicFileExtension );
  1414. // Maybe the file hasn't been converted to the new s-expression file format so
  1415. // see if the legacy schematic file is still in play.
  1416. if( !fn.FileExists() )
  1417. {
  1418. fn.SetExt( LegacySchematicFileExtension );
  1419. if( !fn.FileExists() )
  1420. {
  1421. DisplayError( this, _( "The schematic for this board cannot be found." ) );
  1422. return -2;
  1423. }
  1424. }
  1425. frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
  1426. // we show the schematic editor frame, because do not show is seen as
  1427. // a not yet opened schematic by Kicad manager, which is not the case
  1428. frame->Show( true );
  1429. // bring ourselves back to the front
  1430. Raise();
  1431. }
  1432. return 1; //Success!
  1433. }
  1434. bool PCB_EDIT_FRAME::FetchNetlistFromSchematic( NETLIST& aNetlist,
  1435. const wxString& aAnnotateMessage )
  1436. {
  1437. if( TestStandalone() == 0 )
  1438. {
  1439. DisplayErrorMessage( this, _( "Cannot update the PCB because PCB editor is opened in "
  1440. "stand-alone mode. In order to create or update PCBs from "
  1441. "schematics, you must launch the KiCad project manager and "
  1442. "create a project." ) );
  1443. return false; // Not in standalone mode
  1444. }
  1445. if( TestStandalone() < 0 ) // Problem with Eeschema or the schematic
  1446. return false;
  1447. Raise(); // Show
  1448. std::string payload( aAnnotateMessage );
  1449. Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_GET_NETLIST, payload, this );
  1450. if( payload == aAnnotateMessage )
  1451. {
  1452. Raise();
  1453. DisplayErrorMessage( this, aAnnotateMessage );
  1454. return false;
  1455. }
  1456. try
  1457. {
  1458. auto lineReader = new STRING_LINE_READER( payload, _( "Eeschema netlist" ) );
  1459. KICAD_NETLIST_READER netlistReader( lineReader, &aNetlist );
  1460. netlistReader.LoadNetlist();
  1461. }
  1462. catch( const IO_ERROR& e )
  1463. {
  1464. Raise();
  1465. // Do not translate extra_info strings. These are for developers
  1466. wxString extra_info = e.Problem() + wxT( " : " ) + e.What() + wxT( " at " ) + e.Where();
  1467. DisplayErrorMessage( this, _( "Received an error while reading netlist. Please "
  1468. "report this issue to the KiCad team using the menu "
  1469. "Help->Report Bug."), extra_info );
  1470. return false;
  1471. }
  1472. return true;
  1473. }
  1474. void PCB_EDIT_FRAME::RunEeschema()
  1475. {
  1476. wxString msg;
  1477. wxFileName schematic( Prj().GetProjectPath(), Prj().GetProjectName(),
  1478. KiCadSchematicFileExtension );
  1479. if( !schematic.FileExists() )
  1480. {
  1481. wxFileName legacySchematic( Prj().GetProjectPath(), Prj().GetProjectName(),
  1482. LegacySchematicFileExtension );
  1483. if( legacySchematic.FileExists() )
  1484. {
  1485. schematic = legacySchematic;
  1486. }
  1487. else
  1488. {
  1489. msg.Printf( _( "Schematic file '%s' not found." ), schematic.GetFullPath() );
  1490. DisplayErrorMessage( this, msg );
  1491. return;
  1492. }
  1493. }
  1494. if( Kiface().IsSingle() )
  1495. {
  1496. ExecuteFile( EESCHEMA_EXE, schematic.GetFullPath() );
  1497. }
  1498. else
  1499. {
  1500. KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, false );
  1501. // Please: note: DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() calls
  1502. // Kiway.Player( FRAME_SCH, true )
  1503. // therefore, the schematic editor is sometimes running, but the schematic project
  1504. // is not loaded, if the library editor was called, and the dialog field editor was used.
  1505. // On Linux, it happens the first time the schematic editor is launched, if
  1506. // library editor was running, and the dialog field editor was open
  1507. // On Windows, it happens always after the library editor was called,
  1508. // and the dialog field editor was used
  1509. if( !frame )
  1510. {
  1511. try
  1512. {
  1513. frame = Kiway().Player( FRAME_SCH, true );
  1514. }
  1515. catch( const IO_ERROR& err )
  1516. {
  1517. DisplayErrorMessage( this, _( "Eeschema failed to load." ) + wxS( "\n" ) + err.What() );
  1518. return;
  1519. }
  1520. }
  1521. // If Kiway() cannot create the eeschema frame, it shows a error message, and
  1522. // frame is null
  1523. if( !frame )
  1524. return;
  1525. if( !frame->IsShown() ) // the frame exists, (created by the dialog field editor)
  1526. // but no project loaded.
  1527. {
  1528. frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFullPath() ) );
  1529. frame->Show( true );
  1530. }
  1531. // On Windows, Raise() does not bring the window on screen, when iconized or not shown
  1532. // On Linux, Raise() brings the window on screen, but this code works fine
  1533. if( frame->IsIconized() )
  1534. {
  1535. frame->Iconize( false );
  1536. // If an iconized frame was created by Pcbnew, Iconize( false ) is not enough
  1537. // to show the frame at its normal size: Maximize should be called.
  1538. frame->Maximize( false );
  1539. }
  1540. frame->Raise();
  1541. }
  1542. }
  1543. void PCB_EDIT_FRAME::PythonSyncEnvironmentVariables()
  1544. {
  1545. const ENV_VAR_MAP& vars = Pgm().GetLocalEnvVariables();
  1546. // Set the environment variables for python scripts
  1547. // note: the string will be encoded UTF8 for python env
  1548. for( const std::pair<const wxString, ENV_VAR_ITEM>& var : vars )
  1549. UpdatePythonEnvVar( var.first, var.second.GetValue() );
  1550. // Because the env vars can be modified by the python scripts (rewritten in UTF8),
  1551. // regenerate them (in Unicode) for our normal environment
  1552. for( const std::pair<const wxString, ENV_VAR_ITEM>& var : vars )
  1553. wxSetEnv( var.first, var.second.GetValue() );
  1554. }
  1555. void PCB_EDIT_FRAME::PythonSyncProjectName()
  1556. {
  1557. wxString evValue;
  1558. wxGetEnv( PROJECT_VAR_NAME, &evValue );
  1559. UpdatePythonEnvVar( wxString( PROJECT_VAR_NAME ).ToStdString(), evValue );
  1560. // Because PROJECT_VAR_NAME can be modified by the python scripts (rewritten in UTF8),
  1561. // regenerate it (in Unicode) for our normal environment
  1562. wxSetEnv( PROJECT_VAR_NAME, evValue );
  1563. }
  1564. void PCB_EDIT_FRAME::ShowFootprintPropertiesDialog( FOOTPRINT* aFootprint )
  1565. {
  1566. if( aFootprint == nullptr )
  1567. return;
  1568. DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_RETVALUE retvalue;
  1569. /*
  1570. * Make sure dlg is destroyed before GetCanvas->Refresh is called
  1571. * later or the refresh will try to modify its properties since
  1572. * they share a GL context.
  1573. */
  1574. {
  1575. DIALOG_FOOTPRINT_PROPERTIES dlg( this, aFootprint );
  1576. dlg.ShowModal();
  1577. retvalue = dlg.GetReturnValue();
  1578. }
  1579. /*
  1580. * retvalue =
  1581. * FP_PROPS_UPDATE_FP to show Update Footprints dialog
  1582. * FP_PROPS_CHANGE_FP to show Change Footprints dialog
  1583. * FP_PROPS_OK for normal edit
  1584. * FP_PROPS_CANCEL if aborted
  1585. * FP_PROPS_EDIT_BOARD_FP to load board footprint into Footprint Editor
  1586. * FP_PROPS_EDIT_LIBRARY_FP to load library footprint into Footprint Editor
  1587. */
  1588. if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_OK )
  1589. {
  1590. // If something edited, push a refresh request
  1591. GetCanvas()->Refresh();
  1592. }
  1593. else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_BOARD_FP )
  1594. {
  1595. auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
  1596. editor->LoadFootprintFromBoard( aFootprint );
  1597. editor->Show( true );
  1598. editor->Raise(); // Iconize( false );
  1599. }
  1600. else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_LIBRARY_FP )
  1601. {
  1602. auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
  1603. editor->LoadFootprintFromLibrary( aFootprint->GetFPID() );
  1604. editor->Show( true );
  1605. editor->Raise(); // Iconize( false );
  1606. }
  1607. else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_UPDATE_FP )
  1608. {
  1609. ShowExchangeFootprintsDialog( aFootprint, true, true );
  1610. }
  1611. else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_CHANGE_FP )
  1612. {
  1613. ShowExchangeFootprintsDialog( aFootprint, false, true );
  1614. }
  1615. }
  1616. int PCB_EDIT_FRAME::ShowExchangeFootprintsDialog( FOOTPRINT* aFootprint, bool aUpdateMode,
  1617. bool aSelectedMode )
  1618. {
  1619. DIALOG_EXCHANGE_FOOTPRINTS dialog( this, aFootprint, aUpdateMode, aSelectedMode );
  1620. return dialog.ShowQuasiModal();
  1621. }
  1622. namespace {
  1623. void processTextItem( const PCB_TEXT& aSrc, PCB_TEXT& aDest,
  1624. bool resetText, bool resetTextLayers, bool resetTextEffects,
  1625. bool* aUpdated )
  1626. {
  1627. if( resetText )
  1628. {
  1629. *aUpdated |= aSrc.GetText() != aDest.GetText();
  1630. aDest.SetText( aSrc.GetText() );
  1631. }
  1632. if( resetTextLayers )
  1633. {
  1634. *aUpdated |= aSrc.GetLayer() != aDest.GetLayer();
  1635. *aUpdated |= aSrc.IsVisible() != aDest.IsVisible();
  1636. aDest.SetLayer( aSrc.GetLayer() );
  1637. aDest.SetVisible( aSrc.IsVisible() );
  1638. }
  1639. if( resetTextEffects )
  1640. {
  1641. *aUpdated |= aSrc.GetHorizJustify() != aDest.GetHorizJustify();
  1642. *aUpdated |= aSrc.GetVertJustify() != aDest.GetVertJustify();
  1643. *aUpdated |= aSrc.GetTextSize() != aDest.GetTextSize();
  1644. *aUpdated |= aSrc.GetTextThickness() != aDest.GetTextThickness();
  1645. *aUpdated |= aSrc.GetTextAngle() != aDest.GetTextAngle();
  1646. *aUpdated |= aSrc.GetFPRelativePosition() != aDest.GetFPRelativePosition();
  1647. // Careful: the visible bit and position are also set by SetAttributes()
  1648. bool visible = aDest.IsVisible();
  1649. aDest.SetAttributes( aSrc );
  1650. aDest.SetVisible( visible );
  1651. aDest.SetFPRelativePosition( aSrc.GetFPRelativePosition() );
  1652. }
  1653. aDest.SetLocked( aSrc.IsLocked() );
  1654. }
  1655. PCB_TEXT* getMatchingTextItem( PCB_TEXT* aRefItem, FOOTPRINT* aFootprint )
  1656. {
  1657. std::vector<PCB_TEXT*> candidates;
  1658. for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
  1659. {
  1660. PCB_TEXT* candidate = dynamic_cast<PCB_TEXT*>( item );
  1661. if( candidate && candidate->GetText() == aRefItem->GetText() )
  1662. candidates.push_back( candidate );
  1663. }
  1664. if( candidates.size() == 0 )
  1665. return nullptr;
  1666. if( candidates.size() == 1 )
  1667. return candidates[0];
  1668. // Try refining the match by layer
  1669. std::vector<PCB_TEXT*> candidatesOnSameLayer;
  1670. for( PCB_TEXT* candidate : candidates )
  1671. {
  1672. if( candidate->GetLayer() == aRefItem->GetLayer() )
  1673. candidatesOnSameLayer.push_back( candidate );
  1674. }
  1675. if( candidatesOnSameLayer.size() == 1 )
  1676. return candidatesOnSameLayer[0];
  1677. // Last ditch effort: refine by position
  1678. std::vector<PCB_TEXT*> candidatesAtSamePos;
  1679. for( PCB_TEXT* candidate : candidatesOnSameLayer.size() ? candidatesOnSameLayer : candidates )
  1680. {
  1681. if( candidate->GetFPRelativePosition() == aRefItem->GetFPRelativePosition() )
  1682. candidatesAtSamePos.push_back( candidate );
  1683. }
  1684. if( candidatesAtSamePos.size() > 0 )
  1685. return candidatesAtSamePos[0];
  1686. else if( candidatesOnSameLayer.size() > 0 )
  1687. return candidatesOnSameLayer[0];
  1688. else
  1689. return candidates[0];
  1690. }
  1691. }
  1692. void PCB_EDIT_FRAME::ExchangeFootprint( FOOTPRINT* aExisting, FOOTPRINT* aNew,
  1693. BOARD_COMMIT& aCommit, bool deleteExtraTexts,
  1694. bool resetTextLayers, bool resetTextEffects,
  1695. bool resetFabricationAttrs, bool reset3DModels,
  1696. bool* aUpdated )
  1697. {
  1698. PCB_GROUP* parentGroup = aExisting->GetParentGroup();
  1699. bool dummyBool = false;
  1700. if( !aUpdated )
  1701. aUpdated = &dummyBool;
  1702. if( parentGroup )
  1703. {
  1704. parentGroup->RemoveItem( aExisting );
  1705. parentGroup->AddItem( aNew );
  1706. }
  1707. aNew->SetParent( GetBoard() );
  1708. PlaceFootprint( aNew, false );
  1709. // PlaceFootprint will move the footprint to the cursor position, which we don't want. Copy
  1710. // the original position across.
  1711. aNew->SetPosition( aExisting->GetPosition() );
  1712. if( aNew->GetLayer() != aExisting->GetLayer() )
  1713. aNew->Flip( aNew->GetPosition(), GetPcbNewSettings()->m_FlipLeftRight );
  1714. if( aNew->GetOrientation() != aExisting->GetOrientation() )
  1715. aNew->SetOrientation( aExisting->GetOrientation() );
  1716. aNew->SetLocked( aExisting->IsLocked() );
  1717. // Now transfer the net info from "old" pads to the new footprint
  1718. for( PAD* pad : aNew->Pads() )
  1719. {
  1720. PAD* pad_model = nullptr;
  1721. // Pads with no copper are never connected to a net
  1722. if( !pad->IsOnCopperLayer() )
  1723. {
  1724. pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
  1725. continue;
  1726. }
  1727. // Pads with no numbers are never connected to a net
  1728. if( pad->GetNumber().IsEmpty() )
  1729. {
  1730. pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
  1731. continue;
  1732. }
  1733. // Search for a similar pad on a copper layer, to reuse net info
  1734. PAD* last_pad = nullptr;
  1735. while( true )
  1736. {
  1737. pad_model = aExisting->FindPadByNumber( pad->GetNumber(), last_pad );
  1738. if( !pad_model )
  1739. break;
  1740. if( pad_model->IsOnCopperLayer() ) // a candidate is found
  1741. break;
  1742. last_pad = pad_model;
  1743. }
  1744. if( pad_model )
  1745. {
  1746. pad->SetLocalRatsnestVisible( pad_model->GetLocalRatsnestVisible() );
  1747. pad->SetPinFunction( pad_model->GetPinFunction() );
  1748. pad->SetPinType( pad_model->GetPinType() );
  1749. }
  1750. pad->SetNetCode( pad_model ? pad_model->GetNetCode() : NETINFO_LIST::UNCONNECTED );
  1751. }
  1752. // Copy reference
  1753. processTextItem( aExisting->Reference(), aNew->Reference(),
  1754. // never reset reference text
  1755. false,
  1756. resetTextLayers, resetTextEffects, aUpdated );
  1757. // Copy value
  1758. processTextItem( aExisting->Value(), aNew->Value(),
  1759. // reset value text only when it is a proxy for the footprint ID
  1760. // (cf replacing value "MountingHole-2.5mm" with "MountingHole-4.0mm")
  1761. aExisting->GetValue() == aExisting->GetFPID().GetLibItemName(),
  1762. resetTextLayers, resetTextEffects, aUpdated );
  1763. // Copy fields in accordance with the reset* flags
  1764. for( BOARD_ITEM* item : aExisting->GraphicalItems() )
  1765. {
  1766. PCB_TEXT* srcItem = dynamic_cast<PCB_TEXT*>( item );
  1767. if( srcItem )
  1768. {
  1769. PCB_TEXT* destItem = getMatchingTextItem( srcItem, aNew );
  1770. if( destItem )
  1771. {
  1772. processTextItem( *srcItem, *destItem, false, resetTextLayers, resetTextEffects,
  1773. aUpdated );
  1774. }
  1775. else if( !deleteExtraTexts )
  1776. {
  1777. aNew->Add( new PCB_TEXT( *srcItem ) );
  1778. }
  1779. }
  1780. }
  1781. for( PCB_FIELD* field : aExisting->GetFields() )
  1782. {
  1783. PCB_FIELD* newField = aNew->GetFieldByName( field->GetName() );
  1784. if( !newField )
  1785. {
  1786. newField = new PCB_FIELD( *field );
  1787. aNew->Add( newField );
  1788. processTextItem( *field, *newField, true, true, true, aUpdated );
  1789. }
  1790. else
  1791. processTextItem( *field, *newField, false, resetTextLayers, resetTextEffects, aUpdated );
  1792. }
  1793. if( resetFabricationAttrs )
  1794. {
  1795. // We've replaced the existing footprint with the library one, so the fabrication attrs
  1796. // are already reset.
  1797. //
  1798. // We only have to do anything if resetFabricationAttrs is *not* set....
  1799. }
  1800. else
  1801. {
  1802. // Careful; allow-soldermask-bridges is in the m_attributes field but is not presented
  1803. // as a fabrication attribute in the GUI....
  1804. int libraryFlagsToKeep = aNew->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES;
  1805. int existingFlagsToKeep = aExisting->GetAttributes() & ~FP_ALLOW_SOLDERMASK_BRIDGES;
  1806. aNew->SetAttributes( existingFlagsToKeep | libraryFlagsToKeep );
  1807. }
  1808. if( reset3DModels )
  1809. {
  1810. // We've replaced the existing footprint with the library one, so the 3D models are
  1811. // already reset.
  1812. //
  1813. // We only have to do anything if reset3DModels is *not* set....
  1814. }
  1815. else
  1816. {
  1817. aNew->Models() = aExisting->Models(); // Linked list of 3D models.
  1818. }
  1819. // Updating other parameters
  1820. const_cast<KIID&>( aNew->m_Uuid ) = aExisting->m_Uuid;
  1821. aNew->SetPath( aExisting->GetPath() );
  1822. aCommit.Remove( aExisting );
  1823. aCommit.Add( aNew );
  1824. aNew->ClearFlags();
  1825. }
  1826. void PCB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  1827. {
  1828. PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  1829. GetAppearancePanel()->OnColorThemeChanged();
  1830. KIGFX::PCB_VIEW* view = GetCanvas()->GetView();
  1831. KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
  1832. KIGFX::PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
  1833. renderSettings->LoadDisplayOptions( GetDisplayOptions() );
  1834. SetElementVisibility( LAYER_RATSNEST, GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest );
  1835. GetGalDisplayOptions().ReadWindowSettings( GetPcbNewSettings()->m_Window );
  1836. // Netclass definitions could have changed, either by us or by Eeschema, so we need to
  1837. // recompile the implicit rules
  1838. DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
  1839. WX_INFOBAR* infobar = GetInfoBar();
  1840. try
  1841. {
  1842. drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
  1843. if( infobar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::DRC_RULES_ERROR )
  1844. infobar->Dismiss();
  1845. }
  1846. catch( PARSE_ERROR& )
  1847. {
  1848. wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Edit design rules" ),
  1849. wxEmptyString );
  1850. button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
  1851. [&]( wxHyperlinkEvent& aEvent )
  1852. {
  1853. ShowBoardSetupDialog( _( "Custom Rules" ) );
  1854. } ) );
  1855. infobar->RemoveAllButtons();
  1856. infobar->AddButton( button );
  1857. infobar->AddCloseButton();
  1858. infobar->ShowMessage( _( "Could not compile custom design rules." ), wxICON_ERROR,
  1859. WX_INFOBAR::MESSAGE_TYPE::DRC_RULES_ERROR );
  1860. }
  1861. GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
  1862. GetCanvas()->ForceRefresh();
  1863. // Update the environment variables in the Python interpreter
  1864. if( aEnvVarsChanged )
  1865. PythonSyncEnvironmentVariables();
  1866. Layout();
  1867. SendSizeEvent();
  1868. }
  1869. void PCB_EDIT_FRAME::ThemeChanged()
  1870. {
  1871. PCB_BASE_EDIT_FRAME::ThemeChanged();
  1872. }
  1873. void PCB_EDIT_FRAME::ProjectChanged()
  1874. {
  1875. PythonSyncProjectName();
  1876. }
  1877. bool ExportBoardToHyperlynx( BOARD* aBoard, const wxFileName& aPath );
  1878. void PCB_EDIT_FRAME::OnExportHyperlynx( wxCommandEvent& event )
  1879. {
  1880. wxString wildcard = wxT( "*.hyp" );
  1881. wxFileName fn = GetBoard()->GetFileName();
  1882. fn.SetExt( wxT("hyp") );
  1883. wxFileDialog dlg( this, _( "Export Hyperlynx Layout" ), fn.GetPath(), fn.GetFullName(),
  1884. wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  1885. if( dlg.ShowModal() != wxID_OK )
  1886. return;
  1887. fn = dlg.GetPath();
  1888. // always enforce filename extension, user may not have entered it.
  1889. fn.SetExt( wxT( "hyp" ) );
  1890. ExportBoardToHyperlynx( GetBoard(), fn );
  1891. }
  1892. wxString PCB_EDIT_FRAME::GetCurrentFileName() const
  1893. {
  1894. return GetBoard()->GetFileName();
  1895. }
  1896. bool PCB_EDIT_FRAME::LayerManagerShown()
  1897. {
  1898. return m_auimgr.GetPane( wxS( "LayersManager" ) ).IsShown();
  1899. }
  1900. bool PCB_EDIT_FRAME::PropertiesShown()
  1901. {
  1902. return m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
  1903. }
  1904. void PCB_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
  1905. {
  1906. if( IsShown() )
  1907. {
  1908. // We only need this until the frame is done resizing and the final client size is
  1909. // established.
  1910. Unbind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
  1911. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
  1912. }
  1913. // Skip() is called in the base class.
  1914. EDA_DRAW_FRAME::OnSize( aEvent );
  1915. }
  1916. DIALOG_BOOK_REPORTER* PCB_EDIT_FRAME::GetInspectDrcErrorDialog()
  1917. {
  1918. if( !m_inspectDrcErrorDlg )
  1919. m_inspectDrcErrorDlg = new DIALOG_BOOK_REPORTER( this, INSPECT_DRC_ERROR_DIALOG_NAME,
  1920. _( "Violation Report" ) );
  1921. return m_inspectDrcErrorDlg;
  1922. }
  1923. DIALOG_BOOK_REPORTER* PCB_EDIT_FRAME::GetInspectClearanceDialog()
  1924. {
  1925. if( !m_inspectClearanceDlg )
  1926. m_inspectClearanceDlg = new DIALOG_BOOK_REPORTER( this, INSPECT_CLEARANCE_DIALOG_NAME,
  1927. _( "Clearance Report" ) );
  1928. return m_inspectClearanceDlg;
  1929. }
  1930. DIALOG_BOOK_REPORTER* PCB_EDIT_FRAME::GetInspectConstraintsDialog()
  1931. {
  1932. if( !m_inspectConstraintsDlg )
  1933. m_inspectConstraintsDlg = new DIALOG_BOOK_REPORTER( this, INSPECT_CONSTRAINTS_DIALOG_NAME,
  1934. _( "Constraints Report" ) );
  1935. return m_inspectConstraintsDlg;
  1936. }
  1937. DIALOG_BOOK_REPORTER* PCB_EDIT_FRAME::GetFootprintDiffDialog()
  1938. {
  1939. if( !m_footprintDiffDlg )
  1940. m_footprintDiffDlg = new DIALOG_BOOK_REPORTER( this, FOOTPRINT_DIFF_DIALOG_NAME,
  1941. _( "Diff Footprint with Library" ) );
  1942. return m_footprintDiffDlg;
  1943. }
  1944. void PCB_EDIT_FRAME::onCloseModelessBookReporterDialogs( wxCommandEvent& aEvent )
  1945. {
  1946. if( m_inspectDrcErrorDlg && aEvent.GetString() == INSPECT_DRC_ERROR_DIALOG_NAME )
  1947. {
  1948. m_inspectDrcErrorDlg->Destroy();
  1949. m_inspectDrcErrorDlg = nullptr;
  1950. }
  1951. else if( m_inspectClearanceDlg && aEvent.GetString() == INSPECT_CLEARANCE_DIALOG_NAME )
  1952. {
  1953. m_inspectClearanceDlg->Destroy();
  1954. m_inspectClearanceDlg = nullptr;
  1955. }
  1956. else if( m_inspectConstraintsDlg && aEvent.GetString() == INSPECT_CONSTRAINTS_DIALOG_NAME )
  1957. {
  1958. m_inspectConstraintsDlg->Destroy();
  1959. m_inspectConstraintsDlg = nullptr;
  1960. }
  1961. else if( m_footprintDiffDlg && aEvent.GetString() == INSPECT_CONSTRAINTS_DIALOG_NAME )
  1962. {
  1963. m_footprintDiffDlg->Destroy();
  1964. m_footprintDiffDlg = nullptr;
  1965. }
  1966. }
  1967. DIALOG_NET_INSPECTOR* PCB_EDIT_FRAME::GetNetInspectorDialog()
  1968. {
  1969. if( !m_netInspectorDlg )
  1970. {
  1971. m_netInspectorDlg = new DIALOG_NET_INSPECTOR( this );
  1972. AddBoardChangeListener( m_netInspectorDlg );
  1973. }
  1974. return m_netInspectorDlg;
  1975. }
  1976. void PCB_EDIT_FRAME::onCloseNetInspectorDialog( wxCommandEvent& aEvent )
  1977. {
  1978. if( m_netInspectorDlg )
  1979. {
  1980. RemoveBoardChangeListener( m_netInspectorDlg );
  1981. m_netInspectorDlg->Destroy();
  1982. m_netInspectorDlg = nullptr;
  1983. }
  1984. }
  1985. void PCB_EDIT_FRAME::onUnitsChanged( wxCommandEvent& aEvent )
  1986. {
  1987. wxCommandEvent evt( EDA_EVT_UNITS_CHANGED );
  1988. if( m_netInspectorDlg )
  1989. m_netInspectorDlg->HandleWindowEvent( evt );
  1990. }