Hello. I rebase patches.
PS: All sizes in Kicad internal units. > On Feb 22 2016, at 9:35 pm, Wayne Stambaugh <[email protected]> wrote: > > Eldar, > > There is something unsettling about your patch. Why are there different scalars applied when calculating the length of the text versus the height? This would suggest the PCAD file format does not use the same units for text height, text width, and text position. It appears to me that you have determined the text position and size scalars by comparing the KiCad output with the output of some other EDA application. If the PCAD units are mm, inches, mils, etc, the size and position numbers should be scaled to nanometers which are the units used in Pcbnew. When I see things like / 3, / 1.8, and / 1.4 in two consecutive lines of code translating coordinates, that raises a red flag. > > Cheers, > > Wayne > > On 2/22/2016 11:56 AM, Eldar Khayrullin wrote: > Hello. Patch attached. > P.S. need work to correct a justification of text and text size (I do) > > > _______________________________________________ > Mailing list: https://launchpad.net/~kicad-developers > Post to : [email protected] > Unsubscribe : https://launchpad.net/~kicad-developers > More help : https://help.launchpad.net/ListHelp > > > _______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : [email protected] Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
>From 947c6164c462c1c933147804cea6a3f1f7f5e193 Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin <[email protected]> Date: Mon, 22 Feb 2016 19:46:16 +0300 Subject: [PATCH 1/2] Fix bug #1547822 (partial): wrong position fields of text from PCAD import --- pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 72 +++++++++++------------ pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h | 3 +- pcbnew/pcad2kicadpcb_plugin/pcb_component.h | 6 +- pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 24 +++++--- pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp | 12 ++-- 5 files changed, 64 insertions(+), 53 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp index f588bbc..95876ec 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp @@ -37,6 +37,9 @@ namespace PCAD2KICAD { +// PCAD stroke font average ratio of width to height +const double TEXT_WIDTH_TO_HEIGHT = 0.79; + wxString GetWord( wxString* aStr ) { wxString result = wxEmptyString; @@ -367,48 +370,43 @@ void SetFontProperty( XNODE* aNode, } } +int CalculateTextLengthSize( TTEXTVALUE* aText ) +{ + return KiROUND( (double) aText->text.Len() * + (double) aText->textHeight * TEXT_WIDTH_TO_HEIGHT ); +} -void CorrectTextPosition( TTEXTVALUE* aValue, int aRotation ) +void CorrectTextPosition( TTEXTVALUE* aValue ) { - aValue->correctedPositionX = aValue->textPositionX; - aValue->correctedPositionY = aValue->textPositionY; - aValue->correctedPositionY = aValue->correctedPositionY - KiROUND( - (double) aValue->textHeight / 3.0 ); - aValue->correctedPositionX = aValue->correctedPositionX + - KiROUND( ( (double) aValue->text.Len() / - 1.4 ) * ( (double) aValue->textHeight / 1.8 ) ); - - if( aRotation == 900 ) - { - aValue->correctedPositionX = -aValue->textPositionY; - aValue->correctedPositionY = aValue->textPositionX; - aValue->correctedPositionX = aValue->correctedPositionX + KiROUND( - (double) aValue->textHeight / 3.0 ); - aValue->correctedPositionY = aValue->correctedPositionY + - KiROUND( ( (double) aValue->text.Len() / - 1.4 ) * ( (double) aValue->textHeight / 1.8 ) ); - } + int cm = aValue->mirror ? -1 : 1; + // sizes of justify correction + int cl = KiROUND( (double) CalculateTextLengthSize( aValue ) / 2.0 ); + int ch = KiROUND( (double) aValue->textHeight / 2.0 ); - if( aRotation == 1800 ) - { - aValue->correctedPositionX = -aValue->textPositionX; - aValue->correctedPositionY = -aValue->textPositionY; - aValue->correctedPositionY = aValue->correctedPositionY + - KiROUND( (double) aValue->textHeight / 3.0 ); - aValue->correctedPositionX = aValue->correctedPositionX - - KiROUND( ( (double) aValue->text.Len() / - 1.4 ) * ( (double) aValue->textHeight / 1.8 ) ); - } + aValue->correctedPositionX = aValue->textPositionX; + aValue->correctedPositionY = aValue->textPositionY; - if( aRotation == 2700 ) + // standart justify (low left corner) + switch( aValue->textRotation ) { - aValue->correctedPositionX = aValue->textPositionY; - aValue->correctedPositionY = -aValue->textPositionX; - aValue->correctedPositionX = aValue->correctedPositionX + - KiROUND( (double) aValue->textHeight / 1.0 ); - aValue->correctedPositionY = aValue->correctedPositionY - - KiROUND( ( (double) aValue->text.Len() / - 3.4 ) * ( (double) aValue->textHeight / 1.8 ) ); + case 0: + aValue->correctedPositionX += cl * cm; + aValue->correctedPositionY -= ch; + break; + case 900: + aValue->correctedPositionX -= ch * cm; + aValue->correctedPositionY -= cl; + break; + case 1800: + aValue->correctedPositionX -= cl * cm; + aValue->correctedPositionY += ch; + break; + case 2700: + aValue->correctedPositionX += ch * cm; + aValue->correctedPositionY += cl; + break; + default: + break; } } diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h index 30ce190..35877c1 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h @@ -77,7 +77,8 @@ extern void SetFontProperty( XNODE* aNode, TTEXTVALUE* aTextValue, wxString aDefaultMeasurementUnit, wxString aActualConversion ); -extern void CorrectTextPosition( TTEXTVALUE* aValue, int aRotation ); +extern int CalculateTextLengthSize( TTEXTVALUE* aText ); +extern void CorrectTextPosition( TTEXTVALUE* aValue ); extern XNODE* FindNode( XNODE* aChild, wxString aTag ); extern wxString FindNodeGetContent( XNODE* aChild, wxString aTag ); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_component.h b/pcbnew/pcad2kicadpcb_plugin/pcb_component.h index 41c55ab..6088fad 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_component.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_component.h @@ -56,11 +56,11 @@ public: int m_positionX; int m_positionY; int m_rotation; - TTEXTVALUE m_name; // name has also privete positions, rotations nand so on.... + TTEXTVALUE m_name; // name has also private positions, rotations and so on.... wxString m_net; int m_netCode; - wxString m_compRef; // internal ussage for XL parsing - wxString m_patGraphRefName; // internal ussage for XL parsing + wxString m_compRef; // internal usage for XL parsing + wxString m_patGraphRefName; // internal usage for XL parsing PCB_COMPONENT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); ~PCB_COMPONENT(); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp index cd4ba51..8eb66a7 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp @@ -43,6 +43,8 @@ #include <pcb_text.h> #include <pcb_via.h> +#include <trigo.h> + namespace PCAD2KICAD { PCB_MODULE::PCB_MODULE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks, @@ -282,7 +284,7 @@ void PCB_MODULE::DoLayerContentsObjects( XNODE* aNode, propValue.Trim( false ); propValue.Trim( true ); - if( propValue == wxT( "Type" ) ) + if( propValue == wxT( "RefDes" ) ) { tNode = FindNode( lNode, wxT( "textStyleRef" ) ); @@ -500,10 +502,16 @@ wxString PCB_MODULE::ModuleLayer( int aMirror ) void PCB_MODULE::AddToBoard() { int i; + int r; // transform text positions - CorrectTextPosition( &m_name, m_rotation ); - CorrectTextPosition( &m_value, m_rotation ); + CorrectTextPosition( &m_name ); + RotatePoint( &m_name.correctedPositionX, &m_name.correctedPositionY, + (double) -m_rotation ); + + CorrectTextPosition( &m_value ); + RotatePoint( &m_value.correctedPositionX, &m_value.correctedPositionY, + (double) -m_rotation ); MODULE* module = new MODULE( m_board ); m_board->Add( module, ADD_APPEND ); @@ -528,7 +536,9 @@ void PCB_MODULE::AddToBoard() ref_text->SetSize( wxSize( KiROUND( m_name.textHeight / 2 ), KiROUND( m_name.textHeight / 1.5 ) ) ); - ref_text->SetOrientation( m_name.textRotation ); + r = m_name.textRotation - m_rotation; + ref_text->SetOrientation( r ); + ref_text->SetThickness( m_name.textstrokeWidth ); ref_text->SetMirrored( m_name.mirror ); @@ -549,7 +559,9 @@ void PCB_MODULE::AddToBoard() val_text->SetSize( wxSize( KiROUND( m_value.textHeight / 2 ), KiROUND( m_value.textHeight / 1.5 ) ) ); - val_text->SetOrientation( m_value.textRotation ); + r = m_value.textRotation - m_rotation; + val_text->SetOrientation( r ); + val_text->SetThickness( m_value.textstrokeWidth ); val_text->SetMirrored( m_value.mirror ); @@ -611,9 +623,7 @@ void PCB_MODULE::Flip() // Flipped m_KiCadLayer = FlipLayer( m_KiCadLayer ); m_rotation = -m_rotation; - m_name.textPositionX = -m_name.textPositionX; m_name.mirror = m_mirror; - m_value.textPositionX = -m_value.textPositionX; m_value.mirror = m_mirror; for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ ) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp index a760d0b..51f0f14 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp @@ -98,9 +98,10 @@ void PCB_TEXT::AddToModule( MODULE* aModule ) void PCB_TEXT::AddToBoard() { // Simple, not the best, but acceptable text positioning. - m_name.textPositionX = m_positionX; - m_name.textPositionY = m_positionY; - CorrectTextPosition( &m_name, m_rotation ); + m_name.textPositionX = m_positionX; + m_name.textPositionY = m_positionY; + m_name.textRotation = m_rotation; + CorrectTextPosition( &m_name ); TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board ); m_board->Add( pcbtxt, ADD_APPEND ); @@ -111,9 +112,10 @@ void PCB_TEXT::AddToBoard() KiROUND( m_name.textHeight / 1.1 ) ) ); pcbtxt->SetThickness( m_name.textstrokeWidth ); - pcbtxt->SetOrientation( m_rotation ); + pcbtxt->SetOrientation( m_name.textRotation ); - pcbtxt->SetTextPosition( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) ); + pcbtxt->SetTextPosition( wxPoint( m_name.correctedPositionX, + m_name.correctedPositionY ) ); pcbtxt->SetMirrored( m_name.mirror ); pcbtxt->SetTimeStamp( 0 ); -- 2.5.0
>From ae329d04e18ba7fe82b1c0b82f8a5a4b7f5fed5d Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin <[email protected]> Date: Mon, 22 Feb 2016 20:38:22 +0300 Subject: [PATCH 2/2] Fix bug #1547822: refdes and value fields are set to invisible in new PCAD file format --- pcbnew/pcad2kicadpcb_plugin/pcb.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp index 41f79d2..8f5316b 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp @@ -166,7 +166,7 @@ void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, wxString aActualConversion ) { XNODE* tNode, * t1Node; - wxString n, pn, propValue, str; + wxString n, nnew, pn, propValue, str; // aNode is pattern now tNode = aNode; @@ -199,7 +199,8 @@ void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, str = aTextValue->text; str.Trim( false ); str.Trim( true ); - n = n + wxT( ' ' ) + str; // changed in new file version..... + nnew = n; // new file version + n = n + wxT( ' ' ) + str; // old file version tNode = NULL; } } @@ -219,7 +220,7 @@ void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, propValue.Trim( false ); propValue.Trim( true ); - if( propValue == n ) + if( propValue == n || propValue == nnew ) break; tNode = tNode->GetNext(); -- 2.5.0
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : [email protected] Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp

