← Back to team overview

kicad-developers team mailing list archive

Re: [eeschema] Names/descriptions for units

 

I have a prototype implementation of this now - descriptions are
currently taken from fields _UNITDESC_A, _UNITDESC_B etc. The unit
descriptions show up when browsing parts in the add dialog, and in the
dropdown menu when selecting units in the symbol editor. There is no GUI
for setting unit names yet - for the moment you have to add them as
normal fields. Patch is attached. All feedback very welcome.

Kliment

On 22.03.19 21:56, Kliment (Future Bits) wrote:
> I don't quite follow - what I'm proposing doesn't require any file
> format changes, I was planning to just use the existing field functionality.
> 
> If you want to bake it into the format instead, I'm 100% okay with that,
> but I don't think it's necessary. I'll look into implementing the UI
> functionality and defer to you on how/where to store the data.
> 
> On 22.03.19 21:45, Wayne Stambaugh wrote:
>> Hi Kliment
>>
>> This cannot happen until the new symbol library file format is
>> implemented.  There is a freeze (except for the new bus expansion
>> changes) on the current file format.  I will add a unit description
>> field for units in the new file format this way you can add a unique
>> description for each unit should you desire.
>>
>> Cheers,
>>
>> Wayne
>>
>> On 3/22/19 4:38 AM, Kliment (Future Bits) wrote:
>>> Hey,
>>>
>>> I'm working with a part that has a very large number of
>>> non-interchangeable units, each with many pins. For a part like this,
>>> it's very difficult to tell which unit is which from the preview. Parts
>>> have a description field that is shown in the list, but units don't. For
>>> parts with non-interchangeable units, I think a description like that
>>> would be very useful. I'd be interested in implementing such a thing.
>>> One way I can think of of doing this would be as follows:
>>>
>>> UI changes:
>>> 1. minor change to add part/component selection dialog - use the space
>>> to the right of "Unit A" etc to show description, add description to the
>>> space after the RD in the bottom part of the dialog
>>>
>>> 2. change to symbol editor - display unit description after "Unit A" in
>>> unit dropdown
>>>
>>> optionally, 3. make unit dropdown editable, make changes there save to
>>> unit name
>>>
>>> I would propose storing the descriptions in fields with special names of
>>> the form UNITDESC_A, _B etc. This requires no change to the existing
>>> data model.
>>>
>>> I'd like some feedback on a) whether this is a good idea, b) whether I'm
>>> stepping on anyone's toes if I do it and c) what branch should I base it off
>>>
>>> Thanks!
>>>
>>> Kliment
>>>
>>> _______________________________________________
>>> Mailing list: https://launchpad.net/~kicad-developers
>>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>>> Unsubscribe : https://launchpad.net/~kicad-developers
>>> More help   : https://help.launchpad.net/ListHelp
>>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>>
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 

From f8432c1eb96eef566254f5e6006060d09022444c Mon Sep 17 00:00:00 2001
From: Kliment Yanev <kliment.yanev@xxxxxxxxx>
Date: Sun, 24 Mar 2019 00:23:00 +0100
Subject: [PATCH] Add unit label functionality If a part has _UNITDESC_A,
 _UNITDESC_B etc fields their values will be shown as the unit description in
 the part selection dialog and the unit selection dropdown

---
 common/lib_tree_model.cpp           |  3 +--
 eeschema/class_libentry.cpp         | 17 +++++++++++++++++
 eeschema/class_libentry.h           | 11 +++++++++++
 eeschema/libedit/lib_edit_frame.cpp |  2 +-
 include/lib_tree_item.h             |  1 +
 5 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/common/lib_tree_model.cpp b/common/lib_tree_model.cpp
