← Back to team overview

kicad-developers team mailing list archive

[PATCH] fix position of text and refdes from PCAD import

 

Hello. Patch attached.  
P.S. need work to correct a justification of text and text size (I do)  

>From f5647e191d15e833164076fcd8f35981513e4a98 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
Date: Mon, 22 Feb 2016 19:46:16 +0300
Subject: [PATCH] Fix position of text and refdes for PCAD import

---
 pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 64 ++++++++++-------------
 pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h   |  2 +-
 pcbnew/pcad2kicadpcb_plugin/pcb_component.h       |  6 +--
 pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp        | 17 ++++--
 pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp          | 12 +++--
 5 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
index f588bbc..5fbae08 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
@@ -368,47 +368,37 @@ void SetFontProperty( XNODE*        aNode,
 }
 
 
-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;
+    int cl = KiROUND( ( (double) aValue->text.Len() / 1.4 ) *
+                      ( (double) aValue->textHeight / 1.8 ) );
+    int ch = KiROUND( (double) aValue->textHeight / 3.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 justification (bottom 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..af758ed 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
@@ -77,7 +77,7 @@ extern void         SetFontProperty( XNODE*         aNode,
                                      TTEXTVALUE*    aTextValue,
                                      wxString       aDefaultMeasurementUnit,
                                      wxString       aActualConversion );
-extern void         CorrectTextPosition( TTEXTVALUE* aValue, int aRotation );
+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..ed887ad 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 nand 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..36a43e0 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,14 @@ 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 );
 
     MODULE* module = new MODULE( m_board );
     m_board->Add( module, ADD_APPEND );
@@ -528,7 +534,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 );
@@ -611,7 +619,6 @@ 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;
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


Follow ups