From 62156b9b69b75452fa726393993b1cf98b0eb465 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 18 Oct 2017 10:12:22 +0200 Subject: [PATCH] Eeschema Eagle Import: refactored common code for setting text attributes --- eeschema/sch_eagle_plugin.cpp | 60 ++++++++++++++--------------------- eeschema/sch_eagle_plugin.h | 3 ++ 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index f25294fd90..6fc3ca8159 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -1679,33 +1679,15 @@ LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( std::unique_ptr& aPart, LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText( std::unique_ptr& aPart, - wxXmlNode* aLibText, - int aGateNumber ) + wxXmlNode* aLibText, int aGateNumber ) { std::unique_ptr libtext( new LIB_TEXT( aPart.get() ) ); - ETEXT etext( aLibText ); libtext->SetUnit( aGateNumber ); libtext->SetPosition( wxPoint( etext.x.ToSchUnits(), etext.y.ToSchUnits() ) ); libtext->SetText( aLibText->GetNodeContent().IsEmpty() ? "~~" : aLibText->GetNodeContent() ); - libtext->SetTextSize( etext.ConvertSize() ); - - if( etext.ratio ) - { - if( etext.ratio.Get()>12 ) - { - libtext->SetBold( true ); - libtext->SetThickness( GetPenSizeForBold( libtext->GetTextWidth() ) ); - } - } - - int align = etext.align ? *etext.align : ETEXT::BOTTOM_LEFT; - int degrees = etext.rot ? etext.rot->degrees : 0; - bool mirror = etext.rot ? etext.rot->mirror : false; - bool spin = etext.rot ? etext.rot->spin : false; - - eagleToKicadAlignment( (EDA_TEXT*) libtext.get(), align, degrees, mirror, spin, 0 ); + loadTextAttributes( libtext.get(), etext ); return libtext.release(); } @@ -1714,33 +1696,37 @@ LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText( std::unique_ptr& aPart, SCH_TEXT* SCH_EAGLE_PLUGIN::loadPlainText( wxXmlNode* aSchText ) { std::unique_ptr schtext( new SCH_TEXT() ); - auto etext = ETEXT( aSchText ); + ETEXT etext = ETEXT( aSchText ); - schtext->SetItalic( false ); + const wxString& thetext = aSchText->GetNodeContent(); + schtext->SetText( thetext.IsEmpty() ? "\" \"" : escapeName( thetext ) ); schtext->SetPosition( wxPoint( etext.x.ToSchUnits(), -etext.y.ToSchUnits() ) ); + loadTextAttributes( schtext.get(), etext ); + schtext->SetItalic( false ); - wxString thetext = aSchText->GetNodeContent(); - schtext->SetText( aSchText->GetNodeContent().IsEmpty() ? "\" \"" : escapeName( thetext ) ); + return schtext.release(); +} - if( etext.ratio ) + +void SCH_EAGLE_PLUGIN::loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const +{ + aText->SetTextSize( aAttribs.ConvertSize() ); + + if( aAttribs.ratio ) { - if( etext.ratio.Get()>12 ) + if( aAttribs.ratio.CGet() > 12 ) { - schtext->SetBold( true ); - schtext->SetThickness( GetPenSizeForBold( schtext->GetTextWidth() ) ); + aText->SetBold( true ); + aText->SetThickness( GetPenSizeForBold( aText->GetTextWidth() ) ); } } - schtext->SetTextSize( etext.ConvertSize() ); + int align = aAttribs.align ? *aAttribs.align : ETEXT::BOTTOM_LEFT; + int degrees = aAttribs.rot ? aAttribs.rot->degrees : 0; + bool mirror = aAttribs.rot ? aAttribs.rot->mirror : false; + bool spin = aAttribs.rot ? aAttribs.rot->spin : false; - int align = etext.align ? *etext.align : ETEXT::BOTTOM_LEFT; - int degrees = etext.rot ? etext.rot->degrees : 0; - bool mirror = etext.rot ? etext.rot->mirror : false; - bool spin = etext.rot ? etext.rot->spin : false; - - eagleToKicadAlignment( (EDA_TEXT*) schtext.get(), align, degrees, mirror, spin, 0 ); - - return schtext.release(); + eagleToKicadAlignment( aText, align, degrees, mirror, spin, 0 ); } diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index 85b6c19eb0..2610ef26b3 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -33,6 +33,7 @@ #include +class EDA_TEXT; class KIWAY; class LINE_READER; class SCH_SCREEN; @@ -167,6 +168,8 @@ private: LIB_PIN* loadPin( std::unique_ptr& aPart, wxXmlNode*, EPIN* epin, int aGateNumber ); LIB_TEXT* loadSymbolText( std::unique_ptr& aPart, wxXmlNode* aLibText, int aGateNumber ); + void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const; + KIWAY* m_kiway; ///< For creating sub sheets. SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded.. SCH_SHEET* m_currentSheet; ///< The current sheet of the schematic being loaded..