kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #32410
[PATCH] Import PCAD PCB improvements
Hello guys. Can you check fixes of importing PCAD PCB files?
>From 2418e51a94d27d43277297f00c1eba7f23886891 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
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 97ca994fa..38fa914d2 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 2b82409e7..9f1022299 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
--
2.14.1
>From 83b02041fdcd1edba4e6b7e1365975144beb44fa Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
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 7120b9dfc..09bd9e562 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -545,7 +545,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();
@@ -569,7 +569,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();
@@ -622,9 +622,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++ )
{
--
2.14.1
>From eba41940774f637fb611e78fc719e98781f161a6 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
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 67a360899..3ec71f7fa 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
--
2.14.1
>From 06f5421a3e557768b35875a10f027d1847f5cb6e Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
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.
---
pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 88 ++++++++++++++++-------
pcbnew/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 e6403434c..39569a51c 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( isTrueType )
+ {
+ propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) );
+ aTextValue->isItalic = ( propValue == wxT( "True" ) );
- if( aNode )
+ 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 )
{
- 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 );
-
- if( FindNode( aNode, wxT( "strokeWidth" ) ) )
- SetWidth( FindNode( aNode, wxT(
- "strokeWidth" ) )->GetNodeContent(),
- aDefaultMeasurementUnit, &aTextValue->textstrokeWidth,
- aActualConversion );
+ 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 02997e6b8..86024dd37 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 9d9244c35..5b2eba400 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -538,6 +538,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 );
@@ -560,6 +561,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 b4629f1ed..8df037303 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 );
--
2.14.1
>From df65f30e5f0be1e5e84c233a8839266475bbeb20 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
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 31ebf5de1..fc57b6cbc 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" ) );
--
2.14.1
>From a5ae175e0069be6b58cfe74bbd6d5a1dcf0983b4 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
Date: Tue, 12 Dec 2017 21:21:44 +0300
Subject: [PATCH 08/10] pcad2kicadpcb_plugin: fix size of text
---
pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 41 ++++++++++++++---------
pcbnew/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 8e954ce09..a4c1db251 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 86024dd37..68e5571a3 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 09bd9e562..f5d96c23b 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -533,7 +533,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 );
@@ -557,7 +560,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 8df037303..5c1b19a34 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 );
--
2.14.1
>From c4c5c0d229390a64bb3e114f9f180f92d667c50a Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
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 5b2eba400..7120b9dfc 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -537,6 +537,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 );
@@ -560,6 +561,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 );
--
2.14.1
>From 50a622af70fbd35821bc9fb88a1961eb04bba898 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
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 fc57b6cbc..e6403434c 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
@@ -29,6 +29,7 @@
#include <wx/wx.h>
#include <wx/config.h>
+#include <wx/regex.h>
#include <common.h>
#include <convert_to_biu.h>
@@ -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 5d5a8127f..02997e6b8 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 be3304ac0..9d9244c35 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -529,7 +529,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 ) );
--
2.14.1
>From 157b70013011986f6950beeb3f710983a04df7c0 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
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 f5d96c23b..9634667c9 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -604,6 +604,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++ )
{
@@ -634,6 +641,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 9a5f2530b..c120c8bb9 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
@@ -160,6 +160,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<wxPoint>;
+ 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 );
+ }
}
@@ -211,6 +230,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 a37be8fc5..e3515a81c 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h
@@ -57,6 +57,7 @@ public:
wxStatusBar* aStatusBar );
virtual void SetPosOffset( int aX_offs, int aY_offs ) override;
+ virtual void Flip() override;
void AddToModule( MODULE* aModule ) override;
void AddToBoard() override;
--
2.14.1
>From 7764594695b53963428045e5118e5b56bf5f3b9b Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
Date: Mon, 11 Dec 2017 21:34:50 +0300
Subject: [PATCH 06/10] pcad2kicadpcb_plugin: correct text position with
arbitrary angle
---
pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 111 +++++-----------------
1 file changed, 25 insertions(+), 86 deletions(-)
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
index 39569a51c..8e954ce09 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 );
-
- aValue->correctedPositionX = aValue->textPositionX;
- aValue->correctedPositionY = aValue->textPositionY;
-
- 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 )
- 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;
-
- 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;
- }
+ int posX = 0;
+ int posY = 0;
+
+ 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;
+
+ 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;
+
+ RotatePoint( &posX, &posY, aValue->textRotation );
+
+ aValue->correctedPositionX = aValue->textPositionX + posX;
+ aValue->correctedPositionY = aValue->textPositionY + posY;
}
--
2.14.1