KiCad PCB EDA Suite
STROKE_PARAMS Class Reference

Simple container to manage line stroke parameters. More...

#include <stroke_params.h>

Public Member Functions

 STROKE_PARAMS (int aWidth=0, PLOT_DASH_TYPE aPlotStyle=PLOT_DASH_TYPE::DEFAULT, const KIGFX::COLOR4D &aColor=KIGFX::COLOR4D::UNSPECIFIED)
 
int GetWidth () const
 
void SetWidth (int aWidth)
 
PLOT_DASH_TYPE GetPlotStyle () const
 
void SetPlotStyle (PLOT_DASH_TYPE aPlotStyle)
 
KIGFX::COLOR4D GetColor () const
 
void SetColor (const KIGFX::COLOR4D &aColor)
 
bool operator!= (const STROKE_PARAMS &aOther)
 
void Format (OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
 
void GetMsgPanelInfo (UNITS_PROVIDER *aUnitsProvider, std::vector< MSG_PANEL_ITEM > &aList, bool aIncludeStyle=true, bool aIncludeWidth=true)
 

Static Public Member Functions

static wxString GetLineStyleToken (PLOT_DASH_TYPE aStyle)
 
static void Stroke (const SHAPE *aShape, PLOT_DASH_TYPE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, std::function< void(const VECTOR2I &a, const VECTOR2I &b)> aStroker)
 

Private Attributes

int m_width
 
PLOT_DASH_TYPE m_plotstyle
 
KIGFX::COLOR4D m_color
 

Detailed Description

Simple container to manage line stroke parameters.

Definition at line 87 of file stroke_params.h.

Constructor & Destructor Documentation

◆ STROKE_PARAMS()

STROKE_PARAMS::STROKE_PARAMS ( int  aWidth = 0,
PLOT_DASH_TYPE  aPlotStyle = PLOT_DASH_TYPE::DEFAULT,
const KIGFX::COLOR4D aColor = KIGFX::COLOR4D::UNSPECIFIED 
)
inline

Definition at line 90 of file stroke_params.h.

91 :
92 m_width( aWidth ),
93 m_plotstyle( aPlotStyle ),
94 m_color( aColor )
95 {
96 }
PLOT_DASH_TYPE m_plotstyle
KIGFX::COLOR4D m_color

Member Function Documentation

◆ Format()

void STROKE_PARAMS::Format ( OUTPUTFORMATTER out,
const EDA_IU_SCALE aIuScale,
int  nestLevel 
) const

Definition at line 218 of file stroke_params.cpp.

220{
221 wxASSERT( aFormatter != nullptr );
222
224 {
225 aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s))",
226 EDA_UNIT_UTILS::FormatInternalUnits( aIuScale, GetWidth() ).c_str(),
228 }
229 else
230 {
231 aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s) (color %d %d %d %s))",
232 EDA_UNIT_UTILS::FormatInternalUnits( aIuScale, GetWidth() ).c_str(),
234 KiROUND( GetColor().r * 255.0 ),
235 KiROUND( GetColor().g * 255.0 ),
236 KiROUND( GetColor().b * 255.0 ),
237 FormatDouble2Str( GetColor().a ).c_str() );
238 }
239}
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:390
int GetWidth() const
Definition: stroke_params.h:98
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
static wxString GetLineStyleToken(PLOT_DASH_TYPE aStyle)
E_SERIE r
Definition: eserie.cpp:41
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:139
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References FormatDouble2Str(), EDA_UNIT_UTILS::FormatInternalUnits(), GetColor(), GetLineStyleToken(), GetPlotStyle(), GetWidth(), KiROUND(), OUTPUTFORMATTER::Print(), r, TO_UTF8, and KIGFX::COLOR4D::UNSPECIFIED.

Referenced by PCB_PLUGIN::format(), formatArc(), formatBezier(), formatCircle(), formatPoly(), formatRect(), SCH_SEXPR_PLUGIN::saveBusEntry(), SCH_SEXPR_PLUGIN::saveLine(), SCH_SEXPR_PLUGIN::saveSheet(), SCH_SEXPR_PLUGIN_CACHE::saveTextBox(), and SCH_SEXPR_PLUGIN::saveTextBox().

◆ GetColor()

