API: implement serialization for ZONE
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
#include <api/api_utils.h>
|
||||
#include <geometry/shape_poly_set.h>
|
||||
|
||||
namespace kiapi::common
|
||||
{
|
||||
@@ -146,4 +147,48 @@ SHAPE_LINE_CHAIN UnpackPolyLine( const kiapi::common::types::PolyLine& aInput )
|
||||
return slc;
|
||||
}
|
||||
|
||||
|
||||
void PackPolySet( types::PolySet& aOutput, const SHAPE_POLY_SET& aInput )
|
||||
{
|
||||
for( int idx = 0; idx < aInput.OutlineCount(); ++idx )
|
||||
{
|
||||
const SHAPE_POLY_SET::POLYGON& poly = aInput.Polygon( idx );
|
||||
|
||||
if( poly.empty() )
|
||||
continue;
|
||||
|
||||
types::PolygonWithHoles* polyMsg = aOutput.mutable_polygons()->Add();
|
||||
PackPolyLine( *polyMsg->mutable_outline(), poly.front() );
|
||||
|
||||
if( poly.size() > 1 )
|
||||
{
|
||||
for( size_t hole = 1; hole < poly.size(); ++hole )
|
||||
{
|
||||
types::PolyLine* pl = polyMsg->mutable_holes()->Add();
|
||||
PackPolyLine( *pl, poly[hole] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SHAPE_POLY_SET UnpackPolySet( const types::PolySet& aInput )
|
||||
{
|
||||
SHAPE_POLY_SET sps;
|
||||
|
||||
for( const types::PolygonWithHoles& polygonWithHoles : aInput.polygons() )
|
||||
{
|
||||
SHAPE_POLY_SET::POLYGON polygon;
|
||||
|
||||
polygon.emplace_back( UnpackPolyLine( polygonWithHoles.outline() ) );
|
||||
|
||||
for( const types::PolyLine& holeMsg : polygonWithHoles.holes() )
|
||||
polygon.emplace_back( UnpackPolyLine( holeMsg ) );
|
||||
|
||||
sps.AddPolygon( polygon );
|
||||
}
|
||||
|
||||
return sps;
|
||||
}
|
||||
|
||||
} // namespace kiapi::common
|
||||
|
||||
Reference in New Issue
Block a user