Push component tree down into common.

Precondition to reusing component tree for footprints.
This commit is contained in:
Jeff Young 2018-07-27 21:47:51 +01:00
parent 13b96799ea
commit 97f7bd4cb9
35 changed files with 801 additions and 889 deletions

View File

@ -185,6 +185,7 @@ set( COMMON_WIDGET_SRCS
widgets/grid_icon_text_helpers.cpp
widgets/grid_text_button_helpers.cpp
widgets/indicator_icon.cpp
widgets/lib_tree.cpp
widgets/mathplot.cpp
widgets/paged_dialog.cpp
widgets/progress_reporter.cpp
@ -290,6 +291,8 @@ set( COMMON_SRCS
lib_id.cpp
lib_table_base.cpp
lib_table_keywords.cpp
lib_tree_model.cpp
lib_tree_model_adapter.cpp
lockfile.cpp
marker_base.cpp
md5_hash.cpp

View File

@ -1375,9 +1375,7 @@ void EDA_DRAW_FRAME::SetScrollCenterPosition( const wxPoint& aPoint )
//-----</BASE_SCREEN API moved here >--------------------------------------------
void EDA_DRAW_FRAME::RefreshCrossHair( const wxPoint &aOldPos,
const wxPoint &aEvtPos,
wxDC* aDC )
void EDA_DRAW_FRAME::RefreshCrossHair( const wxPoint &aOldPos, const wxPoint &aEvtPos, wxDC* aDC )
{
wxPoint newpos = GetCrossHairPosition();
@ -1408,8 +1406,30 @@ void EDA_DRAW_FRAME::RefreshCrossHair( const wxPoint &aOldPos,
}
}
bool EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
bool aSnapToGrid )
bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
const wxString& wildcard, const wxString& ext )
{
aFilename.SetExt( ext );
wxFileDialog dlg( this,
doOpen ? _( "Select Library" ) : _( "New Library" ),
Prj().GetProjectPath(),
doOpen ? wxString( wxEmptyString ) : aFilename.GetFullName() ,
wildcard,
doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL )
return false;
aFilename = dlg.GetPath();
aFilename.SetExt( ext );
return true;
}
bool EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, bool aSnapToGrid )
{
bool key_handled = false;

View File

@ -19,10 +19,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cmp_tree_model.h>
#include <lib_tree_model.h>
#include <class_library.h>
#include <eda_pattern_match.h>
#include <lib_tree_item.h>
#include <make_unique.h>
#include <utility>
#include <pgm_base.h>
@ -50,7 +50,7 @@ static int matchPosScore(int aPosition, int aMaximum)
}
void CMP_TREE_NODE::ResetScore()
void LIB_TREE_NODE::ResetScore()
{
for( auto& child: Children )
child->ResetScore();
@ -59,15 +59,15 @@ void CMP_TREE_NODE::ResetScore()
}
void CMP_TREE_NODE::AssignIntrinsicRanks()
void LIB_TREE_NODE::AssignIntrinsicRanks()
{
std::vector<CMP_TREE_NODE*> sort_buf;
std::vector<LIB_TREE_NODE*> sort_buf;
for( auto const& node: Children )
sort_buf.push_back( &*node );
std::sort( sort_buf.begin(), sort_buf.end(),
[]( CMP_TREE_NODE* a, CMP_TREE_NODE* b ) -> bool
[]( LIB_TREE_NODE* a, LIB_TREE_NODE* b ) -> bool
{ return a->MatchName > b->MatchName; } );
for( int i = 0; i < (int) sort_buf.size(); ++i )
@ -75,10 +75,10 @@ void CMP_TREE_NODE::AssignIntrinsicRanks()
}
void CMP_TREE_NODE::SortNodes()
void LIB_TREE_NODE::SortNodes()
{
std::sort( Children.begin(), Children.end(),
[]( std::unique_ptr<CMP_TREE_NODE> const& a, std::unique_ptr<CMP_TREE_NODE> const& b )
[]( std::unique_ptr<LIB_TREE_NODE> const& a, std::unique_ptr<LIB_TREE_NODE> const& b )
{ return Compare( *a, *b ) > 0; } );
for( auto& node: Children )
@ -88,7 +88,7 @@ void CMP_TREE_NODE::SortNodes()
}
int CMP_TREE_NODE::Compare( CMP_TREE_NODE const& aNode1, CMP_TREE_NODE const& aNode2 )
int LIB_TREE_NODE::Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 )
{
if( aNode1.Type != aNode2.Type )
return 0;
@ -103,7 +103,7 @@ int CMP_TREE_NODE::Compare( CMP_TREE_NODE const& aNode1, CMP_TREE_NODE const& aN
}
CMP_TREE_NODE::CMP_TREE_NODE()
LIB_TREE_NODE::LIB_TREE_NODE()
: Parent( nullptr ),
Type( INVALID ),
IntrinsicRank( 0 ),
@ -114,7 +114,7 @@ CMP_TREE_NODE::CMP_TREE_NODE()
{}
CMP_TREE_NODE_UNIT::CMP_TREE_NODE_UNIT( CMP_TREE_NODE* aParent, int aUnit )
LIB_TREE_NODE_UNIT::LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit )
{
static void* locale = nullptr;
static wxString namePrefix;
@ -133,7 +133,7 @@ CMP_TREE_NODE_UNIT::CMP_TREE_NODE_UNIT( CMP_TREE_NODE* aParent, int aUnit )
Unit = aUnit;
LibId = aParent->LibId;
Name = namePrefix + " " + LIB_PART::SubReference( aUnit, false );
Name = namePrefix + " " + aItem->GetUnitReference( aUnit );
Desc = wxEmptyString;
MatchName = wxEmptyString;
@ -141,7 +141,7 @@ CMP_TREE_NODE_UNIT::CMP_TREE_NODE_UNIT( CMP_TREE_NODE* aParent, int aUnit )
}
CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* aAlias )
LIB_TREE_NODE_LIB_ID::LIB_TREE_NODE_LIB_ID( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aAlias )
{
wxASSERT( aParent && aAlias );
@ -151,61 +151,36 @@ CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* a
}
CMP_TREE_NODE_UNIT& CMP_TREE_NODE_LIB_ID::AddUnit( int aUnit )
LIB_TREE_NODE_UNIT& LIB_TREE_NODE_LIB_ID::AddUnit( LIB_TREE_ITEM* aItem, int aUnit )
{
CMP_TREE_NODE_UNIT* unit = new CMP_TREE_NODE_UNIT( this, aUnit );
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( unit ) );
LIB_TREE_NODE_UNIT* unit = new LIB_TREE_NODE_UNIT( this, aItem, aUnit );
Children.push_back( std::unique_ptr<LIB_TREE_NODE>( unit ) );
return *unit;
}
void CMP_TREE_NODE_LIB_ID::Update( LIB_ALIAS* aAlias )
void LIB_TREE_NODE_LIB_ID::Update( LIB_TREE_ITEM* aItem )
{
Name = aAlias->GetName();
Desc = aAlias->GetDescription();
IsRoot = aItem->IsRoot();
LibId = aItem->GetLibId();
// Parent node is the library nickname so set the LIB_ID library nickname.
IsRoot = aAlias->IsRoot();
Name = aItem->GetName();
Desc = aItem->GetDescription();
// Pre-normalized strings for fast case-insensitive matching
// Search text spaces out keywords and description to penalize description
// matches - earlier matches are worth more.
MatchName = aAlias->GetName().Lower();
SearchText = (aAlias->GetKeyWords() + " " + Desc);
// Extract default footprint text
LIB_PART* part = aAlias->GetPart();
wxString footprint;
if( part )
{
LibId = part->GetLibId();
LibId.SetLibItemName( Name );
footprint = part->GetFootprintField().GetText();
}
// If a footprint is defined for the part,
// add it to the serach string
if( !footprint.IsEmpty() )
{
SearchText += " ";
SearchText += footprint;
}
MatchName = aItem->GetName().Lower();
SearchText = aItem->GetSearchText();
SearchTextNormalized = false;
Children.clear();
if( part && part->IsMulti() )
{
for( int u = 1; u <= part->GetUnitCount(); ++u )
AddUnit( u );
}
int unitCount = aItem->GetUnitCount();
SearchTextNormalized = false;
for( int u = 1; u <= unitCount; ++u )
AddUnit( aItem, u );
}
void CMP_TREE_NODE_LIB_ID::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
void LIB_TREE_NODE_LIB_ID::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
{
if( Score <= 0 )
return; // Leaf nodes without scores are out of the game.
@ -259,8 +234,8 @@ void CMP_TREE_NODE_LIB_ID::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
}
CMP_TREE_NODE_LIB::CMP_TREE_NODE_LIB( CMP_TREE_NODE* aParent,
wxString const& aName, wxString const& aDesc )
LIB_TREE_NODE_LIB::LIB_TREE_NODE_LIB( LIB_TREE_NODE* aParent, wxString const& aName,
wxString const& aDesc )
{
Type = LIB;
Name = aName;
@ -271,15 +246,15 @@ CMP_TREE_NODE_LIB::CMP_TREE_NODE_LIB( CMP_TREE_NODE* aParent,
}
CMP_TREE_NODE_LIB_ID& CMP_TREE_NODE_LIB::AddAlias( LIB_ALIAS* aAlias )
LIB_TREE_NODE_LIB_ID& LIB_TREE_NODE_LIB::AddComp( LIB_TREE_ITEM* aAlias )
{
CMP_TREE_NODE_LIB_ID* alias = new CMP_TREE_NODE_LIB_ID( this, aAlias );
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( alias ) );
LIB_TREE_NODE_LIB_ID* alias = new LIB_TREE_NODE_LIB_ID( this, aAlias );
Children.push_back( std::unique_ptr<LIB_TREE_NODE>( alias ) );
return *alias;
}
void CMP_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
void LIB_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
{
Score = 0;
@ -291,21 +266,21 @@ void CMP_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
}
CMP_TREE_NODE_ROOT::CMP_TREE_NODE_ROOT()
LIB_TREE_NODE_ROOT::LIB_TREE_NODE_ROOT()
{
Type = ROOT;
}
CMP_TREE_NODE_LIB& CMP_TREE_NODE_ROOT::AddLib( wxString const& aName, wxString const& aDesc )
LIB_TREE_NODE_LIB& LIB_TREE_NODE_ROOT::AddLib( wxString const& aName, wxString const& aDesc )
{
CMP_TREE_NODE_LIB* lib = new CMP_TREE_NODE_LIB( this, aName, aDesc );
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( lib ) );
LIB_TREE_NODE_LIB* lib = new LIB_TREE_NODE_LIB( this, aName, aDesc );
Children.push_back( std::unique_ptr<LIB_TREE_NODE>( lib ) );
return *lib;
}
void CMP_TREE_NODE_ROOT::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
void LIB_TREE_NODE_ROOT::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
{
for( auto& child: Children )
child->UpdateScore( aMatcher );

View File

@ -3,7 +3,7 @@
*
* 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.
* Copyright (C) 2014-2018 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
@ -19,25 +19,23 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CMP_TREE_MODEL_H
#define _CMP_TREE_MODEL_H
#ifndef LIB_TREE_MODEL_H
#define LIB_TREE_MODEL_H
#include <vector>
#include <memory>
#include <wx/string.h>
#include <lib_id.h>
#include <lib_tree_item.h>
class EDA_COMBINED_MATCHER;
class TREE_NODE;
class LIB_ALIAS;
/**
* Model class in the component selector Model-View-Adapter (mediated MVC)
* architecture. The other pieces are in:
*
* - Adapter: CMP_TREE_MODEL_ADAPTER in eeschema/cmp_tree_model_adapter.h
* - Adapter: LIB_TREE_MODEL_ADAPTER in common/lib_tree_model_adapter.h
* - View:
* - DIALOG_CHOOSE_COMPONENT in eeschema/dialogs/dialog_choose_component.h
* - wxDataViewCtrl
@ -74,15 +72,15 @@ class LIB_ALIAS;
* - `LibId` - the #LIB_ID this alias or unit is from, or not valid
* - `Unit` - the unit number, or zero for non-units
*/
class CMP_TREE_NODE {
class LIB_TREE_NODE {
public:
enum TYPE {
ROOT, LIB, LIBID, UNIT, INVALID
};
typedef std::vector<std::unique_ptr<CMP_TREE_NODE>> PTR_VECTOR;
typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
CMP_TREE_NODE* Parent; ///< Parent node or null
LIB_TREE_NODE* Parent; ///< Parent node or null
PTR_VECTOR Children; ///< List of child nodes
enum TYPE Type; ///< Node type
@ -135,17 +133,17 @@ public:
* Compare two nodes. Returns negative if aNode1 < aNode2, zero if aNode1 ==
* aNode2, or positive if aNode1 > aNode2.
*/
static int Compare( CMP_TREE_NODE const& aNode1, CMP_TREE_NODE const& aNode2 );
static int Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 );
CMP_TREE_NODE();
virtual ~CMP_TREE_NODE() {}
LIB_TREE_NODE();
virtual ~LIB_TREE_NODE() {}
};
/**
* Node type: unit of component.
*/
class CMP_TREE_NODE_UNIT: public CMP_TREE_NODE
class LIB_TREE_NODE_UNIT: public LIB_TREE_NODE
{
public:
@ -153,8 +151,8 @@ public:
* The addresses of CMP_TREE_NODEs are used as unique IDs for the
* wxDataViewModel, so don't let them be copied around.
*/
CMP_TREE_NODE_UNIT( CMP_TREE_NODE_UNIT const& _ ) = delete;
void operator=( CMP_TREE_NODE_UNIT const& _ ) = delete;
LIB_TREE_NODE_UNIT( LIB_TREE_NODE_UNIT const& _ ) = delete;
void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
/**
@ -164,9 +162,10 @@ public:
* by LIB_PART::SubReference.
*
* @param aParent parent node, should be a CMP_TREE_NODE_ALIAS
* @param aItem parent item
* @param aUnit unit number
*/
CMP_TREE_NODE_UNIT( CMP_TREE_NODE* aParent, int aUnit );
LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
/**
@ -179,15 +178,15 @@ public:
/**
* Node type: #LIB_ID.
*/
class CMP_TREE_NODE_LIB_ID: public CMP_TREE_NODE
class LIB_TREE_NODE_LIB_ID: public LIB_TREE_NODE
{
public:
/**
* The addresses of CMP_TREE_NODEs are used as unique IDs for the
* wxDataViewModel, so don't let them be copied around.
*/
CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE_LIB_ID const& _ ) = delete;
void operator=( CMP_TREE_NODE_LIB_ID const& _ ) = delete;
LIB_TREE_NODE_LIB_ID( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
void operator=( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
/**
@ -200,14 +199,14 @@ public:
* The alias must be resolved at the time of use. Anything else is a bug.
*
* @param aParent parent node, should be a CMP_TREE_NODE_LIB
* @param aAlias LIB_ALIAS to populate the node.
* @param aItem LIB_COMPONENT to populate the node.
*/
CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* aAlias );
LIB_TREE_NODE_LIB_ID( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem );
/**
* Update the node using data from a LIB_ALIAS object.
*/
void Update( LIB_ALIAS* aAlias );
void Update( LIB_TREE_ITEM* aItem );
/**
* Perform the actual search.
@ -220,22 +219,22 @@ protected:
*
* This should not be used directly, as the constructor adds all units.
*/
CMP_TREE_NODE_UNIT& AddUnit( int aUnit );
LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
};
/**
* Node type: library
*/
class CMP_TREE_NODE_LIB: public CMP_TREE_NODE
class LIB_TREE_NODE_LIB: public LIB_TREE_NODE
{
public:
/**
* The addresses of CMP_TREE_NODEs are used as unique IDs for the
* wxDataViewModel, so don't let them be copied around.
*/
CMP_TREE_NODE_LIB( CMP_TREE_NODE_LIB const& _ ) = delete;
void operator=( CMP_TREE_NODE_LIB const& _ ) = delete;
LIB_TREE_NODE_LIB( LIB_TREE_NODE_LIB const& _ ) = delete;
void operator=( LIB_TREE_NODE_LIB const& _ ) = delete;
/**
@ -245,14 +244,14 @@ public:
* @param aName display name of the library
* @param aDesc a description of the library
*/
CMP_TREE_NODE_LIB( CMP_TREE_NODE* aParent, wxString const& aName, wxString const& aDesc );
LIB_TREE_NODE_LIB( LIB_TREE_NODE* aParent, wxString const& aName, wxString const& aDesc );
/**
* Construct a new alias node, add it to this library, and return it.
*
* @param aAlias LIB_ALIAS to provide data
* @param aAlias LIB_COMPONENT to provide data
*/
CMP_TREE_NODE_LIB_ID& AddAlias( LIB_ALIAS* aAlias );
LIB_TREE_NODE_LIB_ID& AddComp( LIB_TREE_ITEM* aAlias );
virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
};
@ -261,28 +260,28 @@ public:
/**
* Node type: root
*/
class CMP_TREE_NODE_ROOT: public CMP_TREE_NODE
class LIB_TREE_NODE_ROOT: public LIB_TREE_NODE
{
public:
/**
* The addresses of CMP_TREE_NODEs are used as unique IDs for the
* wxDataViewModel, so don't let them be copied around.
*/
CMP_TREE_NODE_ROOT( CMP_TREE_NODE_ROOT const& _ ) = delete;
void operator=( CMP_TREE_NODE_ROOT const& _ ) = delete;
LIB_TREE_NODE_ROOT( LIB_TREE_NODE_ROOT const& _ ) = delete;
void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
/**
* Construct the root node. Root nodes have no properties.
*/
CMP_TREE_NODE_ROOT();
LIB_TREE_NODE_ROOT();
/**
* Construct an empty library node, add it to the root, and return it.
*/
CMP_TREE_NODE_LIB& AddLib( wxString const& aName, wxString const& aDesc );
LIB_TREE_NODE_LIB& AddLib( wxString const& aName, wxString const& aDesc );
virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
};
#endif // _CMP_TREE_MODEL_H
#endif // LIB_TREE_MODEL_H

View File

@ -19,7 +19,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cmp_tree_model_adapter_base.h>
#include <lib_tree_model_adapter.h>
#include <eda_pattern_match.h>
@ -28,11 +28,7 @@
#include <wx/wupdlock.h>
CMP_TREE_MODEL_ADAPTER_BASE::WIDTH_CACHE CMP_TREE_MODEL_ADAPTER_BASE::m_width_cache;
bool CMP_TREE_MODEL_ADAPTER_BASE::m_show_progress = true;
#define PROGRESS_INTERVAL_MILLIS 66
LIB_TREE_MODEL_ADAPTER::WIDTH_CACHE LIB_TREE_MODEL_ADAPTER::m_width_cache;
static const int kDataViewIndent = 20;
@ -40,7 +36,7 @@ static const int kDataViewIndent = 20;
/**
* Convert CMP_TREE_NODE -> wxDataViewItem
*/
wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::ToItem( CMP_TREE_NODE const* aNode )
wxDataViewItem LIB_TREE_MODEL_ADAPTER::ToItem( LIB_TREE_NODE const* aNode )
{
return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
}
@ -49,17 +45,17 @@ wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::ToItem( CMP_TREE_NODE const* aNode )
/**
* Convert wxDataViewItem -> CMP_TREE_NODE
*/
CMP_TREE_NODE const* CMP_TREE_MODEL_ADAPTER_BASE::ToNode( wxDataViewItem aItem )
LIB_TREE_NODE const* LIB_TREE_MODEL_ADAPTER::ToNode( wxDataViewItem aItem )
{
return static_cast<CMP_TREE_NODE const*>( aItem.GetID() );
return static_cast<LIB_TREE_NODE const*>( aItem.GetID() );
}
/**
* Convert CMP_TREE_NODE's children to wxDataViewItemArray
*/
unsigned int CMP_TREE_MODEL_ADAPTER_BASE::IntoArray(
CMP_TREE_NODE const& aNode, wxDataViewItemArray& aChildren )
unsigned int LIB_TREE_MODEL_ADAPTER::IntoArray( LIB_TREE_NODE const& aNode,
wxDataViewItemArray& aChildren )
{
unsigned int n = 0;
@ -76,7 +72,7 @@ unsigned int CMP_TREE_MODEL_ADAPTER_BASE::IntoArray(
}
CMP_TREE_MODEL_ADAPTER_BASE::CMP_TREE_MODEL_ADAPTER_BASE()
LIB_TREE_MODEL_ADAPTER::LIB_TREE_MODEL_ADAPTER()
:m_filter( CMP_FILTER_NONE ),
m_show_units( true ),
m_preselect_unit( 0 ),
@ -87,79 +83,43 @@ CMP_TREE_MODEL_ADAPTER_BASE::CMP_TREE_MODEL_ADAPTER_BASE()
{}
CMP_TREE_MODEL_ADAPTER_BASE::~CMP_TREE_MODEL_ADAPTER_BASE()
LIB_TREE_MODEL_ADAPTER::~LIB_TREE_MODEL_ADAPTER()
{}
void CMP_TREE_MODEL_ADAPTER_BASE::SetFilter( CMP_FILTER_TYPE aFilter )
void LIB_TREE_MODEL_ADAPTER::SetFilter( CMP_FILTER_TYPE aFilter )
{
m_filter = aFilter;
}
void CMP_TREE_MODEL_ADAPTER_BASE::ShowUnits( bool aShow )
void LIB_TREE_MODEL_ADAPTER::ShowUnits( bool aShow )
{
m_show_units = aShow;
}
void CMP_TREE_MODEL_ADAPTER_BASE::SetPreselectNode( LIB_ID const& aLibId, int aUnit )
void LIB_TREE_MODEL_ADAPTER::SetPreselectNode( LIB_ID const& aLibId, int aUnit )
{
m_preselect_lib_id = aLibId;
m_preselect_unit = aUnit;
}
void CMP_TREE_MODEL_ADAPTER_BASE::AddLibrariesWithProgress(
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 CMP_TREE_MODEL_ADAPTER_BASE::AddAliasList( wxString const& aNodeName, wxString const& aDesc,
std::vector<LIB_ALIAS*> const& aAliasList )
void LIB_TREE_MODEL_ADAPTER::DoAddLibrary( wxString const& aNodeName, wxString const& aDesc,
std::vector<LIB_TREE_ITEM*> const& aCompList )
{
auto& lib_node = m_tree.AddLib( aNodeName, aDesc );
for( auto a: aAliasList )
{
lib_node.AddAlias( a );
}
for( auto a: aCompList )
lib_node.AddComp( a );
lib_node.AssignIntrinsicRanks();
m_tree.AssignIntrinsicRanks();
}
void CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString( wxString const& aSearch )
void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch )
{
m_tree.ResetScore();
@ -193,7 +153,7 @@ void CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString( wxString const& aSearch )
#endif
}
CMP_TREE_NODE* bestMatch = ShowResults();
LIB_TREE_NODE* bestMatch = ShowResults();
if( !bestMatch )
bestMatch = ShowPreselect();
@ -210,7 +170,7 @@ void CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString( wxString const& aSearch )
}
void CMP_TREE_MODEL_ADAPTER_BASE::AttachTo( wxDataViewCtrl* aDataViewCtrl )
void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
{
m_widget = aDataViewCtrl;
aDataViewCtrl->SetIndent( kDataViewIndent );
@ -227,7 +187,7 @@ void CMP_TREE_MODEL_ADAPTER_BASE::AttachTo( wxDataViewCtrl* aDataViewCtrl )
}
LIB_ID CMP_TREE_MODEL_ADAPTER_BASE::GetAliasFor( const wxDataViewItem& aSelection ) const
LIB_ID LIB_TREE_MODEL_ADAPTER::GetAliasFor( const wxDataViewItem& aSelection ) const
{
auto node = ToNode( aSelection );
@ -240,38 +200,32 @@ LIB_ID CMP_TREE_MODEL_ADAPTER_BASE::GetAliasFor( const wxDataViewItem& aSelectio
}
int CMP_TREE_MODEL_ADAPTER_BASE::GetUnitFor( const wxDataViewItem& aSelection ) const
int LIB_TREE_MODEL_ADAPTER::GetUnitFor( const wxDataViewItem& aSelection ) const
{
auto node = ToNode( aSelection );
return node ? node->Unit : 0;
}
CMP_TREE_NODE::TYPE CMP_TREE_MODEL_ADAPTER_BASE::GetTypeFor( const wxDataViewItem& aSelection ) const
LIB_TREE_NODE::TYPE LIB_TREE_MODEL_ADAPTER::GetTypeFor( const wxDataViewItem& aSelection ) const
{
auto node = ToNode( aSelection );
return node ? node->Type : CMP_TREE_NODE::INVALID;
return node ? node->Type : LIB_TREE_NODE::INVALID;
}
int CMP_TREE_MODEL_ADAPTER_BASE::GetComponentsCount() const
int LIB_TREE_MODEL_ADAPTER::GetItemCount() const
{
int n = 0;
for( auto& lib: m_tree.Children )
{
for( auto& alias: lib->Children )
{
(void) alias;
++n;
}
}
n += lib->Children.size();
return n;
}
wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::FindItem( const LIB_ID& aLibId )
wxDataViewItem LIB_TREE_MODEL_ADAPTER::FindItem( const LIB_ID& aLibId )
{
for( auto& lib: m_tree.Children )
{
@ -295,53 +249,47 @@ wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::FindItem( const LIB_ID& aLibId )
}
unsigned int CMP_TREE_MODEL_ADAPTER_BASE::GetChildren(
wxDataViewItem const& aItem,
unsigned int LIB_TREE_MODEL_ADAPTER::GetChildren( wxDataViewItem const& aItem,
wxDataViewItemArray& aChildren ) const
{
auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
if( node->Type != CMP_TREE_NODE::TYPE::LIBID
|| ( m_show_units && node->Type == CMP_TREE_NODE::TYPE::LIBID ) )
if( node->Type != LIB_TREE_NODE::TYPE::LIBID
|| ( m_show_units && node->Type == LIB_TREE_NODE::TYPE::LIBID ) )
return IntoArray( *node, aChildren );
else
return 0;
}
bool CMP_TREE_MODEL_ADAPTER_BASE::HasContainerColumns( wxDataViewItem const& aItem ) const
bool LIB_TREE_MODEL_ADAPTER::HasContainerColumns( wxDataViewItem const& aItem ) const
{
return IsContainer( aItem );
}
bool CMP_TREE_MODEL_ADAPTER_BASE::IsContainer( wxDataViewItem const& aItem ) const
bool LIB_TREE_MODEL_ADAPTER::IsContainer( wxDataViewItem const& aItem ) const
{
auto node = ToNode( aItem );
return node ? node->Children.size() : true;
}
wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::GetParent( wxDataViewItem const& aItem ) const
wxDataViewItem LIB_TREE_MODEL_ADAPTER::GetParent( wxDataViewItem const& aItem ) const
{
auto node = ToNode( aItem );
auto parent = node ? node->Parent : nullptr;
// wxDataViewModel has no root node, but rather top-level elements have
// an invalid (null) parent.
if( !node || !parent || parent->Type == CMP_TREE_NODE::TYPE::ROOT )
{
if( !node || !parent || parent->Type == LIB_TREE_NODE::TYPE::ROOT )
return ToItem( nullptr );
}
else
{
return ToItem( parent );
}
}
void CMP_TREE_MODEL_ADAPTER_BASE::GetValue(
wxVariant& aVariant,
void LIB_TREE_MODEL_ADAPTER::GetValue( wxVariant& aVariant,
wxDataViewItem const& aItem,
unsigned int aCol ) const
{
@ -367,8 +315,7 @@ void CMP_TREE_MODEL_ADAPTER_BASE::GetValue(
}
bool CMP_TREE_MODEL_ADAPTER_BASE::GetAttr(
wxDataViewItem const& aItem,
bool LIB_TREE_MODEL_ADAPTER::GetAttr( wxDataViewItem const& aItem,
unsigned int aCol,
wxDataViewItemAttr& aAttr ) const
{
@ -378,7 +325,7 @@ bool CMP_TREE_MODEL_ADAPTER_BASE::GetAttr(
auto node = ToNode( aItem );
wxASSERT( node );
if( node->Type != CMP_TREE_NODE::LIBID )
if( node->Type != LIB_TREE_NODE::LIBID )
{
// Currently only aliases are formatted at all
return false;
@ -397,67 +344,20 @@ bool CMP_TREE_MODEL_ADAPTER_BASE::GetAttr(
}
int CMP_TREE_MODEL_ADAPTER_BASE::ColWidth( CMP_TREE_NODE& aTree, int aCol, wxString const& aHeading )
int LIB_TREE_MODEL_ADAPTER::ColWidth( LIB_TREE_NODE& aTree, int aCol, wxString const& aHeading )
{
const int indent = aCol ? 0 : kDataViewIndent;
int min_width = WidthFor( aHeading, aCol );
int width = std::max( aTree.Score > 0 ? WidthFor( aTree, aCol ) : 0, min_width );
if( aTree.Score > 0 )
{
for( auto& node: aTree.Children )
{
width = std::max( width, ColWidth( *node, aCol, aHeading ) + indent );
}
}
return width;
}
int CMP_TREE_MODEL_ADAPTER_BASE::WidthFor( CMP_TREE_NODE& aNode, int aCol )
{
auto result = m_width_cache.find( aNode.Name );
if( result != m_width_cache.end() )
{
return result->second[aCol];
}
// It's too expensive to calculate widths on really big trees, and the user probably
// wants it left where they dragged it anyway.
if( aCol == 0 )
return 360;
else
{
int wname = m_widget->GetTextExtent( aNode.Name ).x + kDataViewIndent;
int wdesc = m_widget->GetTextExtent( aNode.Desc ).x;
auto& val = m_width_cache[aNode.Name];
val.push_back( wname );
val.push_back( wdesc );
return val[aCol];
}
return 2000;
}
int CMP_TREE_MODEL_ADAPTER_BASE::WidthFor( wxString const& aHeading, int aCol )
{
static std::vector<int> widths;
for( int i = (int) widths.size(); i <= aCol; ++i )
{
widths.push_back( 0 );
}
if( widths[aCol] == 0 )
{
widths[aCol] = m_widget->GetTextExtent( aHeading ).x;
}
return widths[aCol];
}
void CMP_TREE_MODEL_ADAPTER_BASE::FindAndExpand( CMP_TREE_NODE& aNode,
std::function<bool( CMP_TREE_NODE const* )> aFunc,
CMP_TREE_NODE** aHighScore )
void LIB_TREE_MODEL_ADAPTER::FindAndExpand( LIB_TREE_NODE& aNode,
std::function<bool( LIB_TREE_NODE const* )> aFunc,
LIB_TREE_NODE** aHighScore )
{
for( auto& node: aNode.Children )
{
@ -477,14 +377,14 @@ void CMP_TREE_MODEL_ADAPTER_BASE::FindAndExpand( CMP_TREE_NODE& aNode,
}
CMP_TREE_NODE* CMP_TREE_MODEL_ADAPTER_BASE::ShowResults()
LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowResults()
{
CMP_TREE_NODE* highScore = nullptr;
LIB_TREE_NODE* highScore = nullptr;
FindAndExpand( m_tree,
[]( CMP_TREE_NODE const* n )
[]( LIB_TREE_NODE const* n )
{
return n->Type == CMP_TREE_NODE::TYPE::LIBID && n->Score > 1;
return n->Type == LIB_TREE_NODE::TYPE::LIBID && n->Score > 1;
},
&highScore );
@ -492,19 +392,19 @@ CMP_TREE_NODE* CMP_TREE_MODEL_ADAPTER_BASE::ShowResults()
}
CMP_TREE_NODE* CMP_TREE_MODEL_ADAPTER_BASE::ShowPreselect()
LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowPreselect()
{
CMP_TREE_NODE* highScore = nullptr;
LIB_TREE_NODE* highScore = nullptr;
if( !m_preselect_lib_id.IsValid() )
return highScore;
FindAndExpand( m_tree,
[&]( CMP_TREE_NODE const* n )
[&]( LIB_TREE_NODE const* n )
{
if( n->Type == CMP_TREE_NODE::LIBID && ( n->Children.empty() || !m_preselect_unit ) )
if( n->Type == LIB_TREE_NODE::LIBID && ( n->Children.empty() || !m_preselect_unit ) )
return m_preselect_lib_id == n->LibId;
else if( n->Type == CMP_TREE_NODE::UNIT && m_preselect_unit )
else if( n->Type == LIB_TREE_NODE::UNIT && m_preselect_unit )
return m_preselect_lib_id == n->Parent->LibId && m_preselect_unit == n->Unit;
else
return false;
@ -515,14 +415,14 @@ CMP_TREE_NODE* CMP_TREE_MODEL_ADAPTER_BASE::ShowPreselect()
}
CMP_TREE_NODE* CMP_TREE_MODEL_ADAPTER_BASE::ShowSingleLibrary()
LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowSingleLibrary()
{
CMP_TREE_NODE* highScore = nullptr;
LIB_TREE_NODE* highScore = nullptr;
FindAndExpand( m_tree,
[]( CMP_TREE_NODE const* n )
[]( LIB_TREE_NODE const* n )
{
return n->Type == CMP_TREE_NODE::TYPE::LIBID &&
return n->Type == LIB_TREE_NODE::TYPE::LIBID &&
n->Parent->Parent->Children.size() == 1;
},
&highScore );

View File

@ -19,12 +19,12 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CMP_TREE_MODEL_ADAPTER_BASE_H
#define _CMP_TREE_MODEL_ADAPTER_BASE_H
#ifndef LIB_TREE_MODEL_ADAPTER_H
#define LIB_TREE_MODEL_ADAPTER_H
#include <lib_id.h>
#include <cmp_tree_model.h>
#include <lib_tree_model.h>
#include <wx/hashmap.h>
#include <wx/dataview.h>
@ -56,8 +56,8 @@
*
* Because this adapter is a wxDataViewModel, it is reference-counted by
* wxObject. To ensure this interface is used correctly, the constructor
* is private; CMP_TREE_MODEL_ADAPTER should be created by the static
* factory method CMP_TREE_MODEL_ADAPTER::Create().
* is private; LIB_TREE_MODEL_ADAPTER should be created by the static
* factory method LIB_TREE_MODEL_ADAPTER::Create().
*
* Quick summary of methods used to drive this class:
*
@ -89,20 +89,20 @@
* - `Compare()` - compare two rows, for sorting
* - `HasDefaultCompare()` - whether sorted by default
*/
class CMP_TREE_MODEL_ADAPTER_BASE: public wxDataViewModel
class LIB_TREE_MODEL_ADAPTER: public wxDataViewModel
{
public:
/**
* Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
*/
typedef wxObjectDataPtr<CMP_TREE_MODEL_ADAPTER_BASE> PTR;
typedef wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> PTR;
/**
* Destructor. Do NOT delete this class manually; it is reference-counted
* by wxObject.
*/
~CMP_TREE_MODEL_ADAPTER_BASE();
~LIB_TREE_MODEL_ADAPTER();
/**
* This enum allows a selective filtering of components to list
@ -142,47 +142,16 @@ public:
*/
void SetPreselectNode( LIB_ID const& aLibId, int aUnit );
/**
* Add all the components and their aliases in this library. To be called
* in the setup phase.
*
* @param aLibNickname reference to a symbol library nickname
*/
virtual void AddLibrary( wxString const& aLibNickname ) = 0;
/**
* Add all the libraries in a SYMBOL_LIB_TABLE to the model,
* displaying a progress dialog attached to the parent frame
*
* @param aNicknames is the list of library nicknames
* @param aParent is the parent window to display the progress dialog
*/
void AddLibrariesWithProgress( const std::vector<wxString>& aNicknames,
wxWindow* aParent );
/**
* Add the given list of components, by name. To be called in the setup
* phase.
*
* @param aNodeName the parent node the components will appear under
* @param aAliasNameList list of alias names
*/
virtual void AddAliasList(
wxString const& aNodeName,
wxArrayString const& aAliasNameList ) = 0;
/**
* Add the given list of components by alias. To be called in the setup
* phase.
*
* @param aNodeName the parent node the components will appear under
* @param aDesc the description field of the parent node
* @param aAliasList list of aliases
* @param aCompList list of components
*/
void AddAliasList(
wxString const& aNodeName,
wxString const& aDesc,
std::vector<LIB_ALIAS*> const& aAliasList );
void DoAddLibrary( wxString const& aNodeName, wxString const& aDesc,
std::vector<LIB_TREE_ITEM*> const& aCompList );
/**
* Set the search string provided by the user.
@ -228,12 +197,14 @@ public:
*
* @return Type of the selected node, might be INVALID.
*/
CMP_TREE_NODE::TYPE GetTypeFor( const wxDataViewItem& aSelection ) const;
LIB_TREE_NODE::TYPE GetTypeFor( const wxDataViewItem& aSelection ) const;
virtual wxString GenerateInfo( LIB_ID const& aLibId, int aUnit ) { return wxEmptyString; };
/**
* Return the number of components loaded in the tree.
*/
int GetComponentsCount() const;
int GetItemCount() const;
/**
* Return the number of libraries loaded in the tree.
@ -256,8 +227,7 @@ public:
*
* @return number of children
*/
virtual unsigned int GetChildren(
wxDataViewItem const& aItem,
unsigned int GetChildren( wxDataViewItem const& aItem,
wxDataViewItemArray& aChildren ) const override;
// Freezing/Thawing. Used when updating the table model so that we don't try and fetch
@ -268,16 +238,16 @@ public:
bool IsFrozen() const { return m_freeze; }
protected:
static wxDataViewItem ToItem( CMP_TREE_NODE const* aNode );
static CMP_TREE_NODE const* ToNode( wxDataViewItem aItem );
static unsigned int IntoArray( CMP_TREE_NODE const& aNode, wxDataViewItemArray& aChildren );
static wxDataViewItem ToItem( LIB_TREE_NODE const* aNode );
static LIB_TREE_NODE const* ToNode( wxDataViewItem aItem );
static unsigned int IntoArray( LIB_TREE_NODE const& aNode, wxDataViewItemArray& aChildren );
CMP_TREE_NODE_ROOT m_tree;
LIB_TREE_NODE_ROOT m_tree;
/**
* Constructor
*/
CMP_TREE_MODEL_ADAPTER_BASE();
LIB_TREE_MODEL_ADAPTER();
/**
* Check whether a container has columns too
@ -316,8 +286,7 @@ protected:
* @param aItem item whose data will be placed into aVariant
* @param aCol column number of the data
*/
virtual void GetValue(
wxVariant& aVariant,
virtual void GetValue( wxVariant& aVariant,
wxDataViewItem const& aItem,
unsigned int aCol ) const override;
@ -325,8 +294,7 @@ protected:
* Set the value of an item. Does nothing - this model doesn't support
* editing.
*/
virtual bool SetValue(
wxVariant const& aVariant,
virtual bool SetValue( wxVariant const& aVariant,
wxDataViewItem const& aItem,
unsigned int aCol ) override { return false; }
@ -338,8 +306,7 @@ protected:
* @param aAttr receiver for attributes
* @return true iff the item has non-default attributes
*/
virtual bool GetAttr(
wxDataViewItem const& aItem,
virtual bool GetAttr( wxDataViewItem const& aItem,
unsigned int aCol,
wxDataViewItemAttr& aAttr ) const override;
@ -358,11 +325,6 @@ private:
static WIDTH_CACHE m_width_cache;
/**
* Flag to only show the symbol library table load progress dialog the first time.
*/
static bool m_show_progress;
/**
* Compute the width required for the given column of a node and its
* children.
@ -371,45 +333,32 @@ private:
* @param aCol - column number
* @param aHeading - heading text, to set the minimum width
*/
int ColWidth( CMP_TREE_NODE& aTree, int aCol, wxString const& aHeading );
/**
* Return the width required to display a single row's aCol text.
* This is cached for efficiency as it's very slow on some platforms
* (*cough* macOS)
*/
int WidthFor( CMP_TREE_NODE& aNode, int aCol );
/**
* Return the width required to display a column's heading. This is
* cached by column number for the same reason as the width per cell.
*/
int WidthFor( wxString const& aHeading, int aCol );
int ColWidth( LIB_TREE_NODE& aTree, int aCol, wxString const& aHeading );
/**
* Find any results worth highlighting and expand them, according to given
* criteria (f(CMP_TREE_NODE const*) -> bool)
* The highest-scoring node is written to aHighScore
*/
void FindAndExpand( CMP_TREE_NODE& aNode,
std::function<bool( CMP_TREE_NODE const* )> aFunc,
CMP_TREE_NODE** aHighScore );
void FindAndExpand( LIB_TREE_NODE& aNode,
std::function<bool( LIB_TREE_NODE const* )> aFunc,
LIB_TREE_NODE** aHighScore );
/**
* Find and expand successful search results. Return the best match (if any).
*/
CMP_TREE_NODE* ShowResults();
LIB_TREE_NODE* ShowResults();
/**
* Find and expand preselected node. Return the best match (if any).
*/
CMP_TREE_NODE* ShowPreselect();
LIB_TREE_NODE* ShowPreselect();
/**
* Find and expand a library if there is only one. Return the best match (if any).
*/
CMP_TREE_NODE* ShowSingleLibrary();
LIB_TREE_NODE* ShowSingleLibrary();
};
#endif // _CMP_TREE_MODEL_ADAPTER_BASE_H
#endif // LIB_TREE_MODEL_ADAPTER_H

View File

@ -22,8 +22,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "component_tree.h"
#include <generate_alias_info.h>
#include "lib_tree.h"
#include <wxdataviewctrl_helpers.h>
#include <wx/artprov.h>
@ -31,13 +30,13 @@
#include <wx/statbmp.h>
#include <wx/html/htmlwin.h>
#include <symbol_lib_table.h>
#include <lib_table_base.h>
COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTable,
CMP_TREE_MODEL_ADAPTER_BASE::PTR& aAdapter, WIDGETS aWidgets, wxHtmlWindow* aDetails )
LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAPTER::PTR& aAdapter,
WIDGETS aWidgets, wxHtmlWindow* aDetails )
: wxPanel( aParent ),
m_sym_lib_table( aSymLibTable ),
m_lib_table( aLibTable ),
m_adapter( aAdapter ),
m_query_ctrl( nullptr ),
m_details_ctrl( nullptr ),
@ -45,7 +44,7 @@ COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTabl
m_filtering( false )
{
// create space for context menu pointers, INVALID is the max value
m_menus.resize( CMP_TREE_NODE::TYPE::INVALID + 1 );
m_menus.resize( LIB_TREE_NODE::TYPE::INVALID + 1 );
auto sizer = new wxBoxSizer( wxVERTICAL );
@ -59,17 +58,16 @@ COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTabl
// Additional visual cue for GTK, which hides the placeholder text on focus
#ifdef __WXGTK__
search_sizer->Add( new wxStaticBitmap( this, wxID_ANY,
wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) ),
0, wxALIGN_CENTER | wxALL, 5 );
auto bitmap = new wxStaticBitmap( this, wxID_ANY, wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) );
search_sizer->Add( bitmap, 0, wxALIGN_CENTER | wxALL, 5 );
#endif
search_sizer->Add( m_query_ctrl, 1, wxLEFT | wxTOP | wxEXPAND, 5 );
sizer->Add( search_sizer, 0, wxEXPAND, 5 );
m_query_ctrl->Bind( wxEVT_TEXT, &COMPONENT_TREE::onQueryText, this );
m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &COMPONENT_TREE::onQueryEnter, this );
m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &COMPONENT_TREE::onQueryCharHook, this );
m_query_ctrl->Bind( wxEVT_TEXT, &LIB_TREE::onQueryText, this );
m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &LIB_TREE::onQueryEnter, this );
m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
}
// Component tree
@ -97,16 +95,16 @@ COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTabl
m_details_ctrl = aDetails;
}
m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &COMPONENT_TREE::onDetailsLink, this );
m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &LIB_TREE::onDetailsLink, this );
}
SetSizer( sizer );
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &COMPONENT_TREE::onTreeActivate, this );
m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &COMPONENT_TREE::onTreeSelect, this );
m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &COMPONENT_TREE::onContextMenu, this );
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
Bind( COMPONENT_PRESELECTED, &COMPONENT_TREE::onPreselect, this );
Bind( COMPONENT_PRESELECTED, &LIB_TREE::onPreselect, this );
// If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
// handler will intermittently fire.
@ -132,7 +130,7 @@ COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTabl
}
LIB_ID COMPONENT_TREE::GetSelectedLibId( int* aUnit ) const
LIB_ID LIB_TREE::GetSelectedLibId( int* aUnit ) const
{
auto sel = m_tree_ctrl->GetSelection();
@ -150,19 +148,19 @@ LIB_ID COMPONENT_TREE::GetSelectedLibId( int* aUnit ) const
}
void COMPONENT_TREE::SelectLibId( const LIB_ID& aLibId )
void LIB_TREE::SelectLibId( const LIB_ID& aLibId )
{
selectIfValid( m_adapter->FindItem( aLibId ) );
}
void COMPONENT_TREE::Unselect()
void LIB_TREE::Unselect()
{
m_tree_ctrl->UnselectAll();
}
void COMPONENT_TREE::Regenerate()
void LIB_TREE::Regenerate()
{
STATE current;
@ -181,7 +179,7 @@ void COMPONENT_TREE::Regenerate()
}
void COMPONENT_TREE::SetFocus()
void LIB_TREE::SetFocus()
{
if( m_query_ctrl )
m_query_ctrl->SetFocus();
@ -190,7 +188,7 @@ void COMPONENT_TREE::SetFocus()
}
void COMPONENT_TREE::toggleExpand( const wxDataViewItem& aTreeId )
void LIB_TREE::toggleExpand( const wxDataViewItem& aTreeId )
{
if( !aTreeId.IsOk() )
return;
@ -202,7 +200,7 @@ void COMPONENT_TREE::toggleExpand( const wxDataViewItem& aTreeId )
}
void COMPONENT_TREE::selectIfValid( const wxDataViewItem& aTreeId )
void LIB_TREE::selectIfValid( const wxDataViewItem& aTreeId )
{
if( aTreeId.IsOk() )
{
@ -213,21 +211,21 @@ void COMPONENT_TREE::selectIfValid( const wxDataViewItem& aTreeId )
}
void COMPONENT_TREE::postPreselectEvent()
void LIB_TREE::postPreselectEvent()
{
wxCommandEvent event( COMPONENT_PRESELECTED );
wxPostEvent( this, event );
}
void COMPONENT_TREE::postSelectEvent()
void LIB_TREE::postSelectEvent()
{
wxCommandEvent event( COMPONENT_SELECTED );
wxPostEvent( this, event );
}
COMPONENT_TREE::STATE COMPONENT_TREE::getState() const
LIB_TREE::STATE LIB_TREE::getState() const
{
STATE state;
wxDataViewItemArray items;
@ -245,7 +243,7 @@ COMPONENT_TREE::STATE COMPONENT_TREE::getState() const
}
void COMPONENT_TREE::setState( const STATE& aState )
void LIB_TREE::setState( const STATE& aState )
{
m_tree_ctrl->Freeze();
@ -261,7 +259,7 @@ void COMPONENT_TREE::setState( const STATE& aState )
}
void COMPONENT_TREE::onQueryText( wxCommandEvent& aEvent )
void LIB_TREE::onQueryText( wxCommandEvent& aEvent )
{
Regenerate();
@ -271,17 +269,17 @@ void COMPONENT_TREE::onQueryText( wxCommandEvent& aEvent )
}
void COMPONENT_TREE::onQueryEnter( wxCommandEvent& aEvent )
void LIB_TREE::onQueryEnter( wxCommandEvent& aEvent )
{
if( GetSelectedLibId().IsValid() )
postSelectEvent();
}
void COMPONENT_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
{
auto const sel = m_tree_ctrl->GetSelection();
auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : CMP_TREE_NODE::INVALID;
auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
switch( aKeyStroke.GetKeyCode() )
{
@ -294,7 +292,7 @@ void COMPONENT_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
break;
case WXK_RETURN:
if( type == CMP_TREE_NODE::LIB )
if( type == LIB_TREE_NODE::LIB )
{
toggleExpand( sel );
break;
@ -308,13 +306,13 @@ void COMPONENT_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
}
void COMPONENT_TREE::onTreeSelect( wxDataViewEvent& aEvent )
void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent )
{
postPreselectEvent();
}
void COMPONENT_TREE::onTreeActivate( wxDataViewEvent& aEvent )
void LIB_TREE::onTreeActivate( wxDataViewEvent& aEvent )
{
if( !GetSelectedLibId().IsValid() )
{
@ -328,14 +326,14 @@ void COMPONENT_TREE::onTreeActivate( wxDataViewEvent& aEvent )
}
void COMPONENT_TREE::onDetailsLink( wxHtmlLinkEvent& aEvent )
void LIB_TREE::onDetailsLink( wxHtmlLinkEvent& aEvent )
{
const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
::wxLaunchDefaultBrowser( info.GetHref() );
}
void COMPONENT_TREE::onPreselect( wxCommandEvent& aEvent )
void LIB_TREE::onPreselect( wxCommandEvent& aEvent )
{
if( m_details_ctrl )
{
@ -343,7 +341,7 @@ void COMPONENT_TREE::onPreselect( wxCommandEvent& aEvent )
LIB_ID id = GetSelectedLibId( &unit );
if( id.IsValid() )
m_details_ctrl->SetPage( GenerateAliasInfo( m_sym_lib_table, id, unit ) );
m_details_ctrl->SetPage( m_adapter->GenerateInfo( id, unit ) );
else
m_details_ctrl->SetPage( wxEmptyString );
}
@ -352,10 +350,10 @@ void COMPONENT_TREE::onPreselect( wxCommandEvent& aEvent )
}
void COMPONENT_TREE::onContextMenu( wxDataViewEvent& aEvent )
void LIB_TREE::onContextMenu( wxDataViewEvent& aEvent )
{
auto const sel = m_tree_ctrl->GetSelection();
auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : CMP_TREE_NODE::INVALID;
auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
if( m_menus[type] )
{

View File

@ -22,24 +22,24 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef COMPONENT_TREE_H
#define COMPONENT_TREE_H
#ifndef LIB_TREE_H
#define LIB_TREE_H
#include <wx/panel.h>
#include <cmp_tree_model_adapter.h>
#include <lib_tree_model_adapter.h>
class wxDataViewCtrl;
class wxTextCtrl;
class wxHtmlWindow;
class wxHtmlLinkEvent;
class LIB_ID;
class SYMBOL_LIB_TABLE;
class LIB_TABLE;
/**
* Widget displaying a tree of components with optional search text control and description panel.
*/
class COMPONENT_TREE : public wxPanel
class LIB_TREE : public wxPanel
{
public:
///> Flags to select extra widgets
@ -49,15 +49,14 @@ public:
* Construct a component tree.
*
* @param aParent parent window containing this tree widget
* @param aSymLibTable table containing symbols to display
* @param aAdapter a CMP_TREE_MODEL_ADAPTER instance to use
* @param aLibTable table containing libraries and items to display
* @param aAdapter a LIB_TREE_MODEL_ADAPTER instance to use
* @param aWidgets selection of sub-widgets to include
* @param aDetails if not null, a custom wxHtmlWindow to hold symbol details. If null this will
* be created inside the COMPONENT_TREE.
* @param aDetails if not null, a custom wxHtmlWindow to hold symbol details. If null this
* will be created inside the LIB_TREE.
*/
COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTable,
CMP_TREE_MODEL_ADAPTER_BASE::PTR& aAdapter, WIDGETS aWidgets = ALL,
wxHtmlWindow *aDetails = nullptr );
LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAPTER::PTR& aAdapter,
WIDGETS aWidgets = ALL, wxHtmlWindow *aDetails = nullptr );
/**
* For multi-unit components, if the user selects the component itself
@ -87,7 +86,7 @@ public:
* @param aType is the node type to have a menu associated.
* @param aMenu is the associated menu.
*/
void SetMenu( CMP_TREE_NODE::TYPE aType, std::unique_ptr<wxMenu> aMenu )
void SetMenu( LIB_TREE_NODE::TYPE aType, std::unique_ptr<wxMenu> aMenu )
{
m_menus[aType] = std::move( aMenu );
}
@ -163,8 +162,8 @@ protected:
void onPreselect( wxCommandEvent& aEvent );
void onContextMenu( wxDataViewEvent& aEvent );
SYMBOL_LIB_TABLE* m_sym_lib_table;
CMP_TREE_MODEL_ADAPTER_BASE::PTR m_adapter;
LIB_TABLE* m_lib_table;
LIB_TREE_MODEL_ADAPTER::PTR m_adapter;
wxTextCtrl* m_query_ctrl;
wxDataViewCtrl* m_tree_ctrl;
@ -189,4 +188,4 @@ wxDECLARE_EVENT( COMPONENT_PRESELECTED, wxCommandEvent );
///> Custom event sent when a component is selected
wxDECLARE_EVENT( COMPONENT_SELECTED, wxCommandEvent );
#endif /* COMPONENT_TREE_H */
#endif /* LIB_TREE_H */

View File

@ -753,7 +753,7 @@ void CVPCB_MAINFRAME::DisplayStatus()
if( module ) // can be NULL if no netlist loaded
{
msg = wxString::Format( _( "Description: %s; Key words: %s" ),
module->GetDoc(),
module->GetDescription(),
module->GetKeywords() );
}

View File

@ -87,10 +87,9 @@ set( EESCHEMA_DLGS
)
set( EESCHEMA_WIDGETS
widgets/cmp_tree_pane.cpp
widgets/component_tree.cpp
widgets/pin_shape_combobox.cpp
widgets/pin_type_combobox.cpp
widgets/symbol_tree_pane.cpp
widgets/widget_eeschema_color_config.cpp
)
@ -109,9 +108,6 @@ set( EESCHEMA_SRCS
class_library.cpp
cmp_library_keywords.cpp
cmp_library_lexer.cpp
cmp_tree_model.cpp
cmp_tree_model_adapter.cpp
cmp_tree_model_adapter_base.cpp
component_references_lister.cpp
controle.cpp
cross-probing.cpp
@ -140,7 +136,6 @@ set( EESCHEMA_SRCS
lib_export.cpp
lib_field.cpp
lib_manager.cpp
lib_manager_adapter.cpp
lib_pin.cpp
lib_polyline.cpp
lib_rectangle.cpp
@ -201,6 +196,8 @@ set( EESCHEMA_SRCS
symbdraw.cpp
symbedit.cpp
symbol_lib_table.cpp
symbol_tree_model_adapter.cpp
symbol_tree_synchronizing_adapter.cpp
template_fieldnames.cpp
template_fieldnames_keywords.cpp
tool_lib.cpp

View File

@ -111,6 +111,14 @@ bool LIB_ALIAS::IsRoot() const
}
LIB_ID LIB_ALIAS::GetLibId() const
{
LIB_ID id = shared->GetLibId();
id.SetLibItemName( name );
return id;
}
PART_LIB* LIB_ALIAS::GetLib()
{
return shared->GetLib();
@ -123,6 +131,34 @@ void LIB_ALIAS::SetName( const wxString& aName )
}
int LIB_ALIAS::GetUnitCount()
{
return shared->GetUnitCount();
}
wxString LIB_ALIAS::GetUnitReference( int aUnit )
{
return LIB_PART::SubReference( aUnit, false );
}
wxString LIB_ALIAS::GetSearchText()
{
wxString text = GetKeyWords() + wxT( " " ) + GetDescription();
// If a footprint is defined for the part, add it to the serach string
if( shared )
{
wxString footprint = shared->GetFootprintField().GetText();
if( !footprint.IsEmpty() )
text += wxT( " " ) + footprint;
}
return text;
}
bool LIB_ALIAS::operator==( const wxChar* aName ) const
{
@ -136,12 +172,6 @@ bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 )
}
int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 )
{
return aItem1->GetName().Cmp( aItem2->GetName() );
}
/// http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
struct null_deleter
{

View File

@ -31,7 +31,7 @@
#define CLASS_LIBENTRY_H
#include <general.h>
#include <lib_id.h>
#include <lib_tree_item.h>
#include <lib_draw_item.h>
#include <lib_field.h>
#include <vector>
@ -70,7 +70,7 @@ enum LIBRENTRYOPTIONS
* method to create parts that have the same physical layout with different names
* such as 74LS00, 74HC00 ... and many op amps.
*/
class LIB_ALIAS : public EDA_ITEM
class LIB_ALIAS : public EDA_ITEM, public LIB_TREE_ITEM
{
/**
* Actual LIB_PART referenced by [multiple] aliases.
@ -111,23 +111,22 @@ public:
const wxString GetLibraryName();
bool IsRoot() const;
bool IsRoot() const override;
LIB_ID GetLibId() const override;
PART_LIB* GetLib();
const wxString& GetName() const { return name; }
const wxString& GetName() const override { return name; }
void SetName( const wxString& aName );
///> Helper function to replace illegal chars in symbol names
static void ValidateName( wxString& aName );
void SetDescription( const wxString& aDescription )
{
description = aDescription;
}
wxString GetDescription() const { return description; }
wxString GetDescription() override { return description; }
void SetKeyWords( const wxString& aKeyWords )
{
@ -143,6 +142,12 @@ public:
wxString GetDocFileName() const { return docFileName; }
wxString GetSearchText() override;
int GetUnitCount() override;
wxString GetUnitReference( int aUnit ) override;
/**
* KEEPCASE sensitive comparison of the part entry name.
*/
@ -161,8 +166,6 @@ public:
extern bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 );
extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 );
struct PART_DRAW_OPTIONS
{

View File

@ -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 );
}

View File

@ -40,7 +40,7 @@
#include <sch_base_frame.h>
#include <template_fieldnames.h>
#include <symbol_lib_table.h>
#include <widgets/component_tree.h>
#include <widgets/lib_tree.h>
#include <widgets/footprint_preview_widget.h>
#include <widgets/footprint_select_widget.h>
@ -53,14 +53,16 @@ std::mutex DIALOG_CHOOSE_COMPONENT::g_Mutex;
DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle,
CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert, bool aAllowFieldEdits,
bool aShowFootprints )
SYMBOL_TREE_MODEL_ADAPTER::PTR& aAdapter,
int aDeMorganConvert, bool aAllowFieldEdits,
bool aShowFootprints, bool aAllowBrowser )
: DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
m_browser_button( nullptr ),
m_hsplitter( nullptr ),
m_vsplitter( nullptr ),
m_fp_sel_ctrl( nullptr ),
m_fp_view_ctrl( nullptr ),
m_fp_preview( nullptr ),
m_parent( aParent ),
m_deMorganConvert( aDeMorganConvert >= 0 ? aDeMorganConvert : 0 ),
m_allow_field_edits( aAllowFieldEdits ),
@ -110,33 +112,43 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const
sizer->Add( m_vsplitter, 1, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
}
m_tree = new COMPONENT_TREE( m_hsplitter, Prj().SchSymbolLibTable(), aAdapter,
COMPONENT_TREE::WIDGETS::ALL, details );
m_symbol_view_panel = ConstructRightPanel( m_hsplitter );
m_tree = new LIB_TREE( m_hsplitter, Prj().SchSymbolLibTable(), aAdapter,
LIB_TREE::WIDGETS::ALL, details );
m_hsplitter->SetSashGravity( 0.8 );
m_hsplitter->SetMinimumPaneSize( 20 );
m_hsplitter->SplitVertically( m_tree, m_symbol_view_panel );
m_hsplitter->SplitVertically( m_tree, ConstructRightPanel( m_hsplitter ) );
m_dbl_click_timer = new wxTimer( this );
auto buttons = new wxStdDialogButtonSizer();
buttons->AddButton( new wxButton( this, wxID_OK ) );
buttons->AddButton( new wxButton( this, wxID_CANCEL ) );
buttons->Realize();
auto buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
sizer->Add( buttons, 0, wxEXPAND | wxALL, 5 );
if( aAllowBrowser )
{
m_browser_button = new wxButton( this, wxID_ANY, _( "Select with Browser" ) );
buttonsSizer->Add( m_browser_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 10 );
}
auto sdbSizer = new wxStdDialogButtonSizer();
auto okButton = new wxButton( this, wxID_OK );
auto cancelButton = new wxButton( this, wxID_CANCEL );
sdbSizer->AddButton( okButton );
sdbSizer->AddButton( cancelButton );
sdbSizer->Realize();
buttonsSizer->Add( sdbSizer, 1, wxALL, 5 );
sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 );
SetSizer( sizer );
Bind( wxEVT_INIT_DIALOG, &DIALOG_CHOOSE_COMPONENT::OnInitDialog, this );
Bind( wxEVT_ACTIVATE, &DIALOG_CHOOSE_COMPONENT::OnActivate, this );
Bind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this, m_dbl_click_timer->GetId() );
Bind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentPreselected, this );
Bind( COMPONENT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentSelected, this );
m_symbol_preview->Bind( wxEVT_PAINT, &DIALOG_CHOOSE_COMPONENT::OnSymbolPreviewPaint, this );
m_sch_view_ctrl->Bind( wxEVT_LEFT_DCLICK, &DIALOG_CHOOSE_COMPONENT::OnSchViewDClick, this );
m_sch_view_ctrl->Bind( wxEVT_PAINT, &DIALOG_CHOOSE_COMPONENT::OnSchViewPaint, this );
if( m_browser_button )
m_browser_button->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_CHOOSE_COMPONENT::OnUseBrowser, this );
if( m_fp_sel_ctrl )
m_fp_sel_ctrl->Bind( EVT_FOOTPRINT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnFootprintSelected, this );
@ -154,19 +166,22 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const
SetSizeInDU( 360, 280 );
else
SetSize( m_last_dlg_size );
SetInitialFocus( m_tree );
okButton->SetDefault();
}
DIALOG_CHOOSE_COMPONENT::~DIALOG_CHOOSE_COMPONENT()
{
Unbind( wxEVT_INIT_DIALOG, &DIALOG_CHOOSE_COMPONENT::OnInitDialog, this );
Unbind( wxEVT_ACTIVATE, &DIALOG_CHOOSE_COMPONENT::OnActivate, this );
Unbind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this );
Unbind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentPreselected, this );
Unbind( COMPONENT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnComponentSelected, this );
m_symbol_preview->Unbind( wxEVT_PAINT, &DIALOG_CHOOSE_COMPONENT::OnSymbolPreviewPaint, this );
m_sch_view_ctrl->Unbind( wxEVT_LEFT_DCLICK, &DIALOG_CHOOSE_COMPONENT::OnSchViewDClick, this );
m_sch_view_ctrl->Unbind( wxEVT_PAINT, &DIALOG_CHOOSE_COMPONENT::OnSchViewPaint, this );
if( m_browser_button )
m_browser_button->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_CHOOSE_COMPONENT::OnUseBrowser, this );
if( m_fp_sel_ctrl )
m_fp_sel_ctrl->Unbind( EVT_FOOTPRINT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnFootprintSelected, this );
@ -189,9 +204,9 @@ wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructRightPanel( wxWindow* aParent )
auto panel = new wxPanel( aParent );
auto sizer = new wxBoxSizer( wxVERTICAL );
m_sch_view_ctrl = new wxPanel( panel, wxID_ANY, wxDefaultPosition, wxSize( -1, -1 ),
m_symbol_preview = new wxPanel( panel, wxID_ANY, wxDefaultPosition, wxSize( -1, -1 ),
wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL | wxRAISED_BORDER );
m_sch_view_ctrl->SetLayoutDirection( wxLayout_LeftToRight );
m_symbol_preview->SetLayoutDirection( wxLayout_LeftToRight );
if( m_show_footprints )
{
@ -200,19 +215,19 @@ wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructRightPanel( wxWindow* aParent )
if( m_allow_field_edits )
m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( panel, fp_list, true );
m_fp_view_ctrl = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() );
m_fp_preview = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() );
sizer->Add( m_sch_view_ctrl, 1, wxEXPAND | wxTOP | wxBOTTOM | wxRIGHT, 5 );
sizer->Add( m_symbol_preview, 1, wxEXPAND | wxTOP | wxBOTTOM | wxRIGHT, 5 );
if( m_fp_sel_ctrl )
sizer->Add( m_fp_sel_ctrl, 0, wxEXPAND | wxTOP | wxRIGHT, 5 );
sizer->Add( m_fp_view_ctrl, 1, wxEXPAND | wxBOTTOM | wxRIGHT, 5 );
sizer->Add( m_fp_preview, 1, wxEXPAND | wxBOTTOM | wxRIGHT, 5 );
}
else
{
sizer->Add( m_sch_view_ctrl, 1, wxEXPAND | wxTOP | wxRIGHT, 5 );
sizer->Add( m_symbol_preview, 1, wxEXPAND | wxTOP | wxRIGHT, 5 );
}
panel->SetSizer( sizer );
@ -225,10 +240,10 @@ wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructRightPanel( wxWindow* aParent )
void DIALOG_CHOOSE_COMPONENT::OnInitDialog( wxInitDialogEvent& aEvent )
{
if( m_fp_view_ctrl && m_fp_view_ctrl->IsInitialized() )
if( m_fp_preview && m_fp_preview->IsInitialized() )
{
// This hides the GAL panel and shows the status label
m_fp_view_ctrl->SetStatusText( wxEmptyString );
m_fp_preview->SetStatusText( wxEmptyString );
}
if( m_fp_sel_ctrl )
@ -236,20 +251,19 @@ void DIALOG_CHOOSE_COMPONENT::OnInitDialog( wxInitDialogEvent& aEvent )
}
void DIALOG_CHOOSE_COMPONENT::OnActivate( wxActivateEvent& event )
{
m_tree->SetFocus();
event.Skip(); // required under wxMAC
}
LIB_ID DIALOG_CHOOSE_COMPONENT::GetSelectedLibId( int* aUnit ) const
{
return m_tree->GetSelectedLibId( aUnit );
}
void DIALOG_CHOOSE_COMPONENT::OnUseBrowser( wxCommandEvent& aEvent )
{
m_external_browser_requested = true;
EndQuasiModal( wxID_OK );
}
void DIALOG_CHOOSE_COMPONENT::OnCloseTimer( wxTimerEvent& aEvent )
{
// Hack handler because of eaten MouseUp event. See
@ -271,16 +285,9 @@ void DIALOG_CHOOSE_COMPONENT::OnCloseTimer( wxTimerEvent& aEvent )
}
void DIALOG_CHOOSE_COMPONENT::OnSchViewDClick( wxMouseEvent& aEvent )
{
m_external_browser_requested = true;
EndQuasiModal( wxID_OK );
}
void DIALOG_CHOOSE_COMPONENT::ShowFootprintFor( LIB_ID const& aLibId )
{
if( !m_fp_view_ctrl || !m_fp_view_ctrl->IsInitialized() )
if( !m_fp_preview || !m_fp_preview->IsInitialized() )
return;
LIB_ALIAS* alias = nullptr;
@ -298,10 +305,8 @@ void DIALOG_CHOOSE_COMPONENT::ShowFootprintFor( LIB_ID const& aLibId )
ioe.What() ) );
}
if( alias == nullptr )
{
if( !alias )
return;
}
LIB_FIELD* fp_field = alias->GetPart()->GetField( FOOTPRINT );
wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
@ -312,14 +317,12 @@ void DIALOG_CHOOSE_COMPONENT::ShowFootprintFor( LIB_ID const& aLibId )
void DIALOG_CHOOSE_COMPONENT::ShowFootprint( wxString const& aName )
{
if( !m_fp_view_ctrl || !m_fp_view_ctrl->IsInitialized() )
{
if( !m_fp_preview || !m_fp_preview->IsInitialized() )
return;
}
if( aName == wxEmptyString )
{
m_fp_view_ctrl->SetStatusText( _( "No footprint specified" ) );
m_fp_preview->SetStatusText( _( "No footprint specified" ) );
}
else
{
@ -327,13 +330,13 @@ void DIALOG_CHOOSE_COMPONENT::ShowFootprint( wxString const& aName )
if( lib_id.Parse( aName, LIB_ID::ID_PCB ) == -1 && lib_id.IsValid() )
{
m_fp_view_ctrl->ClearStatus();
m_fp_view_ctrl->CacheFootprint( lib_id );
m_fp_view_ctrl->DisplayFootprint( lib_id );
m_fp_preview->ClearStatus();
m_fp_preview->CacheFootprint( lib_id );
m_fp_preview->DisplayFootprint( lib_id );
}
else
{
m_fp_view_ctrl->SetStatusText( _( "Invalid footprint specified" ) );
m_fp_preview->SetStatusText( _( "Invalid footprint specified" ) );
}
}
}
@ -386,7 +389,7 @@ void DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector( LIB_ID const& aLibId )
}
void DIALOG_CHOOSE_COMPONENT::OnSchViewPaint( wxPaintEvent& aEvent )
void DIALOG_CHOOSE_COMPONENT::OnSymbolPreviewPaint( wxPaintEvent& aEvent )
{
int unit = 0;
LIB_ID id = m_tree->GetSelectedLibId( &unit );
@ -413,18 +416,13 @@ void DIALOG_CHOOSE_COMPONENT::OnSchViewPaint( wxPaintEvent& aEvent )
ioe.What() ) );
}
if( alias == nullptr )
if( !alias )
return;
LIB_PART* part = alias ? alias->GetPart() : nullptr;
LIB_PART* part = alias->GetPart();
// Don't draw if we don't have a part to show
// just display a tooltip
if( !part )
{
RenderPreview( nullptr, unit );
return;
}
if( alias->IsRoot() )
{
@ -465,7 +463,7 @@ void DIALOG_CHOOSE_COMPONENT::OnComponentPreselected( wxCommandEvent& aEvent )
LIB_ID id = m_tree->GetSelectedLibId( &unit );
m_sch_view_ctrl->Refresh();
m_symbol_preview->Refresh();
if( id.IsValid() )
{
@ -474,8 +472,8 @@ void DIALOG_CHOOSE_COMPONENT::OnComponentPreselected( wxCommandEvent& aEvent )
}
else
{
if( m_fp_view_ctrl && m_fp_view_ctrl->IsInitialized() )
m_fp_view_ctrl->SetStatusText( wxEmptyString );
if( m_fp_preview && m_fp_preview->IsInitialized() )
m_fp_preview->SetStatusText( wxEmptyString );
PopulateFootprintSelector( id );
}
@ -505,7 +503,7 @@ void DIALOG_CHOOSE_COMPONENT::OnComponentSelected( wxCommandEvent& aEvent )
void DIALOG_CHOOSE_COMPONENT::RenderPreview( LIB_PART* aComponent, int aUnit )
{
wxPaintDC dc( m_sch_view_ctrl );
wxPaintDC dc( m_symbol_preview );
const wxSize dc_size = dc.GetSize();
@ -513,12 +511,8 @@ void DIALOG_CHOOSE_COMPONENT::RenderPreview( LIB_PART* aComponent, int aUnit )
if( dc_size.x == 0 || dc_size.y == 0 )
return;
if( !aComponent ) // display a tooltip
{
wxString tooltip = _( "Double-click here to select a symbol from the library browser" );
GRDrawWrappedText( dc, tooltip );
if( !aComponent )
return;
}
GRResetPenAndBrush( &dc );

View File

@ -25,7 +25,7 @@
#define DIALOG_CHOOSE_COMPONENT_H
#include "dialog_shim.h"
#include <cmp_tree_model_adapter.h>
#include <symbol_tree_model_adapter.h>
#include <footprint_info.h>
class wxStaticBitmap;
@ -39,7 +39,7 @@ class wxChoice;
class wxButton;
class wxTimer;
class COMPONENT_TREE;
class LIB_TREE;
class FOOTPRINT_PREVIEW_WIDGET;
class FOOTPRINT_SELECT_WIDGET;
class LIB_ALIAS;
@ -52,14 +52,14 @@ class SCH_BASE_FRAME;
* View class in a Model-View-Adapter (mediated MVC) architecture. The other
* pieces are in:
*
* - Adapter: CMP_TREE_MODEL_ADAPTER in eeschema/cmp_tree_model_adapter.h
* - Model: CMP_TREE_NODE and descendants in eeschema/cmp_tree_model.h
* - Adapter: CMP_TREE_MODEL_ADAPTER in common/cmp_tree_model_adapter.h
* - Model: CMP_TREE_NODE and descendants in common/cmp_tree_model.h
*
* Because everything is tied together in the adapter class, see that file
* for thorough documentation. A simple example usage follows:
*
* // Create the adapter class
* auto adapter( CMP_TREE_MODEL_ADAPTER::Create( Prj().SchSymbolLibTable() ) );
* auto adapter( SYMBOL_TREE_MODEL_ADAPTER::Create( Prj().SchSymbolLibTable() ) );
*
* // Perform any configuration of adapter properties here
* adapter->SetPreselectNode( "LIB_NICKNAME", "SYMBO_NAME", 2 );
@ -93,18 +93,19 @@ public:
*
* @param aParent a SCH_BASE_FRAME parent window.
* @param aTitle Dialog title.
* @param aAdapter CMP_TREE_MODEL_ADAPTER::PTR. See CMP_TREE_MODEL_ADAPTER
* @param aAdapter SYMBOL_TREE_MODEL_ADAPTER::PTR. See CMP_TREE_MODEL_ADAPTER
* for documentation.
* @param aDeMorganConvert preferred deMorgan conversion
* (TODO: should happen in dialog)
* @param aAllowFieldEdits if false, all functions that allow the user to edit
* fields (currently just footprint selection) will not be available.
* @param aShowFootprints if false, all footprint preview and selection features
* are disabled. This forces aAllowFieldEdits false too.
* @param aAllowFieldEdits if false, all functions that allow the user to edit fields
* (currently just footprint selection) will not be available.
* @param aShowFootprints if false, all footprint preview and selection features are
* disabled. This forces aAllowFieldEdits false too.
* @param aAllowBrowser show a Select with Browser button
*/
DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle,
CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert, bool aAllowFieldEdits,
bool aShowFootprints );
SYMBOL_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert,
bool aAllowFieldEdits, bool aShowFootprints, bool aAllowBrowser );
~DIALOG_CHOOSE_COMPONENT();
@ -148,14 +149,12 @@ protected:
wxPanel* ConstructRightPanel( wxWindow* aParent );
void OnInitDialog( wxInitDialogEvent& aEvent );
void OnActivate( wxActivateEvent& event );
void OnCloseTimer( wxTimerEvent& aEvent );
void OnUseBrowser( wxCommandEvent& aEvent );
void OnSchViewDClick( wxMouseEvent& aEvent );
void OnSchViewPaint( wxPaintEvent& aEvent );
void OnSymbolPreviewPaint( wxPaintEvent& aEvent );
void OnFootprintSelected( wxCommandEvent& aEvent );
void OnComponentPreselected( wxCommandEvent& aEvent );
/**
@ -190,20 +189,17 @@ protected:
void RenderPreview( LIB_PART* aComponent, int aUnit );
wxTimer* m_dbl_click_timer;
wxPanel* m_sch_view_ctrl;
// the wxSplitterWindow that manages the symbol tree and symbol canvas viewer
wxPanel* m_symbol_preview;
wxButton* m_browser_button;
wxSplitterWindow* m_hsplitter;
wxSplitterWindow* m_vsplitter;
// the symbol canvas viewer
wxPanel* m_symbol_view_panel;
// the sash position separation between symbol tree and symbol canvas viewer
// (remember the sash position during a session)
static int m_h_sash_pos;
static int m_v_sash_pos;
FOOTPRINT_SELECT_WIDGET* m_fp_sel_ctrl;
FOOTPRINT_PREVIEW_WIDGET* m_fp_view_ctrl;
COMPONENT_TREE* m_tree;
FOOTPRINT_PREVIEW_WIDGET* m_fp_preview;
LIB_TREE* m_tree;
static int m_h_sash_pos; // remember sash positions during a session
static int m_v_sash_pos;
SCH_BASE_FRAME* m_parent;
int m_deMorganConvert;

View File

@ -303,7 +303,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnBrowseLibrary( wxCommandEvent& event
LIB_ID id;
id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH );
auto sel = GetParent()->SelectComponentFromLibrary( nullptr, dummy, true, 0, 0, false, &id );
auto sel = GetParent()->SelectComponentFromLibTree( nullptr, dummy, true, 0, 0, false, &id );
if( !sel.LibId.IsValid() )
return;

View File

@ -45,20 +45,20 @@ static const wxString FieldFormat =
static const wxString DatasheetLinkFormat = "<a href=\"__HREF__\">__TEXT__</a>";
class ALIAS_INFO_GENERATOR
class FOOTPRINT_INFO_GENERATOR
{
wxString m_html;
SYMBOL_LIB_TABLE* m_sym_lib_table;
LIB_ID const m_lib_id;
LIB_ALIAS* m_alias;
LIB_ALIAS* m_module;
int m_unit;
public:
ALIAS_INFO_GENERATOR( SYMBOL_LIB_TABLE* aSymbolLibTable, LIB_ID const& aLibId, int aUnit )
FOOTPRINT_INFO_GENERATOR( SYMBOL_LIB_TABLE* aSymbolLibTable, LIB_ID const& aLibId, int aUnit )
: m_html( DescriptionFormat ),
m_sym_lib_table( aSymbolLibTable ),
m_lib_id( aLibId ),
m_alias( nullptr ),
m_module( nullptr ),
m_unit( aUnit )
{ }
@ -74,7 +74,7 @@ public:
try
{
m_alias = const_cast< LIB_ALIAS* >( m_sym_lib_table->LoadSymbol( m_lib_id ) );
m_module = const_cast< LIB_ALIAS* >( m_sym_lib_table->LoadSymbol( m_lib_id ) );
}
catch( const IO_ERROR& ioe )
{
@ -86,7 +86,7 @@ public:
return;
}
if( m_alias )
if( m_module )
{
SetHtmlName();
SetHtmlAliasOf();
@ -107,13 +107,13 @@ public:
protected:
void SetHtmlName()
{
m_html.Replace( "__NAME__", EscapedHTML( m_alias->GetName() ) );
m_html.Replace( "__NAME__", EscapedHTML( m_module->GetName() ) );
}
void SetHtmlAliasOf()
{
if( m_alias->IsRoot() )
if( m_module->IsRoot() )
{
m_html.Replace( "__ALIASOF__", wxEmptyString );
}
@ -122,7 +122,7 @@ protected:
wxString root_name = _( "Unknown" );
wxString root_desc = "";
LIB_PART* root = m_alias->GetPart();
LIB_PART* root = m_module->GetPart();
LIB_ALIAS* root_alias = root ? root->GetAlias( 0 ) : nullptr;
if( root )
@ -140,7 +140,7 @@ protected:
void SetHtmlDesc()
{
wxString raw_desc = m_alias->GetDescription();
wxString raw_desc = m_module->GetDescription();
m_html.Replace( "__DESC__", wxString::Format( DescFormat, EscapedHTML( raw_desc ) ) );
}
@ -148,7 +148,7 @@ protected:
void SetHtmlKeywords()
{
wxString keywords = m_alias->GetKeyWords();
wxString keywords = m_module->GetKeyWords();
if( keywords.empty() )
m_html.Replace( "__KEY__", wxEmptyString );
@ -171,7 +171,7 @@ protected:
case DATASHEET:
{
if( text.IsEmpty() )
text = m_alias->GetDocFileName();
text = m_module->GetDocFileName();
wxString datasheetlink = DatasheetLinkFormat;
datasheetlink.Replace( "__HREF__", EscapedHTML( text ) );
@ -197,7 +197,7 @@ protected:
{
wxString fieldtable;
LIB_FIELDS fields;
m_alias->GetPart()->GetFields( fields );
m_module->GetPart()->GetFields( fields );
for( auto const & field: fields )
{
@ -211,7 +211,7 @@ protected:
wxString GenerateAliasInfo( SYMBOL_LIB_TABLE* aSymLibTable, LIB_ID const& aLibId, int aUnit )
{
ALIAS_INFO_GENERATOR gen( aSymLibTable, aLibId, aUnit );
FOOTPRINT_INFO_GENERATOR gen( aSymLibTable, aLibId, aUnit );
gen.GenerateHtml();
return gen.GetHtml();
}

View File

@ -48,7 +48,7 @@
#include <symbol_lib_table.h>
#include <dialog_choose_component.h>
#include <cmp_tree_model_adapter.h>
#include <symbol_tree_model_adapter.h>
SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowser(
@ -98,10 +98,10 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowse
}
SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibTree(
const SCHLIB_FILTER* aFilter,
std::vector<COMPONENT_SELECTION>& aHistoryList,
bool aUseLibBrowser,
bool aAllowBrowser,
int aUnit,
int aConvert,
bool aShowFootprints,
@ -116,7 +116,8 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
if( !dialogLock.try_lock() )
return COMPONENT_SELECTION();
auto adapter( CMP_TREE_MODEL_ADAPTER::Create( libs ) );
auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( libs ) );
auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
bool loaded = false;
if( aFilter )
@ -133,13 +134,13 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
}
if( aFilter->GetFilterPowerParts() )
adapter->SetFilter( CMP_TREE_MODEL_ADAPTER::CMP_FILTER_POWER );
adapter->SetFilter( SYMBOL_TREE_MODEL_ADAPTER::CMP_FILTER_POWER );
}
if( !aHistoryList.empty() )
{
std::vector< LIB_ALIAS* > history_list;
std::vector< LIB_TREE_ITEM* > history_list;
for( auto const& i : aHistoryList )
{
@ -149,7 +150,7 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
history_list.push_back( alias );
}
adapter->AddAliasList( "-- " + _( "History" ) + " --", _( "Recently used items" ), history_list );
adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, history_list );
adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );
}
@ -157,18 +158,19 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
if( !loaded )
{
adapter->AddLibrariesWithProgress( libNicknames, this );
adapter->AddLibraries( libNicknames, this );
}
if( aHighlight && aHighlight->IsValid() )
adapter->SetPreselectNode( *aHighlight, /* aUnit */ 0 );
if( adapter->GetFilter() == CMP_TREE_MODEL_ADAPTER::CMP_FILTER_POWER )
dialogTitle.Printf( _( "Choose Power Symbol (%d items loaded)" ), adapter->GetComponentsCount() );
if( adapter->GetFilter() == SYMBOL_TREE_MODEL_ADAPTER::CMP_FILTER_POWER )
dialogTitle.Printf( _( "Choose Power Symbol (%d items loaded)" ), adapter->GetItemCount() );
else
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetComponentsCount() );
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, aConvert, aAllowFields, aShowFootprints );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, aConvert,
aAllowFields, aShowFootprints, aAllowBrowser );
if( dlg.ShowQuasiModal() == wxID_CANCEL )
return COMPONENT_SELECTION();
@ -214,14 +216,14 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibrary(
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC,
const SCHLIB_FILTER* aFilter,
SCH_BASE_FRAME::HISTORY_LIST& aHistoryList,
bool aUseLibBrowser )
bool aAllowBrowser )
{
wxString msg;
SetRepeatItem( NULL );
m_canvas->SetIgnoreMouseEvents( true );
auto sel = SelectComponentFromLibrary( aFilter, aHistoryList, aUseLibBrowser, 1, 1,
auto sel = SelectComponentFromLibTree( aFilter, aHistoryList, aAllowBrowser, 1, 1,
m_footprintPreview );
if( !sel.LibId.IsValid() )

View File

@ -48,8 +48,8 @@
#include <lib_pin.h>
#include <lib_manager.h>
#include <widgets/cmp_tree_pane.h>
#include <widgets/component_tree.h>
#include <widgets/symbol_tree_pane.h>
#include <widgets/lib_tree.h>
#include <symbol_lib_table.h>
#include <kicad_device_context.h>
@ -245,7 +245,7 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_libMgr = new LIB_MANAGER( *this );
SyncLibraries( true );
m_treePane = new CMP_TREE_PANE( this, m_libMgr );
m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr );
ReCreateMenuBar();
ReCreateHToolbar();
@ -460,7 +460,7 @@ bool LIB_EDIT_FRAME::IsSearchTreeShown()
void LIB_EDIT_FRAME::ClearSearchTreeSelection()
{
m_treePane->GetCmpTree()->Unselect();
m_treePane->GetLibTree()->Unselect();
}
@ -1031,7 +1031,7 @@ void LIB_EDIT_FRAME::SetCurPart( LIB_PART* aPart )
// select the current component in the tree widget
if( aPart )
m_treePane->GetCmpTree()->SelectLibId( aPart->GetLibId() );
m_treePane->GetLibTree()->SelectLibId( aPart->GetLibId() );
wxString partName = aPart ? aPart->GetName() : wxString();
m_libMgr->SetCurrentPart( partName );
@ -1457,7 +1457,7 @@ void LIB_EDIT_FRAME::OnModify()
{
GetScreen()->SetModify();
storeCurrentPart();
m_treePane->GetCmpTree()->Refresh();
m_treePane->GetLibTree()->Refresh();
}
@ -1519,17 +1519,19 @@ void LIB_EDIT_FRAME::refreshSchematic()
bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
{
wxFileName fileName = getLibraryFileName( !aCreateNew );
wxString libName = fileName.GetName();
bool res = false;
wxFileName fn = m_libMgr->GetUniqueLibraryName();
if( !LibraryFileBrowser( !aCreateNew, fn, SchematicLibraryFileWildcard(), SchematicLibraryFileExtension) )
return false;
wxString libName = fn.GetName();
if( libName.IsEmpty() )
return false;
if( m_libMgr->LibraryExists( libName ) )
{
DisplayError( this,
wxString::Format( _( "Library \"%s\" already exists" ), GetChars( libName ) ) );
DisplayError( this, wxString::Format( _( "Library \"%s\" already exists" ), libName ) );
return false;
}
@ -1541,46 +1543,25 @@ bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
if( aCreateNew )
{
res = m_libMgr->CreateLibrary( fileName.GetFullPath(), libTable );
if( !res )
if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
{
DisplayError( this, _( "Could not create the library file. Check write permission." ) );
return false;
}
}
else
{
res = m_libMgr->AddLibrary( fileName.GetFullPath(), libTable );
if( !res )
if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
{
DisplayError( this, _( "Could not open the library file." ) );
return false;
}
}
bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
saveSymbolLibTables( globalTable, !globalTable );
return res;
}
wxFileName LIB_EDIT_FRAME::getLibraryFileName( bool aExisting )
{
wxFileName fn = m_libMgr->GetUniqueLibraryName();
fn.SetExt( SchematicLibraryFileExtension );
wxFileDialog dlg( this,
aExisting ? _( "Select Library" ) : _( "New Library" ),
Prj().GetProjectPath(),
aExisting ? wxString( wxEmptyString ) : fn.GetFullName() ,
SchematicLibraryFileWildcard(),
aExisting ? wxFD_OPEN | wxFD_FILE_MUST_EXIST :
wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL )
return wxFileName();
fn = dlg.GetPath();
fn.SetExt( SchematicLibraryFileExtension );
return fn;
return true;
}
@ -1588,9 +1569,9 @@ LIB_PART* LIB_EDIT_FRAME::getTargetPart() const
{
LIB_ALIAS* alias = nullptr;
if( m_treePane->GetCmpTree()->IsMenuActive() )
if( m_treePane->GetLibTree()->IsMenuActive() )
{
LIB_ID libId = m_treePane->GetCmpTree()->GetSelectedLibId();
LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId();
alias = m_libMgr->GetAlias( libId.GetLibItemName(), libId.GetLibNickname() );
}
else if( LIB_PART* part = GetCurPart() )
@ -1604,7 +1585,7 @@ LIB_PART* LIB_EDIT_FRAME::getTargetPart() const
LIB_ID LIB_EDIT_FRAME::getTargetLibId() const
{
LIB_ID id = m_treePane->GetCmpTree()->GetSelectedLibId();
LIB_ID id = m_treePane->GetLibTree()->GetSelectedLibId();
wxString nickname = id.GetLibNickname();
if( nickname.IsEmpty() && GetCurPart() )
@ -1625,7 +1606,7 @@ void LIB_EDIT_FRAME::SyncLibraries( bool aProgress )
LIB_ID selected;
if( m_treePane )
selected = m_treePane->GetCmpTree()->GetSelectedLibId();
selected = m_treePane->GetLibTree()->GetSelectedLibId();
if( aProgress )
{
@ -1652,7 +1633,7 @@ void LIB_EDIT_FRAME::SyncLibraries( bool aProgress )
found = m_libMgr->GetAdapter()->FindItem( selected );
if( !found )
m_treePane->GetCmpTree()->Unselect();
m_treePane->GetLibTree()->Unselect();
}
m_treePane->Regenerate();
@ -1664,7 +1645,7 @@ void LIB_EDIT_FRAME::SyncLibraries( bool aProgress )
found = m_libMgr->GetAdapter()->FindItem( selected );
if( found )
m_treePane->GetCmpTree()->SelectLibId( selected );
m_treePane->GetLibTree()->SelectLibId( selected );
}
}
}

View File

@ -45,7 +45,7 @@ class LIB_PART;
class LIB_ALIAS;
class LIB_FIELD;
class DIALOG_LIB_EDIT_TEXT;
class CMP_TREE_PANE;
class SYMBOL_TREE_PANE;
class LIB_ID;
class LIB_MANAGER;
@ -60,7 +60,7 @@ class LIB_EDIT_FRAME : public SCH_BASE_FRAME
LIB_COLLECTOR m_collectedItems; ///< Used for hit testing.
wxComboBox* m_partSelectBox; ///< a Box to select a part to edit (if any)
wxComboBox* m_aliasSelectBox; ///< a box to select the alias to edit (if any)
CMP_TREE_PANE* m_treePane; ///< component search tree widget
SYMBOL_TREE_PANE* m_treePane; ///< component search tree widget
LIB_MANAGER* m_libMgr; ///< manager taking care of temporary modificatoins
/** Convert of the item currently being drawn. */
@ -745,9 +745,6 @@ private:
///> Creates or adds an existing library to the symbol library table.
bool addLibraryFile( bool aCreateNew );
///> Displays a file browser dialog to select a library file.
wxFileName getLibraryFileName( bool aExisting );
///> Stores the currently modified part in the library manager buffer.
void storeCurrentPart();