◆ GetLineStyleToken()

wxString STROKE_PARAMS::GetLineStyleToken ( PLOT_DASH_TYPE  aStyle)
static

Definition at line 175 of file stroke_params.cpp.

176{
177 wxString token;
178
179 switch( aStyle )
180 {
181 case PLOT_DASH_TYPE::DASH: token = wxT( "dash" ); break;
182 case PLOT_DASH_TYPE::DOT: token = wxT( "dot" ); break;
183 case PLOT_DASH_TYPE::DASHDOT: token = wxT( "dash_dot" ); break;
184 case PLOT_DASH_TYPE::DASHDOTDOT: token = wxT( "dash_dot_dot" ); break;
185 case PLOT_DASH_TYPE::SOLID: token = wxT( "solid" ); break;
186 case PLOT_DASH_TYPE::DEFAULT: token = wxT( "default" ); break;
187 }
188
189 return token;
190}

References DASH, DASHDOT, DASHDOTDOT, DEFAULT, DOT, and SOLID.

Referenced by Format(), and SCH_LEGACY_PLUGIN::saveLine().

◆ GetMsgPanelInfo()

void STROKE_PARAMS::GetMsgPanelInfo ( UNITS_PROVIDER aUnitsProvider,
std::vector< MSG_PANEL_ITEM > &  aList,
bool  aIncludeStyle = true,
bool  aIncludeWidth = true 
)

Definition at line 193 of file stroke_params.cpp.

196{
197 if( aIncludeStyle )
198 {
199 wxString lineStyle = _( "Default" );
200
201 for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
202 {
203 if( typeEntry.first == GetPlotStyle() )
204 {
205 lineStyle = typeEntry.second.name;
206 break;
207 }
208 }
209
210 aList.emplace_back( _( "Line Style" ), lineStyle );
211 }
212
213 if( aIncludeWidth )
214 aList.emplace_back( _( "Line Width" ), aUnitsProvider->MessageTextFromValue( GetWidth() ) );
215}
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A lower-precision version of StringFromValue().
#define _(s)
const std::map< PLOT_DASH_TYPE, struct lineTypeStruct > lineTypeNames
Definition: stroke_params.h:70

References _, GetPlotStyle(), GetWidth(), lineTypeNames, and UNITS_PROVIDER::MessageTextFromValue().

Referenced by LIB_TEXTBOX::GetMsgPanelInfo(), SCH_LINE::GetMsgPanelInfo(), SCH_TEXTBOX::GetMsgPanelInfo(), FP_TEXTBOX::GetMsgPanelInfo(), PCB_TEXTBOX::GetMsgPanelInfo(), and EDA_SHAPE::ShapeGetMsgPanelInfo().

◆ GetPlotStyle()

◆ GetWidth()

◆ operator!=()

bool STROKE_PARAMS::operator!= ( const STROKE_PARAMS aOther)
inline

Definition at line 107 of file stroke_params.h.

108 {
109 return m_width != aOther.m_width
110 || m_plotstyle != aOther.m_plotstyle
111 || m_color != aOther.m_color;
112 }

References m_color, m_plotstyle, and m_width.

◆ SetColor()

◆ SetPlotStyle()

◆ SetWidth()

◆ Stroke()

void STROKE_PARAMS::Stroke ( const SHAPE aShape,
PLOT_DASH_TYPE  aLineStyle,
int  aWidth,
const KIGFX::RENDER_SETTINGS aRenderSettings,
std::function< void(const VECTOR2I &a, const VECTOR2I &b)>  aStroker 
)
static

Definition at line 35 of file stroke_params.cpp.

