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:
44 PGPROPERTY_DISTANCE( EDA_DRAW_FRAME* aParentFrame, const wxString& aRegEx,
46 virtual ~PGPROPERTY_DISTANCE() = 0;
47
49
50protected:
51 bool StringToDistance( wxVariant& aVariant, const wxString& aText, int aArgFlags = 0 ) const;
52 wxString DistanceToString( wxVariant& aVariant, int aArgFlags = 0 ) const;
53
54protected:
56 std::unique_ptr<REGEX_VALIDATOR> m_regExValidator;
58};
59
60
61class PGPROPERTY_SIZE : public wxUIntProperty, public PGPROPERTY_DISTANCE
62{
63public:
64 PGPROPERTY_SIZE( EDA_DRAW_FRAME* aParentFrame );
65
66 bool StringToValue( wxVariant& aVariant, const wxString& aText,
67 int aArgFlags = 0 ) const override
68 {
69 return StringToDistance( aVariant, aText, aArgFlags );
70 }
71
72 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override
73 {
74 return DistanceToString( aVariant, aArgFlags );
75 }
76
77 wxValidator* DoGetValidator() const override;
78};
79
80
81class PGPROPERTY_COORD : public wxIntProperty, public PGPROPERTY_DISTANCE
82{
83public:
85
86 bool StringToValue( wxVariant& aVariant, const wxString& aText,
87 int aArgFlags = 0 ) const override
88 {
89 return StringToDistance( aVariant, aText, aArgFlags );
90 }
91
92 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override
93 {
94 return DistanceToString( aVariant, aArgFlags );
95 }
96
97 wxValidator* DoGetValidator() const override;
98};
99
100
102class PGPROPERTY_ANGLE : public wxFloatProperty
103{
104public:
106 wxFloatProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
107 m_scale( 1.0 )
108 {
109 }
110
111 bool StringToValue( wxVariant& aVariant, const wxString& aText,
112 int aArgFlags = 0 ) const override;
113 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
114
115 void SetScale( double aScale )
116 {
117 m_scale = aScale;
118 }
119
120 wxValidator* DoGetValidator() const override;
121
123 bool ValidateValue( wxVariant&, wxPGValidationInfo& ) const override { return true; }
124
125protected:
127 double m_scale;
128};
129
130
132class PGPROPERTY_COLORENUM : public wxEnumProperty
133{
134public:
135 PGPROPERTY_COLORENUM( wxPGChoices* aChoices ) :
136 wxEnumProperty( wxPG_LABEL, wxPG_LABEL, *aChoices, 0 ),
137 m_colorFunc( []( int aDummy ) { return wxNullColour; } )
138 {
139 SetFlag( wxPG_PROP_CUSTOMIMAGE );
140 }
141
142 wxSize OnMeasureImage( int aItem = -1 ) const override;
143
144 void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override;
145
146 void SetColorFunc( std::function<wxColour( int aValue )> aFunc )
147 {
148 m_colorFunc = aFunc;
149 }
150
151 wxColour GetColor( int aValue )
152 {
153 return m_colorFunc( aValue );
154 }
155
156protected:
157 std::function<wxColour( int aValue )> m_colorFunc;
158};
159
160
161class PGPROPERTY_STRING : public wxStringProperty
162{
163public:
165 wxStringProperty( wxPG_LABEL, wxPG_LABEL, wxEmptyString )
166 {}
167
168 virtual ~PGPROPERTY_STRING() = default;
169
170 wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
171
172 bool StringToValue( wxVariant& aVariant, const wxString& aString,
173 int aFlags = 0 ) const override;
174};
175
176
177class PGPROPERTY_BOOL : public wxBoolProperty
178{
179public:
180 PGPROPERTY_BOOL( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
181 bool aValue = false );
182
183 virtual ~PGPROPERTY_BOOL() = default;
184
185 const wxPGEditor* DoGetEditorClass() const override;
186};
187
188
189class PGPROPERTY_COLOR4D : public wxStringProperty
190{
191public:
192 PGPROPERTY_COLOR4D( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
195
196 virtual ~PGPROPERTY_COLOR4D() = default;
197
198 wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
199
200 bool StringToValue( wxVariant &aVariant, const wxString &aText,
201 int aFlags = 0 ) const override;
202
203 void SetBackgroundColor( const KIGFX::COLOR4D& aColor ) { m_backgroundColor = aColor; }
205
206 private:
209};
210
211#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:382
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.
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
bool ValidateValue(wxVariant &, wxPGValidationInfo &) const override
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
std::function< wxColour(int aValue)> m_colorFunc
PGPROPERTY_COLORENUM(wxPGChoices *aChoices)
Customized wxPGProperty class to handle angles.
Definition: pg_properties.h:82
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
Definition: pg_properties.h:92
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
Definition: pg_properties.h:86
wxValidator * DoGetValidator() const override
EDA_DRAW_FRAME * m_parentFrame
Definition: pg_properties.h:55
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:57
std::unique_ptr< REGEX_VALIDATOR > m_regExValidator
Definition: pg_properties.h:56
wxValidator * DoGetValidator() const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
Definition: pg_properties.h:66
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
Definition: pg_properties.h:72
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:130
The common library.
wxPGProperty * PGPropertyFactory(const PROPERTY_BASE *aProperty, EDA_DRAW_FRAME *aFrame)
Customized abstract wxPGProperty class to handle coordinate/size units.