← Back to team overview

kicad-developers team mailing list archive

[PATCH] - an issue with pcad2kicadpcb conversion of stand-alone text objects

 

Fixed not working pcad2kicadpcb conversion of stand-alone text objects.
The bug was introduced in rev. 3681 of pcad2kicad branch (applied S-expressions DSNLEXER to load P-Cad ASCII files).
The patch is against revision 4208 of lp:kicad branch.
=== modified file 'common/wildcards_and_files_ext.cpp'
--- common/wildcards_and_files_ext.cpp	2013-04-25 16:29:35 +0000
+++ common/wildcards_and_files_ext.cpp	2013-06-12 18:01:52 +0000
@@ -72,7 +72,7 @@
 const wxString GerberFileWildcard( _( "Gerber files (*.pho)|*.pho" ) );
 const wxString LegacyPcbFileWildcard( _( "KiCad printed circuit board files (*.brd)|*.brd" ) );
 const wxString EaglePcbFileWildcard( _( "Eagle ver. 6.x XML PCB files (*.brd)|*.brd" ) );
-const wxString PCadPcbFileWildcard( _( "P-Cad 2002/2004 ASCII PCB files (*.pcb)|*.pcb" ) );
+const wxString PCadPcbFileWildcard( _( "P-Cad 200x ASCII PCB files (*.pcb)|*.pcb" ) );
 const wxString PcbFileWildcard( _( "KiCad s-expr printed circuit board files (*.kicad_pcb)|*.kicad_pcb" ) );
 const wxString KiCadFootprintLibFileWildcard( _( "KiCad footprint s-expre library file (*.kicad_mod)|*.kicad_mod" ) );
 const wxString KiCadFootprintLibPathWildcard( _( "KiCad footprint s-expre library path (*.pretty)|*.pretty" ) );

=== modified file 'include/xnode.h'
--- include/xnode.h	2012-12-29 09:54:25 +0000
+++ include/xnode.h	2013-06-08 10:11:07 +0000
@@ -106,15 +106,19 @@
 
     wxString GetAttribute( const wxString& attrName, const wxString& defaultVal ) const
     {
-        return GetPropVal(attrName, defaultVal);
+        return GetPropVal( attrName, defaultVal );
     }
     bool GetAttribute( const wxString& attrName, wxString *value ) const
     {
-        return GetPropVal(attrName, value);
+        return GetPropVal( attrName, value );
     }
     void AddAttribute( const wxString& attrName, const wxString& value )
     {
-        AddProperty(attrName, value);
+        AddProperty( attrName, value );
+    }
+    bool DeleteAttribute( const wxString& attrName )
+    {
+        DeleteProperty( attrName );
     }
     wxXmlProperty* GetAttributes() const
     {

=== modified file 'pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp'
--- pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp	2012-12-29 09:54:25 +0000
+++ pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp	2013-06-08 17:05:18 +0000
@@ -131,7 +131,8 @@
         {
             ls.ToDouble( &i );
 #ifdef PCAD2KICAD_SCALE_SCH_TO_INCH_GRID
-            if( aActualConversion == wxT( "SCH" ) )
+            if( aActualConversion == wxT( "SCH" )
+                || aActualConversion == wxT( "SCHLIB" ) )
                 i = i * (0.0254 / 0.025);
 #endif
             i = Millimeter2iu( i );

=== modified file 'pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp'
--- pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp	2013-03-18 19:36:07 +0000
+++ pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp	2013-06-08 05:23:28 +0000
@@ -76,10 +76,7 @@
         m_rotation = StrToInt1Units( str );
     }
 
-    lNode = FindNode( aNode, wxT( "value" ) );
-
-    if( lNode )
-        m_name.text = lNode->GetNodeContent();
+    aNode->GetAttribute( wxT( "Name" ), &m_name.text );
 
     str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
 

=== modified file 'pcbnew/pcad2kicadpcb_plugin/s_expr_loader.cpp'
--- pcbnew/pcad2kicadpcb_plugin/s_expr_loader.cpp	2013-03-09 19:36:31 +0000
+++ pcbnew/pcad2kicadpcb_plugin/s_expr_loader.cpp	2013-06-08 05:24:43 +0000
@@ -39,9 +39,7 @@
 {
     int       tok;
     XNODE*    iNode = NULL, *cNode = NULL;
-    wxString  str;
-    bool      growing = false;
-    bool      attr = false;
+    wxString  str, propValue, content;
     wxCSConv  conv( wxT( "windows-1251" ) );
 
     FILE* fp = wxFopen( aFileName, wxT( "rt" ) );
@@ -56,21 +54,6 @@
 
     while( ( tok = lexer.NextTok() ) != DSN_EOF )
     {
-        if( growing && ( tok == DSN_LEFT || tok == DSN_RIGHT ) )
-        {
-            if( attr )
-            {
-                cNode->AddAttribute( wxT( "Name" ), str.Trim( false ) );
-            }
-            else if( str != wxEmptyString )
-            {
-                cNode->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, str ) );
-            }
-
-            growing = false;
-            attr = false;
-        }
-
         if( tok == DSN_RIGHT )
         {
             iNode = iNode->GetParent();
@@ -82,14 +65,33 @@
             cNode = new XNODE( wxXML_ELEMENT_NODE, wxString( lexer.CurText(), conv ) );
             iNode->AddChild( cNode );
             iNode = cNode;
-            growing = true;
         }
-        else
+        else if( cNode )
         {
-            str += wxT( ' ' );
-            str += wxString( lexer.CurText(), conv );
+            str = wxString( lexer.CurText(), conv );
             if( tok == DSN_STRING )
-                attr = true;
+            {
+                // update attribute
+                if( iNode->GetAttribute( wxT( "Name" ), &propValue ) )
+                {
+                    iNode->DeleteAttribute( wxT( "Name" ) );
+                    iNode->AddAttribute( wxT( "Name" ), propValue + wxT( ' ' ) + str );
+                }
+                else
+                    iNode->AddAttribute( wxT( "Name" ), str );
+            }
+            else if( str != wxEmptyString )
+            {
+                // update node content
+                content = cNode->GetNodeContent() + wxT( ' ' ) + str;
+
+                if( cNode->GetChildren() )
+                    cNode->GetChildren()->SetContent( content );
+                else
+                    cNode->AddChild( new wxXmlNode( wxXML_TEXT_NODE,
+                                                    wxEmptyString,
+                                                    content ) );
+            }
         }
     }
 


Follow ups