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.

1886 lines
59 KiB

5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
Mark null project initial screen as zoom-initialized The variable `m_Initialized` in `BASE_SCREEN` is used by `SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized by the "zoom to fit screen" action. When this variable is `false`, the function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit screen", modifying the zoom level. This function is indirectly called in the undo routines, so if `m_Initialized` is not set to `true`, a zoom change will occur when the user undoes an operation, a behavior that is undesired. `m_Initialized` was not initialized to `true` for the null schematic (the schematic that is loaded if no project is loaded), causing the aforementioned undesired behavior. To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set `m_Initialized` to `true`, since it zooms to fit screen already. I've moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used only in Eeschema, and renamed it to `m_zoomInitialized`, a name I believe that better describes what this variable does. I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to group the "zoom to fit screen" action with setting `m_Initialized` to `true`, as they often should occur together. I'd also like to say that I'm not confident whether `SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level initialization at this point, but I have decided to not change this behavior for now, as the commit history suggests it's several years old. Fixes https://gitlab.com/kicad/code/kicad/issues/7343
5 years ago
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
5 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
4 years ago
3 years ago
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
Make the new schematic and symbol library file formats the default. This is a very large and potentially disruptive change so this will be an unusually long and detailed commit message. The new file formats are now the default in both the schematic and symbol library editors. Existing symbol libraries will be saved in their current format until new features are added to library symbols. Once this happens, both the legacy schematic and symbol file formats will be no longer be savable and existing libraries will have to be converted. Saving to the legacy file formats is still available for round robin testing and should not be used for normal editing. When loading the legacy schematic file, it is imperative that the schematic library symbols are rescued and/or remapped to valid library identifiers. Otherwise, there will be no way to link to the original library symbol and the user will be required manually set the library identifier. The cached symbol will be saved in the schematic file so the last library symbol in the cache will still be used but there will be no way to update it from the original library. The next save after loading a legacy schematic file will be converted to the s-expression file format. Schematics with hierarchical sheets will automatically have all sheet file name extensions changed to .kicad_sym and saved to the new format as well. Appending schematics requires that the schematic to append has already been converted to the new file format. This is required to ensure that library symbols are guaranteed to be valid for the appended schematic. The schematic symbol library symbol link resolution has been moved out of the SCH_COMPONENT object and move into the SCH_SCREEN object that owns the symbol. This was done to ensure that there is a single place where the library symbol links get resolved rather than the dozen or so different code paths that previously existed. It also removes the necessity of the SCH_COMPONENT object of requiring any knowledge of the symbol library table and/or the cache library. When opening an s-expression schematic, the legacy cache library is not loaded so any library symbols not rescued cannot be loaded. Broken library symbol links will have to be manually resolved by adding the cache library to the symbol library table and changing the links in the schematic symbol. Now that the library symbols are embedded in the schematic file, the SCH_SCREEN object maintains the list of library symbols for the schematic automatically. No external manipulation of this library cache should ever occur. ADDED: S-expression schematic and symbol library file formats.
6 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
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
Mark null project initial screen as zoom-initialized The variable `m_Initialized` in `BASE_SCREEN` is used by `SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized by the "zoom to fit screen" action. When this variable is `false`, the function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit screen", modifying the zoom level. This function is indirectly called in the undo routines, so if `m_Initialized` is not set to `true`, a zoom change will occur when the user undoes an operation, a behavior that is undesired. `m_Initialized` was not initialized to `true` for the null schematic (the schematic that is loaded if no project is loaded), causing the aforementioned undesired behavior. To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set `m_Initialized` to `true`, since it zooms to fit screen already. I've moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used only in Eeschema, and renamed it to `m_zoomInitialized`, a name I believe that better describes what this variable does. I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to group the "zoom to fit screen" action with setting `m_Initialized` to `true`, as they often should occur together. I'd also like to say that I'm not confident whether `SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level initialization at this point, but I have decided to not change this behavior for now, as the commit history suggests it's several years old. Fixes https://gitlab.com/kicad/code/kicad/issues/7343
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <base_units.h>
  25. #include <bitmaps.h>
  26. #include <symbol_library.h>
  27. #include <confirm.h>
  28. #include <connection_graph.h>
  29. #include <dialogs/dialog_schematic_find.h>
  30. #include <eeschema_id.h>
  31. #include <executable_names.h>
  32. #include <gestfich.h>
  33. #include <dialogs/html_message_box.h>
  34. #include <ignore.h>
  35. #include <invoke_sch_dialog.h>
  36. #include <string_utils.h>
  37. #include <kiface_base.h>
  38. #include <kiplatform/app.h>
  39. #include <kiway.h>
  40. #include <symbol_edit_frame.h>
  41. #include <symbol_viewer_frame.h>
  42. #include <pgm_base.h>
  43. #include <profile.h>
  44. #include <project.h>
  45. #include <project/project_file.h>
  46. #include <project/net_settings.h>
  47. #include <dialog_erc.h>
  48. #include <python_scripting.h>
  49. #include <sch_edit_frame.h>
  50. #include <sch_painter.h>
  51. #include <sch_sheet.h>
  52. #include <sch_marker.h>
  53. #include <schematic.h>
  54. #include <settings/settings_manager.h>
  55. #include <advanced_config.h>
  56. #include <sim/sim_plot_frame.h>
  57. #include <sim/spice_settings.h>
  58. #include <tool/action_manager.h>
  59. #include <tool/action_toolbar.h>
  60. #include <tool/common_control.h>
  61. #include <tool/common_tools.h>
  62. #include <tool/picker_tool.h>
  63. #include <tool/selection.h>
  64. #include <tool/tool_dispatcher.h>
  65. #include <tool/tool_manager.h>
  66. #include <tool/zoom_tool.h>
  67. #include <tools/ee_actions.h>
  68. #include <tools/ee_inspection_tool.h>
  69. #include <tools/ee_point_editor.h>
  70. #include <tools/ee_selection_tool.h>
  71. #include <tools/sch_drawing_tools.h>
  72. #include <tools/sch_edit_tool.h>
  73. #include <tools/sch_editor_conditions.h>
  74. #include <tools/sch_editor_control.h>
  75. #include <tools/sch_line_wire_bus_tool.h>
  76. #include <tools/sch_move_tool.h>
  77. #include <tools/sch_navigate_tool.h>
  78. #include <tools/sch_find_replace_tool.h>
  79. #include <view/view_controls.h>
  80. #include <widgets/wx_infobar.h>
  81. #include <widgets/hierarchy_pane.h>
  82. #include <wildcards_and_files_ext.h>
  83. #include <wx/cmdline.h>
  84. #include <wx/app.h>
  85. #include <wx/filedlg.h>
  86. #include <wx/socket.h>
  87. #include <widgets/wx_aui_utils.h>
  88. #include <gal/graphics_abstraction_layer.h>
  89. #include <drawing_sheet/ds_proxy_view_item.h>
  90. BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, SCH_BASE_FRAME )
  91. EVT_SOCKET( ID_EDA_SOCKET_EVENT_SERV, EDA_DRAW_FRAME::OnSockRequestServer )
  92. EVT_SOCKET( ID_EDA_SOCKET_EVENT, EDA_DRAW_FRAME::OnSockRequest )
  93. EVT_SIZE( SCH_EDIT_FRAME::OnSize )
  94. EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, SCH_EDIT_FRAME::OnLoadFile )
  95. EVT_MENU( ID_FILE_LIST_CLEAR, SCH_EDIT_FRAME::OnClearFileHistory )
  96. EVT_MENU( ID_APPEND_PROJECT, SCH_EDIT_FRAME::OnAppendProject )
  97. EVT_MENU( ID_IMPORT_NON_KICAD_SCH, SCH_EDIT_FRAME::OnImportProject )
  98. EVT_MENU( wxID_EXIT, SCH_EDIT_FRAME::OnExit )
  99. EVT_MENU( wxID_CLOSE, SCH_EDIT_FRAME::OnExit )
  100. EVT_MENU( ID_GRID_SETTINGS, SCH_BASE_FRAME::OnGridSettings )
  101. // Drop files event
  102. EVT_DROP_FILES( SCH_EDIT_FRAME::OnDropFiles )
  103. END_EVENT_TABLE()
  104. SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  105. SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH, wxT( "Eeschema" ), wxDefaultPosition,
  106. wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, SCH_EDIT_FRAME_NAME ),
  107. m_highlightedConn( nullptr )
  108. {
  109. m_maximizeByDefault = true;
  110. m_schematic = new SCHEMATIC( nullptr );
  111. m_showBorderAndTitleBlock = true; // true to show sheet references
  112. m_supportsAutoSave = true;
  113. m_syncingPcbToSchSelection = false;
  114. m_aboutTitle = _HKI( "KiCad Schematic Editor" );
  115. m_findReplaceDialog = nullptr;
  116. m_findReplaceData = std::make_unique<SCH_SEARCH_DATA>();
  117. // Give an icon
  118. wxIcon icon;
  119. wxIconBundle icon_bundle;
  120. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema ) );
  121. icon_bundle.AddIcon( icon );
  122. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_32 ) );
  123. icon_bundle.AddIcon( icon );
  124. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_16 ) );
  125. icon_bundle.AddIcon( icon );
  126. SetIcons( icon_bundle );
  127. LoadSettings( eeconfig() );
  128. // NB: also links the schematic to the loaded project
  129. CreateScreens();
  130. SetCurrentSheet( Schematic().GetSheets()[0] );
  131. setupTools();
  132. setupUIConditions();
  133. ReCreateMenuBar();
  134. ReCreateHToolbar();
  135. ReCreateVToolbar();
  136. ReCreateOptToolbar();
  137. m_hierarchy = new HIERARCHY_PANE( this );
  138. // Initialize common print setup dialog settings.
  139. m_pageSetupData.GetPrintData().SetPrintMode( wxPRINT_MODE_PRINTER );
  140. m_pageSetupData.GetPrintData().SetQuality( wxPRINT_QUALITY_MEDIUM );
  141. m_pageSetupData.GetPrintData().SetBin( wxPRINTBIN_AUTO );
  142. m_pageSetupData.GetPrintData().SetNoCopies( 1 );
  143. m_auimgr.SetManagedWindow( this );
  144. CreateInfoBar();
  145. // Rows; layers 4 - 6
  146. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( wxS( "MainToolbar" ) )
  147. .Top().Layer( 6 ) );
  148. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( wxS( "MsgPanel" ) )
  149. .Bottom().Layer( 6 ) );
  150. // Columns; layers 1 - 3
  151. m_auimgr.AddPane( m_hierarchy, EDA_PANE().Palette().Name( SchematicHierarchyPaneName() )
  152. .Caption( _( "Schematic Hierarchy" ) )
  153. .Left().Layer( 3 )
  154. .TopDockable( false )
  155. .BottomDockable( false )
  156. .CloseButton( true )
  157. .MinSize( 120, 60 )
  158. .BestSize( 200, 200 )
  159. .FloatingSize( 200, 200 )
  160. .Show( false ) );
  161. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( wxS( "OptToolbar" ) )
  162. .Left().Layer( 2 ) );
  163. m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( wxS( "ToolsToolbar" ) )
  164. .Right().Layer( 2 ) );
  165. // Center
  166. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( wxS( "DrawFrame" ) )
  167. .Center() );
  168. FinishAUIInitialization();
  169. resolveCanvasType();
  170. SwitchCanvas( m_canvasType );
  171. GetCanvas()->GetGAL()->SetAxesEnabled( false );
  172. KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
  173. static_cast<KIGFX::SCH_PAINTER*>( view->GetPainter() )->SetSchematic( m_schematic );
  174. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  175. EESCHEMA_SETTINGS* cfg = eeconfig();
  176. hierarchy_pane.Show( cfg->m_AuiPanels.show_schematic_hierarchy );
  177. if( cfg->m_AuiPanels.hierarchy_panel_float_width > 0
  178. && cfg->m_AuiPanels.hierarchy_panel_float_height > 0 )
  179. {
  180. // Show at end, after positioning
  181. hierarchy_pane.FloatingSize( cfg->m_AuiPanels.hierarchy_panel_float_width,
  182. cfg->m_AuiPanels.hierarchy_panel_float_height );
  183. }
  184. if( cfg->m_AuiPanels.schematic_hierarchy_float )
  185. hierarchy_pane.Float();
  186. if( cfg->m_AuiPanels.hierarchy_panel_docked_width > 0 )
  187. {
  188. SetAuiPaneSize( m_auimgr, hierarchy_pane,
  189. cfg->m_AuiPanels.hierarchy_panel_docked_width, -1 );
  190. // wxAUI hack: force width by setting MinSize() and then Fixed()
  191. // thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
  192. hierarchy_pane.MinSize( cfg->m_AuiPanels.hierarchy_panel_docked_width, -1 );
  193. hierarchy_pane.Fixed();
  194. m_auimgr.Update();
  195. // now make it resizable again
  196. hierarchy_pane.Resizable();
  197. m_auimgr.Update();
  198. // Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
  199. // back to minimum.
  200. hierarchy_pane.MinSize( 120, 60 );
  201. }
  202. else
  203. {
  204. m_auimgr.Update();
  205. }
  206. LoadProjectSettings();
  207. initScreenZoom();
  208. m_hierarchy->Connect( wxEVT_SIZE,
  209. wxSizeEventHandler( SCH_EDIT_FRAME::OnResizeHierarchyNavigator ),
  210. NULL, this );
  211. // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
  212. // to calculate the wrong zoom size. See SCH_EDIT_FRAME::onSize().
  213. Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
  214. setupUnits( eeconfig() );
  215. // Net list generator
  216. DefaultExecFlags();
  217. updateTitle();
  218. m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->ResetHistory();
  219. // Default shutdown reason until a file is loaded
  220. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New schematic file is unsaved" ) );
  221. // Init for dropping files
  222. m_acceptedExts.emplace( KiCadSchematicFileExtension, &EE_ACTIONS::ddAppendFile );
  223. DragAcceptFiles( true );
  224. // Ensure the window is on top
  225. Raise();
  226. // Now that all sizes are fixed, set the initial hierarchy_pane floating position to the
  227. // top-left corner of the canvas
  228. wxPoint canvas_pos = GetCanvas()->GetScreenPosition();
  229. hierarchy_pane.FloatingPosition( canvas_pos.x + 10, canvas_pos.y + 10 );
  230. }
  231. SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
  232. {
  233. m_hierarchy->Disconnect( wxEVT_SIZE,
  234. wxSizeEventHandler( SCH_EDIT_FRAME::OnResizeHierarchyNavigator ),
  235. NULL, this );
  236. // Ensure m_canvasType is up to date, to save it in config
  237. m_canvasType = GetCanvas()->GetBackend();
  238. // Close modeless dialogs
  239. wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME );
  240. if( open_dlg )
  241. open_dlg->Close( true );
  242. // Shutdown all running tools
  243. if( m_toolManager )
  244. {
  245. m_toolManager->ShutdownAllTools();
  246. delete m_toolManager;
  247. m_toolManager = nullptr;
  248. }
  249. SetScreen( nullptr );
  250. delete m_schematic;
  251. m_schematic = nullptr;
  252. // Close the project if we are standalone, so it gets cleaned up properly
  253. if( Kiface().IsSingle() )
  254. {
  255. try
  256. {
  257. GetSettingsManager()->UnloadProject( &Prj(), false );
  258. }
  259. catch( const nlohmann::detail::type_error& exc )
  260. {
  261. // This may be overkill and could be an assertion but we are more likely to
  262. // find any settings manager errors this way.
  263. wxLogError( wxT( "Settings exception '%s' occurred." ), exc.what() );
  264. }
  265. }
  266. delete m_hierarchy;
  267. }
  268. void SCH_EDIT_FRAME::OnResizeHierarchyNavigator( wxSizeEvent& aEvent )
  269. {
  270. aEvent.Skip();
  271. // Called when resizing the Hierarchy Navigator panel
  272. // Store the current pane size
  273. // It allows to retrieve the last defined pane size when switching between
  274. // docked and floating pane state
  275. // Note: *DO NOT* call m_auimgr.Update() here: it crashes Kicad at least on Windows
  276. EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
  277. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  278. if( cfg && m_hierarchy->IsShown() )
  279. {
  280. cfg->m_AuiPanels.hierarchy_panel_float_width = hierarchy_pane.floating_size.x;
  281. cfg->m_AuiPanels.hierarchy_panel_float_height = hierarchy_pane.floating_size.y;
  282. // initialize hierarchy_panel_docked_width and best size only if the hierarchy_pane
  283. // width is > 0 (i.e. if its size is already set and has meaning)
  284. // if it is floating, its size is not initialized (only floating_size is initialized)
  285. // initializing hierarchy_pane.best_size is useful when switching to float pane and
  286. // after switching to the docked pane, to retrieve the last docked pane width
  287. if( hierarchy_pane.rect.width > 50 ) // 50 is a good margin
  288. {
  289. cfg->m_AuiPanels.hierarchy_panel_docked_width = hierarchy_pane.rect.width;
  290. hierarchy_pane.best_size.x = hierarchy_pane.rect.width;
  291. }
  292. }
  293. }
  294. void SCH_EDIT_FRAME::setupTools()
  295. {
  296. // Create the manager and dispatcher & route draw panel events to the dispatcher
  297. m_toolManager = new TOOL_MANAGER;
  298. m_toolManager->SetEnvironment( &Schematic(), GetCanvas()->GetView(),
  299. GetCanvas()->GetViewControls(), config(), this );
  300. m_actions = new EE_ACTIONS();
  301. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  302. // Register tools
  303. m_toolManager->RegisterTool( new COMMON_CONTROL );
  304. m_toolManager->RegisterTool( new COMMON_TOOLS );
  305. m_toolManager->RegisterTool( new ZOOM_TOOL );
  306. m_toolManager->RegisterTool( new EE_SELECTION_TOOL );
  307. m_toolManager->RegisterTool( new PICKER_TOOL );
  308. m_toolManager->RegisterTool( new SCH_DRAWING_TOOLS );
  309. m_toolManager->RegisterTool( new SCH_LINE_WIRE_BUS_TOOL );
  310. m_toolManager->RegisterTool( new SCH_MOVE_TOOL );
  311. m_toolManager->RegisterTool( new SCH_EDIT_TOOL );
  312. m_toolManager->RegisterTool( new EE_INSPECTION_TOOL );
  313. m_toolManager->RegisterTool( new SCH_EDITOR_CONTROL );
  314. m_toolManager->RegisterTool( new SCH_FIND_REPLACE_TOOL );
  315. m_toolManager->RegisterTool( new EE_POINT_EDITOR );
  316. m_toolManager->RegisterTool( new SCH_NAVIGATE_TOOL );
  317. m_toolManager->InitTools();
  318. // Run the selection tool, it is supposed to be always active
  319. m_toolManager->RunAction( EE_ACTIONS::selectionActivate );
  320. GetCanvas()->SetEventDispatcher( m_toolDispatcher );
  321. }
  322. void SCH_EDIT_FRAME::setupUIConditions()
  323. {
  324. SCH_BASE_FRAME::setupUIConditions();
  325. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  326. SCH_EDITOR_CONDITIONS cond( this );
  327. wxASSERT( mgr );
  328. auto hasElements =
  329. [ this ] ( const SELECTION& aSel )
  330. {
  331. return GetScreen() &&
  332. ( !GetScreen()->Items().empty() || !SELECTION_CONDITIONS::Idle( aSel ) );
  333. };
  334. auto hierarchyNavigatorCond =
  335. [ this ] ( const SELECTION& aSel )
  336. {
  337. return m_auimgr.GetPane( SchematicHierarchyPaneName() ).IsShown();
  338. };
  339. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  340. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  341. mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  342. mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
  343. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  344. mgr->SetConditions( EE_ACTIONS::showHierarchy, CHECK( hierarchyNavigatorCond ) );
  345. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  346. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  347. mgr->SetConditions( ACTIONS::millimetersUnits,
  348. CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  349. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  350. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  351. mgr->SetConditions( EE_ACTIONS::lineModeFree, CHECK( cond.LineMode( LINE_MODE::LINE_MODE_FREE ) ) );
  352. mgr->SetConditions( EE_ACTIONS::lineMode90, CHECK( cond.LineMode( LINE_MODE::LINE_MODE_90 ) ) );
  353. mgr->SetConditions( EE_ACTIONS::lineMode45, CHECK( cond.LineMode( LINE_MODE::LINE_MODE_45 ) ) );
  354. mgr->SetConditions( ACTIONS::cut, ENABLE( hasElements ) );
  355. mgr->SetConditions( ACTIONS::copy, ENABLE( hasElements ) );
  356. mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle ) );
  357. mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle ) );
  358. mgr->SetConditions( ACTIONS::doDelete, ENABLE( hasElements ) );
  359. mgr->SetConditions( ACTIONS::duplicate, ENABLE( hasElements ) );
  360. mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) );
  361. mgr->SetConditions( EE_ACTIONS::rotateCW, ENABLE( hasElements ) );
  362. mgr->SetConditions( EE_ACTIONS::rotateCCW, ENABLE( hasElements ) );
  363. mgr->SetConditions( EE_ACTIONS::mirrorH, ENABLE( hasElements ) );
  364. mgr->SetConditions( EE_ACTIONS::mirrorV, ENABLE( hasElements ) );
  365. mgr->SetConditions( ACTIONS::zoomTool,
  366. CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  367. mgr->SetConditions( ACTIONS::selectionTool,
  368. CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  369. if( SCRIPTING::IsWxAvailable() )
  370. {
  371. mgr->SetConditions( EE_ACTIONS::showPythonConsole,
  372. CHECK( cond.ScriptingConsoleVisible() ) );
  373. }
  374. auto showHiddenPinsCond =
  375. [this]( const SELECTION& )
  376. {
  377. return GetShowAllPins();
  378. };
  379. auto showHiddenFieldsCond =
  380. [this]( const SELECTION& )
  381. {
  382. EESCHEMA_SETTINGS* cfg = eeconfig();
  383. return cfg && cfg->m_Appearance.show_hidden_fields;
  384. };
  385. auto showERCErrorsCond =
  386. [this]( const SELECTION& )
  387. {
  388. EESCHEMA_SETTINGS* cfg = eeconfig();
  389. return cfg && cfg->m_Appearance.show_erc_errors;
  390. };
  391. auto showERCWarningsCond =
  392. [this]( const SELECTION& )
  393. {
  394. EESCHEMA_SETTINGS* cfg = eeconfig();
  395. return cfg && cfg->m_Appearance.show_erc_warnings;
  396. };
  397. auto showERCExclusionsCond =
  398. [this]( const SELECTION& )
  399. {
  400. EESCHEMA_SETTINGS* cfg = eeconfig();
  401. return cfg && cfg->m_Appearance.show_erc_exclusions;
  402. };
  403. auto showAnnotateAutomaticallyCond =
  404. [this]( const SELECTION& )
  405. {
  406. EESCHEMA_SETTINGS* cfg = eeconfig();
  407. return cfg && cfg->m_AnnotatePanel.automatic;
  408. };
  409. auto remapSymbolsCondition =
  410. [&]( const SELECTION& aSel )
  411. {
  412. SCH_SCREENS schematic( Schematic().Root() );
  413. // The remapping can only be performed on legacy projects.
  414. return schematic.HasNoFullyDefinedLibIds();
  415. };
  416. auto belowRootSheetCondition =
  417. [this]( const SELECTION& aSel )
  418. {
  419. return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoUp();
  420. };
  421. auto navHistoryHasForward =
  422. [this]( const SELECTION& aSel )
  423. {
  424. return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoForward();
  425. };
  426. auto navHistoryHasBackward =
  427. [this]( const SELECTION& aSel )
  428. {
  429. return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoBack();
  430. };
  431. auto navSchematicHasPreviousSheet =
  432. [this]( const SELECTION& aSel )
  433. {
  434. return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoPrevious();
  435. };
  436. auto navSchematicHasNextSheet =
  437. [this]( const SELECTION& aSel )
  438. {
  439. return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoNext();
  440. };
  441. mgr->SetConditions( EE_ACTIONS::leaveSheet, ENABLE( belowRootSheetCondition ) );
  442. mgr->SetConditions( EE_ACTIONS::navigateUp, ENABLE( belowRootSheetCondition ) );
  443. mgr->SetConditions( EE_ACTIONS::navigateForward, ENABLE( navHistoryHasForward ) );
  444. mgr->SetConditions( EE_ACTIONS::navigateBack, ENABLE( navHistoryHasBackward ) );
  445. mgr->SetConditions( EE_ACTIONS::navigatePrevious, ENABLE( navSchematicHasPreviousSheet ) );
  446. mgr->SetConditions( EE_ACTIONS::navigateNext, ENABLE( navSchematicHasNextSheet ) );
  447. mgr->SetConditions( EE_ACTIONS::remapSymbols, ENABLE( remapSymbolsCondition ) );
  448. mgr->SetConditions( EE_ACTIONS::toggleHiddenPins, CHECK( showHiddenPinsCond ) );
  449. mgr->SetConditions( EE_ACTIONS::toggleHiddenFields, CHECK( showHiddenFieldsCond ) );
  450. mgr->SetConditions( EE_ACTIONS::toggleERCErrors, CHECK( showERCErrorsCond ) );
  451. mgr->SetConditions( EE_ACTIONS::toggleERCWarnings, CHECK( showERCWarningsCond ) );
  452. mgr->SetConditions( EE_ACTIONS::toggleERCExclusions, CHECK( showERCExclusionsCond ) );
  453. mgr->SetConditions( EE_ACTIONS::toggleAnnotateAuto, CHECK( showAnnotateAutomaticallyCond ) );
  454. mgr->SetConditions( ACTIONS::toggleBoundingBoxes, CHECK( cond.BoundingBoxes() ) );
  455. #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
  456. CURRENT_TOOL( ACTIONS::deleteTool );
  457. CURRENT_TOOL( EE_ACTIONS::highlightNetTool );
  458. CURRENT_TOOL( EE_ACTIONS::placeSymbol );
  459. CURRENT_TOOL( EE_ACTIONS::placePower );
  460. CURRENT_TOOL( EE_ACTIONS::drawWire );
  461. CURRENT_TOOL( EE_ACTIONS::drawBus );
  462. CURRENT_TOOL( EE_ACTIONS::placeBusWireEntry );
  463. CURRENT_TOOL( EE_ACTIONS::placeNoConnect );
  464. CURRENT_TOOL( EE_ACTIONS::placeJunction );
  465. CURRENT_TOOL( EE_ACTIONS::placeLabel );
  466. CURRENT_TOOL( EE_ACTIONS::placeClassLabel );
  467. CURRENT_TOOL( EE_ACTIONS::placeGlobalLabel );
  468. CURRENT_TOOL( EE_ACTIONS::placeHierLabel );
  469. CURRENT_TOOL( EE_ACTIONS::drawSheet );
  470. CURRENT_TOOL( EE_ACTIONS::importSheetPin );
  471. CURRENT_TOOL( EE_ACTIONS::drawRectangle );
  472. CURRENT_TOOL( EE_ACTIONS::drawCircle );
  473. CURRENT_TOOL( EE_ACTIONS::drawArc );
  474. CURRENT_TOOL( EE_ACTIONS::drawLines );
  475. CURRENT_TOOL( EE_ACTIONS::placeSchematicText );
  476. CURRENT_TOOL( EE_ACTIONS::drawTextBox );
  477. CURRENT_TOOL( EE_ACTIONS::placeImage );
  478. #undef CURRENT_TOOL
  479. #undef CHECK
  480. #undef ENABLE
  481. }
  482. void SCH_EDIT_FRAME::SaveCopyForRepeatItem( const SCH_ITEM* aItem )
  483. {
  484. // we cannot store a pointer to an item in the display list here since
  485. // that item may be deleted, such as part of a line concatenation or other.
  486. // So simply always keep a copy of the object which is to be repeated.
  487. if( aItem )
  488. {
  489. m_items_to_repeat.clear();
  490. AddCopyForRepeatItem( aItem );
  491. }
  492. }
  493. void SCH_EDIT_FRAME::AddCopyForRepeatItem( const SCH_ITEM* aItem )
  494. {
  495. // we cannot store a pointer to an item in the display list here since
  496. // that item may be deleted, such as part of a line concatenation or other.
  497. // So simply always keep a copy of the object which is to be repeated.
  498. if( aItem )
  499. {
  500. std::unique_ptr<SCH_ITEM> repeatItem( static_cast<SCH_ITEM*>( aItem->Clone() ) );
  501. // Clone() preserves the flags, we want 'em cleared.
  502. repeatItem->ClearFlags();
  503. m_items_to_repeat.emplace_back( std::move( repeatItem ) );
  504. }
  505. }
  506. EDA_ITEM* SCH_EDIT_FRAME::GetItem( const KIID& aId ) const
  507. {
  508. return Schematic().GetSheets().GetItem( aId );
  509. }
  510. void SCH_EDIT_FRAME::SetSheetNumberAndCount()
  511. {
  512. Schematic().SetSheetNumberAndCount();
  513. }
  514. SCH_SCREEN* SCH_EDIT_FRAME::GetScreen() const
  515. {
  516. return GetCurrentSheet().LastScreen();
  517. }
  518. SCHEMATIC& SCH_EDIT_FRAME::Schematic() const
  519. {
  520. return *m_schematic;
  521. }
  522. wxString SCH_EDIT_FRAME::GetScreenDesc() const
  523. {
  524. wxString s = GetCurrentSheet().PathHumanReadable();
  525. return s;
  526. }
  527. void SCH_EDIT_FRAME::CreateScreens()
  528. {
  529. m_schematic->Reset();
  530. m_schematic->SetProject( &Prj() );
  531. SCH_SHEET* rootSheet = new SCH_SHEET( m_schematic );
  532. m_schematic->SetRoot( rootSheet );
  533. SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic );
  534. const_cast<KIID&>( rootSheet->m_Uuid ) = rootScreen->GetUuid();
  535. m_schematic->Root().SetScreen( rootScreen );
  536. SetScreen( Schematic().RootScreen() );
  537. m_schematic->RootScreen()->SetFileName( wxEmptyString );
  538. // Don't leave root page number empty
  539. SCH_SHEET_PATH rootSheetPath;
  540. rootSheetPath.push_back( rootSheet );
  541. m_schematic->RootScreen()->SetPageNumber( wxT( "1" ) );
  542. rootSheetPath.SetPageNumber( wxT( "1" ) );
  543. if( GetScreen() == nullptr )
  544. {
  545. SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
  546. SetScreen( screen );
  547. }
  548. }
  549. SCH_SHEET_PATH& SCH_EDIT_FRAME::GetCurrentSheet() const
  550. {
  551. return m_schematic->CurrentSheet();
  552. }
  553. void SCH_EDIT_FRAME::SetCurrentSheet( const SCH_SHEET_PATH& aSheet )
  554. {
  555. if( aSheet != GetCurrentSheet() )
  556. {
  557. FocusOnItem( nullptr );
  558. Schematic().SetCurrentSheet( aSheet );
  559. GetCanvas()->DisplaySheet( aSheet.LastScreen() );
  560. }
  561. }
  562. void SCH_EDIT_FRAME::HardRedraw()
  563. {
  564. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  565. for( SCH_ITEM* item : screen->Items() )
  566. item->ClearCaches();
  567. for( std::pair<const wxString, LIB_SYMBOL*>& libSymbol : screen->GetLibSymbols() )
  568. {
  569. wxCHECK2( libSymbol.second, continue );
  570. libSymbol.second->ClearCaches();
  571. }
  572. if( Schematic().Settings().m_IntersheetRefsShow )
  573. RecomputeIntersheetRefs();
  574. FocusOnItem( nullptr );
  575. GetCanvas()->DisplaySheet( GetCurrentSheet().LastScreen() );
  576. GetCanvas()->ForceRefresh();
  577. }
  578. bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
  579. {
  580. // Exit interactive editing
  581. // Note this this will commit *some* pending changes. For instance, the EE_POINT_EDITOR
  582. // will cancel any drag currently in progress, but commit all changes from previous drags.
  583. if( m_toolManager )
  584. m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
  585. // Shutdown blocks must be determined and vetoed as early as possible
  586. if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
  587. && Schematic().GetSheets().IsModified() )
  588. {
  589. return false;
  590. }
  591. if( Kiface().IsSingle() )
  592. {
  593. auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
  594. if( symbolEditor && !symbolEditor->Close() ) // Can close symbol editor?
  595. return false;
  596. auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
  597. if( symbolViewer && !symbolViewer->Close() ) // Can close symbol viewer?
  598. return false;
  599. symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER_MODAL, false );
  600. if( symbolViewer && !symbolViewer->Close() ) // Can close modal symbol viewer?
  601. return false;
  602. }
  603. else
  604. {
  605. auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
  606. if( symbolEditor && symbolEditor->IsSymbolFromSchematic() )
  607. {
  608. if( !symbolEditor->CanCloseSymbolFromSchematic( true ) )
  609. return false;
  610. }
  611. }
  612. if( !Kiway().PlayerClose( FRAME_SIMULATOR, false ) ) // Can close the simulator?
  613. return false;
  614. // We may have gotten multiple events; don't clean up twice
  615. if( !Schematic().IsValid() )
  616. return false;
  617. SCH_SHEET_LIST sheetlist = Schematic().GetSheets();
  618. if( sheetlist.IsModified() )
  619. {
  620. wxFileName fileName = Schematic().RootScreen()->GetFileName();
  621. wxString msg = _( "Save changes to '%s' before closing?" );
  622. if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
  623. [&]() -> bool
  624. {
  625. return SaveProject();
  626. } ) )
  627. {
  628. return false;
  629. }
  630. }
  631. // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or
  632. // board.
  633. wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME );
  634. if( open_dlg )
  635. open_dlg->Close( true );
  636. return true;
  637. }
  638. void SCH_EDIT_FRAME::doCloseWindow()
  639. {
  640. SCH_SHEET_LIST sheetlist = Schematic().GetSheets();
  641. // Shutdown all running tools
  642. if( m_toolManager )
  643. m_toolManager->ShutdownAllTools();
  644. RecordERCExclusions();
  645. // Close the find dialog and preserve its setting if it is displayed.
  646. if( m_findReplaceDialog )
  647. {
  648. m_findStringHistoryList = m_findReplaceDialog->GetFindEntries();
  649. m_replaceStringHistoryList = m_findReplaceDialog->GetReplaceEntries();
  650. m_findReplaceDialog->Destroy();
  651. m_findReplaceDialog = nullptr;
  652. }
  653. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  654. if( hierarchy_pane.IsShown() && hierarchy_pane.IsFloating() )
  655. {
  656. hierarchy_pane.Show( false );
  657. m_auimgr.Update();
  658. }
  659. if( Kiway().Player( FRAME_SIMULATOR, false ) )
  660. Prj().GetProjectFile().m_SchematicSettings->m_NgspiceSimulatorSettings->SaveToFile();
  661. SCH_SCREENS screens( Schematic().Root() );
  662. wxFileName fn;
  663. for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
  664. {
  665. fn = Prj().AbsolutePath( screen->GetFileName() );
  666. // Auto save file name is the normal file name prepended with GetAutoSaveFilePrefix().
  667. fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
  668. if( fn.IsFileWritable() )
  669. wxRemoveFile( fn.GetFullPath() );
  670. }
  671. wxFileName tmpFn = Prj().GetProjectFullName();
  672. wxFileName autoSaveFileName( tmpFn.GetPath(), getAutoSaveFileName() );
  673. if( autoSaveFileName.IsFileWritable() )
  674. wxRemoveFile( autoSaveFileName.GetFullPath() );
  675. sheetlist.ClearModifyStatus();
  676. wxString fileName = Prj().AbsolutePath( Schematic().RootScreen()->GetFileName() );
  677. if( !Schematic().GetFileName().IsEmpty() && !Schematic().RootScreen()->IsEmpty() )
  678. UpdateFileHistory( fileName );
  679. // Make sure local settings are persisted
  680. SaveProjectSettings();
  681. Schematic().RootScreen()->Clear();
  682. // all sub sheets are deleted, only the main sheet is usable
  683. GetCurrentSheet().clear();
  684. // Clear view before destroying schematic as repaints depend on schematic being valid
  685. SetScreen( nullptr );
  686. Schematic().Reset();
  687. Destroy();
  688. }
  689. void SCH_EDIT_FRAME::RecordERCExclusions()
  690. {
  691. SCH_SHEET_LIST sheetList = Schematic().GetSheets();
  692. ERC_SETTINGS& ercSettings = Schematic().ErcSettings();
  693. ercSettings.m_ErcExclusions.clear();
  694. for( unsigned i = 0; i < sheetList.size(); i++ )
  695. {
  696. for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
  697. {
  698. SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
  699. if( marker->IsExcluded() )
  700. ercSettings.m_ErcExclusions.insert( marker->Serialize() );
  701. }
  702. }
  703. }
  704. void SCH_EDIT_FRAME::ResolveERCExclusions()
  705. {
  706. SCH_SHEET_LIST sheetList = Schematic().GetSheets();
  707. for( SCH_MARKER* marker : Schematic().ResolveERCExclusions() )
  708. {
  709. SCH_SHEET_PATH errorPath;
  710. ignore_unused( sheetList.GetItem( marker->GetRCItem()->GetMainItemID(), &errorPath ) );
  711. if( errorPath.LastScreen() )
  712. errorPath.LastScreen()->Append( marker );
  713. else
  714. Schematic().RootScreen()->Append( marker );
  715. }
  716. }
  717. SEVERITY SCH_EDIT_FRAME::GetSeverity( int aErrorCode ) const
  718. {
  719. return Schematic().ErcSettings().GetSeverity( aErrorCode );
  720. }
  721. void SCH_EDIT_FRAME::OnModify()
  722. {
  723. EDA_BASE_FRAME::OnModify();
  724. wxASSERT( GetScreen() );
  725. if( !GetScreen() )
  726. return;
  727. GetScreen()->SetContentModified();
  728. m_autoSaveRequired = true;
  729. RecalculateConnections( NO_CLEANUP );
  730. GetCanvas()->Refresh();
  731. UpdateHierarchyNavigator();
  732. if( !GetTitle().StartsWith( wxS( "*" ) ) )
  733. updateTitle();
  734. }
  735. void SCH_EDIT_FRAME::OnUpdatePCB( wxCommandEvent& event )
  736. {
  737. if( Kiface().IsSingle() )
  738. {
  739. DisplayError( this, _( "Cannot update the PCB, because the Schematic Editor is opened"
  740. " in stand-alone mode. In order to create/update PCBs from"
  741. " schematics, launch the KiCad shell and create a project." ) );
  742. return;
  743. }
  744. KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
  745. if( !frame )
  746. {
  747. wxFileName fn = Prj().GetProjectFullName();
  748. fn.SetExt( PcbFileExtension );
  749. frame = Kiway().Player( FRAME_PCB_EDITOR, true );
  750. // If Kiway() cannot create the Pcbnew frame, it shows a error message, and
  751. // frame is null
  752. if( !frame )
  753. return;
  754. frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
  755. }
  756. if( !frame->IsVisible() )
  757. frame->Show( true );
  758. // On Windows, Raise() does not bring the window on screen, when iconized
  759. if( frame->IsIconized() )
  760. frame->Iconize( false );
  761. frame->Raise();
  762. std::string payload;
  763. Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_PCB_UPDATE, payload, this );
  764. }
  765. void SCH_EDIT_FRAME::UpdateHierarchyNavigator()
  766. {
  767. m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CleanHistory();
  768. m_hierarchy->UpdateHierarchyTree();
  769. }
  770. void SCH_EDIT_FRAME::UpdateHierarchySelection()
  771. {
  772. m_hierarchy->UpdateHierarchySelection();
  773. }
  774. void SCH_EDIT_FRAME::ShowFindReplaceDialog( bool aReplace )
  775. {
  776. wxString findString;
  777. EE_SELECTION& selection = m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
  778. if( selection.Size() == 1 )
  779. {
  780. EDA_ITEM* front = selection.Front();
  781. switch( front->Type() )
  782. {
  783. case SCH_SYMBOL_T:
  784. findString = static_cast<SCH_SYMBOL*>( front )->GetValueFieldText( true );
  785. break;
  786. case SCH_FIELD_T:
  787. findString = static_cast<SCH_FIELD*>( front )->GetShownText();
  788. break;
  789. case SCH_LABEL_T:
  790. case SCH_GLOBAL_LABEL_T:
  791. case SCH_HIER_LABEL_T:
  792. case SCH_SHEET_PIN_T:
  793. findString = static_cast<SCH_LABEL_BASE*>( front )->GetShownText();
  794. break;
  795. case SCH_TEXT_T:
  796. findString = static_cast<SCH_TEXT*>( front )->GetShownText();
  797. if( findString.Contains( wxT( "\n" ) ) )
  798. findString = findString.Before( '\n' );
  799. break;
  800. default:
  801. break;
  802. }
  803. }
  804. if( m_findReplaceDialog )
  805. m_findReplaceDialog->Destroy();
  806. m_findReplaceDialog = new DIALOG_SCH_FIND(
  807. this, static_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() ), wxDefaultPosition,
  808. wxDefaultSize, aReplace ? wxFR_REPLACEDIALOG : 0 );
  809. m_findReplaceDialog->SetFindEntries( m_findStringHistoryList, findString );
  810. m_findReplaceDialog->SetReplaceEntries( m_replaceStringHistoryList );
  811. m_findReplaceDialog->Show( true );
  812. }
  813. void SCH_EDIT_FRAME::ShowFindReplaceStatus( const wxString& aMsg, int aStatusTime )
  814. {
  815. // Prepare the infobar, since we don't know its state
  816. m_infoBar->RemoveAllButtons();
  817. m_infoBar->AddCloseButton();
  818. m_infoBar->ShowMessageFor( aMsg, aStatusTime, wxICON_INFORMATION );
  819. }
  820. void SCH_EDIT_FRAME::ClearFindReplaceStatus()
  821. {
  822. m_infoBar->Dismiss();
  823. }
  824. void SCH_EDIT_FRAME::OnFindDialogClose()
  825. {
  826. m_findStringHistoryList = m_findReplaceDialog->GetFindEntries();
  827. m_replaceStringHistoryList = m_findReplaceDialog->GetReplaceEntries();
  828. m_findReplaceDialog->Destroy();
  829. m_findReplaceDialog = nullptr;
  830. m_toolManager->RunAction( ACTIONS::updateFind, true );
  831. }
  832. void SCH_EDIT_FRAME::OnLoadFile( wxCommandEvent& event )
  833. {
  834. wxString fn = GetFileFromHistory( event.GetId(), _( "Schematic" ) );
  835. if( fn.size() )
  836. OpenProjectFiles( std::vector<wxString>( 1, fn ) );
  837. }
  838. void SCH_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
  839. {
  840. ClearFileHistory();
  841. }
  842. void SCH_EDIT_FRAME::NewProject()
  843. {
  844. wxString pro_dir = m_mruPath;
  845. wxFileDialog dlg( this, _( "New Schematic" ), pro_dir, wxEmptyString,
  846. KiCadSchematicFileWildcard(), wxFD_SAVE );
  847. if( dlg.ShowModal() != wxID_CANCEL )
  848. {
  849. // Enforce the extension, wxFileDialog is inept.
  850. wxFileName create_me = dlg.GetPath();
  851. create_me.SetExt( KiCadSchematicFileExtension );
  852. if( create_me.FileExists() )
  853. {
  854. wxString msg;
  855. msg.Printf( _( "Schematic file '%s' already exists." ), create_me.GetFullName() );
  856. DisplayError( this, msg );
  857. return ;
  858. }
  859. // OpenProjectFiles() requires absolute
  860. wxASSERT_MSG( create_me.IsAbsolute(), wxS( "wxFileDialog returned non-absolute path" ) );
  861. OpenProjectFiles( std::vector<wxString>( 1, create_me.GetFullPath() ), KICTL_CREATE );
  862. m_mruPath = create_me.GetPath();
  863. }
  864. }
  865. void SCH_EDIT_FRAME::LoadProject()
  866. {
  867. wxString pro_dir = m_mruPath;
  868. wxString wildcards = AllSchematicFilesWildcard()
  869. + wxS( "|" ) + KiCadSchematicFileWildcard()
  870. + wxS( "|" ) + LegacySchematicFileWildcard();
  871. wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir, wxEmptyString,
  872. wildcards, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
  873. if( dlg.ShowModal() != wxID_CANCEL )
  874. {
  875. OpenProjectFiles( std::vector<wxString>( 1, dlg.GetPath() ) );
  876. m_mruPath = Prj().GetProjectPath();
  877. }
  878. }
  879. void SCH_EDIT_FRAME::OnOpenPcbnew( wxCommandEvent& event )
  880. {
  881. wxFileName kicad_board = Prj().AbsolutePath( Schematic().GetFileName() );
  882. if( kicad_board.IsOk() && !Schematic().GetFileName().IsEmpty() )
  883. {
  884. kicad_board.SetExt( PcbFileExtension );
  885. wxFileName legacy_board( kicad_board );
  886. legacy_board.SetExt( LegacyPcbFileExtension );
  887. wxFileName& boardfn = legacy_board;
  888. if( !legacy_board.FileExists() || kicad_board.FileExists() )
  889. boardfn = kicad_board;
  890. if( Kiface().IsSingle() )
  891. {
  892. ExecuteFile( PCBNEW_EXE, boardfn.GetFullPath() );
  893. }
  894. else
  895. {
  896. KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
  897. if( !frame )
  898. {
  899. frame = Kiway().Player( FRAME_PCB_EDITOR, true );
  900. // frame can be null if Cvpcb cannot be run. No need to show a warning
  901. // Kiway() generates the error messages
  902. if( !frame )
  903. return;
  904. frame->OpenProjectFiles( std::vector<wxString>( 1, boardfn.GetFullPath() ) );
  905. }
  906. if( !frame->IsVisible() )
  907. frame->Show( true );
  908. // On Windows, Raise() does not bring the window on screen, when iconized
  909. if( frame->IsIconized() )
  910. frame->Iconize( false );
  911. frame->Raise();
  912. }
  913. }
  914. else
  915. {
  916. // If we are running inside a project, it should be impossible for this case to happen
  917. wxASSERT( Kiface().IsSingle() );
  918. ExecuteFile( PCBNEW_EXE );
  919. }
  920. }
  921. void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event )
  922. {
  923. wxFileName fn = Prj().AbsolutePath( Schematic().GetFileName() );
  924. fn.SetExt( NetlistFileExtension );
  925. if( !ReadyToNetlist( _( "Assigning footprints requires a fully annotated schematic." ) ) )
  926. return;
  927. try
  928. {
  929. KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already.
  930. if( !player )
  931. {
  932. player = Kiway().Player( FRAME_CVPCB, true );
  933. // player can be null if Cvpcb cannot be run. No need to show a warning
  934. // Kiway() generates the error messages
  935. if( !player )
  936. return;
  937. player->Show( true );
  938. }
  939. sendNetlistToCvpcb();
  940. player->Raise();
  941. }
  942. catch( const IO_ERROR& )
  943. {
  944. DisplayError( this, _( "Could not open CvPcb" ) );
  945. }
  946. }
  947. void SCH_EDIT_FRAME::OnExit( wxCommandEvent& event )
  948. {
  949. if( event.GetId() == wxID_EXIT )
  950. Kiway().OnKiCadExit();
  951. if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
  952. Close( false );
  953. }
  954. void SCH_EDIT_FRAME::PrintPage( const RENDER_SETTINGS* aSettings )
  955. {
  956. wxString fileName = Prj().AbsolutePath( GetScreen()->GetFileName() );
  957. const wxBrush& brush =
  958. wxBrush( GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ).ToColour() );
  959. aSettings->GetPrintDC()->SetBackground( brush );
  960. aSettings->GetPrintDC()->Clear();
  961. aSettings->GetPrintDC()->SetLogicalFunction( wxCOPY );
  962. GetScreen()->Print( aSettings );
  963. PrintDrawingSheet( aSettings, GetScreen(), Schematic().GetProperties(), schIUScale.IU_PER_MILS,
  964. fileName );
  965. }
  966. void SCH_EDIT_FRAME::AutoRotateItem( SCH_SCREEN* aScreen, SCH_ITEM* aItem )
  967. {
  968. if( aItem->IsType( { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T } ) )
  969. {
  970. auto label = static_cast<SCH_LABEL_BASE*>( aItem );
  971. if( label->AutoRotateOnPlacement() )
  972. {
  973. auto textSpin = aScreen->GetLabelOrientationForPoint(
  974. label->GetPosition(), label->GetTextSpinStyle(), &GetCurrentSheet() );
  975. if( textSpin != label->GetTextSpinStyle() )
  976. {
  977. label->SetTextSpinStyle( textSpin );
  978. for( SCH_ITEM* item : aScreen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
  979. {
  980. SCH_LABEL_BASE* otherLabel = static_cast<SCH_LABEL_BASE*>( item );
  981. if( otherLabel != label && otherLabel->GetText() == label->GetText() )
  982. {
  983. otherLabel->AutoplaceFields( aScreen, false );
  984. }
  985. }
  986. }
  987. }
  988. }
  989. }
  990. void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_SCREEN* aScreen, SCH_ITEM* aItem,
  991. bool aUndoAppend )
  992. {
  993. wxCHECK_RET( aItem != nullptr, wxT( "Cannot add null item to list." ) );
  994. SCH_SHEET* parentSheet = nullptr;
  995. SCH_SYMBOL* parentSymbol = nullptr;
  996. SCH_ITEM* undoItem = aItem;
  997. if( aItem->Type() == SCH_SHEET_PIN_T )
  998. {
  999. parentSheet = (SCH_SHEET*) aItem->GetParent();
  1000. wxCHECK_RET( parentSheet && parentSheet->Type() == SCH_SHEET_T,
  1001. wxT( "Cannot place sheet pin in invalid schematic sheet." ) );
  1002. undoItem = parentSheet;
  1003. }
  1004. else if( aItem->Type() == SCH_FIELD_T )
  1005. {
  1006. parentSymbol = (SCH_SYMBOL*) aItem->GetParent();
  1007. wxCHECK_RET( parentSymbol && parentSymbol->Type() == SCH_SYMBOL_T,
  1008. wxT( "Cannot place field in invalid schematic symbol." ) );
  1009. undoItem = parentSymbol;
  1010. }
  1011. if( aItem->IsNew() )
  1012. {
  1013. if( aItem->Type() == SCH_SHEET_PIN_T )
  1014. {
  1015. // Sheet pins are owned by their parent sheet.
  1016. SaveCopyInUndoList( aScreen, undoItem, UNDO_REDO::CHANGED, aUndoAppend );
  1017. parentSheet->AddPin( (SCH_SHEET_PIN*) aItem );
  1018. }
  1019. else if( aItem->Type() == SCH_FIELD_T )
  1020. {
  1021. // Symbol fields are also owned by their parent, but new symbol fields are
  1022. // handled elsewhere.
  1023. wxLogMessage( wxT( "addCurrentItemToScreen: unexpected new SCH_FIELD" ) );
  1024. }
  1025. else
  1026. {
  1027. if( !aScreen->CheckIfOnDrawList( aItem ) ) // don't want a loop!
  1028. AddToScreen( aItem, aScreen );
  1029. SaveCopyForRepeatItem( aItem );
  1030. SaveCopyInUndoList( aScreen, undoItem, UNDO_REDO::NEWITEM, aUndoAppend );
  1031. }
  1032. // Update connectivity info for new item
  1033. if( !aItem->IsMoving() && aItem->IsConnectable() )
  1034. RecalculateConnections( LOCAL_CLEANUP );
  1035. }
  1036. aItem->ClearFlags( IS_NEW );
  1037. aScreen->SetContentModified();
  1038. UpdateItem( aItem );
  1039. if( !aItem->IsMoving() && aItem->IsConnectable() )
  1040. {
  1041. std::vector<VECTOR2I> pts = aItem->GetConnectionPoints();
  1042. bool connected = true;
  1043. for( auto i = pts.begin(); i != pts.end(); i++ )
  1044. {
  1045. for( auto j = i + 1; j != pts.end(); j++ )
  1046. TrimWire( *i, *j );
  1047. if( aScreen->IsExplicitJunctionNeeded( *i ) )
  1048. {
  1049. AddJunction( aScreen, *i, true, false );
  1050. connected = true;
  1051. }
  1052. }
  1053. if( connected )
  1054. {
  1055. AutoRotateItem( aScreen, aItem );
  1056. }
  1057. TestDanglingEnds();
  1058. for( SCH_ITEM* item : aItem->ConnectedItems( GetCurrentSheet() ) )
  1059. UpdateItem( item );
  1060. }
  1061. aItem->ClearEditFlags();
  1062. GetCanvas()->Refresh();
  1063. }
  1064. void SCH_EDIT_FRAME::updateTitle()
  1065. {
  1066. SCH_SCREEN* screen = GetScreen();
  1067. wxCHECK( screen, /* void */ );
  1068. wxString title;
  1069. if( !screen->GetFileName().IsEmpty() )
  1070. {
  1071. wxFileName fn( Prj().AbsolutePath( screen->GetFileName() ) );
  1072. bool readOnly = false;
  1073. bool unsaved = false;
  1074. if( fn.IsOk() && screen->FileExists() )
  1075. readOnly = screen->IsReadOnly();
  1076. else
  1077. unsaved = true;
  1078. if( IsContentModified() )
  1079. title = wxT( "*" );
  1080. title += fn.GetName();
  1081. wxString sheetPath = GetCurrentSheet().PathHumanReadable( false, true );
  1082. if( sheetPath != title )
  1083. title += wxString::Format( wxT( " [%s]" ), sheetPath );
  1084. if( readOnly )
  1085. title += wxS( " " ) + _( "[Read Only]" );
  1086. if( unsaved )
  1087. title += wxS( " " ) + _( "[Unsaved]" );
  1088. }
  1089. else
  1090. {
  1091. title = _( "[no schematic loaded]" );
  1092. }
  1093. title += wxT( " \u2014 " ) + _( "Schematic Editor" );
  1094. SetTitle( title );
  1095. }
  1096. void SCH_EDIT_FRAME::initScreenZoom()
  1097. {
  1098. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  1099. GetScreen()->m_zoomInitialized = true;
  1100. }
  1101. void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags )
  1102. {
  1103. const SCH_CONNECTION* highlight = GetHighlightedConnection();
  1104. SCH_ITEM* highlightedItem = nullptr;
  1105. SCH_SHEET_PATH highlightPath;
  1106. if( highlight )
  1107. {
  1108. highlightPath = highlight->LocalSheet();
  1109. highlightedItem = dynamic_cast<SCH_ITEM*>( GetItem( highlight->Parent()->m_Uuid ) );
  1110. }
  1111. SCHEMATIC_SETTINGS& settings = Schematic().Settings();
  1112. SCH_SHEET_LIST list = Schematic().GetSheets();
  1113. #ifdef PROFILE
  1114. PROF_TIMER timer;
  1115. #endif
  1116. // Ensure schematic graph is accurate
  1117. if( aCleanupFlags == LOCAL_CLEANUP )
  1118. {
  1119. SchematicCleanUp( GetScreen() );
  1120. }
  1121. else if( aCleanupFlags == GLOBAL_CLEANUP )
  1122. {
  1123. for( const SCH_SHEET_PATH& sheet : list )
  1124. SchematicCleanUp( sheet.LastScreen() );
  1125. }
  1126. #ifdef PROFILE
  1127. timer.Stop();
  1128. wxLogTrace( "CONN_PROFILE", "SchematicCleanUp() %0.4f ms", timer.msecs() );
  1129. #endif
  1130. if( settings.m_IntersheetRefsShow )
  1131. RecomputeIntersheetRefs();
  1132. std::function<void( SCH_ITEM* )> changeHandler =
  1133. [&]( SCH_ITEM* aChangedItem ) -> void
  1134. {
  1135. GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
  1136. };
  1137. Schematic().ConnectionGraph()->Recalculate( list, true, &changeHandler );
  1138. GetCanvas()->GetView()->UpdateAllItemsConditionally(
  1139. [&]( KIGFX::VIEW_ITEM* aItem ) -> int
  1140. {
  1141. int flags = 0;
  1142. SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem );
  1143. SCH_CONNECTION* connection = item ? item->Connection() : nullptr;
  1144. if( connection && connection->HasDriverChanged() )
  1145. {
  1146. connection->ClearDriverChanged();
  1147. flags |= KIGFX::REPAINT;
  1148. }
  1149. if( item )
  1150. {
  1151. item->RunOnChildren(
  1152. [&flags]( SCH_ITEM* aChild )
  1153. {
  1154. EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild );
  1155. if( text && text->HasTextVars() )
  1156. {
  1157. text->ClearRenderCache();
  1158. text->ClearBoundingBoxCache();
  1159. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1160. }
  1161. } );
  1162. EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
  1163. if( text && text->HasTextVars() )
  1164. {
  1165. text->ClearRenderCache();
  1166. text->ClearBoundingBoxCache();
  1167. flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
  1168. }
  1169. if( flags & KIGFX::GEOMETRY )
  1170. GetScreen()->Update( item, false ); // Refresh RTree
  1171. }
  1172. return flags;
  1173. } );
  1174. if( highlightedItem )
  1175. SetHighlightedConnection( highlightedItem->Connection( &highlightPath ) );
  1176. }
  1177. void SCH_EDIT_FRAME::RecomputeIntersheetRefs()
  1178. {
  1179. Schematic().RecomputeIntersheetRefs( [&]( SCH_GLOBALLABEL* label )
  1180. {
  1181. for( SCH_FIELD& field : label->GetFields() )
  1182. field.ClearBoundingBoxCache();
  1183. label->ClearBoundingBoxCache();
  1184. GetCanvas()->GetView()->Update( label );
  1185. } );
  1186. }
  1187. void SCH_EDIT_FRAME::ShowAllIntersheetRefs( bool aShow )
  1188. {
  1189. RecomputeIntersheetRefs();
  1190. GetCanvas()->GetView()->SetLayerVisible( LAYER_INTERSHEET_REFS, aShow );
  1191. }
  1192. void SCH_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  1193. {
  1194. SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  1195. SCHEMATIC_SETTINGS& settings = Schematic().Settings();
  1196. settings.m_JunctionSize = GetSchematicJunctionSize();
  1197. ShowAllIntersheetRefs( settings.m_IntersheetRefsShow );
  1198. EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
  1199. GetGalDisplayOptions().ReadWindowSettings( cfg->m_Window );
  1200. GetRenderSettings()->SetDefaultFont( cfg->m_Appearance.default_font );
  1201. KIGFX::VIEW* view = GetCanvas()->GetView();
  1202. view->SetLayerVisible( LAYER_ERC_ERR, cfg->m_Appearance.show_erc_errors );
  1203. view->SetLayerVisible( LAYER_ERC_WARN, cfg->m_Appearance.show_erc_warnings );
  1204. view->SetLayerVisible( LAYER_ERC_EXCLUSION, cfg->m_Appearance.show_erc_exclusions );
  1205. settings.m_TemplateFieldNames.DeleteAllFieldNameTemplates( true /* global */ );
  1206. if( !cfg->m_Drawing.field_names.IsEmpty() )
  1207. settings.m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names );
  1208. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  1209. for( SCH_ITEM* item : screen->Items() )
  1210. item->ClearCaches();
  1211. for( std::pair<const wxString, LIB_SYMBOL*>& libSymbol : screen->GetLibSymbols() )
  1212. libSymbol.second->ClearCaches();
  1213. GetCanvas()->ForceRefresh();
  1214. RecreateToolbars();
  1215. Layout();
  1216. SendSizeEvent();
  1217. }
  1218. void SCH_EDIT_FRAME::OnPageSettingsChange()
  1219. {
  1220. // Store the current zoom level into the current screen before calling
  1221. // DisplayCurrentSheet() that set the zoom to GetScreen()->m_LastZoomLevel
  1222. GetScreen()->m_LastZoomLevel = GetCanvas()->GetView()->GetScale();
  1223. // Rebuild the sheet view (draw area and any other items):
  1224. DisplayCurrentSheet();
  1225. }
  1226. void SCH_EDIT_FRAME::ShowChangedLanguage()
  1227. {
  1228. // call my base class
  1229. SCH_BASE_FRAME::ShowChangedLanguage();
  1230. // tooltips in toolbars
  1231. RecreateToolbars();
  1232. m_auimgr.GetPane( m_hierarchy ).Caption( _( "Schematic Hierarchy" ) );
  1233. m_auimgr.Update();
  1234. m_hierarchy->UpdateHierarchyTree();
  1235. // status bar
  1236. UpdateMsgPanel();
  1237. updateTitle();
  1238. // This ugly hack is to fix an option(left) toolbar update bug that seems to only affect
  1239. // windows. See https://bugs.launchpad.net/kicad/+bug/1816492. For some reason, calling
  1240. // wxWindow::Refresh() does not resolve the issue. Only a resize event seems to force the
  1241. // toolbar to update correctly.
  1242. #if defined( __WXMSW__ )
  1243. PostSizeEvent();
  1244. #endif
  1245. }
  1246. void SCH_EDIT_FRAME::UpdateNetHighlightStatus()
  1247. {
  1248. if( const SCH_CONNECTION* conn = GetHighlightedConnection() )
  1249. {
  1250. SetStatusText( wxString::Format( _( "Highlighted net: %s" ),
  1251. UnescapeString( conn->Name() ) ) );
  1252. }
  1253. else
  1254. {
  1255. SetStatusText( wxT( "" ) );
  1256. }
  1257. }
  1258. void SCH_EDIT_FRAME::SetScreen( BASE_SCREEN* aScreen )
  1259. {
  1260. if( m_toolManager )
  1261. m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
  1262. SCH_BASE_FRAME::SetScreen( aScreen );
  1263. GetCanvas()->DisplaySheet( static_cast<SCH_SCREEN*>( aScreen ) );
  1264. }
  1265. const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
  1266. {
  1267. BOX2I bBoxDoc;
  1268. if( aIncludeAllVisible )
  1269. {
  1270. // Get the whole page size and return that
  1271. int sizeX = GetScreen()->GetPageSettings().GetWidthIU( schIUScale.IU_PER_MILS );
  1272. int sizeY = GetScreen()->GetPageSettings().GetHeightIU( schIUScale.IU_PER_MILS );
  1273. bBoxDoc = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sizeX, sizeY ) );
  1274. }
  1275. else
  1276. {
  1277. // Get current drawing-sheet in a form we can compare to an EDA_ITEM
  1278. DS_PROXY_VIEW_ITEM* ds = SCH_BASE_FRAME::GetCanvas()->GetView()->GetDrawingSheet();
  1279. EDA_ITEM* dsAsItem = static_cast<EDA_ITEM*>( ds );
  1280. // Calc the bounding box of all items on screen except the page border
  1281. for( EDA_ITEM* item : GetScreen()->Items() )
  1282. {
  1283. if( item != dsAsItem ) // Ignore the drawing-sheet itself
  1284. bBoxDoc.Merge( item->GetBoundingBox() );
  1285. }
  1286. }
  1287. return bBoxDoc;
  1288. }
  1289. bool SCH_EDIT_FRAME::IsContentModified() const
  1290. {
  1291. return Schematic().GetSheets().IsModified();
  1292. }
  1293. bool SCH_EDIT_FRAME::GetShowAllPins() const
  1294. {
  1295. EESCHEMA_SETTINGS* cfg = eeconfig();
  1296. return cfg && cfg->m_Appearance.show_hidden_pins;
  1297. }
  1298. void SCH_EDIT_FRAME::FocusOnItem( SCH_ITEM* aItem )
  1299. {
  1300. static KIID lastBrightenedItemID( niluuid );
  1301. SCH_SHEET_LIST sheetList = Schematic().GetSheets();
  1302. SCH_SHEET_PATH dummy;
  1303. SCH_ITEM* lastItem = sheetList.GetItem( lastBrightenedItemID, &dummy );
  1304. if( lastItem && lastItem != aItem )
  1305. {
  1306. lastItem->ClearBrightened();
  1307. UpdateItem( lastItem );
  1308. lastBrightenedItemID = niluuid;
  1309. }
  1310. if( aItem )
  1311. {
  1312. if( !aItem->IsBrightened() )
  1313. {
  1314. aItem->SetBrightened();
  1315. UpdateItem( aItem );
  1316. lastBrightenedItemID = aItem->m_Uuid;
  1317. }
  1318. FocusOnLocation( aItem->GetFocusPosition() );
  1319. }
  1320. }
  1321. wxString SCH_EDIT_FRAME::GetCurrentFileName() const
  1322. {
  1323. return Schematic().GetFileName();
  1324. }
  1325. SELECTION& SCH_EDIT_FRAME::GetCurrentSelection()
  1326. {
  1327. return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
  1328. }
  1329. void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
  1330. {
  1331. if( IsShown() )
  1332. {
  1333. // We only need this until the frame is done resizing and the final client size is
  1334. // established.
  1335. Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
  1336. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
  1337. }
  1338. // Skip() is called in the base class.
  1339. EDA_DRAW_FRAME::OnSize( aEvent );
  1340. }
  1341. void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol,
  1342. const KIID& aSchematicSymbolUUID )
  1343. {
  1344. bool appendToUndo = false;
  1345. SCH_SHEET_PATH principalPath;
  1346. SCH_ITEM* item = Schematic().GetSheets().GetItem( aSchematicSymbolUUID, &principalPath );
  1347. SCH_SYMBOL* principalSymbol = dynamic_cast<SCH_SYMBOL*>( item );
  1348. if( !principalSymbol )
  1349. return;
  1350. wxString principalRef;
  1351. if( principalSymbol->IsAnnotated( &principalPath ) )
  1352. principalRef = principalSymbol->GetRef( &principalPath, false );
  1353. std::vector< std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> > otherUnits;
  1354. for( const SCH_SHEET_PATH& path : Schematic().GetSheets() )
  1355. {
  1356. for( SCH_ITEM* candidate : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
  1357. {
  1358. SCH_SYMBOL* candidateSymbol = static_cast<SCH_SYMBOL*>( candidate );
  1359. if( candidateSymbol == principalSymbol
  1360. || ( candidateSymbol->IsAnnotated( &path )
  1361. && candidateSymbol->GetRef( &path, false ) == principalRef ) )
  1362. {
  1363. otherUnits.emplace_back( candidateSymbol, path );
  1364. }
  1365. }
  1366. }
  1367. for( auto& [ otherUnit, path ] : otherUnits )
  1368. {
  1369. // This needs to be done before the LIB_SYMBOL is changed to prevent stale
  1370. // library symbols in the schematic file.
  1371. path.LastScreen()->Remove( otherUnit );
  1372. if( !otherUnit->IsNew() )
  1373. {
  1374. SaveCopyInUndoList( path.LastScreen(), otherUnit, UNDO_REDO::CHANGED, appendToUndo );
  1375. appendToUndo = true;
  1376. }
  1377. otherUnit->SetLibSymbol( aSymbol.Flatten().release() );
  1378. otherUnit->UpdateFields( &GetCurrentSheet(),
  1379. true, /* update style */
  1380. true, /* update ref */
  1381. true, /* update other fields */
  1382. false, /* reset ref */
  1383. false /* reset other fields */ );
  1384. path.LastScreen()->Append( otherUnit );
  1385. GetCanvas()->GetView()->Update( otherUnit );
  1386. }
  1387. GetCanvas()->Refresh();
  1388. OnModify();
  1389. }
  1390. void SCH_EDIT_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
  1391. {
  1392. SCH_BASE_FRAME::UpdateItem( aItem, isAddOrDelete, aUpdateRtree );
  1393. if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
  1394. sch_item->ClearCaches();
  1395. }
  1396. void SCH_EDIT_FRAME::DisplayCurrentSheet()
  1397. {
  1398. m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
  1399. m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
  1400. SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
  1401. wxASSERT( screen );
  1402. SetScreen( screen );
  1403. // update the References
  1404. GetCurrentSheet().UpdateAllScreenReferences();
  1405. SetSheetNumberAndCount();
  1406. EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
  1407. auto visit =
  1408. [&]( EDA_ITEM* item )
  1409. {
  1410. if( m_findReplaceDialog
  1411. && !m_findReplaceData->findString.IsEmpty()
  1412. && item->Matches( *m_findReplaceData, &GetCurrentSheet() ) )
  1413. {
  1414. item->SetForceVisible( true );
  1415. selectionTool->BrightenItem( item );
  1416. }
  1417. else if( item->IsBrightened() )
  1418. {
  1419. item->SetForceVisible( false );
  1420. selectionTool->UnbrightenItem( item );
  1421. }
  1422. };
  1423. for( SCH_ITEM* item : screen->Items() )
  1424. {
  1425. visit( item );
  1426. item->RunOnChildren(
  1427. [&]( SCH_ITEM* aChild )
  1428. {
  1429. visit( aChild );
  1430. } );
  1431. }
  1432. if( !screen->m_zoomInitialized )
  1433. {
  1434. initScreenZoom();
  1435. }
  1436. else
  1437. {
  1438. // Set zoom to last used in this screen
  1439. GetCanvas()->GetView()->SetScale( GetScreen()->m_LastZoomLevel );
  1440. RedrawScreen( (wxPoint) GetScreen()->m_ScrollCenter, false );
  1441. }
  1442. updateTitle();
  1443. HardRedraw(); // Ensure all items are redrawn (especially the drawing-sheet items)
  1444. SCH_EDITOR_CONTROL* editTool = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
  1445. TOOL_EVENT dummy;
  1446. editTool->UpdateNetHighlighting( dummy );
  1447. m_hierarchy->UpdateHierarchySelection();
  1448. }