From 8e915ae8d80a5e4ece554b9fa23086acd832bea2 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 28 Aug 2018 14:27:56 +0100 Subject: [PATCH] Add support for LIB_ALIAS objects. --- eeschema/class_libentry.cpp | 3 --- eeschema/class_libentry.h | 4 +--- eeschema/sch_painter.cpp | 39 ++++++++++++++++++++++++++++++------- eeschema/sch_painter.h | 2 ++ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index d87e09869f..74f3d99aa8 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -813,9 +813,6 @@ void LIB_PART::GetFields( LIB_FIELDS& aList ) { LIB_FIELD* field; - // The only caller of this function is the library field editor, so it - // establishes policy here. - // Grab the MANDATORY_FIELDS first, in expected order given by // enum NumFieldType for( int id=0; id& aFieldsList ); /** - * Return a list of fields withing this part. The only known caller of - * this function is the library part field editor, and it establishes - * needed behavior. + * Return a list of fields within this part. * * @param aList - List to add fields to */ diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 9b0b501914..3fc200dadc 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -141,6 +141,7 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer ) */ switch(item->Type()) { + HANDLE_ITEM(LIB_ALIAS_T, LIB_ALIAS); HANDLE_ITEM(LIB_PART_T, LIB_PART); HANDLE_ITEM(LIB_RECTANGLE_T, LIB_RECTANGLE); HANDLE_ITEM(LIB_POLYLINE_T, LIB_POLYLINE); @@ -170,24 +171,48 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer ) return false; } -void SCH_PAINTER::draw ( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit, int aConvert ) + +void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit, int aConvert ) { - auto comp = const_cast(aComp); - for ( auto& item : comp->GetDrawItems() ) + for( auto& item : aComp->GetDrawItems() ) { - if( !aDrawFields && item.Type() == LIB_FIELD_T) + if( !aDrawFields && item.Type() == LIB_FIELD_T ) continue; - if ( aUnit && item.GetUnit() && aUnit != item.GetUnit() ) + if( aUnit && item.GetUnit() && aUnit != item.GetUnit() ) continue; - if ( aConvert && item.GetConvert() && aConvert != item.GetConvert() ) + if( aConvert && item.GetConvert() && aConvert != item.GetConvert() ) continue; - Draw ( &item, aLayer ); + Draw( &item, aLayer ); } } + +void SCH_PAINTER::draw( LIB_ALIAS *aAlias, int aLayer ) +{ + LIB_PART* comp = aAlias->GetPart(); + int unit = 0; + int convert = 0; + + draw( comp, aLayer, false, unit, convert ); + + LIB_FIELDS fields; + comp->GetFields( fields ); + + if( !aAlias->IsRoot() ) + { + fields[ VALUE ].SetText( aAlias->GetName() ); + fields[ DATASHEET ].SetText( aAlias->GetDocFileName() ); + } + + for( LIB_FIELD& field : fields ) + draw( &field, aLayer ); +} + + + static VECTOR2D mapCoords( const wxPoint& aCoord ) { return VECTOR2D( aCoord.x, -aCoord.y ); diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 868caaad2a..94ebf73aad 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -32,6 +32,7 @@ class LIB_PIN; class LIB_CIRCLE; class LIB_ITEM; class LIB_PART; +class LIB_ALIAS; class LIB_POLYLINE; class LIB_ARC; class LIB_FIELD; @@ -120,6 +121,7 @@ private: void draw( LIB_CIRCLE *, int ); void draw( LIB_ITEM *, int ); void draw( LIB_PART *, int, bool aDrawFields = true, int aUnit = 0, int aConvert = 0 ); + void draw( LIB_ALIAS *, int ); void draw( LIB_ARC *, int ); void draw( LIB_POLYLINE *, int ); void draw( LIB_FIELD *, int );