← Back to team overview

kicad-developers team mailing list archive

[PATCH] Minor tweaks for the eeschema component chooser, especially for aliases.

 

Hello,

Attached is a small patch that does a few things in the eeschema component      chooser:

   * Shows aliases' names, rather than the root device names in the 
     preview window
   * Doesn't paint the background if nothing is selected
   * Add the component name as a heading in the description panel
   * Add an "Alias of" field in the description panel, if the component 
     is an alias

For the insertion of the alias name over the root name, I used the same method
as found in viewlibs.cpp:257 and elsewhere, where the name is replaced and then
reverted after drawing.

Thanks,

John
---
 eeschema/dialogs/dialog_choose_component.cpp | 59 +++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 5 deletions(-)

diff --git a/eeschema/dialogs/dialog_choose_component.cpp b/eeschema/dialogs/dialog_choose_component.cpp
index 9352c94..9b00652 100644
--- a/eeschema/dialogs/dialog_choose_component.cpp
+++ b/eeschema/dialogs/dialog_choose_component.cpp
@@ -114,7 +114,7 @@ void DIALOG_CHOOSE_COMPONENT::OnInterceptSearchBoxKey( wxKeyEvent& aKeyStroke )
         selectIfValid( GetNextItem( *m_libraryComponentTree, sel ) );
         break;

-        // The follwoing keys we can only hijack if they are not needed by the textbox itself.
+        // The following keys we can only hijack if they are not needed by the textbox itself.

     case WXK_LEFT:
         if( m_searchBox->GetInsertionPoint() == 0 )
@@ -219,27 +219,55 @@ bool DIALOG_CHOOSE_COMPONENT::updateSelection()
     wxTextAttr text_attribute;
     text_attribute.SetFont(font_normal);

+    const wxString name = selection->GetName();
+
+    if ( !name.empty() )
+    {
+        m_componentDetails->SetDefaultStyle( headline_attribute );
+        m_componentDetails->AppendText( name );
+    }
+
     const wxString description = selection->GetDescription();

     if( !description.empty() )
     {
+        if ( !m_componentDetails->IsEmpty() )
+            m_componentDetails->AppendText( wxT("\n\n") );
+
         m_componentDetails->SetDefaultStyle( headline_attribute );
         m_componentDetails->AppendText( _("Description\n") );
         m_componentDetails->SetDefaultStyle( text_attribute );
         m_componentDetails->AppendText( description );
-        m_componentDetails->AppendText( wxT("\n\n") );
     }

     const wxString keywords = selection->GetKeyWords();

     if( !keywords.empty() )
     {
+        if ( !m_componentDetails->IsEmpty() )
+            m_componentDetails->AppendText( wxT("\n\n") );
+
         m_componentDetails->SetDefaultStyle( headline_attribute );
         m_componentDetails->AppendText( _("Keywords\n") );
         m_componentDetails->SetDefaultStyle( text_attribute );
         m_componentDetails->AppendText( keywords );
     }

+    if ( !selection->IsRoot() )
+    {
+        LIB_PART* root_part = selection->GetPart();
+        const wxString root_component_name( root_part ?
+                root_part->GetName() : _("Unknown") );
+
+        if ( !m_componentDetails->IsEmpty() )
+            m_componentDetails->AppendText( wxT("\n\n") );
+
+        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->Thaw();

@@ -250,18 +278,39 @@ bool DIALOG_CHOOSE_COMPONENT::updateSelection()
 void DIALOG_CHOOSE_COMPONENT::OnHandlePreviewRepaint( wxPaintEvent& aRepaintEvent )
 {
     int unit = 0;
-    LIB_ALIAS* selection = m_search_container->GetSelectedAlias( &unit );
+    LIB_ALIAS*  selection = m_search_container->GetSelectedAlias( &unit );
+    LIB_PART*   part = selection ? selection->GetPart() : NULL;
+
+    // Don't draw anything (not even the background) if we don't have
+    // a part to show
+    if( !part )
+        return;
+
+    if( selection->IsRoot() )
+    {
+        // just show the part directly
+        renderPreview( part, unit );
+    }
+    else
+    {
+        // switch out the name temporarily for the alias name
+        wxString tmp( part->GetName() );
+        part->SetName( selection->GetName() );

-    renderPreview( selection ? selection->GetPart() : NULL, unit );
+        renderPreview( part, unit );
+
+        part->SetName( tmp );
+    }
 }


 // Render the preview in our m_componentView. If this gets more complicated, we should
 // probably have a derived class from wxPanel; but this keeps things local.
-void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_PART*      aComponent, int aUnit )
+void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_PART* aComponent, int aUnit )
 {
     wxPaintDC dc( m_componentView );
     EDA_COLOR_T bgcolor = m_parent->GetDrawBgColor();
+
     dc.SetBackground( bgcolor == BLACK ? *wxBLACK_BRUSH : *wxWHITE_BRUSH );
     dc.Clear();

--
1.8.3.2



Follow ups