From 3b9c47a1be840bbdcc2b5d1626eebca83da8ed3c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 17 Aug 2020 18:30:35 +0100 Subject: [PATCH] Fixes for rectangle segments in STEP plugin. --- utils/kicad2step/pcb/kicadpcb.cpp | 41 +++++++++++++++++++++++++++++++ utils/kicad2step/pcb/kicadpcb.h | 1 + 2 files changed, 42 insertions(+) diff --git a/utils/kicad2step/pcb/kicadpcb.cpp b/utils/kicad2step/pcb/kicadpcb.cpp index 0cc44e55d7..c6f8acb527 100644 --- a/utils/kicad2step/pcb/kicadpcb.cpp +++ b/utils/kicad2step/pcb/kicadpcb.cpp @@ -226,6 +226,8 @@ bool KICADPCB::parsePCB( SEXPR::SEXPR* data ) result = result && parseCurve( child, CURVE_ARC ); else if( symname == "gr_line" ) result = result && parseCurve( child, CURVE_LINE ); + else if( symname == "gr_rect" ) + result = result && parseRect( child ); else if( symname == "gr_circle" ) result = result && parseCurve( child, CURVE_CIRCLE ); } @@ -377,6 +379,45 @@ bool KICADPCB::parseModule( SEXPR::SEXPR* data ) } +bool KICADPCB::parseRect( SEXPR::SEXPR* data ) +{ + KICADCURVE* mp = new KICADCURVE(); + + if( !mp->Read( data, CURVE_LINE ) ) + { + delete mp; + return false; + } + + // reject any curves not on the Edge.Cuts layer + if( mp->GetLayer() != LAYER_EDGE ) + { + delete mp; + return true; + } + + KICADCURVE* top( mp ); + KICADCURVE* right( mp ); + KICADCURVE* bottom( mp ); + KICADCURVE* left( mp ); + delete mp; + + top->m_end.y = top->m_start.y; + m_curves.push_back( top ); + + right->m_start.x = right->m_end.x; + m_curves.push_back( right ); + + bottom->m_start.y = bottom->m_end.y; + m_curves.push_back( bottom ); + + left->m_end.x = left->m_start.x; + m_curves.push_back( left ); + + return true; +} + + bool KICADPCB::parseCurve( SEXPR::SEXPR* data, CURVE_TYPE aCurveType ) { KICADCURVE* mp = new KICADCURVE(); diff --git a/utils/kicad2step/pcb/kicadpcb.h b/utils/kicad2step/pcb/kicadpcb.h index a88e4eca95..cf2cfd68b6 100644 --- a/utils/kicad2step/pcb/kicadpcb.h +++ b/utils/kicad2step/pcb/kicadpcb.h @@ -80,6 +80,7 @@ private: bool parseLayers( SEXPR::SEXPR* data ); bool parseModule( SEXPR::SEXPR* data ); bool parseCurve( SEXPR::SEXPR* data, CURVE_TYPE aCurveType ); + bool parseRect( SEXPR::SEXPR* data ); public: KICADPCB();