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.

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