index 71fe74c7d..dbee70166 100644
--- a/common/lib_tree_model.cpp
+++ b/common/lib_tree_model.cpp
@@ -129,7 +129,6 @@ LIB_TREE_NODE_UNIT::LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* a
 {
     static void* locale = nullptr;
     static wxString namePrefix;
-
     // Fetching translations can take a surprising amount of time when loading libraries,
     // so only do it when necessary.
     if( Pgm().GetLocale() != locale )
@@ -145,7 +144,7 @@ LIB_TREE_NODE_UNIT::LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* a
     LibId = aParent->LibId;
 
     Name = namePrefix + " " + aItem->GetUnitReference( aUnit );
-    Desc = wxEmptyString;
+    Desc = aItem->GetUnitDescription( aUnit );
     MatchName = wxEmptyString;
 
     IntrinsicRank = -aUnit;
diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp
index 0a96f849d..cb422ddd6 100644
--- a/eeschema/class_libentry.cpp
+++ b/eeschema/class_libentry.cpp
@@ -146,6 +146,11 @@ wxString LIB_ALIAS::GetUnitReference( int aUnit )
     return LIB_PART::SubReference( aUnit, false );
 }
 
+wxString LIB_ALIAS::GetUnitDescription( int aUnit )
+{
+    return shared->GetUnitDescription(aUnit);
+}
+
 
 const EDA_RECT LIB_ALIAS::GetBoundingBox() const
 {
@@ -341,6 +346,18 @@ wxString LIB_PART::SubReference( int aUnit, bool aAddSeparator )
     return subRef;
 }
 
+wxString LIB_PART::GetUnitDescription( int aUnit )
+{
+    wxString fieldid="_UNITDESC_";
+    fieldid<<LIB_PART::SubReference(aUnit,false);
+    LIB_FIELD* descfield=FindField(fieldid);
+    if(descfield==NULL)
+    {
+        return wxEmptyString;
+    } else {
+        return descfield->GetFullText();
+    }
+}
 
 const wxString& LIB_PART::GetName() const
 {
diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h
index dcca4e029..c8da0523d 100644
--- a/eeschema/class_libentry.h
+++ b/eeschema/class_libentry.h
@@ -174,6 +174,11 @@ public:
      */
     wxString GetUnitReference( int aUnit ) override;
 
+    /**
+     * For symbols with units, return a unit description for unit x if available.
+     */
+    wxString GetUnitDescription( int aUnit ) override;
+
     /**
      * A temporary conversion (deMorgan) designation for rendering, preview, etc.
      */
@@ -668,6 +673,12 @@ public:
      */
     static wxString SubReference( int aUnit, bool aAddSeparator = true );
 
+     /**
+     * @return the description of this unit (if any)
+     * @param aUnit = the part identifier ( 1 to max count)
+     */
+    wxString GetUnitDescription( int aUnit);
+
     // Accessors to sub ref parameters
     static int GetSubpartIdSeparator() { return m_subpartIdSeparator; }
 
diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp
index 9a81b354e..a6936f29a 100644
--- a/eeschema/libedit/lib_edit_frame.cpp
+++ b/eeschema/libedit/lib_edit_frame.cpp
@@ -372,7 +372,7 @@ void LIB_EDIT_FRAME::UpdatePartSelectList()
         for( int i = 0; i < part->GetUnitCount(); i++ )
         {
             wxString sub  = LIB_PART::SubReference( i+1, false );
-            wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
+            wxString unit = wxString::Format( _( "Unit %s %s" ), GetChars( sub ), GetChars(part->GetUnitDescription(i+1)) );
             m_partSelectBox->Append( unit );
         }
     }
diff --git a/include/lib_tree_item.h b/include/lib_tree_item.h
index 5ad5ef4bd..6efd7f041 100644
--- a/include/lib_tree_item.h
+++ b/include/lib_tree_item.h
@@ -62,6 +62,7 @@ public:
      * For items with units, return an identifier for unit x.
      */
     virtual wxString GetUnitReference( int aUnit ) { return wxEmptyString; }
+    virtual wxString GetUnitDescription( int aUnit ) { return wxEmptyString; }
 };
 
 #endif //LIB_TREE_ITEM_H
-- 
2.17.1


Follow ups

References