kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #23318
Re: [PATCH] fix position of text and refdes from PCAD import
Apply Justify of text and flipped flag of text from import file.
> On Feb 23 2016, at 12:00 pm, Eldar Khayrullin
<eldar.khayrullin@xxxxxxx> wrote:
Hello.
>
> I rebase patches.
>
> PS: All sizes in Kicad internal units.
>
>> On Feb 22 2016, at 9:35 pm, Wayne Stambaugh <stambaughw@xxxxxxxxx>
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 : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>
>>
>> _______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~kicad-developers
More help : https://help.launchpad.net/ListHelp
>From 76d728dee9f2c47c59617404c283cf6b384b9658 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
Date: Tue, 23 Feb 2016 15:24:13 +0300
Subject: [PATCH] pcad2kicadpcb: apply text justify. Set proper flag of flipped
for text fields
---
pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 111 ++++++++++++++++++++--
pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h | 15 +++
pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 2 -
pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp | 3 +
4 files changed, 120 insertions(+), 11 deletions(-)
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
index 95876ec..7ff4a60 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
@@ -273,6 +273,31 @@ void SetDoublePrecisionPosition( wxString aStr,
aActualConversion );
}
+TTEXT_JUSTIFY GetJustifyIdentificator( wxString aJustify )
+{
+ TTEXT_JUSTIFY id;
+
+ if( aJustify == wxT( "LowerCenter" ) )
+ id = LowerCenter;
+ else if( aJustify == wxT( "LowerRight" ) )
+ id = LowerRight;
+ else if( aJustify == wxT( "UpperLeft" ) )
+ id = UpperLeft;
+ else if( aJustify == wxT( "UpperCenter" ) )
+ id = UpperCenter;
+ else if( aJustify == wxT( "UpperRight" ) )
+ id = UpperRight;
+ else if( aJustify == wxT( "Left" ) )
+ id = Left;
+ else if( aJustify == wxT( "Center" ) )
+ id = Center;
+ else if( aJustify == wxT( "Right" ) )
+ id = Right;
+ else
+ id = LowerLeft;
+
+ return id;
+}
void SetTextParameters( XNODE* aNode,
TTEXTVALUE* aTextValue,
@@ -307,6 +332,14 @@ void SetTextParameters( XNODE* aNode,
else if( str == wxT( "False" ) )
aTextValue->textIsVisible = 0;
+ str = FindNodeGetContent( aNode, wxT( "justify" ) );
+ aTextValue->justify = GetJustifyIdentificator( str );
+
+ str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
+
+ if( str == wxT( "True" ) )
+ aTextValue->mirror = 1;
+
tNode = FindNode( aNode, wxT( "textStyleRef" ) );
if( tNode )
@@ -386,24 +419,83 @@ void CorrectTextPosition( TTEXTVALUE* aValue )
aValue->correctedPositionX = aValue->textPositionX;
aValue->correctedPositionY = aValue->textPositionY;
- // standart justify (low left corner)
switch( aValue->textRotation )
{
case 0:
- aValue->correctedPositionX += cl * cm;
- aValue->correctedPositionY -= ch;
+ 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:
- aValue->correctedPositionX -= ch * cm;
- aValue->correctedPositionY -= cl;
+ 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:
- aValue->correctedPositionX -= cl * cm;
- aValue->correctedPositionY += ch;
+ 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:
- aValue->correctedPositionX += ch * cm;
- aValue->correctedPositionY += cl;
+ 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;
@@ -455,6 +547,7 @@ void InitTTextValue( TTEXTVALUE* aTextValue )
aTextValue->textUnit = 0;
aTextValue->correctedPositionX = 0;
aTextValue->correctedPositionY = 0;
+ aTextValue->justify = LowerLeft;
}
} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
index 35877c1..ce61cc2 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
@@ -39,6 +39,19 @@ namespace PCAD2KICAD
#define PCAD2KICAD_SCALE_SCH_TO_INCH_GRID
+enum TTEXT_JUSTIFY
+{
+ LowerLeft,
+ LowerCenter,
+ LowerRight,
+ UpperLeft,
+ UpperCenter,
+ UpperRight,
+ Left,
+ Center,
+ Right
+};
+
typedef struct _TTEXTVALUE
{
wxString text;
@@ -46,6 +59,7 @@ typedef struct _TTEXTVALUE
textRotation, textHeight, textstrokeWidth;
int textIsVisible, mirror, textUnit;
int correctedPositionX, correctedPositionY;
+ TTEXT_JUSTIFY justify;
} TTEXTVALUE;
extern wxString GetWord( wxString* aStr );
@@ -69,6 +83,7 @@ extern void SetDoublePrecisionPosition( wxString aStr,
double* aX,
double* aY,
wxString aActualConversion );
+extern TTEXT_JUSTIFY GetJustifyIdentificator( wxString aJustify );
extern void SetTextParameters( XNODE* aNode,
TTEXTVALUE* aTextValue,
wxString aDefaultMeasurementUnit,
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
index 8eb66a7..5bcf7d9 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -623,8 +623,6 @@ void PCB_MODULE::Flip()
// Flipped
m_KiCadLayer = FlipLayer( m_KiCadLayer );
m_rotation = -m_rotation;
- m_name.mirror = m_mirror;
- 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 51f0f14..db8b57f 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp
@@ -78,6 +78,9 @@ void PCB_TEXT::Parse( XNODE* aNode,
aNode->GetAttribute( wxT( "Name" ), &m_name.text );
+ str = FindNodeGetContent( aNode, wxT( "justify" ) );
+ m_name.justify = GetJustifyIdentificator( str );
+
str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
if( str == wxT( "True" ) )
--
2.5.0
Follow ups
References