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.

1812 lines
54 KiB

3 years ago
4 years ago
4 years ago
8 months ago
3 years ago
3 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
3 years ago
5 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
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 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
3 years ago
3 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
4 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
3 years ago
3 years ago
3 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2023 CERN (www.cern.ch)
  7. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include "dialogs/panel_maintenance.h"
  27. #include "kicad_manager_frame.h"
  28. #include <eda_base_frame.h>
  29. #include <advanced_config.h>
  30. #include <bitmaps.h>
  31. #include <bitmap_store.h>
  32. #include <dialog_shim.h>
  33. #include <dialogs/git/panel_git_repos.h>
  34. #include <dialogs/panel_common_settings.h>
  35. #include <dialogs/panel_mouse_settings.h>
  36. #include <dialogs/panel_spacemouse.h>
  37. #include <dialogs/panel_data_collection.h>
  38. #include <dialogs/panel_plugin_settings.h>
  39. #include <eda_dde.h>
  40. #include <file_history.h>
  41. #include <id.h>
  42. #include <kiface_base.h>
  43. #include <hotkeys_basic.h>
  44. #include <panel_hotkeys_editor.h>
  45. #include <paths.h>
  46. #include <confirm.h>
  47. #include <panel_packages_and_updates.h>
  48. #include <pgm_base.h>
  49. #include <settings/app_settings.h>
  50. #include <settings/common_settings.h>
  51. #include <settings/settings_manager.h>
  52. #include <project/project_local_settings.h>
  53. #include <tool/action_manager.h>
  54. #include <tool/action_menu.h>
  55. #include <tool/action_toolbar.h>
  56. #include <tool/actions.h>
  57. #include <tool/common_control.h>
  58. #include <tool/tool_manager.h>
  59. #include <tool/tool_dispatcher.h>
  60. #include <tool/ui/toolbar_configuration.h>
  61. #include <trace_helpers.h>
  62. #include <widgets/paged_dialog.h>
  63. #include <widgets/wx_busy_indicator.h>
  64. #include <widgets/wx_infobar.h>
  65. #include <widgets/wx_aui_art_providers.h>
  66. #include <widgets/wx_grid.h>
  67. #include <widgets/wx_treebook.h>
  68. #include <wx/app.h>
  69. #include <wx/config.h>
  70. #include <wx/display.h>
  71. #include <wx/stdpaths.h>
  72. #include <wx/string.h>
  73. #include <wx/msgdlg.h>
  74. #include <wx/wupdlock.h>
  75. #include <kiplatform/app.h>
  76. #include <kiplatform/io.h>
  77. #include <kiplatform/ui.h>
  78. #include <functional>
  79. #include <kiface_ids.h>
  80. #ifdef KICAD_IPC_API
  81. #include <api/api_server.h>
  82. #endif
  83. // Minimum window size
  84. static const wxSize minSizeLookup( FRAME_T aFrameType, wxWindow* aWindow )
  85. {
  86. switch( aFrameType )
  87. {
  88. case KICAD_MAIN_FRAME_T:
  89. return wxWindow::FromDIP( wxSize( 406, 354 ), aWindow );
  90. default:
  91. return wxWindow::FromDIP( wxSize( 500, 400 ), aWindow );
  92. }
  93. }
  94. static const wxSize defaultSize( FRAME_T aFrameType, wxWindow* aWindow )
  95. {
  96. switch( aFrameType )
  97. {
  98. case KICAD_MAIN_FRAME_T:
  99. return wxWindow::FromDIP( wxSize( 850, 540 ), aWindow );
  100. default:
  101. return wxWindow::FromDIP( wxSize( 1280, 720 ), aWindow );
  102. }
  103. }
  104. BEGIN_EVENT_TABLE( EDA_BASE_FRAME, wxFrame )
  105. // These event table entries are needed to handle events from the mac application menu
  106. EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::OnKicadAbout )
  107. EVT_MENU( wxID_PREFERENCES, EDA_BASE_FRAME::OnPreferences )
  108. EVT_CHAR_HOOK( EDA_BASE_FRAME::OnCharHook )
  109. EVT_MENU_OPEN( EDA_BASE_FRAME::OnMenuEvent )
  110. EVT_MENU_CLOSE( EDA_BASE_FRAME::OnMenuEvent )
  111. EVT_MENU_HIGHLIGHT_ALL( EDA_BASE_FRAME::OnMenuEvent )
  112. EVT_MOVE( EDA_BASE_FRAME::OnMove )
  113. EVT_SIZE( EDA_BASE_FRAME::OnSize )
  114. EVT_MAXIMIZE( EDA_BASE_FRAME::OnMaximize )
  115. EVT_SYS_COLOUR_CHANGED( EDA_BASE_FRAME::onSystemColorChange )
  116. EVT_ICONIZE( EDA_BASE_FRAME::onIconize )
  117. END_EVENT_TABLE()
  118. void EDA_BASE_FRAME::commonInit( FRAME_T aFrameType )
  119. {
  120. m_ident = aFrameType;
  121. m_maximizeByDefault = false;
  122. m_infoBar = nullptr;
  123. m_settingsManager = nullptr;
  124. m_fileHistory = nullptr;
  125. m_supportsAutoSave = false;
  126. m_autoSavePending = false;
  127. m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
  128. m_isClosing = false;
  129. m_isNonUserClose = false;
  130. m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
  131. m_autoSaveRequired = false;
  132. m_autoSavePermissionError = false;
  133. m_mruPath = PATHS::GetDefaultUserProjectsPath();
  134. m_frameSize = defaultSize( aFrameType, this );
  135. m_displayIndex = -1;
  136. m_auimgr.SetArtProvider( new WX_AUI_DOCK_ART() );
  137. m_settingsManager = &Pgm().GetSettingsManager();
  138. // Set a reasonable minimal size for the frame
  139. wxSize minSize = minSizeLookup( aFrameType, this );
  140. SetSizeHints( minSize.x, minSize.y, -1, -1, -1, -1 );
  141. // Store dimensions of the user area of the main window.
  142. GetClientSize( &m_frameSize.x, &m_frameSize.y );
  143. Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
  144. wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
  145. // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems
  146. // to be called before any other hook for wxCloseEvent, which is necessary.
  147. Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
  148. initExitKey();
  149. }
  150. EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
  151. const wxPoint& aPos, const wxSize& aSize, long aStyle,
  152. const wxString& aFrameName, KIWAY* aKiway,
  153. const EDA_IU_SCALE& aIuScale ) :
  154. wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
  155. TOOLS_HOLDER(),
  156. KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ),
  157. UNITS_PROVIDER( aIuScale, EDA_UNITS::MM )
  158. {
  159. m_tbTopMain = nullptr;
  160. m_tbTopAux = nullptr;
  161. m_tbRight = nullptr;
  162. m_tbLeft = nullptr;
  163. commonInit( aFrameType );
  164. }
  165. wxWindow* findQuasiModalDialog( wxWindow* aParent )
  166. {
  167. for( wxWindow* child : aParent->GetChildren() )
  168. {
  169. if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( child ) )
  170. {
  171. if( dlg->IsQuasiModal() )
  172. return dlg;
  173. if( wxWindow* nestedDlg = findQuasiModalDialog( child ) )
  174. return nestedDlg;
  175. }
  176. }
  177. return nullptr;
  178. }
  179. wxWindow* EDA_BASE_FRAME::findQuasiModalDialog()
  180. {
  181. if( wxWindow* dlg = ::findQuasiModalDialog( this ) )
  182. return dlg;
  183. // FIXME: CvPcb is currently implemented on top of KIWAY_PLAYER rather than DIALOG_SHIM,
  184. // so we have to look for it separately.
  185. if( m_ident == FRAME_SCH )
  186. {
  187. wxWindow* cvpcb = wxWindow::FindWindowByName( wxS( "CvpcbFrame" ) );
  188. if( cvpcb )
  189. return cvpcb;
  190. }
  191. return nullptr;
  192. }
  193. void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
  194. {
  195. // Don't allow closing when a quasi-modal is open.
  196. wxWindow* quasiModal = findQuasiModalDialog();
  197. if( quasiModal )
  198. {
  199. // Raise and notify; don't give the user a warning regarding "quasi-modal dialogs"
  200. // when they have no idea what those are.
  201. quasiModal->Raise();
  202. wxBell();
  203. if( event.CanVeto() )
  204. event.Veto();
  205. return;
  206. }
  207. if( event.GetId() == wxEVT_QUERY_END_SESSION
  208. || event.GetId() == wxEVT_END_SESSION )
  209. {
  210. // End session means the OS is going to terminate us
  211. m_isNonUserClose = true;
  212. }
  213. if( canCloseWindow( event ) )
  214. {
  215. m_isClosing = true;
  216. if( m_infoBar )
  217. m_infoBar->Dismiss();
  218. APP_SETTINGS_BASE* cfg = config();
  219. if( cfg )
  220. SaveSettings( cfg ); // virtual, wxFrame specific
  221. doCloseWindow();
  222. // Destroy (safe delete frame) this frame only in non modal mode.
  223. // In modal mode, the caller will call Destroy().
  224. if( !IsModal() )
  225. Destroy();
  226. }
  227. else
  228. {
  229. if( event.CanVeto() )
  230. event.Veto();
  231. }
  232. }
  233. EDA_BASE_FRAME::~EDA_BASE_FRAME()
  234. {
  235. Disconnect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
  236. wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
  237. Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
  238. delete m_autoSaveTimer;
  239. delete m_fileHistory;
  240. ClearUndoRedoList();
  241. SocketCleanup();
  242. KIPLATFORM::APP::RemoveShutdownBlockReason( this );
  243. }
  244. bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
  245. {
  246. #ifdef __WXMAC__
  247. // Apple in its infinite wisdom will raise a disabled window before even passing
  248. // us the event, so we have no way to stop it. Instead, we have to catch an
  249. // improperly ordered disabled window and quasi-modal dialog here and reorder
  250. // them.
  251. if( !IsEnabled() && IsActive() )
  252. {
  253. wxWindow* dlg = findQuasiModalDialog();
  254. if( dlg )
  255. dlg->Raise();
  256. }
  257. #endif
  258. if( !wxFrame::ProcessEvent( aEvent ) )
  259. return false;
  260. if( Pgm().m_Quitting )
  261. return true;
  262. if( !m_isClosing && m_supportsAutoSave && IsShownOnScreen() && IsActive()
  263. && m_autoSavePending != isAutoSaveRequired()
  264. && GetAutoSaveInterval() > 0 )
  265. {
  266. if( !m_autoSavePending )
  267. {
  268. wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
  269. m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
  270. m_autoSavePending = true;
  271. }
  272. else if( m_autoSaveTimer->IsRunning() )
  273. {
  274. wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
  275. m_autoSaveTimer->Stop();
  276. m_autoSavePending = false;
  277. }
  278. }
  279. return true;
  280. }
  281. int EDA_BASE_FRAME::GetAutoSaveInterval() const
  282. {
  283. return Pgm().GetCommonSettings()->m_System.autosave_interval;
  284. }
  285. void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent )
  286. {
  287. // Don't stomp on someone else's timer event.
  288. if( aEvent.GetId() != ID_AUTO_SAVE_TIMER )
  289. {
  290. aEvent.Skip();
  291. return;
  292. }
  293. if( !doAutoSave() )
  294. m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
  295. }
  296. bool EDA_BASE_FRAME::doAutoSave()
  297. {
  298. wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
  299. }
  300. void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& aKeyEvent )
  301. {
  302. wxLogTrace( kicadTraceKeyEvent, wxS( "EDA_BASE_FRAME::OnCharHook %s" ), dump( aKeyEvent ) );
  303. // Key events can be filtered here.
  304. // Currently no filtering is made.
  305. aKeyEvent.Skip();
  306. }
  307. void EDA_BASE_FRAME::OnMenuEvent( wxMenuEvent& aEvent )
  308. {
  309. if( !m_toolDispatcher )
  310. aEvent.Skip();
  311. else
  312. m_toolDispatcher->DispatchWxEvent( aEvent );
  313. }
  314. void EDA_BASE_FRAME::RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions )
  315. {
  316. UIUpdateHandler evtFunc = std::bind( &EDA_BASE_FRAME::HandleUpdateUIEvent,
  317. std::placeholders::_1,
  318. this,
  319. aConditions );
  320. m_uiUpdateMap[aID] = evtFunc;
  321. Bind( wxEVT_UPDATE_UI, evtFunc, aID );
  322. }
  323. void EDA_BASE_FRAME::UnregisterUIUpdateHandler( int aID )
  324. {
  325. const auto it = m_uiUpdateMap.find( aID );
  326. if( it == m_uiUpdateMap.end() )
  327. return;
  328. Unbind( wxEVT_UPDATE_UI, it->second, aID );
  329. }
  330. void EDA_BASE_FRAME::HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
  331. ACTION_CONDITIONS aCond )
  332. {
  333. bool checkRes = false;
  334. bool enableRes = true;
  335. bool showRes = true;
  336. bool isCut = aEvent.GetId() == ACTIONS::cut.GetUIId();
  337. bool isCopy = aEvent.GetId() == ACTIONS::copy.GetUIId();
  338. bool isPaste = aEvent.GetId() == ACTIONS::paste.GetUIId();
  339. SELECTION& selection = aFrame->GetCurrentSelection();
  340. try
  341. {
  342. checkRes = aCond.checkCondition( selection );
  343. enableRes = aCond.enableCondition( selection );
  344. showRes = aCond.showCondition( selection );
  345. }
  346. catch( std::exception& )
  347. {
  348. // Something broke with the conditions, just skip the event.
  349. aEvent.Skip();
  350. return;
  351. }
  352. if( showRes && aEvent.GetId() == ACTIONS::undo.GetUIId() )
  353. {
  354. wxString msg = _( "Undo" );
  355. if( enableRes )
  356. msg += wxS( " " ) + aFrame->GetUndoActionDescription();
  357. aEvent.SetText( msg );
  358. }
  359. else if( showRes && aEvent.GetId() == ACTIONS::redo.GetUIId() )
  360. {
  361. wxString msg = _( "Redo" );
  362. if( enableRes )
  363. msg += wxS( " " ) + aFrame->GetRedoActionDescription();
  364. aEvent.SetText( msg );
  365. }
  366. if( isCut || isCopy || isPaste )
  367. {
  368. wxWindow* focus = wxWindow::FindFocus();
  369. wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
  370. if( textEntry && isCut && textEntry->CanCut() )
  371. enableRes = true;
  372. else if( textEntry && isCopy && textEntry->CanCopy() )
  373. enableRes = true;
  374. else if( textEntry && isPaste && textEntry->CanPaste() )
  375. enableRes = true;
  376. else if( dynamic_cast<WX_GRID*>( focus ) )
  377. enableRes = false; // Must disable menu in order to get command as CharHook event
  378. }
  379. aEvent.Enable( enableRes );
  380. aEvent.Show( showRes );
  381. if( aEvent.IsCheckable() )
  382. aEvent.Check( checkRes );
  383. }
  384. void EDA_BASE_FRAME::setupUIConditions()
  385. {
  386. // Setup the conditions to check a language menu item
  387. auto isCurrentLang =
  388. [] ( const SELECTION& aSel, int aLangIdentifier )
  389. {
  390. return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
  391. };
  392. for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
  393. {
  394. ACTION_CONDITIONS cond;
  395. cond.Check( std::bind( isCurrentLang, std::placeholders::_1,
  396. LanguagesList[ii].m_WX_Lang_Identifier ) );
  397. RegisterUIUpdateHandler( LanguagesList[ii].m_KI_Lang_Identifier, cond );
  398. }
  399. }
  400. void EDA_BASE_FRAME::RegisterCustomToolbarControlFactory( const ACTION_TOOLBAR_CONTROL& aControlDesc,
  401. const ACTION_TOOLBAR_CONTROL_FACTORY& aControlFactory )
  402. {
  403. m_toolbarControlFactories.emplace( aControlDesc.GetName(), aControlFactory );
  404. }
  405. ACTION_TOOLBAR_CONTROL_FACTORY* EDA_BASE_FRAME::GetCustomToolbarControlFactory( const std::string& aName )
  406. {
  407. for( auto& control : m_toolbarControlFactories )
  408. {
  409. if( control.first == aName )
  410. return &control.second;
  411. }
  412. return nullptr;
  413. }
  414. void EDA_BASE_FRAME::configureToolbars()
  415. {
  416. }
  417. void EDA_BASE_FRAME::RecreateToolbars()
  418. {
  419. wxWindowUpdateLocker dummy( this );
  420. wxASSERT( m_toolbarSettings );
  421. std::optional<TOOLBAR_CONFIGURATION> tbConfig;
  422. // Drawing tools (typically on right edge of window)
  423. tbConfig = m_toolbarSettings->GetToolbarConfig( TOOLBAR_LOC::RIGHT, config()->m_CustomToolbars );
  424. if( tbConfig.has_value() )
  425. {
  426. if( !m_tbRight )
  427. {
  428. m_tbRight = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  429. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  430. m_tbRight->SetAuiManager( &m_auimgr );
  431. }
  432. m_tbRight->ApplyConfiguration( tbConfig.value() );
  433. }
  434. // Options (typically on left edge of window)
  435. tbConfig = m_toolbarSettings->GetToolbarConfig( TOOLBAR_LOC::LEFT, config()->m_CustomToolbars );
  436. if( tbConfig.has_value() )
  437. {
  438. if( !m_tbLeft )
  439. {
  440. m_tbLeft = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  441. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  442. m_tbLeft->SetAuiManager( &m_auimgr );
  443. }
  444. m_tbLeft->ApplyConfiguration( tbConfig.value() );
  445. }
  446. // Top main toolbar (the top one)
  447. tbConfig = m_toolbarSettings->GetToolbarConfig( TOOLBAR_LOC::TOP_MAIN, config()->m_CustomToolbars );
  448. if( tbConfig.has_value() )
  449. {
  450. if( !m_tbTopMain )
  451. {
  452. m_tbTopMain = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  453. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
  454. m_tbTopMain->SetAuiManager( &m_auimgr );
  455. }
  456. m_tbTopMain->ApplyConfiguration( tbConfig.value() );
  457. }
  458. // Top aux toolbar (the bottom one)
  459. tbConfig = m_toolbarSettings->GetToolbarConfig( TOOLBAR_LOC::TOP_AUX, config()->m_CustomToolbars );
  460. if( tbConfig.has_value() )
  461. {
  462. if( !m_tbTopAux )
  463. {
  464. m_tbTopAux = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  465. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
  466. m_tbTopAux->SetAuiManager( &m_auimgr );
  467. }
  468. m_tbTopAux->ApplyConfiguration( tbConfig.value() );
  469. }
  470. }
  471. void EDA_BASE_FRAME::UpdateToolbarControlSizes()
  472. {
  473. if( m_tbTopMain )
  474. m_tbTopMain->UpdateControlWidths();
  475. if( m_tbRight )
  476. m_tbRight->UpdateControlWidths();
  477. if( m_tbLeft )
  478. m_tbLeft->UpdateControlWidths();
  479. if( m_tbTopAux )
  480. m_tbTopAux->UpdateControlWidths();
  481. }
  482. void EDA_BASE_FRAME::OnToolbarSizeChanged()
  483. {
  484. if( m_tbTopMain )
  485. m_auimgr.GetPane( m_tbTopMain ).MaxSize( m_tbTopMain->GetSize() );
  486. if( m_tbRight )
  487. m_auimgr.GetPane( m_tbRight ).MaxSize( m_tbRight->GetSize() );
  488. if( m_tbLeft )
  489. m_auimgr.GetPane( m_tbLeft ).MaxSize( m_tbLeft->GetSize() );
  490. if( m_tbTopAux )
  491. m_auimgr.GetPane( m_tbTopAux ).MaxSize( m_tbTopAux->GetSize() );
  492. m_auimgr.Update();
  493. }
  494. void EDA_BASE_FRAME::ReCreateMenuBar()
  495. {
  496. /**
  497. * As of wxWidgets 3.2, recreating the menubar from within an event handler of that menubar
  498. * will result in memory corruption on macOS. In order to minimize the chance of programmer
  499. * error causing regressions here, we always wrap calls to ReCreateMenuBar in a CallAfter to
  500. * ensure that they do not occur within the same event handling call stack.
  501. */
  502. CallAfter( [this]()
  503. {
  504. if( !m_isClosing )
  505. doReCreateMenuBar();
  506. } );
  507. }
  508. void EDA_BASE_FRAME::AddStandardHelpMenu( wxMenuBar* aMenuBar )
  509. {
  510. COMMON_CONTROL* commonControl = m_toolManager->GetTool<COMMON_CONTROL>();
  511. ACTION_MENU* helpMenu = new ACTION_MENU( false, commonControl );
  512. helpMenu->Add( ACTIONS::help );
  513. helpMenu->Add( ACTIONS::gettingStarted );
  514. helpMenu->Add( ACTIONS::listHotKeys );
  515. helpMenu->Add( ACTIONS::getInvolved );
  516. helpMenu->Add( ACTIONS::donate );
  517. helpMenu->Add( ACTIONS::reportBug );
  518. helpMenu->AppendSeparator();
  519. helpMenu->Add( ACTIONS::about );
  520. aMenuBar->Append( helpMenu, _( "&Help" ) );
  521. }
  522. void EDA_BASE_FRAME::ShowChangedLanguage()
  523. {
  524. TOOLS_HOLDER::ShowChangedLanguage();
  525. if( GetMenuBar() )
  526. {
  527. ReCreateMenuBar();
  528. GetMenuBar()->Refresh();
  529. }
  530. }
  531. void EDA_BASE_FRAME::CommonSettingsChanged( int aFlags )
  532. {
  533. TOOLS_HOLDER::CommonSettingsChanged( aFlags );
  534. COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
  535. #ifdef KICAD_IPC_API
  536. bool running = Pgm().GetApiServer().Running();
  537. if( running && !settings->m_Api.enable_server )
  538. Pgm().GetApiServer().Stop();
  539. else if( !running && settings->m_Api.enable_server )
  540. Pgm().GetApiServer().Start();
  541. #endif
  542. if( m_fileHistory )
  543. {
  544. int historySize = settings->m_System.file_history_size;
  545. m_fileHistory->SetMaxFiles( (unsigned) std::max( 0, historySize ) );
  546. }
  547. GetBitmapStore()->ThemeChanged();
  548. ThemeChanged();
  549. if( GetMenuBar() )
  550. {
  551. // For icons in menus, icon scaling & hotkeys
  552. ReCreateMenuBar();
  553. GetMenuBar()->Refresh();
  554. }
  555. // Update the toolbars
  556. RecreateToolbars();
  557. }
  558. void EDA_BASE_FRAME::ThemeChanged()
  559. {
  560. ClearScaledBitmapCache();
  561. // Update all the toolbars to have new icons
  562. wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
  563. for( size_t i = 0; i < panes.GetCount(); ++i )
  564. {
  565. if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
  566. toolbar->RefreshBitmaps();
  567. }
  568. }
  569. void EDA_BASE_FRAME::OnSize( wxSizeEvent& aEvent )
  570. {
  571. #ifdef __WXMAC__
  572. int currentDisplay = wxDisplay::GetFromWindow( this );
  573. if( m_displayIndex >= 0 && currentDisplay >= 0 && currentDisplay != m_displayIndex )
  574. {
  575. wxLogTrace( traceDisplayLocation, wxS( "OnSize: current display changed %d to %d" ),
  576. m_displayIndex, currentDisplay );
  577. m_displayIndex = currentDisplay;
  578. ensureWindowIsOnScreen();
  579. }
  580. #endif
  581. aEvent.Skip();
  582. }
  583. void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
  584. {
  585. if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
  586. return;
  587. const PROJECT_FILE_STATE* state = Prj().GetLocalSettings().GetFileState( aFileName );
  588. if( state != nullptr )
  589. {
  590. LoadWindowState( state->window );
  591. }
  592. }
  593. void EDA_BASE_FRAME::LoadWindowState( const WINDOW_STATE& aState )
  594. {
  595. bool wasDefault = false;
  596. m_framePos.x = aState.pos_x;
  597. m_framePos.y = aState.pos_y;
  598. m_frameSize.x = aState.size_x;
  599. m_frameSize.y = aState.size_y;
  600. wxLogTrace( traceDisplayLocation, wxS( "Config position (%d, %d) with size (%d, %d)" ),
  601. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  602. // Ensure minimum size is set if the stored config was zero-initialized
  603. wxSize minSize = minSizeLookup( m_ident, this );
  604. if( m_frameSize.x < minSize.x || m_frameSize.y < minSize.y )
  605. {
  606. m_frameSize = defaultSize( m_ident, this );
  607. wasDefault = true;
  608. wxLogTrace( traceDisplayLocation, wxS( "Using minimum size (%d, %d)" ),
  609. m_frameSize.x, m_frameSize.y );
  610. }
  611. wxLogTrace( traceDisplayLocation, wxS( "Number of displays: %d" ), wxDisplay::GetCount() );
  612. if( aState.display >= wxDisplay::GetCount() )
  613. {
  614. wxLogTrace( traceDisplayLocation, wxS( "Previous display not found" ) );
  615. // If it isn't attached, use the first display
  616. // Warning wxDisplay has 2 ctor variants. the parameter needs a type:
  617. const unsigned int index = 0;
  618. wxDisplay display( index );
  619. wxRect clientSize = display.GetGeometry();
  620. m_framePos = wxDefaultPosition;
  621. // Ensure the window fits on the display, since the other one could have been larger
  622. if( m_frameSize.x > clientSize.width )
  623. m_frameSize.x = clientSize.width;
  624. if( m_frameSize.y > clientSize.height )
  625. m_frameSize.y = clientSize.height;
  626. }
  627. else
  628. {
  629. wxPoint upperRight( m_framePos.x + m_frameSize.x, m_framePos.y );
  630. wxPoint upperLeft( m_framePos.x, m_framePos.y );
  631. wxDisplay display( aState.display );
  632. wxRect clientSize = display.GetClientArea();
  633. int yLimTop = clientSize.y;
  634. int yLimBottom = clientSize.y + clientSize.height;
  635. int xLimLeft = clientSize.x;
  636. int xLimRight = clientSize.x + clientSize.width;
  637. if( upperLeft.x > xLimRight || // Upper left corner too close to right edge of screen
  638. upperRight.x < xLimLeft || // Upper right corner too close to left edge of screen
  639. upperLeft.y < yLimTop || // Upper corner too close to the bottom of the screen
  640. upperLeft.y > yLimBottom )
  641. {
  642. m_framePos = wxDefaultPosition;
  643. wxLogTrace( traceDisplayLocation, wxS( "Resetting to default position" ) );
  644. }
  645. }
  646. wxLogTrace( traceDisplayLocation, wxS( "Final window position (%d, %d) with size (%d, %d)" ),
  647. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  648. SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  649. // Center the window if we reset to default
  650. if( m_framePos.x == -1 )
  651. {
  652. wxLogTrace( traceDisplayLocation, wxS( "Centering window" ) );
  653. Center();
  654. m_framePos = GetPosition();
  655. }
  656. // Record the frame sizes in an un-maximized state
  657. m_normalFrameSize = m_frameSize;
  658. m_normalFramePos = m_framePos;
  659. // Maximize if we were maximized before
  660. if( aState.maximized || ( wasDefault && m_maximizeByDefault ) )
  661. {
  662. wxLogTrace( traceDisplayLocation, wxS( "Maximizing window" ) );
  663. Maximize();
  664. }
  665. m_displayIndex = wxDisplay::GetFromWindow( this );
  666. }
  667. void EDA_BASE_FRAME::ensureWindowIsOnScreen()
  668. {
  669. wxDisplay display( wxDisplay::GetFromWindow( this ) );
  670. wxRect clientSize = display.GetClientArea();
  671. wxPoint pos = GetPosition();
  672. wxSize size = GetWindowSize();
  673. wxLogTrace( traceDisplayLocation,
  674. wxS( "ensureWindowIsOnScreen: clientArea (%d, %d) w %d h %d" ),
  675. clientSize.x, clientSize.y,
  676. clientSize.width, clientSize.height );
  677. if( pos.y < clientSize.y )
  678. {
  679. wxLogTrace( traceDisplayLocation,
  680. wxS( "ensureWindowIsOnScreen: y pos %d below minimum, setting to %d" ), pos.y,
  681. clientSize.y );
  682. pos.y = clientSize.y;
  683. }
  684. if( pos.x < clientSize.x )
  685. {
  686. wxLogTrace( traceDisplayLocation,
  687. wxS( "ensureWindowIsOnScreen: x pos %d is off the client rect, setting to %d" ),
  688. pos.x, clientSize.x );
  689. pos.x = clientSize.x;
  690. }
  691. if( pos.x + size.x - clientSize.x > clientSize.width )
  692. {
  693. int newWidth = clientSize.width - ( pos.x - clientSize.x );
  694. wxLogTrace( traceDisplayLocation,
  695. wxS( "ensureWindowIsOnScreen: effective width %d above available %d, setting "
  696. "to %d" ), pos.x + size.x, clientSize.width, newWidth );
  697. size.x = newWidth;
  698. }
  699. if( pos.y + size.y - clientSize.y > clientSize.height )
  700. {
  701. int newHeight = clientSize.height - ( pos.y - clientSize.y );
  702. wxLogTrace( traceDisplayLocation,
  703. wxS( "ensureWindowIsOnScreen: effective height %d above available %d, setting "
  704. "to %d" ), pos.y + size.y, clientSize.height, newHeight );
  705. size.y = newHeight;
  706. }
  707. wxLogTrace( traceDisplayLocation, wxS( "Updating window position (%d, %d) with size (%d, %d)" ),
  708. pos.x, pos.y, size.x, size.y );
  709. SetSize( pos.x, pos.y, size.x, size.y );
  710. }
  711. void EDA_BASE_FRAME::LoadWindowSettings( const WINDOW_SETTINGS* aCfg )
  712. {
  713. LoadWindowState( aCfg->state );
  714. m_perspective = aCfg->perspective;
  715. m_mruPath = aCfg->mru_path;
  716. TOOLS_HOLDER::CommonSettingsChanged();
  717. }
  718. void EDA_BASE_FRAME::SaveWindowSettings( WINDOW_SETTINGS* aCfg )
  719. {
  720. if( IsIconized() )
  721. return;
  722. // If the window is maximized, we use the saved window size from before it was maximized
  723. if( IsMaximized() )
  724. {
  725. m_framePos = m_normalFramePos;
  726. m_frameSize = m_normalFrameSize;
  727. }
  728. else
  729. {
  730. m_frameSize = GetWindowSize();
  731. m_framePos = GetPosition();
  732. }
  733. aCfg->state.pos_x = m_framePos.x;
  734. aCfg->state.pos_y = m_framePos.y;
  735. aCfg->state.size_x = m_frameSize.x;
  736. aCfg->state.size_y = m_frameSize.y;
  737. aCfg->state.maximized = IsMaximized();
  738. aCfg->state.display = wxDisplay::GetFromWindow( this );
  739. wxLogTrace( traceDisplayLocation, wxS( "Saving window maximized: %s" ),
  740. IsMaximized() ? wxS( "true" ) : wxS( "false" ) );
  741. wxLogTrace( traceDisplayLocation, wxS( "Saving config position (%d, %d) with size (%d, %d)" ),
  742. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  743. // Once this is fully implemented, wxAuiManager will be used to maintain
  744. // the persistence of the main frame and all it's managed windows and
  745. // all of the legacy frame persistence position code can be removed.
  746. aCfg->perspective = m_auimgr.SavePerspective().ToStdString();
  747. aCfg->mru_path = m_mruPath;
  748. }
  749. void EDA_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  750. {
  751. LoadWindowSettings( GetWindowSettings( aCfg ) );
  752. // Get file history size from common settings
  753. int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size;
  754. // Load the recently used files into the history menu
  755. m_fileHistory = new FILE_HISTORY( (unsigned) std::max( 1, fileHistorySize ),
  756. ID_FILE1, ID_FILE_LIST_CLEAR );
  757. m_fileHistory->Load( *aCfg );
  758. }
  759. void EDA_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  760. {
  761. wxCHECK( config(), /* void */ );
  762. SaveWindowSettings( GetWindowSettings( aCfg ) );
  763. bool fileOpen = m_isClosing && m_isNonUserClose;
  764. wxString currentlyOpenedFile = GetCurrentFileName();
  765. if( Pgm().GetCommonSettings()->m_Session.remember_open_files && !currentlyOpenedFile.IsEmpty() )
  766. {
  767. wxFileName rfn( currentlyOpenedFile );
  768. rfn.MakeRelativeTo( Prj().GetProjectPath() );
  769. Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &aCfg->m_Window, fileOpen );
  770. }
  771. // Save the recently used files list
  772. if( m_fileHistory )
  773. {
  774. // Save the currently opened file in the file history
  775. if( !currentlyOpenedFile.IsEmpty() )
  776. UpdateFileHistory( currentlyOpenedFile );
  777. m_fileHistory->Save( *aCfg );
  778. }
  779. }
  780. WINDOW_SETTINGS* EDA_BASE_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  781. {
  782. return &aCfg->m_Window;
  783. }
  784. APP_SETTINGS_BASE* EDA_BASE_FRAME::config() const
  785. {
  786. // KICAD_MANAGER_FRAME overrides this
  787. return Kiface().KifaceSettings();
  788. }
  789. const SEARCH_STACK& EDA_BASE_FRAME::sys_search()
  790. {
  791. return Kiface().KifaceSearch();
  792. }
  793. wxString EDA_BASE_FRAME::help_name()
  794. {
  795. return Kiface().GetHelpFileName();
  796. }
  797. void EDA_BASE_FRAME::PrintMsg( const wxString& text )
  798. {
  799. SetStatusText( text );
  800. }
  801. void EDA_BASE_FRAME::CreateInfoBar()
  802. {
  803. #if defined( __WXOSX_MAC__ )
  804. m_infoBar = new WX_INFOBAR( GetToolCanvas() );
  805. #else
  806. m_infoBar = new WX_INFOBAR( this, &m_auimgr );
  807. m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( wxS( "InfoBar" ) ).Top().Layer(1) );
  808. #endif
  809. }
  810. void EDA_BASE_FRAME::FinishAUIInitialization()
  811. {
  812. #if defined( __WXOSX_MAC__ )
  813. m_auimgr.Update();
  814. #else
  815. // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
  816. // hiding it.
  817. m_auimgr.Update();
  818. // We don't want the infobar displayed right away
  819. m_auimgr.GetPane( wxS( "InfoBar" ) ).Hide();
  820. m_auimgr.Update();
  821. #endif
  822. }
  823. void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
  824. WX_INFOBAR::MESSAGE_TYPE aType )
  825. {
  826. m_infoBar->RemoveAllButtons();
  827. if( aShowCloseButton )
  828. m_infoBar->AddCloseButton();
  829. GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR, aType );
  830. }
  831. void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
  832. std::function<void(void)> aCallback )
  833. {
  834. m_infoBar->RemoveAllButtons();
  835. if( aShowCloseButton )
  836. m_infoBar->AddCloseButton();
  837. if( aCallback )
  838. m_infoBar->SetCallback( aCallback );
  839. GetInfoBar()->ShowMessageFor( aErrorMsg, 6000, wxICON_ERROR );
  840. }
  841. void EDA_BASE_FRAME::ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton )
  842. {
  843. m_infoBar->RemoveAllButtons();
  844. if( aShowCloseButton )
  845. m_infoBar->AddCloseButton();
  846. GetInfoBar()->ShowMessageFor( aWarningMsg, 6000, wxICON_WARNING );
  847. }
  848. void EDA_BASE_FRAME::ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton )
  849. {
  850. m_infoBar->RemoveAllButtons();
  851. if( aShowCloseButton )
  852. m_infoBar->AddCloseButton();
  853. GetInfoBar()->ShowMessageFor( aMsg, 8000, wxICON_INFORMATION );
  854. }
  855. void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
  856. {
  857. if( !aFileHistory )
  858. aFileHistory = m_fileHistory;
  859. wxASSERT( aFileHistory );
  860. aFileHistory->AddFileToHistory( FullFileName );
  861. // Update the menubar to update the file history menu
  862. if( !m_isClosing && GetMenuBar() )
  863. {
  864. ReCreateMenuBar();
  865. GetMenuBar()->Refresh();
  866. }
  867. }
  868. wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
  869. FILE_HISTORY* aFileHistory )
  870. {
  871. if( !aFileHistory )
  872. aFileHistory = m_fileHistory;
  873. wxASSERT( aFileHistory );
  874. int baseId = aFileHistory->GetBaseId();
  875. wxASSERT( cmdId >= baseId && cmdId < baseId + (int) aFileHistory->GetCount() );
  876. unsigned i = cmdId - baseId;
  877. if( i < aFileHistory->GetCount() )
  878. {
  879. wxString fn = aFileHistory->GetHistoryFile( i );
  880. if( wxFileName::FileExists( fn ) )
  881. {
  882. return fn;
  883. }
  884. else
  885. {
  886. DisplayErrorMessage( this, wxString::Format( _( "File '%s' was not found." ), fn ) );
  887. aFileHistory->RemoveFileFromHistory( i );
  888. }
  889. }
  890. // Update the menubar to update the file history menu
  891. if( GetMenuBar() )
  892. {
  893. ReCreateMenuBar();
  894. GetMenuBar()->Refresh();
  895. }
  896. return wxEmptyString;
  897. }
  898. void EDA_BASE_FRAME::ClearFileHistory()
  899. {
  900. wxASSERT( m_fileHistory );
  901. m_fileHistory->ClearFileHistory();
  902. // Update the menubar to update the file history menu
  903. if( GetMenuBar() )
  904. {
  905. ReCreateMenuBar();
  906. GetMenuBar()->Refresh();
  907. }
  908. }
  909. void EDA_BASE_FRAME::OnKicadAbout( wxCommandEvent& event )
  910. {
  911. void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
  912. ShowAboutDialog( this );
  913. }
  914. void EDA_BASE_FRAME::OnPreferences( wxCommandEvent& event )
  915. {
  916. ShowPreferences( wxEmptyString, wxEmptyString );
  917. }
  918. void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParentPage )
  919. {
  920. PAGED_DIALOG dlg( this, _( "Preferences" ), true, true, wxEmptyString,
  921. wxWindow::FromDIP( wxSize( 980, 560 ), nullptr ) );
  922. dlg.SetEvtHandlerEnabled( false );
  923. {
  924. WX_BUSY_INDICATOR busy_cursor;
  925. WX_TREEBOOK* book = dlg.GetTreebook();
  926. PANEL_HOTKEYS_EDITOR* hotkeysPanel = new PANEL_HOTKEYS_EDITOR( this, book, false );
  927. std::vector<int> expand;
  928. wxWindow* kicadMgr_window = wxWindow::FindWindowByName( KICAD_MANAGER_FRAME_NAME );
  929. if( KICAD_MANAGER_FRAME* kicadMgr = static_cast<KICAD_MANAGER_FRAME*>( kicadMgr_window ) )
  930. {
  931. ACTION_MANAGER* actionMgr = kicadMgr->GetToolManager()->GetActionManager();
  932. for( const auto& [name, action] : actionMgr->GetActions() )
  933. hotkeysPanel->ActionsList().push_back( action );
  934. }
  935. book->AddLazyPage(
  936. []( wxWindow* aParent ) -> wxWindow*
  937. {
  938. return new PANEL_COMMON_SETTINGS( aParent );
  939. },
  940. _( "Common" ) );
  941. book->AddLazyPage(
  942. []( wxWindow* aParent ) -> wxWindow*
  943. {
  944. return new PANEL_MOUSE_SETTINGS( aParent );
  945. }, _( "Mouse and Touchpad" ) );
  946. book->AddLazyPage(
  947. [] ( wxWindow* aParent ) -> wxWindow*
  948. {
  949. return new PANEL_SPACEMOUSE( aParent );
  950. }, _( "SpaceMouse" ) );
  951. book->AddPage( hotkeysPanel, _( "Hotkeys" ) );
  952. book->AddLazyPage(
  953. []( wxWindow* aParent ) -> wxWindow*
  954. {
  955. return new PANEL_GIT_REPOS( aParent );
  956. }, _( "Version Control" ) );
  957. #ifdef KICAD_USE_SENTRY
  958. book->AddLazyPage(
  959. []( wxWindow* aParent ) -> wxWindow*
  960. {
  961. return new PANEL_DATA_COLLECTION( aParent );
  962. }, _( "Data Collection" ) );
  963. #endif
  964. #define LAZY_CTOR( key ) \
  965. [this, kiface]( wxWindow* aParent ) \
  966. { \
  967. return kiface->CreateKiWindow( aParent, key, &Kiway() ); \
  968. }
  969. // If a dll is not loaded, the loader will show an error message.
  970. try
  971. {
  972. if( KIFACE* kiface = Kiway().KiFACE( KIWAY::FACE_SCH ) )
  973. {
  974. kiface->GetActions( hotkeysPanel->ActionsList() );
  975. if( GetFrameType() == FRAME_SCH_SYMBOL_EDITOR )
  976. expand.push_back( (int) book->GetPageCount() );
  977. book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) );
  978. book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_DISP_OPTIONS ), _( "Display Options" ) );
  979. book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_GRIDS ), _( "Grids" ) );
  980. book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) );
  981. book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_COLORS ), _( "Colors" ) );
  982. if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
  983. book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_TOOLBARS ), _( "Toolbars" ) );
  984. if( GetFrameType() == FRAME_SCH )
  985. expand.push_back( (int) book->GetPageCount() );
  986. book->AddPage( new wxPanel( book ), _( "Schematic Editor" ) );
  987. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_DISP_OPTIONS ), _( "Display Options" ) );
  988. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_GRIDS ), _( "Grids" ) );
  989. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_EDIT_OPTIONS ), _( "Editing Options" ) );
  990. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_COLORS ), _( "Colors" ) );
  991. if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
  992. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_TOOLBARS ), _( "Toolbars" ) );
  993. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_FIELD_NAME_TEMPLATES ), _( "Field Name Templates" ) );
  994. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_SIMULATOR ), _( "Simulator" ) );
  995. }
  996. }
  997. catch( ... )
  998. {
  999. }
  1000. try
  1001. {
  1002. if( KIFACE* kiface = Kiway().KiFACE( KIWAY::FACE_PCB ) )
  1003. {
  1004. kiface->GetActions( hotkeysPanel->ActionsList() );
  1005. if( GetFrameType() == FRAME_FOOTPRINT_EDITOR )
  1006. expand.push_back( (int) book->GetPageCount() );
  1007. book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
  1008. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) );
  1009. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_GRIDS ), _( "Grids" ) );
  1010. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_ORIGINS_AXES ), _( "Origins & Axes" ) );
  1011. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) );
  1012. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_COLORS ), _( "Colors" ) );
  1013. if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
  1014. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_TOOLBARS ), _( "Toolbars" ) );
  1015. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_FIELDS ), _( "Footprint Defaults" ) );
  1016. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_GRAPHICS_VALUES ), _( "Graphics Defaults" ) );
  1017. if( GetFrameType() == FRAME_PCB_EDITOR )
  1018. expand.push_back( (int) book->GetPageCount() );
  1019. book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
  1020. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_DISPLAY_OPTS ), _( "Display Options" ) );
  1021. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_GRIDS ), _( "Grids" ) );
  1022. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) );
  1023. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) );
  1024. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_COLORS ), _( "Colors" ) );
  1025. if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
  1026. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_TOOLBARS ), _( "Toolbars" ) );
  1027. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ACTION_PLUGINS ), _( "Plugins" ) );
  1028. if( GetFrameType() == FRAME_PCB_DISPLAY3D )
  1029. expand.push_back( (int) book->GetPageCount() );
  1030. book->AddPage( new wxPanel( book ), _( "3D Viewer" ) );
  1031. book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) );
  1032. if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
  1033. book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_TOOLBARS ), _( "Toolbars" ) );
  1034. book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) );
  1035. book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) );
  1036. }
  1037. }
  1038. catch( ... )
  1039. {
  1040. }
  1041. try
  1042. {
  1043. if( KIFACE* kiface = Kiway().KiFACE( KIWAY::FACE_GERBVIEW ) )
  1044. {
  1045. kiface->GetActions( hotkeysPanel->ActionsList() );
  1046. if( GetFrameType() == FRAME_GERBER )
  1047. expand.push_back( (int) book->GetPageCount() );
  1048. book->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) );
  1049. book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) );
  1050. book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_COLORS ), _( "Colors" ) );
  1051. if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
  1052. book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_TOOLBARS ), _( "Toolbars" ) );
  1053. book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_GRIDS ), _( "Grids" ) );
  1054. book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_EXCELLON_OPTIONS ), _( "Excellon Options" ) );
  1055. }
  1056. }
  1057. catch( ... )
  1058. {
  1059. }
  1060. try
  1061. {
  1062. if( KIFACE* kiface = Kiway().KiFACE( KIWAY::FACE_PL_EDITOR ) )
  1063. {
  1064. kiface->GetActions( hotkeysPanel->ActionsList() );
  1065. if( GetFrameType() == FRAME_PL_EDITOR )
  1066. expand.push_back( (int) book->GetPageCount() );
  1067. book->AddPage( new wxPanel( book ), _( "Drawing Sheet Editor" ) );
  1068. book->AddLazySubPage( LAZY_CTOR( PANEL_DS_DISPLAY_OPTIONS ), _( "Display Options" ) );
  1069. book->AddLazySubPage( LAZY_CTOR( PANEL_DS_GRIDS ), _( "Grids" ) );
  1070. book->AddLazySubPage( LAZY_CTOR( PANEL_DS_COLORS ), _( "Colors" ) );
  1071. if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
  1072. book->AddLazySubPage( LAZY_CTOR( PANEL_DS_TOOLBARS ), _( "Toolbars" ) );
  1073. book->AddLazyPage(
  1074. []( wxWindow* aParent ) -> wxWindow*
  1075. {
  1076. return new PANEL_PACKAGES_AND_UPDATES( aParent );
  1077. }, _( "Packages and Updates" ) );
  1078. }
  1079. }
  1080. catch( ... )
  1081. {
  1082. }
  1083. #ifdef KICAD_IPC_API
  1084. book->AddPage( new PANEL_PLUGIN_SETTINGS( book ), _( "Plugins" ) );
  1085. #endif
  1086. book->AddPage( new PANEL_MAINTENANCE( book, this ), _( "Maintenance" ) );
  1087. // Update all of the action hotkeys. The process of loading the actions through
  1088. // the KiFACE will only get us the default hotkeys
  1089. ReadHotKeyConfigIntoActions( wxEmptyString, hotkeysPanel->ActionsList() );
  1090. for( size_t i = 0; i < book->GetPageCount(); ++i )
  1091. book->GetPage( i )->Layout();
  1092. for( int page : expand )
  1093. book->ExpandNode( page );
  1094. if( !aStartPage.IsEmpty() )
  1095. dlg.SetInitialPage( aStartPage, aStartParentPage );
  1096. dlg.SetEvtHandlerEnabled( true );
  1097. #undef LAZY_CTOR
  1098. }
  1099. if( dlg.ShowModal() == wxID_OK )
  1100. {
  1101. // Update our grids that are cached in the tool
  1102. m_toolManager->ResetTools( TOOL_BASE::REDRAW );
  1103. Pgm().GetSettingsManager().Save();
  1104. dlg.Kiway().CommonSettingsChanged( HOTKEYS_CHANGED );
  1105. }
  1106. }
  1107. void EDA_BASE_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
  1108. {
  1109. Raise();
  1110. wxString* files = aEvent.GetFiles();
  1111. for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )
  1112. {
  1113. const wxFileName fn = wxFileName( files[nb] );
  1114. wxString ext = fn.GetExt();
  1115. // Alias all gerber files as GerberFileExtension
  1116. if( FILEEXT::IsGerberFileExtension( ext ) )
  1117. ext = FILEEXT::GerberFileExtension;
  1118. if( m_acceptedExts.find( ext.ToStdString() ) != m_acceptedExts.end() )
  1119. m_AcceptedFiles.emplace_back( fn );
  1120. }
  1121. DoWithAcceptedFiles();
  1122. m_AcceptedFiles.clear();
  1123. }
  1124. void EDA_BASE_FRAME::DoWithAcceptedFiles()
  1125. {
  1126. for( const wxFileName& file : m_AcceptedFiles )
  1127. {
  1128. wxString fn = file.GetFullPath();
  1129. m_toolManager->RunAction<wxString*>( *m_acceptedExts.at( file.GetExt() ), &fn );
  1130. }
  1131. }
  1132. bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
  1133. {
  1134. wxString msg;
  1135. wxFileName fn = aFileName;
  1136. // Check for absence of a file path with a file name. Unfortunately KiCad
  1137. // uses paths relative to the current project path without the ./ part which
  1138. // confuses wxFileName. Making the file name path absolute may be less than
  1139. // elegant but it solves the problem.
  1140. if( fn.GetPath().IsEmpty() && fn.HasName() )
  1141. fn.MakeAbsolute();
  1142. wxCHECK_MSG( fn.IsOk(), false,
  1143. wxT( "File name object is invalid. Bad programmer!" ) );
  1144. wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
  1145. wxT( "File name object path <" ) + fn.GetFullPath() +
  1146. wxT( "> is not set. Bad programmer!" ) );
  1147. if( fn.IsDir() && !fn.IsDirWritable() )
  1148. {
  1149. msg.Printf( _( "Insufficient permissions to folder '%s'." ), fn.GetPath() );
  1150. }
  1151. else if( !fn.FileExists() && !fn.IsDirWritable() )
  1152. {
  1153. msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
  1154. }
  1155. else if( fn.FileExists() && !fn.IsFileWritable() )
  1156. {
  1157. msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
  1158. }
  1159. if( !msg.IsEmpty() )
  1160. {
  1161. if( aVerbose )
  1162. DisplayErrorMessage( this, msg );
  1163. return false;
  1164. }
  1165. return true;
  1166. }
  1167. void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
  1168. {
  1169. if( !Pgm().IsGUI() )
  1170. return;
  1171. wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
  1172. wxFileName autoSaveFileName = aFileName;
  1173. // Check for auto save file.
  1174. autoSaveFileName.SetName( FILEEXT::AutoSaveFilePrefix + aFileName.GetName() );
  1175. wxLogTrace( traceAutoSave,
  1176. wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
  1177. if( !autoSaveFileName.FileExists() )
  1178. return;
  1179. wxString msg = wxString::Format( _( "Well this is potentially embarrassing!\n"
  1180. "It appears that the last time you were editing\n"
  1181. "%s\n"
  1182. "KiCad exited before saving.\n"
  1183. "\n"
  1184. "Do you wish to open the auto-saved file instead?" ),
  1185. aFileName.GetFullName() );
  1186. int response = wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
  1187. this );
  1188. // Make a backup of the current file, delete the file, and rename the auto save file to
  1189. // the file name.
  1190. if( response == wxYES )
  1191. {
  1192. // Preserve the permissions of the current file
  1193. KIPLATFORM::IO::DuplicatePermissions( aFileName.GetFullPath(),
  1194. autoSaveFileName.GetFullPath() );
  1195. if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
  1196. {
  1197. wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
  1198. Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
  1199. }
  1200. }
  1201. else
  1202. {
  1203. DeleteAutoSaveFile( aFileName );
  1204. }
  1205. }
  1206. void EDA_BASE_FRAME::DeleteAutoSaveFile( const wxFileName& aFileName )
  1207. {
  1208. if( !Pgm().IsGUI() )
  1209. return;
  1210. wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
  1211. wxFileName autoSaveFn = aFileName;
  1212. autoSaveFn.SetName( FILEEXT::AutoSaveFilePrefix + aFileName.GetName() );
  1213. if( autoSaveFn.FileExists() )
  1214. {
  1215. wxLogTrace( traceAutoSave, wxT( "Removing auto save file " ) + autoSaveFn.GetFullPath() );
  1216. wxRemoveFile( autoSaveFn.GetFullPath() );
  1217. }
  1218. }
  1219. bool EDA_BASE_FRAME::IsContentModified() const
  1220. {
  1221. // This function should be overridden in child classes
  1222. return false;
  1223. }
  1224. void EDA_BASE_FRAME::initExitKey()
  1225. {
  1226. wxAcceleratorEntry entries[1];
  1227. entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
  1228. wxAcceleratorTable accel( 1, entries );
  1229. SetAcceleratorTable( accel );
  1230. }
  1231. void EDA_BASE_FRAME::ClearUndoRedoList()
  1232. {
  1233. ClearUndoORRedoList( UNDO_LIST );
  1234. ClearUndoORRedoList( REDO_LIST );
  1235. }
  1236. void EDA_BASE_FRAME::PushCommandToUndoList( PICKED_ITEMS_LIST* aNewitem )
  1237. {
  1238. m_undoList.PushCommand( aNewitem );
  1239. // Delete the extra items, if count max reached
  1240. if( m_undoRedoCountMax > 0 )
  1241. {
  1242. int extraitems = GetUndoCommandCount() - m_undoRedoCountMax;
  1243. if( extraitems > 0 )
  1244. ClearUndoORRedoList( UNDO_LIST, extraitems );
  1245. }
  1246. }
  1247. void EDA_BASE_FRAME::PushCommandToRedoList( PICKED_ITEMS_LIST* aNewitem )
  1248. {
  1249. m_redoList.PushCommand( aNewitem );
  1250. // Delete the extra items, if count max reached
  1251. if( m_undoRedoCountMax > 0 )
  1252. {
  1253. int extraitems = GetRedoCommandCount() - m_undoRedoCountMax;
  1254. if( extraitems > 0 )
  1255. ClearUndoORRedoList( REDO_LIST, extraitems );
  1256. }
  1257. }
  1258. PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromUndoList( )
  1259. {
  1260. return m_undoList.PopCommand();
  1261. }
  1262. PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromRedoList( )
  1263. {
  1264. return m_redoList.PopCommand();
  1265. }
  1266. wxString EDA_BASE_FRAME::GetUndoActionDescription() const
  1267. {
  1268. if( GetUndoCommandCount() > 0 )
  1269. return m_undoList.m_CommandsList.back()->GetDescription();
  1270. return wxEmptyString;
  1271. }
  1272. wxString EDA_BASE_FRAME::GetRedoActionDescription() const
  1273. {
  1274. if( GetRedoCommandCount() > 0 )
  1275. return m_redoList.m_CommandsList.back()->GetDescription();
  1276. return wxEmptyString;
  1277. }
  1278. void EDA_BASE_FRAME::OnModify()
  1279. {
  1280. m_autoSaveRequired = true;
  1281. }
  1282. void EDA_BASE_FRAME::ChangeUserUnits( EDA_UNITS aUnits )
  1283. {
  1284. SetUserUnits( aUnits );
  1285. unitsChangeRefresh();
  1286. wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
  1287. e.SetInt( static_cast<int>( aUnits ) );
  1288. e.SetClientData( this );
  1289. ProcessEventLocally( e );
  1290. }
  1291. void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent )
  1292. {
  1293. // When we maximize the window, we want to save the old information
  1294. // so that we can add it to the settings on next window load.
  1295. // Contrary to the documentation, this event seems to be generated
  1296. // when the window is also being unmaximized on OSX, so we only
  1297. // capture the size information when we maximize the window when on OSX.
  1298. #ifdef __WXOSX__
  1299. if( !IsMaximized() )
  1300. #endif
  1301. {
  1302. m_normalFrameSize = GetWindowSize();
  1303. m_normalFramePos = GetPosition();
  1304. wxLogTrace( traceDisplayLocation,
  1305. "Maximizing window - Saving position (%d, %d) with size (%d, %d)",
  1306. m_normalFramePos.x, m_normalFramePos.y,
  1307. m_normalFrameSize.x, m_normalFrameSize.y );
  1308. }
  1309. // Skip event to actually maximize the window
  1310. aEvent.Skip();
  1311. }
  1312. wxSize EDA_BASE_FRAME::GetWindowSize()
  1313. {
  1314. #ifdef __WXGTK__
  1315. wxSize winSize = GetSize();
  1316. // GTK includes the window decorations in the normal GetSize call,
  1317. // so we have to use a GTK-specific sizing call that returns the
  1318. // non-decorated window size.
  1319. if( m_ident == KICAD_MAIN_FRAME_T )
  1320. {
  1321. int width = 0;
  1322. int height = 0;
  1323. GTKDoGetSize( &width, &height );
  1324. winSize.Set( width, height );
  1325. }
  1326. #else
  1327. wxSize winSize = GetSize();
  1328. #endif
  1329. return winSize;
  1330. }
  1331. void EDA_BASE_FRAME::HandleSystemColorChange()
  1332. {
  1333. // Update the icon theme when the system theme changes and update the toolbars
  1334. GetBitmapStore()->ThemeChanged();
  1335. ThemeChanged();
  1336. // This isn't handled by ThemeChanged()
  1337. if( GetMenuBar() )
  1338. {
  1339. // For icons in menus, icon scaling & hotkeys
  1340. ReCreateMenuBar();
  1341. GetMenuBar()->Refresh();
  1342. }
  1343. }
  1344. void EDA_BASE_FRAME::onSystemColorChange( wxSysColourChangedEvent& aEvent )
  1345. {
  1346. // Call the handler to update the colors used in the frame
  1347. HandleSystemColorChange();
  1348. // Skip the change event to ensure the rest of the window controls get it
  1349. aEvent.Skip();
  1350. }
  1351. void EDA_BASE_FRAME::onIconize( wxIconizeEvent& aEvent )
  1352. {
  1353. // Call the handler
  1354. handleIconizeEvent( aEvent );
  1355. // Skip the event.
  1356. aEvent.Skip();
  1357. }
  1358. #ifdef __WXMSW__
  1359. WXLRESULT EDA_BASE_FRAME::MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam )
  1360. {
  1361. // This will help avoid the menu keeping focus when the alt key is released
  1362. // You can still trigger accelerators as long as you hold down alt
  1363. if( message == WM_SYSCOMMAND )
  1364. {
  1365. if( wParam == SC_KEYMENU && ( lParam >> 16 ) <= 0 )
  1366. return 0;
  1367. }
  1368. return wxFrame::MSWWindowProc( message, wParam, lParam );
  1369. }
  1370. #endif
  1371. void EDA_BASE_FRAME::AddMenuLanguageList( ACTION_MENU* aMasterMenu, TOOL_INTERACTIVE* aControlTool )
  1372. {
  1373. ACTION_MENU* langsMenu = new ACTION_MENU( false, aControlTool );
  1374. langsMenu->SetTitle( _( "Set Language" ) );
  1375. langsMenu->SetIcon( BITMAPS::language );
  1376. wxString tooltip;
  1377. for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
  1378. {
  1379. wxString label;
  1380. if( LanguagesList[ii].m_DoNotTranslate )
  1381. label = LanguagesList[ii].m_Lang_Label;
  1382. else
  1383. label = wxGetTranslation( LanguagesList[ii].m_Lang_Label );
  1384. wxMenuItem* item =
  1385. new wxMenuItem( langsMenu,
  1386. LanguagesList[ii].m_KI_Lang_Identifier, // wxMenuItem wxID
  1387. label, tooltip, wxITEM_CHECK );
  1388. langsMenu->Append( item );
  1389. }
  1390. // This must be done after the items are added
  1391. aMasterMenu->Add( langsMenu );
  1392. }