CADSTAR SCH: Load symbol shapes with correct fill state

Changes architecture of importer to use SHAPE_LINE_CHAIN.

For now lets just load symbol shapes like this, but we could update code
for all other loading operations (also in PCB).

FIxes https://gitlab.com/kicad/code/kicad/-/issues/8060
This commit is contained in:
Roberto Fernandez Bautista 2023-01-10 22:25:28 +01:00
parent ebce53d574
commit 99d02ac7c0
4 changed files with 65 additions and 23 deletions

View File

@ -483,7 +483,8 @@ void CADSTAR_ARCHIVE_PARSER::VERTEX::Parse( XNODE* aNode, PARSER_CONTEXT* aConte
void CADSTAR_ARCHIVE_PARSER::VERTEX::AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo, void CADSTAR_ARCHIVE_PARSER::VERTEX::AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo,
const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback ) const const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
double aAccuracy ) const
{ {
VECTOR2I endPoint = aCadstarToKicadPointCallback( End ); VECTOR2I endPoint = aCadstarToKicadPointCallback( End );
@ -517,7 +518,7 @@ void CADSTAR_ARCHIVE_PARSER::VERTEX::AppendToChain( SHAPE_LINE_CHAIN* aChainToAp
SHAPE_ARC arc; SHAPE_ARC arc;
arc.ConstructFromStartEndCenter( startPoint, endPoint, centerPoint, clockwise ); arc.ConstructFromStartEndCenter( startPoint, endPoint, centerPoint, clockwise );
aChainToAppendTo->Append( arc ); aChainToAppendTo->Append( arc, aAccuracy );
} }
@ -586,38 +587,54 @@ void CADSTAR_ARCHIVE_PARSER::SHAPE::Parse( XNODE* aNode, PARSER_CONTEXT* aContex
} }
SHAPE_LINE_CHAIN CADSTAR_ARCHIVE_PARSER::SHAPE::OutlineAsChain( SHAPE_LINE_CHAIN CADSTAR_ARCHIVE_PARSER::SHAPE::OutlineAsChain(
const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback ) const const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
double aAccuracy ) const
{ {
SHAPE_LINE_CHAIN outline; SHAPE_LINE_CHAIN outline;
if( Vertices.size() == 0 )
return outline;
for( const auto& vertex : Vertices ) for( const auto& vertex : Vertices )
vertex.AppendToChain( &outline, aCadstarToKicadPointCallback ); vertex.AppendToChain( &outline, aCadstarToKicadPointCallback, aAccuracy );
if( Type != SHAPE_TYPE::OPENSHAPE ) if( Type != SHAPE_TYPE::OPENSHAPE )
{
outline.SetClosed( true ); outline.SetClosed( true );
// Append after closing, to ensre first and last point remain the same
Vertices.at( 0 ).AppendToChain( &outline, aCadstarToKicadPointCallback, aAccuracy );
}
return outline; return outline;
} }
SHAPE_POLY_SET CADSTAR_ARCHIVE_PARSER::SHAPE::ConvertToPolySet( SHAPE_POLY_SET CADSTAR_ARCHIVE_PARSER::SHAPE::ConvertToPolySet(
const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback ) const const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
double aAccuracy ) const
{ {
SHAPE_POLY_SET polyset; SHAPE_POLY_SET polyset;
wxCHECK( Type != SHAPE_TYPE::OPENSHAPE, polyset ); // We shouldn't convert openshapes to polyset! wxCHECK( Type != SHAPE_TYPE::OPENSHAPE, polyset ); // We shouldn't convert openshapes to polyset!
polyset.AddOutline( OutlineAsChain( aCadstarToKicadPointCallback) ); polyset.AddOutline( OutlineAsChain( aCadstarToKicadPointCallback, aAccuracy ) );
for( const auto& cutout : Cutouts ) for( const auto& cutout : Cutouts )
{ {
SHAPE_LINE_CHAIN hole; SHAPE_LINE_CHAIN hole;
if( cutout.Vertices.size() == 0 )
continue;
for( const auto& cutoutVertex : cutout.Vertices ) for( const auto& cutoutVertex : cutout.Vertices )
cutoutVertex.AppendToChain( &hole, aCadstarToKicadPointCallback ); cutoutVertex.AppendToChain( &hole, aCadstarToKicadPointCallback, aAccuracy );
hole.SetClosed( true ); hole.SetClosed( true );
// Append after closing, to ensre first and last point remain the same
cutout.Vertices.at( 0 ).AppendToChain( &hole, aCadstarToKicadPointCallback, aAccuracy );
polyset.AddHole( hole ); polyset.AddHole( hole );
} }

View File

@ -449,7 +449,8 @@ public:
void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override; void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
void AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo, void AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo,
const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback ) const; const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
double aAccuracy ) const;
}; };
/** /**
@ -483,10 +484,12 @@ public:
void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override; void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
SHAPE_LINE_CHAIN OutlineAsChain( const std::function<VECTOR2I( const VECTOR2I& )> SHAPE_LINE_CHAIN OutlineAsChain( const std::function<VECTOR2I( const VECTOR2I& )>
aCadstarToKicadPointCallback ) const; aCadstarToKicadPointCallback,
double aAccuracy ) const;
SHAPE_POLY_SET ConvertToPolySet( const std::function<VECTOR2I( const VECTOR2I& )> SHAPE_POLY_SET ConvertToPolySet( const std::function<VECTOR2I( const VECTOR2I& )>
aCadstarToKicadPointCallback ) const; aCadstarToKicadPointCallback,
double aAccuracy ) const;
}; };

View File

@ -1324,15 +1324,36 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
{ {
FIGURE fig = figPair.second; FIGURE fig = figPair.second;
int lineThickness = getLineThickness( fig.LineCodeID ); int lineThickness = getLineThickness( fig.LineCodeID );
PLOT_DASH_TYPE linestyle = getLineStyle( fig.LineCodeID );
loadLibrarySymbolShapeVertices( fig.Shape.Vertices, symbol.Origin, aSymbol, gateNumber, if( fig.Shape.Type == SHAPE_TYPE::OPENSHAPE )
lineThickness );
for( CUTOUT c : fig.Shape.Cutouts )
{ {
loadLibrarySymbolShapeVertices( c.Vertices, symbol.Origin, aSymbol, gateNumber, loadLibrarySymbolShapeVertices( fig.Shape.Vertices, symbol.Origin, aSymbol, gateNumber,
lineThickness ); lineThickness );
} }
else
{
LIB_SHAPE* shape = new LIB_SHAPE( aSymbol, SHAPE_T::POLY );
shape->SetPolyShape( fig.Shape.ConvertToPolySet(
[&]( const VECTOR2I& aPt )
{
return getKiCadLibraryPoint( aPt, symbol.Origin );
},
ARC_ACCURACY ) );
shape->SetUnit( gateNumber );
shape->SetStroke( STROKE_PARAMS( lineThickness, linestyle ) );
if( fig.Shape.Type == SHAPE_TYPE::SOLID )
shape->SetFillMode( FILL_T::FILLED_SHAPE );
else if( fig.Shape.Type == SHAPE_TYPE::OUTLINE )
shape->SetFillMode( FILL_T::NO_FILL );
else if( fig.Shape.Type == SHAPE_TYPE::HATCHED ) // We don't have an equivalent
shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
aSymbol->AddDrawItem( shape );
}
} }
TERMINAL_TO_PINNUM_MAP pinNumMap; TERMINAL_TO_PINNUM_MAP pinNumMap;
@ -1647,9 +1668,9 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices( const std::vect
LIB_SHAPE* shape = nullptr; LIB_SHAPE* shape = nullptr;
bool cw = false; bool cw = false;
wxPoint startPoint = getKiCadLibraryPoint( prev->End, aSymbolOrigin ); VECTOR2I startPoint = getKiCadLibraryPoint( prev->End, aSymbolOrigin );
wxPoint endPoint = getKiCadLibraryPoint( cur->End, aSymbolOrigin ); VECTOR2I endPoint = getKiCadLibraryPoint( cur->End, aSymbolOrigin );
wxPoint centerPoint; VECTOR2I centerPoint;
if( cur->Type == VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE if( cur->Type == VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE
|| cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE ) || cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE )
@ -2094,7 +2115,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& a
// TODO: Load as arc... // TODO: Load as arc...
SHAPE_ARC tempArc( centerPoint, startPoint, arcAngle ); SHAPE_ARC tempArc( centerPoint, startPoint, arcAngle );
SHAPE_LINE_CHAIN arcSegments = tempArc.ConvertToPolyline( schIUScale.mmToIU( 0.1 ) ); SHAPE_LINE_CHAIN arcSegments = tempArc.ConvertToPolyline( ARC_ACCURACY );
// Load the arc as a series of piece-wise segments // Load the arc as a series of piece-wise segments
@ -3040,10 +3061,10 @@ VECTOR2I CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPoint( const VECTOR2I& aCadstarPoin
} }
wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint( const wxPoint& aCadstarPoint, VECTOR2I CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint( const VECTOR2I& aCadstarPoint,
const wxPoint& aCadstarCentre ) const VECTOR2I& aCadstarCentre )
{ {
wxPoint retval; VECTOR2I retval;
retval.x = getKiCadLength( aCadstarPoint.x - aCadstarCentre.x ); retval.x = getKiCadLength( aCadstarPoint.x - aCadstarCentre.x );
retval.y = getKiCadLength( aCadstarPoint.y - aCadstarCentre.y ); retval.y = getKiCadLength( aCadstarPoint.y - aCadstarCentre.y );

View File

@ -54,6 +54,7 @@ class CADSTAR_SCH_ARCHIVE_LOADER : public CADSTAR_SCH_ARCHIVE_PARSER
public: public:
// Size of tiny net labels when none present in original design // Size of tiny net labels when none present in original design
const int SMALL_LABEL_SIZE = KiROUND( (double) SCH_IU_PER_MM * 0.4 ); const int SMALL_LABEL_SIZE = KiROUND( (double) SCH_IU_PER_MM * 0.4 );
const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01; // 0.01mm
explicit CADSTAR_SCH_ARCHIVE_LOADER( wxString aFilename, REPORTER* aReporter, explicit CADSTAR_SCH_ARCHIVE_LOADER( wxString aFilename, REPORTER* aReporter,
PROGRESS_REPORTER* aProgressReporter ) : PROGRESS_REPORTER* aProgressReporter ) :
@ -234,7 +235,7 @@ private:
VECTOR2I getKiCadPoint( const VECTOR2I& aCadstarPoint ); VECTOR2I getKiCadPoint( const VECTOR2I& aCadstarPoint );
wxPoint getKiCadLibraryPoint( const wxPoint& aCadstarPoint, const wxPoint& aCadstarCentre ); VECTOR2I getKiCadLibraryPoint( const VECTOR2I& aCadstarPoint, const VECTOR2I& aCadstarCentre );
VECTOR2I applyTransform( const VECTOR2I& aPoint, const VECTOR2I& aMoveVector = { 0, 0 }, VECTOR2I applyTransform( const VECTOR2I& aPoint, const VECTOR2I& aMoveVector = { 0, 0 },
const EDA_ANGLE& aRotation = ANGLE_0, const EDA_ANGLE& aRotation = ANGLE_0,