KiCad PCB EDA Suite
stroke_params.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef STROKE_PARAMS_H
25#define STROKE_PARAMS_H
26
27#include <map>
28#include <bitmaps.h>
29#include <units_provider.h>
30#include <gal/color4d.h>
31#include <wx/translation.h>
32#include <geometry/shape.h>
33#include <stroke_params_lexer.h>
34
35class STROKE_PARAMS_LEXER;
36class MSG_PANEL_ITEM;
37
38namespace KIGFX
39{
40class RENDER_SETTINGS;
41}
42
43
48{
49 DEFAULT = -1,
50 SOLID = 0,
52 DASH,
53 DOT,
54 DASHDOT,
57};
58
59
61{
62 wxString name;
64};
65
66
67/*
68 * Conversion map between PLOT_DASH_TYPE values and style names displayed
69 */
70const std::map<PLOT_DASH_TYPE, struct lineTypeStruct> lineTypeNames =
71{
73 { PLOT_DASH_TYPE::DASH, { _( "Dashed" ), BITMAPS::stroke_dash } },
74 { PLOT_DASH_TYPE::DOT, { _( "Dotted" ), BITMAPS::stroke_dot } },
77};
78
79
80#define DEFAULT_STYLE _( "Default" )
81#define INDETERMINATE_STYLE _( "Leave unchanged" )
82
83
88{
89public:
92 m_width( aWidth ),
93 m_plotstyle( aPlotStyle ),
94 m_color( aColor )
95 {
96 }
97
98 int GetWidth() const { return m_width; }
99 void SetWidth( int aWidth ) { m_width = aWidth; }
100
102 void SetPlotStyle( PLOT_DASH_TYPE aPlotStyle ) { m_plotstyle = aPlotStyle; }
103
104 KIGFX::COLOR4D GetColor() const { return m_color; }
105 void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
106
107 bool operator!=( const STROKE_PARAMS& aOther )
108 {
109 return m_width != aOther.m_width
110 || m_plotstyle != aOther.m_plotstyle
111 || m_color != aOther.m_color;
112 }
113
114 void Format( OUTPUTFORMATTER* out, const EDA_IU_SCALE& aIuScale, int nestLevel ) const;
115
116 void GetMsgPanelInfo( UNITS_PROVIDER* aUnitsProvider, std::vector<MSG_PANEL_ITEM>& aList,
117 bool aIncludeStyle = true, bool aIncludeWidth = true );
118
119 // Helper functions
120
121 static wxString GetLineStyleToken( PLOT_DASH_TYPE aStyle );
122
123 static void Stroke( const SHAPE* aShape, PLOT_DASH_TYPE aLineStyle, int aWidth,
124 const KIGFX::RENDER_SETTINGS* aRenderSettings,
125 std::function<void( const VECTOR2I& a, const VECTOR2I& b )> aStroker );
126
127private:
131};
132
133
134class STROKE_PARAMS_PARSER : public STROKE_PARAMS_LEXER
135{
136public:
137 STROKE_PARAMS_PARSER( LINE_READER* aReader, int iuPerMM ) :
138 STROKE_PARAMS_LEXER( aReader ),
139 m_iuPerMM( iuPerMM )
140 {
141 }
142
143 void ParseStroke( STROKE_PARAMS& aStroke );
144
145private:
146 int parseInt( const char* aText );
147 double parseDouble( const char* aText );
148
149private:
151};
152
153
154#endif // STROKE_PARAMS_H
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
@ stroke_dashdotdot
@ stroke_dashdot
@ stroke_solid
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:390
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:81
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
An abstract shape on 2D plane.
Definition: shape.h:123
int parseInt(const char *aText)
void ParseStroke(STROKE_PARAMS &aStroke)
double parseDouble(const char *aText)
STROKE_PARAMS_PARSER(LINE_READER *aReader, int iuPerMM)
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
int GetWidth() const
Definition: stroke_params.h:98
void SetWidth(int aWidth)
Definition: stroke_params.h:99
bool operator!=(const STROKE_PARAMS &aOther)
void SetColor(const KIGFX::COLOR4D &aColor)
void GetMsgPanelInfo(UNITS_PROVIDER *aUnitsProvider, std::vector< MSG_PANEL_ITEM > &aList, bool aIncludeStyle=true, bool aIncludeWidth=true)
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)
STROKE_PARAMS(int aWidth=0, PLOT_DASH_TYPE aPlotStyle=PLOT_DASH_TYPE::DEFAULT, const KIGFX::COLOR4D &aColor=KIGFX::COLOR4D::UNSPECIFIED)
Definition: stroke_params.h:90
PLOT_DASH_TYPE m_plotstyle
KIGFX::COLOR4D GetColor() const
KIGFX::COLOR4D m_color
PLOT_DASH_TYPE GetPlotStyle() const
static wxString GetLineStyleToken(PLOT_DASH_TYPE aStyle)
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
#define _(s)
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:243
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
const std::map< PLOT_DASH_TYPE, struct lineTypeStruct > lineTypeNames
Definition: stroke_params.h:70
const BITMAPS bitmap
Definition: stroke_params.h:63