altium: Use newly introduced RECT shape, apply fill and improve stroke handling (#8741)

This commit is contained in:
Thomas Pointhuber 2021-12-27 16:50:30 +01:00
parent 8b714deae1
commit 82ab04c1d6
2 changed files with 89 additions and 133 deletions

View File

@ -107,6 +107,20 @@ enum class ASCH_RECORD_ORIENTATION
};
struct ASCH_SHAPE_INTERFACE
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
int lineWidth;
bool isSolid;
int color;
int areacolor;
};
struct ASCH_SYMBOL
{
int currentpartid;
@ -330,42 +344,23 @@ struct ASCH_POLYLINE
};
struct ASCH_POLYGON
struct ASCH_POLYGON : ASCH_SHAPE_INTERFACE
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
std::vector<wxPoint> points;
int lineWidth;
bool isSolid;
int color;
int areacolor;
explicit ASCH_POLYGON( const std::map<wxString, wxString>& aProps );
};
struct ASCH_ROUND_RECTANGLE
struct ASCH_ROUND_RECTANGLE : ASCH_SHAPE_INTERFACE
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
wxPoint bottomLeft;
wxPoint topRight;
wxSize cornerradius;
int lineWidth;
bool isSolid;
bool isTransparent;
int color;
int areacolor;
explicit ASCH_ROUND_RECTANGLE( const std::map<wxString, wxString>& aProps );
};
@ -402,22 +397,13 @@ struct ASCH_LINE
};
struct ASCH_RECTANGLE
struct ASCH_RECTANGLE : ASCH_SHAPE_INTERFACE
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
wxPoint bottomLeft;
wxPoint topRight;
int lineWidth;
bool isSolid;
bool isTransparent;
int color;
int areacolor;
explicit ASCH_RECTANGLE( const std::map<wxString, wxString>& aProps );
};

View File

