← Back to team overview

kicad-developers team mailing list archive

Re: Bug 1754130

 

Here's a patch to import the netclasses from eagle.

As already mentioned, all nets without a label are in the default
netclass. The clearances are ignored because I have no idea what clearance
to use. The trackwidths are ignored, I've never used that and saw no
reason to fix this since the patch isn't that usefull anyway.

regards,

Mark.

Seth Hillbrand <seth@xxxxxxxxxxxxx> wrote:

	<div dir='auto'>Hi Mark-<div dir="auto"><br></div><div dir="auto">That would be great, thanks!</div><div dir="auto"><br></div><div dir="auto">-Seth</div></div>
>From c5f78b33f2020ac78b0fb7b40f457b7e73bbd4db Mon Sep 17 00:00:00 2001
From: Mark van Doesburg <mark.vandoesburg@xxxxxxxxx>
Date: Fri, 13 Jul 2018 09:31:13 +0200
Subject: [PATCH] Copy netclasses during eagle import.

---
 pcbnew/eagle_plugin.cpp | 51 +++++++++++++++++++++++++++++++++++++----
 pcbnew/eagle_plugin.h   | 19 +++++++++++++++
 2 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp
index b676bad50..e9bd51e77 100644
--- a/pcbnew/eagle_plugin.cpp
+++ b/pcbnew/eagle_plugin.cpp
@@ -171,7 +171,6 @@ void ERULES::parse( wxXmlNode* aRules )
     }
 }
 
-
 EAGLE_PLUGIN::EAGLE_PLUGIN() :
     m_rules( new ERULES() ),
     m_xpath( new XPATH() ),
@@ -341,6 +340,9 @@ void EAGLE_PLUGIN::loadAllSections( wxXmlNode* aDoc )
         wxXmlNode* designrules = boardChildren["designrules"];
         loadDesignRules( designrules );
 
+        wxXmlNode*  net_classes = boardChildren["classes"];
+        loadNetClasses( net_classes );
+
         m_xpath->pop();
     }
 
@@ -385,6 +387,40 @@ void EAGLE_PLUGIN::loadDesignRules( wxXmlNode* aDesignRules )
     }
 }
 
+void EAGLE_PLUGIN::loadNetClasses( wxXmlNode* NetClasses )
+{
+    m_xpath->push( "classes" );
+    auto stod = []( wxString i ) { return std::stod( static_cast<std::string>( i ) ); };
+    auto stoul = []( wxString i ) { return std::stoul( static_cast<std::string>( i ) ); };
+    for( wxXmlNode* child = NetClasses->GetChildren(); child; child = child->GetNext() )
+    {
+        if( child->GetName() != "class" )
+            continue;
+        auto name = child->GetAttribute( "name" );
+        auto number = stoul( child->GetAttribute( "number" ) );
+        auto width = stod( child->GetAttribute( "width" ) );
+        auto drill = stod( child->GetAttribute( "drill" ) );
+        if( m_classes.size() <= number )
+            m_classes.resize( number + 1 );
+        m_classes[number] = ECLASS( name, number, width, drill );
+        std::cerr << "Netclass " << name << " " << number << " " << width << " " << drill
+                  << std::endl;
+        for( auto& p : m_classes )
+            p.clearance.resize( m_classes.size() );
+        /* Doesn't work ?
+	for(wxXmlNode* clearance = child->GetChildren(); clearance; clearance = clearance->GetNext()) {
+	    if(clearance->GetName() != "clearance")
+		continue;
+	    auto other=stoi(child->GetAttribute("class"));
+	    auto value=stod(child->GetAttribute("value"));
+	    m_classes[number].clearance[other]=value;
+	}
+	*/
+        m_classes[number].ptr = std::make_shared<NETCLASS>( name );
+        m_board->GetDesignSettings().m_NetClasses.Add( m_classes[number].ptr );
+    }
+    m_xpath->pop(); // "classes"
+}
 
 void EAGLE_PLUGIN::loadLayerDefs( wxXmlNode* aLayers )
 {
@@ -843,7 +879,6 @@ void EAGLE_PLUGIN::loadLibraries( wxXmlNode* aLibs )
     m_xpath->pop();
 }
 
-
 void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
 {
     if( !aElements )
@@ -1903,8 +1938,15 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
         zones.clear();
 
         const wxString& netName = escapeName( net->GetAttribute( "name" ) );
+
         m_board->Add( new NETINFO_ITEM( m_board, netName, netCode ) );
 
+	auto netClass = net -> GetAttribute( "class" );
+	if( netClass.length() )
+	{
+	    m_classes[std::stoi( static_cast<std::string>( netClass ) )].ptr->Add( netName );
+	}
+
         m_xpath->Value( netName.c_str() );
 
         // Get the first net item and iterate
@@ -1996,7 +2038,6 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
 
                 m_xpath->pop();
             }
-
             else if( itemName == "via" )
             {
                 m_xpath->push( "via" );
@@ -2064,7 +2105,6 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
 
                 m_xpath->pop();
             }
-
             else if( itemName == "contactref" )
             {
                 m_xpath->push( "contactref" );
@@ -2082,7 +2122,6 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
 
                 sawPad = true;
             }
-
             else if( itemName == "polygon" )
             {
                 m_xpath->push( "polygon" );
@@ -2117,6 +2156,8 @@ void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
         // Get next signal
         net = net->GetNext();
     }
+    m_board->SynchronizeNetsAndNetClasses();
+
 
     m_xpath->pop();     // "signals.signal"
 }
diff --git a/pcbnew/eagle_plugin.h b/pcbnew/eagle_plugin.h
index e3df6d535..0a7b0605f 100644
--- a/pcbnew/eagle_plugin.h
+++ b/pcbnew/eagle_plugin.h
@@ -101,6 +101,23 @@ struct ERULES
     void parse( wxXmlNode* aRules );
 };
 
+struct ECLASS
+{
+    wxString                  name;
+    int                       number;
+    double                    width;
+    double                    drill;
+    std::vector<double>       clearance;
+    std::shared_ptr<NETCLASS> ptr;
+    ECLASS( void ) : number( -1 )
+    {
+    }
+    ECLASS( wxString const& n, int num, double w, double d )
+            : name( n ), number( num ), width( w ), drill( d )
+    {
+    }
+};
+
 /**
  * Class EAGLE_PLUGIN
  * works with Eagle 6.x XML board files and footprints to implement the
@@ -163,6 +180,7 @@ private:
     std::map<int, ELAYER> m_eagleLayers; ///< Eagle layers data stored by the layer number
 
     ERULES*     m_rules;            ///< Eagle design rules.
+    std::vector<ECLASS> m_classes;  ///< Eagle net classes.
     XPATH*      m_xpath;            ///< keeps track of what we are working on within
                                     ///< XML document during a Load().
 
@@ -213,6 +231,7 @@ private:
 
     void loadAllSections( wxXmlNode* aDocument );
     void loadDesignRules( wxXmlNode* aDesignRules );
+    void loadNetClasses( wxXmlNode* aNetClasses );
     void loadLayerDefs( wxXmlNode* aLayers );
     void loadPlain( wxXmlNode* aPlain );
     void loadSignals( wxXmlNode* aSignals );
-- 
2.19.1


Follow ups

References