From 21ddb2d9899f511a592f7bc615ee4c59416d88b9 Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Sun, 10 Dec 2017 10:10:17 +0300 Subject: [PATCH 01/10] pcad2kicadpcb_plugin: use default text parameters if not defined --- pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp index 31ebf5de18..fc57b6cbc7 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp @@ -327,12 +327,16 @@ void SetTextParameters( XNODE* aNode, str.Trim( false ); aTextValue->textRotation = StrToInt1Units( str ); } + else + { + aTextValue->textRotation = 0; + } str = FindNodeGetContent( aNode, wxT( "isVisible" ) ); if( str == wxT( "True" ) ) aTextValue->textIsVisible = 1; - else if( str == wxT( "False" ) ) + else aTextValue->textIsVisible = 0; str = FindNodeGetContent( aNode, wxT( "justify" ) ); @@ -342,6 +346,8 @@ void SetTextParameters( XNODE* aNode, if( str == wxT( "True" ) ) aTextValue->mirror = 1; + else + aTextValue->mirror = 0; tNode = FindNode( aNode, wxT( "textStyleRef" ) ); From 897702b2dcfb4491e4a184a1a09b75b76fbde14d Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Sun, 10 Dec 2017 11:12:10 +0300 Subject: [PATCH 02/10] pcad2kicadpcb_plugin: prepend numerical Ref with '.' Kicad (EESchema) doesn't support only numerical references (like '1'). Prepend with '.' same references (convert reference '1' to '.1'). --- pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 13 +++++++++++++ pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h | 1 + pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp index fc57b6cbc7..e6403434c7 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -225,6 +226,18 @@ wxString ValidateName( wxString aName ) } +wxString ValidateReference( wxString aRef ) +{ + wxRegEx reRef; + reRef.Compile( wxT( "^[[:digit:]][[:digit:]]*$" ) ); + + if( reRef.Matches( aRef ) ) + aRef.Prepend( wxT( '.' ) ); + + return aRef; +} + + void SetWidth( wxString aStr, wxString aDefaultMeasurementUnit, int* aWidth, diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h index 5d5a8127fb..02997e6b8f 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h @@ -71,6 +71,7 @@ extern wxString GetAndCutWordWithMeasureUnits( wxString* aStr, wxString aDefaultMeasurementUnit ); extern int StrToInt1Units( wxString aStr ); extern wxString ValidateName( wxString aName ); +extern wxString ValidateReference( wxString aRef ); extern void SetWidth( wxString aStr, wxString aDefaultMeasurementUnit, int* aWidth, diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp index 849bcb048d..eeb73a5801 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp @@ -526,7 +526,7 @@ void PCB_MODULE::AddToBoard() // reference text TEXTE_MODULE* ref_text = &module->Reference(); - ref_text->SetText( m_name.text ); + ref_text->SetText( ValidateReference( m_name.text ) ); ref_text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE ); ref_text->SetPos0( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) ); From 08b71cd252958b4d2db2202c59d6b028fbf48c98 Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Sun, 10 Dec 2017 12:21:43 +0300 Subject: [PATCH 03/10] pcad2kicadpcb_plugin: use a valid font properties Use current selected font (Stroke, TrueType) properties. Import TrueType Font properties: bold, italic. --- .../pcad2kicad_common.cpp | 88 +++++++++++++------ .../pcad2kicadpcb_plugin/pcad2kicad_common.h | 12 +-- pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 2 + pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp | 1 + 4 files changed, 73 insertions(+), 30 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp index e6403434c7..39569a51ce 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp @@ -43,6 +43,10 @@ const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.79; // PCAD proportions of stroke font const double TEXT_HEIGHT_TO_SIZE = 0.656; const double TEXT_WIDTH_TO_SIZE = 0.656; +// True type font +const double TRUETYPE_WIDTH_PER_HEIGHT = 0.073; +const double TRUETYPE_BOLD_WIDTH_MUL = 1.6; +const long TRUETYPE_BOLD_MIN_WEIGHT = 700; wxString GetWord( wxString* aStr ) { @@ -289,6 +293,7 @@ void SetDoublePrecisionPosition( wxString aStr, aActualConversion ); } + TTEXT_JUSTIFY GetJustifyIdentificator( wxString aJustify ) { TTEXT_JUSTIFY id; @@ -315,6 +320,7 @@ TTEXT_JUSTIFY GetJustifyIdentificator( wxString aJustify ) return id; } + void SetTextParameters( XNODE* aNode, TTEXTVALUE* aTextValue, wxString aDefaultMeasurementUnit, @@ -382,49 +388,77 @@ void SetFontProperty( XNODE* aNode, aNode = aNode->GetParent(); aNode = FindNode( aNode, wxT( "library" ) ); - if( aNode ) aNode = FindNode( aNode, wxT( "textStyleDef" ) ); + while( aNode ) + { + aNode->GetAttribute( wxT( "Name" ), &propValue ); + propValue.Trim( false ); + propValue.Trim( true ); + + if( propValue == n ) + break; + + aNode = aNode->GetNext(); + } + if( aNode ) { - while( true ) - { - aNode->GetAttribute( wxT( "Name" ), &propValue ); - propValue.Trim( false ); - propValue.Trim( true ); + bool isTrueType; + wxString fontType; - if( propValue == n ) - break; + propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) ); + isTrueType = ( propValue == wxT( "True" ) ); + aNode = FindNode( aNode, wxT( "font" ) ); + fontType = FindNodeGetContent( aNode, wxT( "fontType" ) ); + if( ( isTrueType && ( fontType != wxT( "TrueType" ) ) ) || + ( !isTrueType && ( fontType != wxT( "Stroke" ) ) ) ) aNode = aNode->GetNext(); - } if( aNode ) { - aNode = FindNode( aNode, wxT( "font" ) ); - - if( aNode ) + if( isTrueType ) { - if( FindNode( aNode, wxT( "fontHeight" ) ) ) - // // SetWidth(iNode.ChildNodes.FindNode('fontHeight').Text, - // // DefaultMeasurementUnit,tv.TextHeight); - // Fixed By Lubo, 02/2008 - SetHeight( FindNode( aNode, wxT( - "fontHeight" ) )->GetNodeContent(), - aDefaultMeasurementUnit, &aTextValue->textHeight, - aActualConversion ); + propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) ); + aTextValue->isItalic = ( propValue == wxT( "True" ) ); - if( FindNode( aNode, wxT( "strokeWidth" ) ) ) - SetWidth( FindNode( aNode, wxT( - "strokeWidth" ) )->GetNodeContent(), - aDefaultMeasurementUnit, &aTextValue->textstrokeWidth, - aActualConversion ); + propValue = FindNodeGetContent( aNode, wxT( "fontWeight" ) ); + if( propValue != wxEmptyString ) + { + long fontWeight; + + propValue.ToLong( &fontWeight ); + aTextValue->isBold = ( fontWeight >= TRUETYPE_BOLD_MIN_WEIGHT ); + } + } + + XNODE* lNode; + + lNode = FindNode( aNode, wxT( "fontHeight" ) ); + if( lNode ) + SetHeight( lNode->GetNodeContent(), aDefaultMeasurementUnit, + &aTextValue->textHeight, aActualConversion ); + + if( isTrueType ) + { + aTextValue->textstrokeWidth = TRUETYPE_WIDTH_PER_HEIGHT * aTextValue->textHeight; + if( aTextValue->isBold ) + aTextValue->textstrokeWidth *= TRUETYPE_BOLD_WIDTH_MUL; + } + else + { + lNode = FindNode( aNode, wxT( "strokeWidth" ) ); + if( lNode ) + SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, + &aTextValue->textstrokeWidth, aActualConversion ); } } } } + void SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify ) { switch( aJustify ) @@ -468,12 +502,14 @@ void SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify ) } } + int CalculateTextLengthSize( TTEXTVALUE* aText ) { return KiROUND( (double) aText->text.Len() * (double) aText->textHeight * TEXT_WIDTH_TO_SIZE_AVERAGE ); } + void CorrectTextPosition( TTEXTVALUE* aValue ) { int cm = aValue->mirror ? -1 : 1; @@ -620,6 +656,8 @@ void InitTTextValue( TTEXTVALUE* aTextValue ) aTextValue->correctedPositionX = 0; aTextValue->correctedPositionY = 0; aTextValue->justify = LowerLeft; + aTextValue->isBold = false; + aTextValue->isItalic = false; } } // namespace PCAD2KICAD diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h index 02997e6b8f..86024dd371 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h @@ -56,12 +56,14 @@ enum TTEXT_JUSTIFY typedef struct _TTEXTVALUE { - wxString text; - int textPositionX, textPositionY, - textRotation, textHeight, textstrokeWidth; - int textIsVisible, mirror, textUnit; - int correctedPositionX, correctedPositionY; + wxString text; + int textPositionX, textPositionY, + textRotation, textHeight, textstrokeWidth; + int textIsVisible, mirror, textUnit; + int correctedPositionX, correctedPositionY; TTEXT_JUSTIFY justify; + bool isBold; + bool isItalic; } TTEXTVALUE; extern wxString GetWord( wxString* aStr ); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp index eeb73a5801..af60af9bbc 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp @@ -535,6 +535,7 @@ void PCB_MODULE::AddToBoard() r = m_name.textRotation - m_rotation; ref_text->SetTextAngle( r ); + ref_text->SetItalic( m_name.isItalic ); ref_text->SetThickness( m_name.textstrokeWidth ); ref_text->SetMirrored( m_name.mirror ); @@ -557,6 +558,7 @@ void PCB_MODULE::AddToBoard() r = m_value.textRotation - m_rotation; val_text->SetTextAngle( r ); + val_text->SetItalic( m_value.isItalic ); val_text->SetThickness( m_value.textstrokeWidth ); val_text->SetMirrored( m_value.mirror ); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp index b4629f1ed4..8df037303c 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp @@ -112,6 +112,7 @@ void PCB_TEXT::AddToBoard() SetTextSizeFromStrokeFontHeight( pcbtxt, m_name.textHeight ); + pcbtxt->SetItalic( m_name.isItalic ); pcbtxt->SetThickness( m_name.textstrokeWidth ); pcbtxt->SetTextAngle( m_name.textRotation ); From c9852d7c811431da8c322de312cd82c91eb35ea7 Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Sun, 10 Dec 2017 21:18:21 +0300 Subject: [PATCH 04/10] pcad2kicadpcb_plugin: import circles --- pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp | 10 ++++++++-- pcbnew/pcad2kicadpcb_plugin/pcb_arc.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp index 97ca994fab..38fa914d2c 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp @@ -160,7 +160,7 @@ void PCB_ARC::AddToModule( MODULE* aModule ) { if( IsNonCopperLayer( m_KiCadLayer ) ) { - EDGE_MODULE* arc = new EDGE_MODULE( aModule, S_ARC ); + EDGE_MODULE* arc = new EDGE_MODULE( aModule, ( IsCircle() ? S_CIRCLE : S_ARC ) ); aModule->GraphicalItemsList().PushBack( arc ); arc->SetAngle( -m_angle ); @@ -181,7 +181,7 @@ void PCB_ARC::AddToBoard() m_board->Add( dseg, ADD_APPEND ); - dseg->SetShape( S_ARC ); + dseg->SetShape( IsCircle() ? S_CIRCLE : S_ARC ); dseg->SetTimeStamp( m_timestamp ); dseg->SetLayer( m_KiCadLayer ); dseg->SetStart( wxPoint( m_positionX, m_positionY ) ); @@ -190,4 +190,10 @@ void PCB_ARC::AddToBoard() dseg->SetWidth( m_width ); } + +bool PCB_ARC::IsCircle() +{ + return ( m_angle == 3600 ); +} + } // namespace PCAD2KICAD diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_arc.h b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.h index 2b82409e7d..9f1022299a 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_arc.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.h @@ -54,6 +54,9 @@ public: virtual void Flip() override; void AddToModule( MODULE* aModule ) override; void AddToBoard() override; + +private: + bool IsCircle(); }; } // namespace PCAD2KICAD From 6f0e0826fabb0cda99dc61fe726baccd24d35150 Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Sun, 10 Dec 2017 21:46:57 +0300 Subject: [PATCH 05/10] pcad2kicadpcb_plugin: unlock orientation of footprint fields --- pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp index af60af9bbc..dff943dfa0 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp @@ -534,6 +534,7 @@ void PCB_MODULE::AddToBoard() r = m_name.textRotation - m_rotation; ref_text->SetTextAngle( r ); + ref_text->SetUnlocked( true ); ref_text->SetItalic( m_name.isItalic ); ref_text->SetThickness( m_name.textstrokeWidth ); @@ -557,6 +558,7 @@ void PCB_MODULE::AddToBoard() r = m_value.textRotation - m_rotation; val_text->SetTextAngle( r ); + val_text->SetUnlocked( true ); val_text->SetItalic( m_value.isItalic ); val_text->SetThickness( m_value.textstrokeWidth ); From 9620a430220c2b698d391da4f419a4e40aeaac7e Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Mon, 11 Dec 2017 21:34:50 +0300 Subject: [PATCH 06/10] pcad2kicadpcb_plugin: correct text position with arbitrary angle --- .../pcad2kicad_common.cpp | 103 ++++-------------- 1 file changed, 21 insertions(+), 82 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp index 39569a51ce..8e954ce095 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp @@ -513,94 +513,33 @@ int CalculateTextLengthSize( TTEXTVALUE* aText ) void CorrectTextPosition( TTEXTVALUE* aValue ) { 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 ); + int posX = 0; + int posY = 0; - aValue->correctedPositionX = aValue->textPositionX; - aValue->correctedPositionY = aValue->textPositionY; + if( aValue->justify == LowerLeft || + aValue->justify == Left || + aValue->justify == UpperLeft ) + posX += cl * cm; + else if( aValue->justify == LowerRight || + aValue->justify == Right || + aValue->justify == UpperRight ) + posX -= cl * cm; - switch( aValue->textRotation ) - { - case 0: - if( aValue->justify == LowerLeft || - aValue->justify == Left || - aValue->justify == UpperLeft ) - aValue->correctedPositionX += cl * cm; - else if( aValue->justify == LowerRight || - aValue->justify == Right || - aValue->justify == UpperRight ) - aValue->correctedPositionX -= cl * cm; + if( aValue->justify == LowerLeft || + aValue->justify == LowerCenter || + aValue->justify == LowerRight ) + posY -= ch; + else if( aValue->justify == UpperLeft || + aValue->justify == UpperCenter || + aValue->justify == UpperRight ) + posY += ch; - if( aValue->justify == LowerLeft || - aValue->justify == LowerCenter || - aValue->justify == LowerRight ) - aValue->correctedPositionY -= ch; - else if( aValue->justify == UpperLeft || - aValue->justify == UpperCenter || - aValue->justify == UpperRight ) - aValue->correctedPositionY += ch; - break; - case 900: - if( aValue->justify == LowerLeft || - aValue->justify == LowerCenter || - aValue->justify == LowerRight ) - aValue->correctedPositionX -= ch * cm; - else if( aValue->justify == UpperLeft || - aValue->justify == UpperCenter || - aValue->justify == UpperRight ) - aValue->correctedPositionX += ch * cm; + RotatePoint( &posX, &posY, aValue->textRotation ); - if( aValue->justify == LowerLeft || - aValue->justify == Left || - aValue->justify == UpperLeft ) - aValue->correctedPositionY -= cl; - else if( aValue->justify == LowerRight || - aValue->justify == Right || - aValue->justify == UpperRight ) - aValue->correctedPositionY += cl; - break; - case 1800: - if( aValue->justify == LowerLeft || - aValue->justify == Left || - aValue->justify == UpperLeft ) - aValue->correctedPositionX -= cl * cm; - else if( aValue->justify == LowerRight || - aValue->justify == Right || - aValue->justify == UpperRight ) - aValue->correctedPositionX += cl * cm; - - if( aValue->justify == LowerLeft || - aValue->justify == LowerCenter || - aValue->justify == LowerRight ) - aValue->correctedPositionY += ch; - else if( aValue->justify == UpperLeft || - aValue->justify == UpperCenter || - aValue->justify == UpperRight ) - aValue->correctedPositionY -= ch; - break; - case 2700: - if( aValue->justify == LowerLeft || - aValue->justify == LowerCenter || - aValue->justify == LowerRight ) - aValue->correctedPositionX += ch * cm; - else if( aValue->justify == UpperLeft || - aValue->justify == UpperCenter || - aValue->justify == UpperRight ) - aValue->correctedPositionX -= ch * cm; - - if( aValue->justify == LowerLeft || - aValue->justify == Left || - aValue->justify == UpperLeft ) - aValue->correctedPositionY += cl; - else if( aValue->justify == LowerRight || - aValue->justify == Right || - aValue->justify == UpperRight ) - aValue->correctedPositionY -= cl; - break; - default: - break; - } + aValue->correctedPositionX = aValue->textPositionX + posX; + aValue->correctedPositionY = aValue->textPositionY + posY; } From 613272852d800e5a351b1065c7ee00ac23b144d5 Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Mon, 11 Dec 2017 21:35:14 +0300 Subject: [PATCH 07/10] pcad2kicadpcb_plugin: fix import a flipped RefDes Fixes: lp:1730172 * https://bugs.launchpad.net/kicad/+bug/1730172 --- pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp index dff943dfa0..a13bdb2586 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp @@ -542,7 +542,7 @@ void PCB_MODULE::AddToBoard() ref_text->SetMirrored( m_name.mirror ); ref_text->SetVisible( m_name.textIsVisible ); - ref_text->SetLayer( m_KiCadLayer ); + ref_text->SetLayer( m_name.mirror ? FlipLayer( m_KiCadLayer ) : m_KiCadLayer ); // Calculate the actual position. ref_text->SetDrawCoord(); @@ -566,7 +566,7 @@ void PCB_MODULE::AddToBoard() val_text->SetMirrored( m_value.mirror ); val_text->SetVisible( m_value.textIsVisible ); - val_text->SetLayer( m_KiCadLayer ); + val_text->SetLayer( m_value.mirror ? FlipLayer( m_KiCadLayer ) : m_KiCadLayer ); // Calculate the actual position. val_text->SetDrawCoord(); @@ -619,9 +619,7 @@ void PCB_MODULE::Flip() if( m_mirror == 1 ) { - // Flipped - m_KiCadLayer = FlipLayer( m_KiCadLayer ); - m_rotation = -m_rotation; + m_rotation = -m_rotation; for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ ) { From 87566eedc50dcae6643b91f2d0567609de70c3b7 Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Tue, 12 Dec 2017 21:21:44 +0300 Subject: [PATCH 08/10] pcad2kicadpcb_plugin: fix size of text --- .../pcad2kicad_common.cpp | 41 +++++++++++-------- .../pcad2kicadpcb_plugin/pcad2kicad_common.h | 3 +- pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 10 ++++- pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp | 5 ++- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp index 8e954ce095..a4c1db2517 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp @@ -39,13 +39,15 @@ namespace PCAD2KICAD { // PCAD stroke font average ratio of width to size -const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.79; +const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.5; // PCAD proportions of stroke font -const double TEXT_HEIGHT_TO_SIZE = 0.656; -const double TEXT_WIDTH_TO_SIZE = 0.656; -// True type font -const double TRUETYPE_WIDTH_PER_HEIGHT = 0.073; -const double TRUETYPE_BOLD_WIDTH_MUL = 1.6; +const double STROKE_HEIGHT_TO_SIZE = 0.656; +const double STROKE_WIDTH_TO_SIZE = 0.69; +// TrueType font +const double TRUETYPE_HEIGHT_TO_SIZE = 0.585; +const double TRUETYPE_WIDTH_TO_SIZE = 0.585; +const double TRUETYPE_THICK_PER_HEIGHT = 0.073; +const double TRUETYPE_BOLD_THICK_MUL = 1.6; const long TRUETYPE_BOLD_MIN_WEIGHT = 700; wxString GetWord( wxString* aStr ) @@ -405,21 +407,20 @@ void SetFontProperty( XNODE* aNode, if( aNode ) { - bool isTrueType; wxString fontType; propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) ); - isTrueType = ( propValue == wxT( "True" ) ); + aTextValue->isTrueType = ( propValue == wxT( "True" ) ); aNode = FindNode( aNode, wxT( "font" ) ); fontType = FindNodeGetContent( aNode, wxT( "fontType" ) ); - if( ( isTrueType && ( fontType != wxT( "TrueType" ) ) ) || - ( !isTrueType && ( fontType != wxT( "Stroke" ) ) ) ) + if( ( aTextValue->isTrueType && ( fontType != wxT( "TrueType" ) ) ) || + ( !aTextValue->isTrueType && ( fontType != wxT( "Stroke" ) ) ) ) aNode = aNode->GetNext(); if( aNode ) { - if( isTrueType ) + if( aTextValue->isTrueType ) { propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) ); aTextValue->isItalic = ( propValue == wxT( "True" ) ); @@ -441,11 +442,11 @@ void SetFontProperty( XNODE* aNode, SetHeight( lNode->GetNodeContent(), aDefaultMeasurementUnit, &aTextValue->textHeight, aActualConversion ); - if( isTrueType ) + if( aTextValue->isTrueType ) { - aTextValue->textstrokeWidth = TRUETYPE_WIDTH_PER_HEIGHT * aTextValue->textHeight; + aTextValue->textstrokeWidth = TRUETYPE_THICK_PER_HEIGHT * aTextValue->textHeight; if( aTextValue->isBold ) - aTextValue->textstrokeWidth *= TRUETYPE_BOLD_WIDTH_MUL; + aTextValue->textstrokeWidth *= TRUETYPE_BOLD_THICK_MUL; } else { @@ -545,8 +546,15 @@ void CorrectTextPosition( TTEXTVALUE* aValue ) void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, int aTextHeight ) { - aText->SetTextSize( wxSize( KiROUND( aTextHeight * TEXT_WIDTH_TO_SIZE ), - KiROUND( aTextHeight * TEXT_HEIGHT_TO_SIZE ) ) ); + aText->SetTextSize( wxSize( KiROUND( aTextHeight * STROKE_WIDTH_TO_SIZE ), + KiROUND( aTextHeight * STROKE_HEIGHT_TO_SIZE ) ) ); +} + + +void SetTextSizeFromTrueTypeFontHeight( EDA_TEXT* aText, int aTextHeight ) +{ + aText->SetTextSize( wxSize( KiROUND( aTextHeight * TRUETYPE_WIDTH_TO_SIZE ), + KiROUND( aTextHeight * TRUETYPE_HEIGHT_TO_SIZE ) ) ); } @@ -597,6 +605,7 @@ void InitTTextValue( TTEXTVALUE* aTextValue ) aTextValue->justify = LowerLeft; aTextValue->isBold = false; aTextValue->isItalic = false; + aTextValue->isTrueType = false; } } // namespace PCAD2KICAD diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h index 86024dd371..68e5571a37 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h @@ -64,6 +64,7 @@ typedef struct _TTEXTVALUE TTEXT_JUSTIFY justify; bool isBold; bool isItalic; + bool isTrueType; } TTEXTVALUE; extern wxString GetWord( wxString* aStr ); @@ -102,7 +103,7 @@ extern int CalculateTextLengthSize( TTEXTVALUE* aText ); extern void CorrectTextPosition( TTEXTVALUE* aValue ); extern void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, int aTextHeight ); - +extern void SetTextSizeFromTrueTypeFontHeight( EDA_TEXT* aText, int aTextHeight ); extern XNODE* FindNode( XNODE* aChild, wxString aTag ); extern wxString FindNodeGetContent( XNODE* aChild, wxString aTag ); extern void InitTTextValue( TTEXTVALUE* aTextValue ); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp index a13bdb2586..9337449e30 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp @@ -530,7 +530,10 @@ void PCB_MODULE::AddToBoard() ref_text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE ); ref_text->SetPos0( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) ); - SetTextSizeFromStrokeFontHeight( ref_text, m_name.textHeight ); + if( m_name.isTrueType ) + SetTextSizeFromTrueTypeFontHeight( ref_text, m_name.textHeight ); + else + SetTextSizeFromStrokeFontHeight( ref_text, m_name.textHeight ); r = m_name.textRotation - m_rotation; ref_text->SetTextAngle( r ); @@ -554,7 +557,10 @@ void PCB_MODULE::AddToBoard() val_text->SetType( TEXTE_MODULE::TEXT_is_VALUE ); val_text->SetPos0( wxPoint( m_value.correctedPositionX, m_value.correctedPositionY ) ); - SetTextSizeFromStrokeFontHeight( val_text, m_value.textHeight ); + if( m_value.isTrueType ) + SetTextSizeFromTrueTypeFontHeight( val_text, m_value.textHeight ); + else + SetTextSizeFromStrokeFontHeight( val_text, m_value.textHeight ); r = m_value.textRotation - m_rotation; val_text->SetTextAngle( r ); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp index 8df037303c..5c1b19a349 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp @@ -110,7 +110,10 @@ void PCB_TEXT::AddToBoard() pcbtxt->SetText( m_name.text ); - SetTextSizeFromStrokeFontHeight( pcbtxt, m_name.textHeight ); + if( m_name.isTrueType ) + SetTextSizeFromTrueTypeFontHeight( pcbtxt, m_name.textHeight ); + else + SetTextSizeFromStrokeFontHeight( pcbtxt, m_name.textHeight ); pcbtxt->SetItalic( m_name.isItalic ); pcbtxt->SetThickness( m_name.textstrokeWidth ); From d62d3b8e215062278b2fe27cba50f6e27b743dff Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Wed, 13 Dec 2017 20:47:03 +0300 Subject: [PATCH 09/10] pcad2kicadpcb_plugin: map layers Top/Bot Assy to F/B Fab --- pcbnew/pcad2kicadpcb_plugin/pcb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp index 8b9535b66e..35ed2fee31 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp @@ -487,7 +487,7 @@ void PCB::MapLayer( XNODE* aNode ) lName = lName.MakeUpper(); if( lName == wxT( "TOP ASSY" ) ) - KiCadLayer = Cmts_User; + KiCadLayer = F_Fab; else if( lName == wxT( "TOP SILK" ) ) KiCadLayer = F_SilkS; else if( lName == wxT( "TOP PASTE" ) ) @@ -505,7 +505,7 @@ void PCB::MapLayer( XNODE* aNode ) else if( lName == wxT( "BOT SILK" ) ) KiCadLayer = B_SilkS; else if( lName == wxT( "BOT ASSY" ) ) - KiCadLayer = Dwgs_User; + KiCadLayer = B_Fab; else if( lName == wxT( "BOARD" ) ) KiCadLayer = Edge_Cuts; else From 4cd3992b946d4642334849585bb7528f19ed6c18 Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Wed, 13 Dec 2017 22:14:23 +0300 Subject: [PATCH 10/10] pcad2kicadpcb_plugin: import graphic polygons from modules Fixes: lp:1725931 * https://bugs.launchpad.net/kicad/+bug/1725931 --- pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 8 ++++++ pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp | 27 +++++++++++++++++++++ pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h | 1 + 3 files changed, 36 insertions(+) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp index 9337449e30..44946ecbd3 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp @@ -601,6 +601,13 @@ void PCB_MODULE::AddToBoard() m_moduleObjects[i]->AddToModule( module ); } + // MODULE POLYGONS + for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ ) + { + if( m_moduleObjects[i]->m_objType == wxT( 'Z' ) ) + m_moduleObjects[i]->AddToModule( module ); + } + // PADS for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ ) { @@ -631,6 +638,7 @@ void PCB_MODULE::Flip() { if( m_moduleObjects[i]->m_objType == wxT( 'L' ) || // lines m_moduleObjects[i]->m_objType == wxT( 'A' ) || // arcs + m_moduleObjects[i]->m_objType == wxT( 'Z' ) || // polygons m_moduleObjects[i]->m_objType == wxT( 'P' ) || // pads m_moduleObjects[i]->m_objType == wxT( 'V' ) ) // vias { diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp index d3fb6bd9b9..e6cd534adc 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp @@ -157,6 +157,25 @@ bool PCB_POLYGON::Parse( XNODE* aNode, void PCB_POLYGON::AddToModule( MODULE* aModule ) { + if( IsNonCopperLayer( m_KiCadLayer ) ) + { + EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON ); + aModule->GraphicalItemsList().PushBack( dwg ); + + dwg->SetWidth( 0 ); + dwg->SetLayer( m_KiCadLayer ); + + auto outline = new std::vector; + for( auto point : m_outline ) + outline->push_back( wxPoint( point->x, point->y ) ); + + dwg->SetPolyPoints( *outline ); + dwg->SetStart0( *outline->begin() ); + dwg->SetEnd0( outline->back() ); + dwg->SetDrawCoord(); + + delete( outline ); + } } @@ -208,6 +227,14 @@ void PCB_POLYGON::AddToBoard() } +void PCB_POLYGON::Flip() +{ + PCB_COMPONENT::Flip(); + + m_KiCadLayer = FlipLayer( m_KiCadLayer ); +} + + void PCB_POLYGON::SetPosOffset( int aX_offs, int aY_offs ) { int i, island; diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h index fe35832894..a6623edd7f 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h @@ -56,6 +56,7 @@ public: wxString aActualConversion ); virtual void SetPosOffset( int aX_offs, int aY_offs ) override; + virtual void Flip() override; void AddToModule( MODULE* aModule ) override; void AddToBoard() override;