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.

1491 lines
44 KiB

3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 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
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
* 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
3 years ago
3 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
  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) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <bitmaps.h>
  26. #include <bitmap_store.h>
  27. #include <dialog_shim.h>
  28. #include <dialogs/panel_common_settings.h>
  29. #include <dialogs/panel_mouse_settings.h>
  30. #include <dialogs/panel_data_collection.h>
  31. #include <eda_dde.h>
  32. #include <file_history.h>
  33. #include <id.h>
  34. #include <kiface_base.h>
  35. #include <menus_helpers.h>
  36. #include <hotkeys_basic.h>
  37. #include <panel_hotkeys_editor.h>
  38. #include <paths.h>
  39. #include <confirm.h>
  40. #include <panel_pcm_settings.h>
  41. #include <pgm_base.h>
  42. #include <settings/app_settings.h>
  43. #include <settings/common_settings.h>
  44. #include <settings/settings_manager.h>
  45. #include <project/project_local_settings.h>
  46. #include <tool/action_manager.h>
  47. #include <tool/action_menu.h>
  48. #include <tool/action_toolbar.h>
  49. #include <tool/actions.h>
  50. #include <tool/common_control.h>
  51. #include <tool/tool_manager.h>
  52. #include <tool/tool_dispatcher.h>
  53. #include <trace_helpers.h>
  54. #include <widgets/paged_dialog.h>
  55. #include <widgets/wx_infobar.h>
  56. #include <widgets/wx_aui_art_providers.h>
  57. #include <widgets/wx_grid.h>
  58. #include <widgets/wx_treebook.h>
  59. #include <wx/app.h>
  60. #include <wx/config.h>
  61. #include <wx/display.h>
  62. #include <wx/stdpaths.h>
  63. #include <wx/string.h>
  64. #include <kiplatform/app.h>
  65. #include <kiplatform/ui.h>
  66. #include <functional>
  67. #include <kiface_ids.h>
  68. wxDEFINE_EVENT( EDA_EVT_UNITS_CHANGED, wxCommandEvent );
  69. // Minimum window size
  70. static const wxSize minSize( FRAME_T aFrameType )
  71. {
  72. switch( aFrameType )
  73. {
  74. case KICAD_MAIN_FRAME_T:
  75. return wxSize( 406, 354 );
  76. default:
  77. return wxSize( 500, 400 );
  78. }
  79. }
  80. static const wxSize defaultSize( FRAME_T aFrameType )
  81. {
  82. switch( aFrameType )
  83. {
  84. case KICAD_MAIN_FRAME_T:
  85. return wxSize( 850, 540 );
  86. default:
  87. return wxSize( 1280, 720 );
  88. }
  89. }
  90. BEGIN_EVENT_TABLE( EDA_BASE_FRAME, wxFrame )
  91. EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::OnKicadAbout )
  92. EVT_MENU( wxID_PREFERENCES, EDA_BASE_FRAME::OnPreferences )
  93. EVT_CHAR_HOOK( EDA_BASE_FRAME::OnCharHook )
  94. EVT_MENU_OPEN( EDA_BASE_FRAME::OnMenuEvent )
  95. EVT_MENU_CLOSE( EDA_BASE_FRAME::OnMenuEvent )
  96. EVT_MENU_HIGHLIGHT_ALL( EDA_BASE_FRAME::OnMenuEvent )
  97. EVT_MOVE( EDA_BASE_FRAME::OnMove )
  98. EVT_SIZE( EDA_BASE_FRAME::OnSize )
  99. EVT_MAXIMIZE( EDA_BASE_FRAME::OnMaximize )
  100. EVT_SYS_COLOUR_CHANGED( EDA_BASE_FRAME::onSystemColorChange )
  101. EVT_ICONIZE( EDA_BASE_FRAME::onIconize )
  102. END_EVENT_TABLE()
  103. void EDA_BASE_FRAME::commonInit( FRAME_T aFrameType )
  104. {
  105. m_ident = aFrameType;
  106. m_maximizeByDefault = false;
  107. m_infoBar = nullptr;
  108. m_settingsManager = nullptr;
  109. m_fileHistory = nullptr;
  110. m_supportsAutoSave = false;
  111. m_autoSavePending = false;
  112. m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
  113. m_isClosing = false;
  114. m_isNonUserClose = false;
  115. m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
  116. m_autoSaveRequired = false;
  117. m_mruPath = PATHS::GetDefaultUserProjectsPath();
  118. m_frameSize = defaultSize( aFrameType );
  119. m_displayIndex = -1;
  120. m_auimgr.SetArtProvider( new WX_AUI_DOCK_ART() );
  121. m_settingsManager = &Pgm().GetSettingsManager();
  122. // Set a reasonable minimal size for the frame
  123. SetSizeHints( minSize( aFrameType ).x, minSize( aFrameType ).y, -1, -1, -1, -1 );
  124. // Store dimensions of the user area of the main window.
  125. GetClientSize( &m_frameSize.x, &m_frameSize.y );
  126. Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
  127. wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
  128. // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems
  129. // to be called before any other hook for wxCloseEvent, which is necessary.
  130. Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
  131. initExitKey();
  132. }
  133. EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
  134. const wxPoint& aPos, const wxSize& aSize, long aStyle,
  135. const wxString& aFrameName, KIWAY* aKiway,
  136. const EDA_IU_SCALE& aIuScale ) :
  137. wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
  138. TOOLS_HOLDER(),
  139. KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ),
  140. UNITS_PROVIDER( aIuScale, EDA_UNITS::MILLIMETRES )
  141. {
  142. commonInit( aFrameType );
  143. }
  144. wxWindow* EDA_BASE_FRAME::findQuasiModalDialog()
  145. {
  146. for( wxWindow* iter : GetChildren() )
  147. {
  148. DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( iter );
  149. if( dlg && dlg->IsQuasiModal() )
  150. return dlg;
  151. }
  152. // FIXME: CvPcb is currently implemented on top of KIWAY_PLAYER rather than DIALOG_SHIM,
  153. // so we have to look for it separately.
  154. if( m_ident == FRAME_SCH )
  155. {
  156. wxWindow* cvpcb = wxWindow::FindWindowByName( wxS( "CvpcbFrame" ) );
  157. if( cvpcb )
  158. return cvpcb;
  159. }
  160. return nullptr;
  161. }
  162. void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
  163. {
  164. // Don't allow closing when a quasi-modal is open.
  165. wxWindow* quasiModal = findQuasiModalDialog();
  166. if( quasiModal )
  167. {
  168. // Raise and notify; don't give the user a warning regarding "quasi-modal dialogs"
  169. // when they have no idea what those are.
  170. quasiModal->Raise();
  171. wxBell();
  172. if( event.CanVeto() )
  173. event.Veto();
  174. return;
  175. }
  176. if( event.GetId() == wxEVT_QUERY_END_SESSION
  177. || event.GetId() == wxEVT_END_SESSION )
  178. {
  179. // End session means the OS is going to terminate us
  180. m_isNonUserClose = true;
  181. }
  182. if( canCloseWindow( event ) )
  183. {
  184. m_isClosing = true;
  185. if( m_infoBar )
  186. m_infoBar->Dismiss();
  187. APP_SETTINGS_BASE* cfg = config();
  188. if( cfg )
  189. SaveSettings( cfg ); // virtual, wxFrame specific
  190. doCloseWindow();
  191. // Destroy (safe delete frame) this frame only in non modal mode.
  192. // In modal mode, the caller will call Destroy().
  193. if( !IsModal() )
  194. Destroy();
  195. }
  196. else
  197. {
  198. if( event.CanVeto() )
  199. event.Veto();
  200. }
  201. }
  202. EDA_BASE_FRAME::~EDA_BASE_FRAME()
  203. {
  204. delete m_autoSaveTimer;
  205. delete m_fileHistory;
  206. ClearUndoRedoList();
  207. SocketCleanup();
  208. KIPLATFORM::APP::RemoveShutdownBlockReason( this );
  209. }
  210. bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
  211. {
  212. #ifdef __WXMAC__
  213. // Apple in its infinite wisdom will raise a disabled window before even passing
  214. // us the event, so we have no way to stop it. Instead, we have to catch an
  215. // improperly ordered disabled window and quasi-modal dialog here and reorder
  216. // them.
  217. if( !IsEnabled() && IsActive() )
  218. {
  219. wxWindow* dlg = findQuasiModalDialog();
  220. if( dlg )
  221. dlg->Raise();
  222. }
  223. #endif
  224. if( !wxFrame::ProcessEvent( aEvent ) )
  225. return false;
  226. if( Pgm().m_Quitting )
  227. return true;
  228. if( !m_isClosing && m_supportsAutoSave && IsShown() && IsActive()
  229. && m_autoSavePending != isAutoSaveRequired()
  230. && GetAutoSaveInterval() > 0 )
  231. {
  232. if( !m_autoSavePending )
  233. {
  234. wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
  235. m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
  236. m_autoSavePending = true;
  237. }
  238. else if( m_autoSaveTimer->IsRunning() )
  239. {
  240. wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
  241. m_autoSaveTimer->Stop();
  242. m_autoSavePending = false;
  243. }
  244. }
  245. return true;
  246. }
  247. int EDA_BASE_FRAME::GetAutoSaveInterval() const
  248. {
  249. return Pgm().GetCommonSettings()->m_System.autosave_interval;
  250. }
  251. void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent )
  252. {
  253. // Don't stomp on someone else's timer event.
  254. if( aEvent.GetId() != ID_AUTO_SAVE_TIMER )
  255. {
  256. aEvent.Skip();
  257. return;
  258. }
  259. if( !doAutoSave() )
  260. m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
  261. }
  262. bool EDA_BASE_FRAME::doAutoSave()
  263. {
  264. wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
  265. }
  266. void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& aKeyEvent )
  267. {
  268. wxLogTrace( kicadTraceKeyEvent, wxS( "EDA_BASE_FRAME::OnCharHook %s" ), dump( aKeyEvent ) );
  269. // Key events can be filtered here.
  270. // Currently no filtering is made.
  271. aKeyEvent.Skip();
  272. }
  273. void EDA_BASE_FRAME::OnMenuEvent( wxMenuEvent& aEvent )
  274. {
  275. if( !m_toolDispatcher )
  276. aEvent.Skip();
  277. else
  278. m_toolDispatcher->DispatchWxEvent( aEvent );
  279. }
  280. void EDA_BASE_FRAME::RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions )
  281. {
  282. UIUpdateHandler evtFunc = std::bind( &EDA_BASE_FRAME::HandleUpdateUIEvent,
  283. std::placeholders::_1,
  284. this,
  285. aConditions );
  286. m_uiUpdateMap[aID] = evtFunc;
  287. Bind( wxEVT_UPDATE_UI, evtFunc, aID );
  288. }
  289. void EDA_BASE_FRAME::UnregisterUIUpdateHandler( int aID )
  290. {
  291. const auto it = m_uiUpdateMap.find( aID );
  292. if( it == m_uiUpdateMap.end() )
  293. return;
  294. Unbind( wxEVT_UPDATE_UI, it->second, aID );
  295. }
  296. void EDA_BASE_FRAME::HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
  297. ACTION_CONDITIONS aCond )
  298. {
  299. bool checkRes = false;
  300. bool enableRes = true;
  301. bool showRes = true;
  302. bool isCut = aEvent.GetId() == ACTIONS::cut.GetUIId();
  303. bool isCopy = aEvent.GetId() == ACTIONS::copy.GetUIId();
  304. bool isPaste = aEvent.GetId() == ACTIONS::paste.GetUIId();
  305. SELECTION& selection = aFrame->GetCurrentSelection();
  306. try
  307. {
  308. checkRes = aCond.checkCondition( selection );
  309. enableRes = aCond.enableCondition( selection );
  310. showRes = aCond.showCondition( selection );
  311. }
  312. catch( std::exception& )
  313. {
  314. // Something broke with the conditions, just skip the event.
  315. aEvent.Skip();
  316. return;
  317. }
  318. if( isCut || isCopy || isPaste )
  319. {
  320. wxWindow* focus = wxWindow::FindFocus();
  321. wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
  322. if( textEntry && isCut && textEntry->CanCut() )
  323. enableRes = true;
  324. else if( textEntry && isCopy && textEntry->CanCopy() )
  325. enableRes = true;
  326. else if( textEntry && isPaste && textEntry->CanPaste() )
  327. enableRes = true;
  328. else if( dynamic_cast<WX_GRID*>( focus ) )
  329. enableRes = false; // Must disable menu in order to get command as CharHook event
  330. }
  331. aEvent.Enable( enableRes );
  332. aEvent.Show( showRes );
  333. // wxWidgets 3.1.5+ includes a field in the event that says if the event supports being
  334. // checked, since wxMenuItems don't want to be checked unless they actually are checkable
  335. #if wxCHECK_VERSION( 3, 1, 5 )
  336. if( aEvent.IsCheckable() )
  337. aEvent.Check( checkRes );
  338. #else
  339. bool canCheck = true;
  340. // wxMenuItems don't want to be checked unless they actually are checkable, so we have to
  341. // check to see if they can be and can't just universally apply a check in this event.
  342. if( wxMenu* menu = dynamic_cast<wxMenu*>( aEvent.GetEventObject() ) )
  343. canCheck = menu->FindItem( aEvent.GetId() )->IsCheckable();
  344. if( canCheck )
  345. aEvent.Check( checkRes );
  346. #endif
  347. }
  348. void EDA_BASE_FRAME::setupUIConditions()
  349. {
  350. // Setup the conditions to check a language menu item
  351. auto isCurrentLang =
  352. [] ( const SELECTION& aSel, int aLangIdentifier )
  353. {
  354. return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
  355. };
  356. for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
  357. {
  358. ACTION_CONDITIONS cond;
  359. cond.Check( std::bind( isCurrentLang, std::placeholders::_1,
  360. LanguagesList[ii].m_WX_Lang_Identifier ) );
  361. RegisterUIUpdateHandler( LanguagesList[ii].m_KI_Lang_Identifier, cond );
  362. }
  363. }
  364. void EDA_BASE_FRAME::ReCreateMenuBar()
  365. {
  366. /**
  367. * As of wxWidgets 3.2, recreating the menubar from within an event handler of that menubar
  368. * will result in memory corruption on macOS. In order to minimize the chance of programmer
  369. * error causing regressions here, we always wrap calls to ReCreateMenuBar in a CallAfter to
  370. * ensure that they do not occur within the same event handling call stack.
  371. */
  372. CallAfter( [=]()
  373. {
  374. doReCreateMenuBar();
  375. } );
  376. }
  377. void EDA_BASE_FRAME::AddStandardHelpMenu( wxMenuBar* aMenuBar )
  378. {
  379. COMMON_CONTROL* commonControl = m_toolManager->GetTool<COMMON_CONTROL>();
  380. ACTION_MENU* helpMenu = new ACTION_MENU( false, commonControl );
  381. helpMenu->Add( ACTIONS::help );
  382. helpMenu->Add( ACTIONS::gettingStarted );
  383. helpMenu->Add( ACTIONS::listHotKeys );
  384. helpMenu->Add( ACTIONS::getInvolved );
  385. helpMenu->Add( ACTIONS::donate );
  386. helpMenu->Add( ACTIONS::reportBug );
  387. helpMenu->AppendSeparator();
  388. helpMenu->Add( _( "&About KiCad" ), "", wxID_ABOUT, BITMAPS::about );
  389. // Trailing space keeps OSX from hijacking our menu (and disabling everything in it).
  390. aMenuBar->Append( helpMenu, _( "&Help" ) + wxS( " " ) );
  391. }
  392. void EDA_BASE_FRAME::ShowChangedLanguage()
  393. {
  394. TOOLS_HOLDER::ShowChangedLanguage();
  395. if( GetMenuBar() )
  396. {
  397. ReCreateMenuBar();
  398. GetMenuBar()->Refresh();
  399. }
  400. }
  401. void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  402. {
  403. TOOLS_HOLDER::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  404. COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
  405. if( m_fileHistory )
  406. {
  407. int historySize = settings->m_System.file_history_size;
  408. m_fileHistory->SetMaxFiles( (unsigned) std::max( 0, historySize ) );
  409. }
  410. GetBitmapStore()->ThemeChanged();
  411. ThemeChanged();
  412. if( GetMenuBar() )
  413. {
  414. // For icons in menus, icon scaling & hotkeys
  415. ReCreateMenuBar();
  416. GetMenuBar()->Refresh();
  417. }
  418. }
  419. void EDA_BASE_FRAME::ThemeChanged()
  420. {
  421. ClearScaledBitmapCache();
  422. // Update all the toolbars to have new icons
  423. wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
  424. for( size_t i = 0; i < panes.GetCount(); ++i )
  425. {
  426. if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
  427. toolbar->RefreshBitmaps();
  428. }
  429. }
  430. void EDA_BASE_FRAME::OnSize( wxSizeEvent& aEvent )
  431. {
  432. #ifdef __WXMAC__
  433. int currentDisplay = wxDisplay::GetFromWindow( this );
  434. if( m_displayIndex >= 0 && currentDisplay >= 0 && currentDisplay != m_displayIndex )
  435. {
  436. wxLogTrace( traceDisplayLocation, wxS( "OnSize: current display changed %d to %d" ),
  437. m_displayIndex, currentDisplay );
  438. m_displayIndex = currentDisplay;
  439. ensureWindowIsOnScreen();
  440. }
  441. #endif
  442. aEvent.Skip();
  443. }
  444. void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
  445. {
  446. if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
  447. return;
  448. const PROJECT_FILE_STATE* state = Prj().GetLocalSettings().GetFileState( aFileName );
  449. if( state != nullptr )
  450. {
  451. LoadWindowState( state->window );
  452. }
  453. }
  454. void EDA_BASE_FRAME::LoadWindowState( const WINDOW_STATE& aState )
  455. {
  456. bool wasDefault = false;
  457. m_framePos.x = aState.pos_x;
  458. m_framePos.y = aState.pos_y;
  459. m_frameSize.x = aState.size_x;
  460. m_frameSize.y = aState.size_y;
  461. wxLogTrace( traceDisplayLocation, wxS( "Config position (%d, %d) with size (%d, %d)" ),
  462. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  463. // Ensure minimum size is set if the stored config was zero-initialized
  464. if( m_frameSize.x < minSize( m_ident ).x || m_frameSize.y < minSize( m_ident ).y )
  465. {
  466. m_frameSize = defaultSize( m_ident );
  467. wasDefault = true;
  468. wxLogTrace( traceDisplayLocation, wxS( "Using minimum size (%d, %d)" ),
  469. m_frameSize.x, m_frameSize.y );
  470. }
  471. wxLogTrace( traceDisplayLocation, wxS( "Number of displays: %d" ), wxDisplay::GetCount() );
  472. if( aState.display >= wxDisplay::GetCount() )
  473. {
  474. wxLogTrace( traceDisplayLocation, wxS( "Previous display not found" ) );
  475. // If it isn't attached, use the first display
  476. // Warning wxDisplay has 2 ctor variants. the parameter needs a type:
  477. const unsigned int index = 0;
  478. wxDisplay display( index );
  479. wxRect clientSize = display.GetGeometry();
  480. m_framePos = wxDefaultPosition;
  481. // Ensure the window fits on the display, since the other one could have been larger
  482. if( m_frameSize.x > clientSize.width )
  483. m_frameSize.x = clientSize.width;
  484. if( m_frameSize.y > clientSize.height )
  485. m_frameSize.y = clientSize.height;
  486. }
  487. else
  488. {
  489. wxPoint upperRight( m_framePos.x + m_frameSize.x, m_framePos.y );
  490. wxPoint upperLeft( m_framePos.x, m_framePos.y );
  491. wxDisplay display( aState.display );
  492. wxRect clientSize = display.GetClientArea();
  493. int yLimTop = clientSize.y;
  494. int yLimBottom = clientSize.y + clientSize.height;
  495. int xLimLeft = clientSize.x;
  496. int xLimRight = clientSize.x + clientSize.width;
  497. if( upperLeft.x > xLimRight || // Upper left corner too close to right edge of screen
  498. upperRight.x < xLimLeft || // Upper right corner too close to left edge of screen
  499. upperLeft.y < yLimTop || // Upper corner too close to the bottom of the screen
  500. upperLeft.y > yLimBottom )
  501. {
  502. m_framePos = wxDefaultPosition;
  503. wxLogTrace( traceDisplayLocation, wxS( "Resetting to default position" ) );
  504. }
  505. }
  506. wxLogTrace( traceDisplayLocation, wxS( "Final window position (%d, %d) with size (%d, %d)" ),
  507. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  508. SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  509. // Center the window if we reset to default
  510. if( m_framePos.x == -1 )
  511. {
  512. wxLogTrace( traceDisplayLocation, wxS( "Centering window" ) );
  513. Center();
  514. m_framePos = GetPosition();
  515. }
  516. // Record the frame sizes in an un-maximized state
  517. m_normalFrameSize = m_frameSize;
  518. m_normalFramePos = m_framePos;
  519. // Maximize if we were maximized before
  520. if( aState.maximized || ( wasDefault && m_maximizeByDefault ) )
  521. {
  522. wxLogTrace( traceDisplayLocation, wxS( "Maximizing window" ) );
  523. Maximize();
  524. }
  525. m_displayIndex = wxDisplay::GetFromWindow( this );
  526. }
  527. void EDA_BASE_FRAME::ensureWindowIsOnScreen()
  528. {
  529. wxDisplay display( wxDisplay::GetFromWindow( this ) );
  530. wxRect clientSize = display.GetClientArea();
  531. wxPoint pos = GetPosition();
  532. wxSize size = GetWindowSize();
  533. wxLogTrace( traceDisplayLocation,
  534. wxS( "ensureWindowIsOnScreen: clientArea (%d, %d) w %d h %d" ),
  535. clientSize.x, clientSize.y,
  536. clientSize.width, clientSize.height );
  537. if( pos.y < clientSize.y )
  538. {
  539. wxLogTrace( traceDisplayLocation,
  540. wxS( "ensureWindowIsOnScreen: y pos %d below minimum, setting to %d" ), pos.y,
  541. clientSize.y );
  542. pos.y = clientSize.y;
  543. }
  544. if( pos.x < clientSize.x )
  545. {
  546. wxLogTrace( traceDisplayLocation,
  547. wxS( "ensureWindowIsOnScreen: x pos %d is off the client rect, setting to %d" ),
  548. pos.x, clientSize.x );
  549. pos.x = clientSize.x;
  550. }
  551. if( pos.x + size.x - clientSize.x > clientSize.width )
  552. {
  553. int newWidth = clientSize.width - ( pos.x - clientSize.x );
  554. wxLogTrace( traceDisplayLocation,
  555. wxS( "ensureWindowIsOnScreen: effective width %d above available %d, setting "
  556. "to %d" ), pos.x + size.x, clientSize.width, newWidth );
  557. size.x = newWidth;
  558. }
  559. if( pos.y + size.y - clientSize.y > clientSize.height )
  560. {
  561. int newHeight = clientSize.height - ( pos.y - clientSize.y );
  562. wxLogTrace( traceDisplayLocation,
  563. wxS( "ensureWindowIsOnScreen: effective height %d above available %d, setting "
  564. "to %d" ), pos.y + size.y, clientSize.height, newHeight );
  565. size.y = newHeight;
  566. }
  567. wxLogTrace( traceDisplayLocation, wxS( "Updating window position (%d, %d) with size (%d, %d)" ),
  568. pos.x, pos.y, size.x, size.y );
  569. SetSize( pos.x, pos.y, size.x, size.y );
  570. }
  571. void EDA_BASE_FRAME::LoadWindowSettings( const WINDOW_SETTINGS* aCfg )
  572. {
  573. LoadWindowState( aCfg->state );
  574. m_perspective = aCfg->perspective;
  575. m_mruPath = aCfg->mru_path;
  576. TOOLS_HOLDER::CommonSettingsChanged( false, false );
  577. }
  578. void EDA_BASE_FRAME::SaveWindowSettings( WINDOW_SETTINGS* aCfg )
  579. {
  580. if( IsIconized() )
  581. return;
  582. // If the window is maximized, we use the saved window size from before it was maximized
  583. if( IsMaximized() )
  584. {
  585. m_framePos = m_normalFramePos;
  586. m_frameSize = m_normalFrameSize;
  587. }
  588. else
  589. {
  590. m_frameSize = GetWindowSize();
  591. m_framePos = GetPosition();
  592. }
  593. aCfg->state.pos_x = m_framePos.x;
  594. aCfg->state.pos_y = m_framePos.y;
  595. aCfg->state.size_x = m_frameSize.x;
  596. aCfg->state.size_y = m_frameSize.y;
  597. aCfg->state.maximized = IsMaximized();
  598. aCfg->state.display = wxDisplay::GetFromWindow( this );
  599. wxLogTrace( traceDisplayLocation, wxS( "Saving window maximized: %s" ),
  600. IsMaximized() ? wxS( "true" ) : wxS( "false" ) );
  601. wxLogTrace( traceDisplayLocation, wxS( "Saving config position (%d, %d) with size (%d, %d)" ),
  602. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  603. // Once this is fully implemented, wxAuiManager will be used to maintain
  604. // the persistence of the main frame and all it's managed windows and
  605. // all of the legacy frame persistence position code can be removed.
  606. aCfg->perspective = m_auimgr.SavePerspective().ToStdString();
  607. aCfg->mru_path = m_mruPath;
  608. }
  609. void EDA_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  610. {
  611. LoadWindowSettings( GetWindowSettings( aCfg ) );
  612. // Get file history size from common settings
  613. int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size;
  614. // Load the recently used files into the history menu
  615. m_fileHistory = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ),
  616. ID_FILE1, ID_FILE_LIST_CLEAR );
  617. m_fileHistory->Load( *aCfg );
  618. }
  619. void EDA_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  620. {
  621. wxCHECK( config(), /* void */ );
  622. SaveWindowSettings( GetWindowSettings( aCfg ) );
  623. bool fileOpen = m_isClosing && m_isNonUserClose;
  624. wxString currentlyOpenedFile = GetCurrentFileName();
  625. if( Pgm().GetCommonSettings()->m_Session.remember_open_files && !currentlyOpenedFile.IsEmpty() )
  626. {
  627. wxFileName rfn( currentlyOpenedFile );
  628. rfn.MakeRelativeTo( Prj().GetProjectPath() );
  629. Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &aCfg->m_Window, fileOpen );
  630. }
  631. // Save the recently used files list
  632. if( m_fileHistory )
  633. {
  634. // Save the currently opened file in the file history
  635. if( !currentlyOpenedFile.IsEmpty() )
  636. UpdateFileHistory( currentlyOpenedFile );
  637. m_fileHistory->Save( *aCfg );
  638. }
  639. }
  640. WINDOW_SETTINGS* EDA_BASE_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  641. {
  642. return &aCfg->m_Window;
  643. }
  644. APP_SETTINGS_BASE* EDA_BASE_FRAME::config() const
  645. {
  646. // KICAD_MANAGER_FRAME overrides this
  647. return Kiface().KifaceSettings();
  648. }
  649. const SEARCH_STACK& EDA_BASE_FRAME::sys_search()
  650. {
  651. return Kiface().KifaceSearch();
  652. }
  653. wxString EDA_BASE_FRAME::help_name()
  654. {
  655. return Kiface().GetHelpFileName();
  656. }
  657. void EDA_BASE_FRAME::PrintMsg( const wxString& text )
  658. {
  659. SetStatusText( text );
  660. }
  661. void EDA_BASE_FRAME::CreateInfoBar()
  662. {
  663. #if defined( __WXOSX_MAC__ )
  664. m_infoBar = new WX_INFOBAR( GetToolCanvas() );
  665. #else
  666. m_infoBar = new WX_INFOBAR( this, &m_auimgr );
  667. m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( wxS( "InfoBar" ) ).Top().Layer(1) );
  668. #endif
  669. }
  670. void EDA_BASE_FRAME::FinishAUIInitialization()
  671. {
  672. #if defined( __WXOSX_MAC__ )
  673. m_auimgr.Update();
  674. #else
  675. // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
  676. // hiding it.
  677. m_auimgr.Update();
  678. // We don't want the infobar displayed right away
  679. m_auimgr.GetPane( wxS( "InfoBar" ) ).Hide();
  680. m_auimgr.Update();
  681. #endif
  682. }
  683. void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
  684. WX_INFOBAR::MESSAGE_TYPE aType )
  685. {
  686. m_infoBar->RemoveAllButtons();
  687. if( aShowCloseButton )
  688. m_infoBar->AddCloseButton();
  689. GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR, aType );
  690. }
  691. void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
  692. std::function<void(void)> aCallback )
  693. {
  694. m_infoBar->RemoveAllButtons();
  695. if( aShowCloseButton )
  696. m_infoBar->AddCloseButton();
  697. if( aCallback )
  698. m_infoBar->SetCallback( aCallback );
  699. GetInfoBar()->ShowMessageFor( aErrorMsg, 6000, wxICON_ERROR );
  700. }
  701. void EDA_BASE_FRAME::ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton )
  702. {
  703. m_infoBar->RemoveAllButtons();
  704. if( aShowCloseButton )
  705. m_infoBar->AddCloseButton();
  706. GetInfoBar()->ShowMessageFor( aWarningMsg, 6000, wxICON_WARNING );
  707. }
  708. void EDA_BASE_FRAME::ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton )
  709. {
  710. m_infoBar->RemoveAllButtons();
  711. if( aShowCloseButton )
  712. m_infoBar->AddCloseButton();
  713. GetInfoBar()->ShowMessageFor( aMsg, 8000, wxICON_INFORMATION );
  714. }
  715. void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
  716. {
  717. if( !aFileHistory )
  718. aFileHistory = m_fileHistory;
  719. wxASSERT( aFileHistory );
  720. aFileHistory->AddFileToHistory( FullFileName );
  721. // Update the menubar to update the file history menu
  722. if( !m_isClosing && GetMenuBar() )
  723. {
  724. ReCreateMenuBar();
  725. GetMenuBar()->Refresh();
  726. }
  727. }
  728. wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
  729. FILE_HISTORY* aFileHistory )
  730. {
  731. if( !aFileHistory )
  732. aFileHistory = m_fileHistory;
  733. wxASSERT( aFileHistory );
  734. int baseId = aFileHistory->GetBaseId();
  735. wxASSERT( cmdId >= baseId && cmdId < baseId + (int) aFileHistory->GetCount() );
  736. unsigned i = cmdId - baseId;
  737. if( i < aFileHistory->GetCount() )
  738. {
  739. wxString fn = aFileHistory->GetHistoryFile( i );
  740. if( wxFileName::FileExists( fn ) )
  741. {
  742. return fn;
  743. }
  744. else
  745. {
  746. DisplayErrorMessage( this, wxString::Format( _( "File '%s' was not found." ), fn ) );
  747. aFileHistory->RemoveFileFromHistory( i );
  748. }
  749. }
  750. // Update the menubar to update the file history menu
  751. if( GetMenuBar() )
  752. {
  753. ReCreateMenuBar();
  754. GetMenuBar()->Refresh();
  755. }
  756. return wxEmptyString;
  757. }
  758. void EDA_BASE_FRAME::ClearFileHistory( FILE_HISTORY* aFileHistory )
  759. {
  760. if( !aFileHistory )
  761. aFileHistory = m_fileHistory;
  762. wxASSERT( aFileHistory );
  763. aFileHistory->ClearFileHistory();
  764. // Update the menubar to update the file history menu
  765. if( GetMenuBar() )
  766. {
  767. ReCreateMenuBar();
  768. GetMenuBar()->Refresh();
  769. }
  770. }
  771. void EDA_BASE_FRAME::OnKicadAbout( wxCommandEvent& event )
  772. {
  773. void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
  774. ShowAboutDialog( this );
  775. }
  776. void EDA_BASE_FRAME::OnPreferences( wxCommandEvent& event )
  777. {
  778. ShowPreferences( wxEmptyString, wxEmptyString );
  779. }
  780. void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParentPage )
  781. {
  782. wxBeginBusyCursor( wxHOURGLASS_CURSOR );
  783. PAGED_DIALOG dlg( this, _( "Preferences" ), true );
  784. dlg.SetEvtHandlerEnabled( false );
  785. WX_TREEBOOK* book = dlg.GetTreebook();
  786. PANEL_HOTKEYS_EDITOR* hotkeysPanel = new PANEL_HOTKEYS_EDITOR( this, book, false );
  787. KIFACE* kiface = nullptr;
  788. std::vector<int> expand;
  789. Kiway().GetActions( hotkeysPanel->ActionsList() );
  790. book->AddLazyPage(
  791. []( wxWindow* aParent ) -> wxWindow*
  792. {
  793. return new PANEL_COMMON_SETTINGS( aParent );
  794. },
  795. _( "Common" ) );
  796. book->AddLazyPage(
  797. []( wxWindow* aParent ) -> wxWindow*
  798. {
  799. return new PANEL_MOUSE_SETTINGS( aParent );
  800. }, _( "Mouse and Touchpad" ) );
  801. book->AddPage( hotkeysPanel, _( "Hotkeys" ) );
  802. #ifdef KICAD_USE_SENTRY
  803. book->AddLazyPage(
  804. []( wxWindow* aParent ) -> wxWindow*
  805. {
  806. return new PANEL_DATA_COLLECTION( aParent );
  807. }, _( "Data Collection" ) );
  808. #endif
  809. #define LAZY_CTOR( key ) \
  810. [=]( wxWindow* aParent ) \
  811. { \
  812. return kiface->CreateKiWindow( aParent, key, &Kiway() ); \
  813. }
  814. // If a dll is not loaded, the loader will show an error message.
  815. try
  816. {
  817. kiface = Kiway().KiFACE( KIWAY::FACE_SCH );
  818. kiface->GetActions( hotkeysPanel->ActionsList() );
  819. if( GetFrameType() == FRAME_SCH_SYMBOL_EDITOR )
  820. expand.push_back( book->GetPageCount() );
  821. book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) );
  822. book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_DISP_OPTIONS ), _( "Display Options" ) );
  823. book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) );
  824. book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_COLORS ), _( "Colors" ) );
  825. if( GetFrameType() == FRAME_SCH )
  826. expand.push_back( book->GetPageCount() );
  827. book->AddPage( new wxPanel( book ), _( "Schematic Editor" ) );
  828. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_DISP_OPTIONS ), _( "Display Options" ) );
  829. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_EDIT_OPTIONS ), _( "Editing Options" ) );
  830. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_ANNO_OPTIONS ), _( "Annotation Options" ) );
  831. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_COLORS ), _( "Colors" ) );
  832. book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_FIELD_NAME_TEMPLATES ), _( "Field Name Templates" ) );
  833. }
  834. catch( ... )
  835. {
  836. }
  837. try
  838. {
  839. kiface = Kiway().KiFACE( KIWAY::FACE_PCB );
  840. kiface->GetActions( hotkeysPanel->ActionsList() );
  841. if( GetFrameType() == FRAME_FOOTPRINT_EDITOR )
  842. expand.push_back( book->GetPageCount() );
  843. book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
  844. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) );
  845. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) );
  846. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_COLORS ), _( "Colors" ) );
  847. book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_VALUES ), _( "Default Values" ) );
  848. if( GetFrameType() == FRAME_PCB_EDITOR )
  849. expand.push_back( book->GetPageCount() );
  850. book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
  851. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_DISPLAY_OPTIONS ), _( "Display Options" ) );
  852. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) );
  853. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_COLORS ), _( "Colors" ) );
  854. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ACTION_PLUGINS ), _( "Action Plugins" ) );
  855. book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) );
  856. if( GetFrameType() == FRAME_PCB_DISPLAY3D )
  857. expand.push_back( book->GetPageCount() );
  858. book->AddPage( new wxPanel( book ), _( "3D Viewer" ) );
  859. book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) );
  860. book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) );
  861. book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) );
  862. book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_COLORS ), _( "Colors" ) );
  863. }
  864. catch( ... )
  865. {
  866. }
  867. try
  868. {
  869. kiface = Kiway().KiFACE( KIWAY::FACE_GERBVIEW );
  870. kiface->GetActions( hotkeysPanel->ActionsList() );
  871. if( GetFrameType() == FRAME_GERBER )
  872. expand.push_back( book->GetPageCount() );
  873. book->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) );
  874. book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) );
  875. book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_COLORS ), _( "Colors" ) );
  876. book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_EXCELLON_OPTIONS ), _( "Excellon Options" ) );
  877. }
  878. catch( ... )
  879. {
  880. }
  881. try
  882. {
  883. kiface = Kiway().KiFACE( KIWAY::FACE_PL_EDITOR );
  884. kiface->GetActions( hotkeysPanel->ActionsList() );
  885. if( GetFrameType() == FRAME_PL_EDITOR )
  886. expand.push_back( book->GetPageCount() );
  887. book->AddPage( new wxPanel( book ), _( "Drawing Sheet Editor" ) );
  888. book->AddLazySubPage( LAZY_CTOR( PANEL_DS_DISPLAY_OPTIONS ), _( "Display Options" ) );
  889. book->AddLazySubPage( LAZY_CTOR( PANEL_DS_COLORS ), _( "Colors" ) );
  890. book->AddLazyPage(
  891. []( wxWindow* aParent ) -> wxWindow*
  892. {
  893. return new PANEL_PCM_SETTINGS( aParent );
  894. }, _( "Plugin and Content Manager" ) );
  895. }
  896. catch( ... )
  897. {
  898. }
  899. // Update all of the action hotkeys. The process of loading the actions through
  900. // the KiFACE will only get us the default hotkeys
  901. ReadHotKeyConfigIntoActions( wxEmptyString, hotkeysPanel->ActionsList() );
  902. for( size_t i = 0; i < book->GetPageCount(); ++i )
  903. book->GetPage( i )->Layout();
  904. for( int page : expand )
  905. book->ExpandNode( page );
  906. if( !aStartPage.IsEmpty() )
  907. dlg.SetInitialPage( aStartPage, aStartParentPage );
  908. dlg.SetEvtHandlerEnabled( true );
  909. wxEndBusyCursor();
  910. if( dlg.ShowModal() == wxID_OK )
  911. {
  912. Pgm().GetSettingsManager().Save();
  913. dlg.Kiway().CommonSettingsChanged( false, false );
  914. }
  915. #undef LAZY_CTOR
  916. }
  917. void EDA_BASE_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
  918. {
  919. wxString* files = aEvent.GetFiles();
  920. for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )
  921. {
  922. const wxFileName fn = wxFileName( files[nb] );
  923. wxString ext = fn.GetExt();
  924. // Alias all gerber files as GerberFileExtension
  925. if( IsGerberFileExtension( ext ) )
  926. ext = GerberFileExtension;
  927. if( m_acceptedExts.find( ext.ToStdString() ) != m_acceptedExts.end() )
  928. m_AcceptedFiles.emplace_back( fn );
  929. }
  930. DoWithAcceptedFiles();
  931. m_AcceptedFiles.clear();
  932. }
  933. void EDA_BASE_FRAME::DoWithAcceptedFiles()
  934. {
  935. for( const wxFileName& file : m_AcceptedFiles )
  936. {
  937. wxString fn = file.GetFullPath();
  938. m_toolManager->RunAction( *m_acceptedExts.at( file.GetExt() ), true, &fn );
  939. }
  940. }
  941. bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
  942. {
  943. wxString msg;
  944. wxFileName fn = aFileName;
  945. // Check for absence of a file path with a file name. Unfortunately KiCad
  946. // uses paths relative to the current project path without the ./ part which
  947. // confuses wxFileName. Making the file name path absolute may be less than
  948. // elegant but it solves the problem.
  949. if( fn.GetPath().IsEmpty() && fn.HasName() )
  950. fn.MakeAbsolute();
  951. wxCHECK_MSG( fn.IsOk(), false,
  952. wxT( "File name object is invalid. Bad programmer!" ) );
  953. wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
  954. wxT( "File name object path <" ) + fn.GetFullPath() +
  955. wxT( "> is not set. Bad programmer!" ) );
  956. if( fn.IsDir() && !fn.IsDirWritable() )
  957. {
  958. msg.Printf( _( "Insufficient permissions to folder '%s'." ), fn.GetPath() );
  959. }
  960. else if( !fn.FileExists() && !fn.IsDirWritable() )
  961. {
  962. msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
  963. }
  964. else if( fn.FileExists() && !fn.IsFileWritable() )
  965. {
  966. msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
  967. }
  968. if( !msg.IsEmpty() )
  969. {
  970. if( aVerbose )
  971. DisplayErrorMessage( this, msg );
  972. return false;
  973. }
  974. return true;
  975. }
  976. void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
  977. {
  978. if( !Pgm().IsGUI() )
  979. return;
  980. wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
  981. wxFileName autoSaveFileName = aFileName;
  982. // Check for auto save file.
  983. autoSaveFileName.SetName( GetAutoSaveFilePrefix() + aFileName.GetName() );
  984. wxLogTrace( traceAutoSave,
  985. wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
  986. if( !autoSaveFileName.FileExists() )
  987. return;
  988. wxString msg = wxString::Format( _( "Well this is potentially embarrassing!\n"
  989. "It appears that the last time you were editing\n"
  990. "%s\n"
  991. "KiCad exited before saving.\n"
  992. "\n"
  993. "Do you wish to open the auto-saved file instead?" ),
  994. aFileName.GetFullName() );
  995. int response = wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
  996. this );
  997. // Make a backup of the current file, delete the file, and rename the auto save file to
  998. // the file name.
  999. if( response == wxYES )
  1000. {
  1001. if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
  1002. {
  1003. wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
  1004. Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
  1005. }
  1006. }
  1007. else
  1008. {
  1009. wxLogTrace( traceAutoSave,
  1010. wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
  1011. // Remove the auto save file when using the previous file as is.
  1012. wxRemoveFile( autoSaveFileName.GetFullPath() );
  1013. }
  1014. }
  1015. bool EDA_BASE_FRAME::IsContentModified() const
  1016. {
  1017. // This function should be overridden in child classes
  1018. return false;
  1019. }
  1020. void EDA_BASE_FRAME::initExitKey()
  1021. {
  1022. wxAcceleratorEntry entries[1];
  1023. entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
  1024. wxAcceleratorTable accel( 1, entries );
  1025. SetAcceleratorTable( accel );
  1026. }
  1027. void EDA_BASE_FRAME::ClearUndoRedoList()
  1028. {
  1029. ClearUndoORRedoList( UNDO_LIST );
  1030. ClearUndoORRedoList( REDO_LIST );
  1031. }
  1032. void EDA_BASE_FRAME::PushCommandToUndoList( PICKED_ITEMS_LIST* aNewitem )
  1033. {
  1034. m_undoList.PushCommand( aNewitem );
  1035. // Delete the extra items, if count max reached
  1036. if( m_undoRedoCountMax > 0 )
  1037. {
  1038. int extraitems = GetUndoCommandCount() - m_undoRedoCountMax;
  1039. if( extraitems > 0 )
  1040. ClearUndoORRedoList( UNDO_LIST, extraitems );
  1041. }
  1042. }
  1043. void EDA_BASE_FRAME::PushCommandToRedoList( PICKED_ITEMS_LIST* aNewitem )
  1044. {
  1045. m_redoList.PushCommand( aNewitem );
  1046. // Delete the extra items, if count max reached
  1047. if( m_undoRedoCountMax > 0 )
  1048. {
  1049. int extraitems = GetRedoCommandCount() - m_undoRedoCountMax;
  1050. if( extraitems > 0 )
  1051. ClearUndoORRedoList( REDO_LIST, extraitems );
  1052. }
  1053. }
  1054. PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromUndoList( )
  1055. {
  1056. return m_undoList.PopCommand();
  1057. }
  1058. PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromRedoList( )
  1059. {
  1060. return m_redoList.PopCommand();
  1061. }
  1062. void EDA_BASE_FRAME::OnModify()
  1063. {
  1064. m_autoSaveRequired = true;
  1065. }
  1066. void EDA_BASE_FRAME::ChangeUserUnits( EDA_UNITS aUnits )
  1067. {
  1068. SetUserUnits( aUnits );
  1069. unitsChangeRefresh();
  1070. wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
  1071. e.SetInt( static_cast<int>( aUnits ) );
  1072. e.SetClientData( this );
  1073. ProcessEventLocally( e );
  1074. }
  1075. void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent )
  1076. {
  1077. // When we maximize the window, we want to save the old information
  1078. // so that we can add it to the settings on next window load.
  1079. // Contrary to the documentation, this event seems to be generated
  1080. // when the window is also being unmaximized on OSX, so we only
  1081. // capture the size information when we maximize the window when on OSX.
  1082. #ifdef __WXOSX__
  1083. if( !IsMaximized() )
  1084. #endif
  1085. {
  1086. m_normalFrameSize = GetWindowSize();
  1087. m_normalFramePos = GetPosition();
  1088. wxLogTrace( traceDisplayLocation,
  1089. "Maximizing window - Saving position (%d, %d) with size (%d, %d)",
  1090. m_normalFramePos.x, m_normalFramePos.y,
  1091. m_normalFrameSize.x, m_normalFrameSize.y );
  1092. }
  1093. // Skip event to actually maximize the window
  1094. aEvent.Skip();
  1095. }
  1096. wxSize EDA_BASE_FRAME::GetWindowSize()
  1097. {
  1098. #ifdef __WXGTK__
  1099. wxSize winSize = GetSize();
  1100. // GTK includes the window decorations in the normal GetSize call,
  1101. // so we have to use a GTK-specific sizing call that returns the
  1102. // non-decorated window size.
  1103. if( m_ident == KICAD_MAIN_FRAME_T )
  1104. {
  1105. int width = 0;
  1106. int height = 0;
  1107. GTKDoGetSize( &width, &height );
  1108. winSize.Set( width, height );
  1109. }
  1110. #else
  1111. wxSize winSize = GetSize();
  1112. #endif
  1113. return winSize;
  1114. }
  1115. void EDA_BASE_FRAME::HandleSystemColorChange()
  1116. {
  1117. // Update the icon theme when the system theme changes and update the toolbars
  1118. GetBitmapStore()->ThemeChanged();
  1119. ThemeChanged();
  1120. // This isn't handled by ThemeChanged()
  1121. if( GetMenuBar() )
  1122. {
  1123. // For icons in menus, icon scaling & hotkeys
  1124. ReCreateMenuBar();
  1125. GetMenuBar()->Refresh();
  1126. }
  1127. }
  1128. void EDA_BASE_FRAME::onSystemColorChange( wxSysColourChangedEvent& aEvent )
  1129. {
  1130. // Call the handler to update the colors used in the frame
  1131. HandleSystemColorChange();
  1132. // Skip the change event to ensure the rest of the window controls get it
  1133. aEvent.Skip();
  1134. }
  1135. void EDA_BASE_FRAME::onIconize( wxIconizeEvent& aEvent )
  1136. {
  1137. // Call the handler
  1138. handleIconizeEvent( aEvent );
  1139. // Skip the event.
  1140. aEvent.Skip();
  1141. }
  1142. #ifdef _WIN32
  1143. WXLRESULT EDA_BASE_FRAME::MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam )
  1144. {
  1145. // This will help avoid the menu keeping focus when the alt key is released
  1146. // You can still trigger accelerators as long as you hold down alt
  1147. if( message == WM_SYSCOMMAND )
  1148. {
  1149. if( wParam == SC_KEYMENU && ( lParam >> 16 ) <= 0 )
  1150. return 0;
  1151. }
  1152. return wxFrame::MSWWindowProc( message, wParam, lParam );
  1153. }
  1154. #endif