From b5982f73196ff8c0e70da7d7a7578fe4f5468911 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 11 Feb 2024 23:46:24 +0300 Subject: [PATCH] EasyEDA import: force close some line chains. --- common/io/easyeda/easyeda_parser_base.cpp | 14 ++++++++++++-- common/io/easyeda/easyeda_parser_base.h | 3 ++- .../sch_io/easyeda/sch_easyeda_parser.cpp | 4 ++-- .../pcb_io/easyeda/pcb_io_easyeda_parser.cpp | 19 +++++++++++-------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/common/io/easyeda/easyeda_parser_base.cpp b/common/io/easyeda/easyeda_parser_base.cpp index 653f639ff8..3305c56b98 100644 --- a/common/io/easyeda/easyeda_parser_base.cpp +++ b/common/io/easyeda/easyeda_parser_base.cpp @@ -66,8 +66,8 @@ double EASYEDA_PARSER_BASE::RelPosY( const wxString& aValue ) } -std::vector EASYEDA_PARSER_BASE::ParseLineChains( const wxString& data, - int aArcMinSegLen ) +std::vector +EASYEDA_PARSER_BASE::ParseLineChains( const wxString& data, int aArcMinSegLen, bool aForceClosed ) { std::vector result; @@ -109,7 +109,12 @@ std::vector EASYEDA_PARSER_BASE::ParseLineChains( const wxStri readNumber( yStr ); if( chain.PointCount() > 1 ) + { + if( aForceClosed ) + chain.SetClosed( true ); + result.emplace_back( chain ); + } chain.Clear(); @@ -229,7 +234,12 @@ std::vector EASYEDA_PARSER_BASE::ParseLineChains( const wxStri } while( pos < data.size() ); if( chain.PointCount() > 1 ) + { + if( aForceClosed ) + chain.SetClosed( true ); + result.emplace_back( chain ); + } return result; } \ No newline at end of file diff --git a/common/io/easyeda/easyeda_parser_base.h b/common/io/easyeda/easyeda_parser_base.h index 64b7bf50fe..ab29290b01 100644 --- a/common/io/easyeda/easyeda_parser_base.h +++ b/common/io/easyeda/easyeda_parser_base.h @@ -58,7 +58,8 @@ public: return ScalePos( aVec - m_relOrigin ); } - std::vector ParseLineChains( const wxString& aData, int aArcMinSegLen ); + std::vector ParseLineChains( const wxString& aData, int aArcMinSegLen, + bool aForceClosed ); protected: VECTOR2D m_relOrigin; diff --git a/eeschema/sch_io/easyeda/sch_easyeda_parser.cpp b/eeschema/sch_io/easyeda/sch_easyeda_parser.cpp index 7450385538..32bce0c2ba 100644 --- a/eeschema/sch_io/easyeda/sch_easyeda_parser.cpp +++ b/eeschema/sch_io/easyeda/sch_easyeda_parser.cpp @@ -478,7 +478,7 @@ void SCH_EASYEDA_PARSER::ParseSymbolShapes( LIB_SYMBOL* aSymbol aSymbol->AddDrawItem( line.release() ); } - else if( elType == wxS( "PT" ) ) + else if( elType == wxS( "PT" ) ) // Freedraw { wxString pointsData = arr[1]; wxString strokeColor = arr[2]; @@ -488,7 +488,7 @@ void SCH_EASYEDA_PARSER::ParseSymbolShapes( LIB_SYMBOL* aSymbol //bool locked = arr[7] != wxS( "0" ); std::vector lineChains = - ParseLineChains( pointsData, schIUScale.MilsToIU( 10 ) ); + ParseLineChains( pointsData, schIUScale.MilsToIU( 10 ), false ); for( SHAPE_LINE_CHAIN outline : lineChains ) { diff --git a/pcbnew/pcb_io/easyeda/pcb_io_easyeda_parser.cpp b/pcbnew/pcb_io/easyeda/pcb_io_easyeda_parser.cpp index 35096564ec..1bd49c5d43 100644 --- a/pcbnew/pcb_io/easyeda/pcb_io_easyeda_parser.cpp +++ b/pcbnew/pcb_io/easyeda/pcb_io_easyeda_parser.cpp @@ -438,7 +438,7 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer( //double textHeight = !arr[4].IsEmpty() ? ConvertSize( arr[4] ) : 0; std::vector lineChains = - ParseLineChains( shapeData, pcbIUScale.mmToIU( 0.01 ) ); + ParseLineChains( shapeData, pcbIUScale.mmToIU( 0.01 ), false ); std::unique_ptr group = std::make_unique( aContainer ); group->SetName( wxS( "Dimension" ) ); @@ -469,7 +469,8 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer( { wxString layer = arr[1]; - SHAPE_POLY_SET polySet = ParseLineChains( arr[3].Trim(), pcbIUScale.mmToIU( 0.01 ) ); + SHAPE_POLY_SET polySet = + ParseLineChains( arr[3].Trim(), pcbIUScale.mmToIU( 0.01 ), true ); if( layer == wxS( "11" ) ) // Multi-layer (board cutout) { @@ -543,7 +544,8 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer( // Do not fill? } - SHAPE_POLY_SET polySet = ParseLineChains( arr[4].Trim(), pcbIUScale.mmToIU( 0.01 ) ); + SHAPE_POLY_SET polySet = + ParseLineChains( arr[4].Trim(), pcbIUScale.mmToIU( 0.01 ), true ); for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() ) zone->Outline()->AddPolygon( poly ); @@ -564,8 +566,8 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer( { for( const nlohmann::json& contourData : polyData ) { - SHAPE_POLY_SET contourPolySet = ParseLineChains( contourData.get(), - pcbIUScale.mmToIU( 0.01 ) ); + SHAPE_POLY_SET contourPolySet = ParseLineChains( + contourData.get(), pcbIUScale.mmToIU( 0.01 ), true ); SHAPE_POLY_SET currentOutline( contourPolySet.COutline( 0 ) ); @@ -742,10 +744,11 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer( { if( auto dataStr = get_opt( attributes, "d" ) ) { + int minSegLen = dataStr->size() < 8000 ? pcbIUScale.mmToIU( 0.005 ) + : pcbIUScale.mmToIU( 0.05 ); + SHAPE_POLY_SET polySet = - ParseLineChains( dataStr->Trim(), - dataStr->size() < 8000 ? pcbIUScale.mmToIU( 0.005 ) - : pcbIUScale.mmToIU( 0.05 ) ); + ParseLineChains( dataStr->Trim(), minSegLen, true ); polySet.RebuildHolesFromContours();