Browse Source
Push component tree down into common.
Push component tree down into common.
Precondition to reusing component tree for footprints.pull/13/head
35 changed files with 799 additions and 887 deletions
-
3common/CMakeLists.txt
-
30common/draw_frame.cpp
-
103common/lib_tree_model.cpp
-
71common/lib_tree_model.h
-
230common/lib_tree_model_adapter.cpp
-
133common/lib_tree_model_adapter.h
-
80common/widgets/lib_tree.cpp
-
31common/widgets/lib_tree.h
-
2cvpcb/cvpcb_mainframe.cpp
-
9eeschema/CMakeLists.txt
-
44eeschema/class_libentry.cpp
-
23eeschema/class_libentry.h
-
98eeschema/cmp_tree_model_adapter.cpp
-
136eeschema/dialogs/dialog_choose_component.cpp
-
68eeschema/dialogs/dialog_choose_component.h
-
2eeschema/dialogs/dialog_edit_component_in_schematic.cpp
-
28eeschema/generate_alias_info.cpp
-
30eeschema/getpart.cpp
-
75eeschema/lib_edit_frame.cpp
-
19eeschema/lib_edit_frame.h
-
2eeschema/lib_manager.cpp
-
8eeschema/lib_manager.h
-
24eeschema/libedit.cpp
-
8eeschema/libedit_undo_redo.cpp
-
6eeschema/libfield.cpp
-
18eeschema/sch_base_frame.h
-
117eeschema/symbol_tree_model_adapter.cpp
-
60eeschema/symbol_tree_model_adapter.h
-
69eeschema/symbol_tree_synchronizing_adapter.cpp
-
35eeschema/symbol_tree_synchronizing_adapter.h
-
12eeschema/viewlibs.cpp
-
24eeschema/widgets/symbol_tree_pane.cpp
-
12eeschema/widgets/symbol_tree_pane.h
-
10include/draw_frame.h
-
66include/lib_tree_item.h
@ -1,98 +0,0 @@ |
|||
/*
|
|||
* 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> |
|||
* Copyright (C) 2014-2017 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 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 <cmp_tree_model_adapter.h>
|
|||
|
|||
#include <eda_pattern_match.h>
|
|||
#include <wx/tokenzr.h>
|
|||
#include <symbol_lib_table.h>
|
|||
#include <wx/progdlg.h>
|
|||
|
|||
CMP_TREE_MODEL_ADAPTER_BASE::PTR CMP_TREE_MODEL_ADAPTER::Create( SYMBOL_LIB_TABLE* aLibs ) |
|||
{ |
|||
auto adapter = new CMP_TREE_MODEL_ADAPTER( aLibs ); |
|||
auto container = CMP_TREE_MODEL_ADAPTER::PTR( adapter ); |
|||
return container; |
|||
} |
|||
|
|||
|
|||
CMP_TREE_MODEL_ADAPTER::CMP_TREE_MODEL_ADAPTER( SYMBOL_LIB_TABLE* aLibs ) |
|||
: m_libs( aLibs ) |
|||
{} |
|||
|
|||
|
|||
CMP_TREE_MODEL_ADAPTER::~CMP_TREE_MODEL_ADAPTER() |
|||
{} |
|||
|
|||
|
|||
void CMP_TREE_MODEL_ADAPTER::AddLibrary( wxString const& aLibNickname ) |
|||
{ |
|||
bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER ); |
|||
|
|||
std::vector<LIB_ALIAS*> alias_list; |
|||
|
|||
try |
|||
{ |
|||
m_libs->LoadSymbolLib( alias_list, aLibNickname, onlyPowerSymbols ); |
|||
} |
|||
catch( const IO_ERROR& ioe ) |
|||
{ |
|||
wxLogError( wxString::Format( _( "Error occurred loading symbol library %s." |
|||
"\n\n%s" ), aLibNickname, ioe.What() ) ); |
|||
return; |
|||
} |
|||
|
|||
if( alias_list.size() > 0 ) |
|||
{ |
|||
AddAliasList( aLibNickname, m_libs->GetDescription( aLibNickname ), alias_list ); |
|||
m_tree.AssignIntrinsicRanks(); |
|||
} |
|||
} |
|||
|
|||
|
|||
void CMP_TREE_MODEL_ADAPTER::AddAliasList( |
|||
wxString const& aNodeName, |
|||
wxArrayString const& aAliasNameList ) |
|||
{ |
|||
std::vector<LIB_ALIAS*> alias_list; |
|||
|
|||
for( const wxString& name: aAliasNameList ) |
|||
{ |
|||
LIB_ALIAS* a = nullptr; |
|||
|
|||
try |
|||
{ |
|||
a = m_libs->LoadSymbol( aNodeName, name ); |
|||
} |
|||
catch( const IO_ERROR& ioe ) |
|||
{ |
|||
wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s." |
|||
"\n\n%s" ), name, aNodeName, ioe.What() ) ); |
|||
continue; |
|||
} |
|||
|
|||
if( a ) |
|||
alias_list.push_back( a ); |
|||
} |
|||
|
|||
if( alias_list.size() > 0 ) |
|||
AddAliasList( aNodeName, m_libs->GetDescription( aNodeName ), alias_list ); |
|||
} |
|||
@ -0,0 +1,117 @@ |
|||
/*
|
|||
* 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> |
|||
* Copyright (C) 2014-2017 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 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>
|
|||
#include <wx/progdlg.h>
|
|||
|
|||
#include <eda_pattern_match.h>
|
|||
#include <symbol_lib_table.h>
|
|||
#include <class_libentry.h>
|
|||
#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
|
|||
|
|||
|
|||
SYMBOL_TREE_MODEL_ADAPTER::PTR SYMBOL_TREE_MODEL_ADAPTER::Create( LIB_TABLE* aLibs ) |
|||
{ |
|||
return PTR( new SYMBOL_TREE_MODEL_ADAPTER( aLibs ) ); |
|||
} |
|||
|
|||
|
|||
SYMBOL_TREE_MODEL_ADAPTER::SYMBOL_TREE_MODEL_ADAPTER( LIB_TABLE* aLibs ) |
|||
: m_libs( (SYMBOL_LIB_TABLE*) aLibs ) |
|||
{} |
|||
|
|||
|
|||
SYMBOL_TREE_MODEL_ADAPTER::~SYMBOL_TREE_MODEL_ADAPTER() |
|||
{} |
|||
|
|||
|
|||
void SYMBOL_TREE_MODEL_ADAPTER::AddLibraries( const std::vector<wxString>& aNicknames, |
|||
wxWindow* aParent ) |
|||
{ |
|||
wxProgressDialog* prg = nullptr; |
|||
wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2); |
|||
|
|||
if( m_show_progress ) |
|||
{ |
|||
prg = new wxProgressDialog( _( "Loading Symbol Libraries" ), wxEmptyString, |
|||
aNicknames.size(), aParent ); |
|||
} |
|||
|
|||
unsigned int ii = 0; |
|||
|
|||
for( const auto& nickname : aNicknames ) |
|||
{ |
|||
if( prg && wxGetUTCTimeMillis() > nextUpdate ) |
|||
{ |
|||
prg->Update( ii, wxString::Format( _( "Loading library \"%s\"" ), nickname ) ); |
|||
nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS; |
|||
} |
|||
|
|||
AddLibrary( nickname ); |
|||
ii++; |
|||
} |
|||
|
|||
if( prg ) |
|||
{ |
|||
prg->Destroy(); |
|||
m_show_progress = false; |
|||
} |
|||
} |
|||
|
|||
|
|||
void SYMBOL_TREE_MODEL_ADAPTER::AddLibrary( wxString const& aLibNickname ) |
|||
{ |
|||
bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER ); |
|||
std::vector<LIB_ALIAS*> alias_list; |
|||
std::vector<LIB_TREE_ITEM*> comp_list; |
|||
|
|||
try |
|||
{ |
|||
m_libs->LoadSymbolLib( alias_list, aLibNickname, onlyPowerSymbols ); |
|||
} |
|||
catch( const IO_ERROR& ioe ) |
|||
{ |
|||
wxLogError( wxString::Format( _( "Error loading symbol library %s.\n\n%s" ), |
|||
aLibNickname, |
|||
ioe.What() ) ); |
|||
return; |
|||
} |
|||
|
|||
if( alias_list.size() > 0 ) |
|||
{ |
|||
comp_list.assign( alias_list.begin(), alias_list.end() ); |
|||
DoAddLibrary( aLibNickname, m_libs->GetDescription( aLibNickname ), comp_list ); |
|||
m_tree.AssignIntrinsicRanks(); |
|||
} |
|||
} |
|||
|
|||
|
|||
wxString SYMBOL_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit ) |
|||
{ |
|||
return GenerateAliasInfo( m_libs, aLibId, aUnit ); |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2018 KiCad Developers, see change_log.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 |
|||
*/ |
|||
|
|||
|
|||
#ifndef LIB_TREE_ITEM_H |
|||
#define LIB_TREE_ITEM_H |
|||
|
|||
#include <base_struct.h> |
|||
#include <lib_id.h> |
|||
|
|||
|
|||
/** |
|||
* A mix-in to provide polymorphism between items stored in libraries (symbols, aliases |
|||
* and footprints). |
|||
* |
|||
* It is used primarily to drive the component tree for library browsing and editing. |
|||
*/ |
|||
|
|||
class LIB_TREE_ITEM |
|||
{ |
|||
public: |
|||
/** |
|||
* For items having aliases, IsRoot() indicates the principal item. |
|||
*/ |
|||
virtual bool IsRoot() const { return true; } |
|||
|
|||
virtual LIB_ID GetLibId() const = 0; |
|||
|
|||
virtual const wxString& GetName() const = 0; |
|||
|
|||
virtual wxString GetDescription() { return wxEmptyString; } |
|||
|
|||
virtual wxString GetSearchText() { return wxEmptyString; } |
|||
|
|||
/** |
|||
* For items with units, return the number of units. |
|||
*/ |
|||
virtual int GetUnitCount() { return 0; } |
|||
|
|||
/** |
|||
* For items with units, return an identifier for unit x. |
|||
*/ |
|||
virtual wxString GetUnitReference( int aUnit ) { return wxEmptyString; } |
|||
}; |
|||
|
|||
#endif //LIB_TREE_ITEM_H |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue