From 561c01803575190097c777b1c5428c8a0e822595 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Mar 2015 11:26:07 +0100 Subject: [PATCH] Add pin table dialog --- bitmaps_png/CMakeLists.txt | 1 + bitmaps_png/cpp_26/pin_table.cpp | 38 ++ bitmaps_png/sources/pin_table.svg | 195 ++++++ eeschema/CMakeLists.txt | 2 + .../dialogs/dialog_lib_edit_pin_table.cpp | 563 ++++++++++++++++++ eeschema/dialogs/dialog_lib_edit_pin_table.h | 18 + .../dialog_lib_edit_pin_table_base.cpp | 46 ++ .../dialog_lib_edit_pin_table_base.fbp | 193 ++++++ .../dialogs/dialog_lib_edit_pin_table_base.h | 53 ++ eeschema/eeschema_id.h | 1 + eeschema/lib_pin.h | 3 + eeschema/libeditframe.cpp | 19 + eeschema/libeditframe.h | 3 + eeschema/tool_lib.cpp | 2 + include/bitmaps.h | 1 + 15 files changed, 1138 insertions(+) create mode 100644 bitmaps_png/cpp_26/pin_table.cpp create mode 100644 bitmaps_png/sources/pin_table.svg create mode 100644 eeschema/dialogs/dialog_lib_edit_pin_table.cpp create mode 100644 eeschema/dialogs/dialog_lib_edit_pin_table.h create mode 100644 eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp create mode 100644 eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp create mode 100644 eeschema/dialogs/dialog_lib_edit_pin_table_base.h diff --git a/bitmaps_png/CMakeLists.txt b/bitmaps_png/CMakeLists.txt index 78a5241946..04cf7e2ff4 100644 --- a/bitmaps_png/CMakeLists.txt +++ b/bitmaps_png/CMakeLists.txt @@ -446,6 +446,7 @@ set( BMAPS_MID pin_name_to pin_number_to pin_size_to + pin_table pin_to pin plot diff --git a/bitmaps_png/cpp_26/pin_table.cpp b/bitmaps_png/cpp_26/pin_table.cpp new file mode 100644 index 0000000000..a78967df85 --- /dev/null +++ b/bitmaps_png/cpp_26/pin_table.cpp @@ -0,0 +1,38 @@ + +/* Do not modify this file, it was automatically generated by the + * PNG2cpp CMake script, using a *.png file as input. + */ + +#include + +static const unsigned char png[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x1a, 0x08, 0x06, 0x00, 0x00, 0x00, 0xa9, 0x4a, 0x4c, + 0xce, 0x00, 0x00, 0x01, 0x53, 0x49, 0x44, 0x41, 0x54, 0x48, 0xc7, 0xed, 0x96, 0x31, 0x4b, 0xc3, + 0x40, 0x14, 0xc7, 0xff, 0x54, 0x04, 0x33, 0x69, 0x05, 0xa5, 0x83, 0x83, 0xb8, 0x09, 0x99, 0xeb, + 0x54, 0x1a, 0x45, 0x0a, 0x82, 0xa3, 0x7e, 0x86, 0x8a, 0x4b, 0x71, 0x71, 0x11, 0xaa, 0xe2, 0xa0, + 0x43, 0x70, 0x71, 0x74, 0xe9, 0x28, 0x7e, 0x0a, 0xf1, 0x13, 0xc4, 0xcf, 0xe0, 0xe8, 0x66, 0x45, + 0xa1, 0xb4, 0x3d, 0xef, 0x1f, 0xee, 0xe0, 0x88, 0x25, 0xbe, 0x23, 0x35, 0x3a, 0x18, 0xf8, 0x25, + 0x8f, 0x24, 0xe4, 0x97, 0x7b, 0xf7, 0xde, 0x25, 0x50, 0x4a, 0xa1, 0x0c, 0xbe, 0x9c, 0xb8, 0x07, + 0x66, 0x2e, 0x80, 0x75, 0xc2, 0x78, 0xea, 0xa2, 0x6b, 0x20, 0x38, 0x03, 0x62, 0x4d, 0x5f, 0xa3, + 0x0c, 0x8c, 0x63, 0x5e, 0x9b, 0x8a, 0xc8, 0x48, 0x12, 0x47, 0x90, 0x25, 0x29, 0x2a, 0x4b, 0x77, + 0x66, 0x24, 0xe9, 0x43, 0x6f, 0xeb, 0x75, 0x95, 0xf4, 0x7a, 0x29, 0x8c, 0x1d, 0x59, 0x5c, 0x48, + 0xc4, 0x79, 0xb0, 0xe9, 0xe2, 0x83, 0x47, 0x83, 0x81, 0xb2, 0x1b, 0x63, 0x47, 0xf6, 0x76, 0x0e, + 0x6c, 0xe9, 0x63, 0xe4, 0xc9, 0x4a, 0x2a, 0xe2, 0xa4, 0xdb, 0xb7, 0xe6, 0x28, 0xb2, 0x1b, 0xcf, + 0xe5, 0xa4, 0x54, 0xc2, 0x8b, 0x66, 0xb9, 0x0c, 0xd1, 0xeb, 0x15, 0x30, 0x2f, 0x4e, 0xdd, 0x89, + 0x66, 0x0d, 0x18, 0xad, 0x7a, 0xb0, 0x03, 0x74, 0x2e, 0x81, 0xaa, 0x57, 0x31, 0x1c, 0x02, 0x77, + 0x00, 0x9a, 0x02, 0x3a, 0x9a, 0xa1, 0xa1, 0xe9, 0x55, 0xde, 0xc7, 0x41, 0xd0, 0xdf, 0x6e, 0x34, + 0x1e, 0xa3, 0x28, 0x7a, 0xf8, 0x0e, 0x23, 0x9b, 0x2c, 0x72, 0x1b, 0xb6, 0x0b, 0xbc, 0x5b, 0x01, + 0xe3, 0x76, 0xad, 0xf6, 0x2c, 0x95, 0x88, 0x44, 0x96, 0x39, 0x60, 0x73, 0x49, 0xdf, 0x44, 0x18, + 0x4b, 0x05, 0x7f, 0x4f, 0x54, 0x4a, 0xea, 0x4a, 0x2b, 0x06, 0x49, 0x79, 0x73, 0x64, 0x85, 0x44, + 0xd2, 0x86, 0x3d, 0xad, 0x54, 0x86, 0xfb, 0x61, 0xf8, 0xb4, 0x17, 0x86, 0x49, 0x1e, 0x6c, 0x52, + 0xb7, 0x61, 0xff, 0xd7, 0x3a, 0x56, 0xe0, 0xc7, 0x2e, 0x70, 0xc4, 0x74, 0xe4, 0xb1, 0x01, 0xdc, + 0x14, 0x5a, 0xeb, 0x5a, 0xc0, 0xd8, 0x99, 0x64, 0x29, 0x7e, 0xe5, 0x7d, 0xa0, 0x25, 0xb3, 0xfe, + 0x92, 0xfc, 0x86, 0xe5, 0x97, 0xd4, 0x6d, 0x58, 0xae, 0xda, 0x8b, 0x40, 0x4b, 0xb8, 0x72, 0x67, + 0x59, 0xf8, 0xbd, 0xdf, 0xad, 0x9f, 0xe6, 0x13, 0xee, 0x33, 0xf3, 0x74, 0xce, 0xbb, 0x6e, 0x19, + 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, +}; + +const BITMAP_OPAQUE pin_table_xpm[1] = {{ png, sizeof( png ), "pin_table_xpm" }}; + +//EOF diff --git a/bitmaps_png/sources/pin_table.svg b/bitmaps_png/sources/pin_table.svg new file mode 100644 index 0000000000..b0ed841c25 --- /dev/null +++ b/bitmaps_png/sources/pin_table.svg @@ -0,0 +1,195 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 3441899bf7..700007faff 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -53,6 +53,8 @@ set( EESCHEMA_DLGS dialogs/dialog_libedit_options.cpp dialogs/dialog_lib_edit_pin.cpp dialogs/dialog_lib_edit_pin_base.cpp + dialogs/dialog_lib_edit_pin_table.cpp + dialogs/dialog_lib_edit_pin_table_base.cpp dialogs/dialog_lib_new_component.cpp dialogs/dialog_lib_new_component_base.cpp dialogs/dialog_netlist.cpp diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp new file mode 100644 index 0000000000..4ba45eb1d3 --- /dev/null +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -0,0 +1,563 @@ +#include "dialog_lib_edit_pin_table.h" + +#include "lib_pin.h" + +#include +#include + +/* Avoid wxWidgets bug #16906 -- http://trac.wxwidgets.org/ticket/16906 + * + * If multiple elements live in the root of a wxDataViewCtrl, using + * ItemsAdded() can run into an assertion failure. To avoid this, we avoid + * notifying the widget of changes, but rather reinitialize it. + * + * When a fix for this exists in wxWidgets, this is the place to turn it + * off. + */ +#define REASSOCIATE_HACK + +class DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel : + public wxDataViewModel +{ +public: + DataViewModel( LIB_PART& aPart ); + + // wxDataViewModel + virtual unsigned int GetColumnCount() const; + virtual wxString GetColumnType( unsigned int col ) const; + virtual void GetValue( wxVariant&, const wxDataViewItem&, unsigned int ) const; + virtual bool SetValue( const wxVariant&, const wxDataViewItem&, unsigned int ); + virtual wxDataViewItem GetParent( const wxDataViewItem& ) const; + virtual bool IsContainer( const wxDataViewItem& ) const; + virtual bool HasContainerColumns( const wxDataViewItem& ) const; + virtual unsigned int GetChildren( const wxDataViewItem&, wxDataViewItemArray& ) const; + + virtual int Compare( const wxDataViewItem& lhs, + const wxDataViewItem& rhs, + unsigned int col, + bool ascending ) const; + + void SetGroupingColumn( int aCol ); + void CalculateGrouping(); + void Refresh(); + +#ifdef REASSOCIATE_HACK + void SetWidget( wxDataViewCtrl* aWidget ) { m_Widget = aWidget; } +#endif + + enum + { + NONE = -1, + PIN_NUMBER = 0, + PIN_NAME = 1, + PIN_TYPE = 2 + }; + +private: + LIB_PART& m_Part; + LIB_PINS m_Backing; + int m_GroupingColumn; + int m_UnitCount; + + class Item; + class Group; + class Pin; + + mutable std::list m_Pins; + mutable std::map m_Groups; + +#ifdef REASSOCIATE_HACK + wxDataViewCtrl* m_Widget; +#endif +}; + +class DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Item +{ +public: + virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const = 0; + virtual wxDataViewItem GetParent() const = 0; + virtual bool IsContainer() const = 0; + virtual unsigned int GetChildren( wxDataViewItemArray& ) const = 0; +}; + +class DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group : + public Item +{ +public: + Group( unsigned int aGroupingColumn ) : m_GroupingColumn( aGroupingColumn ) {} + + virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const; + + virtual wxDataViewItem GetParent() const { return wxDataViewItem(); } + virtual bool IsContainer() const { return true; } + virtual unsigned int GetChildren( wxDataViewItemArray& aItems ) const + { + /// @todo C++11 + for( std::list::const_iterator i = m_Members.begin(); i != m_Members.end(); ++i ) + aItems.push_back( wxDataViewItem( *i ) ); + + return aItems.size(); + } + + unsigned int GetCount() const { return m_Members.size(); } + void Add( Pin* aPin ); + +private: + std::list m_Members; + unsigned int m_GroupingColumn; +}; + +class DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin : + public Item +{ +public: + Pin( DataViewModel& aModel, + LIB_PIN* aBacking ) : m_Model( aModel ), m_Backing( aBacking ), m_Group( 0 ) {} + + virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const; + + virtual wxDataViewItem GetParent() const { return wxDataViewItem( m_Group ); } + virtual bool IsContainer() const { return false; } + virtual unsigned int GetChildren( wxDataViewItemArray& ) const { return 0; } + + void SetGroup( Group* aGroup ) { m_Group = aGroup; } + +private: + DataViewModel& m_Model; + LIB_PIN* m_Backing; + Group* m_Group; +}; + +DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( wxWindow* parent, + LIB_PART& aPart ) : + DIALOG_LIB_EDIT_PIN_TABLE_BASE( parent ), + m_Model( new DataViewModel( aPart ) ) +{ +#ifdef REASSOCIATE_HACK + m_Model->SetWidget( m_Pins ); +#endif + m_Pins->AssociateModel( m_Model.get() ); + + /// @todo wxFormBuilder bug #61 -- move to base once supported + wxDataViewTextRenderer* rend0 = new wxDataViewTextRenderer( wxT( "string" ), wxDATAVIEW_CELL_INERT ); + wxDataViewColumn* col0 = new wxDataViewColumn( _( "Number" ), + rend0, + DataViewModel::PIN_NUMBER, + 100, + wxAlignment( wxALIGN_LEFT | wxALIGN_TOP ), + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE ); + wxDataViewTextRenderer* rend1 = new wxDataViewTextRenderer( wxT( "string" ), wxDATAVIEW_CELL_INERT ); + wxDataViewColumn* col1 = new wxDataViewColumn( _( "Name" ), + rend1, + DataViewModel::PIN_NAME, + 100, + wxAlignment( wxALIGN_LEFT | wxALIGN_TOP ), + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE ); + wxDataViewTextRenderer* rend2 = new wxDataViewTextRenderer( wxT( "string" ), wxDATAVIEW_CELL_INERT ); + wxDataViewColumn* col2 = new wxDataViewColumn( _( "Type" ), + rend2, + DataViewModel::PIN_TYPE, + 100, + wxAlignment( wxALIGN_LEFT | wxALIGN_TOP ), + wxDATAVIEW_COL_RESIZABLE ); + m_Pins->AppendColumn( col0 ); + m_Pins->SetExpanderColumn( col0 ); + m_Pins->AppendColumn( col1 ); + m_Pins->AppendColumn( col2 ); + + GetSizer()->SetSizeHints(this); + Centre(); +} + + +DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE() +{ +} + + +void DIALOG_LIB_EDIT_PIN_TABLE::OnColumnHeaderRightClicked( wxDataViewEvent& event ) +{ + m_Model->SetGroupingColumn( event.GetDataViewColumn()->GetModelColumn() ); + event.Skip(); +} + + +DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::DataViewModel( LIB_PART& aPart ) : + m_Part( aPart ), + m_GroupingColumn( 1 ), + m_UnitCount( m_Part.GetUnitCount() ) +{ + aPart.GetPins( m_Backing ); + /// @todo C++11 + for( LIB_PINS::const_iterator i = m_Backing.begin(); i != m_Backing.end(); ++i ) + m_Pins.push_back( Pin( *this, *i ) ); + + CalculateGrouping(); +} + + +unsigned int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetColumnCount() const +{ + return 3; +} + + +wxString DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetColumnType( unsigned int aCol ) const +{ + return wxT( "string" ); +} + + +void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetValue( wxVariant& aVal, + const wxDataViewItem& aItem, + unsigned int aCol ) const +{ + assert( aItem.IsOk() ); + + reinterpret_cast( aItem.GetID() )->GetValue( aVal, aCol ); +} + + +bool DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::SetValue( const wxVariant&, + const wxDataViewItem&, + unsigned int ) +{ + return false; +} + + +wxDataViewItem DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetParent( const wxDataViewItem& aItem ) +const +{ + assert( aItem.IsOk() ); + + return reinterpret_cast( aItem.GetID() )->GetParent(); +} + + +bool DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::IsContainer( const wxDataViewItem& aItem ) const +{ + if( aItem.IsOk() ) + return reinterpret_cast( aItem.GetID() )->IsContainer(); + else + return true; +} + + +bool DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::HasContainerColumns( const wxDataViewItem& ) const +{ + return true; +} + + +unsigned int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetChildren( const wxDataViewItem& aItem, + wxDataViewItemArray& aItems ) const +{ + if( !aItem.IsOk() ) + { + for( std::map::iterator i = m_Groups.begin(); i != m_Groups.end(); ++i ) + if( i->second.GetCount() > 1 ) + aItems.push_back( wxDataViewItem( &i->second ) ); + + for( std::list::iterator i = m_Pins.begin(); i != m_Pins.end(); ++i ) + if( !i->GetParent().IsOk() ) + aItems.push_back( wxDataViewItem( &*i ) ); + + return aItems.size(); + } + else + return reinterpret_cast( aItem.GetID() )->GetChildren( aItems ); +} + + +namespace { +wxString GetNextComponent( const wxString& str, wxString::size_type& cursor ) +{ + if( str.size() <= cursor ) + return wxEmptyString; + + wxString::size_type begin = cursor; + + wxUniChar c = str[cursor]; + + if( isdigit( c ) || c == '+' || c == '-' ) + { + // number, possibly with sign + while( ++cursor < str.size() ) + { + c = str[cursor]; + + if( isdigit( c ) || c == 'v' || c == 'V' ) + continue; + else + break; + } + } + else + { + while( ++cursor < str.size() ) + { + c = str[cursor]; + + if( isdigit( c ) ) + break; + else + continue; + } + } + + return str.substr( begin, cursor - begin ); +} + + +int ComparePinNames( const wxString& lhs, const wxString& rhs ) +{ + wxString::size_type cursor1 = 0; + wxString::size_type cursor2 = 0; + + wxString comp1, comp2; + + for( ; ; ) + { + comp1 = GetNextComponent( lhs, cursor1 ); + comp2 = GetNextComponent( rhs, cursor2 ); + + if( comp1.empty() && comp2.empty() ) + return 0; + + if( comp1.empty() ) + return -1; + + if( comp2.empty() ) + return 1; + + wxUniChar c1 = comp1[0]; + wxUniChar c2 = comp2[0]; + + if( isdigit( c1 ) || c1 == '-' || c1 == '+' ) + { + if( isdigit( c2 ) || c2 == '-' || c2 == '+' ) + { + // numeric comparison + wxString::size_type v1 = comp1.find_first_of( "vV" ); + + if( v1 != wxString::npos ) + comp1[v1] = '.'; + + wxString::size_type v2 = comp2.find_first_of( "vV" ); + + if( v2 != wxString::npos ) + comp2[v2] = '.'; + + double val1, val2; + + comp1.ToDouble( &val1 ); + comp2.ToDouble( &val2 ); + + if( val1 < val2 ) + return -1; + + if( val1 > val2 ) + return 1; + } + else + return -1; + } + else + { + if( isdigit( c2 ) || c2 == '-' || c2 == '+' ) + return 1; + + int res = comp1.Cmp( comp2 ); + + if( res != 0 ) + return res; + } + } +} + + +class CompareLess +{ +public: + bool operator()( const wxString& lhs, const wxString& rhs ) + { + return ComparePinNames( lhs, rhs ) == -1; + } +}; +} + +int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Compare( const wxDataViewItem& aItem1, + const wxDataViewItem& aItem2, + unsigned int aCol, + bool aAscending ) const +{ + wxVariant var1; + + GetValue( var1, aItem1, aCol ); + wxString str1 = var1.GetString(); + + wxVariant var2; + GetValue( var2, aItem2, aCol ); + wxString str2 = var2.GetString(); + + int res = ComparePinNames( str1, str2 ); + + if( res == 0 ) + res = ( aItem1.GetID() < aItem2.GetID() ) ? -1 : 1; + + return res * ( aAscending ? 1 : -1 ); +} + + +void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::SetGroupingColumn( int aCol ) +{ + if( m_GroupingColumn == aCol ) + return; + + m_GroupingColumn = aCol; + + CalculateGrouping(); + Refresh(); +} + + +void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::CalculateGrouping() +{ + m_Groups.clear(); + + if( m_GroupingColumn != -1 ) + { + wxVariant value; + + for( std::list::iterator i = m_Pins.begin(); i != m_Pins.end(); ++i ) + { + i->GetValue( value, m_GroupingColumn ); + wxString str = value.GetString(); + std::map::iterator j = m_Groups.find( str ); + + if( j == m_Groups.end() ) + j = m_Groups.insert( std::make_pair( str, m_GroupingColumn ) ).first; + + j->second.Add( &*i ); + } + } + else + { + for( std::list::iterator i = m_Pins.begin(); i != m_Pins.end(); ++i ) + i->SetGroup( 0 ); + } +} + + +void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Refresh() +{ +#ifdef REASSOCIATE_HACK + m_Widget->AssociateModel( this ); +#else + Cleared(); + + std::queue todo; + todo.push( wxDataViewItem() ); + + while( !todo.empty() ) + { + wxDataViewItem current = todo.front(); + wxDataViewItemArray items; + + GetChildren( current, items ); + ItemsAdded( current, items ); + + for( wxDataViewItemArray::const_iterator i = items.begin(); i != items.end(); ++i ) + { + if( IsContainer( *i ) ) + todo.push( *i ); + } + + todo.pop(); + } + +#endif +} + + +void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::GetValue( wxVariant& aValue, + unsigned int aCol ) const +{ + if( aCol == m_GroupingColumn ) + { + // shortcut + m_Members.front()->GetValue( aValue, aCol ); + } + else + { + std::set values; + + for( std::list::const_iterator i = m_Members.begin(); i != m_Members.end(); ++i ) + { + wxVariant value; + (*i)->GetValue( value, aCol ); + values.insert( value.GetString() ); + } + + aValue = boost::algorithm::join( values, "," ); + } +} + + +void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::Add( Pin* aPin ) +{ + switch( GetCount() ) + { + case 0: + aPin->SetGroup( 0 ); + break; + + case 1: + m_Members.front()->SetGroup( this ); + + default: + aPin->SetGroup( this ); + } + + m_Members.push_back( aPin ); +} + + +void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin::GetValue( wxVariant& aValue, + unsigned int aCol ) const +{ + switch( aCol ) + { + case PIN_NUMBER: + aValue = m_Backing->GetNumberString(); + break; + + case PIN_NAME: + { + if( m_Model.m_UnitCount > 1 ) + { + wxString name; + int unit = m_Backing->GetPartNumber(); + + if( unit ) + name << unit; + else + name << "com"; + + name << ':'; + name << m_Backing->GetName(); + aValue = name; + } + else + { + aValue = m_Backing->GetName(); + } + } + break; + + case PIN_TYPE: + aValue = m_Backing->GetTypeString(); + break; + } +} diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.h b/eeschema/dialogs/dialog_lib_edit_pin_table.h new file mode 100644 index 0000000000..345a77c3fa --- /dev/null +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.h @@ -0,0 +1,18 @@ +#include "dialog_lib_edit_pin_table_base.h" + +#include "class_library.h" + +class DIALOG_LIB_EDIT_PIN_TABLE : + public DIALOG_LIB_EDIT_PIN_TABLE_BASE +{ +public: + DIALOG_LIB_EDIT_PIN_TABLE( wxWindow* parent, LIB_PART& aPart ); + ~DIALOG_LIB_EDIT_PIN_TABLE(); + + virtual void OnColumnHeaderRightClicked( wxDataViewEvent& aEvent ); + +private: + class DataViewModel; + + wxObjectDataPtr m_Model; +}; diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp new file mode 100644 index 0000000000..7c37307695 --- /dev/null +++ b/eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jun 5 2014) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_lib_edit_pin_table_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_LIB_EDIT_PIN_TABLE_BASE::DIALOG_LIB_EDIT_PIN_TABLE_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* top_sizer; + top_sizer = new wxBoxSizer( wxVERTICAL ); + + m_Pins = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ), wxDV_HORIZ_RULES|wxDV_MULTIPLE|wxDV_ROW_LINES|wxDV_VERT_RULES|wxVSCROLL ); + m_Pins->SetMinSize( wxSize( 400,400 ) ); + + top_sizer->Add( m_Pins, 1, wxALL|wxEXPAND, 5 ); + + m_Buttons = new wxStdDialogButtonSizer(); + m_ButtonsOK = new wxButton( this, wxID_OK ); + m_Buttons->AddButton( m_ButtonsOK ); + m_Buttons->Realize(); + + top_sizer->Add( m_Buttons, 0, wxEXPAND|wxALL, 5 ); + + + this->SetSizer( top_sizer ); + this->Layout(); + + this->Centre( wxBOTH ); + + // Connect Events + this->Connect( wxID_ANY, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnColumnHeaderRightClicked ) ); +} + +DIALOG_LIB_EDIT_PIN_TABLE_BASE::~DIALOG_LIB_EDIT_PIN_TABLE_BASE() +{ + // Disconnect Events + this->Disconnect( wxID_ANY, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnColumnHeaderRightClicked ) ); + +} diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp b/eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp new file mode 100644 index 0000000000..a010e01009 --- /dev/null +++ b/eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp @@ -0,0 +1,193 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_lib_edit_pin_table_base + 1000 + none + 1 + dialog_lib_edit_pin_table + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + decl_pure_virtual + + + + 0 + wxID_ANY + + + DIALOG_LIB_EDIT_PIN_TABLE_BASE + + 431,304 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + Pin Table + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + top_sizer + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 1 + + + + 1 + 1 + + + 0 + wxID_ANY + + 400,400 + m_Pins + protected + + -1,-1 + wxDV_HORIZ_RULES|wxDV_MULTIPLE|wxDV_ROW_LINES|wxDV_VERT_RULES + + + + + wxVSCROLL + + + OnColumnHeaderRightClicked + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxALL + 0 + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + + m_Buttons + protected + + + + + + + + + + + + + + diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table_base.h b/eeschema/dialogs/dialog_lib_edit_pin_table_base.h new file mode 100644 index 0000000000..5763e40368 --- /dev/null +++ b/eeschema/dialogs/dialog_lib_edit_pin_table_base.h @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jun 5 2014) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_LIB_EDIT_PIN_TABLE_BASE_H__ +#define __DIALOG_LIB_EDIT_PIN_TABLE_BASE_H__ + +#include +#include +#include +class DIALOG_SHIM; + +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_LIB_EDIT_PIN_TABLE_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_LIB_EDIT_PIN_TABLE_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxDataViewCtrl* m_Pins; + wxStdDialogButtonSizer* m_Buttons; + wxButton* m_ButtonsOK; + + // Virtual event handlers, overide them in your derived class + virtual void OnColumnHeaderRightClicked( wxDataViewEvent& event ) = 0; + + + public: + + DIALOG_LIB_EDIT_PIN_TABLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Pin Table"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 431,304 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_LIB_EDIT_PIN_TABLE_BASE(); + +}; + +#endif //__DIALOG_LIB_EDIT_PIN_TABLE_BASE_H__ diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index 8646173317..021e8982eb 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -199,6 +199,7 @@ enum id_eeschema_frm ID_DE_MORGAN_NORMAL_BUTT, ID_DE_MORGAN_CONVERT_BUTT, ID_LIBEDIT_EDIT_PIN_BY_PIN, + ID_LIBEDIT_EDIT_PIN_BY_TABLE, ID_LIBEDIT_VIEW_DOC, ID_LIBEDIT_CHECK_PART, diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index 2e17264259..e50b69235b 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -307,6 +307,9 @@ public: */ void SetPartNumber( int aPart ); + /** Get the pin part number. */ + int GetPartNumber() const { return m_Unit; } + /** * Set the body style (conversion) of the pin. * diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index bf0dec7dc7..a65bc88b53 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include @@ -108,6 +109,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_TOOL( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnSelectBodyStyle ) EVT_TOOL( ID_LIBEDIT_VIEW_DOC, LIB_EDIT_FRAME::OnViewEntryDoc ) EVT_TOOL( ID_LIBEDIT_EDIT_PIN_BY_PIN, LIB_EDIT_FRAME::Process_Special_Functions ) + EVT_TOOL( ID_LIBEDIT_EDIT_PIN_BY_TABLE, LIB_EDIT_FRAME::OnOpenPinTable ) EVT_TOOL( ExportPartId, LIB_EDIT_FRAME::OnExportPart ) EVT_TOOL( CreateNewLibAndSavePartId, LIB_EDIT_FRAME::OnExportPart ) EVT_TOOL( ImportPartId, LIB_EDIT_FRAME::OnImportPart ) @@ -165,6 +167,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_LIB, LIB_EDIT_FRAME::OnUpdateSaveCurrentLib ) EVT_UPDATE_UI( ID_LIBEDIT_VIEW_DOC, LIB_EDIT_FRAME::OnUpdateViewDoc ) EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_PIN, LIB_EDIT_FRAME::OnUpdatePinByPin ) + EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_TABLE, LIB_EDIT_FRAME::OnUpdatePinTable ) EVT_UPDATE_UI( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnUpdatePartNumber ) EVT_UPDATE_UI( ID_LIBEDIT_SELECT_ALIAS, LIB_EDIT_FRAME::OnUpdateSelectAlias ) EVT_UPDATE_UI( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganNormal ) @@ -508,6 +511,11 @@ void LIB_EDIT_FRAME::OnUpdatePinByPin( wxUpdateUIEvent& event ) event.Check( m_editPinsPerPartOrConvert ); } +void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event ) +{ + LIB_PART* part = GetCurPart(); + event.Enable( part ); +} void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event ) { @@ -1334,6 +1342,17 @@ void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent ) } } +void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent ) +{ + LIB_PART* part = GetCurPart(); + + DIALOG_LIB_EDIT_PIN_TABLE dlg( this, *part ); + + if( dlg.ShowModal() == wxID_CANCEL ) + return; + + return; +} bool LIB_EDIT_FRAME::SynchronizePins() { diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index 4abccf5b7d..233b77f031 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -266,6 +266,8 @@ public: void OnEditPin( wxCommandEvent& event ); void OnSelectItem( wxCommandEvent& aEvent ); + void OnOpenPinTable( wxCommandEvent& aEvent ); + void OnUpdateSelectTool( wxUpdateUIEvent& aEvent ); void OnUpdateEditingPart( wxUpdateUIEvent& event ); void OnUpdateNotEditingPart( wxUpdateUIEvent& event ); @@ -274,6 +276,7 @@ public: void OnUpdateSaveCurrentLib( wxUpdateUIEvent& event ); void OnUpdateViewDoc( wxUpdateUIEvent& event ); void OnUpdatePinByPin( wxUpdateUIEvent& event ); + void OnUpdatePinTable( wxUpdateUIEvent& event ); void OnUpdatePartNumber( wxUpdateUIEvent& event ); void OnUpdateDeMorganNormal( wxUpdateUIEvent& event ); void OnUpdateDeMorganConvert( wxUpdateUIEvent& event ); diff --git a/eeschema/tool_lib.cpp b/eeschema/tool_lib.cpp index e9e930136e..fc5e66a1e6 100644 --- a/eeschema/tool_lib.cpp +++ b/eeschema/tool_lib.cpp @@ -209,6 +209,8 @@ void LIB_EDIT_FRAME::ReCreateHToolbar() msg = _( "Edit pins per part or body style (Use carefully!)" ); m_mainToolBar->AddTool( ID_LIBEDIT_EDIT_PIN_BY_PIN, wxEmptyString, KiBitmap( pin2pin_xpm ), msg, wxITEM_CHECK ); + m_mainToolBar->AddTool( ID_LIBEDIT_EDIT_PIN_BY_TABLE, wxEmptyString, KiBitmap( pin_table_xpm ), + _( "Show pin table" ) ); // after adding the buttons to the toolbar, must call Realize() to reflect the changes m_mainToolBar->Realize(); diff --git a/include/bitmaps.h b/include/bitmaps.h index ee86cd1cba..50629964b9 100644 --- a/include/bitmaps.h +++ b/include/bitmaps.h @@ -415,6 +415,7 @@ EXTERN_BITMAP( pin2pin_xpm ) EXTERN_BITMAP( pin_name_to_xpm ) EXTERN_BITMAP( pin_number_to_xpm ) EXTERN_BITMAP( pin_size_to_xpm ) +EXTERN_BITMAP( pin_table_xpm ) EXTERN_BITMAP( pinorient_right_xpm ) EXTERN_BITMAP( pinorient_left_xpm ) EXTERN_BITMAP( pinorient_up_xpm )