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.

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