2018-07-29 15:33:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
2019-06-24 12:00:21 +00:00
|
|
|
* Copyright (C)-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-07-29 15:33:58 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fp_tree_synchronizing_adapter.h>
|
|
|
|
#include <footprint_edit_frame.h>
|
|
|
|
#include <fp_lib_table.h>
|
|
|
|
#include <footprint_info_impl.h>
|
2020-10-15 22:39:33 +00:00
|
|
|
#include <kicad_string.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2019-06-05 19:15:57 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/footprint_editor_tools.h>
|
2018-09-13 23:39:40 +00:00
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
|
|
|
|
FP_TREE_SYNCHRONIZING_ADAPTER::Create( FOOTPRINT_EDIT_FRAME* aFrame, FP_LIB_TABLE* aLibs )
|
2018-07-29 15:33:58 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
auto* adapter = new FP_TREE_SYNCHRONIZING_ADAPTER( aFrame, aLibs );
|
|
|
|
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FP_TREE_SYNCHRONIZING_ADAPTER::FP_TREE_SYNCHRONIZING_ADAPTER( FOOTPRINT_EDIT_FRAME* aFrame,
|
|
|
|
FP_LIB_TABLE* aLibs ) :
|
2020-02-14 14:22:21 +00:00
|
|
|
FP_TREE_MODEL_ADAPTER( aFrame, aLibs ),
|
2018-07-29 15:33:58 +00:00
|
|
|
m_frame( aFrame )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-05 19:15:57 +00:00
|
|
|
TOOL_INTERACTIVE* FP_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool()
|
|
|
|
{
|
2020-05-03 10:27:33 +00:00
|
|
|
return m_frame->GetToolManager()->GetTool<FOOTPRINT_EDITOR_TOOLS>();
|
2019-06-05 19:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
bool FP_TREE_SYNCHRONIZING_ADAPTER::IsContainer( const wxDataViewItem& aItem ) const
|
|
|
|
{
|
|
|
|
const LIB_TREE_NODE* node = ToNode( aItem );
|
2020-02-07 17:06:24 +00:00
|
|
|
return node ? node->m_Type == LIB_TREE_NODE::LIB : true;
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define PROGRESS_INTERVAL_MILLIS 66
|
|
|
|
|
|
|
|
void FP_TREE_SYNCHRONIZING_ADAPTER::Sync()
|
|
|
|
{
|
|
|
|
// 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(); )
|
2018-07-29 15:33:58 +00:00
|
|
|
{
|
2020-02-07 17:06:24 +00:00
|
|
|
const wxString& name = it->get()->m_Name;
|
2018-07-29 15:33:58 +00:00
|
|
|
|
|
|
|
if( !m_libs->HasLibrary( name, true ) )
|
|
|
|
{
|
|
|
|
it = deleteLibrary( it );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for new libraries
|
2018-08-05 11:56:02 +00:00
|
|
|
size_t count = m_libMap.size();
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
for( const auto& libName : m_libs->GetLogicalLibs() )
|
|
|
|
{
|
|
|
|
if( m_libMap.count( libName ) == 0 )
|
|
|
|
{
|
|
|
|
const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName );
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
|
2018-07-29 15:33:58 +00:00
|
|
|
m_libMap.insert( libName );
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 11:56:02 +00:00
|
|
|
|
|
|
|
if( m_libMap.size() > count )
|
|
|
|
m_tree.AssignIntrinsicRanks();
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FP_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount() const
|
|
|
|
{
|
|
|
|
return GFootprintTable.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary( LIB_TREE_NODE_LIB& aLibNode )
|
|
|
|
{
|
2020-02-07 17:06:24 +00:00
|
|
|
std::vector<LIB_TREE_ITEM*> footprints = getFootprints( aLibNode.m_Name );
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
// remove the common part from the footprints list
|
2020-02-07 17:06:24 +00:00
|
|
|
for( auto nodeIt = aLibNode.m_Children.begin(); nodeIt != aLibNode.m_Children.end(); )
|
2018-07-29 15:33:58 +00:00
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
// Since the list is sorted we can use a binary search to speed up searches within
|
|
|
|
// libraries with lots of footprints.
|
2020-02-07 17:06:24 +00:00
|
|
|
FOOTPRINT_INFO_IMPL dummy( wxEmptyString, (*nodeIt)->m_Name );
|
2018-07-30 13:18:37 +00:00
|
|
|
auto footprintIt = std::lower_bound( footprints.begin(), footprints.end(), &dummy,
|
2018-08-03 21:09:48 +00:00
|
|
|
[]( LIB_TREE_ITEM* a, LIB_TREE_ITEM* b )
|
|
|
|
{
|
2019-06-24 12:00:21 +00:00
|
|
|
return StrNumCmp( a->GetName(), b->GetName(), false ) < 0;
|
2018-08-03 21:09:48 +00:00
|
|
|
} );
|
2018-07-30 13:18:37 +00:00
|
|
|
|
|
|
|
if( footprintIt != footprints.end() && dummy.GetName() == (*footprintIt)->GetName() )
|
2018-07-29 15:33:58 +00:00
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
// footprint exists both in the lib tree and the footprint info list; just
|
|
|
|
// update the node data
|
2018-07-29 15:33:58 +00:00
|
|
|
static_cast<LIB_TREE_NODE_LIB_ID*>( nodeIt->get() )->Update( *footprintIt );
|
|
|
|
footprints.erase( footprintIt );
|
|
|
|
++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 );
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
// now the footprint list contains only new aliases that need to be added to the tree
|
2018-07-29 15:33:58 +00:00
|
|
|
for( auto footprint : footprints )
|
2018-07-30 13:18:37 +00:00
|
|
|
aLibNode.AddItem( footprint );
|
2018-07-29 15:33:58 +00:00
|
|
|
|
|
|
|
aLibNode.AssignIntrinsicRanks();
|
2020-02-07 17:06:24 +00:00
|
|
|
m_libMap.insert( aLibNode.m_Name );
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LIB_TREE_NODE::PTR_VECTOR::iterator FP_TREE_SYNCHRONIZING_ADAPTER::deleteLibrary(
|
|
|
|
LIB_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt )
|
|
|
|
{
|
|
|
|
LIB_TREE_NODE* node = aLibNodeIt->get();
|
2020-02-07 17:06:24 +00:00
|
|
|
m_libMap.erase( node->m_Name );
|
|
|
|
auto it = m_tree.m_Children.erase( aLibNodeIt );
|
2018-07-29 15:33:58 +00:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FP_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol ) const
|
|
|
|
{
|
|
|
|
if( IsFrozen() )
|
|
|
|
{
|
|
|
|
aVariant = wxEmptyString;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto node = ToNode( aItem );
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case 0:
|
2020-02-07 17:06:24 +00:00
|
|
|
if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
|
2018-09-13 23:39:40 +00:00
|
|
|
{
|
2020-03-31 01:09:01 +00:00
|
|
|
node->m_Name = m_frame->GetLoadedFPID().GetLibItemName();
|
2018-09-13 23:39:40 +00:00
|
|
|
|
2019-06-24 12:00:21 +00:00
|
|
|
// mark modified part with an asterisk
|
2018-09-13 23:39:40 +00:00
|
|
|
if( m_frame->GetScreen()->IsModify() )
|
2020-03-31 01:09:01 +00:00
|
|
|
aVariant = node->m_Name + " *";
|
2018-09-13 23:39:40 +00:00
|
|
|
else
|
2020-03-31 01:09:01 +00:00
|
|
|
aVariant = node->m_Name;
|
2018-09-13 23:39:40 +00:00
|
|
|
}
|
2020-02-07 17:06:24 +00:00
|
|
|
else if( node->m_Pinned )
|
2020-02-16 09:21:36 +00:00
|
|
|
aVariant = GetPinningSymbol() + node->m_Name;
|
2018-07-29 15:33:58 +00:00
|
|
|
else
|
2020-02-07 17:06:24 +00:00
|
|
|
aVariant = node->m_Name;
|
2018-07-29 15:33:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2020-03-31 01:09:01 +00:00
|
|
|
if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
|
2020-11-08 21:29:04 +00:00
|
|
|
node->m_Desc = m_frame->GetBoard()->GetFirstFootprint()->GetDescription();
|
2020-03-31 01:09:01 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
aVariant = node->m_Desc;
|
2018-07-29 15:33:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: // column == -1 is used for default Compare function
|
2020-02-07 17:06:24 +00:00
|
|
|
aVariant = node->m_Name;
|
2018-07-29 15:33:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
|
|
|
|
wxDataViewItemAttr& aAttr ) const
|
|
|
|
{
|
|
|
|
if( IsFrozen() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// change attributes only for the name field
|
|
|
|
if( aCol != 0 )
|
|
|
|
return false;
|
|
|
|
|
2018-09-13 15:39:14 +00:00
|
|
|
// don't link to a board footprint, even if the FPIDs match
|
|
|
|
if( m_frame->IsCurrentFPFromBoard() )
|
|
|
|
return false;
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
auto node = ToNode( aItem );
|
|
|
|
wxCHECK( node, false );
|
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
switch( node->m_Type )
|
2018-07-29 15:33:58 +00:00
|
|
|
{
|
2019-06-24 12:00:21 +00:00
|
|
|
case LIB_TREE_NODE::LIB:
|
2020-02-07 17:06:24 +00:00
|
|
|
if( node->m_Name == m_frame->GetLoadedFPID().GetLibNickname() )
|
2019-06-24 12:00:21 +00:00
|
|
|
{
|
2018-08-25 15:12:08 +00:00
|
|
|
#ifdef __WXGTK__
|
2019-06-24 12:00:21 +00:00
|
|
|
// The native wxGTK+ impl ignores background colour, so set the text colour
|
|
|
|
// instead. Works reasonably well in dark themes, less well in light ones....
|
|
|
|
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
|
2018-07-29 15:33:58 +00:00
|
|
|
#else
|
2019-06-24 12:00:21 +00:00
|
|
|
aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
|
2019-07-18 12:54:52 +00:00
|
|
|
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
|
2018-08-25 15:12:08 +00:00
|
|
|
#endif
|
|
|
|
|
2019-06-24 12:00:21 +00:00
|
|
|
// mark modified libs with bold font
|
|
|
|
if( m_frame->GetScreen()->IsModify() && !m_frame->IsCurrentFPFromBoard() )
|
|
|
|
aAttr.SetBold( true );
|
|
|
|
}
|
|
|
|
break;
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2019-06-24 12:00:21 +00:00
|
|
|
case LIB_TREE_NODE::LIBID:
|
2020-02-07 17:06:24 +00:00
|
|
|
if( node->m_LibId == m_frame->GetLoadedFPID() )
|
2019-06-24 12:00:21 +00:00
|
|
|
{
|
2018-08-25 15:12:08 +00:00
|
|
|
#ifdef __WXGTK__
|
2019-06-24 12:00:21 +00:00
|
|
|
// The native wxGTK+ impl ignores background colour, so set the text colour
|
|
|
|
// instead. Works reasonably well in dark themes, less well in light ones....
|
|
|
|
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
|
2018-07-29 15:33:58 +00:00
|
|
|
#else
|
2019-06-24 12:00:21 +00:00
|
|
|
aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
|
2019-07-18 12:54:52 +00:00
|
|
|
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
|
2018-08-25 15:12:08 +00:00
|
|
|
#endif
|
|
|
|
|
2019-06-24 12:00:21 +00:00
|
|
|
// mark modified part with bold font
|
|
|
|
if( m_frame->GetScreen()->IsModify() && !m_frame->IsCurrentFPFromBoard() )
|
|
|
|
aAttr.SetBold( true );
|
|
|
|
}
|
|
|
|
break;
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2019-06-24 12:00:21 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|