View File

@ -38,7 +38,7 @@
LIB_MANAGER::LIB_MANAGER( LIB_EDIT_FRAME& aFrame )
: m_frame( aFrame ), m_syncHash( 0 )
{
m_adapter = LIB_MANAGER_ADAPTER::Create( this );
m_adapter = SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create( this );
m_adapter->ShowUnits( false );
}

View File

@ -31,7 +31,7 @@
#include <set>
#include <memory>
#include <wx/arrstr.h>
#include <lib_manager_adapter.h>
#include <symbol_tree_synchronizing_adapter.h>
#include <sch_screen.h>
class LIB_ALIAS;
@ -232,7 +232,7 @@ public:
/**
* Returns the adapter object that provides the stored data.
*/
CMP_TREE_MODEL_ADAPTER_BASE::PTR& GetAdapter() { return m_adapter; }
LIB_TREE_MODEL_ADAPTER::PTR& GetAdapter() { return m_adapter; }
/**
* Returns the currently modified library name.
@ -448,8 +448,8 @@ private:
///> Currently modified library
wxString m_currentPart;
LIB_MANAGER_ADAPTER::PTR m_adapter;
LIB_MANAGER_ADAPTER* getAdapter() { return static_cast<LIB_MANAGER_ADAPTER*>( m_adapter.get() ); }
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter;
SYMBOL_TREE_SYNCHRONIZING_ADAPTER* getAdapter() { return static_cast<SYMBOL_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() ); }
};
#endif /* LIB_MANAGER_H */

