← Back to team overview

kicad-developers team mailing list archive

Fwd: [PATCH] Eagle board importer fixes

 

Hi all,

I have two patches right now, one is a little higher priority than the
other.

The first is eagle_keepout_area_fix.patch. When I "fixed" importing
polygons in the eagle importer a few months ago I neglected to handle
keepout areas which causes a segfault if you try to open an eagle board
with a keepout. This patch fixes this.

The second patch adds the ability to import dimensions from eagle.

Wayne - I'll let you decide whether or not to accept either of these
patches. I would like to see the first applied for the release since it
causes a segfault, but the second one could wait until after the release.

Thanks!
Jon
From 38f8fdd2c84676c508a3335ca04f32187fefbee4 Mon Sep 17 00:00:00 2001
From: Jon Neal <reportingsjr@xxxxxxxxx>
Date: Thu, 12 Nov 2015 18:11:16 -0500
Subject: [PATCH] The eagle importer now imports keepout zones and does not
 segfault on them.

---
 pcbnew/eagle_plugin.cpp | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp
index 05f2783..3f120ab 100644
--- a/pcbnew/eagle_plugin.cpp
+++ b/pcbnew/eagle_plugin.cpp
@@ -849,7 +849,7 @@ struct EPOLYGON
         HATCH,
         CUTOUT,
     };
-    opt_int     pour;
+    int         pour = EPOLYGON::SOLID;
     opt_double  isolate;
     opt_bool    orphans;
     opt_bool    thermals;
@@ -888,8 +888,6 @@ EPOLYGON::EPOLYGON( CPTREE& aPolygon )
             pour = EPOLYGON::HATCH;
         else if( !s->compare( "cutout" ) )
             pour = EPOLYGON::CUTOUT;
-        else
-            pour = EPOLYGON::SOLID;
     }
 
     orphans  = parseOptionalBool( attribs, "orphans" );
@@ -2525,7 +2523,6 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
             (void) breakhere;
         }
 #endif
-
         // (contactref | polygon | wire | via)*
         for( CITER it = net->second.begin();  it != net->second.end();  ++it )
         {
@@ -2658,8 +2655,6 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
                     zone->SetLayer( layer );
                     zone->SetNetCode( netCode );
 
-                    CPolyLine::HATCH_STYLE outline_hatch = CPolyLine::DIAGONAL_EDGE;
-
                     bool first = true;
                     for( CITER vi = it->second.begin();  vi != it->second.end();  ++vi )
                     {
@@ -2672,7 +2667,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
                         if( first )
                         {
                             zone->Outline()->Start( layer,  kicad_x( v.x ), kicad_y( v.y ),
-                                                    outline_hatch );
+                                                    CPolyLine::NO_HATCH);
                             first = false;
                         }
                         else
@@ -2681,14 +2676,19 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
 
                     zone->Outline()->CloseLastContour();
 
-                    // If pour is set the zone should be hatched,
-                    // set the hatch size from the spacing variable.
-                    if( p.pour )
+                    // If the pour is a cutout it needs to be set to a keepout
+                    if( p.pour == EPOLYGON::CUTOUT )
                     {
-                        zone->Outline()->SetHatch( outline_hatch,
+                        zone->SetIsKeepout( true );
+                        zone->SetDoNotAllowCopperPour( true );
+                        zone->Outline()->SetHatchStyle( CPolyLine::NO_HATCH );
+                    }
+
+                    // if spacing is set the zone should be hatched
+                    if( p.spacing )
+                        zone->Outline()->SetHatch( CPolyLine::DIAGONAL_EDGE,
                                                    *p.spacing,
                                                    true );
-                    }
 
                     // clearances, etc.
                     zone->SetArcSegmentCount( 32 );     // @todo: should be a constructor default?
From 84f0c676a35e6fc44b9cb900043665c6e76bdd76 Mon Sep 17 00:00:00 2001
From: Jon Neal <reportingsjr@xxxxxxxxx>
Date: Sat, 14 Nov 2015 16:04:50 -0500
Subject: [PATCH 1/1] The eagle importer now supports dimensions.

---
 pcbnew/eagle_plugin.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp
index 00b7635..1cb03fe 100644
--- a/pcbnew/eagle_plugin.cpp
+++ b/pcbnew/eagle_plugin.cpp
@@ -74,6 +74,7 @@ Load() TODO's
 #include <class_edge_mod.h>
 #include <class_zone.h>
 #include <class_pcb_text.h>
+#include <class_dimension.h>
 
 using namespace boost::property_tree;
 using namespace std;
@@ -533,6 +534,54 @@ EATTR::EATTR( CPTREE& aAttribute )
     }
 }
 
