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.

1661 lines
49 KiB

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