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.

2608 lines
86 KiB

5 years ago
5 years ago
3 months ago
3 months 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
3 months ago
3 months ago
6 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 months ago
3 months ago
3 years ago
6 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
4 months 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
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months 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 The 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 <algorithm>
  25. #include <api/api_handler_sch.h>
  26. #include <api/api_server.h>
  27. #include <base_units.h>
  28. #include <bitmaps.h>
  29. #include <symbol_library.h>
  30. #include <confirm.h>
  31. #include <connection_graph.h>
  32. #include <dialogs/dialog_erc.h>
  33. #include <dialogs/dialog_book_reporter.h>
  34. #include <dialogs/dialog_symbol_fields_table.h>
  35. #include <widgets/sch_design_block_pane.h>
  36. #include <eeschema_id.h>
  37. #include <executable_names.h>
  38. #include <gal/graphics_abstraction_layer.h>
  39. #include <geometry/shape_segment.h>
  40. #include <gestfich.h>
  41. #include <dialogs/html_message_box.h>
  42. #include <string_utils.h>
  43. #include <kiface_base.h>
  44. #include <kiplatform/app.h>
  45. #include <kiway.h>
  46. #include <symbol_edit_frame.h>
  47. #include <symbol_viewer_frame.h>
  48. #include <pgm_base.h>
  49. #include <core/profile.h>
  50. #include <project/project_file.h>
  51. #include <project/net_settings.h>
  52. #include <python_scripting.h>
  53. #include <sch_edit_frame.h>
  54. #include <symbol_chooser_frame.h>
  55. #include <sch_painter.h>
  56. #include <sch_marker.h>
  57. #include <sch_sheet_pin.h>
  58. #include <sch_commit.h>
  59. #include <sch_rule_area.h>
  60. #include <settings/settings_manager.h>
  61. #include <advanced_config.h>
  62. #include <sim/simulator_frame.h>
  63. #include <tool/action_manager.h>
  64. #include <tool/action_toolbar.h>
  65. #include <tool/common_control.h>
  66. #include <tool/common_tools.h>
  67. #include <tool/embed_tool.h>
  68. #include <tool/picker_tool.h>
  69. #include <tool/properties_tool.h>
  70. #include <tool/selection.h>
  71. #include <tool/tool_dispatcher.h>
  72. #include <tool/tool_manager.h>
  73. #include <tool/zoom_tool.h>
  74. #include <tools/sch_actions.h>
  75. #include <tools/ee_grid_helper.h>
  76. #include <tools/sch_inspection_tool.h>
  77. #include <tools/sch_point_editor.h>
  78. #include <tools/sch_design_block_control.h>
  79. #include <tools/sch_drawing_tools.h>
  80. #include <tools/sch_edit_tool.h>
  81. #include <tools/sch_edit_table_tool.h>
  82. #include <tools/sch_editor_conditions.h>
  83. #include <tools/sch_editor_control.h>
  84. #include <tools/sch_group_tool.h>
  85. #include <tools/sch_line_wire_bus_tool.h>
  86. #include <tools/sch_move_tool.h>
  87. #include <tools/sch_navigate_tool.h>
  88. #include <tools/sch_find_replace_tool.h>
  89. #include <unordered_set>
  90. #include <view/view_controls.h>
  91. #include <widgets/wx_infobar.h>
  92. #include <widgets/hierarchy_pane.h>
  93. #include <widgets/sch_properties_panel.h>
  94. #include <widgets/sch_search_pane.h>
  95. #include <wildcards_and_files_ext.h>
  96. #include <wx/cmdline.h>
  97. #include <wx/app.h>
  98. #include <wx/filedlg.h>
  99. #include <wx/socket.h>
  100. #include <wx/debug.h>
  101. #include <widgets/panel_sch_selection_filter.h>
  102. #include <widgets/wx_aui_utils.h>
  103. #include <drawing_sheet/ds_proxy_view_item.h>
  104. #include <project/project_local_settings.h>
  105. #include <toolbars_sch_editor.h>
  106. #include <wx/log.h>
  107. #ifdef KICAD_IPC_API
  108. #include <api/api_plugin_manager.h>
  109. #include <api/api_utils.h>
  110. #include <dialog_change_symbols.h>
  111. #endif
  112. #define DIFF_SYMBOLS_DIALOG_NAME wxT( "DiffSymbolsDialog" )
  113. BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, SCH_BASE_FRAME )
  114. EVT_SOCKET( ID_EDA_SOCKET_EVENT_SERV, EDA_DRAW_FRAME::OnSockRequestServer )
  115. EVT_SOCKET( ID_EDA_SOCKET_EVENT, EDA_DRAW_FRAME::OnSockRequest )
  116. EVT_SIZE( SCH_EDIT_FRAME::OnSize )
  117. EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, SCH_EDIT_FRAME::OnLoadFile )
  118. EVT_MENU( ID_FILE_LIST_CLEAR, SCH_EDIT_FRAME::OnClearFileHistory )
  119. EVT_MENU( ID_IMPORT_NON_KICAD_SCH, SCH_EDIT_FRAME::OnImportProject )
  120. EVT_MENU( wxID_EXIT, SCH_EDIT_FRAME::OnExit )
  121. EVT_MENU( wxID_CLOSE, SCH_EDIT_FRAME::OnExit )
  122. // Drop files event
  123. EVT_DROP_FILES( SCH_EDIT_FRAME::OnDropFiles )
  124. END_EVENT_TABLE()
  125. wxDEFINE_EVENT( EDA_EVT_SCHEMATIC_CHANGING, wxCommandEvent );
  126. wxDEFINE_EVENT( EDA_EVT_SCHEMATIC_CHANGED, wxCommandEvent );
  127. SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  128. SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH, wxT( "Eeschema" ), wxDefaultPosition,
  129. wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, SCH_EDIT_FRAME_NAME ),
  130. m_ercDialog( nullptr ),
  131. m_diffSymbolDialog( nullptr ),
  132. m_symbolFieldsTableDialog( nullptr ),
  133. m_netNavigator( nullptr ),
  134. m_highlightedConnChanged( false ),
  135. m_designBlocksPane( nullptr )
  136. {
  137. m_maximizeByDefault = true;
  138. m_schematic = new SCHEMATIC( &Prj() );
  139. m_schematic->SetSchematicHolder( this );
  140. CreateDefaultScreens();
  141. m_showBorderAndTitleBlock = true; // true to show sheet references
  142. m_supportsAutoSave = true;
  143. m_syncingPcbToSchSelection = false;
  144. m_aboutTitle = _HKI( "KiCad Schematic Editor" );
  145. m_show_search = false;
  146. // Ensure timer has an owner before binding so it generates events.
  147. m_crossProbeFlashTimer.SetOwner( this );
  148. Bind( wxEVT_TIMER, &SCH_EDIT_FRAME::OnCrossProbeFlashTimer, this, m_crossProbeFlashTimer.GetId() );
  149. // Give an icon
  150. wxIcon icon;
  151. wxIconBundle icon_bundle;
  152. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 48 ) );
  153. icon_bundle.AddIcon( icon );
  154. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 128 ) );
  155. icon_bundle.AddIcon( icon );
  156. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 256 ) );
  157. icon_bundle.AddIcon( icon );
  158. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_32 ) );
  159. icon_bundle.AddIcon( icon );
  160. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_16 ) );
  161. icon_bundle.AddIcon( icon );
  162. SetIcons( icon_bundle );
  163. LoadSettings( eeconfig() );
  164. SCH_SHEET_PATH root;
  165. root.push_back( &Schematic().Root() );
  166. SetCurrentSheet( root );
  167. setupTools();
  168. setupUIConditions();
  169. ReCreateMenuBar();
  170. m_toolbarSettings = GetToolbarSettings<SCH_EDIT_TOOLBAR_SETTINGS>( "eeschema-toolbars" );
  171. configureToolbars();
  172. RecreateToolbars();
  173. // Ensure the "Line modes" toolbar group shows the current angle mode on startup
  174. if( GetToolManager() )
  175. GetToolManager()->RunAction( SCH_ACTIONS::angleSnapModeChanged );
  176. #ifdef KICAD_IPC_API
  177. wxTheApp->Bind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED, &SCH_EDIT_FRAME::onPluginAvailabilityChanged, this );
  178. #endif
  179. m_hierarchy = new HIERARCHY_PANE( this );
  180. // Initialize common print setup dialog settings.
  181. m_pageSetupData.GetPrintData().SetPrintMode( wxPRINT_MODE_PRINTER );
  182. m_pageSetupData.GetPrintData().SetQuality( wxPRINT_QUALITY_MEDIUM );
  183. m_pageSetupData.GetPrintData().SetBin( wxPRINTBIN_AUTO );
  184. m_pageSetupData.GetPrintData().SetNoCopies( 1 );
  185. m_searchPane = new SCH_SEARCH_PANE( this );
  186. m_propertiesPanel = new SCH_PROPERTIES_PANEL( this, this );
  187. m_propertiesPanel->SetSplitterProportion( eeconfig()->m_AuiPanels.properties_splitter );
  188. m_selectionFilterPanel = new PANEL_SCH_SELECTION_FILTER( this );
  189. m_designBlocksPane = new SCH_DESIGN_BLOCK_PANE( this, nullptr, m_designBlockHistoryList );
  190. m_auimgr.SetManagedWindow( this );
  191. CreateInfoBar();
  192. // Fetch a COPY of the config as a lot of these initializations are going to overwrite our
  193. // data.
  194. EESCHEMA_SETTINGS::AUI_PANELS aui_cfg = eeconfig()->m_AuiPanels;
  195. EESCHEMA_SETTINGS::APPEARANCE appearance_cfg = eeconfig()->m_Appearance;
  196. // Rows; layers 4 - 6
  197. m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( wxS( "TopMainToolbar" ) )
  198. .Top().Layer( 6 ) );
  199. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( wxS( "MsgPanel" ) )
  200. .Bottom().Layer( 6 ) );
  201. // Columns; layers 1 - 3
  202. m_auimgr.AddPane( m_hierarchy, EDA_PANE().Palette().Name( SchematicHierarchyPaneName() )
  203. .Caption( _( "Schematic Hierarchy" ) )
  204. .Left().Layer( 3 ).Position( 1 )
  205. .TopDockable( false )
  206. .BottomDockable( false )
  207. .CloseButton( true )
  208. .MinSize( FromDIP( wxSize( 120, 60 ) ) )
  209. .BestSize( FromDIP( wxSize( 200, 200 ) ) )
  210. .FloatingSize( FromDIP( wxSize( 200, 200 ) ) )
  211. .FloatingPosition( FromDIP( wxPoint( 50, 50 ) ) )
  212. .Show( false ) );
  213. m_auimgr.AddPane( m_propertiesPanel, defaultPropertiesPaneInfo( this ) );
  214. m_auimgr.AddPane( m_selectionFilterPanel, defaultSchSelectionFilterPaneInfo( this ) );
  215. m_auimgr.AddPane( m_designBlocksPane, defaultDesignBlocksPaneInfo( this ) );
  216. m_auimgr.AddPane( createHighlightedNetNavigator(), defaultNetNavigatorPaneInfo() );
  217. m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( wxS( "LeftToolbar" ) )
  218. .Left().Layer( 2 ) );
  219. m_auimgr.AddPane( m_tbRight, EDA_PANE().VToolbar().Name( wxS( "RightToolbar" ) )
  220. .Right().Layer( 2 ) );
  221. // Center
  222. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( wxS( "DrawFrame" ) )
  223. .Center() );
  224. m_auimgr.AddPane( m_searchPane, EDA_PANE()
  225. .Name( SearchPaneName() )
  226. .Bottom()
  227. .Caption( _( "Search" ) )
  228. .PaneBorder( false )
  229. .MinSize( FromDIP( wxSize( 180, 60 ) ) )
  230. .BestSize( FromDIP( wxSize( 180, 100 ) ) )
  231. .FloatingSize( FromDIP( wxSize( 480, 200 ) ) )
  232. .CloseButton( true )
  233. .DestroyOnClose( false )
  234. .Show( m_show_search ) );
  235. RestoreAuiLayout();
  236. FinishAUIInitialization();
  237. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  238. wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
  239. wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
  240. wxAuiPaneInfo& selectionFilterPane = m_auimgr.GetPane( wxS( "SelectionFilter" ) );
  241. wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
  242. hierarchy_pane.Show( aui_cfg.show_schematic_hierarchy );
  243. netNavigatorPane.Show( aui_cfg.show_net_nav_panel );
  244. propertiesPane.Show( aui_cfg.show_properties );
  245. designBlocksPane.Show( aui_cfg.design_blocks_show );
  246. updateSelectionFilterVisbility();
  247. // The selection filter doesn't need to grow in the vertical direction when docked
  248. selectionFilterPane.dock_proportion = 0;
  249. if( aui_cfg.hierarchy_panel_float_width > 0 && aui_cfg.hierarchy_panel_float_height > 0 )
  250. {
  251. // Show at end, after positioning
  252. hierarchy_pane.FloatingSize( aui_cfg.hierarchy_panel_float_width,
  253. aui_cfg.hierarchy_panel_float_height );
  254. }
  255. if( aui_cfg.net_nav_panel_float_size.GetWidth() > 0
  256. && aui_cfg.net_nav_panel_float_size.GetHeight() > 0 )
  257. {
  258. netNavigatorPane.FloatingSize( aui_cfg.net_nav_panel_float_size );
  259. netNavigatorPane.FloatingPosition( aui_cfg.net_nav_panel_float_pos );
  260. }
  261. if( aui_cfg.properties_panel_width > 0 )
  262. SetAuiPaneSize( m_auimgr, propertiesPane, aui_cfg.properties_panel_width, -1 );
  263. if( aui_cfg.schematic_hierarchy_float )
  264. hierarchy_pane.Float();
  265. if( aui_cfg.search_panel_height > 0
  266. && ( aui_cfg.search_panel_dock_direction == wxAUI_DOCK_TOP
  267. || aui_cfg.search_panel_dock_direction == wxAUI_DOCK_BOTTOM ) )
  268. {
  269. wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
  270. searchPane.Direction( aui_cfg.search_panel_dock_direction );
  271. SetAuiPaneSize( m_auimgr, searchPane, -1, aui_cfg.search_panel_height );
  272. }
  273. else if( aui_cfg.search_panel_width > 0
  274. && ( aui_cfg.search_panel_dock_direction == wxAUI_DOCK_LEFT
  275. || aui_cfg.search_panel_dock_direction == wxAUI_DOCK_RIGHT ) )
  276. {
  277. wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
  278. searchPane.Direction( aui_cfg.search_panel_dock_direction );
  279. SetAuiPaneSize( m_auimgr, searchPane, aui_cfg.search_panel_width, -1 );
  280. }
  281. if( aui_cfg.float_net_nav_panel )
  282. netNavigatorPane.Float();
  283. if( aui_cfg.design_blocks_show )
  284. SetAuiPaneSize( m_auimgr, designBlocksPane, aui_cfg.design_blocks_panel_docked_width, -1 );
  285. if( aui_cfg.hierarchy_panel_docked_width > 0 )
  286. {
  287. // If the net navigator is not show, let the hierarchy navigator take all of the vertical
  288. // space.
  289. if( !aui_cfg.show_net_nav_panel )
  290. {
  291. SetAuiPaneSize( m_auimgr, hierarchy_pane, aui_cfg.hierarchy_panel_docked_width, -1 );
  292. }
  293. else
  294. {
  295. SetAuiPaneSize( m_auimgr, hierarchy_pane,
  296. aui_cfg.hierarchy_panel_docked_width,
  297. aui_cfg.hierarchy_panel_docked_height );
  298. SetAuiPaneSize( m_auimgr, netNavigatorPane,
  299. aui_cfg.net_nav_panel_docked_size.GetWidth(),
  300. aui_cfg.net_nav_panel_docked_size.GetHeight() );
  301. }
  302. // wxAUI hack: force width by setting MinSize() and then Fixed()
  303. // thanks to ZenJu https://github.com/wxWidgets/wxWidgets/issues/13180
  304. hierarchy_pane.MinSize( aui_cfg.hierarchy_panel_docked_width, 60 );
  305. hierarchy_pane.Fixed();
  306. netNavigatorPane.MinSize( aui_cfg.net_nav_panel_docked_size.GetWidth(), 60 );
  307. netNavigatorPane.Fixed();
  308. m_auimgr.Update();
  309. // now make it resizable again
  310. hierarchy_pane.Resizable();
  311. netNavigatorPane.Resizable();
  312. m_auimgr.Update();
  313. // Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
  314. // back to minimum.
  315. hierarchy_pane.MinSize( FromDIP( wxSize( 120, 60 ) ) );
  316. netNavigatorPane.MinSize( FromDIP( wxSize( 120, 60 ) ) );
  317. }
  318. else
  319. {
  320. m_auimgr.Update();
  321. }
  322. resolveCanvasType();
  323. SwitchCanvas( m_canvasType );
  324. GetCanvas()->GetGAL()->SetAxesEnabled( false );
  325. KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
  326. static_cast<KIGFX::SCH_PAINTER*>( view->GetPainter() )->SetSchematic( m_schematic );
  327. LoadProjectSettings();
  328. LoadDrawingSheet();
  329. view->SetLayerVisible( LAYER_ERC_ERR, appearance_cfg.show_erc_errors );
  330. view->SetLayerVisible( LAYER_ERC_WARN, appearance_cfg.show_erc_warnings );
  331. view->SetLayerVisible( LAYER_ERC_EXCLUSION, appearance_cfg.show_erc_exclusions );
  332. view->SetLayerVisible( LAYER_OP_VOLTAGES, appearance_cfg.show_op_voltages );
  333. view->SetLayerVisible( LAYER_OP_CURRENTS, appearance_cfg.show_op_currents );
  334. initScreenZoom();
  335. m_hierarchy->Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::OnResizeHierarchyNavigator, this );
  336. m_netNavigator->Bind( wxEVT_TREE_SEL_CHANGING, &SCH_EDIT_FRAME::onNetNavigatorSelChanging, this );
  337. m_netNavigator->Bind( wxEVT_TREE_SEL_CHANGED, &SCH_EDIT_FRAME::onNetNavigatorSelection, this );
  338. m_netNavigator->Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onResizeNetNavigator, this );
  339. // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
  340. // to calculate the wrong zoom size. See SCH_EDIT_FRAME::onSize().
  341. Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
  342. setupUnits( eeconfig() );
  343. // Net list generator
  344. DefaultExecFlags();
  345. updateTitle();
  346. m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->ResetHistory();
  347. #ifdef KICAD_IPC_API
  348. m_apiHandler = std::make_unique<API_HANDLER_SCH>( this );
  349. Pgm().GetApiServer().RegisterHandler( m_apiHandler.get() );
  350. #endif
  351. // Default shutdown reason until a file is loaded
  352. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New schematic file is unsaved" ) );
  353. // Init for dropping files
  354. m_acceptedExts.emplace( FILEEXT::KiCadSchematicFileExtension, &SCH_ACTIONS::ddAppendFile );
  355. m_acceptedExts.emplace( FILEEXT::PngFileExtension, &SCH_ACTIONS::ddAddImage );
  356. m_acceptedExts.emplace( FILEEXT::JpegFileExtension, &SCH_ACTIONS::ddAddImage );
  357. m_acceptedExts.emplace( wxS( "jpeg" ), &SCH_ACTIONS::ddAddImage );
  358. m_acceptedExts.emplace( wxS( "dxf" ), &SCH_ACTIONS::ddImportGraphics );
  359. m_acceptedExts.emplace( FILEEXT::SVGFileExtension, &SCH_ACTIONS::ddImportGraphics );
  360. DragAcceptFiles( true );
  361. // Ensure the window is on top
  362. Raise();
  363. // Now that all sizes are fixed, set the initial hierarchy_pane floating position to the
  364. // top-left corner of the canvas
  365. wxPoint canvas_pos = GetCanvas()->GetScreenPosition();
  366. hierarchy_pane.FloatingPosition( canvas_pos.x + 10, canvas_pos.y + 10 );
  367. Bind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &SCH_EDIT_FRAME::onCloseSymbolDiffDialog, this );
  368. Bind( EDA_EVT_CLOSE_ERC_DIALOG, &SCH_EDIT_FRAME::onCloseErcDialog, this );
  369. Bind( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, &SCH_EDIT_FRAME::onCloseSymbolFieldsTableDialog, this );
  370. }
  371. void SCH_EDIT_FRAME::StartCrossProbeFlash( const std::vector<SCH_ITEM*>& aItems )
  372. {
  373. if( !eeconfig()->m_CrossProbing.flash_selection )
  374. {
  375. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash: aborted (setting disabled) items=%zu", aItems.size() );
  376. return;
  377. }
  378. if( aItems.empty() )
  379. {
  380. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash: aborted (no items)" );
  381. return;
  382. }
  383. if( m_crossProbeFlashing )
  384. {
  385. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash: restarting existing flash (phase=%d)", m_crossProbeFlashPhase );
  386. m_crossProbeFlashTimer.Stop();
  387. }
  388. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash: starting with %zu items", aItems.size() );
  389. m_crossProbeFlashItems.clear();
  390. for( SCH_ITEM* it : aItems )
  391. m_crossProbeFlashItems.push_back( it->m_Uuid );
  392. m_crossProbeFlashPhase = 0;
  393. m_crossProbeFlashing = true;
  394. if( !m_crossProbeFlashTimer.GetOwner() )
  395. m_crossProbeFlashTimer.SetOwner( this );
  396. bool started = m_crossProbeFlashTimer.Start( 500, wxTIMER_CONTINUOUS );
  397. wxLogTrace( "CROSS_PROBE_FLASH", "StartCrossProbeFlash: timer start=%d id=%d", (int) started, m_crossProbeFlashTimer.GetId() );
  398. }
  399. void SCH_EDIT_FRAME::OnCrossProbeFlashTimer( wxTimerEvent& aEvent )
  400. {
  401. wxLogTrace( "CROSS_PROBE_FLASH", "Timer(SCH) fired: phase=%d running=%d items=%zu", m_crossProbeFlashPhase, (int) m_crossProbeFlashing, m_crossProbeFlashItems.size() );
  402. if( !m_crossProbeFlashing )
  403. {
  404. wxLogTrace( "CROSS_PROBE_FLASH", "Timer fired but not flashing (ignored)" );
  405. return;
  406. }
  407. SCH_SELECTION_TOOL* selTool = GetToolManager()->GetTool<SCH_SELECTION_TOOL>();
  408. if( !selTool )
  409. return;
  410. bool prevGuard = m_syncingPcbToSchSelection;
  411. m_syncingPcbToSchSelection = true;
  412. if( m_crossProbeFlashPhase % 2 == 0 )
  413. {
  414. selTool->ClearSelection( true );
  415. wxLogTrace( "CROSS_PROBE_FLASH", "Phase %d: cleared selection", m_crossProbeFlashPhase );
  416. }
  417. else
  418. {
  419. for( const KIID& id : m_crossProbeFlashItems )
  420. {
  421. if( SCH_ITEM* item = Schematic().ResolveItem( id, nullptr, true ) )
  422. selTool->AddItemToSel( item, true );
  423. }
  424. wxLogTrace( "CROSS_PROBE_FLASH", "Phase %d: restored %zu items", m_crossProbeFlashPhase, m_crossProbeFlashItems.size() );
  425. }
  426. if( GetCanvas() )
  427. {
  428. GetCanvas()->ForceRefresh();
  429. wxLogTrace( "CROSS_PROBE_FLASH", "Phase %d: forced canvas refresh", m_crossProbeFlashPhase );
  430. }
  431. m_syncingPcbToSchSelection = prevGuard;
  432. m_crossProbeFlashPhase++;
  433. if( m_crossProbeFlashPhase > 6 )
  434. {
  435. for( const KIID& id : m_crossProbeFlashItems )
  436. {
  437. if( SCH_ITEM* item = Schematic().ResolveItem( id, nullptr, true ) )
  438. selTool->AddItemToSel( item, true );
  439. }
  440. m_crossProbeFlashing = false;
  441. m_crossProbeFlashTimer.Stop();
  442. wxLogTrace( "CROSS_PROBE_FLASH", "Flashing complete. Final selection size=%zu", m_crossProbeFlashItems.size() );
  443. }
  444. }
  445. SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
  446. {
  447. m_hierarchy->Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::OnResizeHierarchyNavigator, this );
  448. // Ensure m_canvasType is up to date, to save it in config
  449. m_canvasType = GetCanvas()->GetBackend();
  450. SetScreen( nullptr );
  451. if( m_schematic )
  452. m_schematic->RemoveAllListeners();
  453. // Delete all items not in draw list before deleting schematic
  454. // to avoid dangling pointers stored in these items
  455. ClearUndoRedoList();
  456. ClearRepeatItemsList();
  457. delete m_schematic;
  458. m_schematic = nullptr;
  459. // Close the project if we are standalone, so it gets cleaned up properly
  460. if( Kiface().IsSingle() )
  461. {
  462. try
  463. {
  464. GetSettingsManager()->UnloadProject( &Prj(), false );
  465. }
  466. catch( const nlohmann::detail::type_error& e )
  467. {
  468. wxFAIL_MSG( wxString::Format( wxT( "Settings exception occurred: %s" ), e.what() ) );
  469. }
  470. }
  471. // We passed ownership of these to wxAuiManager.
  472. // delete m_hierarchy;
  473. // delete m_selectionFilterPanel;
  474. }
  475. void SCH_EDIT_FRAME::OnResizeHierarchyNavigator( wxSizeEvent& aEvent )
  476. {
  477. aEvent.Skip();
  478. // 1st Call: Handle the size update during the first resize event.
  479. CaptureHierarchyPaneSize();
  480. // Defer the second size capture
  481. CallAfter( [this]()
  482. {
  483. CaptureHierarchyPaneSize();
  484. } );
  485. }
  486. void SCH_EDIT_FRAME::CaptureHierarchyPaneSize()
  487. {
  488. // Called when resizing the Hierarchy Navigator panel
  489. // Store the current pane size
  490. // It allows to retrieve the last defined pane size when switching between
  491. // docked and floating pane state
  492. // Note: *DO NOT* call m_auimgr.Update() here: it crashes KiCad at least on Windows
  493. EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
  494. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  495. if( cfg && m_hierarchy->IsShownOnScreen() )
  496. {
  497. cfg->m_AuiPanels.hierarchy_panel_float_width = hierarchy_pane.floating_size.x;
  498. cfg->m_AuiPanels.hierarchy_panel_float_height = hierarchy_pane.floating_size.y;
  499. // initialize hierarchy_panel_docked_width and best size only if the hierarchy_pane
  500. // width is > 0 (i.e. if its size is already set and has meaning)
  501. // if it is floating, its size is not initialized (only floating_size is initialized)
  502. // initializing hierarchy_pane.best_size is useful when switching to float pane and
  503. // after switching to the docked pane, to retrieve the last docked pane width
  504. if( hierarchy_pane.rect.width > 50 ) // 50 is a good margin
  505. {
  506. cfg->m_AuiPanels.hierarchy_panel_docked_width = hierarchy_pane.rect.width;
  507. hierarchy_pane.best_size.x = hierarchy_pane.rect.width;
  508. }
  509. }
  510. }
  511. void SCH_EDIT_FRAME::setupTools()
  512. {
  513. // Create the manager and dispatcher & route draw panel events to the dispatcher
  514. m_toolManager = new TOOL_MANAGER;
  515. m_toolManager->SetEnvironment( &Schematic(), GetCanvas()->GetView(),
  516. GetCanvas()->GetViewControls(), config(), this );
  517. m_actions = new SCH_ACTIONS();
  518. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  519. // Register tools
  520. m_toolManager->RegisterTool( new COMMON_CONTROL );
  521. m_toolManager->RegisterTool( new COMMON_TOOLS );
  522. m_toolManager->RegisterTool( new ZOOM_TOOL );
  523. m_toolManager->RegisterTool( new SCH_SELECTION_TOOL );
  524. m_toolManager->RegisterTool( new PICKER_TOOL );
  525. m_toolManager->RegisterTool( new SCH_DRAWING_TOOLS );
  526. m_toolManager->RegisterTool( new SCH_LINE_WIRE_BUS_TOOL );
  527. m_toolManager->RegisterTool( new SCH_MOVE_TOOL );
  528. m_toolManager->RegisterTool( new SCH_EDIT_TOOL );
  529. m_toolManager->RegisterTool( new SCH_EDIT_TABLE_TOOL );
  530. m_toolManager->RegisterTool( new SCH_GROUP_TOOL );
  531. m_toolManager->RegisterTool( new SCH_INSPECTION_TOOL );
  532. m_toolManager->RegisterTool( new SCH_DESIGN_BLOCK_CONTROL );
  533. m_toolManager->RegisterTool( new SCH_EDITOR_CONTROL );
  534. m_toolManager->RegisterTool( new SCH_FIND_REPLACE_TOOL );
  535. m_toolManager->RegisterTool( new SCH_POINT_EDITOR );
  536. m_toolManager->RegisterTool( new SCH_NAVIGATE_TOOL );
  537. m_toolManager->RegisterTool( new PROPERTIES_TOOL );
  538. m_toolManager->RegisterTool( new EMBED_TOOL );
  539. m_toolManager->InitTools();
  540. // Run the selection tool, it is supposed to be always active
  541. m_toolManager->PostAction( ACTIONS::selectionActivate );
  542. GetCanvas()->SetEventDispatcher( m_toolDispatcher );
  543. }
  544. void SCH_EDIT_FRAME::setupUIConditions()
  545. {
  546. SCH_BASE_FRAME::setupUIConditions();
  547. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  548. SCH_EDITOR_CONDITIONS cond( this );
  549. wxASSERT( mgr );
  550. auto hasElements =
  551. [ this ] ( const SELECTION& aSel )
  552. {
  553. return GetScreen() &&
  554. ( !GetScreen()->Items().empty() || !SELECTION_CONDITIONS::Idle( aSel ) );
  555. };
  556. auto searchPaneCond =
  557. [this] ( const SELECTION& )
  558. {
  559. return m_auimgr.GetPane( SearchPaneName() ).IsShown();
  560. };
  561. auto propertiesCond =
  562. [this] ( const SELECTION& )
  563. {
  564. return m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
  565. };
  566. auto hierarchyNavigatorCond =
  567. [ this ] ( const SELECTION& aSel )
  568. {
  569. return m_auimgr.GetPane( SchematicHierarchyPaneName() ).IsShown();
  570. };
  571. auto netNavigatorCond =
  572. [ this ] (const SELECTION& aSel )
  573. {
  574. return m_auimgr.GetPane( NetNavigatorPaneName() ).IsShown();
  575. };
  576. auto designBlockCond =
  577. [ this ] (const SELECTION& aSel )
  578. {
  579. return m_auimgr.GetPane( DesignBlocksPaneName() ).IsShown();
  580. };
  581. auto undoCond =
  582. [ this ] (const SELECTION& aSel )
  583. {
  584. if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
  585. return true;
  586. return GetUndoCommandCount() > 0;
  587. };
  588. auto groupWithDesignBlockLink =
  589. [] ( const SELECTION& aSel )
  590. {
  591. if( aSel.Size() != 1 )
  592. return false;
  593. if( aSel[0]->Type() != SCH_GROUP_T )
  594. return false;
  595. SCH_GROUP* group = static_cast<SCH_GROUP*>( aSel.GetItem( 0 ) );
  596. return group->HasDesignBlockLink();
  597. };
  598. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  599. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  600. mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  601. mgr->SetConditions( ACTIONS::undo, ENABLE( undoCond ) );
  602. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  603. mgr->SetConditions( SCH_ACTIONS::showSearch, CHECK( searchPaneCond ) );
  604. mgr->SetConditions( SCH_ACTIONS::showHierarchy, CHECK( hierarchyNavigatorCond ) );
  605. mgr->SetConditions( SCH_ACTIONS::showNetNavigator, CHECK( netNavigatorCond ) );
  606. mgr->SetConditions( ACTIONS::showProperties, CHECK( propertiesCond ) );
  607. mgr->SetConditions( SCH_ACTIONS::showDesignBlockPanel, CHECK( designBlockCond ) );
  608. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  609. mgr->SetConditions( ACTIONS::toggleGridOverrides, CHECK( cond.GridOverrides() ) );
  610. mgr->SetConditions( ACTIONS::cut, ENABLE( hasElements ) );
  611. mgr->SetConditions( ACTIONS::copy, ENABLE( hasElements ) );
  612. mgr->SetConditions( ACTIONS::copyAsText, ENABLE( hasElements ) );
  613. mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
  614. mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
  615. mgr->SetConditions( ACTIONS::doDelete, ENABLE( hasElements ) );
  616. mgr->SetConditions( ACTIONS::duplicate, ENABLE( hasElements ) );
  617. mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) );
  618. mgr->SetConditions( ACTIONS::unselectAll, ENABLE( hasElements ) );
  619. mgr->SetConditions( SCH_ACTIONS::rotateCW, ENABLE( hasElements ) );
  620. mgr->SetConditions( SCH_ACTIONS::rotateCCW, ENABLE( hasElements ) );
  621. mgr->SetConditions( SCH_ACTIONS::mirrorH, ENABLE( hasElements ) );
  622. mgr->SetConditions( SCH_ACTIONS::mirrorV, ENABLE( hasElements ) );
  623. mgr->SetConditions( ACTIONS::group, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  624. mgr->SetConditions( ACTIONS::ungroup, ENABLE( SELECTION_CONDITIONS::HasType( SCH_GROUP_T ) ) );
  625. mgr->SetConditions( SCH_ACTIONS::placeLinkedDesignBlock, ENABLE( groupWithDesignBlockLink ) );
  626. mgr->SetConditions( SCH_ACTIONS::saveToLinkedDesignBlock, ENABLE( groupWithDesignBlockLink ) );
  627. mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  628. mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  629. auto showHiddenPinsCond =
  630. [this]( const SELECTION& )
  631. {
  632. return GetShowAllPins();
  633. };
  634. auto showHiddenFieldsCond =
  635. [this]( const SELECTION& )
  636. {
  637. EESCHEMA_SETTINGS* cfg = eeconfig();
  638. return cfg && cfg->m_Appearance.show_hidden_fields;
  639. };
  640. auto showDirectiveLabelsCond =
  641. [this]( const SELECTION& )
  642. {
  643. EESCHEMA_SETTINGS* cfg = eeconfig();
  644. return cfg && cfg->m_Appearance.show_directive_labels;
  645. };
  646. auto showERCErrorsCond =
  647. [this]( const SELECTION& )
  648. {
  649. EESCHEMA_SETTINGS* cfg = eeconfig();
  650. return cfg && cfg->m_Appearance.show_erc_errors;
  651. };
  652. auto showERCWarningsCond =
  653. [this]( const SELECTION& )
  654. {
  655. EESCHEMA_SETTINGS* cfg = eeconfig();
  656. return cfg && cfg->m_Appearance.show_erc_warnings;
  657. };
  658. auto showERCExclusionsCond =
  659. [this]( const SELECTION& )
  660. {
  661. EESCHEMA_SETTINGS* cfg = eeconfig();
  662. return cfg && cfg->m_Appearance.show_erc_exclusions;
  663. };
  664. auto markSimExclusionsCond =
  665. [this]( const SELECTION& )
  666. {
  667. EESCHEMA_SETTINGS* cfg = eeconfig();
  668. return cfg && cfg->m_Appearance.mark_sim_exclusions;
  669. };
  670. auto showOPVoltagesCond =
  671. [this]( const SELECTION& )
  672. {
  673. EESCHEMA_SETTINGS* cfg = eeconfig();
  674. return cfg && cfg->m_Appearance.show_op_voltages;
  675. };
  676. auto showOPCurrentsCond =
  677. [this]( const SELECTION& )
  678. {
  679. EESCHEMA_SETTINGS* cfg = eeconfig();
  680. return cfg && cfg->m_Appearance.show_op_currents;
  681. };
  682. auto showPinAltModeIconsCond =
  683. [this]( const SELECTION& )
  684. {
  685. EESCHEMA_SETTINGS* cfg = eeconfig();
  686. return cfg && cfg->m_Appearance.show_pin_alt_icons;
  687. };
  688. auto showAnnotateAutomaticallyCond =
  689. [this]( const SELECTION& )
  690. {
  691. return eeconfig()->m_AnnotatePanel.automatic;
  692. };
  693. auto remapSymbolsCondition =
  694. [&]( const SELECTION& aSel )
  695. {
  696. SCH_SCREENS schematic( Schematic().Root() );
  697. // The remapping can only be performed on legacy projects.
  698. return schematic.HasNoFullyDefinedLibIds();
  699. };
  700. auto belowRootSheetCondition =
  701. [this]( const SELECTION& aSel )
  702. {
  703. SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
  704. return navigateTool && navigateTool->CanGoUp();
  705. };
  706. mgr->SetConditions( SCH_ACTIONS::leaveSheet, ENABLE( belowRootSheetCondition ) );
  707. /* Some of these are bound by default to arrow keys which will get a different action if we
  708. * disable the buttons. So always leave them enabled so the action is consistent.
  709. * https://gitlab.com/kicad/code/kicad/-/issues/14783
  710. mgr->SetConditions( SCH_ACTIONS::navigateUp, ENABLE( belowRootSheetCondition ) );
  711. mgr->SetConditions( SCH_ACTIONS::navigateForward, ENABLE( navHistoryHasForward ) );
  712. mgr->SetConditions( SCH_ACTIONS::navigateBack, ENABLE( navHistoryHsBackward ) );
  713. */
  714. mgr->SetConditions( SCH_ACTIONS::remapSymbols, ENABLE( remapSymbolsCondition ) );
  715. mgr->SetConditions( SCH_ACTIONS::toggleHiddenPins, CHECK( showHiddenPinsCond ) );
  716. mgr->SetConditions( SCH_ACTIONS::toggleHiddenFields, CHECK( showHiddenFieldsCond ) );
  717. mgr->SetConditions( SCH_ACTIONS::toggleDirectiveLabels, CHECK( showDirectiveLabelsCond ) );
  718. mgr->SetConditions( SCH_ACTIONS::toggleERCErrors, CHECK( showERCErrorsCond ) );
  719. mgr->SetConditions( SCH_ACTIONS::toggleERCWarnings, CHECK( showERCWarningsCond ) );
  720. mgr->SetConditions( SCH_ACTIONS::toggleERCExclusions, CHECK( showERCExclusionsCond ) );
  721. mgr->SetConditions( SCH_ACTIONS::markSimExclusions, CHECK( markSimExclusionsCond ) );
  722. mgr->SetConditions( SCH_ACTIONS::toggleOPVoltages, CHECK( showOPVoltagesCond ) );
  723. mgr->SetConditions( SCH_ACTIONS::toggleOPCurrents, CHECK( showOPCurrentsCond ) );
  724. mgr->SetConditions( SCH_ACTIONS::togglePinAltIcons, CHECK( showPinAltModeIconsCond ) );
  725. mgr->SetConditions( SCH_ACTIONS::toggleAnnotateAuto, CHECK( showAnnotateAutomaticallyCond ) );
  726. mgr->SetConditions( ACTIONS::toggleBoundingBoxes, CHECK( cond.BoundingBoxes() ) );
  727. mgr->SetConditions( SCH_ACTIONS::saveSheetAsDesignBlock, ENABLE( hasElements ) );
  728. mgr->SetConditions( SCH_ACTIONS::saveSelectionAsDesignBlock, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  729. #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
  730. CURRENT_TOOL( ACTIONS::deleteTool );
  731. CURRENT_TOOL( SCH_ACTIONS::highlightNetTool );
  732. CURRENT_TOOL( SCH_ACTIONS::placeSymbol );
  733. CURRENT_TOOL( SCH_ACTIONS::placePower );
  734. CURRENT_TOOL( SCH_ACTIONS::placeDesignBlock );
  735. CURRENT_TOOL( SCH_ACTIONS::drawWire );
  736. CURRENT_TOOL( SCH_ACTIONS::drawBus );
  737. CURRENT_TOOL( SCH_ACTIONS::placeBusWireEntry );
  738. CURRENT_TOOL( SCH_ACTIONS::placeNoConnect );
  739. CURRENT_TOOL( SCH_ACTIONS::placeJunction );
  740. CURRENT_TOOL( SCH_ACTIONS::placeLabel );
  741. CURRENT_TOOL( SCH_ACTIONS::placeClassLabel );
  742. CURRENT_TOOL( SCH_ACTIONS::placeGlobalLabel );
  743. CURRENT_TOOL( SCH_ACTIONS::placeHierLabel );
  744. CURRENT_TOOL( SCH_ACTIONS::drawRuleArea );
  745. CURRENT_TOOL( SCH_ACTIONS::drawSheet );
  746. CURRENT_TOOL( SCH_ACTIONS::placeSheetPin );
  747. CURRENT_TOOL( SCH_ACTIONS::syncSheetPins );
  748. CURRENT_TOOL( SCH_ACTIONS::drawSheetFromFile );
  749. CURRENT_TOOL( SCH_ACTIONS::drawSheetFromDesignBlock );
  750. CURRENT_TOOL( SCH_ACTIONS::drawRectangle );
  751. CURRENT_TOOL( SCH_ACTIONS::drawCircle );
  752. CURRENT_TOOL( SCH_ACTIONS::drawArc );
  753. CURRENT_TOOL( SCH_ACTIONS::drawBezier );
  754. CURRENT_TOOL( SCH_ACTIONS::drawLines );
  755. CURRENT_TOOL( SCH_ACTIONS::placeSchematicText );
  756. CURRENT_TOOL( SCH_ACTIONS::drawTextBox );
  757. CURRENT_TOOL( SCH_ACTIONS::drawTable );
  758. CURRENT_TOOL( SCH_ACTIONS::placeImage );
  759. #undef CURRENT_TOOL
  760. #undef CHECK
  761. #undef ENABLE
  762. }
  763. void SCH_EDIT_FRAME::SaveCopyForRepeatItem( const SCH_ITEM* aItem )
  764. {
  765. // we cannot store a pointer to an item in the display list here since
  766. // that item may be deleted, such as part of a line concatenation or other.
  767. // So simply always keep a copy of the object which is to be repeated.
  768. if( aItem )
  769. {
  770. m_items_to_repeat.clear();
  771. AddCopyForRepeatItem( aItem );
  772. }
  773. }
  774. void SCH_EDIT_FRAME::AddCopyForRepeatItem( const SCH_ITEM* aItem )
  775. {
  776. // we cannot store a pointer to an item in the display list here since
  777. // that item may be deleted, such as part of a line concatenation or other.
  778. // So simply always keep a copy of the object which is to be repeated.
  779. if( aItem )
  780. {
  781. std::unique_ptr<SCH_ITEM> repeatItem( static_cast<SCH_ITEM*>( aItem->Duplicate( IGNORE_PARENT_GROUP ) ) );
  782. // Clone() preserves the flags & parent, we want 'em cleared.
  783. repeatItem->ClearFlags();
  784. repeatItem->SetParent( nullptr );
  785. m_items_to_repeat.emplace_back( std::move( repeatItem ) );
  786. }
  787. }
  788. EDA_ITEM* SCH_EDIT_FRAME::ResolveItem( const KIID& aId, bool aAllowNullptrReturn ) const
  789. {
  790. return Schematic().ResolveItem( aId, nullptr, aAllowNullptrReturn );
  791. }
  792. void SCH_EDIT_FRAME::SetSheetNumberAndCount()
  793. {
  794. Schematic().SetSheetNumberAndCount();
  795. }
  796. SCH_SCREEN* SCH_EDIT_FRAME::GetScreen() const
  797. {
  798. return GetCurrentSheet().LastScreen();
  799. }
  800. SCHEMATIC& SCH_EDIT_FRAME::Schematic() const
  801. {
  802. return *m_schematic;
  803. }
  804. wxString SCH_EDIT_FRAME::GetScreenDesc() const
  805. {
  806. return GetCurrentSheet().Last()->GetName();
  807. }
  808. wxString SCH_EDIT_FRAME::GetFullScreenDesc() const
  809. {
  810. return GetCurrentSheet().PathHumanReadable();
  811. }
  812. void SCH_EDIT_FRAME::CreateDefaultScreens()
  813. {
  814. m_schematic->CreateDefaultScreens();
  815. SetScreen( Schematic().RootScreen() );
  816. if( GetScreen() == nullptr )
  817. {
  818. SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
  819. SetScreen( screen );
  820. }
  821. }
  822. SCH_SHEET_PATH& SCH_EDIT_FRAME::GetCurrentSheet() const
  823. {
  824. return m_schematic->CurrentSheet();
  825. }
  826. void SCH_EDIT_FRAME::SetCurrentSheet( const SCH_SHEET_PATH& aSheet )
  827. {
  828. if( aSheet != GetCurrentSheet() )
  829. {
  830. ClearFocus();
  831. Schematic().SetCurrentSheet( aSheet );
  832. GetCanvas()->DisplaySheet( aSheet.LastScreen() );
  833. }
  834. }
  835. void SCH_EDIT_FRAME::HardRedraw()
  836. {
  837. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  838. for( SCH_ITEM* item : screen->Items() )
  839. item->ClearCaches();
  840. for( const std::pair<const wxString, LIB_SYMBOL*>& libSymbol : screen->GetLibSymbols() )
  841. {
  842. wxCHECK2( libSymbol.second, continue );
  843. libSymbol.second->ClearCaches();
  844. }
  845. if( Schematic().Settings().m_IntersheetRefsShow )
  846. RecomputeIntersheetRefs();
  847. ClearFocus();
  848. GetCanvas()->DisplaySheet( GetCurrentSheet().LastScreen() );
  849. if( SCH_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<SCH_SELECTION_TOOL>() )
  850. selectionTool->Reset( TOOL_BASE::REDRAW );
  851. GetCanvas()->ForceRefresh();
  852. }
  853. bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
  854. {
  855. // Exit interactive editing
  856. // Note this this will commit *some* pending changes. For instance, the SCH_POINT_EDITOR
  857. // will cancel any drag currently in progress, but commit all changes from previous drags.
  858. if( m_toolManager )
  859. m_toolManager->RunAction( ACTIONS::cancelInteractive );
  860. // Shutdown blocks must be determined and vetoed as early as possible
  861. if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
  862. && IsContentModified() )
  863. {
  864. return false;
  865. }
  866. if( Kiface().IsSingle() )
  867. {
  868. auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
  869. if( symbolEditor && !symbolEditor->Close() ) // Can close symbol editor?
  870. return false;
  871. auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
  872. if( symbolViewer && !symbolViewer->Close() ) // Can close symbol viewer?
  873. return false;
  874. // SYMBOL_CHOOSER_FRAME is always modal so this shouldn't come up, but better safe than
  875. // sorry.
  876. auto* chooser = (SYMBOL_CHOOSER_FRAME*) Kiway().Player( FRAME_SYMBOL_CHOOSER, false );
  877. if( chooser && !chooser->Close() ) // Can close symbol chooser?
  878. return false;
  879. }
  880. else
  881. {
  882. auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
  883. if( symbolEditor && symbolEditor->IsSymbolFromSchematic() )
  884. {
  885. if( !symbolEditor->CanCloseSymbolFromSchematic( true ) )
  886. return false;
  887. }
  888. }
  889. if( !Kiway().PlayerClose( FRAME_SIMULATOR, false ) ) // Can close the simulator?
  890. return false;
  891. if( m_symbolFieldsTableDialog
  892. && !m_symbolFieldsTableDialog->Close( false ) ) // Can close the symbol fields table?
  893. {
  894. return false;
  895. }
  896. // We may have gotten multiple events; don't clean up twice
  897. if( !Schematic().IsValid() )
  898. return false;
  899. if( IsContentModified() )
  900. {
  901. wxFileName fileName = Schematic().RootScreen()->GetFileName();
  902. wxString msg = _( "Save changes to '%s' before closing?" );
  903. if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
  904. [&]() -> bool
  905. {
  906. return SaveProject();
  907. } ) )
  908. {
  909. return false;
  910. }
  911. }
  912. return true;
  913. }
  914. void SCH_EDIT_FRAME::doCloseWindow()
  915. {
  916. SCH_BASE_FRAME::doCloseWindow();
  917. SCH_SHEET_LIST sheetlist = Schematic().Hierarchy();
  918. #ifdef KICAD_IPC_API
  919. Pgm().GetApiServer().DeregisterHandler( m_apiHandler.get() );
  920. wxTheApp->Unbind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED, &SCH_EDIT_FRAME::onPluginAvailabilityChanged, this );
  921. #endif
  922. // Close modeless dialogs. They're trouble when they get destroyed after the frame.
  923. Unbind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &SCH_EDIT_FRAME::onCloseSymbolDiffDialog, this );
  924. Unbind( EDA_EVT_CLOSE_ERC_DIALOG, &SCH_EDIT_FRAME::onCloseErcDialog, this );
  925. Unbind( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, &SCH_EDIT_FRAME::onCloseSymbolFieldsTableDialog, this );
  926. m_netNavigator->Unbind( wxEVT_TREE_SEL_CHANGING, &SCH_EDIT_FRAME::onNetNavigatorSelChanging, this );
  927. m_netNavigator->Unbind( wxEVT_TREE_SEL_CHANGED, &SCH_EDIT_FRAME::onNetNavigatorSelection, this );
  928. if( m_diffSymbolDialog )
  929. {
  930. m_diffSymbolDialog->Destroy();
  931. m_diffSymbolDialog = nullptr;
  932. }
  933. if( m_ercDialog )
  934. {
  935. m_ercDialog->Destroy();
  936. m_ercDialog = nullptr;
  937. }
  938. if( m_symbolFieldsTableDialog )
  939. {
  940. m_symbolFieldsTableDialog->Destroy();
  941. m_symbolFieldsTableDialog = nullptr;
  942. }
  943. // Make sure local settings are persisted
  944. if( Prj().GetLocalSettings().ShouldAutoSave() )
  945. SaveProjectLocalSettings();
  946. delete m_toolManager;
  947. m_toolManager = nullptr;
  948. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  949. if( hierarchy_pane.IsShown() && hierarchy_pane.IsFloating() )
  950. {
  951. hierarchy_pane.Show( false );
  952. m_auimgr.Update();
  953. }
  954. SCH_SCREENS screens( Schematic().Root() );
  955. wxFileName fn;
  956. for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
  957. {
  958. fn = Prj().AbsolutePath( screen->GetFileName() );
  959. // Auto save file name is the normal file name prepended with FILEEXT::AutoSaveFilePrefix.
  960. fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() );
  961. if( fn.IsFileWritable() )
  962. wxRemoveFile( fn.GetFullPath() );
  963. }
  964. wxFileName tmpFn = Prj().GetProjectFullName();
  965. wxFileName autoSaveFileName( tmpFn.GetPath(), getAutoSaveFileName() );
  966. if( autoSaveFileName.IsFileWritable() )
  967. wxRemoveFile( autoSaveFileName.GetFullPath() );
  968. sheetlist.ClearModifyStatus();
  969. wxString fileName = Prj().AbsolutePath( Schematic().RootScreen()->GetFileName() );
  970. if( !Schematic().GetFileName().IsEmpty() && !Schematic().RootScreen()->IsEmpty() )
  971. UpdateFileHistory( fileName );
  972. Schematic().RootScreen()->Clear( true );
  973. // all sub sheets are deleted, only the main sheet is usable
  974. GetCurrentSheet().clear();
  975. // Clear view before destroying schematic as repaints depend on schematic being valid
  976. SetScreen( nullptr );
  977. Schematic().Reset();
  978. // Prevents any rogue events from continuing (i.e. search panel tries to redraw)
  979. Show( false );
  980. Destroy();
  981. }
  982. void SCH_EDIT_FRAME::FocusSearch()
  983. {
  984. m_searchPane->FocusSearch();
  985. }
  986. SEVERITY SCH_EDIT_FRAME::GetSeverity( int aErrorCode ) const
  987. {
  988. return Schematic().ErcSettings().GetSeverity( aErrorCode );
  989. }
  990. void SCH_EDIT_FRAME::OnModify()
  991. {
  992. EDA_BASE_FRAME::OnModify();
  993. if( GetScreen() )
  994. GetScreen()->SetContentModified();
  995. if( m_isClosing )
  996. return;
  997. if( GetCanvas() )
  998. GetCanvas()->Refresh();
  999. if( !GetTitle().StartsWith( wxS( "*" ) ) )
  1000. updateTitle();
  1001. }
  1002. void SCH_EDIT_FRAME::OnUpdatePCB()
  1003. {
  1004. if( Kiface().IsSingle() )
  1005. {
  1006. DisplayError( this, _( "Cannot update the PCB, because the Schematic Editor is opened"
  1007. " in stand-alone mode. In order to create/update PCBs from"
  1008. " schematics, launch the KiCad shell and create a project." ) );
  1009. return;
  1010. }
  1011. KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
  1012. wxEventBlocker blocker( this );
  1013. if( !frame )
  1014. {
  1015. wxFileName fn = Prj().GetProjectFullName();
  1016. fn.SetExt( FILEEXT::PcbFileExtension );
  1017. frame = Kiway().Player( FRAME_PCB_EDITOR, true );
  1018. // If Kiway() cannot create the Pcbnew frame, it shows a error message, and
  1019. // frame is null
  1020. if( !frame )
  1021. return;
  1022. frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
  1023. }
  1024. if( !frame->IsVisible() )
  1025. frame->Show( true );
  1026. // On Windows, Raise() does not bring the window on screen, when iconized
  1027. if( frame->IsIconized() )
  1028. frame->Iconize( false );
  1029. frame->Raise();
  1030. std::string payload;
  1031. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_PCB_UPDATE, payload, this );
  1032. }
  1033. void SCH_EDIT_FRAME::UpdateHierarchyNavigator( bool aRefreshNetNavigator, bool aClear )
  1034. {
  1035. m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CleanHistory();
  1036. m_hierarchy->UpdateHierarchyTree( aClear );
  1037. if( aRefreshNetNavigator )
  1038. RefreshNetNavigator();
  1039. }
  1040. void SCH_EDIT_FRAME::UpdateLabelsHierarchyNavigator()
  1041. {
  1042. // Update only the hierarchy navigation tree labels.
  1043. // The tree list is expected to be up to date
  1044. m_hierarchy->UpdateLabelsHierarchyTree();
  1045. }
  1046. void SCH_EDIT_FRAME::UpdateHierarchySelection()
  1047. {
  1048. m_hierarchy->UpdateHierarchySelection();
  1049. }
  1050. void SCH_EDIT_FRAME::OnLoadFile( wxCommandEvent& event )
  1051. {
  1052. wxString fn = GetFileFromHistory( event.GetId(), _( "Schematic" ) );
  1053. if( fn.size() )
  1054. OpenProjectFiles( std::vector<wxString>( 1, fn ) );
  1055. }
  1056. void SCH_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
  1057. {
  1058. ClearFileHistory();
  1059. }
  1060. void SCH_EDIT_FRAME::NewProject()
  1061. {
  1062. // Only standalone mode can directly load a new document
  1063. if( !Kiface().IsSingle() )
  1064. return;
  1065. wxString pro_dir = m_mruPath;
  1066. wxFileDialog dlg( this, _( "New Schematic" ), pro_dir, wxEmptyString,
  1067. FILEEXT::KiCadSchematicFileWildcard(), wxFD_SAVE );
  1068. if( dlg.ShowModal() != wxID_CANCEL )
  1069. {
  1070. // Enforce the extension, wxFileDialog is inept.
  1071. wxFileName create_me =
  1072. EnsureFileExtension( dlg.GetPath(), FILEEXT::KiCadSchematicFileExtension );
  1073. if( create_me.FileExists() )
  1074. {
  1075. wxString msg;
  1076. msg.Printf( _( "Schematic file '%s' already exists." ), create_me.GetFullName() );
  1077. DisplayError( this, msg );
  1078. return ;
  1079. }
  1080. // OpenProjectFiles() requires absolute
  1081. wxASSERT_MSG( create_me.IsAbsolute(), wxS( "wxFileDialog returned non-absolute path" ) );
  1082. OpenProjectFiles( std::vector<wxString>( 1, create_me.GetFullPath() ), KICTL_CREATE );
  1083. m_mruPath = create_me.GetPath();
  1084. }
  1085. }
  1086. void SCH_EDIT_FRAME::LoadProject()
  1087. {
  1088. // Only standalone mode can directly load a new document
  1089. if( !Kiface().IsSingle() )
  1090. return;
  1091. wxString pro_dir = m_mruPath;
  1092. wxString wildcards = FILEEXT::AllSchematicFilesWildcard()
  1093. + wxS( "|" ) + FILEEXT::KiCadSchematicFileWildcard()
  1094. + wxS( "|" ) + FILEEXT::LegacySchematicFileWildcard();
  1095. wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir, wxEmptyString,
  1096. wildcards, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
  1097. if( dlg.ShowModal() != wxID_CANCEL )
  1098. {
  1099. OpenProjectFiles( std::vector<wxString>( 1, dlg.GetPath() ) );
  1100. m_mruPath = Prj().GetProjectPath();
  1101. }
  1102. }
  1103. void SCH_EDIT_FRAME::OnOpenPcbnew()
  1104. {
  1105. wxFileName kicad_board = Prj().AbsolutePath( Schematic().GetFileName() );
  1106. if( kicad_board.IsOk() && !Schematic().GetFileName().IsEmpty() )
  1107. {
  1108. kicad_board.SetExt( FILEEXT::PcbFileExtension );
  1109. wxFileName legacy_board( kicad_board );
  1110. legacy_board.SetExt( FILEEXT::LegacyPcbFileExtension );
  1111. wxFileName& boardfn = legacy_board;
  1112. if( !legacy_board.FileExists() || kicad_board.FileExists() )
  1113. boardfn = kicad_board;
  1114. if( Kiface().IsSingle() )
  1115. {
  1116. ExecuteFile( PCBNEW_EXE, boardfn.GetFullPath() );
  1117. }
  1118. else
  1119. {
  1120. wxEventBlocker blocker(this);
  1121. KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
  1122. if( !frame )
  1123. {
  1124. frame = Kiway().Player( FRAME_PCB_EDITOR, true );
  1125. // frame can be null if Cvpcb cannot be run. No need to show a warning
  1126. // Kiway() generates the error messages
  1127. if( !frame )
  1128. return;
  1129. frame->OpenProjectFiles( std::vector<wxString>( 1, boardfn.GetFullPath() ) );
  1130. }
  1131. if( !frame->IsVisible() )
  1132. frame->Show( true );
  1133. // On Windows, Raise() does not bring the window on screen, when iconized
  1134. if( frame->IsIconized() )
  1135. frame->Iconize( false );
  1136. frame->Raise();
  1137. }
  1138. }
  1139. else
  1140. {
  1141. ExecuteFile( PCBNEW_EXE );
  1142. }
  1143. }
  1144. void SCH_EDIT_FRAME::OnOpenCvpcb()
  1145. {
  1146. wxFileName fn = Prj().AbsolutePath( Schematic().GetFileName() );
  1147. fn.SetExt( FILEEXT::NetlistFileExtension );
  1148. if( !ReadyToNetlist( _( "Assigning footprints requires a fully annotated schematic." ) ) )
  1149. return;
  1150. try
  1151. {
  1152. KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already.
  1153. if( !player )
  1154. {
  1155. player = Kiway().Player( FRAME_CVPCB, true );
  1156. // player can be null if Cvpcb cannot be run. No need to show a warning
  1157. // Kiway() generates the error messages
  1158. if( !player )
  1159. return;
  1160. player->Show( true );
  1161. }
  1162. // Ensure the netlist (mainly info about symbols) is up to date
  1163. RecalculateConnections( nullptr, GLOBAL_CLEANUP );
  1164. sendNetlistToCvpcb();
  1165. player->Raise();
  1166. }
  1167. catch( const IO_ERROR& )
  1168. {
  1169. DisplayError( this, _( "Could not open CvPcb" ) );
  1170. }
  1171. }
  1172. void SCH_EDIT_FRAME::OnExit( wxCommandEvent& event )
  1173. {
  1174. if( event.GetId() == wxID_EXIT )
  1175. Kiway().OnKiCadExit();
  1176. if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
  1177. Close( false );
  1178. }
  1179. void SCH_EDIT_FRAME::RefreshOperatingPointDisplay()
  1180. {
  1181. SCHEMATIC_SETTINGS& settings = m_schematic->Settings();
  1182. SIM_LIB_MGR simLibMgr( &Prj() );
  1183. NULL_REPORTER devnull;
  1184. // Patch for bug early in V7.99 dev
  1185. if( settings.m_OPO_VRange.EndsWith( 'A' ) )
  1186. settings.m_OPO_VRange[ settings.m_OPO_VRange.Length() - 1 ] = 'V';
  1187. // Update items which may have ${OP} text variables
  1188. //
  1189. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  1190. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  1191. {
  1192. int flags = 0;
  1193. auto invalidateTextVars =
  1194. [&flags]( EDA_TEXT* text )
  1195. {
  1196. if( text->HasTextVars() )
  1197. {
  1198. text->ClearRenderCache();
  1199. text->ClearBoundingBoxCache();
  1200. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1201. }
  1202. };
  1203. if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
  1204. {
  1205. item->RunOnChildren(
  1206. [&invalidateTextVars]( SCH_ITEM* aChild )
  1207. {
  1208. if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild ) )
  1209. invalidateTextVars( text );
  1210. },
  1211. RECURSE_MODE::NO_RECURSE );
  1212. }
  1213. if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
  1214. invalidateTextVars( text );
  1215. return flags;
  1216. } );
  1217. // Update OP overlay items
  1218. //
  1219. for( SCH_ITEM* item : GetScreen()->Items() )
  1220. {
  1221. if( GetCurrentSheet().GetExcludedFromSim() )
  1222. continue;
  1223. if( item->Type() == SCH_LINE_T )
  1224. {
  1225. SCH_LINE* line = static_cast<SCH_LINE*>( item );
  1226. if( !line->GetOperatingPoint().IsEmpty() )
  1227. GetCanvas()->GetView()->Update( line );
  1228. line->SetOperatingPoint( wxEmptyString );
  1229. // update value from netlist, below
  1230. }
  1231. else if( item->Type() == SCH_SYMBOL_T )
  1232. {
  1233. SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
  1234. wxString ref = symbol->GetRef( &GetCurrentSheet() );
  1235. std::vector<SCH_PIN*> pins = symbol->GetPins( &GetCurrentSheet() );
  1236. // Power symbols and other symbols which have the reference starting with "#" are
  1237. // not included in simulation
  1238. if( ref.StartsWith( '#' ) || symbol->ResolveExcludedFromSim() )
  1239. continue;
  1240. for( SCH_PIN* pin : pins )
  1241. {
  1242. if( !pin->GetOperatingPoint().IsEmpty() )
  1243. GetCanvas()->GetView()->Update( pin );
  1244. pin->SetOperatingPoint( wxEmptyString );
  1245. }
  1246. if( pins.size() == 2 )
  1247. {
  1248. wxString op = m_schematic->GetOperatingPoint( ref, settings.m_OPO_IPrecision,
  1249. settings.m_OPO_IRange );
  1250. if( !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
  1251. {
  1252. pins[0]->SetOperatingPoint( op );
  1253. GetCanvas()->GetView()->Update( symbol );
  1254. }
  1255. }
  1256. else
  1257. {
  1258. std::vector<EMBEDDED_FILES*> embeddedFilesStack;
  1259. embeddedFilesStack.push_back( m_schematic->GetEmbeddedFiles() );
  1260. if( EMBEDDED_FILES* symbolEmbeddedFiles = symbol->GetEmbeddedFiles() )
  1261. embeddedFilesStack.push_back( symbolEmbeddedFiles );
  1262. simLibMgr.SetFilesStack( std::move( embeddedFilesStack ) );
  1263. SIM_MODEL& model = simLibMgr.CreateModel( &GetCurrentSheet(), *symbol, true, 0, devnull ).model;
  1264. SPICE_ITEM spiceItem;
  1265. spiceItem.refName = ref;
  1266. ref = model.SpiceGenerator().ItemName( spiceItem );
  1267. for( const auto& modelPin : model.GetPins() )
  1268. {
  1269. SCH_PIN* symbolPin = symbol->GetPin( modelPin.get().symbolPinNumber );
  1270. wxString signalName = ref + wxS( ":" ) + modelPin.get().modelPinName;
  1271. wxString op = m_schematic->GetOperatingPoint( signalName,
  1272. settings.m_OPO_IPrecision,
  1273. settings.m_OPO_IRange );
  1274. if( symbolPin && !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
  1275. {
  1276. symbolPin->SetOperatingPoint( op );
  1277. GetCanvas()->GetView()->Update( symbol );
  1278. }
  1279. }
  1280. }
  1281. }
  1282. }
  1283. for( const auto& [ key, subgraphList ] : m_schematic->m_connectionGraph->GetNetMap() )
  1284. {
  1285. wxString op = m_schematic->GetOperatingPoint( key.Name, settings.m_OPO_VPrecision,
  1286. settings.m_OPO_VRange );
  1287. if( !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
  1288. {
  1289. for( CONNECTION_SUBGRAPH* subgraph : subgraphList )
  1290. {
  1291. SCH_LINE* longestWire = nullptr;
  1292. double length = 0.0;
  1293. if( subgraph->GetSheet().GetExcludedFromSim() )
  1294. continue;
  1295. for( SCH_ITEM* item : subgraph->GetItems() )
  1296. {
  1297. if( item->Type() == SCH_LINE_T )
  1298. {
  1299. SCH_LINE* line = static_cast<SCH_LINE*>( item );
  1300. if( line->IsWire() && line->GetLength() > length )
  1301. {
  1302. longestWire = line;
  1303. length = line->GetLength();
  1304. }
  1305. }
  1306. }
  1307. if( longestWire )
  1308. {
  1309. longestWire->SetOperatingPoint( op );
  1310. GetCanvas()->GetView()->Update( longestWire );
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. void SCH_EDIT_FRAME::AutoRotateItem( SCH_SCREEN* aScreen, SCH_ITEM* aItem )
  1317. {
  1318. if( aItem->Type() == SCH_GLOBAL_LABEL_T || aItem->Type() == SCH_HIER_LABEL_T )
  1319. {
  1320. SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
  1321. if( label->AutoRotateOnPlacement() )
  1322. {
  1323. SPIN_STYLE spin = aScreen->GetLabelOrientationForPoint( label->GetPosition(),
  1324. label->GetSpinStyle(),
  1325. &GetCurrentSheet() );
  1326. if( spin != label->GetSpinStyle() )
  1327. {
  1328. label->SetSpinStyle( spin );
  1329. for( SCH_ITEM* item : aScreen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
  1330. {
  1331. SCH_LABEL_BASE* otherLabel = static_cast<SCH_LABEL_BASE*>( item );
  1332. if( otherLabel != label && otherLabel->GetText() == label->GetText() )
  1333. otherLabel->AutoplaceFields( aScreen, AUTOPLACE_AUTO );
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. void SCH_EDIT_FRAME::updateTitle()
  1340. {
  1341. SCH_SCREEN* screen = GetScreen();
  1342. wxCHECK( screen, /* void */ );
  1343. wxString title;
  1344. if( !screen->GetFileName().IsEmpty() )
  1345. {
  1346. wxFileName fn( Prj().AbsolutePath( screen->GetFileName() ) );
  1347. bool readOnly = false;
  1348. bool unsaved = false;
  1349. if( fn.IsOk() && screen->FileExists() )
  1350. readOnly = screen->IsReadOnly();
  1351. else
  1352. unsaved = true;
  1353. if( IsContentModified() )
  1354. title = wxT( "*" );
  1355. title += fn.GetName();
  1356. wxString sheetPath = GetCurrentSheet().PathHumanReadable( false, true );
  1357. if( sheetPath != title )
  1358. title += wxString::Format( wxT( " [%s]" ), sheetPath );
  1359. if( readOnly )
  1360. title += wxS( " " ) + _( "[Read Only]" );
  1361. if( unsaved )
  1362. title += wxS( " " ) + _( "[Unsaved]" );
  1363. }
  1364. else
  1365. {
  1366. title = _( "[no schematic loaded]" );
  1367. }
  1368. title += wxT( " \u2014 " ) + _( "Schematic Editor" );
  1369. SetTitle( title );
  1370. }
  1371. void SCH_EDIT_FRAME::initScreenZoom()
  1372. {
  1373. m_toolManager->RunAction( ACTIONS::zoomFitScreen );
  1374. GetScreen()->m_zoomInitialized = true;
  1375. }
  1376. void SCH_EDIT_FRAME::RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
  1377. PROGRESS_REPORTER* aProgressReporter )
  1378. {
  1379. wxString highlightedConn = GetHighlightedConnection();
  1380. bool hasHighlightedConn = !highlightedConn.IsEmpty();
  1381. std::function<void( SCH_ITEM* )> changeHandler =
  1382. [&]( SCH_ITEM* aChangedItem ) -> void
  1383. {
  1384. GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
  1385. SCH_CONNECTION* connection = aChangedItem->Connection();
  1386. if( m_highlightedConnChanged )
  1387. return;
  1388. if( !hasHighlightedConn )
  1389. {
  1390. // No highlighted connection, but connectivity has changed, so refresh
  1391. // the list of all nets
  1392. m_highlightedConnChanged = true;
  1393. }
  1394. else if( connection
  1395. && ( connection->Name() == highlightedConn
  1396. || connection->HasDriverChanged() ) )
  1397. {
  1398. m_highlightedConnChanged = true;
  1399. }
  1400. };
  1401. Schematic().RecalculateConnections( aCommit, aCleanupFlags,
  1402. m_toolManager,
  1403. aProgressReporter,
  1404. GetCanvas()->GetView(),
  1405. &changeHandler,
  1406. m_undoList.m_CommandsList.empty() ? nullptr
  1407. : m_undoList.m_CommandsList.back() );
  1408. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  1409. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  1410. {
  1411. int flags = 0;
  1412. SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem );
  1413. SCH_CONNECTION* connection = item ? item->Connection() : nullptr;
  1414. auto invalidateTextVars =
  1415. [&flags]( EDA_TEXT* text )
  1416. {
  1417. if( text->HasTextVars() )
  1418. {
  1419. text->ClearRenderCache();
  1420. text->ClearBoundingBoxCache();
  1421. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1422. }
  1423. };
  1424. if( connection && connection->HasDriverChanged() )
  1425. {
  1426. connection->ClearDriverChanged();
  1427. flags |= KIGFX::REPAINT;
  1428. }
  1429. if( item )
  1430. {
  1431. item->RunOnChildren(
  1432. [&invalidateTextVars]( SCH_ITEM* aChild )
  1433. {
  1434. if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild ) )
  1435. invalidateTextVars( text );
  1436. },
  1437. RECURSE_MODE::NO_RECURSE );
  1438. if( flags & KIGFX::GEOMETRY )
  1439. GetScreen()->Update( item, false ); // Refresh RTree
  1440. }
  1441. if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
  1442. invalidateTextVars( text );
  1443. return flags;
  1444. } );
  1445. if( m_highlightedConnChanged
  1446. || !Schematic().ConnectionGraph()->FindFirstSubgraphByName( highlightedConn ) )
  1447. {
  1448. GetToolManager()->RunAction( SCH_ACTIONS::updateNetHighlighting );
  1449. RefreshNetNavigator();
  1450. m_highlightedConnChanged = false;
  1451. }
  1452. }
  1453. void SCH_EDIT_FRAME::RecomputeIntersheetRefs()
  1454. {
  1455. Schematic().RecomputeIntersheetRefs();
  1456. }
  1457. void SCH_EDIT_FRAME::IntersheetRefUpdate( SCH_GLOBALLABEL* aItem )
  1458. {
  1459. GetCanvas()->GetView()->Update( aItem );
  1460. }
  1461. void SCH_EDIT_FRAME::ShowAllIntersheetRefs( bool aShow )
  1462. {
  1463. RecomputeIntersheetRefs();
  1464. GetCanvas()->GetView()->SetLayerVisible( LAYER_INTERSHEET_REFS, aShow );
  1465. }
  1466. std::unique_ptr<GRID_HELPER> SCH_EDIT_FRAME::MakeGridHelper()
  1467. {
  1468. return std::make_unique<EE_GRID_HELPER>( m_toolManager );
  1469. }
  1470. void SCH_EDIT_FRAME::CommonSettingsChanged( int aFlags )
  1471. {
  1472. SCH_BASE_FRAME::CommonSettingsChanged( aFlags );
  1473. SCHEMATIC_SETTINGS& settings = Schematic().Settings();
  1474. settings.m_JunctionSize = GetSchematicJunctionSize();
  1475. settings.m_HopOverScale = GetSchematicHopOverScale();
  1476. ShowAllIntersheetRefs( settings.m_IntersheetRefsShow );
  1477. if( EESCHEMA_SETTINGS* cfg = GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" ) )
  1478. {
  1479. GetGalDisplayOptions().ReadWindowSettings( cfg->m_Window );
  1480. GetRenderSettings()->SetDefaultFont( cfg->m_Appearance.default_font );
  1481. KIGFX::VIEW* view = GetCanvas()->GetView();
  1482. view->SetLayerVisible( LAYER_ERC_ERR, cfg->m_Appearance.show_erc_errors );
  1483. view->SetLayerVisible( LAYER_ERC_WARN, cfg->m_Appearance.show_erc_warnings );
  1484. view->SetLayerVisible( LAYER_ERC_EXCLUSION, cfg->m_Appearance.show_erc_exclusions );
  1485. view->SetLayerVisible( LAYER_OP_VOLTAGES, cfg->m_Appearance.show_op_voltages );
  1486. view->SetLayerVisible( LAYER_OP_CURRENTS, cfg->m_Appearance.show_op_currents );
  1487. GetRenderSettings()->m_ShowPinAltIcons = cfg->m_Appearance.show_pin_alt_icons;
  1488. RefreshOperatingPointDisplay();
  1489. settings.m_TemplateFieldNames.DeleteAllFieldNameTemplates( true /* global */ );
  1490. if( !cfg->m_Drawing.field_names.IsEmpty() )
  1491. settings.m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names );
  1492. }
  1493. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  1494. for( SCH_ITEM* item : screen->Items() )
  1495. {
  1496. item->ClearCaches();
  1497. if( item->Type() == SCH_LINE_T )
  1498. {
  1499. SCH_LINE* line = static_cast<SCH_LINE*>( item );
  1500. if( line->IsWire() )
  1501. UpdateHopOveredWires( line );
  1502. }
  1503. }
  1504. for( const auto& [ libItemName, libSymbol ] : screen->GetLibSymbols() )
  1505. libSymbol->ClearCaches();
  1506. GetCanvas()->ForceRefresh();
  1507. RecreateToolbars();
  1508. Layout();
  1509. SendSizeEvent();
  1510. }
  1511. void SCH_EDIT_FRAME::OnPageSettingsChange()
  1512. {
  1513. // Store the current zoom level into the current screen before calling
  1514. // DisplayCurrentSheet() that set the zoom to GetScreen()->m_LastZoomLevel
  1515. GetScreen()->m_LastZoomLevel = GetCanvas()->GetView()->GetScale();
  1516. // Rebuild the sheet view (draw area and any other items):
  1517. DisplayCurrentSheet();
  1518. }
  1519. void SCH_EDIT_FRAME::ShowChangedLanguage()
  1520. {
  1521. // call my base class
  1522. SCH_BASE_FRAME::ShowChangedLanguage();
  1523. // tooltips in toolbars
  1524. RecreateToolbars();
  1525. // For some obscure reason, the AUI manager hides the first modified pane.
  1526. // So force show panes
  1527. wxAuiPaneInfo& design_blocks_pane_info = m_auimgr.GetPane( m_designBlocksPane );
  1528. bool panel_shown = design_blocks_pane_info.IsShown();
  1529. design_blocks_pane_info.Caption( _( "Design Blocks" ) );
  1530. design_blocks_pane_info.Show( panel_shown );
  1531. m_auimgr.GetPane( m_hierarchy ).Caption( _( "Schematic Hierarchy" ) );
  1532. m_auimgr.GetPane( m_selectionFilterPanel ).Caption( _( "Selection Filter" ) );
  1533. m_auimgr.GetPane( m_propertiesPanel ).Caption( _( "Properties" ) );
  1534. m_auimgr.GetPane( m_designBlocksPane ).Caption( _( "Design Blocks" ) );
  1535. m_auimgr.Update();
  1536. m_hierarchy->UpdateHierarchyTree();
  1537. // status bar
  1538. UpdateMsgPanel();
  1539. updateTitle();
  1540. // This ugly hack is to fix an option(left) toolbar update bug that seems to only affect
  1541. // windows. See https://bugs.launchpad.net/kicad/+bug/1816492. For some reason, calling
  1542. // wxWindow::Refresh() does not resolve the issue. Only a resize event seems to force the
  1543. // toolbar to update correctly.
  1544. #if defined( __WXMSW__ )
  1545. PostSizeEvent();
  1546. #endif
  1547. }
  1548. void SCH_EDIT_FRAME::UpdateNetHighlightStatus()
  1549. {
  1550. if( !GetHighlightedConnection().IsEmpty() )
  1551. {
  1552. SetStatusText( wxString::Format( _( "Highlighted net: %s" ),
  1553. UnescapeString( GetHighlightedConnection() ) ) );
  1554. }
  1555. else
  1556. {
  1557. SetStatusText( wxT( "" ) );
  1558. }
  1559. }
  1560. void SCH_EDIT_FRAME::SetScreen( BASE_SCREEN* aScreen )
  1561. {
  1562. if( m_toolManager )
  1563. m_toolManager->RunAction( ACTIONS::selectionClear );
  1564. SCH_BASE_FRAME::SetScreen( aScreen );
  1565. GetCanvas()->DisplaySheet( static_cast<SCH_SCREEN*>( aScreen ) );
  1566. if( m_toolManager )
  1567. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  1568. }
  1569. const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
  1570. {
  1571. BOX2I bBoxDoc;
  1572. if( aIncludeAllVisible )
  1573. {
  1574. // Get the whole page size and return that
  1575. int sizeX = GetScreen()->GetPageSettings().GetWidthIU( schIUScale.IU_PER_MILS );
  1576. int sizeY = GetScreen()->GetPageSettings().GetHeightIU( schIUScale.IU_PER_MILS );
  1577. bBoxDoc = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sizeX, sizeY ) );
  1578. }
  1579. else
  1580. {
  1581. // Get current drawing-sheet in a form we can compare to an EDA_ITEM
  1582. DS_PROXY_VIEW_ITEM* ds = SCH_BASE_FRAME::GetCanvas()->GetView()->GetDrawingSheet();
  1583. EDA_ITEM* dsAsItem = static_cast<EDA_ITEM*>( ds );
  1584. // Calc the bounding box of all items on screen except the page border
  1585. for( EDA_ITEM* item : GetScreen()->Items() )
  1586. {
  1587. if( item != dsAsItem ) // Ignore the drawing-sheet itself
  1588. bBoxDoc.Merge( item->GetBoundingBox() );
  1589. }
  1590. }
  1591. return bBoxDoc;
  1592. }
  1593. bool SCH_EDIT_FRAME::IsContentModified() const
  1594. {
  1595. return Schematic().Hierarchy().IsModified();
  1596. }
  1597. bool SCH_EDIT_FRAME::GetShowAllPins() const
  1598. {
  1599. EESCHEMA_SETTINGS* cfg = eeconfig();
  1600. return cfg && cfg->m_Appearance.show_hidden_pins;
  1601. }
  1602. void SCH_EDIT_FRAME::FocusOnItem( EDA_ITEM* aItem, bool aAllowScroll )
  1603. {
  1604. // nullptr will clear the current focus
  1605. if( aItem != nullptr && !aItem->IsSCH_ITEM() )
  1606. return;
  1607. static KIID lastBrightenedItemID( niluuid );
  1608. SCH_ITEM* lastItem = Schematic().ResolveItem( lastBrightenedItemID, nullptr, true );
  1609. if( lastItem && lastItem != aItem )
  1610. {
  1611. lastItem->ClearBrightened();
  1612. UpdateItem( lastItem );
  1613. lastBrightenedItemID = niluuid;
  1614. }
  1615. if( aItem )
  1616. {
  1617. if( !aItem->IsBrightened() )
  1618. {
  1619. aItem->SetBrightened();
  1620. UpdateItem( aItem );
  1621. lastBrightenedItemID = aItem->m_Uuid;
  1622. }
  1623. FocusOnLocation( aItem->GetFocusPosition(), aAllowScroll );
  1624. }
  1625. }
  1626. wxString SCH_EDIT_FRAME::GetCurrentFileName() const
  1627. {
  1628. return Schematic().GetFileName();
  1629. }
  1630. SELECTION& SCH_EDIT_FRAME::GetCurrentSelection()
  1631. {
  1632. return m_toolManager->GetTool<SCH_SELECTION_TOOL>()->GetSelection();
  1633. }
  1634. void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
  1635. {
  1636. if( IsShown() )
  1637. {
  1638. // We only need this until the frame is done resizing and the final client size is
  1639. // established.
  1640. Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
  1641. GetToolManager()->RunAction( ACTIONS::zoomFitScreen );
  1642. }
  1643. // Skip() is called in the base class.
  1644. EDA_DRAW_FRAME::OnSize( aEvent );
  1645. }
  1646. void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol,
  1647. const KIID& aSchematicSymbolUUID )
  1648. {
  1649. SCH_SHEET_PATH principalPath;
  1650. SCH_SHEET_LIST sheets = Schematic().Hierarchy();
  1651. SCH_ITEM* item = sheets.ResolveItem( aSchematicSymbolUUID, &principalPath, true );
  1652. SCH_SYMBOL* principalSymbol = dynamic_cast<SCH_SYMBOL*>( item );
  1653. SCH_COMMIT commit( m_toolManager );
  1654. if( !principalSymbol )
  1655. return;
  1656. wxString principalRef;
  1657. if( principalSymbol->IsAnnotated( &principalPath ) )
  1658. principalRef = principalSymbol->GetRef( &principalPath, false );
  1659. std::vector< std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> > allUnits;
  1660. for( const SCH_SHEET_PATH& path : sheets )
  1661. {
  1662. for( SCH_ITEM* candidate : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
  1663. {
  1664. SCH_SYMBOL* candidateSymbol = static_cast<SCH_SYMBOL*>( candidate );
  1665. if( candidateSymbol == principalSymbol
  1666. || ( candidateSymbol->IsAnnotated( &path )
  1667. && candidateSymbol->GetRef( &path, false ) == principalRef ) )
  1668. {
  1669. allUnits.emplace_back( candidateSymbol, path );
  1670. }
  1671. }
  1672. }
  1673. for( auto& [ unit, path ] : allUnits )
  1674. {
  1675. // This needs to be done before the LIB_SYMBOL is changed to prevent stale
  1676. // library symbols in the schematic file.
  1677. path.LastScreen()->Remove( unit );
  1678. if( !unit->IsNew() )
  1679. commit.Modify( unit, path.LastScreen() );
  1680. unit->SetLibSymbol( aSymbol.Flatten().release() );
  1681. unit->UpdateFields( &GetCurrentSheet(),
  1682. true, /* update style */
  1683. true, /* update ref */
  1684. true, /* update other fields */
  1685. false, /* reset ref */
  1686. false /* reset other fields */ );
  1687. path.LastScreen()->Append( unit );
  1688. GetCanvas()->GetView()->Update( unit );
  1689. }
  1690. // Clear any orphaned alternate pins.
  1691. for( SCH_PIN* pin : principalSymbol->GetPins() )
  1692. {
  1693. wxString altName = pin->GetAlt();
  1694. if( altName.IsEmpty() )
  1695. continue;
  1696. if( pin->GetAlternates().count( altName ) == 0 )
  1697. pin->SetAlt( wxEmptyString );
  1698. }
  1699. if( !commit.Empty() )
  1700. commit.Push( _( "Save Symbol to Schematic" ) );
  1701. }
  1702. void SCH_EDIT_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
  1703. {
  1704. SCH_BASE_FRAME::UpdateItem( aItem, isAddOrDelete, aUpdateRtree );
  1705. if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
  1706. sch_item->ClearCaches();
  1707. }
  1708. void SCH_EDIT_FRAME::DisplayCurrentSheet()
  1709. {
  1710. wxCHECK( m_toolManager, /* void */ );
  1711. m_toolManager->RunAction( ACTIONS::cancelInteractive );
  1712. m_toolManager->RunAction( ACTIONS::selectionClear );
  1713. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  1714. wxCHECK( screen, /* void */ );
  1715. m_toolManager->RunAction( ACTIONS::selectionClear );
  1716. SCH_BASE_FRAME::SetScreen( screen );
  1717. SetSheetNumberAndCount(); // will also update CurrentScreen()'s sheet number info
  1718. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  1719. // update the references, units, and intersheet-refs
  1720. GetCurrentSheet().UpdateAllScreenReferences();
  1721. // dangling state can also have changed if different units with different pin locations are
  1722. // used
  1723. GetCurrentSheet().LastScreen()->TestDanglingEnds();
  1724. RefreshOperatingPointDisplay();
  1725. SCH_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<SCH_SELECTION_TOOL>();
  1726. wxCHECK( selectionTool, /* void */ );
  1727. auto visit =
  1728. [&]( EDA_ITEM* item )
  1729. {
  1730. if( m_findReplaceDialog
  1731. && !m_findReplaceData->findString.IsEmpty()
  1732. && item->Matches( *m_findReplaceData, &GetCurrentSheet() ) )
  1733. {
  1734. item->SetForceVisible( true );
  1735. selectionTool->BrightenItem( item );
  1736. }
  1737. else if( item->IsBrightened() )
  1738. {
  1739. item->SetForceVisible( false );
  1740. selectionTool->UnbrightenItem( item );
  1741. }
  1742. };
  1743. for( SCH_ITEM* item : screen->Items() )
  1744. {
  1745. visit( item );
  1746. item->RunOnChildren(
  1747. [&]( SCH_ITEM* aChild )
  1748. {
  1749. visit( aChild );
  1750. },
  1751. RECURSE_MODE::NO_RECURSE );
  1752. }
  1753. if( !screen->m_zoomInitialized )
  1754. {
  1755. initScreenZoom();
  1756. }
  1757. else
  1758. {
  1759. // Set zoom to last used in this screen
  1760. GetCanvas()->GetView()->SetScale( GetScreen()->m_LastZoomLevel );
  1761. GetCanvas()->GetView()->SetCenter( GetScreen()->m_ScrollCenter );
  1762. }
  1763. updateTitle();
  1764. HardRedraw(); // Ensure all items are redrawn (especially the drawing-sheet items)
  1765. // Allow tools to re-add their VIEW_ITEMs after the last call to Clear in HardRedraw
  1766. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  1767. SCH_EDITOR_CONTROL* editTool = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
  1768. wxCHECK( editTool, /* void */ );
  1769. TOOL_EVENT dummy;
  1770. editTool->UpdateNetHighlighting( dummy );
  1771. m_hierarchy->UpdateHierarchySelection();
  1772. m_schematic->OnSchSheetChanged();
  1773. }
  1774. DIALOG_BOOK_REPORTER* SCH_EDIT_FRAME::GetSymbolDiffDialog()
  1775. {
  1776. if( !m_diffSymbolDialog )
  1777. {
  1778. m_diffSymbolDialog = new DIALOG_BOOK_REPORTER( this, DIFF_SYMBOLS_DIALOG_NAME,
  1779. _( "Compare Symbol with Library" ) );
  1780. m_diffSymbolDialog->m_sdbSizerApply->SetLabel( _( "Update Symbol from Library..." ) );
  1781. m_diffSymbolDialog->m_sdbSizerApply->Show();
  1782. }
  1783. return m_diffSymbolDialog;
  1784. }
  1785. void SCH_EDIT_FRAME::onCloseSymbolDiffDialog( wxCommandEvent& aEvent )
  1786. {
  1787. if( m_diffSymbolDialog && aEvent.GetString() == DIFF_SYMBOLS_DIALOG_NAME )
  1788. {
  1789. if( aEvent.GetId() == wxID_APPLY )
  1790. {
  1791. KIID symbolUUID = m_diffSymbolDialog->GetUserItemID();
  1792. CallAfter(
  1793. [this, symbolUUID]()
  1794. {
  1795. EDA_ITEM* item = ResolveItem( symbolUUID );
  1796. if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item ) )
  1797. {
  1798. m_toolManager->RunAction<EDA_ITEM*>( ACTIONS::selectItem, symbol );
  1799. DIALOG_CHANGE_SYMBOLS dlg( this, symbol, DIALOG_CHANGE_SYMBOLS::MODE::UPDATE );
  1800. dlg.ShowQuasiModal();
  1801. }
  1802. } );
  1803. }
  1804. m_diffSymbolDialog->Destroy();
  1805. m_diffSymbolDialog = nullptr;
  1806. }
  1807. }
  1808. DIALOG_ERC* SCH_EDIT_FRAME::GetErcDialog()
  1809. {
  1810. if( !m_ercDialog )
  1811. m_ercDialog = new DIALOG_ERC( this );
  1812. return m_ercDialog;
  1813. }
  1814. void SCH_EDIT_FRAME::onCloseErcDialog( wxCommandEvent& aEvent )
  1815. {
  1816. if( m_ercDialog )
  1817. {
  1818. m_ercDialog->Destroy();
  1819. m_ercDialog = nullptr;
  1820. }
  1821. }
  1822. DIALOG_SYMBOL_FIELDS_TABLE* SCH_EDIT_FRAME::GetSymbolFieldsTableDialog()
  1823. {
  1824. if( !m_symbolFieldsTableDialog )
  1825. m_symbolFieldsTableDialog = new DIALOG_SYMBOL_FIELDS_TABLE( this );
  1826. return m_symbolFieldsTableDialog;
  1827. }
  1828. void SCH_EDIT_FRAME::onCloseSymbolFieldsTableDialog( wxCommandEvent& aEvent )
  1829. {
  1830. if( m_symbolFieldsTableDialog )
  1831. {
  1832. m_symbolFieldsTableDialog->Destroy();
  1833. m_symbolFieldsTableDialog = nullptr;
  1834. }
  1835. }
  1836. void SCH_EDIT_FRAME::AddSchematicChangeListener( wxEvtHandler* aListener )
  1837. {
  1838. auto it = std::find( m_schematicChangeListeners.begin(), m_schematicChangeListeners.end(), aListener );
  1839. // Don't add duplicate listeners.
  1840. if( it == m_schematicChangeListeners.end() )
  1841. m_schematicChangeListeners.push_back( aListener );
  1842. }
  1843. void SCH_EDIT_FRAME::RemoveSchematicChangeListener( wxEvtHandler* aListener )
  1844. {
  1845. auto it = std::find( m_schematicChangeListeners.begin(), m_schematicChangeListeners.end(), aListener );
  1846. // Don't add duplicate listeners.
  1847. if( it != m_schematicChangeListeners.end() )
  1848. m_schematicChangeListeners.erase( it );
  1849. }
  1850. wxTreeCtrl* SCH_EDIT_FRAME::createHighlightedNetNavigator()
  1851. {
  1852. m_netNavigator = new wxTreeCtrl( this, wxID_ANY, wxPoint( 0, 0 ), FromDIP( wxSize( 160, 250 ) ),
  1853. wxTR_DEFAULT_STYLE | wxNO_BORDER );
  1854. return m_netNavigator;
  1855. }
  1856. void SCH_EDIT_FRAME::SetHighlightedConnection( const wxString& aConnection,
  1857. const NET_NAVIGATOR_ITEM_DATA* aSelection )
  1858. {
  1859. bool refreshNetNavigator = aConnection != m_highlightedConn;
  1860. m_highlightedConn = aConnection;
  1861. if( refreshNetNavigator )
  1862. RefreshNetNavigator( aSelection );
  1863. }
  1864. void SCH_EDIT_FRAME::unitsChangeRefresh()
  1865. {
  1866. if( m_netNavigator )
  1867. {
  1868. NET_NAVIGATOR_ITEM_DATA itemData;
  1869. wxTreeItemId selection = m_netNavigator->GetSelection();
  1870. bool refreshSelection = selection.IsOk() && ( selection != m_netNavigator->GetRootItem() );
  1871. if( refreshSelection )
  1872. {
  1873. NET_NAVIGATOR_ITEM_DATA* tmp =
  1874. dynamic_cast<NET_NAVIGATOR_ITEM_DATA*>( m_netNavigator->GetItemData( selection ) );
  1875. wxCHECK( tmp, /* void */ );
  1876. itemData = *tmp;
  1877. }
  1878. m_netNavigator->DeleteAllItems();
  1879. RefreshNetNavigator( refreshSelection ? &itemData : nullptr );
  1880. }
  1881. UpdateProperties();
  1882. }
  1883. void SCH_EDIT_FRAME::updateSelectionFilterVisbility()
  1884. {
  1885. wxAuiPaneInfo& hierarchyPane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  1886. wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
  1887. wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
  1888. wxAuiPaneInfo& selectionFilterPane = m_auimgr.GetPane( wxS( "SelectionFilter" ) );
  1889. // Don't give the selection filter its own visibility controls; instead show it if
  1890. // anything else is visible
  1891. bool showFilter = ( hierarchyPane.IsShown() && hierarchyPane.IsDocked() )
  1892. || ( netNavigatorPane.IsShown() && netNavigatorPane.IsDocked() )
  1893. || ( propertiesPane.IsShown() && propertiesPane.IsDocked() );
  1894. selectionFilterPane.Show( showFilter );
  1895. }
  1896. #ifdef KICAD_IPC_API
  1897. void SCH_EDIT_FRAME::onPluginAvailabilityChanged( wxCommandEvent& aEvt )
  1898. {
  1899. wxLogTrace( traceApi, "SCH frame: EDA_EVT_PLUGIN_AVAILABILITY_CHANGED" );
  1900. RecreateToolbars();
  1901. aEvt.Skip();
  1902. }
  1903. #endif
  1904. void SCH_EDIT_FRAME::ToggleSearch()
  1905. {
  1906. EESCHEMA_SETTINGS* cfg = eeconfig();
  1907. // Ensure m_show_search is up to date (the pane can be closed outside the menu)
  1908. m_show_search = m_auimgr.GetPane( SearchPaneName() ).IsShown();
  1909. m_show_search = !m_show_search;
  1910. wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
  1911. searchPaneInfo.Show( m_show_search );
  1912. if( m_show_search )
  1913. {
  1914. searchPaneInfo.Direction( cfg->m_AuiPanels.search_panel_dock_direction );
  1915. if( cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_TOP
  1916. || cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_BOTTOM )
  1917. {
  1918. SetAuiPaneSize( m_auimgr, searchPaneInfo, -1, cfg->m_AuiPanels.search_panel_height );
  1919. }
  1920. else if( cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_LEFT
  1921. || cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_RIGHT )
  1922. {
  1923. SetAuiPaneSize( m_auimgr, searchPaneInfo, cfg->m_AuiPanels.search_panel_width, -1 );
  1924. }
  1925. m_searchPane->FocusSearch();
  1926. m_searchPane->RefreshSearch();
  1927. }
  1928. else
  1929. {
  1930. cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
  1931. cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
  1932. cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
  1933. m_auimgr.Update();
  1934. }
  1935. }
  1936. void SCH_EDIT_FRAME::ToggleProperties()
  1937. {
  1938. if( !m_propertiesPanel )
  1939. return;
  1940. bool show = !m_propertiesPanel->IsShownOnScreen();
  1941. wxAuiPaneInfo& propertiesPaneInfo = m_auimgr.GetPane( PropertiesPaneName() );
  1942. propertiesPaneInfo.Show( show );
  1943. updateSelectionFilterVisbility();
  1944. EESCHEMA_SETTINGS* settings = eeconfig();
  1945. if( show )
  1946. {
  1947. SetAuiPaneSize( m_auimgr, propertiesPaneInfo,
  1948. settings->m_AuiPanels.properties_panel_width, -1 );
  1949. }
  1950. else
  1951. {
  1952. settings->m_AuiPanels.properties_panel_width = m_propertiesPanel->GetSize().x;
  1953. m_auimgr.Update();
  1954. }
  1955. }
  1956. void SCH_EDIT_FRAME::ToggleSchematicHierarchy()
  1957. {
  1958. EESCHEMA_SETTINGS* cfg = eeconfig();
  1959. wxCHECK( cfg, /* void */ );
  1960. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  1961. hierarchy_pane.Show( !hierarchy_pane.IsShown() );
  1962. updateSelectionFilterVisbility();
  1963. if( hierarchy_pane.IsShown() )
  1964. {
  1965. if( hierarchy_pane.IsFloating() )
  1966. {
  1967. hierarchy_pane.FloatingSize( cfg->m_AuiPanels.hierarchy_panel_float_width,
  1968. cfg->m_AuiPanels.hierarchy_panel_float_height );
  1969. m_auimgr.Update();
  1970. }
  1971. else if( cfg->m_AuiPanels.hierarchy_panel_docked_width > 0 )
  1972. {
  1973. // SetAuiPaneSize also updates m_auimgr
  1974. SetAuiPaneSize( m_auimgr, hierarchy_pane,
  1975. cfg->m_AuiPanels.hierarchy_panel_docked_width, -1 );
  1976. }
  1977. }
  1978. else
  1979. {
  1980. if( hierarchy_pane.IsFloating() )
  1981. {
  1982. cfg->m_AuiPanels.hierarchy_panel_float_width = hierarchy_pane.floating_size.x;
  1983. cfg->m_AuiPanels.hierarchy_panel_float_height = hierarchy_pane.floating_size.y;
  1984. }
  1985. else
  1986. {
  1987. cfg->m_AuiPanels.hierarchy_panel_docked_width = m_hierarchy->GetSize().x;
  1988. }
  1989. m_auimgr.Update();
  1990. }
  1991. }
  1992. void SCH_EDIT_FRAME::ToggleLibraryTree()
  1993. {
  1994. EESCHEMA_SETTINGS* cfg = eeconfig();
  1995. wxCHECK( cfg, /* void */ );
  1996. wxAuiPaneInfo& db_library_pane = m_auimgr.GetPane( DesignBlocksPaneName() );
  1997. db_library_pane.Show( !db_library_pane.IsShown() );
  1998. if( db_library_pane.IsShown() )
  1999. {
  2000. if( db_library_pane.IsFloating() )
  2001. {
  2002. db_library_pane.FloatingSize( cfg->m_AuiPanels.design_blocks_panel_float_width,
  2003. cfg->m_AuiPanels.design_blocks_panel_float_height );
  2004. m_auimgr.Update();
  2005. }
  2006. else if( cfg->m_AuiPanels.design_blocks_panel_docked_width > 0 )
  2007. {
  2008. // SetAuiPaneSize also updates m_auimgr
  2009. SetAuiPaneSize( m_auimgr, db_library_pane,
  2010. cfg->m_AuiPanels.design_blocks_panel_docked_width, -1 );
  2011. }
  2012. }
  2013. else
  2014. {
  2015. if( db_library_pane.IsFloating() )
  2016. {
  2017. cfg->m_AuiPanels.design_blocks_panel_float_width = db_library_pane.floating_size.x;
  2018. cfg->m_AuiPanels.design_blocks_panel_float_height = db_library_pane.floating_size.y;
  2019. }
  2020. else
  2021. {
  2022. cfg->m_AuiPanels.design_blocks_panel_docked_width = m_designBlocksPane->GetSize().x;
  2023. }
  2024. m_auimgr.Update();
  2025. }
  2026. }
  2027. void SCH_EDIT_FRAME::SetSchematic( SCHEMATIC* aSchematic )
  2028. {
  2029. wxCHECK( aSchematic, /* void */ );
  2030. if( m_schematic )
  2031. m_schematic->SetProject( nullptr );
  2032. aSchematic->SetProject( &Prj() );
  2033. delete m_schematic;
  2034. m_schematic = aSchematic;
  2035. m_schematic->SetSchematicHolder( this );
  2036. KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
  2037. static_cast<KIGFX::SCH_PAINTER*>( view->GetPainter() )->SetSchematic( m_schematic );
  2038. m_toolManager->SetEnvironment( m_schematic, GetCanvas()->GetView(), GetCanvas()->GetViewControls(), config(),
  2039. this );
  2040. }