KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pg_properties.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) 2020-2023 CERN
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef PG_PROPERTIES_H
24#define PG_PROPERTIES_H
25
26#include <wx/propgrid/propgrid.h>
27#include <wx/propgrid/property.h>
28#include <wx/propgrid/props.h>
29#include <wx/propgrid/advprops.h>
30#include <common.h>
31#include <gal/color4d.h>
32#include <origin_transforms.h>
33
34class PROPERTY_BASE;
35class REGEX_VALIDATOR;
36class EDA_DRAW_FRAME;
37
38wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty, EDA_DRAW_FRAME* aFrame );
39
42{
43public:
46 virtual ~PGPROPERTY_DISTANCE() = 0;
47
49
50protected:
51#if wxCHECK_VERSION( 3, 3, 0 )
52 bool StringToDistance( wxVariant& aVariant, const wxString& aText,
53 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const;
54 wxString DistanceToString( wxVariant& aVariant,
55 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const;
56#else
57 bool StringToDistance( wxVariant& aVariant, const wxString& aText, int aArgFlags = 0 ) const;
58 wxString DistanceToString( wxVariant& aVariant, int aArgFlags = 0 ) const;
59#endif
60
61protected:
64};
65
66
67class PGPROPERTY_AREA : public wxIntProperty
68{
69public:
70 PGPROPERTY_AREA( EDA_DRAW_FRAME* aParentFrame );
71
72 virtual ~PGPROPERTY_AREA() = default;
73
74protected:
75#if wxCHECK_VERSION( 3, 3, 0 )
76 bool StringToValue( wxVariant& aVariant, const wxString& aText,
77 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
78
79 wxString ValueToString( wxVariant& aVariant,
80 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
81#else
82 bool StringToValue( wxVariant& aVariant, const wxString& aText,
83 int aArgFlags = 0 ) const override;
84
85 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
86#endif
87
88 wxValidator* DoGetValidator() const override;
89
90protected:
92};
93
94
95class PGPROPERTY_SIZE : public wxUIntProperty, public PGPROPERTY_DISTANCE
96{
97public:
98 PGPROPERTY_SIZE( EDA_DRAW_FRAME* aParentFrame );
99
100 virtual ~PGPROPERTY_SIZE() = default;
101
102#if wxCHECK_VERSION( 3, 3, 0 )
103 bool StringToValue( wxVariant& aVariant, const wxString& aText,
104 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
105 {
106 return StringToDistance( aVariant, aText, aFlags );
107 }
108
109 wxString ValueToString( wxVariant& aVariant,
110 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
111 {
112 return DistanceToString( aVariant, aFlags );
113 }
114#else
115 bool StringToValue( wxVariant& aVariant, const wxString& aText,
116 int aArgFlags = 0 ) const override
117 {
118 return StringToDistance( aVariant, aText, aArgFlags );
119 }
120
121 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override
122 {
123 return DistanceToString( aVariant, aArgFlags );
124 }
125#endif
126
127 bool ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const override;
128
129 wxValidator* DoGetValidator() const override;
130};
131
132
133class PGPROPERTY_COORD : public wxIntProperty, public PGPROPERTY_DISTANCE
134{
135public:
137
138 virtual ~PGPROPERTY_COORD() = default;
139
140#if wxCHECK_VERSION( 3, 3, 0 )
141 bool StringToValue( wxVariant& aVariant, const wxString& aText,
142 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
143 {
144 return StringToDistance( aVariant, aText, aFlags );
145 }
146
147 wxString ValueToString( wxVariant& aVariant,
148 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
149 {
150 return DistanceToString( aVariant, aFlags );
151 }
152#else
153 bool StringToValue( wxVariant& aVariant, const wxString& aText,
154 int aArgFlags = 0 ) const override
155 {
156 return StringToDistance( aVariant, aText, aArgFlags );
157 }
158
159 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override
160 {
161 return DistanceToString( aVariant, aArgFlags );
162 }
163#endif
164
165 wxValidator* DoGetValidator() const override;
166};
167
168
170class PGPROPERTY_ANGLE : public wxFloatProperty
171{
172public:
174 wxFloatProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
175 m_scale( 1.0 )
176 {
177 }
178
179 virtual ~PGPROPERTY_ANGLE() = default;
180
181#if wxCHECK_VERSION( 3, 3, 0 )
182 bool StringToValue( wxVariant& aVariant, const wxString& aText,
183 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
184
185 wxString ValueToString( wxVariant& aVariant,
186 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
187#else
188 bool StringToValue( wxVariant& aVariant, const wxString& aText,
189 int aArgFlags = 0 ) const override;
190 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
191#endif
192
193 void SetScale( double aScale )
194 {
195 m_scale = aScale;
196 }
197
198 wxValidator* DoGetValidator() const override;
199
201 bool ValidateValue( wxVariant&, wxPGValidationInfo& ) const override { return true; }
202
203protected:
205 double m_scale;
206};
207
208
210class PGPROPERTY_COLORENUM : public wxEnumProperty
211{
212public:
213 PGPROPERTY_COLORENUM( wxPGChoices* aChoices ) :
214 wxEnumProperty( wxPG_LABEL, wxPG_LABEL, *aChoices, 0 ),
215 m_colorFunc( []( int aDummy ) { return wxNullColour; } )
216 {
217#if wxCHECK_VERSION( 3, 3, 0 )
218 SetFlag( wxPGPropertyFlags::CustomImage );
219#else
220 SetFlag( wxPG_PROP_CUSTOMIMAGE );
221#endif
222 }
223
224 virtual ~PGPROPERTY_COLORENUM() = default;
225
226 wxSize OnMeasureImage( int aItem = -1 ) const override;
227
228 void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override;
229
230 void SetColorFunc( std::function<wxColour( int aValue )> aFunc )
231 {
232 m_colorFunc = aFunc;
233 }
234
235 wxColour GetColor( int aValue )
236 {
237 return m_colorFunc( aValue );
238 }
239
240protected:
241 std::function<wxColour( int aValue )> m_colorFunc;
242};
243
244
245class PGPROPERTY_RATIO : public wxFloatProperty
246{
247public:
249
250 const wxPGEditor* DoGetEditorClass() const override;
251
252 virtual ~PGPROPERTY_RATIO() = default;
253
254#if wxCHECK_VERSION( 3, 3, 0 )
255 bool StringToValue( wxVariant& aVariant, const wxString& aText,
256 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
257
258 wxString ValueToString( wxVariant& aVariant,
259 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
260#else
261 bool StringToValue( wxVariant& aVariant, const wxString& aText,
262 int aArgFlags = 0 ) const override;
263
264 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
265#endif
266
267 bool ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const override;
268
269 wxValidator* DoGetValidator() const override;
270};
271
272
273class PGPROPERTY_STRING : public wxStringProperty
274{
275public:
277 wxStringProperty( wxPG_LABEL, wxPG_LABEL, wxEmptyString )
278 {}
279
280 virtual ~PGPROPERTY_STRING() = default;
281
282#if wxCHECK_VERSION( 3, 3, 0 )
283 bool StringToValue( wxVariant& aVariant, const wxString& aText,
284 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
285
286 wxString ValueToString( wxVariant& aVariant,
287 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
288#else
289 wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
290
291 bool StringToValue( wxVariant& aVariant, const wxString& aString,
292 int aFlags = 0 ) const override;
293#endif
294};
295
296
297class PGPROPERTY_BOOL : public wxBoolProperty
298{
299public:
300 PGPROPERTY_BOOL( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
301 bool aValue = false );
302
303 virtual ~PGPROPERTY_BOOL() = default;
304
305 const wxPGEditor* DoGetEditorClass() const override;
306};
307
308
309class PGPROPERTY_COLOR4D : public wxStringProperty
310{
311public:
312 PGPROPERTY_COLOR4D( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
315
316 virtual ~PGPROPERTY_COLOR4D() = default;
317
318#if wxCHECK_VERSION( 3, 3, 0 )
319 bool StringToValue( wxVariant& aVariant, const wxString& aText,
320 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
321
322 wxString ValueToString( wxVariant& aVariant,
323 wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
324#else
325 wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
326
327 bool StringToValue( wxVariant &aVariant, const wxString &aText,
328 int aFlags = 0 ) const override;
329#endif
330
331 void SetBackgroundColor( const KIGFX::COLOR4D& aColor ) { m_backgroundColor = aColor; }
333
334 private:
337};
338
339#endif /* PG_PROPERTIES_H */
The base class for create windows for drawing purpose.
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
COORD_TYPES_T
The supported Display Origin Transform types.
A wxEnumProperty that displays a color next to the enum value.
void SetScale(double aScale)
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
double m_scale
< Scale factor to convert between raw and displayed value
wxValidator * DoGetValidator() const override
Do not perform PG validation; the UX is not what we want.
virtual ~PGPROPERTY_ANGLE()=default
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
bool ValidateValue(wxVariant &, wxPGValidationInfo &) const override
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
wxValidator * DoGetValidator() const override
virtual ~PGPROPERTY_AREA()=default
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
EDA_DRAW_FRAME * m_parentFrame
Definition: pg_properties.h:91
const wxPGEditor * DoGetEditorClass() const override
virtual ~PGPROPERTY_BOOL()=default
virtual ~PGPROPERTY_COLOR4D()=default
KIGFX::COLOR4D m_backgroundColor
Used for rendering colors with opacity.
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aFlags=0) const override
wxString ValueToString(wxVariant &aValue, int aFlags=0) const override
const KIGFX::COLOR4D & GetBackgroundColor() const
void SetBackgroundColor(const KIGFX::COLOR4D &aColor)
void SetColorFunc(std::function< wxColour(int aValue)> aFunc)
wxColour GetColor(int aValue)
wxSize OnMeasureImage(int aItem=-1) const override
void OnCustomPaint(wxDC &aDC, const wxRect &aRect, wxPGPaintData &aPaintData) override
virtual ~PGPROPERTY_COLORENUM()=default
std::function< wxColour(int aValue)> m_colorFunc
PGPROPERTY_COLORENUM(wxPGChoices *aChoices)
Customized wxPGProperty class to handle angles.
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
virtual ~PGPROPERTY_COORD()=default
wxValidator * DoGetValidator() const override
EDA_DRAW_FRAME * m_parentFrame
Definition: pg_properties.h:62
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition: pg_properties.h:48
wxString DistanceToString(wxVariant &aVariant, int aArgFlags=0) const
bool StringToDistance(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const
virtual ~PGPROPERTY_DISTANCE()=0
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Definition: pg_properties.h:63
wxValidator * DoGetValidator() const override
bool ValidateValue(wxVariant &aValue, wxPGValidationInfo &aValidationInfo) const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
virtual ~PGPROPERTY_RATIO()=default
const wxPGEditor * DoGetEditorClass() const override
virtual ~PGPROPERTY_SIZE()=default
wxValidator * DoGetValidator() const override
bool ValidateValue(wxVariant &aValue, wxPGValidationInfo &aValidationInfo) const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
wxString ValueToString(wxVariant &aValue, int aFlags=0) const override
bool StringToValue(wxVariant &aVariant, const wxString &aString, int aFlags=0) const override
virtual ~PGPROPERTY_STRING()=default
Custom validator that checks verifies that a string exactly matches a regular expression.
Definition: validators.h:113
The common library.
wxPGProperty * PGPropertyFactory(const PROPERTY_BASE *aProperty, EDA_DRAW_FRAME *aFrame)
Customized abstract wxPGProperty class to handle coordinate/size units.