View File

@ -46,11 +46,11 @@
#include <sch_edit_frame.h>
#include <symbol_lib_table.h>
#include <lib_manager.h>
#include <cmp_tree_pane.h>
#include <component_tree.h>
#include <symbol_tree_pane.h>
#include <widgets/lib_tree.h>
#include <dialog_choose_component.h>
#include <cmp_tree_model_adapter.h>
#include <symbol_tree_model_adapter.h>
#include <dialogs/dialog_lib_new_component.h>
#include <dialog_helpers.h>
@ -319,7 +319,7 @@ void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event )
void LIB_EDIT_FRAME::OnEditPart( wxCommandEvent& aEvent )
{
int unit = 0;
LIB_ID partId = m_treePane->GetCmpTree()->GetSelectedLibId( &unit );
LIB_ID partId = m_treePane->GetLibTree()->GetSelectedLibId( &unit );
loadPart( partId.GetLibItemName(), partId.GetLibNickname(), unit );
}
@ -332,13 +332,13 @@ void LIB_EDIT_FRAME::OnSave( wxCommandEvent& aEvent )
if( partName.IsEmpty() )
{
saveLibrary( getTargetLib(), false );
saveLibrary( libName, false );
}
else
{
// Save Part
if( m_libMgr->FlushPart( libId.GetLibItemName(), libId.GetLibNickname() ) )
m_libMgr->ClearPartModified( libId.GetLibItemName(), libId.GetLibNickname() );
if( m_libMgr->FlushPart( partName,libName ) )
m_libMgr->ClearPartModified( partName, libName );
}
m_treePane->Refresh();
@ -352,7 +352,7 @@ void LIB_EDIT_FRAME::OnSaveAs( wxCommandEvent& aEvent )
const wxString& partName = libId.GetLibItemName();
if( partName.IsEmpty() )
saveLibrary( getTargetLib(), true );
saveLibrary( libName, true );
else
savePartAs();
@ -448,7 +448,7 @@ void LIB_EDIT_FRAME::savePartAs()
fixDuplicateAliases( &new_part, new_lib );
m_libMgr->UpdatePart( &new_part, new_lib );
m_treePane->GetCmpTree()->SelectLibId( LIB_ID( new_lib, new_part.GetName() ) );
m_treePane->GetLibTree()->SelectLibId( LIB_ID( new_lib, new_part.GetName() ) );
if( isCurrentPart( old_lib_id ) )
loadPart( new_name, new_lib, m_unit );
@ -480,7 +480,7 @@ void LIB_EDIT_FRAME::OnRemovePart( wxCommandEvent& aEvent )
void LIB_EDIT_FRAME::OnDuplicatePart( wxCommandEvent& aEvent )
{
int unit = 0;
LIB_ID libId = m_treePane->GetCmpTree()->GetSelectedLibId( &unit );
LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &unit );
wxString lib = libId.GetLibNickname();
if( !m_libMgr->LibraryExists( lib ) )
@ -494,7 +494,7 @@ void LIB_EDIT_FRAME::OnDuplicatePart( wxCommandEvent& aEvent )
LIB_PART newPart( *srcPart );
fixDuplicateAliases( &newPart, lib );
m_libMgr->UpdatePart( &newPart, lib );
m_treePane->GetCmpTree()->SelectLibId( LIB_ID( lib, newPart.GetName() ) );
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newPart.GetName() ) );
}
@ -549,7 +549,7 @@ void LIB_EDIT_FRAME::OnRevert( wxCommandEvent& aEvent )
{
libId = m_libMgr->RevertPart( libId.GetLibItemName(), libId.GetLibNickname() );
m_treePane->GetCmpTree()->SelectLibId( libId );
m_treePane->GetLibTree()->SelectLibId( libId );
m_libMgr->ClearPartModified( libId.GetLibItemName(), libId.GetLibNickname() );
}