+/// Eagle dimension element
+struct EDIMENSION
+{
+    double      x1;
+    double      y1;
+    double      x2;
+    double      y2;
+    double      x3;
+    double      y3;
+    int         layer;
+
+    opt_string dimensionType;
+
+    EDIMENSION( CPTREE& aDimension );
+};
+
+EDIMENSION::EDIMENSION( CPTREE& aDimension )
+{
+    CPTREE& attribs = aDimension.get_child( "<xmlattr>" );
+
+    /*
+    <!ELEMENT dimension EMPTY>
+    <!ATTLIST dimension
+          x1            %Coord;        #REQUIRED
+          y1            %Coord;        #REQUIRED
+          x2            %Coord;        #REQUIRED
+          y2            %Coord;        #REQUIRED
+          x3            %Coord;        #REQUIRED
+          y3            %Coord;        #REQUIRED
+          layer         %Layer;        #REQUIRED
+          dtype         %DimensionType; "parallel"
+          >
+    */
+
+    x1      = attribs.get<double>( "x1" );
+    y1      = attribs.get<double>( "y1" );
+    x2      = attribs.get<double>( "x2" );
+    y2      = attribs.get<double>( "y2" );
+    x3      = attribs.get<double>( "x3" );
+    y3      = attribs.get<double>( "y3" );
+    layer   = attribs.get<int>( "layer" );
+
+    opt_string dimensionType = attribs.get_optional<string>( "dtype" );
+    if(!dimensionType)
+    {
+        // default type is parallel
+    }
+}
 
 /// Eagle text element
 struct ETEXT
@@ -1620,6 +1669,39 @@ void EAGLE_PLUGIN::loadPlain( CPTREE& aGraphics )
             // could be on a copper layer, could be on another layer.
             // copper layer would be done using netCode=0 type of ZONE_CONTAINER.
         }
+        else if( gr->first == "dimension" )
+        {
+            EDIMENSION d( gr->second );
+
+            DIMENSION* dimension = new DIMENSION( m_board );
+            m_board->Add( dimension, ADD_APPEND );
+
+            dimension->SetLayer( kicad_layer( d.layer ) );
+            // The origin and end are assumed to always be in this order from eagle
+            dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) );
+            dimension->SetEnd( wxPoint( kicad_x( d.x2 ), kicad_y( d.y2 ) ) );
+            dimension->Text().SetSize( m_board->GetDesignSettings().m_PcbTextSize );
+
+            int width = m_board->GetDesignSettings().m_PcbTextWidth;
+            int maxThickness = Clamp_Text_PenSize( width, dimension->Text().GetSize() );
+
+            if( width > maxThickness )
+                width = maxThickness;
+
+            dimension->Text().SetThickness( width );
+            dimension->SetWidth( width );
+
+            // check which axis the dimension runs in
+            // because the "height" of the dimension is perpendicular to that axis
+            // Note the check is just if two axes are close enough to each other
+            // Eagle appears to have some rounding errors
+            if( fabs( d.x1 - d.x2 ) < 0.05 )
+                dimension->SetHeight( kicad_x( d.x1 - d.x3 ) );
+            else
+                dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
+
+            dimension->AdjustDimensionDetails();
+         }
     }
     m_xpath->pop();
 }
-- 
2.4.3


Follow ups