2018-07-27 20:47:51 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
2019-11-06 19:15:42 +00:00
|
|
|
* Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-07-27 20:47:51 +00:00
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/tokenzr.h>
|
2020-08-09 10:55:00 +00:00
|
|
|
#include <wx/window.h>
|
|
|
|
#include <widgets/app_progress_dialog.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
|
|
|
|
#include <eda_pattern_match.h>
|
|
|
|
#include <symbol_lib_table.h>
|
2021-01-27 23:06:43 +00:00
|
|
|
#include <lib_part.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <generate_alias_info.h>
|
|
|
|
#include <symbol_tree_model_adapter.h>
|
|
|
|
|
|
|
|
|
|
|
|
bool SYMBOL_TREE_MODEL_ADAPTER::m_show_progress = true;
|
|
|
|
|
|
|
|
#define PROGRESS_INTERVAL_MILLIS 66
|
|
|
|
|
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
|
|
|
|
SYMBOL_TREE_MODEL_ADAPTER::Create( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs )
|
2018-07-27 20:47:51 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
auto* adapter = new SYMBOL_TREE_MODEL_ADAPTER( aParent, aLibs );
|
|
|
|
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
|
2018-07-27 20:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-14 14:22:21 +00:00
|
|
|
SYMBOL_TREE_MODEL_ADAPTER::SYMBOL_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs ) :
|
2020-05-31 21:42:04 +00:00
|
|
|
LIB_TREE_MODEL_ADAPTER( aParent, "pinned_symbol_libs" ),
|
2020-02-14 14:22:21 +00:00
|
|
|
m_libs( (SYMBOL_LIB_TABLE*) aLibs )
|
2018-07-27 20:47:51 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
SYMBOL_TREE_MODEL_ADAPTER::~SYMBOL_TREE_MODEL_ADAPTER()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_TREE_MODEL_ADAPTER::AddLibraries( const std::vector<wxString>& aNicknames,
|
|
|
|
wxWindow* aParent )
|
|
|
|
{
|
2020-08-09 10:55:00 +00:00
|
|
|
APP_PROGRESS_DIALOG* prg = nullptr;
|
2018-07-27 20:47:51 +00:00
|
|
|
wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
|
|
|
|
|
|
|
|
if( m_show_progress )
|
|
|
|
{
|
2020-08-09 10:55:00 +00:00
|
|
|
prg = new APP_PROGRESS_DIALOG( _( "Loading Symbol Libraries" ), wxEmptyString,
|
|
|
|
aNicknames.size(), aParent );
|
2018-07-27 20:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int ii = 0;
|
|
|
|
|
|
|
|
for( const auto& nickname : aNicknames )
|
|
|
|
{
|
|
|
|
if( prg && wxGetUTCTimeMillis() > nextUpdate )
|
|
|
|
{
|
|
|
|
prg->Update( ii, wxString::Format( _( "Loading library \"%s\"" ), nickname ) );
|
2020-08-09 10:55:00 +00:00
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddLibrary( nickname );
|
|
|
|
ii++;
|
|
|
|
}
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
m_tree.AssignIntrinsicRanks();
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
if( prg )
|
|
|
|
{
|
2021-01-01 16:08:17 +00:00
|
|
|
// Force immediate deletion of the APP_PROGRESS_DIALOG
|
|
|
|
// ( do not use Destroy(), or use Destroy() followed by wxSafeYield() )
|
2021-01-01 12:08:42 +00:00
|
|
|
// because on Windows, APP_PROGRESS_DIALOG has some side effects on the event loop
|
|
|
|
// manager. A side effect is the call of ShowModal() of a dialog following
|
2021-01-01 16:08:17 +00:00
|
|
|
// the use of SYMBOL_TREE_MODEL_ADAPTER creating a APP_PROGRESS_DIALOG
|
2021-01-01 12:08:42 +00:00
|
|
|
// has a broken behavior (incorrect modal behavior).
|
|
|
|
delete prg;
|
2018-07-27 20:47:51 +00:00
|
|
|
m_show_progress = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_TREE_MODEL_ADAPTER::AddLibrary( wxString const& aLibNickname )
|
|
|
|
{
|
|
|
|
bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER );
|
2019-11-06 19:15:42 +00:00
|
|
|
std::vector<LIB_PART*> symbols;
|
2018-07-27 20:47:51 +00:00
|
|
|
std::vector<LIB_TREE_ITEM*> comp_list;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
m_libs->LoadSymbolLib( symbols, aLibNickname, onlyPowerSymbols );
|
2018-07-27 20:47:51 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( _( "Error loading symbol library %s.\n\n%s" ),
|
|
|
|
aLibNickname,
|
|
|
|
ioe.What() ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( symbols.size() > 0 )
|
2018-07-27 20:47:51 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
comp_list.assign( symbols.begin(), symbols.end() );
|
2018-08-05 11:56:02 +00:00
|
|
|
DoAddLibrary( aLibNickname, m_libs->GetDescription( aLibNickname ), comp_list, false );
|
2018-07-27 20:47:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SYMBOL_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
|
|
|
|
{
|
|
|
|
return GenerateAliasInfo( m_libs, aLibId, aUnit );
|
|
|
|
}
|