View File

@ -28,8 +28,8 @@
#include <lib_edit_frame.h>
#include <class_libentry.h>
#include <lib_manager.h>
#include <component_tree.h>
#include <cmp_tree_pane.h>
#include <widgets/lib_tree.h>
#include <symbol_tree_pane.h>
void LIB_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* ItemToCopy, UNDO_REDO_T undoType )
@ -86,7 +86,7 @@ void LIB_EDIT_FRAME::GetComponentFromRedoList( wxCommandEvent& event )
m_libMgr->UpdatePartAfterRename( part, oldPart->GetName(), lib );
// Reselect the renamed part
m_treePane->GetCmpTree()->SelectLibId( LIB_ID( lib, part->GetName() ) );
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, part->GetName() ) );
}
if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) )
@ -137,7 +137,7 @@ void LIB_EDIT_FRAME::GetComponentFromUndoList( wxCommandEvent& event )
m_libMgr->UpdatePartAfterRename( part, oldPart->GetName(), lib );
// Reselect the renamed part
m_treePane->GetCmpTree()->SelectLibId( LIB_ID( lib, part->GetName() ) );
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, part->GetName() ) );
}
if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) )

View File

@ -35,8 +35,8 @@
#include <dialog_edit_one_field.h>
#include <lib_manager.h>
#include <widgets/cmp_tree_pane.h>
#include <component_tree.h>
#include <widgets/symbol_tree_pane.h>
#include <widgets/lib_tree.h>
void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
@ -93,7 +93,7 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
m_libMgr->UpdatePartAfterRename( parent, oldFieldValue, lib );
// Reselect the renamed part
m_treePane->GetCmpTree()->SelectLibId( LIB_ID( lib, newFieldValue ) );
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newFieldValue ) );
}
if( !aField->InEditMode() && !renamed )

