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>
|
2018-09-13 23:39:40 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.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
|
|
|
|
|
|
|
LIB_TREE_MODEL_ADAPTER::PTR FP_TREE_SYNCHRONIZING_ADAPTER::Create( FOOTPRINT_EDIT_FRAME* aFrame,
|
|
|
|
FP_LIB_TABLE* aLibs )
|
|
|
|
{
|
|
|
|
return PTR( new FP_TREE_SYNCHRONIZING_ADAPTER( aFrame, aLibs ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FP_TREE_SYNCHRONIZING_ADAPTER::FP_TREE_SYNCHRONIZING_ADAPTER( FOOTPRINT_EDIT_FRAME* aFrame,
|
|
|
|
FP_LIB_TABLE* aLibs ) :
|
|
|
|
FP_TREE_MODEL_ADAPTER( aLibs ),
|
|
|
|
m_frame( aFrame )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-05 19:15:57 +00:00
|
|
|
TOOL_INTERACTIVE* FP_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool()
|
|
|
|
{
|
|
|
|
return m_frame->GetToolManager()->GetTool<MODULE_EDITOR_TOOLS>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
return node ? node->Type == LIB_TREE_NODE::LIB : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define PROGRESS_INTERVAL_MILLIS 66
|
|
|
|
|
|
|
|
void FP_TREE_SYNCHRONIZING_ADAPTER::Sync()
|
|
|
|
{
|
|
|
|
// Process already stored libraries
|
|
|
|
for( auto it = m_tree.Children.begin(); it != m_tree.Children.end(); )
|
|
|
|
{
|
|
|
|
const wxString& name = it->get()->Name;
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
std::vector<LIB_TREE_ITEM*> footprints = getFootprints( aLibNode.Name );
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
// remove the common part from the footprints list
|
2018-07-29 15:33:58 +00:00
|
|
|
for( auto nodeIt = aLibNode.Children.begin(); nodeIt != aLibNode.Children.end(); )
|
|
|
|
{
|
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.
|
2018-08-03 21:09:48 +00:00
|
|
|
FOOTPRINT_INFO_IMPL dummy( wxEmptyString, (*nodeIt)->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
|
|
|
|
nodeIt = aLibNode.Children.erase( nodeIt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
m_libMap.insert( aLibNode.Name );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LIB_TREE_NODE::PTR_VECTOR::iterator FP_TREE_SYNCHRONIZING_ADAPTER::deleteLibrary(
|
|
|
|
LIB_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt )
|
|
|
|
{
|
|
|
|
LIB_TREE_NODE* node = aLibNodeIt->get();
|
|
|
|
m_libMap.erase( node->Name );
|
|
|
|
auto it = m_tree.Children.erase( aLibNodeIt );
|
|
|
|
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:
|
2018-09-13 23:39:40 +00:00
|
|
|
if( node->LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
|
|
|
|
{
|
2019-05-31 00:15:57 +00:00
|
|
|
auto mod = m_frame->GetBoard()->GetFirstModule();
|
|
|
|
|
|
|
|
wxASSERT( mod );
|
|
|
|
|
|
|
|
wxString currentFPName = mod->GetFPID().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() )
|
|
|
|
aVariant = currentFPName + " *";
|
|
|
|
else
|
|
|
|
aVariant = currentFPName;
|
|
|
|
}
|
2018-07-29 15:33:58 +00:00
|
|
|
else
|
|
|
|
aVariant = node->Name;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2019-09-04 16:18:42 +00:00
|
|
|
aVariant = node->Desc;
|
2018-07-29 15:33:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: // column == -1 is used for default Compare function
|
|
|
|
aVariant = node->Name;
|
|
|
|
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 );
|
|
|
|
|
|
|
|
switch( node->Type )
|
|
|
|
{
|
2019-06-24 12:00:21 +00:00
|
|
|
case LIB_TREE_NODE::LIB:
|
|
|
|
if( node->Name == m_frame->GetLoadedFPID().GetLibNickname() )
|
|
|
|
{
|
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:
|
|
|
|
if( node->LibId == m_frame->GetLoadedFPID() )
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|