Display more information in component selector

This commit is contained in:
Chris Pavlina 2017-02-05 14:18:29 -05:00
parent cdc392867a
commit bca74853d1
8 changed files with 104 additions and 70 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -167,6 +167,30 @@ std::string EscapedUTF8( const wxString& aString )
} }
wxString EscapedHTML( const wxString& aString )
{
wxString converted;
for( wxUniChar c: aString )
{
if( c == '\"' )
converted += """;
else if( c == '\'' )
converted += "'";
else if( c == '&' )
converted += "&";
else if( c == '<' )
converted += "&lt;";
else if( c == '>' )
converted += "&gt;";
else
converted += c;
}
return converted;
}
char* StrPurge( char* text ) char* StrPurge( char* text )
{ {
static const char whitespace[] = " \t\n\r\f\v"; static const char whitespace[] = " \t\n\r\f\v";

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org> * Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -29,6 +29,7 @@
#include <class_library.h> #include <class_library.h>
#include <component_tree_search_container.h> #include <component_tree_search_container.h>
#include <sch_base_frame.h> #include <sch_base_frame.h>
#include <kicad_string.h>
// Tree navigation helpers. // Tree navigation helpers.
static wxTreeItemId GetPrevItem( const wxTreeCtrl& tree, const wxTreeItemId& item ); static wxTreeItemId GetPrevItem( const wxTreeCtrl& tree, const wxTreeItemId& item );
@ -44,7 +45,6 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const
m_external_browser_requested = false; m_external_browser_requested = false;
m_received_doubleclick_in_tree = false; m_received_doubleclick_in_tree = false;
m_search_container->SetTree( m_libraryComponentTree ); m_search_container->SetTree( m_libraryComponentTree );
m_componentDetails->SetEditable( false );
m_componentView->SetLayoutDirection( wxLayout_LeftToRight ); m_componentView->SetLayoutDirection( wxLayout_LeftToRight );
m_libraryComponentTree->ScrollTo( m_libraryComponentTree->GetFocusedItem() ); m_libraryComponentTree->ScrollTo( m_libraryComponentTree->GetFocusedItem() );
@ -221,70 +221,83 @@ bool DIALOG_CHOOSE_COMPONENT::updateSelection()
m_componentView->Refresh(); m_componentView->Refresh();
m_componentDetails->Clear(); m_componentDetails->SetPage( wxEmptyString );
if( selection == NULL ) if( selection == NULL )
return false; return false;
m_componentDetails->Freeze(); m_componentDetails->Freeze();
wxFont font_normal = m_componentDetails->GetFont();
wxFont font_bold = m_componentDetails->GetFont();
font_bold.SetWeight( wxFONTWEIGHT_BOLD );
wxTextAttr headline_attribute;
headline_attribute.SetFont( font_bold );
wxTextAttr text_attribute;
text_attribute.SetFont( font_normal );
const wxString name = selection->GetName(); const wxString name = selection->GetName();
wxString description = selection->GetDescription();
if ( !name.empty() ) if ( !name.empty() )
{ {
m_componentDetails->SetDefaultStyle( headline_attribute ); m_componentDetails->AppendToPage( "<b>" );
m_componentDetails->AppendText( name ); m_componentDetails->AppendToPage( EscapedHTML( name ) );
m_componentDetails->AppendToPage( "</b>" );
} }
const wxString description = selection->GetDescription(); if( !selection->IsRoot() )
{
LIB_PART* root_part = selection->GetPart();
const wxString root_name( root_part ? root_part->GetName() : _( "Unknown" ) );
m_componentDetails->AppendToPage(
"<br><i>" + _( "Alias of " ) + EscapedHTML( root_name ) + "</i>" );
// For some reason descriptions are a property of aliases, even though
// only the root component's main LIB_ALIAS can actually have a description.
// If the description was empty, go through the alias list and find an alias
// that actually has one.
if( description.empty() )
{
for( size_t i = 0; i < root_part->GetAliasCount(); ++i )
{
LIB_ALIAS* alias = root_part->GetAlias( i );
if( !alias )
continue;
description = alias->GetDescription();
if( !description.empty() )
break;
}
}
}
if( !description.empty() ) if( !description.empty() )
{ {
if ( !m_componentDetails->IsEmpty() ) m_componentDetails->AppendToPage( "<br>" );
m_componentDetails->AppendText( wxT( "\n\n" ) ); m_componentDetails->AppendToPage( EscapedHTML( description ) );
m_componentDetails->SetDefaultStyle( headline_attribute );
m_componentDetails->AppendText( _( "Description\n" ) );
m_componentDetails->SetDefaultStyle( text_attribute );
m_componentDetails->AppendText( description );
} }
const wxString keywords = selection->GetKeyWords(); wxString keywords = selection->GetKeyWords();
if( !keywords.empty() ) if( !keywords.empty() )
{ {
if ( !m_componentDetails->IsEmpty() ) m_componentDetails->AppendToPage( "<br>" + _( "Keywords:" ) + " " );
m_componentDetails->AppendText( wxT( "\n\n" ) ); m_componentDetails->AppendToPage( EscapedHTML( keywords ) );
m_componentDetails->SetDefaultStyle( headline_attribute );
m_componentDetails->AppendText( _( "Keywords\n" ) );
m_componentDetails->SetDefaultStyle( text_attribute );
m_componentDetails->AppendText( keywords );
} }
if ( !selection->IsRoot() ) m_componentDetails->AppendToPage( "<hr><table border=0>" );
LIB_FIELDS fields;
selection->GetPart()->GetFields( fields );
for( auto const & field: fields )
{ {
LIB_PART* root_part = selection->GetPart(); wxString name = field.GetName();
const wxString root_component_name( root_part ? root_part->GetName() : _( "Unknown" ) ); wxString text = field.GetFullText();
if ( !m_componentDetails->IsEmpty() ) m_componentDetails->AppendToPage( "<tr><td><b>" + EscapedHTML( name ) + "</b></td>" );
m_componentDetails->AppendText( wxT( "\n\n" ) ); m_componentDetails->AppendToPage( "<td>" + EscapedHTML( text ) + "</td></tr>" );
m_componentDetails->SetDefaultStyle( headline_attribute );
m_componentDetails->AppendText( _( "Alias of " ) );
m_componentDetails->SetDefaultStyle( text_attribute );
m_componentDetails->AppendText( root_component_name );
} }
m_componentDetails->SetInsertionPoint( 0 ); // scroll up. m_componentDetails->AppendToPage( "</table>" );
m_componentDetails->Thaw(); m_componentDetails->Thaw();
return true; return true;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jan 15 2017) // C++ code generated with wxFormBuilder (version Jan 5 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -40,12 +40,10 @@ DIALOG_CHOOSE_COMPONENT_BASE::DIALOG_CHOOSE_COMPONENT_BASE( wxWindow* parent, wx
m_componentView = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER ); m_componentView = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER );
m_componentView->SetMinSize( wxSize( 200,200 ) ); m_componentView->SetMinSize( wxSize( 200,200 ) );
bSizerView->Add( m_componentView, 4, wxEXPAND | wxALL, 5 ); bSizerView->Add( m_componentView, 1, wxEXPAND | wxALL, 5 );
m_componentDetails = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( -1,-1 ), wxTE_MULTILINE ); m_componentDetails = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO );
m_componentDetails->SetMinSize( wxSize( 200,200 ) ); bSizerView->Add( m_componentDetails, 1, wxALL|wxEXPAND, 5 );
bSizerView->Add( m_componentDetails, 3, wxALL|wxEXPAND, 5 );
bSizerMain->Add( bSizerView, 1, wxEXPAND, 5 ); bSizerMain->Add( bSizerView, 1, wxEXPAND, 5 );

View File

@ -392,7 +392,7 @@
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property> <property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">4</property> <property name="proportion">1</property>
<object class="wxPanel" expanded="1"> <object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>
<property name="LeftDockable">1</property> <property name="LeftDockable">1</property>
@ -469,11 +469,11 @@
<event name="OnUpdateUI"></event> <event name="OnUpdateUI"></event>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="0"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property> <property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">3</property> <property name="proportion">1</property>
<object class="wxTextCtrl" expanded="0"> <object class="wxHtmlWindow" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>
<property name="LeftDockable">1</property> <property name="LeftDockable">1</property>
<property name="RightDockable">1</property> <property name="RightDockable">1</property>
@ -504,10 +504,9 @@
<property name="max_size"></property> <property name="max_size"></property>
<property name="maximize_button">0</property> <property name="maximize_button">0</property>
<property name="maximum_size"></property> <property name="maximum_size"></property>
<property name="maxlength"></property>
<property name="min_size"></property> <property name="min_size"></property>
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size">200,200</property> <property name="minimum_size"></property>
<property name="moveable">1</property> <property name="moveable">1</property>
<property name="name">m_componentDetails</property> <property name="name">m_componentDetails</property>
<property name="pane_border">1</property> <property name="pane_border">1</property>
@ -518,22 +517,20 @@
<property name="pos"></property> <property name="pos"></property>
<property name="resize">Resizable</property> <property name="resize">Resizable</property>
<property name="show">1</property> <property name="show">1</property>
<property name="size">-1,-1</property> <property name="size"></property>
<property name="style">wxTE_MULTILINE</property> <property name="style">wxHW_SCROLLBAR_AUTO</property>
<property name="subclass"></property> <property name="subclass"></property>
<property name="toolbar_pane">0</property> <property name="toolbar_pane">0</property>
<property name="tooltip"></property> <property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
<event name="OnChar"></event> <event name="OnChar"></event>
<event name="OnEnterWindow"></event> <event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event> <event name="OnEraseBackground"></event>
<event name="OnHtmlCellClicked"></event>
<event name="OnHtmlCellHover"></event>
<event name="OnHtmlLinkClicked"></event>
<event name="OnKeyDown"></event> <event name="OnKeyDown"></event>
<event name="OnKeyUp"></event> <event name="OnKeyUp"></event>
<event name="OnKillFocus"></event> <event name="OnKillFocus"></event>
@ -553,10 +550,6 @@
<event name="OnRightUp"></event> <event name="OnRightUp"></event>
<event name="OnSetFocus"></event> <event name="OnSetFocus"></event>
<event name="OnSize"></event> <event name="OnSize"></event>
<event name="OnText"></event>
<event name="OnTextEnter"></event>
<event name="OnTextMaxLen"></event>
<event name="OnTextURL"></event>
<event name="OnUpdateUI"></event> <event name="OnUpdateUI"></event>
</object> </object>
</object> </object>

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jan 15 2017) // C++ code generated with wxFormBuilder (version Jan 5 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -24,6 +24,7 @@ class DIALOG_SHIM;
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/treectrl.h> #include <wx/treectrl.h>
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/html/htmlwin.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/dialog.h> #include <wx/dialog.h>
@ -42,7 +43,7 @@ class DIALOG_CHOOSE_COMPONENT_BASE : public DIALOG_SHIM
wxTextCtrl* m_searchBox; wxTextCtrl* m_searchBox;
wxTreeCtrl* m_libraryComponentTree; wxTreeCtrl* m_libraryComponentTree;
wxPanel* m_componentView; wxPanel* m_componentView;
wxTextCtrl* m_componentDetails; wxHtmlWindow* m_componentDetails;
wxStdDialogButtonSizer* m_stdButtons; wxStdDialogButtonSizer* m_stdButtons;
wxButton* m_stdButtonsOK; wxButton* m_stdButtonsOK;
wxButton* m_stdButtonsCancel; wxButton* m_stdButtonsCancel;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -528,7 +528,7 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
} }
wxString LIB_FIELD::GetFullText( int unit ) wxString LIB_FIELD::GetFullText( int unit ) const
{ {
if( m_id != REFERENCE ) if( m_id != REFERENCE )
return GetText(); return GetText();

View File

@ -189,7 +189,7 @@ public:
* @param unit - The package unit number. Only effects reference field. * @param unit - The package unit number. Only effects reference field.
* @return Field text. * @return Field text.
*/ */
wxString GetFullText( int unit = 1 ); wxString GetFullText( int unit = 1 ) const;
EDA_COLOR_T GetDefaultColor() override; EDA_COLOR_T GetDefaultColor() override;

View File

@ -73,6 +73,11 @@ int ReadDelimitedText( wxString* aDest, const char* aSource );
*/ */
std::string EscapedUTF8( const wxString& aString ); std::string EscapedUTF8( const wxString& aString );
/**
* Return a new wxString escaped for embedding in HTML.
*/
wxString EscapedHTML( const wxString& aString );
/** /**
* Function GetLine * Function GetLine
* reads one line line from \a aFile. * reads one line line from \a aFile.