View File

@ -194,7 +194,7 @@ public:
*
* @return the selected component
*/
COMPONENT_SELECTION SelectComponentFromLibrary(
COMPONENT_SELECTION SelectComponentFromLibTree(
const SCHLIB_FILTER* aFilter,
std::vector<COMPONENT_SELECTION>& aHistoryList,
bool aUseLibBrowser,

View File

@ -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 );
}

View File

@ -19,65 +19,55 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CMP_TREE_MODEL_ADAPTER_H
#define _CMP_TREE_MODEL_ADAPTER_H
#ifndef SYMBOL_TREE_MODEL_ADAPTER_H
#define SYMBOL_TREE_MODEL_ADAPTER_H
#include <cmp_tree_model_adapter_base.h>
#include <lib_tree_model_adapter.h>
class LIB_TABLE;
class SYMBOL_LIB_TABLE;
class CMP_TREE_MODEL_ADAPTER: public CMP_TREE_MODEL_ADAPTER_BASE
class SYMBOL_TREE_MODEL_ADAPTER : public LIB_TREE_MODEL_ADAPTER
{
public:
/**
* Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER.
* Destructor. Do NOT delete this class manually; it is reference-counted by wxObject.
*/
//typedef wxObjectDataPtr<CMP_TREE_MODEL_ADAPTER> PTR;
~SYMBOL_TREE_MODEL_ADAPTER();
/**
* Destructor. Do NOT delete this class manually; it is reference-counted
* by wxObject.
*/
~CMP_TREE_MODEL_ADAPTER();
/**
* Factory function: create a model adapter in a reference-counting
* container.
* Factory function: create a model adapter in a reference-counting container.
*
* @param aLibs library set from which parts will be loaded
*/
static PTR Create( SYMBOL_LIB_TABLE* aLibs );
static PTR Create( LIB_TABLE* aLibs );
/**
* Add all the components and their aliases in this library. To be called
* in the setup phase.
* Add all the libraries in a SYMBOL_LIB_TABLE to the model.
* Displays a progress dialog attached to the parent frame the first time it is run.
*
* @param aLibNickname reference to a symbol library nickname
* @param aNicknames is the list of library nicknames
* @param aParent is the parent window to display the progress dialog
*/
void AddLibrary( wxString const& aLibNickname ) override;
void AddLibraries( const std::vector<wxString>& aNicknames, wxWindow* aParent );
/**
* Add the given list of components, by name. To be called in the setup
* phase.
*
* @param aNodeName the parent node the components will appear under
* @param aAliasNameList list of alias names
*/
void AddAliasList(
wxString const& aNodeName,
wxArrayString const& aAliasNameList ) override;
void AddLibrary( wxString const& aLibNickname );
wxString GenerateInfo( LIB_ID const& aLibId, int aUnit ) override;
using CMP_TREE_MODEL_ADAPTER_BASE::AddAliasList;
protected:
/**
* Constructor; takes a set of libraries to be included in the search.
*/
CMP_TREE_MODEL_ADAPTER( SYMBOL_LIB_TABLE* aLibs );
SYMBOL_TREE_MODEL_ADAPTER( LIB_TABLE* aLibs );
private:
/**
* Flag to only show the symbol library table load progress dialog the first time.
*/
static bool m_show_progress;
SYMBOL_LIB_TABLE* m_libs;
};
#endif // _CMP_TREE_MODEL_ADAPTER_H
#endif // SYMBOL_TREE_MODEL_ADAPTER_H

