2017-11-12 17:55:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
2023-10-14 22:00:02 +00:00
|
|
|
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-11-12 17:55:20 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 3
|
|
|
|
* 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:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-07-22 08:26:49 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <project/project_file.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <symbol_tree_synchronizing_adapter.h>
|
2022-09-16 03:06:23 +00:00
|
|
|
#include <lib_symbol_library_manager.h>
|
2018-02-06 15:14:01 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2020-12-12 03:13:52 +00:00
|
|
|
#include <tools/symbol_editor_control.h>
|
2023-09-28 03:04:53 +00:00
|
|
|
#include <project_sch.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2023-09-02 21:13:48 +00:00
|
|
|
#include <symbol_preview_widget.h>
|
|
|
|
#include <widgets/wx_panel.h>
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
|
|
|
|
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create( SYMBOL_EDIT_FRAME* aParent,
|
|
|
|
SYMBOL_LIBRARY_MANAGER* aLibMgr )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
auto* adapter = new SYMBOL_TREE_SYNCHRONIZING_ADAPTER( aParent, aLibMgr );
|
|
|
|
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::SYMBOL_TREE_SYNCHRONIZING_ADAPTER( SYMBOL_EDIT_FRAME* aParent,
|
|
|
|
SYMBOL_LIBRARY_MANAGER* aLibMgr ) :
|
2020-05-31 21:42:04 +00:00
|
|
|
LIB_TREE_MODEL_ADAPTER( aParent, "pinned_symbol_libs" ),
|
2019-06-05 19:15:57 +00:00
|
|
|
m_frame( aParent ),
|
|
|
|
m_libMgr( aLibMgr ),
|
|
|
|
m_lastSyncHash( -1 )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-05 19:15:57 +00:00
|
|
|
TOOL_INTERACTIVE* SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool()
|
|
|
|
{
|
2020-12-12 03:13:52 +00:00
|
|
|
return m_frame->GetToolManager()->GetTool<SYMBOL_EDITOR_CONTROL>();
|
2019-06-05 19:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::IsContainer( const wxDataViewItem& aItem ) const
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
const LIB_TREE_NODE* node = ToNode( aItem );
|
2023-11-08 17:34:14 +00:00
|
|
|
return node ? node->m_Type == LIB_TREE_NODE::LIBRARY : true;
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
#define PROGRESS_INTERVAL_MILLIS 120
|
2018-01-25 23:49:04 +00:00
|
|
|
|
2021-01-31 22:58:34 +00:00
|
|
|
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( const wxString& aForceRefresh,
|
|
|
|
std::function<void( int, int, const wxString& )> aProgressCallback )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2018-01-29 00:51:07 +00:00
|
|
|
wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
|
2018-01-25 23:49:04 +00:00
|
|
|
|
2021-01-31 22:58:34 +00:00
|
|
|
m_lastSyncHash = m_libMgr->GetHash();
|
2017-11-22 11:06:17 +00:00
|
|
|
int i = 0, max = GetLibrariesCount();
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
// Process already stored libraries
|
2020-02-07 17:06:24 +00:00
|
|
|
for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); /* iteration inside */ )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2020-02-07 17:06:24 +00:00
|
|
|
const wxString& name = it->get()->m_Name;
|
2018-01-25 23:49:04 +00:00
|
|
|
|
|
|
|
if( wxGetUTCTimeMillis() > nextUpdate )
|
|
|
|
{
|
2018-01-29 00:51:07 +00:00
|
|
|
aProgressCallback( i, max, name );
|
2018-01-25 23:49:04 +00:00
|
|
|
nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
|
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-01-31 22:58:34 +00:00
|
|
|
// There is a bug in SYMBOL_LIBRARY_MANAGER::LibraryExists() that uses the buffered
|
|
|
|
// modified libraries before the symbol library table which prevents the library from
|
|
|
|
// being removed from the tree control.
|
2019-06-13 11:44:12 +00:00
|
|
|
if( !m_libMgr->LibraryExists( name, true )
|
2023-09-28 03:04:53 +00:00
|
|
|
|| !PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->HasLibrary( name, true )
|
|
|
|
|| PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->FindRow( name, true ) !=
|
|
|
|
PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->FindRow( name, false )
|
2021-01-31 22:58:34 +00:00
|
|
|
|| name == aForceRefresh )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2017-11-12 13:24:55 +00:00
|
|
|
it = deleteLibrary( it );
|
2017-11-12 17:55:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-01-31 22:58:34 +00:00
|
|
|
else
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2023-11-08 17:34:14 +00:00
|
|
|
updateLibrary( *(LIB_TREE_NODE_LIBRARY*) it->get() );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
2018-01-29 00:51:07 +00:00
|
|
|
++i;
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Look for new libraries
|
2022-07-22 08:26:49 +00:00
|
|
|
//
|
|
|
|
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
|
|
|
PROJECT_FILE& project = m_frame->Prj().GetProjectFile();
|
|
|
|
|
2020-03-31 01:09:01 +00:00
|
|
|
for( const wxString& libName : m_libMgr->GetLibraryNames() )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
if( m_libHashes.count( libName ) == 0 )
|
2017-11-22 11:06:17 +00:00
|
|
|
{
|
2018-01-25 23:49:04 +00:00
|
|
|
if( wxGetUTCTimeMillis() > nextUpdate )
|
|
|
|
{
|
|
|
|
aProgressCallback( i++, max, libName );
|
|
|
|
nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:14:01 +00:00
|
|
|
SYMBOL_LIB_TABLE_ROW* library = m_libMgr->GetLibrary( libName );
|
2022-07-22 08:26:49 +00:00
|
|
|
bool pinned = alg::contains( cfg->m_Session.pinned_symbol_libs, libName )
|
|
|
|
|| alg::contains( project.m_PinnedSymbolLibs, libName );
|
|
|
|
|
2023-11-08 17:34:14 +00:00
|
|
|
LIB_TREE_NODE_LIBRARY& lib_node = DoAddLibraryNode( libName, library->GetDescr(),
|
|
|
|
pinned );
|
2018-02-06 15:14:01 +00:00
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
updateLibrary( lib_node );
|
2017-11-22 11:06:17 +00:00
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
2018-08-05 11:56:02 +00:00
|
|
|
|
|
|
|
m_tree.AssignIntrinsicRanks();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
int SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount() const
|
2017-11-22 11:06:17 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
int count = LIB_TREE_MODEL_ADAPTER::GetLibrariesCount();
|
2017-11-22 11:06:17 +00:00
|
|
|
|
2020-03-31 01:09:01 +00:00
|
|
|
for( const wxString& libName : m_libMgr->GetLibraryNames() )
|
2017-11-22 11:06:17 +00:00
|
|
|
{
|
|
|
|
if( m_libHashes.count( libName ) == 0 )
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-08 17:34:14 +00:00
|
|
|
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary( LIB_TREE_NODE_LIBRARY& aLibNode )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2020-02-07 17:06:24 +00:00
|
|
|
auto hashIt = m_libHashes.find( aLibNode.m_Name );
|
2018-01-10 11:04:34 +00:00
|
|
|
|
|
|
|
if( hashIt == m_libHashes.end() )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2017-11-12 13:24:55 +00:00
|
|
|
// add a new library
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_SYMBOL* alias : m_libMgr->GetAliases( aLibNode.m_Name ) )
|
2018-07-30 13:18:37 +00:00
|
|
|
aLibNode.AddItem( alias );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
2020-02-07 17:06:24 +00:00
|
|
|
else if( hashIt->second != m_libMgr->GetLibraryHash( aLibNode.m_Name ) )
|
2017-11-12 13:24:55 +00:00
|
|
|
{
|
2019-06-13 11:44:12 +00:00
|
|
|
// update an existing library
|
2021-06-10 18:51:46 +00:00
|
|
|
std::list<LIB_SYMBOL*> aliases = m_libMgr->GetAliases( aLibNode.m_Name );
|
2017-11-12 13:24:55 +00:00
|
|
|
|
|
|
|
// remove the common part from the aliases list
|
2020-02-07 17:06:24 +00:00
|
|
|
for( auto nodeIt = aLibNode.m_Children.begin(); nodeIt != aLibNode.m_Children.end(); /**/ )
|
2017-11-12 13:24:55 +00:00
|
|
|
{
|
|
|
|
auto aliasIt = std::find_if( aliases.begin(), aliases.end(),
|
2021-06-30 10:53:04 +00:00
|
|
|
[&] ( const LIB_SYMBOL* a )
|
|
|
|
{
|
|
|
|
return a->GetName() == (*nodeIt)->m_LibId.GetLibItemName();
|
|
|
|
} );
|
2017-11-12 13:24:55 +00:00
|
|
|
|
|
|
|
if( aliasIt != aliases.end() )
|
|
|
|
{
|
2021-06-14 18:00:08 +00:00
|
|
|
// alias exists both in the symbol tree and the library manager,
|
|
|
|
// update only the node data.
|
2023-11-17 18:17:50 +00:00
|
|
|
static_cast<LIB_TREE_NODE_ITEM*>( nodeIt->get() )->Update( *aliasIt );
|
2017-11-12 13:24:55 +00:00
|
|
|
aliases.erase( aliasIt );
|
|
|
|
++nodeIt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// node does not exist in the library manager, remove the corresponding node
|
2020-02-07 17:06:24 +00:00
|
|
|
nodeIt = aLibNode.m_Children.erase( nodeIt );
|
2017-11-12 13:24:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2017-11-12 13:24:55 +00:00
|
|
|
// now the aliases list contains only new aliases that need to be added to the tree
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_SYMBOL* alias : aliases )
|
2018-07-30 13:18:37 +00:00
|
|
|
aLibNode.AddItem( alias );
|
2017-11-12 13:24:55 +00:00
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2017-11-12 13:24:55 +00:00
|
|
|
aLibNode.AssignIntrinsicRanks();
|
2020-02-07 17:06:24 +00:00
|
|
|
m_libHashes[aLibNode.m_Name] = m_libMgr->GetLibraryHash( aLibNode.m_Name );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-22 11:56:52 +00:00
|
|
|
LIB_TREE_NODE::PTR_VECTOR::iterator
|
|
|
|
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::deleteLibrary( LIB_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt )
|
2017-11-12 13:24:55 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
LIB_TREE_NODE* node = aLibNodeIt->get();
|
2020-02-07 17:06:24 +00:00
|
|
|
m_libHashes.erase( node->m_Name );
|
|
|
|
auto it = m_tree.m_Children.erase( aLibNodeIt );
|
2017-11-12 13:24:55 +00:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-04 19:51:28 +00:00
|
|
|
wxDataViewItem SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetCurrentDataViewItem()
|
|
|
|
{
|
|
|
|
if( m_frame->GetCurSymbol() )
|
|
|
|
return FindItem( m_frame->GetCurSymbol()->GetLibId() );
|
|
|
|
|
|
|
|
return wxDataViewItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol ) const
|
2018-01-20 17:15:46 +00:00
|
|
|
{
|
2018-04-28 09:43:41 +00:00
|
|
|
if( IsFrozen() )
|
|
|
|
{
|
|
|
|
aVariant = wxEmptyString;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-31 01:09:01 +00:00
|
|
|
LIB_TREE_NODE* node = ToNode( aItem );
|
2018-01-20 17:15:46 +00:00
|
|
|
wxASSERT( node );
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2022-07-28 13:51:13 +00:00
|
|
|
case NAME_COL:
|
2021-06-15 12:31:28 +00:00
|
|
|
if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId )
|
2023-09-14 15:35:19 +00:00
|
|
|
node->m_Name = m_frame->GetCurSymbol()->GetLibId().GetUniStringLibItemName();
|
2020-02-07 17:06:24 +00:00
|
|
|
|
|
|
|
if( node->m_Pinned )
|
2021-06-30 10:53:04 +00:00
|
|
|
aVariant = GetPinningSymbol() + UnescapeString( node->m_Name );
|
2020-03-31 01:09:01 +00:00
|
|
|
else
|
2021-06-30 10:53:04 +00:00
|
|
|
aVariant = UnescapeString( node->m_Name );
|
2018-01-20 17:15:46 +00:00
|
|
|
|
2020-03-31 01:09:01 +00:00
|
|
|
// mark modified items with an asterisk
|
2023-11-08 17:34:14 +00:00
|
|
|
if( node->m_Type == LIB_TREE_NODE::LIBRARY )
|
2020-03-31 01:09:01 +00:00
|
|
|
{
|
|
|
|
if( m_libMgr->IsLibraryModified( node->m_Name ) )
|
|
|
|
aVariant = aVariant.GetString() + " *";
|
|
|
|
}
|
2023-11-17 18:17:50 +00:00
|
|
|
else if( node->m_Type == LIB_TREE_NODE::ITEM )
|
2020-03-31 01:09:01 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( m_libMgr->IsSymbolModified( node->m_Name, node->m_Parent->m_Name ) )
|
2020-03-31 01:09:01 +00:00
|
|
|
aVariant = aVariant.GetString() + " *";
|
|
|
|
}
|
2018-01-20 17:15:46 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2023-02-14 23:21:05 +00:00
|
|
|
default:
|
|
|
|
if( m_colIdxMap.count( aCol ) )
|
2021-03-17 14:53:27 +00:00
|
|
|
{
|
2023-11-08 17:34:14 +00:00
|
|
|
if( node->m_Type == LIB_TREE_NODE::LIBRARY )
|
2023-02-14 23:21:05 +00:00
|
|
|
{
|
|
|
|
LIB_SYMBOL_LIBRARY_MANAGER& libMgr = m_frame->GetLibManager();
|
|
|
|
SYMBOL_LIB_TABLE_ROW* lib = libMgr.GetLibrary( node->m_LibId.GetLibNickname() );
|
2021-03-17 14:53:27 +00:00
|
|
|
|
2023-02-14 23:21:05 +00:00
|
|
|
if( lib )
|
|
|
|
node->m_Desc = lib->GetDescr();
|
2020-03-31 01:09:01 +00:00
|
|
|
|
2023-02-14 23:21:05 +00:00
|
|
|
if( !m_libMgr->IsLibraryLoaded( node->m_Name ) )
|
|
|
|
aVariant = _( "(failed to load)" ) + wxS( " " ) + aVariant.GetString();
|
|
|
|
}
|
2020-08-29 23:19:05 +00:00
|
|
|
|
2023-02-14 23:21:05 +00:00
|
|
|
const wxString& key = m_colIdxMap.at( aCol );
|
2020-08-29 23:19:05 +00:00
|
|
|
|
2023-02-14 23:21:05 +00:00
|
|
|
if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId )
|
|
|
|
{
|
|
|
|
node->m_Desc = m_frame->GetCurSymbol()->GetDescription();
|
|
|
|
}
|
2018-01-20 17:15:46 +00:00
|
|
|
|
2023-10-14 22:00:02 +00:00
|
|
|
wxString valueStr;
|
|
|
|
|
2023-02-14 23:21:05 +00:00
|
|
|
if( node->m_Fields.count( key ) )
|
2023-10-14 22:00:02 +00:00
|
|
|
valueStr = node->m_Fields.at( key );
|
2023-02-14 23:21:05 +00:00
|
|
|
else if( key == wxT( "Description" ) )
|
2023-10-14 22:00:02 +00:00
|
|
|
valueStr = node->m_Desc;
|
2023-02-14 23:21:05 +00:00
|
|
|
else
|
2023-10-14 22:00:02 +00:00
|
|
|
valueStr = wxEmptyString;
|
|
|
|
|
|
|
|
valueStr.Replace( wxS( "\n" ), wxS( " " ) ); // Clear line breaks
|
|
|
|
|
|
|
|
aVariant = valueStr;
|
2023-02-14 23:21:05 +00:00
|
|
|
}
|
2018-01-20 17:15:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
|
|
|
|
wxDataViewItemAttr& aAttr ) const
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2018-04-28 09:43:41 +00:00
|
|
|
if( IsFrozen() )
|
|
|
|
return false;
|
|
|
|
|
2020-03-31 01:09:01 +00:00
|
|
|
LIB_TREE_NODE* node = ToNode( aItem );
|
2017-11-12 17:55:20 +00:00
|
|
|
wxCHECK( node, false );
|
|
|
|
|
2020-08-29 23:19:05 +00:00
|
|
|
// Mark both columns of unloaded libraries using grey text color (to look disabled)
|
2023-11-08 17:34:14 +00:00
|
|
|
if( node->m_Type == LIB_TREE_NODE::LIBRARY && !m_libMgr->IsLibraryLoaded( node->m_Name ) )
|
2020-08-29 23:19:05 +00:00
|
|
|
{
|
|
|
|
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The remaining attributes are only for the name column
|
2022-07-28 13:51:13 +00:00
|
|
|
if( aCol != NAME_COL )
|
2020-08-29 23:19:05 +00:00
|
|
|
return false;
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* curSymbol = m_frame->GetCurSymbol();
|
2020-12-22 02:29:27 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
switch( node->m_Type )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2023-11-08 17:34:14 +00:00
|
|
|
case LIB_TREE_NODE::LIBRARY:
|
2019-06-13 11:44:12 +00:00
|
|
|
// mark modified libs with bold font
|
2020-02-07 17:06:24 +00:00
|
|
|
aAttr.SetBold( m_libMgr->IsLibraryModified( node->m_Name ) );
|
2017-11-13 11:19:14 +00:00
|
|
|
|
2023-11-15 16:53:58 +00:00
|
|
|
// mark the current library if it's collapsed
|
2021-06-10 18:51:46 +00:00
|
|
|
if( curSymbol && curSymbol->GetLibId().GetLibNickname() == node->m_LibId.GetLibNickname() )
|
2020-12-22 02:29:27 +00:00
|
|
|
{
|
2023-11-15 16:53:58 +00:00
|
|
|
if( !m_widget->IsExpanded( ToItem( node ) ) )
|
|
|
|
{
|
2023-11-20 19:25:51 +00:00
|
|
|
aAttr.SetStrikethrough( true ); // LIB_TREE_RENDERER uses strikethrough as a
|
|
|
|
// proxy for "is canvas item"
|
2023-11-15 16:53:58 +00:00
|
|
|
}
|
2020-12-22 02:29:27 +00:00
|
|
|
}
|
2019-06-13 11:44:12 +00:00
|
|
|
break;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2023-11-17 18:17:50 +00:00
|
|
|
case LIB_TREE_NODE::ITEM:
|
2019-06-13 11:44:12 +00:00
|
|
|
// mark modified part with bold font
|
2021-06-15 12:31:28 +00:00
|
|
|
aAttr.SetBold( m_libMgr->IsSymbolModified( node->m_Name, node->m_Parent->m_Name ) );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-06-13 11:44:12 +00:00
|
|
|
// mark aliases with italic font
|
2020-02-07 17:06:24 +00:00
|
|
|
aAttr.SetItalic( !node->m_IsRoot );
|
2017-11-13 11:19:14 +00:00
|
|
|
|
2023-11-15 16:53:58 +00:00
|
|
|
// mark the current (on-canvas) part
|
2021-06-10 18:51:46 +00:00
|
|
|
if( curSymbol && curSymbol->GetLibId() == node->m_LibId )
|
2020-12-22 02:29:27 +00:00
|
|
|
{
|
2023-11-20 19:25:51 +00:00
|
|
|
aAttr.SetStrikethrough( true ); // LIB_TREE_RENDERER uses strikethrough as a
|
|
|
|
// proxy for "is canvas item"
|
2020-12-22 02:29:27 +00:00
|
|
|
}
|
2019-06-13 11:44:12 +00:00
|
|
|
break;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-06-13 11:44:12 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-09-02 21:13:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::HasPreview( const wxDataViewItem& aItem )
|
|
|
|
{
|
|
|
|
LIB_TREE_NODE* node = ToNode( aItem );
|
|
|
|
wxCHECK( node, false );
|
|
|
|
|
2023-11-17 18:17:50 +00:00
|
|
|
return node->m_Type == LIB_TREE_NODE::ITEM && node->m_LibId != m_frame->GetTargetLibId();
|
2023-09-02 21:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-09 16:02:08 +00:00
|
|
|
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::ShowPreview( wxWindow* aParent,
|
|
|
|
const wxDataViewItem& aItem )
|
2023-09-02 21:13:48 +00:00
|
|
|
{
|
2023-11-09 16:02:08 +00:00
|
|
|
static const wxString c_previewName = wxS( "symHoverPreview" );
|
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
LIB_TREE_NODE* node = ToNode( aItem );
|
|
|
|
wxCHECK( node, /* void */ );
|
|
|
|
|
2023-11-09 16:02:08 +00:00
|
|
|
SYMBOL_PREVIEW_WIDGET* preview = dynamic_cast<SYMBOL_PREVIEW_WIDGET*>(
|
|
|
|
wxWindow::FindWindowByName( c_previewName, aParent ) );
|
|
|
|
|
|
|
|
if( !preview )
|
|
|
|
{
|
|
|
|
wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
aParent->SetSizer( mainSizer );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-11-09 16:02:08 +00:00
|
|
|
WX_PANEL* panel = new WX_PANEL( aParent );
|
|
|
|
panel->SetBorders( true, true, true, true );
|
|
|
|
panel->SetBorderColor( KIGFX::COLOR4D::BLACK );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-11-09 16:02:08 +00:00
|
|
|
wxBoxSizer* panelSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
panel->SetSizer( panelSizer );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-11-09 16:02:08 +00:00
|
|
|
EDA_DRAW_PANEL_GAL::GAL_TYPE backend = m_frame->GetCanvas()->GetBackend();
|
|
|
|
preview = new SYMBOL_PREVIEW_WIDGET( panel, &m_frame->Kiway(), false, backend );
|
|
|
|
preview->SetName( c_previewName );
|
|
|
|
preview->SetLayoutDirection( wxLayout_LeftToRight );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-11-09 16:02:08 +00:00
|
|
|
panelSizer->Add( preview, 1, wxEXPAND | wxALL, 1 );
|
|
|
|
mainSizer->Add( panel, 1, wxEXPAND, 0 );
|
|
|
|
aParent->Layout();
|
|
|
|
}
|
2023-09-02 21:13:48 +00:00
|
|
|
|
|
|
|
preview->DisplaySymbol( node->m_LibId, node->m_Unit );
|
|
|
|
}
|