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.

2343 lines
76 KiB

5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
Mark null project initial screen as zoom-initialized The variable `m_Initialized` in `BASE_SCREEN` is used by `SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized by the "zoom to fit screen" action. When this variable is `false`, the function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit screen", modifying the zoom level. This function is indirectly called in the undo routines, so if `m_Initialized` is not set to `true`, a zoom change will occur when the user undoes an operation, a behavior that is undesired. `m_Initialized` was not initialized to `true` for the null schematic (the schematic that is loaded if no project is loaded), causing the aforementioned undesired behavior. To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set `m_Initialized` to `true`, since it zooms to fit screen already. I've moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used only in Eeschema, and renamed it to `m_zoomInitialized`, a name I believe that better describes what this variable does. I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to group the "zoom to fit screen" action with setting `m_Initialized` to `true`, as they often should occur together. I'd also like to say that I'm not confident whether `SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level initialization at this point, but I have decided to not change this behavior for now, as the commit history suggests it's several years old. Fixes https://gitlab.com/kicad/code/kicad/issues/7343
5 years ago
7 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
5 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
3 years ago
7 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
3 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* 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
Mark null project initial screen as zoom-initialized The variable `m_Initialized` in `BASE_SCREEN` is used by `SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized by the "zoom to fit screen" action. When this variable is `false`, the function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit screen", modifying the zoom level. This function is indirectly called in the undo routines, so if `m_Initialized` is not set to `true`, a zoom change will occur when the user undoes an operation, a behavior that is undesired. `m_Initialized` was not initialized to `true` for the null schematic (the schematic that is loaded if no project is loaded), causing the aforementioned undesired behavior. To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set `m_Initialized` to `true`, since it zooms to fit screen already. I've moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used only in Eeschema, and renamed it to `m_zoomInitialized`, a name I believe that better describes what this variable does. I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to group the "zoom to fit screen" action with setting `m_Initialized` to `true`, as they often should occur together. I'd also like to say that I'm not confident whether `SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level initialization at this point, but I have decided to not change this behavior for now, as the commit history suggests it's several years old. Fixes https://gitlab.com/kicad/code/kicad/issues/7343
5 years ago
Mark null project initial screen as zoom-initialized The variable `m_Initialized` in `BASE_SCREEN` is used by `SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized by the "zoom to fit screen" action. When this variable is `false`, the function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit screen", modifying the zoom level. This function is indirectly called in the undo routines, so if `m_Initialized` is not set to `true`, a zoom change will occur when the user undoes an operation, a behavior that is undesired. `m_Initialized` was not initialized to `true` for the null schematic (the schematic that is loaded if no project is loaded), causing the aforementioned undesired behavior. To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set `m_Initialized` to `true`, since it zooms to fit screen already. I've moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used only in Eeschema, and renamed it to `m_zoomInitialized`, a name I believe that better describes what this variable does. I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to group the "zoom to fit screen" action with setting `m_Initialized` to `true`, as they often should occur together. I'd also like to say that I'm not confident whether `SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level initialization at this point, but I have decided to not change this behavior for now, as the commit history suggests it's several years old. Fixes https://gitlab.com/kicad/code/kicad/issues/7343
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <base_units.h>
  25. #include <bitmaps.h>
  26. #include <symbol_library.h>
  27. #include <confirm.h>
  28. #include <connection_graph.h>
  29. #include <dialogs/dialog_erc.h>
  30. #include <dialogs/dialog_schematic_find.h>
  31. #include <dialogs/dialog_book_reporter.h>
  32. #include <dialogs/dialog_symbol_fields_table.h>
  33. #include <eeschema_id.h>
  34. #include <executable_names.h>
  35. #include <gal/graphics_abstraction_layer.h>
  36. #include <gestfich.h>
  37. #include <dialogs/html_message_box.h>
  38. #include <core/ignore.h>
  39. #include <invoke_sch_dialog.h>
  40. #include <string_utils.h>
  41. #include <kiface_base.h>
  42. #include <kiplatform/app.h>
  43. #include <kiway.h>
  44. #include <symbol_edit_frame.h>
  45. #include <symbol_viewer_frame.h>
  46. #include <pgm_base.h>
  47. #include <core/profile.h>
  48. #include <project/project_file.h>
  49. #include <project/net_settings.h>
  50. #include <python_scripting.h>
  51. #include <sch_edit_frame.h>
  52. #include <symbol_chooser_frame.h>
  53. #include <sch_painter.h>
  54. #include <sch_sheet.h>
  55. #include <sch_marker.h>
  56. #include <schematic.h>
  57. #include <sch_commit.h>
  58. #include <settings/settings_manager.h>
  59. #include <advanced_config.h>
  60. #include <sim/simulator_frame.h>
  61. #include <tool/action_manager.h>
  62. #include <tool/action_toolbar.h>
  63. #include <tool/common_control.h>
  64. #include <tool/common_tools.h>
  65. #include <tool/picker_tool.h>
  66. #include <tool/properties_tool.h>
  67. #include <tool/selection.h>
  68. #include <tool/tool_dispatcher.h>
  69. #include <tool/tool_manager.h>
  70. #include <tool/zoom_tool.h>
  71. #include <tools/ee_actions.h>
  72. #include <tools/ee_inspection_tool.h>
  73. #include <tools/ee_point_editor.h>
  74. #include <tools/ee_selection_tool.h>
  75. #include <tools/sch_drawing_tools.h>
  76. #include <tools/sch_edit_tool.h>
  77. #include <tools/sch_editor_conditions.h>
  78. #include <tools/sch_editor_control.h>
  79. #include <tools/sch_line_wire_bus_tool.h>
  80. #include <tools/sch_move_tool.h>
  81. #include <tools/sch_navigate_tool.h>
  82. #include <tools/sch_find_replace_tool.h>
  83. #include <view/view_controls.h>
  84. #include <widgets/wx_infobar.h>
  85. #include <widgets/hierarchy_pane.h>
  86. #include <widgets/sch_properties_panel.h>
  87. #include <widgets/sch_search_pane.h>
  88. #include <wildcards_and_files_ext.h>
  89. #include <wx/cmdline.h>
  90. #include <wx/app.h>
  91. #include <wx/filedlg.h>
  92. #include <wx/socket.h>
  93. #include <widgets/wx_aui_utils.h>
  94. #include <drawing_sheet/ds_proxy_view_item.h>
  95. #define DIFF_SYMBOLS_DIALOG_NAME wxT( "DiffSymbolsDialog" )
  96. BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, SCH_BASE_FRAME )
  97. EVT_SOCKET( ID_EDA_SOCKET_EVENT_SERV, EDA_DRAW_FRAME::OnSockRequestServer )
  98. EVT_SOCKET( ID_EDA_SOCKET_EVENT, EDA_DRAW_FRAME::OnSockRequest )
  99. EVT_SIZE( SCH_EDIT_FRAME::OnSize )
  100. EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, SCH_EDIT_FRAME::OnLoadFile )
  101. EVT_MENU( ID_FILE_LIST_CLEAR, SCH_EDIT_FRAME::OnClearFileHistory )
  102. EVT_MENU( ID_APPEND_PROJECT, SCH_EDIT_FRAME::OnAppendProject )
  103. EVT_MENU( ID_IMPORT_NON_KICAD_SCH, SCH_EDIT_FRAME::OnImportProject )
  104. EVT_MENU( wxID_EXIT, SCH_EDIT_FRAME::OnExit )
  105. EVT_MENU( wxID_CLOSE, SCH_EDIT_FRAME::OnExit )
  106. // Drop files event
  107. EVT_DROP_FILES( SCH_EDIT_FRAME::OnDropFiles )
  108. END_EVENT_TABLE()
  109. wxDEFINE_EVENT( EDA_EVT_SCHEMATIC_CHANGED, wxCommandEvent );
  110. SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  111. SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH, wxT( "Eeschema" ), wxDefaultPosition,
  112. wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, SCH_EDIT_FRAME_NAME ),
  113. m_ercDialog( nullptr ),
  114. m_diffSymbolDialog( nullptr ),
  115. m_symbolFieldsTableDialog( nullptr ),
  116. m_netNavigator( nullptr ),
  117. m_highlightedConnChanged( false )
  118. {
  119. m_maximizeByDefault = true;
  120. m_schematic = new SCHEMATIC( nullptr );
  121. m_showBorderAndTitleBlock = true; // true to show sheet references
  122. m_supportsAutoSave = true;
  123. m_syncingPcbToSchSelection = false;
  124. m_aboutTitle = _HKI( "KiCad Schematic Editor" );
  125. m_show_search = false;
  126. m_findReplaceDialog = nullptr;
  127. m_findReplaceData = std::make_unique<SCH_SEARCH_DATA>();
  128. // Give an icon
  129. wxIcon icon;
  130. wxIconBundle icon_bundle;
  131. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 48 ) );
  132. icon_bundle.AddIcon( icon );
  133. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 128 ) );
  134. icon_bundle.AddIcon( icon );
  135. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 256 ) );
  136. icon_bundle.AddIcon( icon );
  137. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_32 ) );
  138. icon_bundle.AddIcon( icon );
  139. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_16 ) );
  140. icon_bundle.AddIcon( icon );
  141. SetIcons( icon_bundle );
  142. LoadSettings( eeconfig() );
  143. // NB: also links the schematic to the loaded project
  144. CreateScreens();
  145. SetCurrentSheet( Schematic().GetSheets()[0] );
  146. setupTools();
  147. setupUIConditions();
  148. ReCreateMenuBar();
  149. ReCreateHToolbar();
  150. ReCreateVToolbar();
  151. ReCreateOptToolbar();
  152. m_hierarchy = new HIERARCHY_PANE( this );
  153. // Initialize common print setup dialog settings.
  154. m_pageSetupData.GetPrintData().SetPrintMode( wxPRINT_MODE_PRINTER );
  155. m_pageSetupData.GetPrintData().SetQuality( wxPRINT_QUALITY_MEDIUM );
  156. m_pageSetupData.GetPrintData().SetBin( wxPRINTBIN_AUTO );
  157. m_pageSetupData.GetPrintData().SetNoCopies( 1 );
  158. m_searchPane = new SCH_SEARCH_PANE( this );
  159. m_propertiesPanel = new SCH_PROPERTIES_PANEL( this, this );
  160. m_propertiesPanel->SetSplitterProportion( eeconfig()->m_AuiPanels.properties_splitter );
  161. m_auimgr.SetManagedWindow( this );
  162. CreateInfoBar();
  163. // Rows; layers 4 - 6
  164. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( wxS( "MainToolbar" ) )
  165. .Top().Layer( 6 ) );
  166. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( wxS( "MsgPanel" ) )
  167. .Bottom().Layer( 6 ) );
  168. // Columns; layers 1 - 3
  169. m_auimgr.AddPane( m_hierarchy, EDA_PANE().Palette().Name( SchematicHierarchyPaneName() )
  170. .Caption( _( "Schematic Hierarchy" ) )
  171. .Left().Layer( 3 )
  172. .TopDockable( false )
  173. .BottomDockable( false )
  174. .CloseButton( true )
  175. .MinSize( 120, 60 )
  176. .BestSize( 200, 200 )
  177. .FloatingSize( 200, 200 )
  178. .FloatingPosition( 50, 50 )
  179. .Show( false ) );
  180. m_auimgr.AddPane( m_propertiesPanel, defaultPropertiesPaneInfo() );
  181. m_auimgr.AddPane( createHighlightedNetNavigator(), defaultNetNavigatorPaneInfo() );
  182. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( wxS( "OptToolbar" ) )
  183. .Left().Layer( 2 ) );
  184. m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( wxS( "ToolsToolbar" ) )
  185. .Right().Layer( 2 ) );
  186. // Center
  187. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( wxS( "DrawFrame" ) )
  188. .Center() );
  189. m_auimgr.AddPane( m_searchPane, EDA_PANE()
  190. .Name( SearchPaneName() )
  191. .Bottom()
  192. .Caption( _( "Search" ) )
  193. .PaneBorder( false )
  194. .MinSize( 180, 60 )
  195. .BestSize( 180, 100 )
  196. .FloatingSize( 480, 200 )
  197. .CloseButton( true )
  198. .DestroyOnClose( false )
  199. .Show( m_show_search ) );
  200. FinishAUIInitialization();
  201. resolveCanvasType();
  202. SwitchCanvas( m_canvasType );
  203. GetCanvas()->GetGAL()->SetAxesEnabled( false );
  204. KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
  205. static_cast<KIGFX::SCH_PAINTER*>( view->GetPainter() )->SetSchematic( m_schematic );
  206. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  207. wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
  208. wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
  209. EESCHEMA_SETTINGS* cfg = eeconfig();
  210. hierarchy_pane.Show( cfg->m_AuiPanels.show_schematic_hierarchy );
  211. netNavigatorPane.Show( cfg->m_AuiPanels.show_net_nav_panel );
  212. propertiesPane.Show( cfg->m_AuiPanels.show_properties );
  213. if( cfg->m_AuiPanels.hierarchy_panel_float_width > 0
  214. && cfg->m_AuiPanels.hierarchy_panel_float_height > 0 )
  215. {
  216. // Show at end, after positioning
  217. hierarchy_pane.FloatingSize( cfg->m_AuiPanels.hierarchy_panel_float_width,
  218. cfg->m_AuiPanels.hierarchy_panel_float_height );
  219. }
  220. if( cfg->m_AuiPanels.net_nav_panel_float_size.GetWidth() > 0
  221. && cfg->m_AuiPanels.net_nav_panel_float_size.GetHeight() > 0 )
  222. {
  223. netNavigatorPane.FloatingSize( cfg->m_AuiPanels.net_nav_panel_float_size );
  224. }
  225. if( cfg->m_AuiPanels.properties_panel_width > 0 )
  226. SetAuiPaneSize( m_auimgr, propertiesPane, cfg->m_AuiPanels.properties_panel_width, -1 );
  227. if( cfg->m_AuiPanels.schematic_hierarchy_float )
  228. hierarchy_pane.Float();
  229. if( cfg->m_AuiPanels.search_panel_height > 0
  230. && ( cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_TOP
  231. || cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_BOTTOM ) )
  232. {
  233. wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
  234. searchPane.Direction( cfg->m_AuiPanels.search_panel_dock_direction );
  235. SetAuiPaneSize( m_auimgr, searchPane, -1, cfg->m_AuiPanels.search_panel_height );
  236. }
  237. else if( cfg->m_AuiPanels.search_panel_width > 0
  238. && ( cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_LEFT
  239. || cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_RIGHT ) )
  240. {
  241. wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
  242. searchPane.Direction( cfg->m_AuiPanels.search_panel_dock_direction );
  243. SetAuiPaneSize( m_auimgr, searchPane, cfg->m_AuiPanels.search_panel_width, -1 );
  244. }
  245. if( cfg->m_AuiPanels.float_net_nav_panel )
  246. netNavigatorPane.Float();
  247. if( cfg->m_AuiPanels.hierarchy_panel_docked_width > 0 )
  248. {
  249. // If the net navigator is not show, let the hierarchy navigator take all of the vertical
  250. // space.
  251. if( !cfg->m_AuiPanels.show_net_nav_panel )
  252. {
  253. SetAuiPaneSize( m_auimgr, hierarchy_pane,
  254. cfg->m_AuiPanels.hierarchy_panel_docked_width, -1 );
  255. }
  256. else
  257. {
  258. SetAuiPaneSize( m_auimgr, hierarchy_pane,
  259. cfg->m_AuiPanels.hierarchy_panel_docked_width,
  260. cfg->m_AuiPanels.hierarchy_panel_docked_height );
  261. SetAuiPaneSize( m_auimgr, netNavigatorPane,
  262. cfg->m_AuiPanels.net_nav_panel_docked_size.GetWidth(),
  263. cfg->m_AuiPanels.net_nav_panel_docked_size.GetHeight() );
  264. }
  265. // wxAUI hack: force width by setting MinSize() and then Fixed()
  266. // thanks to ZenJu https://github.com/wxWidgets/wxWidgets/issues/13180
  267. hierarchy_pane.MinSize( cfg->m_AuiPanels.hierarchy_panel_docked_width, 60 );
  268. hierarchy_pane.Fixed();
  269. netNavigatorPane.MinSize( cfg->m_AuiPanels.net_nav_panel_docked_size.GetWidth(), 60 );
  270. netNavigatorPane.Fixed();
  271. m_auimgr.Update();
  272. // now make it resizable again
  273. hierarchy_pane.Resizable();
  274. netNavigatorPane.Resizable();
  275. m_auimgr.Update();
  276. // Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
  277. // back to minimum.
  278. hierarchy_pane.MinSize( 120, 60 );
  279. netNavigatorPane.MinSize( 120, 60 );
  280. }
  281. else
  282. {
  283. m_auimgr.Update();
  284. }
  285. LoadProjectSettings();
  286. view->SetLayerVisible( LAYER_ERC_ERR, cfg->m_Appearance.show_erc_errors );
  287. view->SetLayerVisible( LAYER_ERC_WARN, cfg->m_Appearance.show_erc_warnings );
  288. view->SetLayerVisible( LAYER_ERC_EXCLUSION, cfg->m_Appearance.show_erc_exclusions );
  289. view->SetLayerVisible( LAYER_OP_VOLTAGES, cfg->m_Appearance.show_op_voltages );
  290. view->SetLayerVisible( LAYER_OP_CURRENTS, cfg->m_Appearance.show_op_currents );
  291. initScreenZoom();
  292. m_hierarchy->Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::OnResizeHierarchyNavigator, this );
  293. m_netNavigator->Bind( wxEVT_TREE_SEL_CHANGING, &SCH_EDIT_FRAME::onNetNavigatorSelChanging,
  294. this );
  295. m_netNavigator->Bind( wxEVT_TREE_SEL_CHANGED, &SCH_EDIT_FRAME::onNetNavigatorSelection, this );
  296. m_netNavigator->Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onResizeNetNavigator, this );
  297. // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
  298. // to calculate the wrong zoom size. See SCH_EDIT_FRAME::onSize().
  299. Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
  300. setupUnits( eeconfig() );
  301. // Net list generator
  302. DefaultExecFlags();
  303. updateTitle();
  304. m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->ResetHistory();
  305. // Default shutdown reason until a file is loaded
  306. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New schematic file is unsaved" ) );
  307. // Init for dropping files
  308. m_acceptedExts.emplace( FILEEXT::KiCadSchematicFileExtension, &EE_ACTIONS::ddAppendFile );
  309. DragAcceptFiles( true );
  310. // Ensure the window is on top
  311. Raise();
  312. // Now that all sizes are fixed, set the initial hierarchy_pane floating position to the
  313. // top-left corner of the canvas
  314. wxPoint canvas_pos = GetCanvas()->GetScreenPosition();
  315. hierarchy_pane.FloatingPosition( canvas_pos.x + 10, canvas_pos.y + 10 );
  316. Bind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &SCH_EDIT_FRAME::onCloseSymbolDiffDialog, this );
  317. Bind( EDA_EVT_CLOSE_ERC_DIALOG, &SCH_EDIT_FRAME::onCloseErcDialog, this );
  318. Bind( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, &SCH_EDIT_FRAME::onCloseSymbolFieldsTableDialog,
  319. this );
  320. }
  321. SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
  322. {
  323. m_hierarchy->Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::OnResizeHierarchyNavigator, this );
  324. // Ensure m_canvasType is up to date, to save it in config
  325. m_canvasType = GetCanvas()->GetBackend();
  326. SetScreen( nullptr );
  327. if( m_schematic )
  328. m_schematic->RemoveAllListeners();
  329. delete m_schematic;
  330. m_schematic = nullptr;
  331. // Close the project if we are standalone, so it gets cleaned up properly
  332. if( Kiface().IsSingle() )
  333. {
  334. try
  335. {
  336. GetSettingsManager()->UnloadProject( &Prj(), false );
  337. }
  338. catch( const nlohmann::detail::type_error& exc )
  339. {
  340. // This may be overkill and could be an assertion but we are more likely to
  341. // find any settings manager errors this way.
  342. wxLogError( wxT( "Settings exception '%s' occurred." ), exc.what() );
  343. }
  344. }
  345. delete m_hierarchy;
  346. }
  347. void SCH_EDIT_FRAME::OnResizeHierarchyNavigator( wxSizeEvent& aEvent )
  348. {
  349. aEvent.Skip();
  350. // Called when resizing the Hierarchy Navigator panel
  351. // Store the current pane size
  352. // It allows to retrieve the last defined pane size when switching between
  353. // docked and floating pane state
  354. // Note: *DO NOT* call m_auimgr.Update() here: it crashes KiCad at least on Windows
  355. EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
  356. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  357. if( cfg && m_hierarchy->IsShownOnScreen() )
  358. {
  359. cfg->m_AuiPanels.hierarchy_panel_float_width = hierarchy_pane.floating_size.x;
  360. cfg->m_AuiPanels.hierarchy_panel_float_height = hierarchy_pane.floating_size.y;
  361. // initialize hierarchy_panel_docked_width and best size only if the hierarchy_pane
  362. // width is > 0 (i.e. if its size is already set and has meaning)
  363. // if it is floating, its size is not initialized (only floating_size is initialized)
  364. // initializing hierarchy_pane.best_size is useful when switching to float pane and
  365. // after switching to the docked pane, to retrieve the last docked pane width
  366. if( hierarchy_pane.rect.width > 50 ) // 50 is a good margin
  367. {
  368. cfg->m_AuiPanels.hierarchy_panel_docked_width = hierarchy_pane.rect.width;
  369. hierarchy_pane.best_size.x = hierarchy_pane.rect.width;
  370. }
  371. }
  372. }
  373. void SCH_EDIT_FRAME::setupTools()
  374. {
  375. // Create the manager and dispatcher & route draw panel events to the dispatcher
  376. m_toolManager = new TOOL_MANAGER;
  377. m_toolManager->SetEnvironment( &Schematic(), GetCanvas()->GetView(),
  378. GetCanvas()->GetViewControls(), config(), this );
  379. m_actions = new EE_ACTIONS();
  380. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  381. // Register tools
  382. m_toolManager->RegisterTool( new COMMON_CONTROL );
  383. m_toolManager->RegisterTool( new COMMON_TOOLS );
  384. m_toolManager->RegisterTool( new ZOOM_TOOL );
  385. m_toolManager->RegisterTool( new EE_SELECTION_TOOL );
  386. m_toolManager->RegisterTool( new PICKER_TOOL );
  387. m_toolManager->RegisterTool( new SCH_DRAWING_TOOLS );
  388. m_toolManager->RegisterTool( new SCH_LINE_WIRE_BUS_TOOL );
  389. m_toolManager->RegisterTool( new SCH_MOVE_TOOL );
  390. m_toolManager->RegisterTool( new SCH_EDIT_TOOL );
  391. m_toolManager->RegisterTool( new EE_INSPECTION_TOOL );
  392. m_toolManager->RegisterTool( new SCH_EDITOR_CONTROL );
  393. m_toolManager->RegisterTool( new SCH_FIND_REPLACE_TOOL );
  394. m_toolManager->RegisterTool( new EE_POINT_EDITOR );
  395. m_toolManager->RegisterTool( new SCH_NAVIGATE_TOOL );
  396. m_toolManager->RegisterTool( new PROPERTIES_TOOL );
  397. m_toolManager->InitTools();
  398. // Run the selection tool, it is supposed to be always active
  399. m_toolManager->PostAction( EE_ACTIONS::selectionActivate );
  400. GetCanvas()->SetEventDispatcher( m_toolDispatcher );
  401. }
  402. void SCH_EDIT_FRAME::setupUIConditions()
  403. {
  404. SCH_BASE_FRAME::setupUIConditions();
  405. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  406. SCH_EDITOR_CONDITIONS cond( this );
  407. wxASSERT( mgr );
  408. auto hasElements =
  409. [ this ] ( const SELECTION& aSel )
  410. {
  411. return GetScreen() &&
  412. ( !GetScreen()->Items().empty() || !SELECTION_CONDITIONS::Idle( aSel ) );
  413. };
  414. auto searchPaneCond =
  415. [this] ( const SELECTION& )
  416. {
  417. return m_auimgr.GetPane( SearchPaneName() ).IsShown();
  418. };
  419. auto propertiesCond =
  420. [this] ( const SELECTION& )
  421. {
  422. return m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
  423. };
  424. auto hierarchyNavigatorCond =
  425. [ this ] ( const SELECTION& aSel )
  426. {
  427. return m_auimgr.GetPane( SchematicHierarchyPaneName() ).IsShown();
  428. };
  429. auto netNavigatorCond =
  430. [ this ] (const SELECTION& aSel )
  431. {
  432. return m_auimgr.GetPane( NetNavigatorPaneName() ).IsShown();
  433. };
  434. auto undoCond =
  435. [ this ] (const SELECTION& aSel )
  436. {
  437. if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
  438. return true;
  439. return GetUndoCommandCount() > 0;
  440. };
  441. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  442. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  443. mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  444. mgr->SetConditions( ACTIONS::undo, ENABLE( undoCond ) );
  445. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  446. mgr->SetConditions( EE_ACTIONS::showSearch, CHECK( searchPaneCond ) );
  447. mgr->SetConditions( EE_ACTIONS::showHierarchy, CHECK( hierarchyNavigatorCond ) );
  448. mgr->SetConditions( EE_ACTIONS::showNetNavigator, CHECK( netNavigatorCond ) );
  449. mgr->SetConditions( ACTIONS::showProperties, CHECK( propertiesCond ) );
  450. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  451. mgr->SetConditions( ACTIONS::toggleGridOverrides, CHECK( cond.GridOverrides() ) );
  452. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  453. mgr->SetConditions( ACTIONS::millimetersUnits,
  454. CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  455. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  456. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  457. mgr->SetConditions( EE_ACTIONS::lineModeFree,
  458. CHECK( cond.LineMode( LINE_MODE::LINE_MODE_FREE ) ) );
  459. mgr->SetConditions( EE_ACTIONS::lineMode90,
  460. CHECK( cond.LineMode( LINE_MODE::LINE_MODE_90 ) ) );
  461. mgr->SetConditions( EE_ACTIONS::lineMode45,
  462. CHECK( cond.LineMode( LINE_MODE::LINE_MODE_45 ) ) );
  463. mgr->SetConditions( ACTIONS::cut, ENABLE( hasElements ) );
  464. mgr->SetConditions( ACTIONS::copy, ENABLE( hasElements ) );
  465. mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle ) );
  466. mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle ) );
  467. mgr->SetConditions( ACTIONS::doDelete, ENABLE( hasElements ) );
  468. mgr->SetConditions( ACTIONS::duplicate, ENABLE( hasElements ) );
  469. mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) );
  470. mgr->SetConditions( ACTIONS::unselectAll, ENABLE( hasElements ) );
  471. mgr->SetConditions( EE_ACTIONS::rotateCW, ENABLE( hasElements ) );
  472. mgr->SetConditions( EE_ACTIONS::rotateCCW, ENABLE( hasElements ) );
  473. mgr->SetConditions( EE_ACTIONS::mirrorH, ENABLE( hasElements ) );
  474. mgr->SetConditions( EE_ACTIONS::mirrorV, ENABLE( hasElements ) );
  475. mgr->SetConditions( ACTIONS::zoomTool,
  476. CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  477. mgr->SetConditions( ACTIONS::selectionTool,
  478. CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  479. if( SCRIPTING::IsWxAvailable() )
  480. {
  481. mgr->SetConditions( EE_ACTIONS::showPythonConsole,
  482. CHECK( cond.ScriptingConsoleVisible() ) );
  483. }
  484. auto showHiddenPinsCond =
  485. [this]( const SELECTION& )
  486. {
  487. return GetShowAllPins();
  488. };
  489. auto showHiddenFieldsCond =
  490. [this]( const SELECTION& )
  491. {
  492. EESCHEMA_SETTINGS* cfg = eeconfig();
  493. return cfg && cfg->m_Appearance.show_hidden_fields;
  494. };
  495. auto showDirectiveLabelsCond =
  496. [this]( const SELECTION& )
  497. {
  498. EESCHEMA_SETTINGS* cfg = eeconfig();
  499. return cfg && cfg->m_Appearance.show_directive_labels;
  500. };
  501. auto showERCErrorsCond =
  502. [this]( const SELECTION& )
  503. {
  504. EESCHEMA_SETTINGS* cfg = eeconfig();
  505. return cfg && cfg->m_Appearance.show_erc_errors;
  506. };
  507. auto showERCWarningsCond =
  508. [this]( const SELECTION& )
  509. {
  510. EESCHEMA_SETTINGS* cfg = eeconfig();
  511. return cfg && cfg->m_Appearance.show_erc_warnings;
  512. };
  513. auto showERCExclusionsCond =
  514. [this]( const SELECTION& )
  515. {
  516. EESCHEMA_SETTINGS* cfg = eeconfig();
  517. return cfg && cfg->m_Appearance.show_erc_exclusions;
  518. };
  519. auto showOPVoltagesCond =
  520. [this]( const SELECTION& )
  521. {
  522. EESCHEMA_SETTINGS* cfg = eeconfig();
  523. return cfg && cfg->m_Appearance.show_op_voltages;
  524. };
  525. auto showOPCurrentsCond =
  526. [this]( const SELECTION& )
  527. {
  528. EESCHEMA_SETTINGS* cfg = eeconfig();
  529. return cfg && cfg->m_Appearance.show_op_currents;
  530. };
  531. auto showAnnotateAutomaticallyCond =
  532. [this]( const SELECTION& )
  533. {
  534. EESCHEMA_SETTINGS* cfg = eeconfig();
  535. return cfg && cfg->m_AnnotatePanel.automatic;
  536. };
  537. auto remapSymbolsCondition =
  538. [&]( const SELECTION& aSel )
  539. {
  540. SCH_SCREENS schematic( Schematic().Root() );
  541. // The remapping can only be performed on legacy projects.
  542. return schematic.HasNoFullyDefinedLibIds();
  543. };
  544. auto belowRootSheetCondition =
  545. [this]( const SELECTION& aSel )
  546. {
  547. SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
  548. return navigateTool && navigateTool->CanGoUp();
  549. };
  550. auto navSchematicHasPreviousSheet =
  551. [this]( const SELECTION& aSel )
  552. {
  553. SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
  554. return navigateTool && navigateTool->CanGoPrevious();
  555. };
  556. auto navSchematicHasNextSheet =
  557. [this]( const SELECTION& aSel )
  558. {
  559. SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
  560. return navigateTool && navigateTool->CanGoNext();
  561. };
  562. mgr->SetConditions( EE_ACTIONS::leaveSheet, ENABLE( belowRootSheetCondition ) );
  563. /* Some of these are bound by default to arrow keys which will get a different action if we
  564. * disable the buttons. So always leave them enabled so the action is consistent.
  565. * https://gitlab.com/kicad/code/kicad/-/issues/14783
  566. mgr->SetConditions( EE_ACTIONS::navigateUp, ENABLE( belowRootSheetCondition ) );
  567. mgr->SetConditions( EE_ACTIONS::navigateForward, ENABLE( navHistoryHasForward ) );
  568. mgr->SetConditions( EE_ACTIONS::navigateBack, ENABLE( navHistoryHsBackward ) );
  569. */
  570. mgr->SetConditions( EE_ACTIONS::navigatePrevious, ENABLE( navSchematicHasPreviousSheet ) );
  571. mgr->SetConditions( EE_ACTIONS::navigateNext, ENABLE( navSchematicHasNextSheet ) );
  572. mgr->SetConditions( EE_ACTIONS::remapSymbols, ENABLE( remapSymbolsCondition ) );
  573. mgr->SetConditions( EE_ACTIONS::toggleHiddenPins, CHECK( showHiddenPinsCond ) );
  574. mgr->SetConditions( EE_ACTIONS::toggleHiddenFields, CHECK( showHiddenFieldsCond ) );
  575. mgr->SetConditions( EE_ACTIONS::toggleDirectiveLabels, CHECK( showDirectiveLabelsCond ) );
  576. mgr->SetConditions( EE_ACTIONS::toggleERCErrors, CHECK( showERCErrorsCond ) );
  577. mgr->SetConditions( EE_ACTIONS::toggleERCWarnings, CHECK( showERCWarningsCond ) );
  578. mgr->SetConditions( EE_ACTIONS::toggleERCExclusions, CHECK( showERCExclusionsCond ) );
  579. mgr->SetConditions( EE_ACTIONS::toggleOPVoltages, CHECK( showOPVoltagesCond ) );
  580. mgr->SetConditions( EE_ACTIONS::toggleOPCurrents, CHECK( showOPCurrentsCond ) );
  581. mgr->SetConditions( EE_ACTIONS::toggleAnnotateAuto, CHECK( showAnnotateAutomaticallyCond ) );
  582. mgr->SetConditions( ACTIONS::toggleBoundingBoxes, CHECK( cond.BoundingBoxes() ) );
  583. #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
  584. CURRENT_TOOL( ACTIONS::deleteTool );
  585. CURRENT_TOOL( EE_ACTIONS::highlightNetTool );
  586. CURRENT_TOOL( EE_ACTIONS::placeSymbol );
  587. CURRENT_TOOL( EE_ACTIONS::placePower );
  588. CURRENT_TOOL( EE_ACTIONS::drawWire );
  589. CURRENT_TOOL( EE_ACTIONS::drawBus );
  590. CURRENT_TOOL( EE_ACTIONS::placeBusWireEntry );
  591. CURRENT_TOOL( EE_ACTIONS::placeNoConnect );
  592. CURRENT_TOOL( EE_ACTIONS::placeJunction );
  593. CURRENT_TOOL( EE_ACTIONS::placeLabel );
  594. CURRENT_TOOL( EE_ACTIONS::placeClassLabel );
  595. CURRENT_TOOL( EE_ACTIONS::placeGlobalLabel );
  596. CURRENT_TOOL( EE_ACTIONS::placeHierLabel );
  597. CURRENT_TOOL( EE_ACTIONS::drawSheet );
  598. CURRENT_TOOL( EE_ACTIONS::importSheetPin );
  599. CURRENT_TOOL( EE_ACTIONS::drawRectangle );
  600. CURRENT_TOOL( EE_ACTIONS::drawCircle );
  601. CURRENT_TOOL( EE_ACTIONS::drawArc );
  602. CURRENT_TOOL( EE_ACTIONS::drawLines );
  603. CURRENT_TOOL( EE_ACTIONS::placeSchematicText );
  604. CURRENT_TOOL( EE_ACTIONS::drawTextBox );
  605. CURRENT_TOOL( EE_ACTIONS::placeImage );
  606. #undef CURRENT_TOOL
  607. #undef CHECK
  608. #undef ENABLE
  609. }
  610. void SCH_EDIT_FRAME::SaveCopyForRepeatItem( const SCH_ITEM* aItem )
  611. {
  612. // we cannot store a pointer to an item in the display list here since
  613. // that item may be deleted, such as part of a line concatenation or other.
  614. // So simply always keep a copy of the object which is to be repeated.
  615. if( aItem )
  616. {
  617. m_items_to_repeat.clear();
  618. AddCopyForRepeatItem( aItem );
  619. }
  620. }
  621. void SCH_EDIT_FRAME::AddCopyForRepeatItem( const SCH_ITEM* aItem )
  622. {
  623. // we cannot store a pointer to an item in the display list here since
  624. // that item may be deleted, such as part of a line concatenation or other.
  625. // So simply always keep a copy of the object which is to be repeated.
  626. if( aItem )
  627. {
  628. std::unique_ptr<SCH_ITEM> repeatItem( static_cast<SCH_ITEM*>( aItem->Duplicate() ) );
  629. // Clone() preserves the flags, we want 'em cleared.
  630. repeatItem->ClearFlags();
  631. m_items_to_repeat.emplace_back( std::move( repeatItem ) );
  632. }
  633. }
  634. EDA_ITEM* SCH_EDIT_FRAME::GetItem( const KIID& aId ) const
  635. {
  636. return Schematic().GetSheets().GetItem( aId );
  637. }
  638. void SCH_EDIT_FRAME::SetSheetNumberAndCount()
  639. {
  640. Schematic().SetSheetNumberAndCount();
  641. }
  642. SCH_SCREEN* SCH_EDIT_FRAME::GetScreen() const
  643. {
  644. return GetCurrentSheet().LastScreen();
  645. }
  646. SCHEMATIC& SCH_EDIT_FRAME::Schematic() const
  647. {
  648. return *m_schematic;
  649. }
  650. wxString SCH_EDIT_FRAME::GetScreenDesc() const
  651. {
  652. return GetCurrentSheet().Last()->GetName();
  653. }
  654. wxString SCH_EDIT_FRAME::GetFullScreenDesc() const
  655. {
  656. return GetCurrentSheet().PathHumanReadable();
  657. }
  658. void SCH_EDIT_FRAME::CreateScreens()
  659. {
  660. m_schematic->Reset();
  661. m_schematic->SetProject( &Prj() );
  662. SCH_SHEET* rootSheet = new SCH_SHEET( m_schematic );
  663. m_schematic->SetRoot( rootSheet );
  664. SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic );
  665. const_cast<KIID&>( rootSheet->m_Uuid ) = rootScreen->GetUuid();
  666. m_schematic->Root().SetScreen( rootScreen );
  667. SetScreen( Schematic().RootScreen() );
  668. m_schematic->RootScreen()->SetFileName( wxEmptyString );
  669. // Don't leave root page number empty
  670. SCH_SHEET_PATH rootSheetPath;
  671. rootSheetPath.push_back( rootSheet );
  672. m_schematic->RootScreen()->SetPageNumber( wxT( "1" ) );
  673. rootSheetPath.SetPageNumber( wxT( "1" ) );
  674. if( GetScreen() == nullptr )
  675. {
  676. SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
  677. SetScreen( screen );
  678. }
  679. }
  680. SCH_SHEET_PATH& SCH_EDIT_FRAME::GetCurrentSheet() const
  681. {
  682. return m_schematic->CurrentSheet();
  683. }
  684. void SCH_EDIT_FRAME::SetCurrentSheet( const SCH_SHEET_PATH& aSheet )
  685. {
  686. if( aSheet != GetCurrentSheet() )
  687. {
  688. FocusOnItem( nullptr );
  689. Schematic().SetCurrentSheet( aSheet );
  690. GetCanvas()->DisplaySheet( aSheet.LastScreen() );
  691. }
  692. }
  693. void SCH_EDIT_FRAME::HardRedraw()
  694. {
  695. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  696. for( SCH_ITEM* item : screen->Items() )
  697. item->ClearCaches();
  698. for( const std::pair<const wxString, LIB_SYMBOL*>& libSymbol : screen->GetLibSymbols() )
  699. {
  700. wxCHECK2( libSymbol.second, continue );
  701. libSymbol.second->ClearCaches();
  702. }
  703. if( Schematic().Settings().m_IntersheetRefsShow )
  704. RecomputeIntersheetRefs();
  705. FocusOnItem( nullptr );
  706. GetCanvas()->DisplaySheet( GetCurrentSheet().LastScreen() );
  707. if( EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>() )
  708. selectionTool->Reset( TOOL_BASE::REDRAW );
  709. GetCanvas()->ForceRefresh();
  710. }
  711. bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
  712. {
  713. // Exit interactive editing
  714. // Note this this will commit *some* pending changes. For instance, the EE_POINT_EDITOR
  715. // will cancel any drag currently in progress, but commit all changes from previous drags.
  716. if( m_toolManager )
  717. m_toolManager->RunAction( ACTIONS::cancelInteractive );
  718. // Shutdown blocks must be determined and vetoed as early as possible
  719. if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
  720. && Schematic().GetSheets().IsModified() )
  721. {
  722. return false;
  723. }
  724. if( Kiface().IsSingle() )
  725. {
  726. auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
  727. if( symbolEditor && !symbolEditor->Close() ) // Can close symbol editor?
  728. return false;
  729. auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
  730. if( symbolViewer && !symbolViewer->Close() ) // Can close symbol viewer?
  731. return false;
  732. // SYMBOL_CHOOSER_FRAME is always modal so this shouldn't come up, but better safe than
  733. // sorry.
  734. auto* chooser = (SYMBOL_CHOOSER_FRAME*) Kiway().Player( FRAME_SYMBOL_CHOOSER, false );
  735. if( chooser && !chooser->Close() ) // Can close symbol chooser?
  736. return false;
  737. }
  738. else
  739. {
  740. auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
  741. if( symbolEditor && symbolEditor->IsSymbolFromSchematic() )
  742. {
  743. if( !symbolEditor->CanCloseSymbolFromSchematic( true ) )
  744. return false;
  745. }
  746. }
  747. if( !Kiway().PlayerClose( FRAME_SIMULATOR, false ) ) // Can close the simulator?
  748. return false;
  749. if( m_symbolFieldsTableDialog
  750. && !m_symbolFieldsTableDialog->Close( false ) ) // Can close the symbol fields table?
  751. {
  752. return false;
  753. }
  754. // We may have gotten multiple events; don't clean up twice
  755. if( !Schematic().IsValid() )
  756. return false;
  757. SCH_SHEET_LIST sheetlist = Schematic().GetSheets();
  758. if( sheetlist.IsModified() )
  759. {
  760. wxFileName fileName = Schematic().RootScreen()->GetFileName();
  761. wxString msg = _( "Save changes to '%s' before closing?" );
  762. if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
  763. [&]() -> bool
  764. {
  765. return SaveProject();
  766. } ) )
  767. {
  768. return false;
  769. }
  770. }
  771. return true;
  772. }
  773. void SCH_EDIT_FRAME::doCloseWindow()
  774. {
  775. SCH_SHEET_LIST sheetlist = Schematic().GetSheets();
  776. // Shutdown all running tools
  777. if( m_toolManager )
  778. m_toolManager->ShutdownAllTools();
  779. // Close modeless dialogs. They're trouble when they get destroyed after the frame.
  780. Unbind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &SCH_EDIT_FRAME::onCloseSymbolDiffDialog, this );
  781. Unbind( EDA_EVT_CLOSE_ERC_DIALOG, &SCH_EDIT_FRAME::onCloseErcDialog, this );
  782. Unbind( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE,
  783. &SCH_EDIT_FRAME::onCloseSymbolFieldsTableDialog, this );
  784. m_netNavigator->Unbind( wxEVT_TREE_SEL_CHANGING, &SCH_EDIT_FRAME::onNetNavigatorSelChanging,
  785. this );
  786. m_netNavigator->Unbind( wxEVT_TREE_SEL_CHANGED, &SCH_EDIT_FRAME::onNetNavigatorSelection,
  787. this );
  788. // Close the find dialog and preserve its setting if it is displayed.
  789. if( m_findReplaceDialog )
  790. {
  791. m_findStringHistoryList = m_findReplaceDialog->GetFindEntries();
  792. m_replaceStringHistoryList = m_findReplaceDialog->GetReplaceEntries();
  793. m_findReplaceDialog->Destroy();
  794. m_findReplaceDialog = nullptr;
  795. }
  796. if( m_diffSymbolDialog )
  797. {
  798. m_diffSymbolDialog->Destroy();
  799. m_diffSymbolDialog = nullptr;
  800. }
  801. if( m_ercDialog )
  802. {
  803. m_ercDialog->Destroy();
  804. m_ercDialog = nullptr;
  805. }
  806. if( m_symbolFieldsTableDialog )
  807. {
  808. m_symbolFieldsTableDialog->Destroy();
  809. m_symbolFieldsTableDialog = nullptr;
  810. }
  811. // Shutdown all running tools
  812. if( m_toolManager )
  813. {
  814. m_toolManager->ShutdownAllTools();
  815. // prevent the canvas from trying to dispatch events during close
  816. GetCanvas()->SetEventDispatcher( nullptr );
  817. delete m_toolManager;
  818. m_toolManager = nullptr;
  819. }
  820. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  821. if( hierarchy_pane.IsShown() && hierarchy_pane.IsFloating() )
  822. {
  823. hierarchy_pane.Show( false );
  824. m_auimgr.Update();
  825. }
  826. SCH_SCREENS screens( Schematic().Root() );
  827. wxFileName fn;
  828. for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
  829. {
  830. fn = Prj().AbsolutePath( screen->GetFileName() );
  831. // Auto save file name is the normal file name prepended with GetAutoSaveFilePrefix().
  832. fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
  833. if( fn.IsFileWritable() )
  834. wxRemoveFile( fn.GetFullPath() );
  835. }
  836. wxFileName tmpFn = Prj().GetProjectFullName();
  837. wxFileName autoSaveFileName( tmpFn.GetPath(), getAutoSaveFileName() );
  838. if( autoSaveFileName.IsFileWritable() )
  839. wxRemoveFile( autoSaveFileName.GetFullPath() );
  840. sheetlist.ClearModifyStatus();
  841. wxString fileName = Prj().AbsolutePath( Schematic().RootScreen()->GetFileName() );
  842. if( !Schematic().GetFileName().IsEmpty() && !Schematic().RootScreen()->IsEmpty() )
  843. UpdateFileHistory( fileName );
  844. // Make sure local settings are persisted
  845. SaveProjectLocalSettings();
  846. Schematic().RootScreen()->Clear();
  847. // all sub sheets are deleted, only the main sheet is usable
  848. GetCurrentSheet().clear();
  849. // Clear view before destroying schematic as repaints depend on schematic being valid
  850. SetScreen( nullptr );
  851. Schematic().Reset();
  852. // Prevents any rogue events from continuing (i.e. search panel tries to redraw)
  853. Show( false );
  854. Destroy();
  855. }
  856. SEVERITY SCH_EDIT_FRAME::GetSeverity( int aErrorCode ) const
  857. {
  858. return Schematic().ErcSettings().GetSeverity( aErrorCode );
  859. }
  860. void SCH_EDIT_FRAME::OnModify()
  861. {
  862. EDA_BASE_FRAME::OnModify();
  863. wxCHECK( GetScreen(), /* void */ );
  864. GetScreen()->SetContentModified();
  865. m_autoSaveRequired = true;
  866. GetCanvas()->Refresh();
  867. if( !GetTitle().StartsWith( wxS( "*" ) ) )
  868. updateTitle();
  869. }
  870. void SCH_EDIT_FRAME::OnUpdatePCB( wxCommandEvent& event )
  871. {
  872. if( Kiface().IsSingle() )
  873. {
  874. DisplayError( this, _( "Cannot update the PCB, because the Schematic Editor is opened"
  875. " in stand-alone mode. In order to create/update PCBs from"
  876. " schematics, launch the KiCad shell and create a project." ) );
  877. return;
  878. }
  879. KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
  880. if( !frame )
  881. {
  882. wxFileName fn = Prj().GetProjectFullName();
  883. fn.SetExt( FILEEXT::PcbFileExtension );
  884. frame = Kiway().Player( FRAME_PCB_EDITOR, true );
  885. // If Kiway() cannot create the Pcbnew frame, it shows a error message, and
  886. // frame is null
  887. if( !frame )
  888. return;
  889. frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
  890. }
  891. if( !frame->IsVisible() )
  892. frame->Show( true );
  893. // On Windows, Raise() does not bring the window on screen, when iconized
  894. if( frame->IsIconized() )
  895. frame->Iconize( false );
  896. frame->Raise();
  897. std::string payload;
  898. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_PCB_UPDATE, payload, this );
  899. }
  900. void SCH_EDIT_FRAME::UpdateHierarchyNavigator()
  901. {
  902. m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CleanHistory();
  903. m_hierarchy->UpdateHierarchyTree();
  904. }
  905. void SCH_EDIT_FRAME::UpdateHierarchySelection()
  906. {
  907. m_hierarchy->UpdateHierarchySelection();
  908. }
  909. void SCH_EDIT_FRAME::ShowFindReplaceDialog( bool aReplace )
  910. {
  911. wxString findString;
  912. EE_SELECTION& selection = m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
  913. if( selection.Size() == 1 )
  914. {
  915. EDA_ITEM* front = selection.Front();
  916. switch( front->Type() )
  917. {
  918. case SCH_SYMBOL_T:
  919. {
  920. SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( front );
  921. findString = UnescapeString( symbol->GetField( VALUE_FIELD )->GetText() );
  922. break;
  923. }
  924. case SCH_FIELD_T:
  925. findString = UnescapeString( static_cast<SCH_FIELD*>( front )->GetText() );
  926. break;
  927. case SCH_LABEL_T:
  928. case SCH_GLOBAL_LABEL_T:
  929. case SCH_HIER_LABEL_T:
  930. case SCH_SHEET_PIN_T:
  931. findString = UnescapeString( static_cast<SCH_LABEL_BASE*>( front )->GetText() );
  932. break;
  933. case SCH_TEXT_T:
  934. findString = UnescapeString( static_cast<SCH_TEXT*>( front )->GetText() );
  935. if( findString.Contains( wxT( "\n" ) ) )
  936. findString = findString.Before( '\n' );
  937. break;
  938. default:
  939. break;
  940. }
  941. }
  942. if( m_findReplaceDialog )
  943. m_findReplaceDialog->Destroy();
  944. m_findReplaceDialog = new DIALOG_SCH_FIND( this,
  945. static_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() ),
  946. wxDefaultPosition, wxDefaultSize,
  947. aReplace ? wxFR_REPLACEDIALOG : 0 );
  948. m_findReplaceDialog->SetFindEntries( m_findStringHistoryList, findString );
  949. m_findReplaceDialog->SetReplaceEntries( m_replaceStringHistoryList );
  950. m_findReplaceDialog->Show( true );
  951. }
  952. void SCH_EDIT_FRAME::ShowFindReplaceStatus( const wxString& aMsg, int aStatusTime )
  953. {
  954. // Prepare the infobar, since we don't know its state
  955. m_infoBar->RemoveAllButtons();
  956. m_infoBar->AddCloseButton();
  957. m_infoBar->ShowMessageFor( aMsg, aStatusTime, wxICON_INFORMATION );
  958. }
  959. void SCH_EDIT_FRAME::ClearFindReplaceStatus()
  960. {
  961. m_infoBar->Dismiss();
  962. }
  963. void SCH_EDIT_FRAME::OnFindDialogClose()
  964. {
  965. m_findStringHistoryList = m_findReplaceDialog->GetFindEntries();
  966. m_replaceStringHistoryList = m_findReplaceDialog->GetReplaceEntries();
  967. m_findReplaceDialog->Destroy();
  968. m_findReplaceDialog = nullptr;
  969. m_toolManager->RunAction( ACTIONS::updateFind );
  970. }
  971. void SCH_EDIT_FRAME::OnLoadFile( wxCommandEvent& event )
  972. {
  973. wxString fn = GetFileFromHistory( event.GetId(), _( "Schematic" ) );
  974. if( fn.size() )
  975. OpenProjectFiles( std::vector<wxString>( 1, fn ) );
  976. }
  977. void SCH_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
  978. {
  979. ClearFileHistory();
  980. }
  981. void SCH_EDIT_FRAME::NewProject()
  982. {
  983. wxString pro_dir = m_mruPath;
  984. wxFileDialog dlg( this, _( "New Schematic" ), pro_dir, wxEmptyString,
  985. FILEEXT::KiCadSchematicFileWildcard(), wxFD_SAVE );
  986. if( dlg.ShowModal() != wxID_CANCEL )
  987. {
  988. // Enforce the extension, wxFileDialog is inept.
  989. wxFileName create_me =
  990. EnsureFileExtension( dlg.GetPath(), FILEEXT::KiCadSchematicFileExtension );
  991. if( create_me.FileExists() )
  992. {
  993. wxString msg;
  994. msg.Printf( _( "Schematic file '%s' already exists." ), create_me.GetFullName() );
  995. DisplayError( this, msg );
  996. return ;
  997. }
  998. // OpenProjectFiles() requires absolute
  999. wxASSERT_MSG( create_me.IsAbsolute(), wxS( "wxFileDialog returned non-absolute path" ) );
  1000. OpenProjectFiles( std::vector<wxString>( 1, create_me.GetFullPath() ), KICTL_CREATE );
  1001. m_mruPath = create_me.GetPath();
  1002. }
  1003. }
  1004. void SCH_EDIT_FRAME::LoadProject()
  1005. {
  1006. wxString pro_dir = m_mruPath;
  1007. wxString wildcards = FILEEXT::AllSchematicFilesWildcard()
  1008. + wxS( "|" ) + FILEEXT::KiCadSchematicFileWildcard()
  1009. + wxS( "|" ) + FILEEXT::LegacySchematicFileWildcard();
  1010. wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir, wxEmptyString,
  1011. wildcards, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
  1012. if( dlg.ShowModal() != wxID_CANCEL )
  1013. {
  1014. OpenProjectFiles( std::vector<wxString>( 1, dlg.GetPath() ) );
  1015. m_mruPath = Prj().GetProjectPath();
  1016. }
  1017. }
  1018. void SCH_EDIT_FRAME::OnOpenPcbnew( wxCommandEvent& event )
  1019. {
  1020. wxFileName kicad_board = Prj().AbsolutePath( Schematic().GetFileName() );
  1021. if( kicad_board.IsOk() && !Schematic().GetFileName().IsEmpty() )
  1022. {
  1023. kicad_board.SetExt( FILEEXT::PcbFileExtension );
  1024. wxFileName legacy_board( kicad_board );
  1025. legacy_board.SetExt( FILEEXT::LegacyPcbFileExtension );
  1026. wxFileName& boardfn = legacy_board;
  1027. if( !legacy_board.FileExists() || kicad_board.FileExists() )
  1028. boardfn = kicad_board;
  1029. if( Kiface().IsSingle() )
  1030. {
  1031. ExecuteFile( PCBNEW_EXE, boardfn.GetFullPath() );
  1032. }
  1033. else
  1034. {
  1035. KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
  1036. if( !frame )
  1037. {
  1038. frame = Kiway().Player( FRAME_PCB_EDITOR, true );
  1039. // frame can be null if Cvpcb cannot be run. No need to show a warning
  1040. // Kiway() generates the error messages
  1041. if( !frame )
  1042. return;
  1043. frame->OpenProjectFiles( std::vector<wxString>( 1, boardfn.GetFullPath() ) );
  1044. }
  1045. if( !frame->IsVisible() )
  1046. frame->Show( true );
  1047. // On Windows, Raise() does not bring the window on screen, when iconized
  1048. if( frame->IsIconized() )
  1049. frame->Iconize( false );
  1050. frame->Raise();
  1051. }
  1052. }
  1053. else
  1054. {
  1055. // If we are running inside a project, it should be impossible for this case to happen
  1056. wxASSERT( Kiface().IsSingle() );
  1057. ExecuteFile( PCBNEW_EXE );
  1058. }
  1059. }
  1060. void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event )
  1061. {
  1062. wxFileName fn = Prj().AbsolutePath( Schematic().GetFileName() );
  1063. fn.SetExt( FILEEXT::NetlistFileExtension );
  1064. if( !ReadyToNetlist( _( "Assigning footprints requires a fully annotated schematic." ) ) )
  1065. return;
  1066. try
  1067. {
  1068. KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already.
  1069. if( !player )
  1070. {
  1071. player = Kiway().Player( FRAME_CVPCB, true );
  1072. // player can be null if Cvpcb cannot be run. No need to show a warning
  1073. // Kiway() generates the error messages
  1074. if( !player )
  1075. return;
  1076. player->Show( true );
  1077. }
  1078. sendNetlistToCvpcb();
  1079. player->Raise();
  1080. }
  1081. catch( const IO_ERROR& )
  1082. {
  1083. DisplayError( this, _( "Could not open CvPcb" ) );
  1084. }
  1085. }
  1086. void SCH_EDIT_FRAME::OnExit( wxCommandEvent& event )
  1087. {
  1088. if( event.GetId() == wxID_EXIT )
  1089. Kiway().OnKiCadExit();
  1090. if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
  1091. Close( false );
  1092. }
  1093. void SCH_EDIT_FRAME::PrintPage( const RENDER_SETTINGS* aSettings )
  1094. {
  1095. wxString fileName = Prj().AbsolutePath( GetScreen()->GetFileName() );
  1096. const wxBrush& brush =
  1097. wxBrush( GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ).ToColour() );
  1098. aSettings->GetPrintDC()->SetBackground( brush );
  1099. aSettings->GetPrintDC()->Clear();
  1100. aSettings->GetPrintDC()->SetLogicalFunction( wxCOPY );
  1101. GetScreen()->Print( aSettings );
  1102. PrintDrawingSheet( aSettings, GetScreen(), Schematic().GetProperties(), schIUScale.IU_PER_MILS,
  1103. fileName );
  1104. }
  1105. void SCH_EDIT_FRAME::RefreshOperatingPointDisplay()
  1106. {
  1107. SCHEMATIC_SETTINGS& settings = m_schematic->Settings();
  1108. SIM_LIB_MGR simLibMgr( &Prj() );
  1109. NULL_REPORTER devnull;
  1110. // Patch for bug early in V7.99 dev
  1111. if( settings.m_OPO_VRange.EndsWith( 'A' ) )
  1112. settings.m_OPO_VRange[ settings.m_OPO_VRange.Length() - 1 ] = 'V';
  1113. // Update items which may have ${OP} text variables
  1114. //
  1115. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  1116. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  1117. {
  1118. int flags = 0;
  1119. if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
  1120. {
  1121. item->RunOnChildren(
  1122. [&flags]( SCH_ITEM* aChild )
  1123. {
  1124. EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild );
  1125. if( text && text->HasTextVars() )
  1126. {
  1127. text->ClearRenderCache();
  1128. text->ClearBoundingBoxCache();
  1129. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1130. }
  1131. } );
  1132. EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
  1133. if( text && text->HasTextVars() )
  1134. {
  1135. text->ClearRenderCache();
  1136. text->ClearBoundingBoxCache();
  1137. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1138. }
  1139. }
  1140. return flags;
  1141. } );
  1142. // Update OP overlay items
  1143. //
  1144. for( SCH_ITEM* item : GetScreen()->Items() )
  1145. {
  1146. if( item->Type() == SCH_LINE_T )
  1147. {
  1148. SCH_LINE* line = static_cast<SCH_LINE*>( item );
  1149. if( !line->GetOperatingPoint().IsEmpty() )
  1150. GetCanvas()->GetView()->Update( line );
  1151. line->SetOperatingPoint( wxEmptyString );
  1152. // update value from netlist, below
  1153. }
  1154. else if( item->Type() == SCH_SYMBOL_T )
  1155. {
  1156. SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
  1157. wxString ref = symbol->GetRef( &GetCurrentSheet() );
  1158. std::vector<SCH_PIN*> pins = symbol->GetPins( &GetCurrentSheet() );
  1159. // Power symbols and other symbols which have the reference starting with "#" are
  1160. // not included in simulation
  1161. if( ref.StartsWith( '#' ) || symbol->GetExcludedFromSim() )
  1162. continue;
  1163. for( SCH_PIN* pin : pins )
  1164. {
  1165. if( !pin->GetOperatingPoint().IsEmpty() )
  1166. GetCanvas()->GetView()->Update( pin );
  1167. pin->SetOperatingPoint( wxEmptyString );
  1168. }
  1169. if( pins.size() == 2 )
  1170. {
  1171. wxString op = m_schematic->GetOperatingPoint( ref, settings.m_OPO_IPrecision,
  1172. settings.m_OPO_IRange );
  1173. if( !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
  1174. {
  1175. pins[0]->SetOperatingPoint( op );
  1176. GetCanvas()->GetView()->Update( symbol );
  1177. }
  1178. }
  1179. else
  1180. {
  1181. SIM_MODEL& model = simLibMgr.CreateModel( &GetCurrentSheet(), *symbol,
  1182. devnull ).model;
  1183. SPICE_ITEM spiceItem;
  1184. spiceItem.refName = ref;
  1185. ref = model.SpiceGenerator().ItemName( spiceItem );
  1186. for( const auto& modelPin : model.GetPins() )
  1187. {
  1188. SCH_PIN* symbolPin = symbol->GetPin( modelPin.get().symbolPinNumber );
  1189. wxString signalName = ref + wxS( ":" ) + modelPin.get().name;
  1190. wxString op = m_schematic->GetOperatingPoint( signalName,
  1191. settings.m_OPO_IPrecision,
  1192. settings.m_OPO_IRange );
  1193. if( symbolPin && !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
  1194. {
  1195. symbolPin->SetOperatingPoint( op );
  1196. GetCanvas()->GetView()->Update( symbol );
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202. for( const auto& [ key, subgraphList ] : m_schematic->m_connectionGraph->GetNetMap() )
  1203. {
  1204. wxString op = m_schematic->GetOperatingPoint( key.Name, settings.m_OPO_VPrecision,
  1205. settings.m_OPO_VRange );
  1206. if( !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
  1207. {
  1208. for( CONNECTION_SUBGRAPH* subgraph : subgraphList )
  1209. {
  1210. SCH_LINE* longestWire = nullptr;
  1211. double length = 0.0;
  1212. for( SCH_ITEM* item : subgraph->GetItems() )
  1213. {
  1214. if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } ) )
  1215. {
  1216. SCH_LINE* wire = static_cast<SCH_LINE*>( item );
  1217. if( wire->GetLength() > length )
  1218. {
  1219. longestWire = wire;
  1220. length = wire->GetLength();
  1221. }
  1222. }
  1223. }
  1224. if( longestWire )
  1225. {
  1226. longestWire->SetOperatingPoint( op );
  1227. GetCanvas()->GetView()->Update( longestWire );
  1228. }
  1229. }
  1230. }
  1231. }
  1232. }
  1233. void SCH_EDIT_FRAME::AutoRotateItem( SCH_SCREEN* aScreen, SCH_ITEM* aItem )
  1234. {
  1235. if( aItem->IsType( { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T } ) )
  1236. {
  1237. SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
  1238. if( label->AutoRotateOnPlacement() )
  1239. {
  1240. SPIN_STYLE spin = aScreen->GetLabelOrientationForPoint( label->GetPosition(),
  1241. label->GetSpinStyle(),
  1242. &GetCurrentSheet() );
  1243. if( spin != label->GetSpinStyle() )
  1244. {
  1245. label->SetSpinStyle( spin );
  1246. for( SCH_ITEM* item : aScreen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
  1247. {
  1248. SCH_LABEL_BASE* otherLabel = static_cast<SCH_LABEL_BASE*>( item );
  1249. if( otherLabel != label && otherLabel->GetText() == label->GetText() )
  1250. otherLabel->AutoplaceFields( aScreen, false );
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. void SCH_EDIT_FRAME::updateTitle()
  1257. {
  1258. SCH_SCREEN* screen = GetScreen();
  1259. wxCHECK( screen, /* void */ );
  1260. wxString title;
  1261. if( !screen->GetFileName().IsEmpty() )
  1262. {
  1263. wxFileName fn( Prj().AbsolutePath( screen->GetFileName() ) );
  1264. bool readOnly = false;
  1265. bool unsaved = false;
  1266. if( fn.IsOk() && screen->FileExists() )
  1267. readOnly = screen->IsReadOnly();
  1268. else
  1269. unsaved = true;
  1270. if( IsContentModified() )
  1271. title = wxT( "*" );
  1272. title += fn.GetName();
  1273. wxString sheetPath = GetCurrentSheet().PathHumanReadable( false, true );
  1274. if( sheetPath != title )
  1275. title += wxString::Format( wxT( " [%s]" ), sheetPath );
  1276. if( readOnly )
  1277. title += wxS( " " ) + _( "[Read Only]" );
  1278. if( unsaved )
  1279. title += wxS( " " ) + _( "[Unsaved]" );
  1280. }
  1281. else
  1282. {
  1283. title = _( "[no schematic loaded]" );
  1284. }
  1285. title += wxT( " \u2014 " ) + _( "Schematic Editor" );
  1286. SetTitle( title );
  1287. }
  1288. void SCH_EDIT_FRAME::initScreenZoom()
  1289. {
  1290. m_toolManager->RunAction( ACTIONS::zoomFitScreen );
  1291. GetScreen()->m_zoomInitialized = true;
  1292. }
  1293. void SCH_EDIT_FRAME::RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags )
  1294. {
  1295. wxString highlightedConn = GetHighlightedConnection();
  1296. SCHEMATIC_SETTINGS& settings = Schematic().Settings();
  1297. SCH_SHEET_LIST list = Schematic().GetSheets();
  1298. SCH_COMMIT localCommit( m_toolManager );
  1299. if( !aCommit )
  1300. aCommit = &localCommit;
  1301. #ifdef PROFILE
  1302. PROF_TIMER timer;
  1303. #endif
  1304. // Ensure schematic graph is accurate
  1305. if( aCleanupFlags == LOCAL_CLEANUP )
  1306. {
  1307. SchematicCleanUp( aCommit, GetScreen() );
  1308. }
  1309. else if( aCleanupFlags == GLOBAL_CLEANUP )
  1310. {
  1311. for( const SCH_SHEET_PATH& sheet : list )
  1312. SchematicCleanUp( aCommit, sheet.LastScreen() );
  1313. }
  1314. #ifdef PROFILE
  1315. timer.Stop();
  1316. wxLogTrace( "CONN_PROFILE", "SchematicCleanUp() %0.4f ms", timer.msecs() );
  1317. #endif
  1318. if( settings.m_IntersheetRefsShow )
  1319. RecomputeIntersheetRefs();
  1320. std::function<void( SCH_ITEM* )> changeHandler =
  1321. [&]( SCH_ITEM* aChangedItem ) -> void
  1322. {
  1323. GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
  1324. SCH_CONNECTION* connection = aChangedItem->Connection();
  1325. if( connection && ( connection->Name() == highlightedConn ) )
  1326. m_highlightedConnChanged = true;
  1327. };
  1328. if( !ADVANCED_CFG::GetCfg().m_IncrementalConnectivity || aCleanupFlags == GLOBAL_CLEANUP
  1329. || m_undoList.m_CommandsList.empty() )
  1330. {
  1331. Schematic().ConnectionGraph()->Recalculate( list, true, &changeHandler );
  1332. }
  1333. else
  1334. {
  1335. PICKED_ITEMS_LIST* changed_list = m_undoList.m_CommandsList.back();
  1336. std::set<SCH_ITEM*> changed_items;
  1337. std::vector<VECTOR2I> pts;
  1338. std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> item_paths;
  1339. for( unsigned ii = 0; ii < changed_list->GetCount(); ++ii )
  1340. {
  1341. EDA_ITEM* item = changed_list->GetPickedItem( ii );
  1342. if( !item || !IsEeschemaType( item->Type() ) )
  1343. continue;
  1344. SCH_SCREEN* screen = static_cast<SCH_SCREEN*>( changed_list->GetScreenForItem( ii ) );
  1345. SCH_ITEM* sch_item = static_cast<SCH_ITEM*>( item );
  1346. SCH_SHEET_PATHS& paths = screen->GetClientSheetPaths();
  1347. std::vector<VECTOR2I> tmp_pts = sch_item->GetConnectionPoints();
  1348. pts.insert( pts.end(), tmp_pts.begin(), tmp_pts.end() );
  1349. changed_items.insert( sch_item );
  1350. for( SCH_SHEET_PATH& path : paths )
  1351. item_paths.insert( std::make_pair( path, sch_item ) );
  1352. }
  1353. for( VECTOR2I& pt: pts )
  1354. {
  1355. for( SCH_ITEM* item : GetScreen()->Items().Overlapping( pt ) )
  1356. {
  1357. if( item->Type() == SCH_LINE_T )
  1358. {
  1359. if( item->HitTest( pt ) )
  1360. changed_items.insert( item );
  1361. }
  1362. else if( item->Type() == SCH_SYMBOL_T )
  1363. {
  1364. SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
  1365. std::vector<SCH_PIN*> pins = symbol->GetPins();
  1366. changed_items.insert( pins.begin(), pins.end() );
  1367. }
  1368. else if( item->IsConnectable() )
  1369. {
  1370. if( item->IsConnected( pt ) )
  1371. changed_items.insert( item );
  1372. }
  1373. }
  1374. }
  1375. std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> all_items =
  1376. Schematic().ConnectionGraph()->ExtractAffectedItems( changed_items );
  1377. all_items.insert( item_paths.begin(), item_paths.end() );
  1378. CONNECTION_GRAPH new_graph( &Schematic() );
  1379. new_graph.SetLastCodes( Schematic().ConnectionGraph() );
  1380. for( auto&[ path, item ] : all_items )
  1381. {
  1382. switch( item->Type() )
  1383. {
  1384. case SCH_FIELD_T:
  1385. case SCH_PIN_T:
  1386. static_cast<SCH_ITEM*>( item->GetParent() )->SetConnectivityDirty();
  1387. break;
  1388. default:
  1389. item->SetConnectivityDirty();
  1390. }
  1391. }
  1392. new_graph.Recalculate( list, false, &changeHandler );
  1393. Schematic().ConnectionGraph()->Merge( new_graph );
  1394. }
  1395. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  1396. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  1397. {
  1398. int flags = 0;
  1399. SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem );
  1400. SCH_CONNECTION* connection = item ? item->Connection() : nullptr;
  1401. if( connection && connection->HasDriverChanged() )
  1402. {
  1403. connection->ClearDriverChanged();
  1404. flags |= KIGFX::REPAINT;
  1405. }
  1406. if( item )
  1407. {
  1408. item->RunOnChildren(
  1409. [&flags]( SCH_ITEM* aChild )
  1410. {
  1411. EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild );
  1412. if( text && text->HasTextVars() )
  1413. {
  1414. text->ClearRenderCache();
  1415. text->ClearBoundingBoxCache();
  1416. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1417. }
  1418. } );
  1419. EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
  1420. if( text && text->HasTextVars() )
  1421. {
  1422. text->ClearRenderCache();
  1423. text->ClearBoundingBoxCache();
  1424. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1425. }
  1426. if( flags & KIGFX::GEOMETRY )
  1427. GetScreen()->Update( item, false ); // Refresh RTree
  1428. }
  1429. return flags;
  1430. } );
  1431. if( !highlightedConn.IsEmpty() )
  1432. {
  1433. if( m_highlightedConnChanged
  1434. || !Schematic().ConnectionGraph()->FindFirstSubgraphByName( highlightedConn ) )
  1435. RefreshNetNavigator();
  1436. m_highlightedConnChanged = false;
  1437. }
  1438. if( !localCommit.Empty() )
  1439. localCommit.Push( _( "Schematic Cleanup" ) );
  1440. }
  1441. void SCH_EDIT_FRAME::RecomputeIntersheetRefs()
  1442. {
  1443. Schematic().RecomputeIntersheetRefs( [&]( SCH_GLOBALLABEL* label )
  1444. {
  1445. for( SCH_FIELD& field : label->GetFields() )
  1446. field.ClearBoundingBoxCache();
  1447. label->ClearBoundingBoxCache();
  1448. GetCanvas()->GetView()->Update( label );
  1449. } );
  1450. }
  1451. void SCH_EDIT_FRAME::ShowAllIntersheetRefs( bool aShow )
  1452. {
  1453. RecomputeIntersheetRefs();
  1454. GetCanvas()->GetView()->SetLayerVisible( LAYER_INTERSHEET_REFS, aShow );
  1455. }
  1456. void SCH_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  1457. {
  1458. SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  1459. SCHEMATIC_SETTINGS& settings = Schematic().Settings();
  1460. settings.m_JunctionSize = GetSchematicJunctionSize();
  1461. ShowAllIntersheetRefs( settings.m_IntersheetRefsShow );
  1462. EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
  1463. GetGalDisplayOptions().ReadWindowSettings( cfg->m_Window );
  1464. GetRenderSettings()->SetDefaultFont( cfg->m_Appearance.default_font );
  1465. KIGFX::VIEW* view = GetCanvas()->GetView();
  1466. view->SetLayerVisible( LAYER_ERC_ERR, cfg->m_Appearance.show_erc_errors );
  1467. view->SetLayerVisible( LAYER_ERC_WARN, cfg->m_Appearance.show_erc_warnings );
  1468. view->SetLayerVisible( LAYER_ERC_EXCLUSION, cfg->m_Appearance.show_erc_exclusions );
  1469. view->SetLayerVisible( LAYER_OP_VOLTAGES, cfg->m_Appearance.show_op_voltages );
  1470. view->SetLayerVisible( LAYER_OP_CURRENTS, cfg->m_Appearance.show_op_currents );
  1471. RefreshOperatingPointDisplay();
  1472. settings.m_TemplateFieldNames.DeleteAllFieldNameTemplates( true /* global */ );
  1473. if( !cfg->m_Drawing.field_names.IsEmpty() )
  1474. settings.m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names );
  1475. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  1476. for( SCH_ITEM* item : screen->Items() )
  1477. item->ClearCaches();
  1478. for( const auto& [ libItemName, libSymbol ] : screen->GetLibSymbols() )
  1479. libSymbol->ClearCaches();
  1480. GetCanvas()->ForceRefresh();
  1481. RecreateToolbars();
  1482. Layout();
  1483. SendSizeEvent();
  1484. }
  1485. void SCH_EDIT_FRAME::OnPageSettingsChange()
  1486. {
  1487. // Store the current zoom level into the current screen before calling
  1488. // DisplayCurrentSheet() that set the zoom to GetScreen()->m_LastZoomLevel
  1489. GetScreen()->m_LastZoomLevel = GetCanvas()->GetView()->GetScale();
  1490. // Rebuild the sheet view (draw area and any other items):
  1491. DisplayCurrentSheet();
  1492. }
  1493. void SCH_EDIT_FRAME::ShowChangedLanguage()
  1494. {
  1495. // call my base class
  1496. SCH_BASE_FRAME::ShowChangedLanguage();
  1497. // tooltips in toolbars
  1498. RecreateToolbars();
  1499. m_auimgr.GetPane( m_hierarchy ).Caption( _( "Schematic Hierarchy" ) );
  1500. m_auimgr.Update();
  1501. m_hierarchy->UpdateHierarchyTree();
  1502. m_propertiesPanel->LanguageChanged();
  1503. // status bar
  1504. UpdateMsgPanel();
  1505. updateTitle();
  1506. // This ugly hack is to fix an option(left) toolbar update bug that seems to only affect
  1507. // windows. See https://bugs.launchpad.net/kicad/+bug/1816492. For some reason, calling
  1508. // wxWindow::Refresh() does not resolve the issue. Only a resize event seems to force the
  1509. // toolbar to update correctly.
  1510. #if defined( __WXMSW__ )
  1511. PostSizeEvent();
  1512. #endif
  1513. }
  1514. void SCH_EDIT_FRAME::UpdateNetHighlightStatus()
  1515. {
  1516. if( !GetHighlightedConnection().IsEmpty() )
  1517. {
  1518. SetStatusText( wxString::Format( _( "Highlighted net: %s" ),
  1519. UnescapeString( GetHighlightedConnection() ) ) );
  1520. }
  1521. else
  1522. {
  1523. SetStatusText( wxT( "" ) );
  1524. }
  1525. }
  1526. void SCH_EDIT_FRAME::SetScreen( BASE_SCREEN* aScreen )
  1527. {
  1528. if( m_toolManager )
  1529. m_toolManager->RunAction( EE_ACTIONS::clearSelection );
  1530. SCH_BASE_FRAME::SetScreen( aScreen );
  1531. GetCanvas()->DisplaySheet( static_cast<SCH_SCREEN*>( aScreen ) );
  1532. if( m_toolManager )
  1533. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  1534. }
  1535. const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
  1536. {
  1537. BOX2I bBoxDoc;
  1538. if( aIncludeAllVisible )
  1539. {
  1540. // Get the whole page size and return that
  1541. int sizeX = GetScreen()->GetPageSettings().GetWidthIU( schIUScale.IU_PER_MILS );
  1542. int sizeY = GetScreen()->GetPageSettings().GetHeightIU( schIUScale.IU_PER_MILS );
  1543. bBoxDoc = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sizeX, sizeY ) );
  1544. }
  1545. else
  1546. {
  1547. // Get current drawing-sheet in a form we can compare to an EDA_ITEM
  1548. DS_PROXY_VIEW_ITEM* ds = SCH_BASE_FRAME::GetCanvas()->GetView()->GetDrawingSheet();
  1549. EDA_ITEM* dsAsItem = static_cast<EDA_ITEM*>( ds );
  1550. // Calc the bounding box of all items on screen except the page border
  1551. for( EDA_ITEM* item : GetScreen()->Items() )
  1552. {
  1553. if( item != dsAsItem ) // Ignore the drawing-sheet itself
  1554. bBoxDoc.Merge( item->GetBoundingBox() );
  1555. }
  1556. }
  1557. return bBoxDoc;
  1558. }
  1559. bool SCH_EDIT_FRAME::IsContentModified() const
  1560. {
  1561. return Schematic().GetSheets().IsModified();
  1562. }
  1563. bool SCH_EDIT_FRAME::GetShowAllPins() const
  1564. {
  1565. EESCHEMA_SETTINGS* cfg = eeconfig();
  1566. return cfg && cfg->m_Appearance.show_hidden_pins;
  1567. }
  1568. void SCH_EDIT_FRAME::FocusOnItem( SCH_ITEM* aItem )
  1569. {
  1570. static KIID lastBrightenedItemID( niluuid );
  1571. SCH_SHEET_LIST sheetList = Schematic().GetSheets();
  1572. SCH_SHEET_PATH dummy;
  1573. SCH_ITEM* lastItem = sheetList.GetItem( lastBrightenedItemID, &dummy );
  1574. if( lastItem && lastItem != aItem )
  1575. {
  1576. lastItem->ClearBrightened();
  1577. UpdateItem( lastItem );
  1578. lastBrightenedItemID = niluuid;
  1579. }
  1580. if( aItem )
  1581. {
  1582. if( !aItem->IsBrightened() )
  1583. {
  1584. aItem->SetBrightened();
  1585. UpdateItem( aItem );
  1586. lastBrightenedItemID = aItem->m_Uuid;
  1587. }
  1588. FocusOnLocation( aItem->GetFocusPosition() );
  1589. }
  1590. }
  1591. wxString SCH_EDIT_FRAME::GetCurrentFileName() const
  1592. {
  1593. return Schematic().GetFileName();
  1594. }
  1595. SELECTION& SCH_EDIT_FRAME::GetCurrentSelection()
  1596. {
  1597. return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
  1598. }
  1599. void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
  1600. {
  1601. if( IsShown() )
  1602. {
  1603. // We only need this until the frame is done resizing and the final client size is
  1604. // established.
  1605. Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
  1606. GetToolManager()->RunAction( ACTIONS::zoomFitScreen );
  1607. }
  1608. // Skip() is called in the base class.
  1609. EDA_DRAW_FRAME::OnSize( aEvent );
  1610. }
  1611. void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol,
  1612. const KIID& aSchematicSymbolUUID )
  1613. {
  1614. SCH_SHEET_PATH principalPath;
  1615. SCH_ITEM* item = Schematic().GetSheets().GetItem( aSchematicSymbolUUID, &principalPath );
  1616. SCH_SYMBOL* principalSymbol = dynamic_cast<SCH_SYMBOL*>( item );
  1617. SCH_COMMIT commit( m_toolManager );
  1618. if( !principalSymbol )
  1619. return;
  1620. wxString principalRef;
  1621. if( principalSymbol->IsAnnotated( &principalPath ) )
  1622. principalRef = principalSymbol->GetRef( &principalPath, false );
  1623. std::vector< std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> > allUnits;
  1624. for( const SCH_SHEET_PATH& path : Schematic().GetSheets() )
  1625. {
  1626. for( SCH_ITEM* candidate : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
  1627. {
  1628. SCH_SYMBOL* candidateSymbol = static_cast<SCH_SYMBOL*>( candidate );
  1629. if( candidateSymbol == principalSymbol
  1630. || ( candidateSymbol->IsAnnotated( &path )
  1631. && candidateSymbol->GetRef( &path, false ) == principalRef ) )
  1632. {
  1633. allUnits.emplace_back( candidateSymbol, path );
  1634. }
  1635. }
  1636. }
  1637. for( auto& [ unit, path ] : allUnits )
  1638. {
  1639. // This needs to be done before the LIB_SYMBOL is changed to prevent stale
  1640. // library symbols in the schematic file.
  1641. path.LastScreen()->Remove( unit );
  1642. if( !unit->IsNew() )
  1643. commit.Modify( unit, path.LastScreen() );
  1644. unit->SetLibSymbol( aSymbol.Flatten().release() );
  1645. unit->UpdateFields( &GetCurrentSheet(),
  1646. true, /* update style */
  1647. true, /* update ref */
  1648. true, /* update other fields */
  1649. false, /* reset ref */
  1650. false /* reset other fields */ );
  1651. path.LastScreen()->Append( unit );
  1652. GetCanvas()->GetView()->Update( unit );
  1653. }
  1654. if( !commit.Empty() )
  1655. commit.Push( _( "Save Symbol to Schematic" ) );
  1656. }
  1657. void SCH_EDIT_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
  1658. {
  1659. SCH_BASE_FRAME::UpdateItem( aItem, isAddOrDelete, aUpdateRtree );
  1660. if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
  1661. sch_item->ClearCaches();
  1662. }
  1663. void SCH_EDIT_FRAME::DisplayCurrentSheet()
  1664. {
  1665. wxCHECK( m_toolManager, /* void */ );
  1666. m_toolManager->RunAction( ACTIONS::cancelInteractive );
  1667. m_toolManager->RunAction( EE_ACTIONS::clearSelection );
  1668. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  1669. wxCHECK( screen, /* void */ );
  1670. m_toolManager->RunAction( EE_ACTIONS::clearSelection );
  1671. SCH_BASE_FRAME::SetScreen( screen );
  1672. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  1673. // update the references, units, and intersheet-refs
  1674. GetCurrentSheet().UpdateAllScreenReferences();
  1675. // dangling state can also have changed if different units with different pin locations are
  1676. // used
  1677. GetCurrentSheet().LastScreen()->TestDanglingEnds();
  1678. SetSheetNumberAndCount();
  1679. RefreshOperatingPointDisplay();
  1680. EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
  1681. wxCHECK( selectionTool, /* void */ );
  1682. auto visit =
  1683. [&]( EDA_ITEM* item )
  1684. {
  1685. if( m_findReplaceDialog
  1686. && !m_findReplaceData->findString.IsEmpty()
  1687. && item->Matches( *m_findReplaceData, &GetCurrentSheet() ) )
  1688. {
  1689. item->SetForceVisible( true );
  1690. selectionTool->BrightenItem( item );
  1691. }
  1692. else if( item->IsBrightened() )
  1693. {
  1694. item->SetForceVisible( false );
  1695. selectionTool->UnbrightenItem( item );
  1696. }
  1697. };
  1698. for( SCH_ITEM* item : screen->Items() )
  1699. {
  1700. visit( item );
  1701. item->RunOnChildren(
  1702. [&]( SCH_ITEM* aChild )
  1703. {
  1704. visit( aChild );
  1705. } );
  1706. }
  1707. if( !screen->m_zoomInitialized )
  1708. {
  1709. initScreenZoom();
  1710. }
  1711. else
  1712. {
  1713. // Set zoom to last used in this screen
  1714. GetCanvas()->GetView()->SetScale( GetScreen()->m_LastZoomLevel );
  1715. GetCanvas()->GetView()->SetCenter( GetScreen()->m_ScrollCenter );
  1716. }
  1717. updateTitle();
  1718. HardRedraw(); // Ensure all items are redrawn (especially the drawing-sheet items)
  1719. // Allow tools to re-add their VIEW_ITEMs after the last call to Clear in HardRedraw
  1720. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  1721. SCH_EDITOR_CONTROL* editTool = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
  1722. wxCHECK( editTool, /* void */ );
  1723. TOOL_EVENT dummy;
  1724. editTool->UpdateNetHighlighting( dummy );
  1725. m_hierarchy->UpdateHierarchySelection();
  1726. m_schematic->OnSchSheetChanged();
  1727. }
  1728. DIALOG_BOOK_REPORTER* SCH_EDIT_FRAME::GetSymbolDiffDialog()
  1729. {
  1730. if( !m_diffSymbolDialog )
  1731. m_diffSymbolDialog = new DIALOG_BOOK_REPORTER( this, DIFF_SYMBOLS_DIALOG_NAME,
  1732. _( "Compare Symbol with Library" ) );
  1733. return m_diffSymbolDialog;
  1734. }
  1735. void SCH_EDIT_FRAME::onCloseSymbolDiffDialog( wxCommandEvent& aEvent )
  1736. {
  1737. if( m_diffSymbolDialog && aEvent.GetString() == DIFF_SYMBOLS_DIALOG_NAME )
  1738. {
  1739. m_diffSymbolDialog->Destroy();
  1740. m_diffSymbolDialog = nullptr;
  1741. }
  1742. }
  1743. DIALOG_ERC* SCH_EDIT_FRAME::GetErcDialog()
  1744. {
  1745. if( !m_ercDialog )
  1746. m_ercDialog = new DIALOG_ERC( this );
  1747. return m_ercDialog;
  1748. }
  1749. void SCH_EDIT_FRAME::onCloseErcDialog( wxCommandEvent& aEvent )
  1750. {
  1751. if( m_ercDialog )
  1752. {
  1753. m_ercDialog->Destroy();
  1754. m_ercDialog = nullptr;
  1755. }
  1756. }
  1757. DIALOG_SYMBOL_FIELDS_TABLE* SCH_EDIT_FRAME::GetSymbolFieldsTableDialog()
  1758. {
  1759. if( !m_symbolFieldsTableDialog )
  1760. m_symbolFieldsTableDialog = new DIALOG_SYMBOL_FIELDS_TABLE( this );
  1761. return m_symbolFieldsTableDialog;
  1762. }
  1763. void SCH_EDIT_FRAME::onCloseSymbolFieldsTableDialog( wxCommandEvent& aEvent )
  1764. {
  1765. if( m_symbolFieldsTableDialog )
  1766. {
  1767. m_symbolFieldsTableDialog->Destroy();
  1768. m_symbolFieldsTableDialog = nullptr;
  1769. }
  1770. }
  1771. void SCH_EDIT_FRAME::AddSchematicChangeListener( wxEvtHandler* aListener )
  1772. {
  1773. auto it = std::find( m_schematicChangeListeners.begin(), m_schematicChangeListeners.end(),
  1774. aListener );
  1775. // Don't add duplicate listeners.
  1776. if( it == m_schematicChangeListeners.end() )
  1777. m_schematicChangeListeners.push_back( aListener );
  1778. }
  1779. void SCH_EDIT_FRAME::RemoveSchematicChangeListener( wxEvtHandler* aListener )
  1780. {
  1781. auto it = std::find( m_schematicChangeListeners.begin(), m_schematicChangeListeners.end(),
  1782. aListener );
  1783. // Don't add duplicate listeners.
  1784. if( it != m_schematicChangeListeners.end() )
  1785. m_schematicChangeListeners.erase( it );
  1786. }
  1787. wxTreeCtrl* SCH_EDIT_FRAME::createHighlightedNetNavigator()
  1788. {
  1789. m_netNavigator = new wxTreeCtrl( this, wxID_ANY, wxPoint( 0, 0 ),
  1790. FromDIP( wxSize( 160, 250 ) ),
  1791. wxTR_DEFAULT_STYLE | wxNO_BORDER );
  1792. return m_netNavigator;
  1793. }
  1794. void SCH_EDIT_FRAME::SetHighlightedConnection( const wxString& aConnection,
  1795. const NET_NAVIGATOR_ITEM_DATA* aSelection )
  1796. {
  1797. bool refreshNetNavigator = aConnection != m_highlightedConn;
  1798. m_highlightedConn = aConnection;
  1799. if( refreshNetNavigator )
  1800. RefreshNetNavigator( aSelection );
  1801. }
  1802. void SCH_EDIT_FRAME::unitsChangeRefresh()
  1803. {
  1804. if( m_netNavigator && !m_highlightedConn.IsEmpty() )
  1805. {
  1806. NET_NAVIGATOR_ITEM_DATA itemData;
  1807. wxTreeItemId selection = m_netNavigator->GetSelection();
  1808. bool refreshSelection = selection.IsOk() && ( selection != m_netNavigator->GetRootItem() );
  1809. if( refreshSelection )
  1810. {
  1811. NET_NAVIGATOR_ITEM_DATA* tmp =
  1812. dynamic_cast<NET_NAVIGATOR_ITEM_DATA*>( m_netNavigator->GetItemData( selection ) );
  1813. wxCHECK( tmp, /* void */ );
  1814. itemData = *tmp;
  1815. }
  1816. m_netNavigator->DeleteAllItems();
  1817. RefreshNetNavigator( refreshSelection ? &itemData : nullptr );
  1818. }
  1819. UpdateProperties();
  1820. }