View File

@ -22,42 +22,35 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <lib_manager_adapter.h>
#include <symbol_tree_synchronizing_adapter.h>
#include <lib_manager.h>
#include <symbol_lib_table.h>
#include <class_libentry.h>
CMP_TREE_MODEL_ADAPTER_BASE::PTR LIB_MANAGER_ADAPTER::Create( LIB_MANAGER* aLibMgr )
LIB_TREE_MODEL_ADAPTER::PTR SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create( LIB_MANAGER* aLibMgr )
{
auto adapter = new LIB_MANAGER_ADAPTER( aLibMgr );
auto container = CMP_TREE_MODEL_ADAPTER_BASE::PTR( adapter );
return container;
return PTR( new SYMBOL_TREE_SYNCHRONIZING_ADAPTER( aLibMgr ) );
}
void LIB_MANAGER_ADAPTER::AddLibrary( const wxString& aLibNickname )
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::SYMBOL_TREE_SYNCHRONIZING_ADAPTER( LIB_MANAGER* aLibMgr )
: m_libMgr( aLibMgr ),
m_lastSyncHash( -1 )
{
}
void LIB_MANAGER_ADAPTER::AddAliasList( const wxString& aNodeName,
const wxArrayString& aAliasNameList )
bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::IsContainer( const wxDataViewItem& aItem ) const
{
wxASSERT( false ); // TODO
}
bool LIB_MANAGER_ADAPTER::IsContainer( const wxDataViewItem& aItem ) const
{
const CMP_TREE_NODE* node = ToNode( aItem );
return node ? node->Type == CMP_TREE_NODE::LIB : true;
const LIB_TREE_NODE* node = ToNode( aItem );
return node ? node->Type == LIB_TREE_NODE::LIB : true;
}
#define PROGRESS_INTERVAL_MILLIS 66
void LIB_MANAGER_ADAPTER::Sync( bool aForce, std::function<void(int, int, const wxString&)> aProgressCallback )
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( bool aForce, std::function<void(int, int, const wxString&)> aProgressCallback )
{
wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
@ -87,7 +80,7 @@ void LIB_MANAGER_ADAPTER::Sync( bool aForce, std::function<void(int, int, const
}
else if( m_libMgr->GetLibraryHash( name ) != m_libHashes[name] )
{
updateLibrary( *(CMP_TREE_NODE_LIB*) it->get() );
updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
}
++it;
@ -115,9 +108,9 @@ void LIB_MANAGER_ADAPTER::Sync( bool aForce, std::function<void(int, int, const
}
int LIB_MANAGER_ADAPTER::GetLibrariesCount() const
int SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount() const
{
int count = CMP_TREE_MODEL_ADAPTER_BASE::GetLibrariesCount();
int count = LIB_TREE_MODEL_ADAPTER::GetLibrariesCount();
for( const auto& libName : m_libMgr->GetLibraryNames() )
{
@ -129,7 +122,7 @@ int LIB_MANAGER_ADAPTER::GetLibrariesCount() const
}
void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode )
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary( LIB_TREE_NODE_LIB& aLibNode )
{
auto hashIt = m_libHashes.find( aLibNode.Name );
@ -137,7 +130,7 @@ void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode )
{
// add a new library
for( auto alias : m_libMgr->GetAliases( aLibNode.Name ) )
aLibNode.AddAlias( alias );
aLibNode.AddComp( alias );
}
else if( hashIt->second != m_libMgr->GetLibraryHash( aLibNode.Name ) )
{
@ -156,7 +149,7 @@ void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode )
{
// alias exists both in the component tree and the library manager,
// update only the node data
static_cast<CMP_TREE_NODE_LIB_ID*>( nodeIt->get() )->Update( *aliasIt );
static_cast<LIB_TREE_NODE_LIB_ID*>( nodeIt->get() )->Update( *aliasIt );
aliases.erase( aliasIt );
++nodeIt;
}
@ -169,7 +162,7 @@ void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode )
// now the aliases list contains only new aliases that need to be added to the tree
for( auto alias : aliases )
aLibNode.AddAlias( alias );
aLibNode.AddComp( alias );
}
aLibNode.AssignIntrinsicRanks();
@ -177,17 +170,17 @@ void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode )
}
CMP_TREE_NODE::PTR_VECTOR::iterator LIB_MANAGER_ADAPTER::deleteLibrary(
CMP_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt )
LIB_TREE_NODE::PTR_VECTOR::iterator SYMBOL_TREE_SYNCHRONIZING_ADAPTER::deleteLibrary(
LIB_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt )
{
CMP_TREE_NODE* node = aLibNodeIt->get();
LIB_TREE_NODE* node = aLibNodeIt->get();
m_libHashes.erase( node->Name );
auto it = m_tree.Children.erase( aLibNodeIt );
return it;
}
CMP_TREE_NODE* LIB_MANAGER_ADAPTER::findLibrary( const wxString& aLibNickName )
LIB_TREE_NODE* SYMBOL_TREE_SYNCHRONIZING_ADAPTER::findLibrary( const wxString& aLibNickName )
{
for( auto& lib : m_tree.Children )
{
@ -199,7 +192,7 @@ CMP_TREE_NODE* LIB_MANAGER_ADAPTER::findLibrary( const wxString& aLibNickName )
}
void LIB_MANAGER_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
unsigned int aCol ) const
{
if( IsFrozen() )
@ -217,11 +210,11 @@ void LIB_MANAGER_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& a
aVariant = node->Name;
// mark modified libs with an asterix
if( node->Type == CMP_TREE_NODE::LIB && m_libMgr->IsLibraryModified( node->Name ) )
if( node->Type == LIB_TREE_NODE::LIB && m_libMgr->IsLibraryModified( node->Name ) )
aVariant = node->Name + " *";
// mark modified parts with an asterix
if( node->Type == CMP_TREE_NODE::LIBID
if( node->Type == LIB_TREE_NODE::LIBID
&& m_libMgr->IsPartModified( node->Name, node->Parent->Name ) )
aVariant = node->Name + " *";
@ -238,7 +231,7 @@ void LIB_MANAGER_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& a
}
bool LIB_MANAGER_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
wxDataViewItemAttr& aAttr ) const
{
if( IsFrozen() )
@ -253,7 +246,7 @@ bool LIB_MANAGER_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCo
switch( node->Type )
{
case CMP_TREE_NODE::LIB:
case LIB_TREE_NODE::LIB:
// mark modified libs with bold font
aAttr.SetBold( m_libMgr->IsLibraryModified( node->Name ) );
@ -269,7 +262,7 @@ bool LIB_MANAGER_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCo
#endif
break;
case CMP_TREE_NODE::LIBID:
case LIB_TREE_NODE::LIBID:
// mark modified part with bold font
aAttr.SetBold( m_libMgr->IsPartModified( node->Name, node->Parent->Name ) );
@ -296,7 +289,3 @@ bool LIB_MANAGER_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCo
}
LIB_MANAGER_ADAPTER::LIB_MANAGER_ADAPTER( LIB_MANAGER* aLibMgr )
: m_libMgr( aLibMgr ), m_lastSyncHash( -1 )
{
}

View File

@ -22,44 +22,39 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef LIB_MANAGER_ADAPTER_H
#define LIB_MANAGER_ADAPTER_H
#ifndef SYMBOL_TREE_SYNCHRONIZING_ADAPTER_H
#define SYMBOL_TREE_SYNCHRONIZING_ADAPTER_H
#include <cmp_tree_model_adapter_base.h>
#include <lib_tree_model_adapter.h>
#include <map>
class LIB_MANAGER;
class LIB_MANAGER_ADAPTER : public CMP_TREE_MODEL_ADAPTER_BASE
class SYMBOL_TREE_SYNCHRONIZING_ADAPTER : public LIB_TREE_MODEL_ADAPTER
{
public:
static PTR Create( LIB_MANAGER* aLibs );
void AddLibrary( const wxString& aLibNickname ) override;
void AddAliasList( const wxString& aNodeName, const wxArrayString& aAliasNameList ) override;
bool IsContainer( const wxDataViewItem& aItem ) const override;
void Sync( bool aForce = false, std::function<void(int, int, const wxString&)> aProgressCallback
= [](int, int, const wxString&){} );
void Sync( bool aForce = false,
std::function<void(int, int, const wxString&)> aProgressCallback = [](int, int, const wxString&){} );
int GetLibrariesCount() const override;
protected:
void updateLibrary( CMP_TREE_NODE_LIB& aLibNode );
void updateLibrary( LIB_TREE_NODE_LIB& aLibNode );
CMP_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(
CMP_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt );
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary( LIB_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt );
CMP_TREE_NODE* findLibrary( const wxString& aLibNickName );
LIB_TREE_NODE* findLibrary( const wxString& aLibNickName );
void GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
unsigned int aCol ) const override;
bool GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
wxDataViewItemAttr& aAttr ) const override;
LIB_MANAGER_ADAPTER( LIB_MANAGER* aLibMgr );
SYMBOL_TREE_SYNCHRONIZING_ADAPTER( LIB_MANAGER* aLibMgr );
LIB_MANAGER* m_libMgr;
@ -70,4 +65,4 @@ protected:
int m_lastSyncHash;
};
#endif /* LIB_MANAGER_ADAPTER_H */
#endif /* SYMBOL_TREE_SYNCHRONIZING_ADAPTER_H */

