kicad/eeschema/symbol_viewer_frame.cpp

913 lines
26 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <bitmaps.h>
#include <class_library.h>
#include <confirm.h>
#include <dialog_helpers.h>
#include <dialog_choose_symbol.h>
#include <eeschema_id.h>
#include <eeschema_settings.h>
#include <kiface_i.h>
#include <kiway.h>
2020-12-25 23:37:01 +00:00
#include <symbol_viewer_frame.h>
#include <widgets/msgpanel.h>
#include <sch_view.h>
#include <sch_painter.h>
#include <symbol_lib_table.h>
#include <symbol_tree_model_adapter.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
2019-06-09 21:57:23 +00:00
#include <tool/action_toolbar.h>
#include <tool/common_control.h>
#include <tool/common_tools.h>
#include <tool/editor_conditions.h>
#include <tool/selection.h>
#include <tool/tool_dispatcher.h>
#include <tool/tool_manager.h>
#include <tool/zoom_tool.h>
#include <tools/ee_actions.h>
2020-12-12 03:13:52 +00:00
#include <tools/symbol_editor_control.h>
2019-06-01 18:36:49 +00:00
#include <tools/ee_inspection_tool.h>
#include <view/view_controls.h>
#include <default_values.h>
// Save previous component library viewer state.
2020-12-25 23:37:01 +00:00
wxString SYMBOL_VIEWER_FRAME::m_libraryName;
wxString SYMBOL_VIEWER_FRAME::m_entryName;
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.
2014-05-03 17:40:19 +00:00
2020-12-25 23:37:01 +00:00
int SYMBOL_VIEWER_FRAME::m_unit = 1;
int SYMBOL_VIEWER_FRAME::m_convert = 1;
2020-12-25 23:37:01 +00:00
BEGIN_EVENT_TABLE( SYMBOL_VIEWER_FRAME, EDA_DRAW_FRAME )
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.
2014-05-03 17:40:19 +00:00
// Window events
2020-12-25 23:37:01 +00:00
EVT_SIZE( SYMBOL_VIEWER_FRAME::OnSize )
EVT_ACTIVATE( SYMBOL_VIEWER_FRAME::OnActivate )
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.
2014-05-03 17:40:19 +00:00
// Toolbar events
2020-12-25 23:37:01 +00:00
EVT_TOOL( ID_LIBVIEW_SELECT_PART, SYMBOL_VIEWER_FRAME::OnSelectSymbol )
EVT_TOOL( ID_LIBVIEW_NEXT, SYMBOL_VIEWER_FRAME::onSelectNextSymbol )
EVT_TOOL( ID_LIBVIEW_PREVIOUS, SYMBOL_VIEWER_FRAME::onSelectPreviousSymbol )
EVT_CHOICE( ID_LIBVIEW_SELECT_PART_NUMBER, SYMBOL_VIEWER_FRAME::onSelectSymbolUnit )
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.
2014-05-03 17:40:19 +00:00
// listbox events
2020-12-25 23:37:01 +00:00
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, SYMBOL_VIEWER_FRAME::ClickOnLibList )
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, SYMBOL_VIEWER_FRAME::ClickOnCmpList )
EVT_LISTBOX_DCLICK( ID_LIBVIEW_CMP_LIST, SYMBOL_VIEWER_FRAME::DClickOnCmpList )
// Menu (and/or hotkey) events
2020-12-25 23:37:01 +00:00
EVT_MENU( wxID_CLOSE, SYMBOL_VIEWER_FRAME::CloseLibraryViewer )
EVT_MENU( ID_GRID_SETTINGS, SCH_BASE_FRAME::OnGridSettings )
2020-12-25 23:37:01 +00:00
EVT_UPDATE_UI( ID_LIBVIEW_SELECT_PART_NUMBER, SYMBOL_VIEWER_FRAME::onUpdateUnitChoice )
END_EVENT_TABLE()
#define LIB_VIEW_NAME "ViewlibFrame"
#define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
#define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
#define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
2020-12-25 23:37:01 +00:00
SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
const wxString& aLibraryName ) :
SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
wxDefaultPosition, wxDefaultSize,
aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_STYLE_MODAL : LIB_VIEW_STYLE,
aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_NAME_MODAL : LIB_VIEW_NAME ),
2020-12-17 23:56:47 +00:00
m_unitChoice( nullptr ),
m_libList( nullptr ),
m_symbolList( nullptr ),
m_previewItem( nullptr )
{
wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
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.
2014-05-03 17:40:19 +00:00
if( aFrameType == FRAME_SCH_VIEWER_MODAL )
SetModal( true );
m_aboutTitle = _( "KiCad Symbol Library Viewer" );
// Force the frame name used in config. the lib viewer frame has a name
// depending on aFrameType (needed to identify the frame by wxWidgets),
// but only one configuration is preferable.
m_configName = LIB_VIEW_NAME;
// Give an icon
wxIcon icon;
icon.CopyFromBitmap( KiBitmap( BITMAPS::library_browser ) );
SetIcon( icon );
m_libListWidth = 200;
2020-12-17 23:56:47 +00:00
m_symbolListWidth = 300;
m_listPowerCmpOnly = false;
SetScreen( new SCH_SCREEN );
GetScreen()->m_Center = true; // Axis origin centered on screen.
* 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.
2014-03-20 00:42:08 +00:00
LoadSettings( config() );
// Ensure axis are always drawn (initial default display was not drawn)
KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions();
gal_opts.m_axesEnabled = true;
gal_opts.m_gridMinSpacing = 10.0;
gal_opts.NotifyChanged();
GetRenderSettings()->LoadColors( GetColorSettings() );
GetCanvas()->GetGAL()->SetAxesColor( m_colorSettings->GetColor( LAYER_SCHEMATIC_GRID_AXES ) );
GetRenderSettings()->m_ShowHiddenText = true;
GetRenderSettings()->m_ShowHiddenPins = true;
GetRenderSettings()->SetDefaultPenWidth( DEFAULT_LINE_THICKNESS * IU_PER_MILS );
setupTools();
setupUIConditions();
ReCreateHToolbar();
ReCreateVToolbar();
ReCreateMenuBar();
m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
0, NULL, wxLB_HSCROLL | wxNO_BORDER );
2020-12-17 23:56:47 +00:00
m_symbolList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize,
0, NULL, wxLB_HSCROLL | wxNO_BORDER );
if( aLibraryName.empty() )
{
2020-12-17 23:56:47 +00:00
ReCreateLibList();
}
else
{
m_libraryName = aLibraryName;
m_entryName.Clear();
m_unit = 1;
m_convert = 1;
}
m_selection_changed = false;
DisplayLibInfos();
m_auimgr.SetManagedWindow( this );
2009-11-02 22:24:55 +00:00
// Manage main toolbar
m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
2009-11-02 22:24:55 +00:00
m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
.CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
2020-12-17 23:56:47 +00:00
m_auimgr.AddPane( m_symbolList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
.CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_symbolListWidth, -1 ) );
2009-11-02 22:24:55 +00:00
m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
2014-01-19 16:36:12 +00:00
m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
2009-11-02 22:24:55 +00:00
m_auimgr.Update();
if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
{
Raise();
Show( true );
}
SyncView();
GetCanvas()->SetCanFocus( false );
setupUnits( config() );
// Set the working/draw area size to display a symbol to a reasonable value:
// A 450mm x 450mm with a origin at the area center looks like a large working area
double max_size_x = Millimeter2iu( 450 );
double max_size_y = Millimeter2iu( 450 );
BOX2D bbox;
bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
bbox.SetSize( max_size_x, max_size_y );
GetCanvas()->GetView()->SetBoundary( bbox );
GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
}
2020-12-25 23:37:01 +00:00
SYMBOL_VIEWER_FRAME::~SYMBOL_VIEWER_FRAME()
{
// Shutdown all running tools
if( m_toolManager )
m_toolManager->ShutdownAllTools();
if( m_previewItem )
GetCanvas()->GetView()->Remove( m_previewItem );
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::setupTools()
{
// Create the manager and dispatcher & route draw panel events to the dispatcher
m_toolManager = new TOOL_MANAGER;
m_toolManager->SetEnvironment( GetScreen(), GetCanvas()->GetView(),
GetCanvas()->GetViewControls(), config(), this );
m_actions = new EE_ACTIONS();
m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
// Register tools
m_toolManager->RegisterTool( new COMMON_TOOLS );
m_toolManager->RegisterTool( new COMMON_CONTROL );
m_toolManager->RegisterTool( new ZOOM_TOOL );
2019-06-01 18:36:49 +00:00
m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
2020-12-12 03:13:52 +00:00
m_toolManager->RegisterTool( new SYMBOL_EDITOR_CONTROL );
m_toolManager->InitTools();
// Run the selection tool, it is supposed to be always active
// It also manages the mouse right click to show the context menu
m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
GetCanvas()->SetEventDispatcher( m_toolDispatcher );
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::setupUIConditions()
{
SCH_BASE_FRAME::setupUIConditions();
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
EDITOR_CONDITIONS cond( this );
wxASSERT( mgr );
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
#define CHECK( x ) ACTION_CONDITIONS().Check( x )
mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
auto electricalTypesShownCondition =
[this] ( const SELECTION& aSel )
{
return GetRenderSettings()->m_ShowPinsElectricalType;
};
auto demorganCond =
[this] ( const SELECTION& )
{
LIB_PART* symbol = GetSelectedSymbol();
return symbol && symbol->HasConversion();
};
auto demorganStandardCond =
[] ( const SELECTION& )
{
return m_convert == LIB_ITEM::LIB_CONVERT::BASE;
};
auto demorganAlternateCond =
[] ( const SELECTION& )
{
return m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN;
};
auto haveDatasheetCond =
[this] ( const SELECTION& )
{
LIB_PART* symbol = GetSelectedSymbol();
return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
};
mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
mgr->SetConditions( EE_ACTIONS::showElectricalTypes, CHECK( electricalTypesShownCondition ) );
mgr->SetConditions( EE_ACTIONS::showDeMorganStandard,
ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) );
mgr->SetConditions( EE_ACTIONS::showDeMorganAlternate,
ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganAlternateCond ) );
#undef CHECK
#undef ENABLE
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
{
m_unit = aUnit > 0 ? aUnit : 1;
m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
m_selection_changed = false;
2019-06-01 19:48:01 +00:00
updatePreviewSymbol();
}
2020-12-25 23:37:01 +00:00
LIB_PART* SYMBOL_VIEWER_FRAME::GetSelectedSymbol() const
{
LIB_PART* symbol = nullptr;
if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
return symbol;
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::updatePreviewSymbol()
{
LIB_PART* symbol = GetSelectedSymbol();
KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
if( m_previewItem )
{
view->Remove( m_previewItem );
m_previewItem = nullptr;
}
ClearMsgPanel();
if( symbol )
{
GetRenderSettings()->m_ShowUnit = m_unit;
GetRenderSettings()->m_ShowConvert = m_convert;
m_previewItem = symbol;
view->Add( m_previewItem );
wxString parentName;
std::shared_ptr<LIB_PART> parent = m_previewItem->GetParent().lock();
if( parent )
parentName = parent->GetName();
AppendMsgPanel( _( "Name" ), m_previewItem->GetName() );
AppendMsgPanel( _( "Parent" ), parentName );
AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription() );
AppendMsgPanel( _( "Keywords" ), m_previewItem->GetKeyWords() );
}
GetCanvas()->ForceRefresh();
}
2020-12-25 23:37:01 +00:00
bool SYMBOL_VIEWER_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
{
if( aSymbol && !aSymbol->IsEmpty() )
{
wxString msg;
LIB_TABLE* libTable = Prj().SchSymbolLibTable();
LIB_ID libid;
libid.Parse( *aSymbol, true );
if( libid.IsValid() )
{
wxString libName = libid.GetLibNickname();
if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
{
msg.Printf( _( "The current configuration does not include the library '%s'.\n"
"Use Manage Symbol Libraries to edit the configuration." ),
libName );
DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
}
else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
{
msg.Printf( _( "The library '%s' is not enabled in the current configuration.\n"
"Use Manage Symbol Libraries to edit the configuration." ),
libName );
DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
}
else
{
SetSelectedLibrary( libid.GetLibNickname() );
2021-03-19 20:27:30 +00:00
SetSelectedSymbol( libid.GetLibItemName());
}
}
}
return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::doCloseWindow()
{
GetCanvas()->StopDrawing();
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.
2014-05-03 17:40:19 +00:00
if( !IsModal() )
{
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.
2014-05-03 17:40:19 +00:00
Destroy();
}
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.
2014-05-03 17:40:19 +00:00
else if( !IsDismissed() )
{
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.
2014-05-03 17:40:19 +00:00
// only dismiss modal frame if not already dismissed.
DismissModal( false );
// Modal frame will be destroyed by the calling function.
}
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
{
if( m_auimgr.GetManagedWindow() )
m_auimgr.Update();
SizeEv.Skip();
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
{
LIB_PART* part = GetSelectedSymbol();
int unit_count = 1;
if( part )
unit_count = std::max( part->GetUnitCount(), 1 );
m_unitChoice->Enable( unit_count > 1 );
if( unit_count > 1 )
{
// rebuild the unit list if it is not suitable (after a new selection for instance)
if( unit_count != (int)m_unitChoice->GetCount() )
{
m_unitChoice->Clear();
for( int ii = 0; ii < unit_count; ii++ )
m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
}
if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
}
else if( m_unitChoice->GetCount() )
m_unitChoice->Clear();
}
2020-12-25 23:37:01 +00:00
bool SYMBOL_VIEWER_FRAME::ReCreateLibList()
{
if( !m_libList )
return false;
2014-01-19 16:36:12 +00:00
m_libList->Clear();
std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
// Remove not allowed libs from main list, if the allowed lib list is not empty
if( m_allowedLibs.GetCount() )
{
for( unsigned ii = 0; ii < libs.size(); )
{
if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
libs.erase( libs.begin() + ii );
else
ii++;
}
}
// Remove libs which have no power components, if this filter is activated
if( m_listPowerCmpOnly )
{
for( unsigned ii = 0; ii < libs.size(); )
{
wxArrayString aliasNames;
Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
if( aliasNames.IsEmpty() )
libs.erase( libs.begin() + ii );
else
ii++;
}
}
if( libs.empty() )
return true;
wxArrayString libNames;
for( const auto& name : libs )
libNames.Add( name );
m_libList->Append( libNames );
// Search for a previous selection:
2014-01-19 16:36:12 +00:00
int index = m_libList->FindString( m_libraryName );
if( index != wxNOT_FOUND )
{
2014-01-19 16:36:12 +00:00
m_libList->SetSelection( index, true );
}
else
{
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.
2014-05-03 17:40:19 +00:00
// If not found, clear current library selection because it can be
// deleted after a config change.
m_libraryName = libs[0];
m_entryName = wxEmptyString;
m_unit = 1;
m_convert = LIB_ITEM::LIB_CONVERT::BASE;
}
2020-12-17 23:56:47 +00:00
bool cmp_changed = ReCreateSymbolList();
DisplayLibInfos();
GetCanvas()->Refresh();
return cmp_changed;
}
2020-12-25 23:37:01 +00:00
bool SYMBOL_VIEWER_FRAME::ReCreateSymbolList()
{
2020-12-17 23:56:47 +00:00
if( m_symbolList == NULL )
return false;
wxArrayString aliasNames;
try
{
Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
m_listPowerCmpOnly );
}
catch( const IO_ERROR& ) {} // ignore, it is handled below
2020-12-17 23:56:47 +00:00
m_symbolList->Clear();
if( aliasNames.IsEmpty() )
{
m_libraryName = wxEmptyString;
m_entryName = wxEmptyString;
m_convert = LIB_ITEM::LIB_CONVERT::BASE;
m_unit = 1;
return true;
}
2020-12-17 23:56:47 +00:00
m_symbolList->Append( aliasNames );
2020-12-17 23:56:47 +00:00
int index = m_symbolList->FindString( m_entryName );
bool changed = false;
if( index == wxNOT_FOUND )
{
// Select the first library entry when the previous entry name does not exist in
// the current library.
m_convert = LIB_ITEM::LIB_CONVERT::BASE;
m_unit = 1;
index = 0;
changed = true;
m_entryName = wxEmptyString;
}
2020-12-17 23:56:47 +00:00
m_symbolList->SetSelection( index, true );
wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
ProcessEvent( evt );
return changed;
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
{
2014-01-19 16:36:12 +00:00
int ii = m_libList->GetSelection();
if( ii < 0 )
return;
m_selection_changed = true;
SetSelectedLibrary( m_libList->GetString( ii ) );
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
{
if( m_libraryName == aLibraryName )
return;
m_libraryName = aLibraryName;
2020-12-17 23:56:47 +00:00
ReCreateSymbolList();
GetCanvas()->Refresh();
DisplayLibInfos();
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.
2014-05-03 17:40:19 +00:00
// Ensure the corresponding line in m_libList is selected
// (which is not necessary the case if SetSelectedLibrary is called
2018-04-08 10:28:59 +00:00
// by another caller than ClickOnLibList.
m_libList->SetStringSelection( m_libraryName, true );
// The m_libList has now the focus, in order to be able to use arrow keys
// to navigate inside the list.
// the gal canvas must not steal the focus to allow navigation
GetCanvas()->SetStealsFocus( false );
m_libList->SetFocus();
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::ClickOnCmpList( wxCommandEvent& event )
{
2020-12-17 23:56:47 +00:00
int ii = m_symbolList->GetSelection();
if( ii < 0 )
return;
m_selection_changed = true;
2021-03-19 20:27:30 +00:00
SetSelectedSymbol( m_symbolList->GetString( ii ));
2020-12-17 23:56:47 +00:00
// The m_symbolList has now the focus, in order to be able to use arrow keys
// to navigate inside the list.
// the gal canvas must not steal the focus to allow navigation
GetCanvas()->SetStealsFocus( false );
2020-12-17 23:56:47 +00:00
m_symbolList->SetFocus();
}
2021-03-19 20:27:30 +00:00
void SYMBOL_VIEWER_FRAME::SetSelectedSymbol( const wxString& aSymbolName )
{
2021-03-19 20:27:30 +00:00
if( m_entryName != aSymbolName )
{
2021-03-19 20:27:30 +00:00
m_entryName = aSymbolName;
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.
2014-05-03 17:40:19 +00:00
2020-12-17 23:56:47 +00:00
// Ensure the corresponding line in m_symbolList is selected
2021-03-19 20:27:30 +00:00
// (which is not necessarily the case if SetSelectedSymbol is called
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.
2014-05-03 17:40:19 +00:00
// by another caller than ClickOnCmpList.
2021-03-19 20:27:30 +00:00
m_symbolList->SetStringSelection( aSymbolName, true );
DisplayLibInfos();
if( m_selection_changed )
{
m_unit = 1;
m_convert = LIB_ITEM::LIB_CONVERT::BASE;
m_selection_changed = false;
}
updatePreviewSymbol();
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
}
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::DClickOnCmpList( wxCommandEvent& event )
{
2019-06-16 18:51:47 +00:00
m_toolManager->RunAction( EE_ACTIONS::addSymbolToSchematic, true );
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{
auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
SCH_BASE_FRAME::LoadSettings( cfg );
// Grid shape, etc.
GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
2020-12-17 23:56:47 +00:00
m_symbolListWidth = cfg->m_LibViewPanel.cmp_list_width;
GetRenderSettings()->m_ShowPinsElectricalType = cfg->m_LibViewPanel.show_pin_electrical_type;
// Set parameters to a reasonable value.
2020-11-16 11:16:44 +00:00
if( m_libListWidth > m_frameSize.x / 2 )
m_libListWidth = m_frameSize.x / 2;
2020-12-17 23:56:47 +00:00
if( m_symbolListWidth > m_frameSize.x / 2 )
m_symbolListWidth = m_frameSize.x / 2;
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg)
{
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
SCH_BASE_FRAME::SaveSettings( cfg );
* 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.
2014-03-20 00:42:08 +00:00
if( m_libListWidth && m_libList )
2014-01-19 16:36:12 +00:00
m_libListWidth = m_libList->GetSize().x;
2020-12-17 23:56:47 +00:00
m_symbolListWidth = m_symbolList->GetSize().x;
cfg->m_LibViewPanel.lib_list_width = m_libListWidth;
2020-12-17 23:56:47 +00:00
cfg->m_LibViewPanel.cmp_list_width = m_symbolListWidth;
cfg->m_LibViewPanel.show_pin_electrical_type = GetRenderSettings()->m_ShowPinsElectricalType;
}
2020-12-25 23:37:01 +00:00
WINDOW_SETTINGS* SYMBOL_VIEWER_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
{
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
wxASSERT( cfg );
return &cfg->m_LibViewPanel.window;
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
{
SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
GetCanvas()->GetGAL()->SetAxesColor( m_colorSettings->GetColor( LAYER_SCHEMATIC_GRID_AXES ) );
GetCanvas()->GetGAL()->DrawGrid();
if( aEnvVarsChanged )
2020-12-17 23:56:47 +00:00
ReCreateLibList();
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
{
if( event.GetActive() )
{
2020-12-17 23:56:47 +00:00
bool changed = m_libList ? ReCreateLibList() : false;
if (changed)
m_selection_changed = true;
updatePreviewSymbol();
DisplayLibInfos();
}
event.Skip(); // required under wxMAC
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::CloseLibraryViewer( wxCommandEvent& event )
{
Close();
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::SetFilter( const SCHLIB_FILTER* aFilter )
{
m_listPowerCmpOnly = false;
m_allowedLibs.Clear();
if( aFilter )
{
m_allowedLibs = aFilter->GetAllowedLibList();
m_listPowerCmpOnly = aFilter->GetFilterPowerParts();
}
2020-12-17 23:56:47 +00:00
ReCreateLibList();
}
2020-12-25 23:37:01 +00:00
const BOX2I SYMBOL_VIEWER_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
{
LIB_PART* part = GetSelectedSymbol();
if( !part )
{
return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
}
else
{
std::shared_ptr< LIB_PART > tmp;
tmp = ( part->IsAlias() ) ? part->GetParent().lock() : part->SharedPtr();
wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
}
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::FinishModal()
{
2020-12-17 23:56:47 +00:00
if( m_symbolList->GetSelection() >= 0 )
DismissModal( true, m_libraryName + ':' + m_symbolList->GetStringSelection() );
2019-06-16 18:51:47 +00:00
else
DismissModal( false );
2019-06-16 18:51:47 +00:00
Close( true );
}
2019-05-10 19:57:24 +00:00
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
{
std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_SYMBOL::g_Mutex, std::defer_lock );
// One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
if( !dialogLock.try_lock() )
return;
// Container doing search-as-you-type.
SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
2020-11-07 14:31:50 +00:00
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> adapter = SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs );
const auto libNicknames = libs->GetLogicalLibs();
2020-11-07 14:31:50 +00:00
static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapter.get() )->AddLibraries( libNicknames, this );
LIB_PART* current = GetSelectedSymbol();
LIB_ID id;
int unit = 0;
if( current )
{
id = current->GetLibId();
adapter->SetPreselectNode( id, unit );
}
wxString dialogTitle;
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
DIALOG_CHOOSE_SYMBOL dlg( this, dialogTitle, adapter, m_convert, false, false, false );
if( dlg.ShowQuasiModal() == wxID_CANCEL )
return;
id = dlg.GetSelectedLibId( &unit );
if( !id.IsValid() )
return;
SetSelectedLibrary( id.GetLibNickname() );
2021-03-19 20:27:30 +00:00
SetSelectedSymbol( id.GetLibItemName() );
SetUnitAndConvert( unit, 1 );
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
{
wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
2020-12-17 23:56:47 +00:00
int ii = m_symbolList->GetSelection();
// Select the next symbol or stop at the end of the list.
2020-12-17 23:56:47 +00:00
if( ii != wxNOT_FOUND || ii != (int) m_symbolList->GetCount() - 1 )
ii += 1;
2020-12-17 23:56:47 +00:00
m_symbolList->SetSelection( ii );
ProcessEvent( evt );
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
{
wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
2020-12-17 23:56:47 +00:00
int ii = m_symbolList->GetSelection();
// Select the previous symbol or stop at the beginning of list.
if( ii != wxNOT_FOUND && ii != 0 )
ii -= 1;
2020-12-17 23:56:47 +00:00
m_symbolList->SetSelection( ii );
ProcessEvent( evt );
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
{
int ii = m_unitChoice->GetSelection();
if( ii < 0 )
return;
m_unit = ii + 1;
updatePreviewSymbol();
}
2020-12-25 23:37:01 +00:00
void SYMBOL_VIEWER_FRAME::DisplayLibInfos()
{
if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
{
const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName, true );
wxString title = wxString::Format( wxT( "%s \u2014 " ) + _( "Symbol Library Browser" ),
row ? row->GetFullURI() : _( "no library selected" ) );
SetTitle( title );
}
}
2020-12-25 23:37:01 +00:00
SELECTION& SYMBOL_VIEWER_FRAME::GetCurrentSelection()
{
return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
}