KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
47enum class LINE_STYLE
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 LINE_STYLE values and style names displayed
69 */
70extern const std::map<LINE_STYLE, struct LINE_STYLE_DESC> lineTypeNames;
71
72
73#define DEFAULT_STYLE _( "Default" )
74#define INDETERMINATE_STYLE _( "Leave unchanged" )
75
76
81{
82public:
83 STROKE_PARAMS( int aWidth = 0, LINE_STYLE aLineStyle = LINE_STYLE::DEFAULT,
85 m_width( aWidth ),
86 m_lineStyle( aLineStyle ),
87 m_color( aColor )
88 {
89 }
90
91 int GetWidth() const { return m_width; }
92 void SetWidth( int aWidth ) { m_width = aWidth; }
93
95 void SetLineStyle( LINE_STYLE aLineStyle ) { m_lineStyle = aLineStyle; }
96
97 KIGFX::COLOR4D GetColor() const { return m_color; }
98 void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
99
100 bool operator!=( const STROKE_PARAMS& aOther )
101 {
102 return m_width != aOther.m_width
103 || m_lineStyle != aOther.m_lineStyle
104 || m_color != aOther.m_color;
105 }
106
107 void Format( OUTPUTFORMATTER* out, const EDA_IU_SCALE& aIuScale, int nestLevel ) const;
108
109 void GetMsgPanelInfo( UNITS_PROVIDER* aUnitsProvider, std::vector<MSG_PANEL_ITEM>& aList,
110 bool aIncludeStyle = true, bool aIncludeWidth = true );
111
112 // Helper functions
113
114 static wxString GetLineStyleToken( LINE_STYLE aStyle );
115
116 static void Stroke( const SHAPE* aShape, LINE_STYLE aLineStyle, int aWidth,
117 const KIGFX::RENDER_SETTINGS* aRenderSettings,
118 const std::function<void( const VECTOR2I& a, const VECTOR2I& b )>& aStroker );
119
120private:
124};
125
126
127class STROKE_PARAMS_PARSER : public STROKE_PARAMS_LEXER
128{
129public:
130 STROKE_PARAMS_PARSER( LINE_READER* aReader, int iuPerMM ) :
131 STROKE_PARAMS_LEXER( aReader ),
132 m_iuPerMM( iuPerMM )
133 {
134 }
135
136 void ParseStroke( STROKE_PARAMS& aStroke );
137
138private:
139 int parseInt( const char* aText );
140 double parseDouble( const char* aText );
141
142private:
144};
145
146
147#endif // STROKE_PARAMS_H
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
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:398
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:93
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:322
An abstract shape on 2D plane.
Definition: shape.h:126
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:81
int GetWidth() const
Definition: stroke_params.h:91
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:95
LINE_STYLE m_lineStyle
void SetWidth(int aWidth)
Definition: stroke_params.h:92
bool operator!=(const STROKE_PARAMS &aOther)
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:98
void GetMsgPanelInfo(UNITS_PROVIDER *aUnitsProvider, std::vector< MSG_PANEL_ITEM > &aList, bool aIncludeStyle=true, bool aIncludeWidth=true)
STROKE_PARAMS(int aWidth=0, LINE_STYLE aLineStyle=LINE_STYLE::DEFAULT, const KIGFX::COLOR4D &aColor=KIGFX::COLOR4D::UNSPECIFIED)
Definition: stroke_params.h:83
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
KIGFX::COLOR4D m_color
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
static void Stroke(const SHAPE *aShape, LINE_STYLE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, const std::function< void(const VECTOR2I &a, const VECTOR2I &b)> &aStroker)
static wxString GetLineStyleToken(LINE_STYLE aStyle)
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:48
const BITMAPS bitmap
Definition: stroke_params.h:63