@ -61,14 +61,14 @@
#include <wx/wfstream.h>
#include <trigo.h>
const wxPoint GetRelativePosition( const wxPoint& aPosition, const SCH_SYMBOL* aSymbol )
static const wxPoint GetRelativePosition( const wxPoint& aPosition, const SCH_SYMBOL* aSymbol )
{
TRANSFORM t = aSymbol->GetTransform().InverseTransform();
return t.TransformCoordinate( aPosition - aSymbol->GetPosition() );
}
COLOR4D GetColorFromInt( int color )
static COLOR4D GetColorFromInt( int color )
{
int red = color & 0x0000FF;
int green = ( color & 0x00FF00 ) >> 8;
@ -77,6 +77,53 @@ COLOR4D GetColorFromInt( int color )
return COLOR4D().FromCSSRGBA( red, green, blue, 1.0 );
}
static PLOT_DASH_TYPE GetPlotDashType( const ASCH_POLYLINE_LINESTYLE linestyle )
{
switch( linestyle )
{
case ASCH_POLYLINE_LINESTYLE::SOLID: return PLOT_DASH_TYPE::SOLID;
case ASCH_POLYLINE_LINESTYLE::DASHED: return PLOT_DASH_TYPE::DASH;
case ASCH_POLYLINE_LINESTYLE::DOTTED: return PLOT_DASH_TYPE::DOT;
case ASCH_POLYLINE_LINESTYLE::DASH_DOTTED: return PLOT_DASH_TYPE::DASHDOT;
default: return PLOT_DASH_TYPE::DEFAULT;
}
}
static void SetSchShapeFillAndColor( const ASCH_SHAPE_INTERFACE& elem, SCH_SHAPE* shape )
{
shape->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
if( !elem.isSolid )
{
shape->SetFillMode( FILL_T::NO_FILL );
}
else
{
shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
shape->SetFillColor( GetColorFromInt( elem.areacolor ) );
}
}
static void SetLibShapeFillAndColor( const ASCH_SHAPE_INTERFACE& elem, LIB_SHAPE* shape )
{
shape->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
if( !elem.isSolid )
{
shape->SetFillMode( FILL_T::NO_FILL );
}
else if( elem.color == elem.areacolor )
{
shape->SetFillMode( FILL_T::FILLED_SHAPE );
}
else
{
shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
}
}
SCH_ALTIUM_PLUGIN::SCH_ALTIUM_PLUGIN()
{
m_rootSheet = nullptr;
@ -994,8 +1041,7 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
line->SetLineWidth( elem.lineWidth );
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
line->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
line->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( line );
@ -1007,7 +1053,7 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
std::vector<wxPoint> polyPoints;
for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
bezierPoints.push_back( elem.points.at( j ) + m_sheetOffset );
bezierPoints.push_back( elem.points.at( j ) );
BEZIER_POLY converter( bezierPoints );
converter.GetPoly( polyPoints );
@ -1018,7 +1064,7 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( polyPoints.at( k + 1 ) + m_sheetOffset );
line->SetLineWidth( elem.lineWidth );
line->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
line->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( line );
@ -1116,24 +1162,13 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map<wxString, wxString>& aProp
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
{
PLOT_DASH_TYPE dashType = PLOT_DASH_TYPE::DEFAULT;
switch( elem.linestyle )
{
default:
case ASCH_POLYLINE_LINESTYLE::SOLID: dashType = PLOT_DASH_TYPE::SOLID; break;
case ASCH_POLYLINE_LINESTYLE::DASHED: dashType = PLOT_DASH_TYPE::DASH; break;
case ASCH_POLYLINE_LINESTYLE::DOTTED: dashType = PLOT_DASH_TYPE::DOT; break;
case ASCH_POLYLINE_LINESTYLE::DASH_DOTTED: dashType = PLOT_DASH_TYPE::DASHDOT; break;
}
for( size_t i = 0; i + 1 < elem.points.size(); i++ )
{
SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
line->SetLineWidth( elem.lineWidth );
line->SetLineStyle( dashType );
line->SetStroke( STROKE_PARAMS( elem.lineWidth, GetPlotDashType( elem.linestyle ) ) );
line->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( line );
@ -1164,7 +1199,7 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map<wxString, wxString>& aProp
for( wxPoint& point : elem.points )
line->AddPoint( GetRelativePosition( point + m_sheetOffset, symbol ) );
line->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
line->SetStroke( STROKE_PARAMS( elem.lineWidth, GetPlotDashType( elem.linestyle ) ) );
}
}
@ -1181,8 +1216,7 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
line->SetLineWidth( elem.lineWidth );
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
line->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
line->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( line );
@ -1192,8 +1226,7 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
SCH_LINE* line = new SCH_LINE( elem.points.front() + m_sheetOffset,
SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( elem.points.back() + m_sheetOffset );
line->SetLineWidth( elem.lineWidth );
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
line->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
line->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( line );
@ -1224,15 +1257,7 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
line->AddPoint( GetRelativePosition( point + m_sheetOffset, symbol ) );
line->AddPoint( GetRelativePosition( elem.points.front() + m_sheetOffset, symbol ) );
line->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
if( !elem.isSolid )
line->SetFillMode( FILL_T::NO_FILL );
else if( elem.color == elem.areacolor )
line->SetFillMode( FILL_T::FILLED_SHAPE );
else
line->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
SetLibShapeFillAndColor( elem, line );
}
}
@ -1249,35 +1274,15 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map<wxString, wxString>&
const wxPoint topLeft = { sheetBottomLeft.x, sheetTopRight.y };
const wxPoint bottomRight = { sheetTopRight.x, sheetBottomLeft.y };
// TODO: we cannot fill this rectangle, only draw it for now
// TODO: misses rounded edges
SCH_LINE* lineTop = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
lineTop->SetEndPoint( topLeft );
lineTop->SetLineWidth( elem.lineWidth );
lineTop->SetLineStyle( PLOT_DASH_TYPE::SOLID );
lineTop->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( lineTop );
SCH_SHAPE* rect = new SCH_SHAPE( SHAPE_T::RECT, SCH_LAYER_ID::LAYER_NOTES );
SCH_LINE* lineBottom = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
lineBottom->SetEndPoint( bottomRight );
lineBottom->SetLineWidth( elem.lineWidth );
lineBottom->SetLineStyle( PLOT_DASH_TYPE::SOLID );
lineBottom->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( lineBottom );
rect->SetPosition( sheetTopRight );
rect->SetEnd( sheetBottomLeft );
SetSchShapeFillAndColor( elem, rect );
rect->SetFlags( IS_NEW );
SCH_LINE* lineRight = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
lineRight->SetEndPoint( bottomRight );
lineRight->SetLineWidth( elem.lineWidth );
lineRight->SetLineStyle( PLOT_DASH_TYPE::SOLID );
lineRight->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( lineRight );
SCH_LINE* lineLeft = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
lineLeft->SetEndPoint( topLeft );
lineLeft->SetLineWidth( elem.lineWidth );
lineLeft->SetLineStyle( PLOT_DASH_TYPE::SOLID );
lineLeft->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( lineLeft );
m_currentSheet->GetScreen()->Append( rect );
}
else
{
@ -1304,14 +1309,7 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map<wxString, wxString>&
rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, symbol ) );
rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, symbol ) );
rect->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
if( !elem.isSolid )
rect->SetFillMode( FILL_T::NO_FILL );
else if( elem.color == elem.areacolor )
rect->SetFillMode( FILL_T::FILLED_SHAPE );
else
rect->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
SetLibShapeFillAndColor( elem, rect );
}
}
@ -1413,8 +1411,7 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map<wxString, wxString>& aProperti
// close polygon
SCH_LINE* line = new SCH_LINE( elem.point1 + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( elem.point2 + m_sheetOffset );
line->SetLineWidth( elem.lineWidth );
line->SetLineStyle( PLOT_DASH_TYPE::SOLID ); // TODO?
line->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) ); // TODO?
line->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( line );
@ -1461,34 +1458,14 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map<wxString, wxString>& aPro
const wxPoint topLeft = { sheetBottomLeft.x, sheetTopRight.y };
const wxPoint bottomRight = { sheetTopRight.x, sheetBottomLeft.y };
// TODO: we cannot fill this rectangle, only draw it for now
SCH_LINE* lineTop = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
lineTop->SetEndPoint( topLeft );
lineTop->SetLineWidth( elem.lineWidth );
lineTop->SetLineStyle( PLOT_DASH_TYPE::SOLID );
lineTop->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( lineTop );
SCH_SHAPE* rect = new SCH_SHAPE( SHAPE_T::RECT, SCH_LAYER_ID::LAYER_NOTES );
SCH_LINE* lineBottom = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
lineBottom->SetEndPoint( bottomRight );
lineBottom->SetLineWidth( elem.lineWidth );
lineBottom->SetLineStyle( PLOT_DASH_TYPE::SOLID );
lineBottom->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( lineBottom );
rect->SetPosition( sheetTopRight );
rect->SetEnd( sheetBottomLeft );
SetSchShapeFillAndColor( elem, rect );
rect->SetFlags( IS_NEW );
SCH_LINE* lineRight = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
lineRight->SetEndPoint( bottomRight );
lineRight->SetLineWidth( elem.lineWidth );
lineRight->SetLineStyle( PLOT_DASH_TYPE::SOLID );
lineRight->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( lineRight );
SCH_LINE* lineLeft = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
lineLeft->SetEndPoint( topLeft );
lineLeft->SetLineWidth( elem.lineWidth );
lineLeft->SetLineStyle( PLOT_DASH_TYPE::SOLID );
lineLeft->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( lineLeft );
m_currentSheet->GetScreen()->Append( rect );
}
else
{
@ -1514,14 +1491,7 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map<wxString, wxString>& aPro
rect->SetPosition( GetRelativePosition( sheetTopRight, symbol ) );
rect->SetEnd( GetRelativePosition( sheetBottomLeft, symbol ) );
rect->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );
if( !elem.isSolid )
rect->SetFillMode( FILL_T::NO_FILL );
else if( elem.color == elem.areacolor )
rect->SetFillMode( FILL_T::FILLED_SHAPE );
else
rect->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
SetLibShapeFillAndColor( elem, rect );
}
}