38{
39 double strokes[6] = { aWidth * 1.0, aWidth * 1.0, aWidth * 1.0, aWidth * 1.0, aWidth * 1.0,
40 aWidth * 1.0 };
41 int wrapAround = 6;
42
43 switch( aLineStyle )
44 {
46 strokes[0] = aRenderSettings->GetDashLength( aWidth );
47 strokes[1] = aRenderSettings->GetGapLength( aWidth );
48 wrapAround = 2;
49 break;
51 strokes[0] = aRenderSettings->GetDotLength( aWidth );
52 strokes[1] = aRenderSettings->GetGapLength( aWidth );
53 wrapAround = 2;
54 break;
56 strokes[0] = aRenderSettings->GetDashLength( aWidth );
57 strokes[1] = aRenderSettings->GetGapLength( aWidth );
58 strokes[2] = aRenderSettings->GetDotLength( aWidth );
59 strokes[3] = aRenderSettings->GetGapLength( aWidth );
60 wrapAround = 4;
61 break;
63 strokes[0] = aRenderSettings->GetDashLength( aWidth );
64 strokes[1] = aRenderSettings->GetGapLength( aWidth );
65 strokes[2] = aRenderSettings->GetDotLength( aWidth );
66 strokes[3] = aRenderSettings->GetGapLength( aWidth );
67 strokes[4] = aRenderSettings->GetDotLength( aWidth );
68 strokes[5] = aRenderSettings->GetGapLength( aWidth );
69 wrapAround = 6;
70 break;
71 default:
72 UNIMPLEMENTED_FOR( lineTypeNames.at( aLineStyle ).name );
73 }
74
75 switch( aShape->Type() )
76 {
77 case SH_SIMPLE:
78 {
79 const SHAPE_SIMPLE* poly = static_cast<const SHAPE_SIMPLE*>( aShape );
80
81 for( size_t ii = 0; ii < poly->GetSegmentCount(); ++ii )
82 {
83 SEG seg = poly->GetSegment( ii );
84 SHAPE_SEGMENT line( seg.A, seg.B );
85 STROKE_PARAMS::Stroke( &line, aLineStyle, aWidth, aRenderSettings, aStroker );
86 }
87 }
88 break;
89
90 case SH_SEGMENT:
91 {
92 const SHAPE_SEGMENT* line = static_cast<const SHAPE_SEGMENT*>( aShape );
93
94 VECTOR2D start = line->GetSeg().A;
95 VECTOR2D end = line->GetSeg().B;
96 BOX2I clip( start, VECTOR2I( end.x - start.x, end.y - start.y ) );
97 clip.Normalize();
98
99 double theta = atan2( end.y - start.y, end.x - start.x );
100
101 for( size_t i = 0; i < 10000; ++i )
102 {
103 // Calculations MUST be done in doubles to keep from accumulating rounding
104 // errors as we go.
105 VECTOR2D next( start.x + strokes[ i % wrapAround ] * cos( theta ),
106 start.y + strokes[ i % wrapAround ] * sin( theta ) );
107
108 // Drawing each segment can be done rounded to ints.
109 VECTOR2I a( KiROUND( start.x ), KiROUND( start.y ) );
110 VECTOR2I b( KiROUND( next.x ), KiROUND( next.y ) );
111
112 if( ClipLine( &clip, a.x, a.y, b.x, b.y ) )
113 break;
114 else if( i % 2 == 0 )
115 aStroker( a, b );
116
117 start = next;
118 }
119 }
120 break;
121
122 case SH_ARC:
123 {
124 const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( aShape );
125
126 double r = arc->GetRadius();
127 double C = 2.0 * M_PI * r;
128 VECTOR2I center = arc->GetCenter();
129 VECTOR2D startRadial( arc->GetP0() - center );
130 EDA_ANGLE startAngle( startRadial );
131 VECTOR2D endRadial( arc->GetP1() - center );
132 EDA_ANGLE arcEndAngle( endRadial );
133
134 if( arcEndAngle == startAngle )
135 arcEndAngle = startAngle + ANGLE_360; // ring, not null
136
137 if( startAngle > arcEndAngle )
138 {
139 if( arcEndAngle < ANGLE_0 )
140 arcEndAngle = arcEndAngle.Normalize();
141 else
142 startAngle = startAngle.Normalize() - ANGLE_360;
143 }
144
145 wxASSERT( startAngle < arcEndAngle );
146
147 for( size_t i = 0; i < 10000 && startAngle < arcEndAngle; ++i )
148 {
149 EDA_ANGLE theta = ANGLE_360 * strokes[ i % wrapAround ] / C;
150 EDA_ANGLE endAngle = std::min( startAngle + theta, arcEndAngle );
151
152 if( i % 2 == 0 )
153 {
154 VECTOR2I a( center.x + r * startAngle.Cos(), center.y + r * startAngle.Sin() );
155 VECTOR2I b( center.x + r * endAngle.Cos(), center.y + r * endAngle.Sin() );
156
157 aStroker( a, b );
158 }
159
160 startAngle = endAngle;
161 }
162 }
163 break;
164
165 case SH_CIRCLE:
166 // A circle is always filled; a ring is represented by a 360° arc.
168
169 default:
171 }
172}
EDA_ANGLE Normalize()
Definition: eda_angle.h:249
double Sin() const
Definition: eda_angle.h:206
double Cos() const
Definition: eda_angle.h:221
double GetGapLength(int aLineWidth) const
double GetDotLength(int aLineWidth) const
double GetDashLength(int aLineWidth) const
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
const VECTOR2I & GetP1() const
Definition: shape_arc.h:113
double GetRadius() const
Definition: shape_arc.cpp:458
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:433
const VECTOR2I & GetP0() const
Definition: shape_arc.h:112
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:95
const SEG & GetSeg() const
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Definition: shape_simple.h:42
virtual const SEG GetSegment(int aIndex) const override
Definition: shape_simple.h:174
virtual size_t GetSegmentCount() const override
Definition: shape_simple.h:176
static void Stroke(const SHAPE *aShape, PLOT_DASH_TYPE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, std::function< void(const VECTOR2I &a, const VECTOR2I &b)> aStroker)
static constexpr EDA_ANGLE & ANGLE_360
Definition: eda_angle.h:418
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:412
bool ClipLine(const BOX2I *aClipBox, int &x1, int &y1, int &x2, int &y2)
Test if any part of a line falls within the bounds of a rectangle.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
CITER next(CITER it)
Definition: ptree.cpp:126
@ SH_CIRCLE
circle
Definition: shape.h:47
@ SH_SIMPLE
simple polygon
Definition: shape.h:48
@ SH_SEGMENT
line segment
Definition: shape.h:45
@ SH_ARC
circular arc
Definition: shape.h:51
static wxString SHAPE_TYPE_asString(SHAPE_TYPE a)
Definition: shape.h:56
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References SEG::A, ANGLE_0, ANGLE_360, SEG::B, C, ClipLine(), EDA_ANGLE::Cos(), DASH, DASHDOT, DASHDOTDOT, DOT, SHAPE_ARC::GetCenter(), KIGFX::RENDER_SETTINGS::GetDashLength(), KIGFX::RENDER_SETTINGS::GetDotLength(), KIGFX::RENDER_SETTINGS::GetGapLength(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), SHAPE_ARC::GetRadius(), SHAPE_SEGMENT::GetSeg(), SHAPE_SIMPLE::GetSegment(), SHAPE_SIMPLE::GetSegmentCount(), KI_FALLTHROUGH, KiROUND(), lineTypeNames, next(), EDA_ANGLE::Normalize(), BOX2< Vec >::Normalize(), r, SH_ARC, SH_CIRCLE, SH_SEGMENT, SH_SIMPLE, SHAPE_TYPE_asString(), EDA_ANGLE::Sin(), Stroke(), SHAPE_BASE::Type(), UNIMPLEMENTED_FOR, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOARD_ADAPTER::addShape(), KIGFX::SCH_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), BRDITEMS_PLOTTER::PlotFootprintShape(), BRDITEMS_PLOTTER::PlotPcbShape(), SCH_BUS_ENTRY_BASE::Print(), SCH_LINE::Print(), SCH_SHAPE::Print(), LIB_SHAPE::print(), LIB_TEXTBOX::print(), SCH_TEXTBOX::Print(), and Stroke().

Member Data Documentation

◆ m_color

KIGFX::COLOR4D STROKE_PARAMS::m_color
private

Definition at line 130 of file stroke_params.h.

Referenced by GetColor(), operator!=(), and SetColor().

◆ m_plotstyle

PLOT_DASH_TYPE STROKE_PARAMS::m_plotstyle
private

Definition at line 129 of file stroke_params.h.

Referenced by GetPlotStyle(), operator!=(), and SetPlotStyle().

◆ m_width

int STROKE_PARAMS::m_width
private

Definition at line 128 of file stroke_params.h.

Referenced by GetWidth(), operator!=(), and SetWidth().


The documentation for this class was generated from the following files: