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.

1938 lines
65 KiB

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