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.

3230 lines
110 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
1 year ago
1 year 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
5 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 months ago
4 months ago
4 months ago
4 months ago
3 years ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months 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 The 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 <connectivity/connectivity_data.h>
  24. #include <kiface_base.h>
  25. #include <kiway.h>
  26. #include <board_design_settings.h>
  27. #include <pgm_base.h>
  28. #include <pcb_edit_frame.h>
  29. #include <3d_viewer/eda_3d_viewer_frame.h>
  30. #include <api/api_plugin_manager.h>
  31. #include <fp_lib_table.h>
  32. #include <geometry/geometry_utils.h>
  33. #include <bitmaps.h>
  34. #include <confirm.h>
  35. #include <lset.h>
  36. #include <trace_helpers.h>
  37. #include <algorithm>
  38. #include <type_traits>
  39. #include <unordered_map>
  40. #include <unordered_set>
  41. #include <vector>
  42. #include <pcbnew_id.h>
  43. #include <pcbnew_settings.h>
  44. #include <pcb_layer_box_selector.h>
  45. #include <footprint_edit_frame.h>
  46. #include <dialog_find.h>
  47. #include <dialog_footprint_properties.h>
  48. #include <dialogs/dialog_exchange_footprints.h>
  49. #include <dialog_board_setup.h>
  50. #include <dialogs/dialog_dimension_properties.h>
  51. #include <dialogs/dialog_table_properties.h>
  52. #include <gal/graphics_abstraction_layer.h>
  53. #include <pcb_target.h>
  54. #include <pcb_point.h>
  55. #include <layer_pairs.h>
  56. #include <drawing_sheet/ds_proxy_view_item.h>
  57. #include <wildcards_and_files_ext.h>
  58. #include <functional>
  59. #include <pcb_painter.h>
  60. #include <project/project_file.h>
  61. #include <project/project_local_settings.h>
  62. #include <python_scripting.h>
  63. #include <settings/common_settings.h>
  64. #include <settings/settings_manager.h>
  65. #include <tool/tool_manager.h>
  66. #include <tool/tool_dispatcher.h>
  67. #include <tool/action_toolbar.h>
  68. #include <tool/common_control.h>
  69. #include <tool/common_tools.h>
  70. #include <tool/embed_tool.h>
  71. #include <tool/properties_tool.h>
  72. #include <tool/selection.h>
  73. #include <tool/zoom_tool.h>
  74. #include <tools/array_tool.h>
  75. #include <tools/pcb_grid_helper.h>
  76. #include <tools/pcb_selection_tool.h>
  77. #include <tools/pcb_picker_tool.h>
  78. #include <tools/pcb_point_editor.h>
  79. #include <tools/edit_tool.h>
  80. #include <tools/pcb_edit_table_tool.h>
  81. #include <tools/pcb_group_tool.h>
  82. #include <tools/generator_tool.h>
  83. #include <tools/drc_tool.h>
  84. #include <tools/global_edit_tool.h>
  85. #include <tools/convert_tool.h>
  86. #include <tools/drawing_tool.h>
  87. #include <tools/pcb_control.h>
  88. #include <tools/pcb_design_block_control.h>
  89. #include <tools/board_editor_control.h>
  90. #include <tools/board_inspection_tool.h>
  91. #include <tools/pcb_editor_conditions.h>
  92. #include <tools/pcb_viewer_tools.h>
  93. #include <tools/board_reannotate_tool.h>
  94. #include <tools/align_distribute_tool.h>
  95. #include <tools/pad_tool.h>
  96. #include <microwave/microwave_tool.h>
  97. #include <tools/position_relative_tool.h>
  98. #include <tools/zone_filler_tool.h>
  99. #include <tools/multichannel_tool.h>
  100. #include <router/router_tool.h>
  101. #include <autorouter/autoplace_tool.h>
  102. #include <python/scripting/pcb_scripting_tool.h>
  103. #include <netlist_reader/netlist_reader.h>
  104. #include <wx/socket.h>
  105. #include <wx/wupdlock.h>
  106. #include <dialog_drc.h> // for DIALOG_DRC_WINDOW_NAME definition
  107. #include <ratsnest/ratsnest_view_item.h>
  108. #include <widgets/appearance_controls.h>
  109. #include <widgets/pcb_design_block_pane.h>
  110. #include <widgets/pcb_search_pane.h>
  111. #include <widgets/wx_infobar.h>
  112. #include <widgets/panel_selection_filter.h>
  113. #include <widgets/pcb_properties_panel.h>
  114. #include <widgets/pcb_net_inspector_panel.h>
  115. #include <widgets/wx_aui_utils.h>
  116. #include <kiplatform/app.h>
  117. #include <kiplatform/ui.h>
  118. #include <core/profile.h>
  119. #include <math/box2_minmax.h>
  120. #include <view/wx_view_controls.h>
  121. #include <footprint_viewer_frame.h>
  122. #include <footprint_chooser_frame.h>
  123. #include <toolbars_pcb_editor.h>
  124. #include <wx/log.h>
  125. #ifdef KICAD_IPC_API
  126. #include <api/api_server.h>
  127. #include <api/api_handler_pcb.h>
  128. #include <api/api_handler_common.h>
  129. #include <api/api_utils.h>
  130. #endif
  131. #include <action_plugin.h>
  132. #include <pcbnew_scripting_helpers.h>
  133. #include "../scripting/python_scripting.h"
  134. #include <wx/filedlg.h>
  135. using namespace std::placeholders;
  136. #define INSPECT_DRC_ERROR_DIALOG_NAME wxT( "InspectDrcErrorDialog" )
  137. #define INSPECT_CLEARANCE_DIALOG_NAME wxT( "InspectClearanceDialog" )
  138. #define INSPECT_CONSTRAINTS_DIALOG_NAME wxT( "InspectConstraintsDialog" )
  139. #define FOOTPRINT_DIFF_DIALOG_NAME wxT( "FootprintDiffDialog" )
  140. BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
  141. EVT_SOCKET( ID_EDA_SOCKET_EVENT_SERV, PCB_EDIT_FRAME::OnSockRequestServer )
  142. EVT_SOCKET( ID_EDA_SOCKET_EVENT, PCB_EDIT_FRAME::OnSockRequest )
  143. EVT_CHOICE( ID_ON_ZOOM_SELECT, PCB_EDIT_FRAME::OnSelectZoom )
  144. EVT_CHOICE( ID_ON_GRID_SELECT, PCB_EDIT_FRAME::OnSelectGrid )
  145. EVT_SIZE( PCB_EDIT_FRAME::OnSize )
  146. // Menu Files:
  147. EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, PCB_EDIT_FRAME::OnFileHistory )
  148. EVT_MENU( ID_FILE_LIST_CLEAR, PCB_EDIT_FRAME::OnClearFileHistory )
  149. EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit )
  150. EVT_MENU( wxID_CLOSE, PCB_EDIT_FRAME::OnQuit )
  151. // Horizontal toolbar
  152. EVT_CHOICE( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
  153. EVT_CHOICE( ID_AUX_TOOLBAR_PCB_VIA_SIZE, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
  154. // Tracks and vias sizes general options
  155. EVT_MENU_RANGE( ID_POPUP_PCB_SELECT_WIDTH_START_RANGE, ID_POPUP_PCB_SELECT_WIDTH_END_RANGE,
  156. PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event )
  157. // User interface update event handlers.
  158. EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
  159. EVT_UPDATE_UI( ID_AUX_TOOLBAR_PCB_VIA_SIZE, PCB_EDIT_FRAME::OnUpdateSelectViaSize )
  160. EVT_UPDATE_UI_RANGE( ID_POPUP_PCB_SELECT_WIDTH1, ID_POPUP_PCB_SELECT_WIDTH8,
  161. PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
  162. EVT_UPDATE_UI_RANGE( ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_VIASIZE8,
  163. PCB_EDIT_FRAME::OnUpdateSelectViaSize )
  164. // Drop files event
  165. EVT_DROP_FILES( PCB_EDIT_FRAME::OnDropFiles )
  166. END_EVENT_TABLE()
  167. PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  168. PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, _( "PCB Editor" ),
  169. wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE,
  170. PCB_EDIT_FRAME_NAME ),
  171. m_exportNetlistAction( nullptr ),
  172. m_findDialog( nullptr ),
  173. m_inspectDrcErrorDlg( nullptr ),
  174. m_inspectClearanceDlg( nullptr ),
  175. m_inspectConstraintsDlg( nullptr ),
  176. m_footprintDiffDlg( nullptr ),
  177. m_boardSetupDlg( nullptr ),
  178. m_designBlocksPane( nullptr ),
  179. m_importProperties( nullptr ),
  180. m_eventCounterTimer( nullptr )
  181. {
  182. m_maximizeByDefault = true;
  183. m_showBorderAndTitleBlock = true; // true to display sheet references
  184. m_SelTrackWidthBox = nullptr;
  185. m_SelViaSizeBox = nullptr;
  186. m_show_layer_manager_tools = true;
  187. m_supportsAutoSave = true;
  188. m_probingSchToPcb = false;
  189. m_show_search = false;
  190. m_show_net_inspector = false;
  191. // Ensure timer has an owner before binding so it generates events.
  192. m_crossProbeFlashTimer.SetOwner( this );
  193. Bind( wxEVT_TIMER, &PCB_EDIT_FRAME::OnCrossProbeFlashTimer, this, m_crossProbeFlashTimer.GetId() );
  194. // We don't know what state board was in when it was last saved, so we have to
  195. // assume dirty
  196. m_ZoneFillsDirty = true;
  197. m_aboutTitle = _HKI( "KiCad PCB Editor" );
  198. // Must be created before the menus are created.
  199. if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist )
  200. {
  201. m_exportNetlistAction = new TOOL_ACTION( "pcbnew.EditorControl.exportNetlist",
  202. AS_GLOBAL, 0, "", _( "Netlist..." ),
  203. _( "Export netlist used to update schematics" ) );
  204. }
  205. // Create GAL canvas
  206. auto canvas = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
  207. GetGalDisplayOptions(),
  208. EDA_DRAW_PANEL_GAL::GAL_FALLBACK );
  209. SetCanvas( canvas );
  210. SetBoard( new BOARD() );
  211. wxIcon icon;
  212. wxIconBundle icon_bundle;
  213. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew, 48 ) );
  214. icon_bundle.AddIcon( icon );
  215. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew, 128 ) );
  216. icon_bundle.AddIcon( icon );
  217. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew, 256 ) );
  218. icon_bundle.AddIcon( icon );
  219. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_32 ) );
  220. icon_bundle.AddIcon( icon );
  221. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_16 ) );
  222. icon_bundle.AddIcon( icon );
  223. SetIcons( icon_bundle );
  224. // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
  225. // initialize parameters in m_LayersManager
  226. LoadSettings( config() );
  227. SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU( pcbIUScale.IU_PER_MILS ) ) );
  228. // PCB drawings start in the upper left corner.
  229. GetScreen()->m_Center = false;
  230. setupTools();
  231. setupUIConditions();
  232. m_toolbarSettings = GetToolbarSettings<PCB_EDIT_TOOLBAR_SETTINGS>( "pcbnew-toolbars" );
  233. configureToolbars();
  234. RecreateToolbars();
  235. PrepareLayerIndicator( true );
  236. ReCreateMenuBar();
  237. #ifdef KICAD_IPC_API
  238. wxTheApp->Bind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED,
  239. &PCB_EDIT_FRAME::onPluginAvailabilityChanged, this );
  240. #endif
  241. // Fetch a COPY of the config as a lot of these initializations are going to overwrite our
  242. // data.
  243. PCBNEW_SETTINGS::AUI_PANELS aui_cfg = GetPcbNewSettings()->m_AuiPanels;
  244. m_propertiesPanel = new PCB_PROPERTIES_PANEL( this, this );
  245. m_propertiesPanel->SetSplitterProportion( aui_cfg.properties_splitter );
  246. m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this );
  247. m_appearancePanel = new APPEARANCE_CONTROLS( this, GetCanvas() );
  248. m_searchPane = new PCB_SEARCH_PANE( this );
  249. m_netInspectorPanel = new PCB_NET_INSPECTOR_PANEL( this, this );
  250. m_designBlocksPane = new PCB_DESIGN_BLOCK_PANE( this, nullptr, m_designBlockHistoryList );
  251. m_auimgr.SetManagedWindow( this );
  252. CreateInfoBar();
  253. unsigned int auiFlags = wxAUI_MGR_DEFAULT;
  254. #if !defined( _WIN32 )
  255. // Windows cannot redraw the UI fast enough during a live resize and may lead to all kinds
  256. // of graphical glitches.
  257. auiFlags |= wxAUI_MGR_LIVE_RESIZE;
  258. #endif
  259. m_auimgr.SetFlags( auiFlags );
  260. // Rows; layers 4 - 6
  261. m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( wxS( "TopMainToolbar" ) )
  262. .Top().Layer( 6 ) );
  263. m_auimgr.AddPane( m_tbTopAux, EDA_PANE().HToolbar().Name( wxS( "TopAuxToolbar" ) )
  264. .Top().Layer( 5 ) );
  265. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( wxS( "MsgPanel" ) )
  266. .Bottom().Layer( 6 ) );
  267. // Columns; layers 1 - 3
  268. m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( wxS( "LeftToolbar" ) )
  269. .Left().Layer( 3 ) );
  270. m_auimgr.AddPane( m_tbRight, EDA_PANE().VToolbar().Name( wxS( "RightToolbar" ) )
  271. .Right().Layer( 3 ) );
  272. m_auimgr.AddPane( m_appearancePanel, EDA_PANE().Name( wxS( "LayersManager" ) )
  273. .Right().Layer( 4 )
  274. .Caption( _( "Appearance" ) ).PaneBorder( false )
  275. .MinSize( m_appearancePanel->GetMinSize().x, -1 )
  276. #ifdef __WXMAC__
  277. // Best size for this pane is calculated larger than necessary on wxMac
  278. .BestSize( m_appearancePanel->GetMinSize().x, -1 )
  279. #else
  280. .BestSize( m_appearancePanel->GetBestSize().x, -1 )
  281. #endif
  282. .FloatingSize( m_appearancePanel->GetBestSize() )
  283. .CloseButton( false ) );
  284. m_auimgr.AddPane( m_selectionFilterPanel, EDA_PANE().Name( wxS( "SelectionFilter" ) )
  285. .Right().Layer( 4 ).Position( 2 )
  286. .Caption( _( "Selection Filter" ) ).PaneBorder( false )
  287. .MinSize( m_selectionFilterPanel->GetMinSize().x, -1 )
  288. .BestSize( m_selectionFilterPanel->GetBestSize().x, -1 )
  289. .FloatingSize( m_selectionFilterPanel->GetBestSize() )
  290. .CloseButton( false ) );
  291. m_auimgr.AddPane( m_designBlocksPane, EDA_PANE().Name( DesignBlocksPaneName() )
  292. .Right().Layer( 5 )
  293. .Caption( _( "Design Blocks" ) )
  294. .CaptionVisible( true )
  295. .PaneBorder( true )
  296. .TopDockable( false )
  297. .BottomDockable( false )
  298. .CloseButton( true )
  299. .MinSize( FromDIP( wxSize( 240, 60 ) ) )
  300. .BestSize( FromDIP( wxSize( 300, 200 ) ) )
  301. .FloatingSize( FromDIP( wxSize( 800, 600 ) ) )
  302. .FloatingPosition( FromDIP( wxPoint( 50, 200 ) ) )
  303. .Show( true ) );
  304. m_auimgr.AddPane( m_propertiesPanel, EDA_PANE().Name( PropertiesPaneName() )
  305. .Left().Layer( 5 )
  306. .Caption( _( "Properties" ) ).PaneBorder( false )
  307. .MinSize( FromDIP( wxSize( 240, 60 ) ) )
  308. .BestSize( FromDIP( wxSize( 300, 200 ) ) )
  309. .FloatingSize( wxSize( 300, 200 ) )
  310. .CloseButton( true ) );
  311. // Center
  312. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( wxS( "DrawFrame" ) )
  313. .Center() );
  314. m_auimgr.AddPane( m_netInspectorPanel, EDA_PANE().Name( NetInspectorPanelName() )
  315. .Bottom()
  316. .Caption( _( "Net Inspector" ) )
  317. .PaneBorder( false )
  318. .MinSize( FromDIP( wxSize( 240, 60 ) ) )
  319. .BestSize( FromDIP( wxSize( 300, 200 ) ) )
  320. .FloatingSize( wxSize( 300, 200 ) )
  321. .CloseButton( true ) );
  322. m_auimgr.AddPane( m_searchPane, EDA_PANE().Name( SearchPaneName() )
  323. .Bottom()
  324. .Caption( _( "Search" ) ).PaneBorder( false )
  325. .MinSize( FromDIP( wxSize ( 180, 60 ) ) )
  326. .BestSize( FromDIP( wxSize ( 180, 100 ) ) )
  327. .FloatingSize( FromDIP( wxSize( 480, 200 ) ) )
  328. .DestroyOnClose( false )
  329. .CloseButton( true ) );
  330. RestoreAuiLayout();
  331. m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
  332. m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools );
  333. m_auimgr.GetPane( PropertiesPaneName() ).Show( GetPcbNewSettings()->m_AuiPanels.show_properties );
  334. m_auimgr.GetPane( NetInspectorPanelName() ).Show( m_show_net_inspector );
  335. m_auimgr.GetPane( SearchPaneName() ).Show( m_show_search );
  336. m_auimgr.GetPane( DesignBlocksPaneName() ).Show( GetPcbNewSettings()->m_AuiPanels.design_blocks_show );
  337. // The selection filter doesn't need to grow in the vertical direction when docked
  338. m_auimgr.GetPane( "SelectionFilter" ).dock_proportion = 0;
  339. FinishAUIInitialization();
  340. if( aui_cfg.right_panel_width > 0 )
  341. {
  342. wxAuiPaneInfo& layersManager = m_auimgr.GetPane( wxS( "LayersManager" ) );
  343. SetAuiPaneSize( m_auimgr, layersManager, aui_cfg.right_panel_width, -1 );
  344. wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
  345. SetAuiPaneSize( m_auimgr, designBlocksPane, aui_cfg.design_blocks_panel_docked_width, -1 );
  346. }
  347. if( aui_cfg.properties_panel_width > 0 && m_propertiesPanel )
  348. {
  349. wxAuiPaneInfo& propertiesPanel = m_auimgr.GetPane( PropertiesPaneName() );
  350. SetAuiPaneSize( m_auimgr, propertiesPanel, aui_cfg.properties_panel_width, -1 );
  351. }
  352. if( aui_cfg.search_panel_height > 0
  353. && ( aui_cfg.search_panel_dock_direction == wxAUI_DOCK_TOP
  354. || aui_cfg.search_panel_dock_direction == wxAUI_DOCK_BOTTOM ) )
  355. {
  356. wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
  357. searchPane.Direction( aui_cfg.search_panel_dock_direction );
  358. SetAuiPaneSize( m_auimgr, searchPane, -1, aui_cfg.search_panel_height );
  359. }
  360. else if( aui_cfg.search_panel_width > 0
  361. && ( aui_cfg.search_panel_dock_direction == wxAUI_DOCK_LEFT
  362. || aui_cfg.search_panel_dock_direction == wxAUI_DOCK_RIGHT ) )
  363. {
  364. wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
  365. searchPane.Direction( aui_cfg.search_panel_dock_direction );
  366. SetAuiPaneSize( m_auimgr, searchPane, aui_cfg.search_panel_width, -1 );
  367. }
  368. m_appearancePanel->SetTabIndex( aui_cfg.appearance_panel_tab );
  369. {
  370. m_layerPairSettings = std::make_unique<LAYER_PAIR_SETTINGS>();
  371. m_layerPairSettings->Bind( PCB_LAYER_PAIR_PRESETS_CHANGED, [&]( wxCommandEvent& aEvt )
  372. {
  373. // Update the project file list
  374. std::span<const LAYER_PAIR_INFO> newPairInfos = m_layerPairSettings->GetLayerPairs();
  375. Prj().GetProjectFile().m_LayerPairInfos =
  376. std::vector<LAYER_PAIR_INFO>{ newPairInfos.begin(), newPairInfos.end() };
  377. });
  378. m_layerPairSettings->Bind( PCB_CURRENT_LAYER_PAIR_CHANGED, [&]( wxCommandEvent& aEvt )
  379. {
  380. const LAYER_PAIR& layerPair = m_layerPairSettings->GetCurrentLayerPair();
  381. PCB_SCREEN& screen = *GetScreen();
  382. screen.m_Route_Layer_TOP = layerPair.GetLayerA();
  383. screen.m_Route_Layer_BOTTOM = layerPair.GetLayerB();
  384. // Update the toolbar icon
  385. PrepareLayerIndicator();
  386. });
  387. }
  388. GetToolManager()->PostAction( ACTIONS::zoomFitScreen );
  389. // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
  390. // to calculate the wrong zoom size. See PCB_EDIT_FRAME::onSize().
  391. Bind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
  392. Bind( wxEVT_IDLE,
  393. [this]( wxIdleEvent& aEvent )
  394. {
  395. BOX2D viewport = GetCanvas()->GetView()->GetViewport();
  396. if( viewport != m_lastNetnamesViewport )
  397. {
  398. redrawNetnames();
  399. m_lastNetnamesViewport = viewport;
  400. }
  401. // Do not forget to pass the Idle event to other clients:
  402. aEvent.Skip();
  403. } );
  404. resolveCanvasType();
  405. setupUnits( config() );
  406. // Ensure the DRC engine is initialized so that constraints can be resolved even before a
  407. // board is loaded or saved
  408. try
  409. {
  410. m_toolManager->GetTool<DRC_TOOL>()->GetDRCEngine()->InitEngine( wxFileName() );
  411. }
  412. catch( PARSE_ERROR& )
  413. {
  414. }
  415. // Ensure the Python interpreter is up to date with its environment variables
  416. PythonSyncEnvironmentVariables();
  417. PythonSyncProjectName();
  418. // Sync action plugins in case they changed since the last time the frame opened
  419. GetToolManager()->RunAction( ACTIONS::pluginsReload );
  420. #ifdef KICAD_IPC_API
  421. m_apiHandler = std::make_unique<API_HANDLER_PCB>( this );
  422. Pgm().GetApiServer().RegisterHandler( m_apiHandler.get() );
  423. if( Kiface().IsSingle() )
  424. {
  425. m_apiHandlerCommon = std::make_unique<API_HANDLER_COMMON>();
  426. Pgm().GetApiServer().RegisterHandler( m_apiHandlerCommon.get() );
  427. }
  428. #endif
  429. GetCanvas()->SwitchBackend( m_canvasType );
  430. ActivateGalCanvas();
  431. // Default shutdown reason until a file is loaded
  432. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New PCB file is unsaved" ) );
  433. // disable Export STEP item if kicad2step does not exist
  434. wxString strK2S = Pgm().GetExecutablePath();
  435. #ifdef __WXMAC__
  436. if( strK2S.Find( wxT( "pcbnew.app" ) ) != wxNOT_FOUND )
  437. {
  438. // On macOS, we have standalone applications inside the main bundle, so we handle that here:
  439. strK2S += wxT( "../../" );
  440. }
  441. strK2S += wxT( "Contents/MacOS/" );
  442. #endif
  443. wxFileName appK2S( strK2S, wxT( "kicad2step" ) );
  444. #ifdef _WIN32
  445. appK2S.SetExt( wxT( "exe" ) );
  446. #endif
  447. // Ensure the window is on top
  448. Raise();
  449. // if( !appK2S.FileExists() )
  450. // GetMenuBar()->FindItem( ID_GEN_EXPORT_FILE_STEP )->Enable( false );
  451. // AUI doesn't refresh properly on wxMac after changes in eb7dc6dd, so force it to
  452. #ifdef __WXMAC__
  453. if( Kiface().IsSingle() )
  454. {
  455. CallAfter( [this]()
  456. {
  457. m_appearancePanel->OnBoardChanged();
  458. } );
  459. }
  460. #endif
  461. // Register a call to update the toolbar sizes. It can't be done immediately because
  462. // it seems to require some sizes calculated that aren't yet (at least on GTK).
  463. CallAfter( [this]()
  464. {
  465. // Ensure the controls on the toolbars all are correctly sized
  466. UpdateToolbarControlSizes();
  467. } );
  468. if( ADVANCED_CFG::GetCfg().m_ShowEventCounters )
  469. {
  470. m_eventCounterTimer = new wxTimer( this );
  471. Bind( wxEVT_TIMER,
  472. [&]( wxTimerEvent& aEvent )
  473. {
  474. GetCanvas()->m_PaintEventCounter->Show();
  475. GetCanvas()->m_PaintEventCounter->Reset();
  476. KIGFX::WX_VIEW_CONTROLS* vc =
  477. static_cast<KIGFX::WX_VIEW_CONTROLS*>( GetCanvas()->GetViewControls() );
  478. vc->m_MotionEventCounter->Show();
  479. vc->m_MotionEventCounter->Reset();
  480. },
  481. m_eventCounterTimer->GetId() );
  482. m_eventCounterTimer->Start( 1000 );
  483. }
  484. m_acceptedExts.emplace( FILEEXT::KiCadPcbFileExtension, &PCB_ACTIONS::ddAppendBoard );
  485. m_acceptedExts.emplace( FILEEXT::LegacyPcbFileExtension, &PCB_ACTIONS::ddAppendBoard );
  486. m_acceptedExts.emplace( wxS( "dxf" ), &PCB_ACTIONS::ddImportGraphics );
  487. m_acceptedExts.emplace( FILEEXT::SVGFileExtension, &PCB_ACTIONS::ddImportGraphics );
  488. DragAcceptFiles( true );
  489. Bind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &PCB_EDIT_FRAME::onCloseModelessBookReporterDialogs, this );
  490. }
  491. void PCB_EDIT_FRAME::StartCrossProbeFlash( const std::vector<BOARD_ITEM*>& aItems )
  492. {
  493. if( !GetPcbNewSettings()->m_CrossProbing.flash_selection )
  494. {
  495. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash(PCB): aborted (setting disabled) items=%zu", aItems.size() );
  496. return;
  497. }
  498. if( aItems.empty() )
  499. {
  500. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash(PCB): aborted (no items)" );
  501. return;
  502. }
  503. if( m_crossProbeFlashing )
  504. {
  505. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash(PCB): restarting existing flash (phase=%d)" , m_crossProbeFlashPhase );
  506. m_crossProbeFlashTimer.Stop();
  507. }
  508. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash(PCB): starting with %zu items", aItems.size() );
  509. // Store uuids
  510. m_crossProbeFlashItems.clear();
  511. for( BOARD_ITEM* it : aItems )
  512. m_crossProbeFlashItems.push_back( it->m_Uuid );
  513. m_crossProbeFlashPhase = 0;
  514. m_crossProbeFlashing = true;
  515. if( !m_crossProbeFlashTimer.GetOwner() )
  516. m_crossProbeFlashTimer.SetOwner( this );
  517. bool started = m_crossProbeFlashTimer.Start( 500, wxTIMER_CONTINUOUS ); // 0.5s intervals -> 3s total for 6 phases
  518. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash(PCB): timer start=%d id=%d", (int) started, m_crossProbeFlashTimer.GetId() );
  519. }
  520. void PCB_EDIT_FRAME::OnCrossProbeFlashTimer( wxTimerEvent& aEvent )
  521. {
  522. wxLogTrace( "CROSS_PROBE_FLASH", "Timer(PCB) fired: phase=%d running=%d items=%zu", m_crossProbeFlashPhase, (int) m_crossProbeFlashing, m_crossProbeFlashItems.size() );
  523. if( !m_crossProbeFlashing )
  524. {
  525. wxLogTrace( "CROSS_PROBE_FLASH", "Timer(PCB) fired but not flashing (ignored)" );
  526. return;
  527. }
  528. PCB_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
  529. if( !selTool )
  530. return;
  531. // Prevent recursion / IPC during flashing
  532. bool prevGuard = m_probingSchToPcb;
  533. m_probingSchToPcb = true;
  534. if( m_crossProbeFlashPhase % 2 == 0 )
  535. {
  536. // Hide selection
  537. selTool->ClearSelection( true );
  538. wxLogTrace( "CROSS_PROBE_FLASH", "Phase %d (PCB): cleared selection", m_crossProbeFlashPhase );
  539. }
  540. else
  541. {
  542. // Restore selection
  543. for( const KIID& id : m_crossProbeFlashItems )
  544. {
  545. if( EDA_ITEM* item = GetBoard()->ResolveItem( id, true ) )
  546. selTool->AddItemToSel( item, true );
  547. }
  548. wxLogTrace( "CROSS_PROBE_FLASH", "Phase %d (PCB): restored %zu items", m_crossProbeFlashPhase, m_crossProbeFlashItems.size() );
  549. }
  550. // Force a redraw even if the canvas / frame does not currently have focus (mouse elsewhere)
  551. if( GetCanvas() )
  552. {
  553. GetCanvas()->ForceRefresh();
  554. wxLogTrace( "CROSS_PROBE_FLASH", "Phase %d (PCB): forced canvas refresh", m_crossProbeFlashPhase );
  555. }
  556. m_probingSchToPcb = prevGuard;
  557. m_crossProbeFlashPhase++;
  558. if( m_crossProbeFlashPhase > 6 )
  559. {
  560. // Ensure final state (selected)
  561. for( const KIID& id : m_crossProbeFlashItems )
  562. {
  563. if( EDA_ITEM* item = GetBoard()->ResolveItem( id, true ) )
  564. selTool->AddItemToSel( item, true );
  565. }
  566. m_crossProbeFlashing = false;
  567. m_crossProbeFlashTimer.Stop();
  568. wxLogTrace( "CROSS_PROBE_FLASH", "Flashing complete (PCB). Final selection size=%zu", m_crossProbeFlashItems.size() );
  569. }
  570. }
  571. PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
  572. {
  573. ScriptingOnDestructPcbEditFrame( this );
  574. if( ADVANCED_CFG::GetCfg().m_ShowEventCounters )
  575. {
  576. // Stop the timer during destruction early to avoid potential event race conditions (that
  577. // do happen on windows)
  578. m_eventCounterTimer->Stop();
  579. delete m_eventCounterTimer;
  580. }
  581. // Close modeless dialogs
  582. wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
  583. if( open_dlg )
  584. open_dlg->Close( true );
  585. // Shutdown all running tools
  586. if( m_toolManager )
  587. m_toolManager->ShutdownAllTools();
  588. if( GetBoard() )
  589. GetBoard()->RemoveAllListeners();
  590. // We passed ownership of these to wxAuiManager.
  591. // delete m_selectionFilterPanel;
  592. // delete m_appearancePanel;
  593. // delete m_propertiesPanel;
  594. // delete m_netInspectorPanel;
  595. delete m_exportNetlistAction;
  596. }
  597. void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard, bool aBuildConnectivity,
  598. PROGRESS_REPORTER* aReporter )
  599. {
  600. if( m_pcb )
  601. m_pcb->ClearProject();
  602. PCB_BASE_EDIT_FRAME::SetBoard( aBoard, aReporter );
  603. aBoard->SetProject( &Prj() );
  604. if( aBuildConnectivity )
  605. aBoard->BuildConnectivity();
  606. // reload the drawing-sheet
  607. SetPageSettings( aBoard->GetPageSettings() );
  608. }
  609. BOARD_ITEM_CONTAINER* PCB_EDIT_FRAME::GetModel() const
  610. {
  611. return m_pcb;
  612. }
  613. std::unique_ptr<GRID_HELPER> PCB_EDIT_FRAME::MakeGridHelper()
  614. {
  615. return std::make_unique<PCB_GRID_HELPER>( m_toolManager, GetMagneticItemsSettings() );
  616. }
  617. void PCB_EDIT_FRAME::redrawNetnames()
  618. {
  619. /*
  620. * While new items being scrolled into the view will get painted, they will only get
  621. * annotated with netname instances currently within the view. Subsequent panning will not
  622. * draw newly-visible netname instances because the item has already been drawn.
  623. *
  624. * This routine, fired on idle if the viewport has changed, looks for visible items that
  625. * might have multiple netname instances and redraws them. (It does not need to handle pads
  626. * and vias because they only ever have a single netname instance drawn on them.)
  627. */
  628. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
  629. if( !cfg || cfg->m_Display.m_NetNames < 2 )
  630. return;
  631. KIGFX::VIEW* view = GetCanvas()->GetView();
  632. BOX2D viewport = view->GetViewport();
  633. // Inflate to catch most of the track width
  634. BOX2I_MINMAX clipbox( BOX2ISafe( viewport.Inflate( pcbIUScale.mmToIU( 2.0 ) ) ) );
  635. for( PCB_TRACK* track : GetBoard()->Tracks() )
  636. {
  637. // Don't need to update vias
  638. if( track->Type() == PCB_VIA_T )
  639. continue;
  640. // Don't update invisible tracks
  641. if( !clipbox.Intersects( BOX2I_MINMAX( track->GetStart(), track->GetEnd() ) ) )
  642. continue;
  643. if( track->ViewGetLOD( GetNetnameLayer( track->GetLayer() ), view ) < view->GetScale() )
  644. view->Update( track, KIGFX::REPAINT );
  645. }
  646. }
  647. void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
  648. {
  649. PCB_BASE_FRAME::SetPageSettings( aPageSettings );
  650. // Prepare drawing-sheet template
  651. DS_PROXY_VIEW_ITEM* drawingSheet = new DS_PROXY_VIEW_ITEM( pcbIUScale,
  652. &m_pcb->GetPageSettings(),
  653. m_pcb->GetProject(),
  654. &m_pcb->GetTitleBlock(),
  655. &m_pcb->GetProperties() );
  656. drawingSheet->SetSheetName( std::string( GetScreenDesc().mb_str() ) );
  657. drawingSheet->SetSheetPath( std::string( GetFullScreenDesc().mb_str() ) );
  658. // A board is not like a schematic having a main page and sub sheets.
  659. // So for the drawing sheet, use only the first page option to display items
  660. drawingSheet->SetIsFirstPage( true );
  661. BASE_SCREEN* screen = GetScreen();
  662. if( screen != nullptr )
  663. {
  664. drawingSheet->SetPageNumber(TO_UTF8( screen->GetPageNumber() ) );
  665. drawingSheet->SetSheetCount( screen->GetPageCount() );
  666. }
  667. if( BOARD* board = GetBoard() )
  668. drawingSheet->SetFileName( TO_UTF8( board->GetFileName() ) );
  669. // PCB_DRAW_PANEL_GAL takes ownership of the drawing-sheet
  670. GetCanvas()->SetDrawingSheet( drawingSheet );
  671. }
  672. bool PCB_EDIT_FRAME::IsContentModified() const
  673. {
  674. return GetScreen() && GetScreen()->IsContentModified();
  675. }
  676. SELECTION& PCB_EDIT_FRAME::GetCurrentSelection()
  677. {
  678. return m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
  679. }
  680. void PCB_EDIT_FRAME::setupTools()
  681. {
  682. // Create the manager and dispatcher & route draw panel events to the dispatcher
  683. m_toolManager = new TOOL_MANAGER;
  684. m_toolManager->SetEnvironment( m_pcb, GetCanvas()->GetView(),
  685. GetCanvas()->GetViewControls(), config(), this );
  686. m_actions = new PCB_ACTIONS();
  687. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  688. // Register tools
  689. m_toolManager->RegisterTool( new COMMON_CONTROL );
  690. m_toolManager->RegisterTool( new COMMON_TOOLS );
  691. m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
  692. m_toolManager->RegisterTool( new ZOOM_TOOL );
  693. m_toolManager->RegisterTool( new PCB_PICKER_TOOL );
  694. m_toolManager->RegisterTool( new ROUTER_TOOL );
  695. m_toolManager->RegisterTool( new EDIT_TOOL );
  696. m_toolManager->RegisterTool( new PCB_EDIT_TABLE_TOOL );
  697. m_toolManager->RegisterTool( new GLOBAL_EDIT_TOOL );
  698. m_toolManager->RegisterTool( new PAD_TOOL );
  699. m_toolManager->RegisterTool( new DRAWING_TOOL );
  700. m_toolManager->RegisterTool( new PCB_POINT_EDITOR );
  701. m_toolManager->RegisterTool( new PCB_CONTROL );
  702. m_toolManager->RegisterTool( new PCB_DESIGN_BLOCK_CONTROL );
  703. m_toolManager->RegisterTool( new BOARD_EDITOR_CONTROL );
  704. m_toolManager->RegisterTool( new BOARD_INSPECTION_TOOL );
  705. m_toolManager->RegisterTool( new BOARD_REANNOTATE_TOOL );
  706. m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL );
  707. m_toolManager->RegisterTool( new MICROWAVE_TOOL );
  708. m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL );
  709. m_toolManager->RegisterTool( new ARRAY_TOOL );
  710. m_toolManager->RegisterTool( new ZONE_FILLER_TOOL );
  711. m_toolManager->RegisterTool( new AUTOPLACE_TOOL );
  712. m_toolManager->RegisterTool( new DRC_TOOL );
  713. m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
  714. m_toolManager->RegisterTool( new CONVERT_TOOL );
  715. m_toolManager->RegisterTool( new PCB_GROUP_TOOL );
  716. m_toolManager->RegisterTool( new GENERATOR_TOOL );
  717. m_toolManager->RegisterTool( new SCRIPTING_TOOL );
  718. m_toolManager->RegisterTool( new PROPERTIES_TOOL );
  719. m_toolManager->RegisterTool( new MULTICHANNEL_TOOL );
  720. m_toolManager->RegisterTool( new EMBED_TOOL );
  721. m_toolManager->InitTools();
  722. for( TOOL_BASE* tool : m_toolManager->Tools() )
  723. {
  724. if( PCB_TOOL_BASE* pcbTool = dynamic_cast<PCB_TOOL_BASE*>( tool ) )
  725. pcbTool->SetIsBoardEditor( true );
  726. }
  727. // Run the selection tool, it is supposed to be always active
  728. m_toolManager->InvokeTool( "common.InteractiveSelection" );
  729. }
  730. void PCB_EDIT_FRAME::setupUIConditions()
  731. {
  732. PCB_BASE_EDIT_FRAME::setupUIConditions();
  733. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  734. PCB_EDITOR_CONDITIONS cond( this );
  735. auto undoCond =
  736. [ this ] (const SELECTION& aSel )
  737. {
  738. DRAWING_TOOL* drawingTool = m_toolManager->GetTool<DRAWING_TOOL>();
  739. if( drawingTool && drawingTool->GetDrawingMode() != DRAWING_TOOL::MODE::NONE )
  740. return true;
  741. ROUTER_TOOL* routerTool = m_toolManager->GetTool<ROUTER_TOOL>();
  742. if( routerTool && routerTool->RoutingInProgress() )
  743. return true;
  744. return GetUndoCommandCount() > 0;
  745. };
  746. auto groupWithDesignBlockLink =
  747. [] ( const SELECTION& aSel )
  748. {
  749. if( aSel.Size() != 1 )
  750. return false;
  751. if( aSel[0]->Type() != PCB_GROUP_T )
  752. return false;
  753. PCB_GROUP* group = static_cast<PCB_GROUP*>( aSel.GetItem( 0 ) );
  754. return group->HasDesignBlockLink();
  755. };
  756. wxASSERT( mgr );
  757. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  758. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  759. // clang-format off
  760. mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  761. mgr->SetConditions( ACTIONS::undo, ENABLE( undoCond ) );
  762. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  763. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  764. mgr->SetConditions( ACTIONS::toggleGridOverrides, CHECK( cond.GridOverrides() ) );
  765. mgr->SetConditions( ACTIONS::togglePolarCoords, CHECK( cond.PolarCoordinates() ) );
  766. mgr->SetConditions( ACTIONS::cut, ENABLE( cond.HasItems() ) );
  767. mgr->SetConditions( ACTIONS::copy, ENABLE( cond.HasItems() ) );
  768. mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
  769. mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
  770. mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );
  771. mgr->SetConditions( ACTIONS::unselectAll, ENABLE( cond.HasItems() ) );
  772. mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
  773. mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );
  774. static const std::vector<KICAD_T> groupTypes = { PCB_GROUP_T, PCB_GENERATOR_T };
  775. mgr->SetConditions( ACTIONS::group, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  776. mgr->SetConditions( ACTIONS::ungroup, ENABLE( SELECTION_CONDITIONS::HasTypes( groupTypes ) ) );
  777. mgr->SetConditions( PCB_ACTIONS::lock, ENABLE( PCB_SELECTION_CONDITIONS::HasUnlockedItems ) );
  778. mgr->SetConditions( PCB_ACTIONS::unlock, ENABLE( PCB_SELECTION_CONDITIONS::HasLockedItems ) );
  779. mgr->SetConditions( PCB_ACTIONS::placeLinkedDesignBlock, ENABLE( groupWithDesignBlockLink) );
  780. mgr->SetConditions( PCB_ACTIONS::saveToLinkedDesignBlock, ENABLE( groupWithDesignBlockLink) );
  781. mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) );
  782. mgr->SetConditions( PCB_ACTIONS::viaDisplayMode, CHECK( !cond.ViaFillDisplay() ) );
  783. mgr->SetConditions( PCB_ACTIONS::trackDisplayMode, CHECK( !cond.TrackFillDisplay() ) );
  784. mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) );
  785. mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) );
  786. if( SCRIPTING::IsWxAvailable() )
  787. mgr->SetConditions( PCB_ACTIONS::showPythonConsole, CHECK( cond.ScriptingConsoleVisible() ) );
  788. auto enableZoneControlCondition =
  789. [this] ( const SELECTION& )
  790. {
  791. return GetBoard() && GetBoard()->GetVisibleElements().Contains( LAYER_ZONES )
  792. && GetDisplayOptions().m_ZoneOpacity > 0.0;
  793. };
  794. mgr->SetConditions( PCB_ACTIONS::zoneDisplayFilled,
  795. ENABLE( enableZoneControlCondition )
  796. .Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FILLED ) ) );
  797. mgr->SetConditions( PCB_ACTIONS::zoneDisplayOutline,
  798. ENABLE( enableZoneControlCondition )
  799. .Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE ) ) );
  800. mgr->SetConditions( PCB_ACTIONS::zoneDisplayFractured,
  801. ENABLE( enableZoneControlCondition )
  802. .Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FRACTURE_BORDERS ) ) );
  803. mgr->SetConditions( PCB_ACTIONS::zoneDisplayTriangulated,
  804. ENABLE( enableZoneControlCondition )
  805. .Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ) ) );
  806. mgr->SetConditions( ACTIONS::toggleBoundingBoxes, CHECK( cond.BoundingBoxes() ) );
  807. auto hasElements =
  808. [ this ] ( const SELECTION& aSel )
  809. {
  810. return GetBoard() &&
  811. ( !GetBoard()->IsEmpty() || !SELECTION_CONDITIONS::Idle( aSel ) );
  812. };
  813. auto constrainedDrawingModeCond =
  814. [this]( const SELECTION& )
  815. {
  816. return GetPcbNewSettings()->m_AngleSnapMode != LEADER_MODE::DIRECT;
  817. };
  818. auto boardFlippedCond =
  819. [this]( const SELECTION& )
  820. {
  821. return GetCanvas() && GetCanvas()->GetView()->IsMirroredX();
  822. };
  823. auto layerManagerCond =
  824. [this] ( const SELECTION& )
  825. {
  826. return LayerManagerShown();
  827. };
  828. auto propertiesCond =
  829. [this] ( const SELECTION& )
  830. {
  831. return PropertiesShown();
  832. };
  833. auto netInspectorCond =
  834. [this] ( const SELECTION& )
  835. {
  836. return NetInspectorShown();
  837. };
  838. auto searchPaneCond =
  839. [this] ( const SELECTION& )
  840. {
  841. return m_auimgr.GetPane( SearchPaneName() ).IsShown();
  842. };
  843. auto designBlockCond =
  844. [ this ] (const SELECTION& aSel )
  845. {
  846. return m_auimgr.GetPane( DesignBlocksPaneName() ).IsShown();
  847. };
  848. auto highContrastCond =
  849. [this] ( const SELECTION& )
  850. {
  851. return GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL;
  852. };
  853. auto globalRatsnestCond =
  854. [this] (const SELECTION& )
  855. {
  856. return GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest;
  857. };
  858. auto curvedRatsnestCond =
  859. [this] (const SELECTION& )
  860. {
  861. return GetPcbNewSettings()->m_Display.m_DisplayRatsnestLinesCurved;
  862. };
  863. auto netHighlightCond =
  864. [this]( const SELECTION& )
  865. {
  866. KIGFX::RENDER_SETTINGS* settings = GetCanvas()->GetView()->GetPainter()->GetSettings();
  867. return !settings->GetHighlightNetCodes().empty();
  868. };
  869. auto enableNetHighlightCond =
  870. [this]( const SELECTION& )
  871. {
  872. BOARD_INSPECTION_TOOL* tool = m_toolManager->GetTool<BOARD_INSPECTION_TOOL>();
  873. return tool && tool->IsNetHighlightSet();
  874. };
  875. mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( constrainedDrawingModeCond ) );
  876. mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastCond ) );
  877. mgr->SetConditions( PCB_ACTIONS::flipBoard, CHECK( boardFlippedCond ) );
  878. mgr->SetConditions( PCB_ACTIONS::showLayersManager, CHECK( layerManagerCond ) );
  879. mgr->SetConditions( PCB_ACTIONS::showRatsnest, CHECK( globalRatsnestCond ) );
  880. mgr->SetConditions( PCB_ACTIONS::ratsnestLineMode, CHECK( curvedRatsnestCond ) );
  881. mgr->SetConditions( PCB_ACTIONS::toggleNetHighlight, CHECK( netHighlightCond )
  882. .Enable( enableNetHighlightCond ) );
  883. mgr->SetConditions( ACTIONS::showProperties, CHECK( propertiesCond ) );
  884. mgr->SetConditions( PCB_ACTIONS::showNetInspector, CHECK( netInspectorCond ) );
  885. mgr->SetConditions( PCB_ACTIONS::showSearch, CHECK( searchPaneCond ) );
  886. mgr->SetConditions( PCB_ACTIONS::showDesignBlockPanel, CHECK( designBlockCond ) );
  887. mgr->SetConditions( PCB_ACTIONS::saveBoardAsDesignBlock, ENABLE( hasElements ) );
  888. mgr->SetConditions( PCB_ACTIONS::saveSelectionAsDesignBlock, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  889. const auto isArcKeepCenterMode =
  890. [this]( const SELECTION& )
  891. {
  892. return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
  893. };
  894. const auto isArcKeepEndpointMode =
  895. [this]( const SELECTION& )
  896. {
  897. return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
  898. };
  899. const auto isArcKeepRadiusMode =
  900. [this]( const SELECTION& )
  901. {
  902. return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ENDS_ADJUST_ANGLE;
  903. };
  904. mgr->SetConditions( ACTIONS::pointEditorArcKeepCenter, CHECK( isArcKeepCenterMode ) );
  905. mgr->SetConditions( ACTIONS::pointEditorArcKeepEndpoint, CHECK( isArcKeepEndpointMode ) );
  906. mgr->SetConditions( ACTIONS::pointEditorArcKeepRadius, CHECK( isArcKeepRadiusMode ) );
  907. auto isHighlightMode =
  908. [this]( const SELECTION& )
  909. {
  910. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  911. return tool && tool->GetRouterMode() == PNS::RM_MarkObstacles;
  912. };
  913. auto isShoveMode =
  914. [this]( const SELECTION& )
  915. {
  916. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  917. return tool && tool->GetRouterMode() == PNS::RM_Shove;
  918. };
  919. auto isWalkaroundMode =
  920. [this]( const SELECTION& )
  921. {
  922. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  923. return tool && tool->GetRouterMode() == PNS::RM_Walkaround;
  924. };
  925. mgr->SetConditions( PCB_ACTIONS::routerHighlightMode, CHECK( isHighlightMode ) );
  926. mgr->SetConditions( PCB_ACTIONS::routerShoveMode, CHECK( isShoveMode ) );
  927. mgr->SetConditions( PCB_ACTIONS::routerWalkaroundMode, CHECK( isWalkaroundMode ) );
  928. auto isAutoTrackWidth =
  929. [this]( const SELECTION& )
  930. {
  931. return GetDesignSettings().m_UseConnectedTrackWidth;
  932. };
  933. mgr->SetConditions( PCB_ACTIONS::autoTrackWidth, CHECK( isAutoTrackWidth ) );
  934. auto haveNetCond =
  935. [] ( const SELECTION& aSel )
  936. {
  937. for( EDA_ITEM* item : aSel )
  938. {
  939. if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
  940. {
  941. if( bci->GetNetCode() > 0 )
  942. return true;
  943. }
  944. }
  945. return false;
  946. };
  947. mgr->SetConditions( PCB_ACTIONS::showNetInRatsnest, ENABLE( haveNetCond ) );
  948. mgr->SetConditions( PCB_ACTIONS::hideNetInRatsnest, ENABLE( haveNetCond ) );
  949. mgr->SetConditions( PCB_ACTIONS::highlightNet, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  950. mgr->SetConditions( PCB_ACTIONS::highlightNetSelection, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  951. static const std::vector<KICAD_T> trackTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T };
  952. static const std::vector<KICAD_T> padOwnerTypes = { PCB_FOOTPRINT_T, PCB_PAD_T };
  953. static const std::vector<KICAD_T> footprintTypes = { PCB_FOOTPRINT_T };
  954. static const std::vector<KICAD_T> crossProbeTypes = { PCB_PAD_T, PCB_FOOTPRINT_T, PCB_GROUP_T };
  955. static const std::vector<KICAD_T> zoneTypes = { PCB_ZONE_T };
  956. mgr->SetConditions( PCB_ACTIONS::selectNet, ENABLE( SELECTION_CONDITIONS::OnlyTypes( trackTypes ) ) );
  957. mgr->SetConditions( PCB_ACTIONS::deselectNet, ENABLE( SELECTION_CONDITIONS::OnlyTypes( trackTypes ) ) );
  958. mgr->SetConditions( PCB_ACTIONS::selectUnconnected, ENABLE( SELECTION_CONDITIONS::OnlyTypes( padOwnerTypes ) ) );
  959. mgr->SetConditions( PCB_ACTIONS::selectSameSheet, ENABLE( SELECTION_CONDITIONS::OnlyTypes( footprintTypes ) ) );
  960. mgr->SetConditions( PCB_ACTIONS::selectOnSchematic, ENABLE( SELECTION_CONDITIONS::HasTypes( crossProbeTypes ) ) );
  961. SELECTION_CONDITION singleZoneCond = SELECTION_CONDITIONS::Count( 1 )
  962. && SELECTION_CONDITIONS::OnlyTypes( zoneTypes );
  963. SELECTION_CONDITION zoneMergeCond = SELECTION_CONDITIONS::MoreThan( 1 )
  964. && SELECTION_CONDITIONS::OnlyTypes( zoneTypes );
  965. mgr->SetConditions( PCB_ACTIONS::zoneDuplicate, ENABLE( singleZoneCond ) );
  966. mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) );
  967. mgr->SetConditions( PCB_ACTIONS::drawSimilarZone, ENABLE( singleZoneCond ) );
  968. mgr->SetConditions( PCB_ACTIONS::zoneMerge, ENABLE( zoneMergeCond ) );
  969. mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( cond.Get45degMode() ) );
  970. #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
  971. // These tools can be used at any time to inspect the board
  972. CURRENT_TOOL( ACTIONS::zoomTool );
  973. CURRENT_TOOL( ACTIONS::measureTool );
  974. CURRENT_TOOL( ACTIONS::selectionTool );
  975. CURRENT_TOOL( PCB_ACTIONS::localRatsnestTool );
  976. auto isDRCIdle =
  977. [this] ( const SELECTION& )
  978. {
  979. DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
  980. return !( tool && tool->IsDRCRunning() );
  981. };
  982. #define CURRENT_EDIT_TOOL( action ) \
  983. mgr->SetConditions( action, ACTION_CONDITIONS().Check( cond.CurrentTool( action ) ) \
  984. .Enable( isDRCIdle ) )
  985. // These tools edit the board, so they must be disabled during some operations
  986. CURRENT_EDIT_TOOL( ACTIONS::embeddedFiles );
  987. CURRENT_EDIT_TOOL( ACTIONS::deleteTool );
  988. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeFootprint );
  989. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeDesignBlock );
  990. CURRENT_EDIT_TOOL( PCB_ACTIONS::routeSingleTrack);
  991. CURRENT_EDIT_TOOL( PCB_ACTIONS::routeDiffPair );
  992. CURRENT_EDIT_TOOL( PCB_ACTIONS::tuneSingleTrack);
  993. CURRENT_EDIT_TOOL( PCB_ACTIONS::tuneDiffPair );
  994. CURRENT_EDIT_TOOL( PCB_ACTIONS::tuneSkew );
  995. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawVia );
  996. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawZone );
  997. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRuleArea );
  998. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawLine );
  999. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRectangle );
  1000. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawCircle );
  1001. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawArc );
  1002. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawPolygon );
  1003. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawBezier );
  1004. CURRENT_EDIT_TOOL( PCB_ACTIONS::placePoint );
  1005. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeReferenceImage );
  1006. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeText );
  1007. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawTextBox );
  1008. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawTable );
  1009. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawAlignedDimension );
  1010. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawOrthogonalDimension );
  1011. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawCenterDimension );
  1012. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRadialDimension );
  1013. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawLeader );
  1014. CURRENT_EDIT_TOOL( PCB_ACTIONS::drillOrigin );
  1015. CURRENT_EDIT_TOOL( ACTIONS::gridSetOrigin );
  1016. CURRENT_EDIT_TOOL( PCB_ACTIONS::createArray );
  1017. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateLine );
  1018. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateGap );
  1019. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateStub );
  1020. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateStubArc );
  1021. CURRENT_EDIT_TOOL( PCB_ACTIONS::microwaveCreateFunctionShape );
  1022. #undef CURRENT_TOOL
  1023. #undef CURRENT_EDIT_TOOL
  1024. #undef ENABLE
  1025. #undef CHECK
  1026. // clang-format on
  1027. }
  1028. void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event )
  1029. {
  1030. if( event.GetId() == wxID_EXIT )
  1031. Kiway().OnKiCadExit();
  1032. if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
  1033. Close( false );
  1034. }
  1035. void PCB_EDIT_FRAME::ResolveDRCExclusions( bool aCreateMarkers )
  1036. {
  1037. BOARD_COMMIT commit( this );
  1038. for( PCB_MARKER* marker : GetBoard()->ResolveDRCExclusions( aCreateMarkers ) )
  1039. {
  1040. if( marker->GetMarkerType() == MARKER_BASE::MARKER_DRAWING_SHEET )
  1041. marker->GetRCItem()->SetItems( GetCanvas()->GetDrawingSheet() );
  1042. commit.Add( marker );
  1043. }
  1044. commit.Push( wxEmptyString, SKIP_UNDO | SKIP_SET_DIRTY );
  1045. for( PCB_MARKER* marker : GetBoard()->Markers() )
  1046. {
  1047. if( marker->GetSeverity() == RPT_SEVERITY_EXCLUSION )
  1048. GetCanvas()->GetView()->Update( marker );
  1049. }
  1050. GetBoard()->UpdateRatsnestExclusions();
  1051. }
  1052. bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
  1053. {
  1054. // Shutdown blocks must be determined and vetoed as early as possible
  1055. if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
  1056. && IsContentModified() )
  1057. {
  1058. return false;
  1059. }
  1060. ZONE_FILLER_TOOL* zoneFillerTool = m_toolManager->GetTool<ZONE_FILLER_TOOL>();
  1061. if( zoneFillerTool->IsBusy() )
  1062. {
  1063. wxBell();
  1064. if( wxWindow* reporter = dynamic_cast<wxWindow*>( zoneFillerTool->GetProgressReporter() ) )
  1065. reporter->ShowWithEffect( wxSHOW_EFFECT_EXPAND );
  1066. return false;
  1067. }
  1068. if( Kiface().IsSingle() )
  1069. {
  1070. auto* fpEditor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
  1071. if( fpEditor && !fpEditor->Close() ) // Can close footprint editor?
  1072. return false;
  1073. auto* fpViewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false );
  1074. if( fpViewer && !fpViewer->Close() ) // Can close footprint viewer?
  1075. return false;
  1076. // FOOTPRINT_CHOOSER_FRAME is always modal so this shouldn't come up, but better safe than
  1077. // sorry.
  1078. auto* chooser = (FOOTPRINT_CHOOSER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_CHOOSER, false );
  1079. if( chooser && !chooser->Close() ) // Can close footprint chooser?
  1080. return false;
  1081. }
  1082. else
  1083. {
  1084. auto* fpEditor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
  1085. if( fpEditor && fpEditor->IsCurrentFPFromBoard() )
  1086. {
  1087. if( !fpEditor->CanCloseFPFromBoard( true ) )
  1088. return false;
  1089. }
  1090. }
  1091. if( IsContentModified() )
  1092. {
  1093. wxFileName fileName = GetBoard()->GetFileName();
  1094. wxString msg = _( "Save changes to '%s' before closing?" );
  1095. if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
  1096. [&]() -> bool
  1097. {
  1098. return SaveBoard();
  1099. } ) )
  1100. {
  1101. return false;
  1102. }
  1103. }
  1104. return PCB_BASE_EDIT_FRAME::canCloseWindow( aEvent );
  1105. }
  1106. void PCB_EDIT_FRAME::doCloseWindow()
  1107. {
  1108. // On Windows 7 / 32 bits, on OpenGL mode only, Pcbnew crashes
  1109. // when closing this frame if a footprint was selected, and the footprint editor called
  1110. // to edit this footprint, and when closing pcbnew if this footprint is still selected
  1111. // See https://bugs.launchpad.net/kicad/+bug/1655858
  1112. // I think this is certainly a OpenGL event fired after frame deletion, so this workaround
  1113. // avoid the crash (JPC)
  1114. GetCanvas()->SetEvtHandlerEnabled( false );
  1115. GetCanvas()->StopDrawing();
  1116. #ifdef KICAD_IPC_API
  1117. Pgm().GetApiServer().DeregisterHandler( m_apiHandler.get() );
  1118. wxTheApp->Unbind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED,
  1119. &PCB_EDIT_FRAME::onPluginAvailabilityChanged, this );
  1120. #endif
  1121. // Clean up mode-less dialogs.
  1122. Unbind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &PCB_EDIT_FRAME::onCloseModelessBookReporterDialogs,
  1123. this );
  1124. wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
  1125. if( open_dlg )
  1126. open_dlg->Close( true );
  1127. if( m_findDialog )
  1128. {
  1129. m_findDialog->Destroy();
  1130. m_findDialog = nullptr;
  1131. }
  1132. if( m_inspectDrcErrorDlg )
  1133. {
  1134. m_inspectDrcErrorDlg->Destroy();
  1135. m_inspectDrcErrorDlg = nullptr;
  1136. }
  1137. if( m_inspectClearanceDlg )
  1138. {
  1139. m_inspectClearanceDlg->Destroy();
  1140. m_inspectClearanceDlg = nullptr;
  1141. }
  1142. if( m_inspectConstraintsDlg )
  1143. {
  1144. m_inspectConstraintsDlg->Destroy();
  1145. m_inspectConstraintsDlg = nullptr;
  1146. }
  1147. if( m_footprintDiffDlg )
  1148. {
  1149. m_footprintDiffDlg->Destroy();
  1150. m_footprintDiffDlg = nullptr;
  1151. }
  1152. // Delete the auto save file if it exists.
  1153. wxFileName fn = GetBoard()->GetFileName();
  1154. // Auto save file name is the normal file name prefixed with 'FILEEXT::AutoSaveFilePrefix'.
  1155. fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() );
  1156. // When the auto save feature does not have write access to the board file path, it falls
  1157. // back to a platform specific user temporary file path.
  1158. if( !fn.IsOk() || !fn.IsDirWritable() )
  1159. fn.SetPath( wxFileName::GetTempDir() );
  1160. wxLogTrace( traceAutoSave, wxT( "Deleting auto save file <" ) + fn.GetFullPath() + wxT( ">" ) );
  1161. // Remove the auto save file on a normal close of Pcbnew.
  1162. if( fn.FileExists() && !wxRemoveFile( fn.GetFullPath() ) )
  1163. {
  1164. wxLogTrace( traceAutoSave, wxT( "The auto save file could not be removed!" ) );
  1165. }
  1166. // Make sure local settings are persisted
  1167. if( Prj().GetLocalSettings().ShouldAutoSave() )
  1168. {
  1169. m_netInspectorPanel->SaveSettings();
  1170. SaveProjectLocalSettings();
  1171. }
  1172. else
  1173. {
  1174. wxLogTrace( traceAutoSave, wxT( "Skipping auto-save of migrated local settings" ) );
  1175. }
  1176. // Do not show the layer manager during closing to avoid flicker
  1177. // on some platforms (Windows) that generate useless redraw of items in
  1178. // the Layer Manager
  1179. if( m_show_layer_manager_tools )
  1180. {
  1181. m_auimgr.GetPane( wxS( "LayersManager" ) ).Show( false );
  1182. m_auimgr.GetPane( wxS( "TabbedPanel" ) ).Show( false );
  1183. }
  1184. // Unlink the old project if needed
  1185. GetBoard()->ClearProject();
  1186. // Delete board structs and undo/redo lists, to avoid crash on exit
  1187. // when deleting some structs (mainly in undo/redo lists) too late
  1188. Clear_Pcb( false, true );
  1189. // do not show the window because ScreenPcb will be deleted and we do not
  1190. // want any paint event
  1191. Show( false );
  1192. PCB_BASE_EDIT_FRAME::doCloseWindow();
  1193. }
  1194. void PCB_EDIT_FRAME::ActivateGalCanvas()
  1195. {
  1196. PCB_BASE_EDIT_FRAME::ActivateGalCanvas();
  1197. GetCanvas()->UpdateColors();
  1198. GetCanvas()->Refresh();
  1199. }
  1200. void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage, wxWindow* aParent )
  1201. {
  1202. static std::mutex dialogMutex; // Local static mutex
  1203. std::unique_lock<std::mutex> dialogLock( dialogMutex, std::try_to_lock );
  1204. // One dialog at a time.
  1205. if( !dialogLock.owns_lock() )
  1206. {
  1207. if( m_boardSetupDlg && m_boardSetupDlg->IsShown() )
  1208. {
  1209. m_boardSetupDlg->Raise(); // Brings the existing dialog to the front
  1210. }
  1211. return;
  1212. }
  1213. // Make sure everything's up-to-date
  1214. GetBoard()->BuildListOfNets();
  1215. DIALOG_BOARD_SETUP dlg( this, aParent );
  1216. if( !aInitialPage.IsEmpty() )
  1217. dlg.SetInitialPage( aInitialPage, wxEmptyString );
  1218. // Assign dlg to the m_boardSetupDlg pointer to track its status.
  1219. m_boardSetupDlg = &dlg;
  1220. // QuasiModal required for Scintilla auto-complete
  1221. if( dlg.ShowQuasiModal() == wxID_OK )
  1222. {
  1223. // Note: We must synchronise time domain properties before nets and classes, otherwise the updates
  1224. // called by the board listener events are using stale data
  1225. GetBoard()->SynchronizeTimeDomainProperties();
  1226. GetBoard()->SynchronizeNetsAndNetClasses( true );
  1227. if( !GetBoard()->SynchronizeComponentClasses( std::unordered_set<wxString>() ) )
  1228. {
  1229. m_infoBar->RemoveAllButtons();
  1230. m_infoBar->AddCloseButton();
  1231. m_infoBar->ShowMessage( _( "Could not load component class assignment rules" ),
  1232. wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::GENERIC );
  1233. }
  1234. // We don't know if anything was modified, so err on the side of requiring a save
  1235. OnModify();
  1236. Kiway().CommonSettingsChanged( TEXTVARS_CHANGED );
  1237. Prj().IncrementTextVarsTicker();
  1238. Prj().IncrementNetclassesTicker();
  1239. PCBNEW_SETTINGS* settings = GetPcbNewSettings();
  1240. static LSET maskAndPasteLayers = LSET( { F_Mask, F_Paste, B_Mask, B_Paste } );
  1241. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  1242. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  1243. {
  1244. int flags = 0;
  1245. if( !aItem->IsBOARD_ITEM() )
  1246. return flags;
  1247. BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aItem );
  1248. if( item->Type() == PCB_VIA_T || item->Type() == PCB_PAD_T )
  1249. {
  1250. // Note: KIGFX::REPAINT isn't enough for things that go from invisible
  1251. // to visible as they won't be found in the view layer's itemset for
  1252. // re-painting.
  1253. if( ( GetBoard()->GetVisibleLayers() & maskAndPasteLayers ).any() )
  1254. flags |= KIGFX::ALL;
  1255. }
  1256. if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T || item->Type() == PCB_VIA_T )
  1257. {
  1258. if( settings->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS )
  1259. flags |= KIGFX::REPAINT;
  1260. }
  1261. if( item->Type() == PCB_PAD_T )
  1262. {
  1263. if( settings->m_Display.m_PadClearance )
  1264. flags |= KIGFX::REPAINT;
  1265. }
  1266. if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
  1267. {
  1268. if( text->HasTextVars() )
  1269. {
  1270. text->ClearRenderCache();
  1271. text->ClearBoundingBoxCache();
  1272. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1273. }
  1274. }
  1275. return flags;
  1276. } );
  1277. GetCanvas()->Refresh();
  1278. UpdateUserInterface();
  1279. ReCreateAuxiliaryToolbar();
  1280. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  1281. //this event causes the routing tool to reload its design rules information
  1282. TOOL_EVENT toolEvent( TC_COMMAND, TA_MODEL_CHANGE, AS_ACTIVE );
  1283. toolEvent.SetHasPosition( false );
  1284. m_toolManager->ProcessEvent( toolEvent );
  1285. }
  1286. GetCanvas()->SetFocus();
  1287. // Reset m_boardSetupDlg after the dialog is closed
  1288. m_boardSetupDlg = nullptr;
  1289. }
  1290. void PCB_EDIT_FRAME::FocusSearch()
  1291. {
  1292. m_searchPane->FocusSearch();
  1293. }
  1294. void PCB_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  1295. {
  1296. PCB_BASE_FRAME::LoadSettings( aCfg );
  1297. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  1298. wxASSERT( cfg );
  1299. if( cfg )
  1300. {
  1301. m_show_layer_manager_tools = cfg->m_AuiPanels.show_layer_manager;
  1302. m_show_search = cfg->m_AuiPanels.show_search;
  1303. m_show_net_inspector = cfg->m_AuiPanels.show_net_inspector;
  1304. }
  1305. }
  1306. void PCB_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  1307. {
  1308. PCB_BASE_FRAME::SaveSettings( aCfg );
  1309. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  1310. wxASSERT( cfg );
  1311. if( cfg )
  1312. {
  1313. wxAuiPaneInfo& apperancePane = m_auimgr.GetPane( AppearancePanelName() );
  1314. cfg->m_AuiPanels.show_layer_manager = apperancePane.IsShown();
  1315. if( m_propertiesPanel )
  1316. {
  1317. cfg->m_AuiPanels.show_properties = m_propertiesPanel->IsShownOnScreen();
  1318. cfg->m_AuiPanels.properties_panel_width = m_propertiesPanel->GetSize().x;
  1319. cfg->m_AuiPanels.properties_splitter = m_propertiesPanel->SplitterProportion();
  1320. }
  1321. // ensure m_show_search is up to date (the pane can be closed)
  1322. wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
  1323. m_show_search = searchPaneInfo.IsShown();
  1324. cfg->m_AuiPanels.show_search = m_show_search;
  1325. cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
  1326. cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
  1327. cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
  1328. if( m_netInspectorPanel )
  1329. {
  1330. wxAuiPaneInfo& netInspectorhPaneInfo = m_auimgr.GetPane( NetInspectorPanelName() );
  1331. m_show_net_inspector = netInspectorhPaneInfo.IsShown();
  1332. cfg->m_AuiPanels.show_net_inspector = m_show_net_inspector;
  1333. }
  1334. if( m_appearancePanel )
  1335. {
  1336. cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
  1337. cfg->m_AuiPanels.appearance_panel_tab = m_appearancePanel->GetTabIndex();
  1338. cfg->m_AuiPanels.appearance_expand_layer_display = m_appearancePanel->IsLayerOptionsExpanded();
  1339. cfg->m_AuiPanels.appearance_expand_net_display = m_appearancePanel->IsNetOptionsExpanded();
  1340. }
  1341. wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
  1342. cfg->m_AuiPanels.design_blocks_show = designBlocksPane.IsShown();
  1343. if( designBlocksPane.IsDocked() )
  1344. cfg->m_AuiPanels.design_blocks_panel_docked_width = m_designBlocksPane->GetSize().x;
  1345. else
  1346. {
  1347. cfg->m_AuiPanels.design_blocks_panel_float_height = designBlocksPane.floating_size.y;
  1348. cfg->m_AuiPanels.design_blocks_panel_float_width = designBlocksPane.floating_size.x;
  1349. }
  1350. m_designBlocksPane->SaveSettings();
  1351. }
  1352. }
  1353. EDA_ANGLE PCB_EDIT_FRAME::GetRotationAngle() const
  1354. {
  1355. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( config() );
  1356. return cfg ? cfg->m_RotationAngle : ANGLE_90;
  1357. }
  1358. COLOR4D PCB_EDIT_FRAME::GetGridColor()
  1359. {
  1360. return GetColorSettings()->GetColor( LAYER_GRID );
  1361. }
  1362. void PCB_EDIT_FRAME::SetGridColor( const COLOR4D& aColor )
  1363. {
  1364. GetColorSettings()->SetColor( LAYER_GRID, aColor );
  1365. GetCanvas()->GetGAL()->SetGridColor( aColor );
  1366. }
  1367. void PCB_EDIT_FRAME::SetActiveLayer( PCB_LAYER_ID aLayer, bool aForceRedraw )
  1368. {
  1369. const PCB_LAYER_ID oldLayer = GetActiveLayer();
  1370. if( oldLayer == aLayer && !aForceRedraw )
  1371. return;
  1372. PCB_BASE_FRAME::SetActiveLayer( aLayer );
  1373. m_appearancePanel->OnLayerChanged();
  1374. m_toolManager->PostAction( PCB_ACTIONS::layerChanged ); // notify other tools
  1375. GetCanvas()->SetFocus(); // allow capture of hotkeys
  1376. GetCanvas()->SetHighContrastLayer( aLayer );
  1377. /*
  1378. * Only show pad, via and track clearances when a copper layer is active
  1379. * and then only show the clearance layer for that copper layer. For
  1380. * front/back non-copper layers, show the clearance layer for the outer
  1381. * layer on that side.
  1382. *
  1383. * For pads/vias, this is to avoid clutter when there are pad/via layers
  1384. * that vary in flash (i.e. clearance from the hole or pad edge), padstack
  1385. * shape on each layer or clearances on each layer.
  1386. *
  1387. * For tracks, this follows the same logic as pads/vias, but in theory could
  1388. * have their own set of independent clearance layers to allow track clearance
  1389. * to be shown for more layers.
  1390. */
  1391. const auto getClearanceLayerForActive = []( PCB_LAYER_ID aActiveLayer ) -> std::optional<int>
  1392. {
  1393. if( IsCopperLayer( aActiveLayer ) )
  1394. return CLEARANCE_LAYER_FOR( aActiveLayer );
  1395. return std::nullopt;
  1396. };
  1397. if( std::optional<int> oldClearanceLayer = getClearanceLayerForActive( oldLayer ) )
  1398. GetCanvas()->GetView()->SetLayerVisible( *oldClearanceLayer, false );
  1399. if( std::optional<int> newClearanceLayer = getClearanceLayerForActive( aLayer ) )
  1400. GetCanvas()->GetView()->SetLayerVisible( *newClearanceLayer, true );
  1401. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  1402. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  1403. {
  1404. if( !aItem->IsBOARD_ITEM() )
  1405. return 0;
  1406. BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aItem );
  1407. // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible
  1408. // as they won't be found in the view layer's itemset for re-painting.
  1409. if( GetDisplayOptions().m_ContrastModeDisplay == HIGH_CONTRAST_MODE::HIDDEN )
  1410. {
  1411. if( item->IsOnLayer( oldLayer ) || item->IsOnLayer( aLayer ) )
  1412. return KIGFX::ALL;
  1413. }
  1414. if( item->Type() == PCB_VIA_T )
  1415. {
  1416. PCB_VIA* via = static_cast<PCB_VIA*>( item );
  1417. // Vias on a restricted layer set must be redrawn when the active layer
  1418. // is changed
  1419. if( via->GetViaType() == VIATYPE::BLIND_BURIED
  1420. || via->GetViaType() == VIATYPE::MICROVIA )
  1421. {
  1422. return KIGFX::REPAINT;
  1423. }
  1424. if( via->GetRemoveUnconnected() )
  1425. return KIGFX::ALL;
  1426. }
  1427. else if( item->Type() == PCB_PAD_T )
  1428. {
  1429. PAD* pad = static_cast<PAD*>( item );
  1430. if( pad->GetRemoveUnconnected() )
  1431. return KIGFX::ALL;
  1432. }
  1433. return 0;
  1434. } );
  1435. GetCanvas()->Refresh();
  1436. }
  1437. void PCB_EDIT_FRAME::OnBoardLoaded()
  1438. {
  1439. ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
  1440. layerEnum.Choices().Clear();
  1441. layerEnum.Undefined( UNDEFINED_LAYER );
  1442. for( PCB_LAYER_ID layer : LSET::AllLayersMask() )
  1443. {
  1444. // Canonical name
  1445. layerEnum.Map( layer, LSET::Name( layer ) );
  1446. // User name
  1447. layerEnum.Map( layer, GetBoard()->GetLayerName( layer ) );
  1448. }
  1449. DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
  1450. try
  1451. {
  1452. drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
  1453. }
  1454. catch( PARSE_ERROR& )
  1455. {
  1456. // Not sure this is the best place to tell the user their rules are buggy, so
  1457. // we'll stay quiet for now. Feel free to revisit this decision....
  1458. }
  1459. UpdateTitle();
  1460. wxFileName fn = GetBoard()->GetFileName();
  1461. // Display a warning that the file is read only
  1462. if( fn.FileExists() && !fn.IsFileWritable() )
  1463. {
  1464. m_infoBar->RemoveAllButtons();
  1465. m_infoBar->AddCloseButton();
  1466. m_infoBar->ShowMessage( _( "Board file is read only." ),
  1467. wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
  1468. }
  1469. ReCreateLayerBox();
  1470. // Sync layer and item visibility
  1471. GetCanvas()->SyncLayersVisibility( m_pcb );
  1472. SetElementVisibility( LAYER_RATSNEST, GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest );
  1473. m_appearancePanel->OnBoardChanged();
  1474. // Apply saved display state to the appearance panel after it has been set up
  1475. PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
  1476. m_appearancePanel->ApplyLayerPreset( localSettings.m_ActiveLayerPreset );
  1477. if( GetBoard()->GetDesignSettings().IsLayerEnabled( localSettings.m_ActiveLayer ) )
  1478. SetActiveLayer( localSettings.m_ActiveLayer, true );
  1479. else
  1480. SetActiveLayer( GetActiveLayer(), true ); // Make sure to repaint even if not switching
  1481. PROJECT_FILE& projectFile = Prj().GetProjectFile();
  1482. m_layerPairSettings->SetLayerPairs( projectFile.m_LayerPairInfos );
  1483. m_layerPairSettings->SetCurrentLayerPair( LAYER_PAIR{ F_Cu, B_Cu } );
  1484. // Updates any auto dimensions and the auxiliary toolbar tracks/via sizes
  1485. unitsChangeRefresh();
  1486. // Sync the net inspector now we have connectivity calculated
  1487. if( m_netInspectorPanel )
  1488. m_netInspectorPanel->OnBoardChanged();
  1489. // Display the loaded board:
  1490. Zoom_Automatique( false );
  1491. // Invalidate painting as loading the DRC engine will cause clearances to become valid
  1492. GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
  1493. Refresh();
  1494. SetMsgPanel( GetBoard() );
  1495. SetStatusText( wxEmptyString );
  1496. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "PCB file changes are unsaved" ) );
  1497. }
  1498. void PCB_EDIT_FRAME::OnDisplayOptionsChanged()
  1499. {
  1500. m_appearancePanel->UpdateDisplayOptions();
  1501. }
  1502. bool PCB_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const
  1503. {
  1504. return GetBoard()->IsElementVisible( aElement );
  1505. }
  1506. void PCB_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
  1507. {
  1508. // Force the RATSNEST visible
  1509. if( aElement == LAYER_RATSNEST )
  1510. GetCanvas()->GetView()->SetLayerVisible( aElement, true );
  1511. else
  1512. GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
  1513. GetBoard()->SetElementVisibility( aElement, aNewState );
  1514. }
  1515. void PCB_EDIT_FRAME::ShowChangedLanguage()
  1516. {
  1517. // call my base class
  1518. PCB_BASE_EDIT_FRAME::ShowChangedLanguage();
  1519. m_auimgr.GetPane( m_appearancePanel ).Caption( _( "Appearance" ) );
  1520. m_auimgr.GetPane( m_selectionFilterPanel ).Caption( _( "Selection Filter" ) );
  1521. m_auimgr.GetPane( m_propertiesPanel ).Caption( _( "Properties" ) );
  1522. m_auimgr.GetPane( m_netInspectorPanel ).Caption( _( "Net Inspector" ) );
  1523. m_auimgr.Update();
  1524. UpdateTitle();
  1525. }
  1526. wxString PCB_EDIT_FRAME::GetLastPath( LAST_PATH_TYPE aType )
  1527. {
  1528. PROJECT_FILE& project = Prj().GetProjectFile();
  1529. if( project.m_PcbLastPath[ aType ].IsEmpty() )
  1530. return wxEmptyString;
  1531. wxFileName absoluteFileName = project.m_PcbLastPath[ aType ];
  1532. wxFileName pcbFileName = GetBoard()->GetFileName();
  1533. absoluteFileName.MakeAbsolute( pcbFileName.GetPath() );
  1534. return absoluteFileName.GetFullPath();
  1535. }
  1536. void PCB_EDIT_FRAME::SetLastPath( LAST_PATH_TYPE aType, const wxString& aLastPath )
  1537. {
  1538. PROJECT_FILE& project = Prj().GetProjectFile();
  1539. wxFileName relativeFileName = aLastPath;
  1540. wxFileName pcbFileName = GetBoard()->GetFileName();
  1541. relativeFileName.MakeRelativeTo( pcbFileName.GetPath() );
  1542. if( relativeFileName.GetFullPath() != project.m_PcbLastPath[ aType ] )
  1543. {
  1544. project.m_PcbLastPath[ aType ] = relativeFileName.GetFullPath();
  1545. OnModify();
  1546. }
  1547. }
  1548. void PCB_EDIT_FRAME::OnModify()
  1549. {
  1550. PCB_BASE_FRAME::OnModify();
  1551. m_ZoneFillsDirty = true;
  1552. if( m_isClosing )
  1553. return;
  1554. Update3DView( true, GetPcbNewSettings()->m_Display.m_Live3DRefresh );
  1555. if( !GetTitle().StartsWith( wxT( "*" ) ) )
  1556. UpdateTitle();
  1557. }
  1558. void PCB_EDIT_FRAME::HardRedraw()
  1559. {
  1560. Update3DView( true, true );
  1561. std::shared_ptr<CONNECTIVITY_DATA> connectivity = GetBoard()->GetConnectivity();
  1562. connectivity->RecalculateRatsnest( nullptr );
  1563. GetCanvas()->RedrawRatsnest();
  1564. std::vector<MSG_PANEL_ITEM> msg_list;
  1565. GetBoard()->GetMsgPanelInfo( this, msg_list );
  1566. SetMsgPanel( msg_list );
  1567. }
  1568. void PCB_EDIT_FRAME::UpdateTitle()
  1569. {
  1570. wxFileName fn = GetBoard()->GetFileName();
  1571. bool readOnly = false;
  1572. bool unsaved = false;
  1573. if( fn.IsOk() && fn.FileExists() )
  1574. readOnly = !fn.IsFileWritable();
  1575. else
  1576. unsaved = true;
  1577. wxString title;
  1578. if( IsContentModified() )
  1579. title = wxT( "*" );
  1580. title += fn.GetName();
  1581. if( readOnly )
  1582. title += wxS( " " ) + _( "[Read Only]" );
  1583. if( unsaved )
  1584. title += wxS( " " ) + _( "[Unsaved]" );
  1585. title += wxT( " \u2014 " ) + _( "PCB Editor" );
  1586. SetTitle( title );
  1587. }
  1588. void PCB_EDIT_FRAME::UpdateUserInterface()
  1589. {
  1590. // Update the layer manager and other widgets from the board setup
  1591. // (layer and items visibility, colors ...)
  1592. // Rebuild list of nets (full ratsnest rebuild)
  1593. GetBoard()->BuildConnectivity();
  1594. // Update info shown by the horizontal toolbars
  1595. ReCreateLayerBox();
  1596. LSET activeLayers = GetBoard()->GetEnabledLayers();
  1597. if( !activeLayers.test( GetActiveLayer() ) )
  1598. SetActiveLayer( activeLayers.Seq().front() );
  1599. m_SelLayerBox->SetLayerSelection( GetActiveLayer() );
  1600. ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
  1601. layerEnum.Choices().Clear();
  1602. layerEnum.Undefined( UNDEFINED_LAYER );
  1603. for( PCB_LAYER_ID layer : LSET::AllLayersMask() )
  1604. {
  1605. // Canonical name
  1606. layerEnum.Map( layer, LSET::Name( layer ) );
  1607. // User name
  1608. layerEnum.Map( layer, GetBoard()->GetLayerName( layer ) );
  1609. }
  1610. // Sync visibility with canvas
  1611. for( PCB_LAYER_ID layer : LSET::AllLayersMask() )
  1612. GetCanvas()->GetView()->SetLayerVisible( layer, GetBoard()->IsLayerVisible( layer ) );
  1613. // Stackup and/or color theme may have changed
  1614. m_appearancePanel->OnBoardChanged();
  1615. m_netInspectorPanel->OnParentSetupChanged();
  1616. }
  1617. void PCB_EDIT_FRAME::SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType )
  1618. {
  1619. // switches currently used canvas (Cairo / OpenGL).
  1620. PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
  1621. }
  1622. void PCB_EDIT_FRAME::ShowFindDialog()
  1623. {
  1624. if( !m_findDialog )
  1625. {
  1626. m_findDialog = new DIALOG_FIND( this );
  1627. m_findDialog->SetCallback( std::bind( &PCB_SELECTION_TOOL::FindItem,
  1628. m_toolManager->GetTool<PCB_SELECTION_TOOL>(), _1 ) );
  1629. }
  1630. wxString findString;
  1631. PCB_SELECTION& selection = m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
  1632. if( selection.Size() == 1 )
  1633. {
  1634. EDA_ITEM* front = selection.Front();
  1635. switch( front->Type() )
  1636. {
  1637. case PCB_FOOTPRINT_T:
  1638. findString = UnescapeString( static_cast<FOOTPRINT*>( front )->GetValue() );
  1639. break;
  1640. case PCB_FIELD_T:
  1641. case PCB_TEXT_T:
  1642. findString = UnescapeString( static_cast<PCB_TEXT*>( front )->GetText() );
  1643. if( findString.Contains( wxT( "\n" ) ) )
  1644. findString = findString.Before( '\n' );
  1645. break;
  1646. default:
  1647. break;
  1648. }
  1649. }
  1650. m_findDialog->Preload( findString );
  1651. m_findDialog->Show( true );
  1652. }
  1653. void PCB_EDIT_FRAME::FindNext( bool reverse )
  1654. {
  1655. if( !m_findDialog )
  1656. ShowFindDialog();
  1657. m_findDialog->FindNext( reverse );
  1658. }
  1659. int PCB_EDIT_FRAME::TestStandalone()
  1660. {
  1661. if( Kiface().IsSingle() )
  1662. return 0;
  1663. // Update PCB requires a netlist. Therefore the schematic editor must be running
  1664. // If this is not the case, open the schematic editor
  1665. KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, true );
  1666. // If Kiway() cannot create the eeschema frame, it shows a error message, and
  1667. // frame is null
  1668. if( !frame )
  1669. return -1;
  1670. if( !frame->IsShownOnScreen() )
  1671. {
  1672. wxEventBlocker blocker( this );
  1673. wxFileName fn( Prj().GetProjectPath(), Prj().GetProjectName(),
  1674. FILEEXT::KiCadSchematicFileExtension );
  1675. // Maybe the file hasn't been converted to the new s-expression file format so
  1676. // see if the legacy schematic file is still in play.
  1677. if( !fn.FileExists() )
  1678. {
  1679. fn.SetExt( FILEEXT::LegacySchematicFileExtension );
  1680. if( !fn.FileExists() )
  1681. {
  1682. DisplayErrorMessage( this, _( "The schematic for this board cannot be found." ) );
  1683. return -2;
  1684. }
  1685. }
  1686. frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
  1687. // we show the schematic editor frame, because do not show is seen as
  1688. // a not yet opened schematic by Kicad manager, which is not the case
  1689. frame->Show( true );
  1690. // bring ourselves back to the front
  1691. Raise();
  1692. }
  1693. return 1; //Success!
  1694. }
  1695. bool PCB_EDIT_FRAME::FetchNetlistFromSchematic( NETLIST& aNetlist,
  1696. const wxString& aAnnotateMessage )
  1697. {
  1698. int standalone = TestStandalone();
  1699. if( standalone == 0 )
  1700. {
  1701. DisplayErrorMessage( this, _( "Cannot update the PCB because PCB editor is opened in "
  1702. "stand-alone mode. In order to create or update PCBs from "
  1703. "schematics, you must launch the KiCad project manager and "
  1704. "create a project." ) );
  1705. return false; // Not in standalone mode
  1706. }
  1707. if( standalone < 0 ) // Problem with Eeschema or the schematic
  1708. return false;
  1709. Raise(); // Show
  1710. std::string payload( aAnnotateMessage );
  1711. Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_GET_NETLIST, payload, this );
  1712. if( payload == aAnnotateMessage )
  1713. {
  1714. Raise();
  1715. DisplayErrorMessage( this, aAnnotateMessage );
  1716. return false;
  1717. }
  1718. try
  1719. {
  1720. auto lineReader = new STRING_LINE_READER( payload, _( "Eeschema netlist" ) );
  1721. KICAD_NETLIST_READER netlistReader( lineReader, &aNetlist );
  1722. netlistReader.LoadNetlist();
  1723. }
  1724. catch( const IO_ERROR& e )
  1725. {
  1726. Raise();
  1727. // Do not translate extra_info strings. These are for developers
  1728. wxString extra_info = e.Problem() + wxT( " : " ) + e.What() + wxT( " at " ) + e.Where();
  1729. DisplayErrorMessage( this, _( "Received an error while reading netlist. Please "
  1730. "report this issue to the KiCad team using the menu "
  1731. "Help->Report Bug."), extra_info );
  1732. return false;
  1733. }
  1734. return true;
  1735. }
  1736. void PCB_EDIT_FRAME::PythonSyncEnvironmentVariables()
  1737. {
  1738. const ENV_VAR_MAP& vars = Pgm().GetLocalEnvVariables();
  1739. // Set the environment variables for python scripts
  1740. // note: the string will be encoded UTF8 for python env
  1741. for( const std::pair<const wxString, ENV_VAR_ITEM>& var : vars )
  1742. UpdatePythonEnvVar( var.first, var.second.GetValue() );
  1743. // Because the env vars can be modified by the python scripts (rewritten in UTF8),
  1744. // regenerate them (in Unicode) for our normal environment
  1745. for( const std::pair<const wxString, ENV_VAR_ITEM>& var : vars )
  1746. wxSetEnv( var.first, var.second.GetValue() );
  1747. }
  1748. void PCB_EDIT_FRAME::PythonSyncProjectName()
  1749. {
  1750. wxString evValue;
  1751. wxGetEnv( PROJECT_VAR_NAME, &evValue );
  1752. UpdatePythonEnvVar( wxString( PROJECT_VAR_NAME ).ToStdString(), evValue );
  1753. // Because PROJECT_VAR_NAME can be modified by the python scripts (rewritten in UTF8),
  1754. // regenerate it (in Unicode) for our normal environment
  1755. wxSetEnv( PROJECT_VAR_NAME, evValue );
  1756. }
  1757. void PCB_EDIT_FRAME::ShowFootprintPropertiesDialog( FOOTPRINT* aFootprint )
  1758. {
  1759. if( aFootprint == nullptr )
  1760. return;
  1761. DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_RETVALUE retvalue;
  1762. /*
  1763. * Make sure dlg is destroyed before GetCanvas->Refresh is called
  1764. * later or the refresh will try to modify its properties since
  1765. * they share a GL context.
  1766. */
  1767. {
  1768. DIALOG_FOOTPRINT_PROPERTIES dlg( this, aFootprint );
  1769. dlg.ShowQuasiModal();
  1770. retvalue = dlg.GetReturnValue();
  1771. }
  1772. /*
  1773. * retvalue =
  1774. * FP_PROPS_UPDATE_FP to show Update Footprints dialog
  1775. * FP_PROPS_CHANGE_FP to show Change Footprints dialog
  1776. * FP_PROPS_OK for normal edit
  1777. * FP_PROPS_CANCEL if aborted
  1778. * FP_PROPS_EDIT_BOARD_FP to load board footprint into Footprint Editor
  1779. * FP_PROPS_EDIT_LIBRARY_FP to load library footprint into Footprint Editor
  1780. */
  1781. if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_OK )
  1782. {
  1783. // If something edited, push a refresh request
  1784. GetCanvas()->Refresh();
  1785. }
  1786. else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_BOARD_FP )
  1787. {
  1788. if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ) )
  1789. {
  1790. FOOTPRINT_EDIT_FRAME* fp_editor = static_cast<FOOTPRINT_EDIT_FRAME*>( frame );
  1791. fp_editor->LoadFootprintFromBoard( aFootprint );
  1792. fp_editor->Show( true );
  1793. fp_editor->Raise(); // Iconize( false );
  1794. }
  1795. }
  1796. else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_LIBRARY_FP )
  1797. {
  1798. if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ) )
  1799. {
  1800. FOOTPRINT_EDIT_FRAME* fp_editor = static_cast<FOOTPRINT_EDIT_FRAME*>( frame );
  1801. fp_editor->LoadFootprintFromLibrary( aFootprint->GetFPID() );
  1802. fp_editor->Show( true );
  1803. fp_editor->Raise(); // Iconize( false );
  1804. }
  1805. }
  1806. else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_UPDATE_FP )
  1807. {
  1808. ShowExchangeFootprintsDialog( aFootprint, true, true );
  1809. }
  1810. else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_CHANGE_FP )
  1811. {
  1812. ShowExchangeFootprintsDialog( aFootprint, false, true );
  1813. }
  1814. }
  1815. int PCB_EDIT_FRAME::ShowExchangeFootprintsDialog( FOOTPRINT* aFootprint, bool aUpdateMode,
  1816. bool aSelectedMode )
  1817. {
  1818. DIALOG_EXCHANGE_FOOTPRINTS dialog( this, aFootprint, aUpdateMode, aSelectedMode );
  1819. return dialog.ShowQuasiModal();
  1820. }
  1821. /**
  1822. * copy text settings from aSrc to aDest
  1823. * @param aSrc is the PCB_TEXT source
  1824. * @param aDest is the PCB_TEXT target
  1825. * @param aResetText is true to keep the default target text (false to use the aSrc text)
  1826. * @param aResetTextLayers is true to keep the default target layers setting
  1827. * (false to use the aSrc setting)
  1828. * @param aResetTextEffects is true to keep the default target text effects
  1829. * (false to use the aSrc effect)
  1830. * @param aUpdated is a refrence to a bool to keep trace of changes
  1831. */
  1832. static void processTextItem( const PCB_TEXT& aSrc, PCB_TEXT& aDest,
  1833. bool aResetText, bool aResetTextLayers, bool aResetTextEffects,
  1834. bool aResetTextPositions, bool* aUpdated )
  1835. {
  1836. if( aResetText )
  1837. *aUpdated |= aSrc.GetText() != aDest.GetText();
  1838. else
  1839. aDest.SetText( aSrc.GetText() );
  1840. if( aResetTextLayers )
  1841. {
  1842. *aUpdated |= aSrc.GetLayer() != aDest.GetLayer();
  1843. *aUpdated |= aSrc.IsVisible() != aDest.IsVisible();
  1844. }
  1845. else
  1846. {
  1847. aDest.SetLayer( aSrc.GetLayer() );
  1848. aDest.SetVisible( aSrc.IsVisible() );
  1849. }
  1850. VECTOR2I origPos = aDest.GetFPRelativePosition();
  1851. if( aResetTextEffects )
  1852. {
  1853. *aUpdated |= aSrc.GetHorizJustify() != aDest.GetHorizJustify();
  1854. *aUpdated |= aSrc.GetVertJustify() != aDest.GetVertJustify();
  1855. *aUpdated |= aSrc.GetTextSize() != aDest.GetTextSize();
  1856. *aUpdated |= aSrc.GetTextThickness() != aDest.GetTextThickness();
  1857. *aUpdated |= aSrc.GetTextAngle() != aDest.GetTextAngle();
  1858. }
  1859. else
  1860. {
  1861. aDest.SetAttributes( aSrc );
  1862. }
  1863. if( aResetTextPositions )
  1864. {
  1865. *aUpdated |= aSrc.GetFPRelativePosition() != origPos;
  1866. aDest.SetFPRelativePosition( origPos );
  1867. }
  1868. else
  1869. {
  1870. aDest.SetFPRelativePosition( aSrc.GetFPRelativePosition() );
  1871. }
  1872. aDest.SetLocked( aSrc.IsLocked() );
  1873. const_cast<KIID&>( aDest.m_Uuid ) = aSrc.m_Uuid;
  1874. }
  1875. template<typename T>
  1876. static std::vector<std::pair<T*, T*>> matchItemsBySimilarity( const std::vector<T*>& aExisting,
  1877. const std::vector<T*>& aNew )
  1878. {
  1879. struct MATCH_CANDIDATE
  1880. {
  1881. T* existing;
  1882. T* updated;
  1883. double score;
  1884. };
  1885. std::vector<MATCH_CANDIDATE> candidates;
  1886. for( T* existing : aExisting )
  1887. {
  1888. for( T* updated : aNew )
  1889. {
  1890. if( existing->Type() != updated->Type() )
  1891. continue;
  1892. double similarity = existing->Similarity( *updated );
  1893. if( similarity <= 0.0 )
  1894. continue;
  1895. double score = similarity;
  1896. if constexpr( std::is_same_v<T, PAD> )
  1897. {
  1898. if( existing->GetNumber() == updated->GetNumber() )
  1899. score += 2.0;
  1900. }
  1901. candidates.push_back( { existing, updated, score } );
  1902. }
  1903. }
  1904. std::sort( candidates.begin(), candidates.end(),
  1905. []( const MATCH_CANDIDATE& a, const MATCH_CANDIDATE& b )
  1906. {
  1907. if( a.score != b.score )
  1908. return a.score > b.score;
  1909. if( a.existing != b.existing )
  1910. return a.existing < b.existing;
  1911. return a.updated < b.updated;
  1912. } );
  1913. std::vector<std::pair<T*, T*>> matches;
  1914. matches.reserve( candidates.size() );
  1915. std::unordered_set<T*> matchedExisting;
  1916. std::unordered_set<T*> matchedNew;
  1917. for( const MATCH_CANDIDATE& candidate : candidates )
  1918. {
  1919. if( matchedExisting.find( candidate.existing ) != matchedExisting.end() )
  1920. continue;
  1921. if( matchedNew.find( candidate.updated ) != matchedNew.end() )
  1922. continue;
  1923. matchedExisting.insert( candidate.existing );
  1924. matchedNew.insert( candidate.updated );
  1925. matches.emplace_back( candidate.existing, candidate.updated );
  1926. }
  1927. return matches;
  1928. }
  1929. void PCB_EDIT_FRAME::ExchangeFootprint( FOOTPRINT* aExisting, FOOTPRINT* aNew,
  1930. BOARD_COMMIT& aCommit,
  1931. bool deleteExtraTexts,
  1932. bool resetTextLayers,
  1933. bool resetTextEffects,
  1934. bool resetTextPositions,
  1935. bool resetTextContent,
  1936. bool resetFabricationAttrs,
  1937. bool resetClearanceOverrides,
  1938. bool reset3DModels,
  1939. bool* aUpdated )
  1940. {
  1941. EDA_GROUP* parentGroup = aExisting->GetParentGroup();
  1942. bool dummyBool = false;
  1943. if( !aUpdated )
  1944. aUpdated = &dummyBool;
  1945. if( parentGroup )
  1946. {
  1947. aCommit.Modify( parentGroup->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
  1948. parentGroup->RemoveItem( aExisting );
  1949. parentGroup->AddItem( aNew );
  1950. }
  1951. aNew->SetParent( GetBoard() );
  1952. PlaceFootprint( aNew, false );
  1953. // PlaceFootprint will move the footprint to the cursor position, which we don't want. Copy
  1954. // the original position across.
  1955. aNew->SetPosition( aExisting->GetPosition() );
  1956. if( aNew->GetLayer() != aExisting->GetLayer() )
  1957. aNew->Flip( aNew->GetPosition(), GetPcbNewSettings()->m_FlipDirection );
  1958. if( aNew->GetOrientation() != aExisting->GetOrientation() )
  1959. aNew->SetOrientation( aExisting->GetOrientation() );
  1960. aNew->SetLocked( aExisting->IsLocked() );
  1961. const_cast<KIID&>( aNew->m_Uuid ) = aExisting->m_Uuid;
  1962. const_cast<KIID&>( aNew->Reference().m_Uuid ) = aExisting->Reference().m_Uuid;
  1963. const_cast<KIID&>( aNew->Value().m_Uuid ) = aExisting->Value().m_Uuid;
  1964. std::vector<PAD*> oldPads;
  1965. oldPads.reserve( aExisting->Pads().size() );
  1966. for( PAD* pad : aExisting->Pads() )
  1967. oldPads.push_back( pad );
  1968. std::vector<PAD*> newPads;
  1969. newPads.reserve( aNew->Pads().size() );
  1970. for( PAD* pad : aNew->Pads() )
  1971. newPads.push_back( pad );
  1972. auto padMatches = matchItemsBySimilarity<PAD>( oldPads, newPads );
  1973. std::unordered_set<PAD*> matchedNewPads;
  1974. for( const auto& match : padMatches )
  1975. {
  1976. PAD* oldPad = match.first;
  1977. PAD* newPad = match.second;
  1978. matchedNewPads.insert( newPad );
  1979. const_cast<KIID&>( newPad->m_Uuid ) = oldPad->m_Uuid;
  1980. newPad->SetLocalRatsnestVisible( oldPad->GetLocalRatsnestVisible() );
  1981. newPad->SetPinFunction( oldPad->GetPinFunction() );
  1982. newPad->SetPinType( oldPad->GetPinType() );
  1983. if( newPad->IsOnCopperLayer() )
  1984. newPad->SetNetCode( oldPad->GetNetCode() );
  1985. else
  1986. newPad->SetNetCode( NETINFO_LIST::UNCONNECTED );
  1987. }
  1988. for( PAD* newPad : aNew->Pads() )
  1989. {
  1990. if( matchedNewPads.find( newPad ) != matchedNewPads.end() )
  1991. continue;
  1992. const_cast<KIID&>( newPad->m_Uuid ) = KIID();
  1993. newPad->SetNetCode( NETINFO_LIST::UNCONNECTED );
  1994. }
  1995. std::vector<BOARD_ITEM*> oldDrawings;
  1996. oldDrawings.reserve( aExisting->GraphicalItems().size() );
  1997. for( BOARD_ITEM* item : aExisting->GraphicalItems() )
  1998. oldDrawings.push_back( item );
  1999. std::vector<BOARD_ITEM*> newDrawings;
  2000. newDrawings.reserve( aNew->GraphicalItems().size() );
  2001. for( BOARD_ITEM* item : aNew->GraphicalItems() )
  2002. newDrawings.push_back( item );
  2003. auto drawingMatches = matchItemsBySimilarity<BOARD_ITEM>( oldDrawings, newDrawings );
  2004. std::unordered_map<BOARD_ITEM*, BOARD_ITEM*> oldToNewDrawings;
  2005. std::unordered_set<BOARD_ITEM*> matchedNewDrawings;
  2006. for( const auto& match : drawingMatches )
  2007. {
  2008. BOARD_ITEM* oldItem = match.first;
  2009. BOARD_ITEM* newItem = match.second;
  2010. oldToNewDrawings[ oldItem ] = newItem;
  2011. matchedNewDrawings.insert( newItem );
  2012. const_cast<KIID&>( newItem->m_Uuid ) = oldItem->m_Uuid;
  2013. }
  2014. for( BOARD_ITEM* newItem : newDrawings )
  2015. {
  2016. if( matchedNewDrawings.find( newItem ) == matchedNewDrawings.end() )
  2017. const_cast<KIID&>( newItem->m_Uuid ) = KIID();
  2018. }
  2019. std::vector<ZONE*> oldZones;
  2020. oldZones.reserve( aExisting->Zones().size() );
  2021. for( ZONE* zone : aExisting->Zones() )
  2022. oldZones.push_back( zone );
  2023. std::vector<ZONE*> newZones;
  2024. newZones.reserve( aNew->Zones().size() );
  2025. for( ZONE* zone : aNew->Zones() )
  2026. newZones.push_back( zone );
  2027. auto zoneMatches = matchItemsBySimilarity<ZONE>( oldZones, newZones );
  2028. std::unordered_set<ZONE*> matchedNewZones;
  2029. for( const auto& match : zoneMatches )
  2030. {
  2031. ZONE* oldZone = match.first;
  2032. ZONE* newZone = match.second;
  2033. matchedNewZones.insert( newZone );
  2034. const_cast<KIID&>( newZone->m_Uuid ) = oldZone->m_Uuid;
  2035. }
  2036. for( ZONE* newZone : newZones )
  2037. {
  2038. if( matchedNewZones.find( newZone ) == matchedNewZones.end() )
  2039. const_cast<KIID&>( newZone->m_Uuid ) = KIID();
  2040. }
  2041. std::vector<PCB_POINT*> oldPoints;
  2042. oldPoints.reserve( aExisting->Points().size() );
  2043. for( PCB_POINT* point : aExisting->Points() )
  2044. oldPoints.push_back( point );
  2045. std::vector<PCB_POINT*> newPoints;
  2046. newPoints.reserve( aNew->Points().size() );
  2047. for( PCB_POINT* point : aNew->Points() )
  2048. newPoints.push_back( point );
  2049. auto pointMatches = matchItemsBySimilarity<PCB_POINT>( oldPoints, newPoints );
  2050. std::unordered_set<PCB_POINT*> matchedNewPoints;
  2051. for( const auto& match : pointMatches )
  2052. {
  2053. PCB_POINT* oldPoint = match.first;
  2054. PCB_POINT* newPoint = match.second;
  2055. matchedNewPoints.insert( newPoint );
  2056. const_cast<KIID&>( newPoint->m_Uuid ) = oldPoint->m_Uuid;
  2057. }
  2058. for( PCB_POINT* newPoint : newPoints )
  2059. {
  2060. if( matchedNewPoints.find( newPoint ) == matchedNewPoints.end() )
  2061. const_cast<KIID&>( newPoint->m_Uuid ) = KIID();
  2062. }
  2063. std::vector<PCB_GROUP*> oldGroups;
  2064. oldGroups.reserve( aExisting->Groups().size() );
  2065. for( PCB_GROUP* group : aExisting->Groups() )
  2066. oldGroups.push_back( group );
  2067. std::vector<PCB_GROUP*> newGroups;
  2068. newGroups.reserve( aNew->Groups().size() );
  2069. for( PCB_GROUP* group : aNew->Groups() )
  2070. newGroups.push_back( group );
  2071. auto groupMatches = matchItemsBySimilarity<PCB_GROUP>( oldGroups, newGroups );
  2072. std::unordered_set<PCB_GROUP*> matchedNewGroups;
  2073. for( const auto& match : groupMatches )
  2074. {
  2075. PCB_GROUP* oldGroup = match.first;
  2076. PCB_GROUP* newGroup = match.second;
  2077. matchedNewGroups.insert( newGroup );
  2078. const_cast<KIID&>( newGroup->m_Uuid ) = oldGroup->m_Uuid;
  2079. }
  2080. for( PCB_GROUP* newGroup : newGroups )
  2081. {
  2082. if( matchedNewGroups.find( newGroup ) == matchedNewGroups.end() )
  2083. const_cast<KIID&>( newGroup->m_Uuid ) = KIID();
  2084. }
  2085. std::vector<PCB_FIELD*> oldFieldsVec;
  2086. std::vector<PCB_FIELD*> newFieldsVec;
  2087. oldFieldsVec.reserve( aExisting->GetFields().size() );
  2088. for( PCB_FIELD* field : aExisting->GetFields() )
  2089. {
  2090. if( field->IsReference() || field->IsValue() )
  2091. continue;
  2092. oldFieldsVec.push_back( field );
  2093. }
  2094. newFieldsVec.reserve( aNew->GetFields().size() );
  2095. for( PCB_FIELD* field : aNew->GetFields() )
  2096. {
  2097. if( field->IsReference() || field->IsValue() )
  2098. continue;
  2099. newFieldsVec.push_back( field );
  2100. }
  2101. auto fieldMatches = matchItemsBySimilarity<PCB_FIELD>( oldFieldsVec, newFieldsVec );
  2102. std::unordered_map<PCB_FIELD*, PCB_FIELD*> oldToNewFields;
  2103. std::unordered_set<PCB_FIELD*> matchedNewFields;
  2104. for( const auto& match : fieldMatches )
  2105. {
  2106. PCB_FIELD* oldField = match.first;
  2107. PCB_FIELD* newField = match.second;
  2108. oldToNewFields[ oldField ] = newField;
  2109. matchedNewFields.insert( newField );
  2110. const_cast<KIID&>( newField->m_Uuid ) = oldField->m_Uuid;
  2111. }
  2112. for( PCB_FIELD* newField : newFieldsVec )
  2113. {
  2114. if( matchedNewFields.find( newField ) == matchedNewFields.end() )
  2115. const_cast<KIID&>( newField->m_Uuid ) = KIID();
  2116. }
  2117. std::unordered_map<PCB_TEXT*, PCB_TEXT*> oldToNewTexts;
  2118. for( const auto& match : drawingMatches )
  2119. {
  2120. PCB_TEXT* oldText = dynamic_cast<PCB_TEXT*>( match.first );
  2121. PCB_TEXT* newText = dynamic_cast<PCB_TEXT*>( match.second );
  2122. if( oldText && newText )
  2123. oldToNewTexts[ oldText ] = newText;
  2124. }
  2125. std::set<PCB_TEXT*> handledTextItems;
  2126. for( BOARD_ITEM* oldItem : aExisting->GraphicalItems() )
  2127. {
  2128. PCB_TEXT* oldTextItem = dynamic_cast<PCB_TEXT*>( oldItem );
  2129. if( oldTextItem )
  2130. {
  2131. // Dimensions have PCB_TEXT base but are not treated like texts in the updater
  2132. if( dynamic_cast<PCB_DIMENSION_BASE*>( oldTextItem ) )
  2133. continue;
  2134. PCB_TEXT* newTextItem = nullptr;
  2135. auto textMatchIt = oldToNewTexts.find( oldTextItem );
  2136. if( textMatchIt != oldToNewTexts.end() )
  2137. newTextItem = textMatchIt->second;
  2138. if( newTextItem )
  2139. {
  2140. handledTextItems.insert( newTextItem );
  2141. processTextItem( *oldTextItem, *newTextItem, resetTextContent, resetTextLayers,
  2142. resetTextEffects, resetTextPositions, aUpdated );
  2143. }
  2144. else if( deleteExtraTexts )
  2145. {
  2146. *aUpdated = true;
  2147. }
  2148. else
  2149. {
  2150. newTextItem = static_cast<PCB_TEXT*>( oldTextItem->Clone() );
  2151. handledTextItems.insert( newTextItem );
  2152. aNew->Add( newTextItem );
  2153. }
  2154. }
  2155. }
  2156. // Check for any newly-added text items and set the update flag as appropriate
  2157. for( BOARD_ITEM* newItem : aNew->GraphicalItems() )
  2158. {
  2159. PCB_TEXT* newTextItem = dynamic_cast<PCB_TEXT*>( newItem );
  2160. if( newTextItem )
  2161. {
  2162. // Dimensions have PCB_TEXT base but are not treated like texts in the updater
  2163. if( dynamic_cast<PCB_DIMENSION_BASE*>( newTextItem ) )
  2164. continue;
  2165. if( !handledTextItems.contains( newTextItem ) )
  2166. {
  2167. *aUpdated = true;
  2168. break;
  2169. }
  2170. }
  2171. }
  2172. // Copy reference. The initial text is always used, never resetted
  2173. processTextItem( aExisting->Reference(), aNew->Reference(), false, resetTextLayers,
  2174. resetTextEffects, resetTextPositions, aUpdated );
  2175. // Copy value
  2176. processTextItem( aExisting->Value(), aNew->Value(),
  2177. // reset value text only when it is a proxy for the footprint ID
  2178. // (cf replacing value "MountingHole-2.5mm" with "MountingHole-4.0mm")
  2179. aExisting->GetValue() == aExisting->GetFPID().GetLibItemName().wx_str(),
  2180. resetTextLayers, resetTextEffects, resetTextPositions, aUpdated );
  2181. std::set<PCB_FIELD*> handledFields;
  2182. // Copy fields in accordance with the reset* flags
  2183. for( PCB_FIELD* oldField : aExisting->GetFields() )
  2184. {
  2185. // Reference and value are already handled
  2186. if( oldField->IsReference() || oldField->IsValue() )
  2187. continue;
  2188. PCB_FIELD* newField = nullptr;
  2189. auto fieldMatchIt = oldToNewFields.find( oldField );
  2190. if( fieldMatchIt != oldToNewFields.end() )
  2191. newField = fieldMatchIt->second;
  2192. if( newField )
  2193. {
  2194. handledFields.insert( newField );
  2195. processTextItem( *oldField, *newField, resetTextContent, resetTextLayers,
  2196. resetTextEffects, resetTextPositions, aUpdated );
  2197. }
  2198. else if( deleteExtraTexts )
  2199. {
  2200. *aUpdated = true;
  2201. }
  2202. else
  2203. {
  2204. newField = new PCB_FIELD( *oldField );
  2205. handledFields.insert( newField );
  2206. aNew->Add( newField );
  2207. }
  2208. }
  2209. // Check for any newly-added fields and set the update flag as appropriate
  2210. for( PCB_FIELD* newField : aNew->GetFields() )
  2211. {
  2212. // Reference and value are already handled
  2213. if( newField->IsReference() || newField->IsValue() )
  2214. continue;
  2215. if( !handledFields.contains( newField ) )
  2216. {
  2217. *aUpdated = true;
  2218. break;
  2219. }
  2220. }
  2221. if( resetFabricationAttrs )
  2222. {
  2223. // We've replaced the existing footprint with the library one, so the fabrication attrs
  2224. // are already reset. Just set the aUpdated flag if appropriate.
  2225. if( aNew->GetAttributes() != aExisting->GetAttributes() )
  2226. *aUpdated = true;
  2227. }
  2228. else
  2229. {
  2230. aNew->SetAttributes( aExisting->GetAttributes() );
  2231. }
  2232. if( resetClearanceOverrides )
  2233. {
  2234. if( aExisting->AllowSolderMaskBridges() != aNew->AllowSolderMaskBridges() )
  2235. *aUpdated = true;
  2236. if( ( aExisting->GetLocalClearance() != aNew->GetLocalClearance() )
  2237. || ( aExisting->GetLocalSolderMaskMargin() != aNew->GetLocalSolderMaskMargin() )
  2238. || ( aExisting->GetLocalSolderPasteMargin() != aNew->GetLocalSolderPasteMargin() )
  2239. || ( aExisting->GetLocalSolderPasteMarginRatio() != aNew->GetLocalSolderPasteMarginRatio() )
  2240. || ( aExisting->GetLocalZoneConnection() != aNew->GetLocalZoneConnection() ) )
  2241. {
  2242. *aUpdated = true;
  2243. }
  2244. }
  2245. else
  2246. {
  2247. aNew->SetLocalClearance( aExisting->GetLocalClearance() );
  2248. aNew->SetLocalSolderMaskMargin( aExisting->GetLocalSolderMaskMargin() );
  2249. aNew->SetLocalSolderPasteMargin( aExisting->GetLocalSolderPasteMargin() );
  2250. aNew->SetLocalSolderPasteMarginRatio( aExisting->GetLocalSolderPasteMarginRatio() );
  2251. aNew->SetLocalZoneConnection( aExisting->GetLocalZoneConnection() );
  2252. aNew->SetAllowSolderMaskBridges( aExisting->AllowSolderMaskBridges() );
  2253. }
  2254. if( reset3DModels )
  2255. {
  2256. // We've replaced the existing footprint with the library one, so the 3D models are
  2257. // already reset. Just set the aUpdated flag if appropriate.
  2258. if( aNew->Models().size() != aExisting->Models().size() )
  2259. {
  2260. *aUpdated = true;
  2261. }
  2262. else
  2263. {
  2264. for( size_t ii = 0; ii < aNew->Models().size(); ++ii )
  2265. {
  2266. if( aNew->Models()[ii] != aExisting->Models()[ii] )
  2267. {
  2268. *aUpdated = true;
  2269. break;
  2270. }
  2271. }
  2272. }
  2273. }
  2274. else
  2275. {
  2276. aNew->Models() = aExisting->Models(); // Linked list of 3D models.
  2277. }
  2278. // Updating other parameters
  2279. aNew->SetPath( aExisting->GetPath() );
  2280. aNew->SetSheetfile( aExisting->GetSheetfile() );
  2281. aNew->SetSheetname( aExisting->GetSheetname() );
  2282. aNew->SetFilters( aExisting->GetFilters() );
  2283. aNew->SetStaticComponentClass( aExisting->GetComponentClass() );
  2284. if( *aUpdated == false )
  2285. {
  2286. // Check pad shapes, graphics, zones, etc. for changes
  2287. if( aNew->FootprintNeedsUpdate( aExisting, BOARD_ITEM::COMPARE_FLAGS::INSTANCE_TO_INSTANCE ) )
  2288. *aUpdated = true;
  2289. }
  2290. aCommit.Remove( aExisting );
  2291. aCommit.Add( aNew );
  2292. aNew->ClearFlags();
  2293. }
  2294. void PCB_EDIT_FRAME::CommonSettingsChanged( int aFlags )
  2295. {
  2296. PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aFlags );
  2297. GetAppearancePanel()->OnColorThemeChanged();
  2298. SetElementVisibility( LAYER_RATSNEST, GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest );
  2299. GetGalDisplayOptions().ReadWindowSettings( GetPcbNewSettings()->m_Window );
  2300. // Netclass definitions could have changed, either by us or by Eeschema, so we need to
  2301. // recompile the implicit rules
  2302. DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
  2303. WX_INFOBAR* infobar = GetInfoBar();
  2304. try
  2305. {
  2306. drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
  2307. if( infobar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::DRC_RULES_ERROR )
  2308. infobar->Dismiss();
  2309. }
  2310. catch( PARSE_ERROR& )
  2311. {
  2312. wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Edit design rules" ),
  2313. wxEmptyString );
  2314. button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
  2315. [&]( wxHyperlinkEvent& aEvent )
  2316. {
  2317. ShowBoardSetupDialog( _( "Custom Rules" ) );
  2318. } ) );
  2319. infobar->RemoveAllButtons();
  2320. infobar->AddButton( button );
  2321. infobar->AddCloseButton();
  2322. infobar->ShowMessage( _( "Could not compile custom design rules." ), wxICON_ERROR,
  2323. WX_INFOBAR::MESSAGE_TYPE::DRC_RULES_ERROR );
  2324. }
  2325. GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
  2326. GetCanvas()->ForceRefresh();
  2327. // Update the environment variables in the Python interpreter
  2328. if( aFlags & ENVVARS_CHANGED )
  2329. PythonSyncEnvironmentVariables();
  2330. Layout();
  2331. SendSizeEvent();
  2332. }
  2333. void PCB_EDIT_FRAME::ThemeChanged()
  2334. {
  2335. PCB_BASE_EDIT_FRAME::ThemeChanged();
  2336. }
  2337. void PCB_EDIT_FRAME::ProjectChanged()
  2338. {
  2339. PythonSyncProjectName();
  2340. }
  2341. bool PCB_EDIT_FRAME::CanAcceptApiCommands()
  2342. {
  2343. // For now, be conservative: Don't allow any API use while the user is changing things
  2344. if( GetToolManager()->GetCurrentTool() != GetToolManager()->GetTool<PCB_SELECTION_TOOL>() )
  2345. return false;
  2346. ZONE_FILLER_TOOL* zoneFillerTool = m_toolManager->GetTool<ZONE_FILLER_TOOL>();
  2347. if( zoneFillerTool->IsBusy() )
  2348. return false;
  2349. ROUTER_TOOL* routerTool = m_toolManager->GetTool<ROUTER_TOOL>();
  2350. if( routerTool && routerTool->RoutingInProgress() )
  2351. return false;
  2352. return EDA_BASE_FRAME::CanAcceptApiCommands();
  2353. }
  2354. wxString PCB_EDIT_FRAME::GetCurrentFileName() const
  2355. {
  2356. return GetBoard()->GetFileName();
  2357. }
  2358. bool PCB_EDIT_FRAME::LayerManagerShown()
  2359. {
  2360. return m_auimgr.GetPane( wxS( "LayersManager" ) ).IsShown();
  2361. }
  2362. bool PCB_EDIT_FRAME::PropertiesShown()
  2363. {
  2364. return m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
  2365. }
  2366. bool PCB_EDIT_FRAME::NetInspectorShown()
  2367. {
  2368. return m_auimgr.GetPane( NetInspectorPanelName() ).IsShown();
  2369. }
  2370. void PCB_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
  2371. {
  2372. if( IsShownOnScreen() )
  2373. {
  2374. // We only need this until the frame is done resizing and the final client size is
  2375. // established.
  2376. Unbind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
  2377. GetToolManager()->RunAction( ACTIONS::zoomFitScreen );
  2378. }
  2379. // Skip() is called in the base class.
  2380. EDA_DRAW_FRAME::OnSize( aEvent );
  2381. }
  2382. DIALOG_BOOK_REPORTER* PCB_EDIT_FRAME::GetInspectDrcErrorDialog()
  2383. {
  2384. if( !m_inspectDrcErrorDlg )
  2385. {
  2386. m_inspectDrcErrorDlg = new DIALOG_BOOK_REPORTER( this, INSPECT_DRC_ERROR_DIALOG_NAME,
  2387. _( "Violation Report" ) );
  2388. }
  2389. return m_inspectDrcErrorDlg;
  2390. }
  2391. DIALOG_BOOK_REPORTER* PCB_EDIT_FRAME::GetInspectClearanceDialog()
  2392. {
  2393. if( !m_inspectClearanceDlg )
  2394. {
  2395. m_inspectClearanceDlg = new DIALOG_BOOK_REPORTER( this, INSPECT_CLEARANCE_DIALOG_NAME,
  2396. _( "Clearance Report" ) );
  2397. }
  2398. return m_inspectClearanceDlg;
  2399. }
  2400. DIALOG_BOOK_REPORTER* PCB_EDIT_FRAME::GetInspectConstraintsDialog()
  2401. {
  2402. if( !m_inspectConstraintsDlg )
  2403. {
  2404. m_inspectConstraintsDlg = new DIALOG_BOOK_REPORTER( this, INSPECT_CONSTRAINTS_DIALOG_NAME,
  2405. _( "Constraints Report" ) );
  2406. }
  2407. return m_inspectConstraintsDlg;
  2408. }
  2409. DIALOG_BOOK_REPORTER* PCB_EDIT_FRAME::GetFootprintDiffDialog()
  2410. {
  2411. if( !m_footprintDiffDlg )
  2412. {
  2413. m_footprintDiffDlg = new DIALOG_BOOK_REPORTER( this, FOOTPRINT_DIFF_DIALOG_NAME,
  2414. _( "Compare Footprint with Library" ) );
  2415. m_footprintDiffDlg->m_sdbSizerApply->SetLabel( _( "Update Footprint from Library..." ) );
  2416. m_footprintDiffDlg->m_sdbSizerApply->Show();
  2417. }
  2418. return m_footprintDiffDlg;
  2419. }
  2420. void PCB_EDIT_FRAME::onCloseModelessBookReporterDialogs( wxCommandEvent& aEvent )
  2421. {
  2422. if( m_inspectDrcErrorDlg && aEvent.GetString() == INSPECT_DRC_ERROR_DIALOG_NAME )
  2423. {
  2424. m_inspectDrcErrorDlg->Destroy();
  2425. m_inspectDrcErrorDlg = nullptr;
  2426. }
  2427. else if( m_inspectClearanceDlg && aEvent.GetString() == INSPECT_CLEARANCE_DIALOG_NAME )
  2428. {
  2429. m_inspectClearanceDlg->Destroy();
  2430. m_inspectClearanceDlg = nullptr;
  2431. }
  2432. else if( m_inspectConstraintsDlg && aEvent.GetString() == INSPECT_CONSTRAINTS_DIALOG_NAME )
  2433. {
  2434. m_inspectConstraintsDlg->Destroy();
  2435. m_inspectConstraintsDlg = nullptr;
  2436. }
  2437. else if( m_footprintDiffDlg && aEvent.GetString() == FOOTPRINT_DIFF_DIALOG_NAME )
  2438. {
  2439. if( aEvent.GetId() == wxID_APPLY )
  2440. {
  2441. KIID fpUUID = m_footprintDiffDlg->GetUserItemID();
  2442. CallAfter(
  2443. [this, fpUUID]()
  2444. {
  2445. BOARD_ITEM* item = m_pcb->ResolveItem( fpUUID );
  2446. if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item ) )
  2447. {
  2448. m_toolManager->RunAction<EDA_ITEM*>( ACTIONS::selectItem, footprint );
  2449. DIALOG_EXCHANGE_FOOTPRINTS dialog( this, footprint, true, true );
  2450. dialog.ShowQuasiModal();
  2451. }
  2452. } );
  2453. }
  2454. m_footprintDiffDlg->Destroy();
  2455. m_footprintDiffDlg = nullptr;
  2456. }
  2457. }
  2458. #ifdef KICAD_IPC_API
  2459. void PCB_EDIT_FRAME::onPluginAvailabilityChanged( wxCommandEvent& aEvt )
  2460. {
  2461. wxLogTrace( traceApi, "PCB frame: EDA_EVT_PLUGIN_AVAILABILITY_CHANGED" );
  2462. ReCreateHToolbar();
  2463. aEvt.Skip();
  2464. }
  2465. #endif
  2466. void PCB_EDIT_FRAME::SwitchLayer( PCB_LAYER_ID layer )
  2467. {
  2468. PCB_LAYER_ID curLayer = GetActiveLayer();
  2469. const PCB_DISPLAY_OPTIONS& displ_opts = GetDisplayOptions();
  2470. // Check if the specified layer matches the present layer
  2471. if( layer == curLayer )
  2472. return;
  2473. // Copper layers cannot be selected unconditionally; how many of those layers are currently
  2474. // enabled needs to be checked.
  2475. if( IsCopperLayer( layer ) )
  2476. {
  2477. if( layer > GetBoard()->GetCopperLayerStackMaxId() )
  2478. return;
  2479. }
  2480. // Is yet more checking required? E.g. when the layer to be selected is a non-copper layer,
  2481. // or when switching between a copper layer and a non-copper layer, or vice-versa?
  2482. SetActiveLayer( layer );
  2483. if( displ_opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL )
  2484. GetCanvas()->Refresh();
  2485. }
  2486. void PCB_EDIT_FRAME::OnEditItemRequest( BOARD_ITEM* aItem )
  2487. {
  2488. switch( aItem->Type() )
  2489. {
  2490. case PCB_REFERENCE_IMAGE_T:
  2491. ShowReferenceImagePropertiesDialog( aItem );
  2492. break;
  2493. case PCB_FIELD_T:
  2494. case PCB_TEXT_T:
  2495. ShowTextPropertiesDialog( static_cast<PCB_TEXT*>( aItem ) );
  2496. break;
  2497. case PCB_TEXTBOX_T:
  2498. ShowTextBoxPropertiesDialog( static_cast<PCB_TEXTBOX*>( aItem ) );
  2499. break;
  2500. case PCB_TABLE_T:
  2501. {
  2502. DIALOG_TABLE_PROPERTIES dlg( this, static_cast<PCB_TABLE*>( aItem ) );
  2503. //QuasiModal required for Scintilla auto-complete
  2504. dlg.ShowQuasiModal();
  2505. break;
  2506. }
  2507. case PCB_PAD_T:
  2508. ShowPadPropertiesDialog( static_cast<PAD*>( aItem ) );
  2509. break;
  2510. case PCB_FOOTPRINT_T:
  2511. ShowFootprintPropertiesDialog( static_cast<FOOTPRINT*>( aItem ) );
  2512. break;
  2513. case PCB_TARGET_T:
  2514. ShowTargetOptionsDialog( static_cast<PCB_TARGET*>( aItem ) );
  2515. break;
  2516. case PCB_DIM_ALIGNED_T:
  2517. case PCB_DIM_CENTER_T:
  2518. case PCB_DIM_RADIAL_T:
  2519. case PCB_DIM_ORTHOGONAL_T:
  2520. case PCB_DIM_LEADER_T:
  2521. {
  2522. DIALOG_DIMENSION_PROPERTIES dlg( this, static_cast<PCB_DIMENSION_BASE*>( aItem ) );
  2523. // TODO: why is this QuasiModal?
  2524. dlg.ShowQuasiModal();
  2525. break;
  2526. }
  2527. case PCB_SHAPE_T:
  2528. ShowGraphicItemPropertiesDialog( static_cast<PCB_SHAPE*>( aItem ) );
  2529. break;
  2530. case PCB_ZONE_T:
  2531. Edit_Zone_Params( static_cast<ZONE*>( aItem ) );
  2532. break;
  2533. case PCB_GROUP_T:
  2534. m_toolManager->RunAction( ACTIONS::groupProperties,
  2535. static_cast<EDA_GROUP*>( static_cast<PCB_GROUP*>( aItem ) ) );
  2536. break;
  2537. case PCB_GENERATOR_T:
  2538. static_cast<PCB_GENERATOR*>( aItem )->ShowPropertiesDialog( this );
  2539. break;
  2540. case PCB_MARKER_T:
  2541. m_toolManager->GetTool<DRC_TOOL>()->CrossProbe( static_cast<PCB_MARKER*>( aItem ) );
  2542. break;
  2543. case PCB_POINT_T:
  2544. break;
  2545. default:
  2546. break;
  2547. }
  2548. }