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.

1914 lines
59 KiB

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