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.

1040 lines
32 KiB

Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
* 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
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
* 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
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2004-2019 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 <3d_viewer/eda_3d_viewer.h>
  26. #include <bitmaps.h>
  27. #include <board_commit.h>
  28. #include <class_board.h>
  29. #include <class_module.h>
  30. #include <confirm.h>
  31. #include <dialog_helpers.h>
  32. #include <eda_pattern_match.h>
  33. #include <fctsys.h>
  34. #include <footprint_info.h>
  35. #include <footprint_viewer_frame.h>
  36. #include <fp_lib_table.h>
  37. #include <kiway.h>
  38. #include <lib_id.h>
  39. #include <memory>
  40. #include <msgpanel.h>
  41. #include <pcb_draw_panel_gal.h>
  42. #include <pcb_painter.h>
  43. #include <pcbnew.h>
  44. #include <pcbnew_id.h>
  45. #include <pcbnew_settings.h>
  46. #include <footprint_editor_settings.h>
  47. #include <pgm_base.h>
  48. #include <settings/settings_manager.h>
  49. #include <tool/action_toolbar.h>
  50. #include <tool/common_control.h>
  51. #include <tool/common_tools.h>
  52. #include <tool/tool_dispatcher.h>
  53. #include <tool/tool_manager.h>
  54. #include <tool/zoom_tool.h>
  55. #include <tools/pcb_viewer_tools.h>
  56. #include <tools/pcb_actions.h>
  57. #include <tools/pcbnew_control.h>
  58. #include <tools/pcbnew_picker_tool.h>
  59. #include <tools/selection_tool.h>
  60. #include <wildcards_and_files_ext.h>
  61. #include <wx/tokenzr.h>
  62. using namespace std::placeholders;
  63. #define NEXT_PART 1
  64. #define NEW_PART 0
  65. #define PREVIOUS_PART -1
  66. BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
  67. // Window events
  68. EVT_CLOSE( FOOTPRINT_VIEWER_FRAME::OnCloseWindow )
  69. EVT_SIZE( FOOTPRINT_VIEWER_FRAME::OnSize )
  70. EVT_ACTIVATE( FOOTPRINT_VIEWER_FRAME::OnActivate )
  71. EVT_MENU( wxID_EXIT, FOOTPRINT_VIEWER_FRAME::OnExitKiCad )
  72. EVT_MENU( wxID_CLOSE, FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer )
  73. // Toolbar events
  74. EVT_TOOL( ID_MODVIEW_NEXT, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
  75. EVT_TOOL( ID_MODVIEW_PREVIOUS, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
  76. EVT_TOOL( ID_ADD_FOOTPRINT_TO_BOARD, FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB )
  77. EVT_CHOICE( ID_ON_ZOOM_SELECT, FOOTPRINT_VIEWER_FRAME::OnSelectZoom )
  78. EVT_CHOICE( ID_ON_GRID_SELECT, FOOTPRINT_VIEWER_FRAME::OnSelectGrid )
  79. EVT_UPDATE_UI( ID_ON_GRID_SELECT, FOOTPRINT_VIEWER_FRAME::OnUpdateSelectGrid )
  80. EVT_UPDATE_UI( ID_ON_ZOOM_SELECT, FOOTPRINT_VIEWER_FRAME::OnUpdateSelectZoom )
  81. EVT_UPDATE_UI( ID_ADD_FOOTPRINT_TO_BOARD, FOOTPRINT_VIEWER_FRAME::OnUpdateFootprintButton )
  82. EVT_TEXT( ID_MODVIEW_LIB_FILTER, FOOTPRINT_VIEWER_FRAME::OnLibFilter )
  83. EVT_TEXT( ID_MODVIEW_FOOTPRINT_FILTER, FOOTPRINT_VIEWER_FRAME::OnFPFilter )
  84. // listbox events
  85. EVT_LISTBOX( ID_MODVIEW_LIB_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnLibList )
  86. EVT_LISTBOX( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList )
  87. EVT_LISTBOX_DCLICK( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList )
  88. END_EVENT_TABLE()
  89. /* Note:
  90. * FOOTPRINT_VIEWER_FRAME can be created in "modal mode", or as a usual frame.
  91. * In modal mode:
  92. * a tool to export the selected footprint is shown in the toolbar
  93. * the style is wxFRAME_FLOAT_ON_PARENT
  94. */
  95. #define PARENT_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
  96. #define MODAL_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP )
  97. #define NONMODAL_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
  98. FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent,
  99. FRAME_T aFrameType ) :
  100. PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ),
  101. wxDefaultPosition, wxDefaultSize,
  102. aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL ? ( aParent ? PARENT_STYLE : MODAL_STYLE )
  103. : NONMODAL_STYLE,
  104. aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL ? FOOTPRINT_VIEWER_FRAME_NAME_MODAL
  105. : FOOTPRINT_VIEWER_FRAME_NAME )
  106. {
  107. wxASSERT( aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL || aFrameType == FRAME_FOOTPRINT_VIEWER );
  108. if( aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL )
  109. SetModal( true );
  110. m_AboutTitle = "Footprint Library Viewer";
  111. // Force the items to always snap
  112. m_magneticItems.pads = MAGNETIC_OPTIONS::CAPTURE_ALWAYS;
  113. m_magneticItems.tracks = MAGNETIC_OPTIONS::CAPTURE_ALWAYS;
  114. m_magneticItems.graphics = true;
  115. // Force the frame name used in config. the footprint viewer frame has a name
  116. // depending on aFrameType (needed to identify the frame by wxWidgets),
  117. // but only one configuration is preferable.
  118. m_configName = FOOTPRINT_VIEWER_FRAME_NAME;
  119. // Give an icon
  120. wxIcon icon;
  121. icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) );
  122. SetIcon( icon );
  123. wxPanel* libPanel = new wxPanel( this );
  124. wxSizer* libSizer = new wxBoxSizer( wxVERTICAL );
  125. m_libFilter = new wxTextCtrl( libPanel, ID_MODVIEW_LIB_FILTER, wxEmptyString,
  126. wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
  127. m_libFilter->SetHint( _( "Filter" ) );
  128. libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
  129. m_libList = new wxListBox( libPanel, ID_MODVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
  130. 0, NULL, wxLB_HSCROLL | wxNO_BORDER );
  131. libSizer->Add( m_libList, 1, wxEXPAND, 5 );
  132. libPanel->SetSizer( libSizer );
  133. libPanel->Fit();
  134. wxPanel* fpPanel = new wxPanel( this );
  135. wxSizer* fpSizer = new wxBoxSizer( wxVERTICAL );
  136. m_fpFilter = new wxTextCtrl( fpPanel, ID_MODVIEW_FOOTPRINT_FILTER, wxEmptyString,
  137. wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
  138. m_fpFilter->SetHint( _( "Filter" ) );
  139. m_fpFilter->SetToolTip(
  140. _( "Filter on footprint name, keywords, description and pad count.\n"
  141. "Search terms are separated by spaces. All search terms must match.\n"
  142. "A term which is a number will also match against the pad count." ) );
  143. fpSizer->Add( m_fpFilter, 0, wxEXPAND, 5 );
  144. m_fpList = new wxListBox( fpPanel, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize,
  145. 0, NULL, wxLB_HSCROLL | wxNO_BORDER );
  146. fpSizer->Add( m_fpList, 1, wxEXPAND, 5 );
  147. fpPanel->SetSizer( fpSizer );
  148. fpPanel->Fit();
  149. SetBoard( new BOARD() );
  150. // In viewer, the default net clearance is not known (it depends on the actual board).
  151. // So we do not show the default clearance, by setting it to 0
  152. // The footprint or pad specific clearance will be shown
  153. GetBoard()->GetDesignSettings().GetDefault()->SetClearance( 0 );
  154. // Don't show the default board solder mask clearance in the footprint viewer. Only the
  155. // footprint or pad clearance setting should be shown if it is not 0.
  156. GetBoard()->GetDesignSettings().m_SolderMaskMargin = 0;
  157. // Ensure all layers and items are visible:
  158. GetBoard()->SetVisibleAlls();
  159. SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
  160. GetScreen()->m_Center = true; // Center coordinate origins on screen.
  161. LoadSettings( config() );
  162. GetGalDisplayOptions().m_axesEnabled = true;
  163. // Create GAL canvas
  164. m_canvasType = LoadCanvasTypeSetting();
  165. auto drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
  166. GetGalDisplayOptions(), m_canvasType );
  167. SetCanvas( drawPanel );
  168. // Create the manager and dispatcher & route draw panel events to the dispatcher
  169. m_toolManager = new TOOL_MANAGER;
  170. m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
  171. drawPanel->GetViewControls(), config(), this );
  172. m_actions = new PCB_ACTIONS();
  173. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
  174. drawPanel->SetEventDispatcher( m_toolDispatcher );
  175. m_toolManager->RegisterTool( new PCBNEW_CONTROL );
  176. m_toolManager->RegisterTool( new SELECTION_TOOL );
  177. m_toolManager->RegisterTool( new COMMON_TOOLS ); // for std context menus (zoom & grid)
  178. m_toolManager->RegisterTool( new COMMON_CONTROL );
  179. m_toolManager->RegisterTool( new PCBNEW_PICKER_TOOL ); // for setting grid origin
  180. m_toolManager->RegisterTool( new ZOOM_TOOL );
  181. m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
  182. m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
  183. m_toolManager->InitTools();
  184. m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
  185. ReCreateMenuBar();
  186. ReCreateHToolbar();
  187. ReCreateVToolbar();
  188. ReCreateOptToolbar();
  189. ReCreateLibraryList();
  190. UpdateTitle();
  191. // If a footprint was previously loaded, reload it
  192. if( getCurNickname().size() && getCurFootprintName().size() )
  193. {
  194. LIB_ID id;
  195. id.SetLibNickname( getCurNickname() );
  196. id.SetLibItemName( getCurFootprintName() );
  197. GetBoard()->Add( loadFootprint( id ) );
  198. }
  199. drawPanel->DisplayBoard( m_Pcb );
  200. m_auimgr.SetManagedWindow( this );
  201. // Horizontal items; layers 4 - 6
  202. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().VToolbar().Name( "MainToolbar" ).Top().Layer(6) );
  203. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
  204. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
  205. // Vertical items; layers 1 - 3
  206. m_auimgr.AddPane( libPanel, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(2)
  207. .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
  208. m_auimgr.AddPane( fpPanel, EDA_PANE().Palette().Name( "Footprints" ).Left().Layer( 1)
  209. .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
  210. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
  211. // after changing something to the aui manager call Update() to reflect the changes
  212. m_auimgr.Update();
  213. // The canvas should not steal the focus from the list boxes
  214. GetCanvas()->SetCanFocus( false );
  215. GetCanvas()->GetGAL()->SetAxesEnabled( true );
  216. GetCanvas()->GetView()->SetScale( GetZoomLevelCoeff() / GetScreen()->GetZoom() );
  217. ActivateGalCanvas();
  218. // Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.)
  219. PCBNEW_SETTINGS* cfg = GetPcbNewSettings();
  220. wxASSERT( cfg );
  221. GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom );
  222. updateView();
  223. InitExitKey();
  224. if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
  225. {
  226. ReCreateFootprintList();
  227. Raise(); // On some window managers, this is needed
  228. Show( true );
  229. }
  230. }
  231. FOOTPRINT_VIEWER_FRAME::~FOOTPRINT_VIEWER_FRAME()
  232. {
  233. // Shutdown all running tools
  234. if( m_toolManager )
  235. m_toolManager->ShutdownAllTools();
  236. GetCanvas()->StopDrawing();
  237. GetCanvas()->GetView()->Clear();
  238. // Be sure any event cannot be fired after frame deletion:
  239. GetCanvas()->SetEvtHandlerEnabled( false );
  240. }
  241. void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event )
  242. {
  243. // A workaround to avoid flicker, in modal mode when modview frame is destroyed,
  244. // when the aui toolbar is not docked (i.e. shown in a miniframe)
  245. // (useful on windows only)
  246. m_mainToolBar->SetFocus();
  247. GetCanvas()->StopDrawing();
  248. if( IsModal() )
  249. {
  250. // Only dismiss a modal frame once, so that the return values set by
  251. // the prior DismissModal() are not bashed for ShowModal().
  252. if( !IsDismissed() )
  253. DismissModal( false );
  254. // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
  255. }
  256. else
  257. Destroy();
  258. }
  259. void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
  260. {
  261. if( m_auimgr.GetManagedWindow() )
  262. m_auimgr.Update();
  263. SizeEv.Skip();
  264. }
  265. void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList()
  266. {
  267. m_libList->Clear();
  268. std::vector<wxString> nicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
  269. std::set<wxString> excludes;
  270. if( !m_libFilter->GetValue().IsEmpty() )
  271. {
  272. wxStringTokenizer tokenizer( m_libFilter->GetValue() );
  273. while( tokenizer.HasMoreTokens() )
  274. {
  275. const wxString term = tokenizer.GetNextToken().Lower();
  276. EDA_COMBINED_MATCHER matcher( term );
  277. int matches, position;
  278. for( const wxString& nickname : nicknames )
  279. {
  280. if( !matcher.Find( nickname.Lower(), matches, position ) )
  281. excludes.insert( nickname );
  282. }
  283. }
  284. }
  285. for( const wxString& nickname : nicknames )
  286. {
  287. if( !excludes.count( nickname ) )
  288. m_libList->Append( nickname );
  289. }
  290. // Search for a previous selection:
  291. int index = m_libList->FindString( getCurNickname(), true );
  292. if( index == wxNOT_FOUND )
  293. {
  294. if( m_libList->GetCount() > 0 )
  295. {
  296. m_libList->SetSelection( 0 );
  297. wxCommandEvent dummy;
  298. ClickOnLibList( dummy );
  299. }
  300. else
  301. {
  302. setCurNickname( wxEmptyString );
  303. setCurFootprintName( wxEmptyString );
  304. }
  305. }
  306. else
  307. {
  308. m_libList->SetSelection( index, true );
  309. wxCommandEvent dummy;
  310. ClickOnLibList( dummy );
  311. }
  312. GetCanvas()->Refresh();
  313. }
  314. void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
  315. {
  316. m_fpList->Clear();
  317. if( !getCurNickname() )
  318. setCurFootprintName( wxEmptyString );
  319. auto fp_info_list = FOOTPRINT_LIST::GetInstance( Kiway() );
  320. wxString nickname = getCurNickname();
  321. fp_info_list->ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? NULL : &nickname );
  322. if( fp_info_list->GetErrorCount() )
  323. {
  324. fp_info_list->DisplayErrors( this );
  325. // For footprint libraries that support one footprint per file, there may have been
  326. // valid footprints read so show the footprints that loaded properly.
  327. if( fp_info_list->GetList().empty() )
  328. return;
  329. }
  330. std::set<wxString> excludes;
  331. if( !m_fpFilter->GetValue().IsEmpty() )
  332. {
  333. wxStringTokenizer tokenizer( m_fpFilter->GetValue() );
  334. while( tokenizer.HasMoreTokens() )
  335. {
  336. const wxString term = tokenizer.GetNextToken().Lower();
  337. EDA_COMBINED_MATCHER matcher( term );
  338. int matches, position;
  339. for( const std::unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
  340. {
  341. wxString search = footprint->GetFootprintName() + " " + footprint->GetSearchText();
  342. bool matched = matcher.Find( search.Lower(), matches, position );
  343. if( !matched && term.IsNumber() )
  344. matched = ( wxAtoi( term ) == (int)footprint->GetPadCount() );
  345. if( !matched )
  346. excludes.insert( footprint->GetFootprintName() );
  347. }
  348. }
  349. }
  350. for( const std::unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
  351. {
  352. if( !excludes.count( footprint->GetFootprintName() ) )
  353. m_fpList->Append( footprint->GetFootprintName() );
  354. }
  355. int index = m_fpList->FindString( getCurFootprintName(), true );
  356. if( index == wxNOT_FOUND )
  357. {
  358. if( m_fpList->GetCount() > 0 )
  359. {
  360. m_fpList->SetSelection( 0 );
  361. m_fpList->EnsureVisible( 0 );
  362. wxCommandEvent dummy;
  363. ClickOnFootprintList( dummy );
  364. }
  365. else
  366. setCurFootprintName( wxEmptyString );
  367. }
  368. else
  369. {
  370. m_fpList->SetSelection( index, true );
  371. m_fpList->EnsureVisible( index );
  372. }
  373. }
  374. void FOOTPRINT_VIEWER_FRAME::OnLibFilter( wxCommandEvent& aEvent )
  375. {
  376. ReCreateLibraryList();
  377. // Required to avoid interaction with SetHint()
  378. // See documentation for wxTextEntry::SetHint
  379. aEvent.Skip();
  380. }
  381. void FOOTPRINT_VIEWER_FRAME::OnFPFilter( wxCommandEvent& aEvent )
  382. {
  383. ReCreateFootprintList();
  384. // Required to avoid interaction with SetHint()
  385. // See documentation for wxTextEntry::SetHint
  386. aEvent.Skip();
  387. }
  388. void FOOTPRINT_VIEWER_FRAME::OnCharHook( wxKeyEvent& aEvent )
  389. {
  390. if( aEvent.GetKeyCode() == WXK_UP )
  391. {
  392. wxWindow* focused = FindFocus();
  393. if( m_libFilter->HasFocus() || m_libList->HasFocus() )
  394. selectPrev( m_libList );
  395. else
  396. selectPrev( m_fpList );
  397. // Need to reset the focus after selection due to GTK mouse-refresh
  398. // that captures the mouse into the canvas to update scrollbars
  399. if( focused )
  400. focused->SetFocus();
  401. }
  402. else if( aEvent.GetKeyCode() == WXK_DOWN )
  403. {
  404. wxWindow* focused = FindFocus();
  405. if( m_libFilter->HasFocus() || m_libList->HasFocus() )
  406. selectNext( m_libList );
  407. else
  408. selectNext( m_fpList );
  409. // Need to reset the focus after selection due to GTK mouse-refresh
  410. // that captures the mouse into the canvas to update scrollbars
  411. if( focused )
  412. focused->SetFocus();
  413. }
  414. else if( aEvent.GetKeyCode() == WXK_TAB && m_libFilter->HasFocus() )
  415. {
  416. if( !aEvent.ShiftDown() )
  417. m_fpFilter->SetFocus();
  418. else
  419. aEvent.Skip();
  420. }
  421. else if( aEvent.GetKeyCode() == WXK_TAB && m_fpFilter->HasFocus() )
  422. {
  423. if( aEvent.ShiftDown() )
  424. m_libFilter->SetFocus();
  425. else
  426. aEvent.Skip();
  427. }
  428. else if( aEvent.GetKeyCode() == WXK_RETURN && m_fpList->GetSelection() >= 0 )
  429. {
  430. wxCommandEvent dummy;
  431. AddFootprintToPCB( dummy );
  432. }
  433. else
  434. aEvent.Skip();
  435. }
  436. void FOOTPRINT_VIEWER_FRAME::selectPrev( wxListBox* aListBox )
  437. {
  438. int prev = aListBox->GetSelection() - 1;
  439. if( prev >= 0 )
  440. {
  441. aListBox->SetSelection( prev );
  442. aListBox->EnsureVisible( prev );
  443. wxCommandEvent dummy;
  444. if( aListBox == m_libList )
  445. ClickOnLibList( dummy );
  446. else
  447. ClickOnFootprintList( dummy );
  448. }
  449. }
  450. void FOOTPRINT_VIEWER_FRAME::selectNext( wxListBox* aListBox )
  451. {
  452. int next = aListBox->GetSelection() + 1;
  453. if( next < (int)aListBox->GetCount() )
  454. {
  455. aListBox->SetSelection( next );
  456. aListBox->EnsureVisible( next );
  457. wxCommandEvent dummy;
  458. if( aListBox == m_libList )
  459. ClickOnLibList( dummy );
  460. else
  461. ClickOnFootprintList( dummy );
  462. }
  463. }
  464. void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& aEvent )
  465. {
  466. int ii = m_libList->GetSelection();
  467. if( ii < 0 )
  468. return;
  469. wxString name = m_libList->GetString( ii );
  470. if( getCurNickname() == name )
  471. return;
  472. setCurNickname( name );
  473. ReCreateFootprintList();
  474. UpdateTitle();
  475. // The m_libList has now the focus, in order to be able to use arrow keys
  476. // to navigate inside the list.
  477. // the gal canvas must not steal the focus to allow navigation
  478. GetCanvas()->SetStealsFocus( false );
  479. m_libList->SetFocus();
  480. }
  481. void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent )
  482. {
  483. if( m_fpList->GetCount() == 0 )
  484. return;
  485. int ii = m_fpList->GetSelection();
  486. if( ii < 0 )
  487. return;
  488. wxString name = m_fpList->GetString( ii );
  489. if( getCurFootprintName().CmpNoCase( name ) != 0 )
  490. {
  491. setCurFootprintName( name );
  492. // Delete the current footprint (MUST reset tools first)
  493. GetToolManager()->ResetTools( TOOL_BASE::MODEL_RELOAD );
  494. GetBoard()->DeleteAllModules();
  495. LIB_ID id;
  496. id.SetLibNickname( getCurNickname() );
  497. id.SetLibItemName( getCurFootprintName() );
  498. try
  499. {
  500. GetBoard()->Add( loadFootprint( id ) );
  501. }
  502. catch( const IO_ERROR& ioe )
  503. {
  504. wxString msg = wxString::Format( _( "Could not load footprint '%s' from library '%s'."
  505. "\n\n%s" ),
  506. getCurFootprintName(),
  507. getCurNickname(),
  508. ioe.Problem() );
  509. DisplayError( this, msg );
  510. }
  511. UpdateTitle();
  512. updateView();
  513. GetCanvas()->Refresh();
  514. Update3DView( true );
  515. }
  516. // The m_fpList has now the focus, in order to be able to use arrow keys
  517. // to navigate inside the list.
  518. // the gal canvas must not steal the focus to allow navigation
  519. GetCanvas()->SetStealsFocus( false );
  520. m_fpList->SetFocus();
  521. }
  522. void FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList( wxCommandEvent& aEvent )
  523. {
  524. AddFootprintToPCB( aEvent );
  525. }
  526. void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent )
  527. {
  528. if( IsModal() )
  529. {
  530. if( m_fpList->GetSelection() >= 0 )
  531. {
  532. LIB_ID fpid( getCurNickname(), m_fpList->GetStringSelection() );
  533. DismissModal( true, fpid.Format() );
  534. }
  535. else
  536. {
  537. DismissModal( false );
  538. }
  539. Close( true );
  540. }
  541. else if( GetBoard()->GetFirstModule() )
  542. {
  543. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
  544. if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
  545. {
  546. DisplayErrorMessage( this, _( "No board currently open." ) );
  547. return;
  548. }
  549. pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
  550. BOARD_COMMIT commit( pcbframe );
  551. // Create the "new" module
  552. MODULE* newmodule = (MODULE*) GetBoard()->GetFirstModule()->Duplicate();
  553. newmodule->SetParent( pcbframe->GetBoard() );
  554. newmodule->SetLink( 0 );
  555. KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
  556. VECTOR2D cursorPos = viewControls->GetCursorPosition();
  557. commit.Add( newmodule );
  558. viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
  559. pcbframe->PlaceModule( newmodule );
  560. newmodule->SetPosition( wxPoint( 0, 0 ) );
  561. viewControls->SetCrossHairCursorPosition( cursorPos, false );
  562. commit.Push( wxT( "Insert module" ) );
  563. pcbframe->Raise();
  564. pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::placeModule, true, newmodule );
  565. newmodule->ClearFlags();
  566. }
  567. }
  568. void FOOTPRINT_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  569. {
  570. auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  571. wxCHECK( cfg, /*void*/ );
  572. // We don't allow people to change this right now, so make sure it's on
  573. GetWindowSettings( cfg )->cursor.always_show_cursor = true;
  574. PCB_BASE_FRAME::LoadSettings( aCfg );
  575. // Fetch grid settings from Footprint Editor
  576. auto fpedit = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  577. GetGalDisplayOptions().ReadWindowSettings( fpedit->m_Window );
  578. }
  579. void FOOTPRINT_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  580. {
  581. auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  582. wxCHECK( cfg, /*void*/ );
  583. // We don't want to store anything other than the window settings
  584. PCB_BASE_FRAME::SaveSettings( cfg );
  585. cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale();
  586. }
  587. WINDOW_SETTINGS* FOOTPRINT_VIEWER_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  588. {
  589. auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  590. wxCHECK_MSG( cfg, nullptr, "config not existing" );
  591. return &cfg->m_FootprintViewer;
  592. }
  593. COLOR_SETTINGS* FOOTPRINT_VIEWER_FRAME::GetColorSettings()
  594. {
  595. auto* settings = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  596. if( settings )
  597. return Pgm().GetSettingsManager().GetColorSettings( settings->m_ColorTheme );
  598. else
  599. return Pgm().GetSettingsManager().GetColorSettings();
  600. }
  601. bool FOOTPRINT_VIEWER_FRAME::GetAutoZoom()
  602. {
  603. // It is stored in pcbnew's settings
  604. PCBNEW_SETTINGS* cfg = GetPcbNewSettings();
  605. wxCHECK( cfg, false );
  606. return cfg->m_FootprintViewerAutoZoom;
  607. }
  608. void FOOTPRINT_VIEWER_FRAME::SetAutoZoom( bool aAutoZoom )
  609. {
  610. // It is stored in pcbnew's settings
  611. PCBNEW_SETTINGS* cfg = GetPcbNewSettings();
  612. wxASSERT( cfg );
  613. cfg->m_FootprintViewerAutoZoom = aAutoZoom;
  614. }
  615. void FOOTPRINT_VIEWER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
  616. {
  617. PCB_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
  618. if( aEnvVarsChanged )
  619. ReCreateLibraryList();
  620. }
  621. const wxString FOOTPRINT_VIEWER_FRAME::getCurNickname()
  622. {
  623. return Prj().GetRString( PROJECT::PCB_FOOTPRINT_VIEWER_NICKNAME );
  624. }
  625. void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
  626. {
  627. Prj().SetRString( PROJECT::PCB_FOOTPRINT_VIEWER_NICKNAME, aNickname );
  628. }
  629. const wxString FOOTPRINT_VIEWER_FRAME::getCurFootprintName()
  630. {
  631. return Prj().GetRString( PROJECT::PCB_FOOTPRINT_VIEWER_FPNAME );
  632. }
  633. void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
  634. {
  635. Prj().SetRString( PROJECT::PCB_FOOTPRINT_VIEWER_FPNAME, aName );
  636. }
  637. void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
  638. {
  639. if( event.GetActive() )
  640. {
  641. // Ensure we have the right library list:
  642. std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
  643. bool stale = false;
  644. if( libNicknames.size() != m_libList->GetCount() )
  645. stale = true;
  646. else
  647. {
  648. for( unsigned ii = 0; ii < libNicknames.size(); ii++ )
  649. {
  650. if( libNicknames[ii] != m_libList->GetString( ii ) )
  651. {
  652. stale = true;
  653. break;
  654. }
  655. }
  656. }
  657. if( stale )
  658. {
  659. ReCreateLibraryList();
  660. UpdateTitle();
  661. }
  662. }
  663. event.Skip(); // required under wxMAC
  664. }
  665. void FOOTPRINT_VIEWER_FRAME::OnUpdateFootprintButton( wxUpdateUIEvent& aEvent )
  666. {
  667. aEvent.Enable( GetBoard()->GetFirstModule() != nullptr );
  668. }
  669. bool FOOTPRINT_VIEWER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent )
  670. {
  671. if( aFootprint && !aFootprint->IsEmpty() )
  672. {
  673. wxString msg;
  674. LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
  675. LIB_ID fpid;
  676. fpid.Parse( *aFootprint, LIB_ID::ID_PCB, true );
  677. if( fpid.IsValid() )
  678. {
  679. wxString nickname = fpid.GetLibNickname();
  680. if( !fpTable->HasLibrary( fpid.GetLibNickname(), false ) )
  681. {
  682. msg.sprintf( _( "The current configuration does not include a library with the\n"
  683. "nickname \"%s\". Use Manage Footprint Libraries\n"
  684. "to edit the configuration." ), nickname );
  685. DisplayErrorMessage( aParent, _( "Footprint library not found." ), msg );
  686. }
  687. else if ( !fpTable->HasLibrary( fpid.GetLibNickname(), true ) )
  688. {
  689. msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
  690. "in the current configuration. Use Manage Footprint Libraries to\n"
  691. "edit the configuration." ), nickname );
  692. DisplayErrorMessage( aParent, _( "Footprint library not enabled." ), msg );
  693. }
  694. else
  695. {
  696. // Update last selection:
  697. setCurNickname( nickname );
  698. setCurFootprintName( fpid.GetLibItemName() );
  699. m_libList->SetStringSelection( nickname );
  700. }
  701. }
  702. }
  703. // Rebuild the fp list from the last selected library,
  704. // and show the last selected footprint
  705. ReCreateFootprintList();
  706. SelectAndViewFootprint( NEW_PART );
  707. bool retval = KIWAY_PLAYER::ShowModal( aFootprint, aParent );
  708. m_libFilter->SetFocus();
  709. return retval;
  710. }
  711. void FOOTPRINT_VIEWER_FRAME::Update3DView( bool aForceReload, const wxString* aTitle )
  712. {
  713. wxString title = wxString::Format( _( "3D Viewer" ) + wxT( " \u2014 %s" ),
  714. getCurFootprintName() );
  715. PCB_BASE_FRAME::Update3DView( aForceReload, &title );
  716. }
  717. COLOR4D FOOTPRINT_VIEWER_FRAME::GetGridColor()
  718. {
  719. return GetColorSettings()->GetColor( LAYER_GRID );
  720. }
  721. void FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList( wxCommandEvent& event )
  722. {
  723. switch( event.GetId() )
  724. {
  725. case ID_MODVIEW_NEXT:
  726. SelectAndViewFootprint( NEXT_PART );
  727. break;
  728. case ID_MODVIEW_PREVIOUS:
  729. SelectAndViewFootprint( PREVIOUS_PART );
  730. break;
  731. default:
  732. wxString id = wxString::Format( "%i", event.GetId() );
  733. wxFAIL_MSG( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " + id );
  734. }
  735. }
  736. void FOOTPRINT_VIEWER_FRAME::UpdateTitle()
  737. {
  738. wxString title;
  739. wxString path;
  740. title.Printf( _( "Footprint Library Browser" ) + L" \u2014 %s",
  741. getCurNickname().IsEmpty() ? _( "no library selected" ) : getCurNickname() );
  742. // Now, add the full path, for info
  743. if( !getCurNickname().IsEmpty() )
  744. {
  745. FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
  746. const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
  747. if( row )
  748. title << L" \u2014 " << row->GetFullURI( true );
  749. }
  750. SetTitle( title );
  751. }
  752. void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
  753. {
  754. if( !getCurNickname() )
  755. return;
  756. int selection = m_fpList->FindString( getCurFootprintName(), true );
  757. if( aMode == NEXT_PART )
  758. {
  759. if( selection != wxNOT_FOUND && selection < (int)m_fpList->GetCount() - 1 )
  760. selection++;
  761. }
  762. if( aMode == PREVIOUS_PART )
  763. {
  764. if( selection != wxNOT_FOUND && selection > 0 )
  765. selection--;
  766. }
  767. if( selection != wxNOT_FOUND )
  768. {
  769. m_fpList->SetSelection( selection );
  770. m_fpList->EnsureVisible( selection );
  771. setCurFootprintName( m_fpList->GetString((unsigned) selection ) );
  772. // Delete the current footprint
  773. GetBoard()->DeleteAllModules();
  774. MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad( getCurNickname(),
  775. getCurFootprintName() );
  776. if( footprint )
  777. GetBoard()->Add( footprint, ADD_MODE::APPEND );
  778. Update3DView( true );
  779. updateView();
  780. }
  781. UpdateTitle();
  782. GetCanvas()->Refresh();
  783. }
  784. void FOOTPRINT_VIEWER_FRAME::updateView()
  785. {
  786. GetCanvas()->UpdateColors();
  787. GetCanvas()->DisplayBoard( GetBoard() );
  788. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  789. if( GetAutoZoom() )
  790. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  791. else
  792. m_toolManager->RunAction( ACTIONS::centerContents, true );
  793. UpdateMsgPanel();
  794. }
  795. void FOOTPRINT_VIEWER_FRAME::OnExitKiCad( wxCommandEvent& event )
  796. {
  797. Kiway().OnKiCadExit();
  798. }
  799. void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
  800. {
  801. Close( false );
  802. }
  803. BOARD_ITEM_CONTAINER* FOOTPRINT_VIEWER_FRAME::GetModel() const
  804. {
  805. return GetBoard()->GetFirstModule();
  806. }