View File

@ -38,7 +38,7 @@
#include <class_library.h>
#include <dialog_helpers.h>
#include <dialog_choose_component.h>
#include <cmp_tree_model_adapter.h>
#include <symbol_tree_model_adapter.h>
#include <symbol_lib_table.h>
void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
@ -52,15 +52,15 @@ void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
return;
// Container doing search-as-you-type.
auto adapter( CMP_TREE_MODEL_ADAPTER::Create( libs ) );
auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( libs ) );
auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
const auto libNicknames = libs->GetLogicalLibs();
adapter->AddLibrariesWithProgress( libNicknames, this );
adapter->AddLibraries( libNicknames, this );
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ),
adapter->GetComponentsCount() );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, m_convert, false, false );
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false );
if( dlg.ShowQuasiModal() == wxID_CANCEL )
return;

View File

@ -22,9 +22,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "cmp_tree_pane.h"
#include "symbol_tree_pane.h"
#include <component_tree.h>
#include <widgets/lib_tree.h>
#include <eeschema_id.h>
#include <lib_manager.h>
#include <lib_edit_frame.h>
@ -32,14 +32,14 @@
#include <menus_helpers.h>
CMP_TREE_PANE::CMP_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr )
SYMBOL_TREE_PANE::SYMBOL_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr )
: wxPanel( aParent ),
m_libEditFrame( aParent ), m_tree( nullptr ), m_libMgr( aLibMgr )
{
// Create widgets
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
m_tree = new COMPONENT_TREE( this, &SYMBOL_LIB_TABLE::GetGlobalLibTable(),
m_libMgr->GetAdapter(), COMPONENT_TREE::SEARCH );
m_tree = new LIB_TREE( this, &SYMBOL_LIB_TABLE::GetGlobalLibTable(),
m_libMgr->GetAdapter(), LIB_TREE::SEARCH );
boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
@ -93,29 +93,29 @@ CMP_TREE_PANE::CMP_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr )
AddMenuItem( menuNoSelection.get(), ID_LIBEDIT_ADD_LIBRARY, _( "&Add Library..." ),
KiBitmap( add_library_xpm ) );
m_tree->SetMenu( CMP_TREE_NODE::LIBID, std::move( menuPart ) );
m_tree->SetMenu( CMP_TREE_NODE::LIB, std::move( menuLibrary ) );
m_tree->SetMenu( CMP_TREE_NODE::INVALID, std::move( menuNoSelection ) );
m_tree->SetMenu( LIB_TREE_NODE::LIBID, std::move( menuPart ) );
m_tree->SetMenu( LIB_TREE_NODE::LIB, std::move( menuLibrary ) );
m_tree->SetMenu( LIB_TREE_NODE::INVALID, std::move( menuNoSelection ) );
// Event handlers
Bind( COMPONENT_SELECTED, &CMP_TREE_PANE::onComponentSelected, this );
Bind( COMPONENT_SELECTED, &SYMBOL_TREE_PANE::onComponentSelected, this );
}
CMP_TREE_PANE::~CMP_TREE_PANE()
SYMBOL_TREE_PANE::~SYMBOL_TREE_PANE()
{
m_tree->Destroy();
}
void CMP_TREE_PANE::Regenerate()
void SYMBOL_TREE_PANE::Regenerate()
{
if( m_tree )
m_tree->Regenerate();
}
void CMP_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent )
void SYMBOL_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent )
{
// Repost the event
wxCommandEvent evt( ID_LIBEDIT_EDIT_PART );

View File

@ -29,7 +29,7 @@
#include <wx/dataview.h>
#include <vector>
class COMPONENT_TREE;
class LIB_TREE;
class LIB_EDIT_FRAME;
class LIB_MANAGER;
class wxBoxSizer;
@ -37,13 +37,13 @@ class wxBoxSizer;
/**
* Library Editor pane with component tree and symbol library table selector.
*/
class CMP_TREE_PANE : public wxPanel
class SYMBOL_TREE_PANE : public wxPanel
{
public:
CMP_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr );
~CMP_TREE_PANE();
SYMBOL_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr );
~SYMBOL_TREE_PANE();
COMPONENT_TREE* GetCmpTree() const
LIB_TREE* GetLibTree() const
{
return m_tree;
}
@ -55,7 +55,7 @@ protected:
void onComponentSelected( wxCommandEvent& aEvent );
LIB_EDIT_FRAME* m_libEditFrame;
COMPONENT_TREE* m_tree; ///< component search tree widget
LIB_TREE* m_tree; ///< component search tree widget
LIB_MANAGER* m_libMgr;
};

View File

@ -180,6 +180,16 @@ protected:
void CommonSettingsChanged() override;
/**
* Function LibraryFileBrowser
* @param doOpen if true runs an Open Library browser, otherwise New Library
* @param aFilename for New may contain a default name; in both cases return the chosen
* filename.
* @return true for OK; false for Cancel.
*/
bool LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
const wxString& wildcard, const wxString& ext );
/**
* Function GeneralControlKeyMovement
* Handle the common part of GeneralControl dedicated to global

66
include/lib_tree_item.h Normal file
View File

@ -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