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.

847 lines
24 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
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
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
* 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
7 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  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 <bitmaps.h>
  26. #include <class_libentry.h>
  27. #include <class_library.h>
  28. #include <confirm.h>
  29. #include <dialog_helpers.h>
  30. #include <dialog_choose_component.h>
  31. #include <eda_doc.h>
  32. #include <eeschema_id.h>
  33. #include <eeschema_settings.h>
  34. #include <fctsys.h>
  35. #include <kiface_i.h>
  36. #include <kiway.h>
  37. #include <lib_view_frame.h>
  38. #include <msgpanel.h>
  39. #include <sch_draw_panel.h>
  40. #include <sch_view.h>
  41. #include <sch_painter.h>
  42. #include <symbol_lib_table.h>
  43. #include <symbol_tree_model_adapter.h>
  44. #include <pgm_base.h>
  45. #include <settings/settings_manager.h>
  46. #include <tool/tool_manager.h>
  47. #include <tool/action_toolbar.h>
  48. #include <tool/tool_dispatcher.h>
  49. #include <tool/common_tools.h>
  50. #include <tool/common_control.h>
  51. #include <tool/zoom_tool.h>
  52. #include <tools/ee_actions.h>
  53. #include <tools/lib_control.h>
  54. #include <tools/ee_inspection_tool.h>
  55. #include <view/view_controls.h>
  56. #include <default_values.h>
  57. // Save previous component library viewer state.
  58. wxString LIB_VIEW_FRAME::m_libraryName;
  59. wxString LIB_VIEW_FRAME::m_entryName;
  60. int LIB_VIEW_FRAME::m_unit = 1;
  61. int LIB_VIEW_FRAME::m_convert = 1;
  62. BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
  63. // Window events
  64. EVT_CLOSE( LIB_VIEW_FRAME::OnCloseWindow )
  65. EVT_SIZE( LIB_VIEW_FRAME::OnSize )
  66. EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )
  67. // Toolbar events
  68. EVT_TOOL( ID_LIBVIEW_SELECT_PART, LIB_VIEW_FRAME::OnSelectSymbol )
  69. EVT_TOOL( ID_LIBVIEW_NEXT, LIB_VIEW_FRAME::onSelectNextSymbol )
  70. EVT_TOOL( ID_LIBVIEW_PREVIOUS, LIB_VIEW_FRAME::onSelectPreviousSymbol )
  71. EVT_CHOICE( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::onSelectSymbolUnit )
  72. // listbox events
  73. EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, LIB_VIEW_FRAME::ClickOnLibList )
  74. EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, LIB_VIEW_FRAME::ClickOnCmpList )
  75. EVT_LISTBOX_DCLICK( ID_LIBVIEW_CMP_LIST, LIB_VIEW_FRAME::DClickOnCmpList )
  76. // Menu (and/or hotkey) events
  77. EVT_MENU( wxID_CLOSE, LIB_VIEW_FRAME::CloseLibraryViewer )
  78. EVT_MENU( ID_GRID_SETTINGS, SCH_BASE_FRAME::OnGridSettings )
  79. EVT_UPDATE_UI( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::onUpdateUnitChoice )
  80. END_EVENT_TABLE()
  81. #define LIB_VIEW_NAME "ViewlibFrame"
  82. #define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
  83. #define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
  84. #define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
  85. LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
  86. const wxString& aLibraryName ) :
  87. SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
  88. wxDefaultPosition, wxDefaultSize,
  89. aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_STYLE_MODAL : LIB_VIEW_STYLE,
  90. aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_NAME_MODAL : LIB_VIEW_NAME ),
  91. m_libList( nullptr ), m_cmpList( nullptr ), m_previewItem( nullptr )
  92. {
  93. wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
  94. if( aFrameType == FRAME_SCH_VIEWER_MODAL )
  95. SetModal( true );
  96. m_AboutTitle = "Symbol Library Viewer";
  97. // Force the frame name used in config. the lib viewer frame has a name
  98. // depending on aFrameType (needed to identify the frame by wxWidgets),
  99. // but only one configuration is preferable.
  100. m_configName = LIB_VIEW_NAME;
  101. // Give an icon
  102. wxIcon icon;
  103. icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) );
  104. SetIcon( icon );
  105. m_libListWidth = 200;
  106. m_cmpListWidth = 300;
  107. m_listPowerCmpOnly = false;
  108. // Initialize grid id to the default value (50 mils):
  109. m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000;
  110. SetScreen( new SCH_SCREEN( aKiway ) );
  111. GetScreen()->m_Center = true; // Axis origin centered on screen.
  112. LoadSettings( config() );
  113. // Synchronize some draw options
  114. SetShowElectricalType( true );
  115. // Ensure axis are always drawn (initial default display was not drawn)
  116. KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions();
  117. gal_opts.m_axesEnabled = true;
  118. GetCanvas()->GetGAL()->SetAxesEnabled( true );
  119. GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
  120. GetRenderSettings()->m_ShowPinsElectricalType = GetShowElectricalType();
  121. GetRenderSettings()->m_ShowHiddenText = true;
  122. GetRenderSettings()->m_ShowHiddenPins = true;
  123. GetRenderSettings()->SetDefaultPenWidth( DEFAULT_LINE_THICKNESS * IU_PER_MILS );
  124. setupTools();
  125. ReCreateHToolbar();
  126. ReCreateVToolbar();
  127. ReCreateMenuBar(); // Create after toolbars so that SyncToolbars works
  128. m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
  129. 0, NULL, wxLB_HSCROLL | wxNO_BORDER );
  130. m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize,
  131. 0, NULL, wxLB_HSCROLL | wxNO_BORDER );
  132. if( aLibraryName.empty() )
  133. {
  134. ReCreateListLib();
  135. }
  136. else
  137. {
  138. m_libraryName = aLibraryName;
  139. m_entryName.Clear();
  140. m_unit = 1;
  141. m_convert = 1;
  142. }
  143. m_selection_changed = false;
  144. DisplayLibInfos();
  145. m_auimgr.SetManagedWindow( this );
  146. // Manage main toolbar
  147. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
  148. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
  149. m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
  150. .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
  151. m_auimgr.AddPane( m_cmpList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
  152. .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_cmpListWidth, -1 ) );
  153. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
  154. m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
  155. m_auimgr.Update();
  156. GetToolManager()->RunAction( ACTIONS::gridPreset, true, m_LastGridSizeId );
  157. if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
  158. {
  159. Raise();
  160. Show( true );
  161. }
  162. SyncView();
  163. GetCanvas()->GetViewControls()->SetSnapping( true );
  164. GetCanvas()->SetCanFocus( false );
  165. // Set the working/draw area size to display a symbol to a reasonable value:
  166. // A 450mm x 450mm with a origin at the area center looks like a large working area
  167. double max_size_x = Millimeter2iu( 450 );
  168. double max_size_y = Millimeter2iu( 450 );
  169. BOX2D bbox;
  170. bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
  171. bbox.SetSize( max_size_x, max_size_y );
  172. GetCanvas()->GetView()->SetBoundary( bbox );
  173. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
  174. }
  175. LIB_VIEW_FRAME::~LIB_VIEW_FRAME()
  176. {
  177. // Shutdown all running tools
  178. if( m_toolManager )
  179. m_toolManager->ShutdownAllTools();
  180. if( m_previewItem )
  181. GetCanvas()->GetView()->Remove( m_previewItem );
  182. }
  183. void LIB_VIEW_FRAME::setupTools()
  184. {
  185. // Create the manager and dispatcher & route draw panel events to the dispatcher
  186. m_toolManager = new TOOL_MANAGER;
  187. m_toolManager->SetEnvironment( GetScreen(), GetCanvas()->GetView(),
  188. GetCanvas()->GetViewControls(), this );
  189. m_actions = new EE_ACTIONS();
  190. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
  191. // Register tools
  192. m_toolManager->RegisterTool( new COMMON_TOOLS );
  193. m_toolManager->RegisterTool( new COMMON_CONTROL );
  194. m_toolManager->RegisterTool( new ZOOM_TOOL );
  195. m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
  196. m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
  197. m_toolManager->RegisterTool( new LIB_CONTROL );
  198. m_toolManager->InitTools();
  199. // Run the selection tool, it is supposed to be always active
  200. // It also manages the mouse right click to show the context menu
  201. m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
  202. GetCanvas()->SetEventDispatcher( m_toolDispatcher );
  203. }
  204. void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
  205. {
  206. m_unit = aUnit > 0 ? aUnit : 1;
  207. m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
  208. m_selection_changed = false;
  209. updatePreviewSymbol();
  210. }
  211. LIB_PART* LIB_VIEW_FRAME::GetSelectedSymbol() const
  212. {
  213. LIB_PART* symbol = nullptr;
  214. if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
  215. symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
  216. return symbol;
  217. }
  218. void LIB_VIEW_FRAME::updatePreviewSymbol()
  219. {
  220. LIB_PART* symbol = GetSelectedSymbol();
  221. KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
  222. if( m_previewItem )
  223. {
  224. view->Remove( m_previewItem );
  225. m_previewItem = nullptr;
  226. }
  227. ClearMsgPanel();
  228. if( symbol )
  229. {
  230. GetRenderSettings()->m_ShowUnit = m_unit;
  231. GetRenderSettings()->m_ShowConvert = m_convert;
  232. m_previewItem = symbol;
  233. view->Add( m_previewItem );
  234. wxString parentName = _( "<none>" );
  235. std::shared_ptr< LIB_PART > parent = m_previewItem->GetParent().lock();
  236. if( parent )
  237. parentName = parent->GetName();
  238. AppendMsgPanel( _( "Name" ), m_previewItem->GetName(), BLUE, 6 );
  239. AppendMsgPanel( _( "Parent" ), parentName, RED, 6 );
  240. AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription(), CYAN, 6 );
  241. AppendMsgPanel( _( "Key words" ), m_previewItem->GetKeyWords(), DARKDARKGRAY );
  242. }
  243. GetCanvas()->ForceRefresh();
  244. }
  245. bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
  246. {
  247. if( aSymbol && !aSymbol->IsEmpty() )
  248. {
  249. wxString msg;
  250. LIB_TABLE* libTable = Prj().SchSymbolLibTable();
  251. LIB_ID libid;
  252. libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );
  253. if( libid.IsValid() )
  254. {
  255. wxString nickname = libid.GetLibNickname();
  256. if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
  257. {
  258. msg.sprintf( _( "The current configuration does not include a library with the\n"
  259. "nickname \"%s\". Use Manage Symbol Libraries\n"
  260. "to edit the configuration." ), nickname );
  261. DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
  262. }
  263. else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
  264. {
  265. msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
  266. "in the current configuration. Use Manage Symbol Libraries to\n"
  267. "edit the configuration." ), nickname );
  268. DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
  269. }
  270. else
  271. {
  272. SetSelectedLibrary( libid.GetLibNickname() );
  273. SetSelectedComponent( libid.GetLibItemName() );
  274. }
  275. }
  276. }
  277. return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
  278. }
  279. void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
  280. {
  281. GetCanvas()->StopDrawing();
  282. if( !IsModal() )
  283. {
  284. Destroy();
  285. }
  286. else if( !IsDismissed() )
  287. {
  288. // only dismiss modal frame if not already dismissed.
  289. DismissModal( false );
  290. // Modal frame will be destroyed by the calling function.
  291. }
  292. }
  293. void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
  294. {
  295. if( m_auimgr.GetManagedWindow() )
  296. m_auimgr.Update();
  297. SizeEv.Skip();
  298. }
  299. void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
  300. {
  301. LIB_PART* part = GetSelectedSymbol();
  302. int unit_count = 1;
  303. if( part )
  304. unit_count = std::max( part->GetUnitCount(), 1 );
  305. m_unitChoice->Enable( unit_count > 1 );
  306. if( unit_count > 1 )
  307. {
  308. // rebuild the unit list if it is not suitable (after a new selection for instance)
  309. if( unit_count != (int)m_unitChoice->GetCount() )
  310. {
  311. m_unitChoice->Clear();
  312. for( int ii = 0; ii < unit_count; ii++ )
  313. m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
  314. }
  315. if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
  316. m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
  317. }
  318. else if( m_unitChoice->GetCount() )
  319. m_unitChoice->Clear();
  320. }
  321. bool LIB_VIEW_FRAME::ReCreateListLib()
  322. {
  323. if( !m_libList )
  324. return false;
  325. m_libList->Clear();
  326. std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
  327. // Remove not allowed libs from main list, if the allowed lib list is not empty
  328. if( m_allowedLibs.GetCount() )
  329. {
  330. for( unsigned ii = 0; ii < libs.size(); )
  331. {
  332. if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
  333. libs.erase( libs.begin() + ii );
  334. else
  335. ii++;
  336. }
  337. }
  338. // Remove libs which have no power components, if this filter is activated
  339. if( m_listPowerCmpOnly )
  340. {
  341. for( unsigned ii = 0; ii < libs.size(); )
  342. {
  343. wxArrayString aliasNames;
  344. Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
  345. if( aliasNames.IsEmpty() )
  346. libs.erase( libs.begin() + ii );
  347. else
  348. ii++;
  349. }
  350. }
  351. if( libs.empty() )
  352. return true;
  353. wxArrayString libNames;
  354. for( const auto& name : libs )
  355. libNames.Add( name );
  356. m_libList->Append( libNames );
  357. // Search for a previous selection:
  358. int index = m_libList->FindString( m_libraryName );
  359. if( index != wxNOT_FOUND )
  360. {
  361. m_libList->SetSelection( index, true );
  362. }
  363. else
  364. {
  365. // If not found, clear current library selection because it can be
  366. // deleted after a config change.
  367. m_libraryName = libs[0];
  368. m_entryName = wxEmptyString;
  369. m_unit = 1;
  370. m_convert = LIB_ITEM::LIB_CONVERT::BASE;
  371. }
  372. bool cmp_changed = ReCreateListCmp();
  373. DisplayLibInfos();
  374. GetCanvas()->Refresh();
  375. return cmp_changed;
  376. }
  377. bool LIB_VIEW_FRAME::ReCreateListCmp()
  378. {
  379. if( m_cmpList == NULL )
  380. return false;
  381. wxArrayString aliasNames;
  382. try
  383. {
  384. Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
  385. m_listPowerCmpOnly );
  386. }
  387. catch( const IO_ERROR& ) {} // ignore, it is handled below
  388. m_cmpList->Clear();
  389. if( aliasNames.IsEmpty() )
  390. {
  391. m_libraryName = wxEmptyString;
  392. m_entryName = wxEmptyString;
  393. m_convert = LIB_ITEM::LIB_CONVERT::BASE;
  394. m_unit = 1;
  395. return true;
  396. }
  397. m_cmpList->Append( aliasNames );
  398. int index = m_cmpList->FindString( m_entryName );
  399. bool changed = false;
  400. if( index == wxNOT_FOUND )
  401. {
  402. // Select the first library entry when the previous entry name does not exist in
  403. // the current library.
  404. m_convert = LIB_ITEM::LIB_CONVERT::BASE;
  405. m_unit = 1;
  406. index = 0;
  407. changed = true;
  408. m_entryName = wxEmptyString;
  409. }
  410. m_cmpList->SetSelection( index, true );
  411. wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
  412. ProcessEvent( evt );
  413. return changed;
  414. }
  415. void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
  416. {
  417. int ii = m_libList->GetSelection();
  418. if( ii < 0 )
  419. return;
  420. m_selection_changed = true;
  421. SetSelectedLibrary( m_libList->GetString( ii ) );
  422. }
  423. void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
  424. {
  425. if( m_libraryName == aLibraryName )
  426. return;
  427. m_libraryName = aLibraryName;
  428. ReCreateListCmp();
  429. GetCanvas()->Refresh();
  430. DisplayLibInfos();
  431. // Ensure the corresponding line in m_libList is selected
  432. // (which is not necessary the case if SetSelectedLibrary is called
  433. // by another caller than ClickOnLibList.
  434. m_libList->SetStringSelection( m_libraryName, true );
  435. // The m_libList has now the focus, in order to be able to use arrow keys
  436. // to navigate inside the list.
  437. // the gal canvas must not steal the focus to allow navigation
  438. GetCanvas()->SetStealsFocus( false );
  439. m_libList->SetFocus();
  440. }
  441. void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
  442. {
  443. int ii = m_cmpList->GetSelection();
  444. if( ii < 0 )
  445. return;
  446. m_selection_changed = true;
  447. SetSelectedComponent( m_cmpList->GetString( ii ) );
  448. // The m_cmpList has now the focus, in order to be able to use arrow keys
  449. // to navigate inside the list.
  450. // the gal canvas must not steal the focus to allow navigation
  451. GetCanvas()->SetStealsFocus( false );
  452. m_cmpList->SetFocus();
  453. }
  454. void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
  455. {
  456. if( m_entryName != aComponentName )
  457. {
  458. m_entryName = aComponentName;
  459. // Ensure the corresponding line in m_cmpList is selected
  460. // (which is not necessarily the case if SetSelectedComponent is called
  461. // by another caller than ClickOnCmpList.
  462. m_cmpList->SetStringSelection( aComponentName, true );
  463. DisplayLibInfos();
  464. if( m_selection_changed )
  465. {
  466. m_unit = 1;
  467. m_convert = LIB_ITEM::LIB_CONVERT::BASE;
  468. m_selection_changed = false;
  469. }
  470. updatePreviewSymbol();
  471. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  472. }
  473. }
  474. void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
  475. {
  476. m_toolManager->RunAction( EE_ACTIONS::addSymbolToSchematic, true );
  477. }
  478. void LIB_VIEW_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  479. {
  480. auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
  481. EDA_DRAW_FRAME::LoadSettings( cfg );
  482. // Grid shape, etc.
  483. GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
  484. m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
  485. m_cmpListWidth = cfg->m_LibViewPanel.cmp_list_width;
  486. m_showPinElectricalTypeName = cfg->m_LibViewPanel.show_pin_electrical_type;
  487. // Set parameters to a reasonable value.
  488. if( m_libListWidth > m_FrameSize.x/2 )
  489. m_libListWidth = m_FrameSize.x/2;
  490. if( m_cmpListWidth > m_FrameSize.x/2 )
  491. m_cmpListWidth = m_FrameSize.x/2;
  492. }
  493. void LIB_VIEW_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg)
  494. {
  495. auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
  496. EDA_DRAW_FRAME::SaveSettings( cfg );
  497. if( m_libListWidth && m_libList )
  498. m_libListWidth = m_libList->GetSize().x;
  499. m_cmpListWidth = m_cmpList->GetSize().x;
  500. cfg->m_LibViewPanel.lib_list_width = m_libListWidth;
  501. cfg->m_LibViewPanel.cmp_list_width = m_cmpListWidth;
  502. cfg->m_LibViewPanel.show_pin_electrical_type = m_showPinElectricalTypeName;
  503. }
  504. WINDOW_SETTINGS* LIB_VIEW_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  505. {
  506. auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
  507. wxASSERT( cfg );
  508. return &cfg->m_LibViewPanel.window;
  509. }
  510. void LIB_VIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
  511. {
  512. SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
  513. if( aEnvVarsChanged )
  514. ReCreateListLib();
  515. }
  516. void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
  517. {
  518. if( event.GetActive() )
  519. {
  520. bool changed = m_libList ? ReCreateListLib() : false;
  521. if (changed)
  522. m_selection_changed = true;
  523. updatePreviewSymbol();
  524. DisplayLibInfos();
  525. }
  526. event.Skip(); // required under wxMAC
  527. }
  528. void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
  529. {
  530. Close();
  531. }
  532. void LIB_VIEW_FRAME::SetFilter( const SCHLIB_FILTER* aFilter )
  533. {
  534. m_listPowerCmpOnly = false;
  535. m_allowedLibs.Clear();
  536. if( aFilter )
  537. {
  538. m_allowedLibs = aFilter->GetAllowedLibList();
  539. m_listPowerCmpOnly = aFilter->GetFilterPowerParts();
  540. }
  541. ReCreateListLib();
  542. }
  543. const BOX2I LIB_VIEW_FRAME::GetDocumentExtents() const
  544. {
  545. LIB_PART* part = GetSelectedSymbol();
  546. if( !part )
  547. {
  548. return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
  549. }
  550. else
  551. {
  552. std::shared_ptr< LIB_PART > tmp;
  553. tmp = ( part->IsAlias() ) ? part->GetParent().lock() : part->SharedPtr();
  554. wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
  555. EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
  556. return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
  557. }
  558. }
  559. void LIB_VIEW_FRAME::FinishModal()
  560. {
  561. if( m_cmpList->GetSelection() >= 0 )
  562. DismissModal( true, m_libraryName + ':' + m_cmpList->GetStringSelection() );
  563. else
  564. DismissModal( false );
  565. Close( true );
  566. }
  567. void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
  568. {
  569. std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
  570. // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
  571. if( !dialogLock.try_lock() )
  572. return;
  573. // Container doing search-as-you-type.
  574. SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
  575. auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs ) );
  576. auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
  577. const auto libNicknames = libs->GetLogicalLibs();
  578. adapter->AddLibraries( libNicknames, this );
  579. LIB_PART* current = GetSelectedSymbol();
  580. LIB_ID id;
  581. int unit = 0;
  582. if( current )
  583. {
  584. id = current->GetLibId();
  585. adapter->SetPreselectNode( id, unit );
  586. }
  587. wxString dialogTitle;
  588. dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
  589. DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false );
  590. if( dlg.ShowQuasiModal() == wxID_CANCEL )
  591. return;
  592. id = dlg.GetSelectedLibId( &unit );
  593. if( !id.IsValid() )
  594. return;
  595. SetSelectedLibrary( id.GetLibNickname() );
  596. SetSelectedComponent( id.GetLibItemName() );
  597. SetUnitAndConvert( unit, 1 );
  598. }
  599. void LIB_VIEW_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
  600. {
  601. wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
  602. int ii = m_cmpList->GetSelection();
  603. // Select the next symbol or stop at the end of the list.
  604. if( ii != wxNOT_FOUND || ii != (int)m_cmpList->GetCount() - 1 )
  605. ii += 1;
  606. m_cmpList->SetSelection( ii );
  607. ProcessEvent( evt );
  608. }
  609. void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
  610. {
  611. wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
  612. int ii = m_cmpList->GetSelection();
  613. // Select the previous symbol or stop at the beginning of list.
  614. if( ii != wxNOT_FOUND && ii != 0 )
  615. ii -= 1;
  616. m_cmpList->SetSelection( ii );
  617. ProcessEvent( evt );
  618. }
  619. void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
  620. {
  621. int ii = m_unitChoice->GetSelection();
  622. if( ii < 0 )
  623. return;
  624. m_unit = ii + 1;
  625. updatePreviewSymbol();
  626. }
  627. void LIB_VIEW_FRAME::DisplayLibInfos()
  628. {
  629. if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
  630. {
  631. const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName );
  632. wxString title = wxString::Format( _( "Symbol Library Browser -- %s" ),
  633. row ? row->GetFullURI() : _( "no library selected" ) );
  634. SetTitle( title );
  635. }
  636. }