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 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 <common.h>
30#include <origin_transforms.h>
31
32class PROPERTY_BASE;
33class REGEX_VALIDATOR;
34class EDA_DRAW_FRAME;
35
36wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty, EDA_DRAW_FRAME* aFrame );
37
40{
41public:
42 PGPROPERTY_DISTANCE( const wxString& aRegEx,
44 virtual ~PGPROPERTY_DISTANCE() = 0;
45
48
49protected:
50 bool StringToDistance( wxVariant& aVariant, const wxString& aText, int aArgFlags = 0 ) const;
51 wxString DistanceToString( wxVariant& aVariant, int aArgFlags = 0 ) const;
52
53 std::unique_ptr<REGEX_VALIDATOR> m_regExValidator;
55};
56
57
58class PGPROPERTY_SIZE : public wxUIntProperty, public PGPROPERTY_DISTANCE
59{
60public:
61 PGPROPERTY_SIZE( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
62 long aValue = 0 );
63
64 bool StringToValue( wxVariant& aVariant, const wxString& aText,
65 int aArgFlags = 0 ) const override
66 {
67 return StringToDistance( aVariant, aText, aArgFlags );
68 }
69
70 wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override
71 {
72 return DistanceToString( aVariant, aArgFlags );
73 }
74
75 wxValidator* DoGetValidator() const override;
76};
77
78
79class PGPROPERTY_COORD : public wxIntProperty, public PGPROPERTY_DISTANCE
80{
81public:
82 PGPROPERTY_COORD( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
83 long aValue = 0,
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:
105 PGPROPERTY_ANGLE( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
106 double aValue = 0 )
107 : wxFloatProperty( aLabel, aName, aValue ), 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( const wxString& aLabel, const wxString& aName, wxPGChoices* aChoices,
136 int aValue = 0 ) :
137 wxEnumProperty( aLabel, aName, *aChoices, aValue ),
138 m_colorFunc( []( int aDummy ) { return wxNullColour; } )
139 {
140 SetFlag( wxPG_PROP_CUSTOMIMAGE );
141 }
142
143 wxSize OnMeasureImage( int aItem = -1 ) const override;
144
145 void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override;
146
147 void SetColorFunc( std::function<wxColour( int aValue )> aFunc )
148 {
149 m_colorFunc = aFunc;
150 }
151
152 wxColour GetColor( int aValue )
153 {
154 return m_colorFunc( aValue );
155 }
156
157protected:
158 std::function<wxColour( int aValue )> m_colorFunc;
159};
160
161
162class PGPROPERTY_STRING : public wxStringProperty
163{
164public:
165 PGPROPERTY_STRING( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
166 const wxString& aValue = wxEmptyString ) :
167 wxStringProperty( aLabel, aName, aValue )
168 {}
169
170 virtual ~PGPROPERTY_STRING() = default;
171
172 wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
173
174 bool StringToValue( wxVariant& aVariant, const wxString& aString,
175 int aFlags = 0 ) const override;
176};
177
178
179class PGPROPERTY_BOOL : public wxBoolProperty
180{
181public:
182 PGPROPERTY_BOOL( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
183 bool aValue = false );
184
185 virtual ~PGPROPERTY_BOOL() = default;
186
187 const wxPGEditor* DoGetEditorClass() const override;
188};
189
190#endif /* PG_PROPERTIES_H */
The base class for create windows for drawing purpose.
COORD_TYPES_T
The supported Display Origin Transform types.
A wxEnumProperty that displays a color next to the enum value.
PGPROPERTY_ANGLE(const wxString &aLabel=wxPG_LABEL, const wxString &aName=wxPG_LABEL, double aValue=0)
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
PGPROPERTY_COLORENUM(const wxString &aLabel, const wxString &aName, wxPGChoices *aChoices, int aValue=0)
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
Customized wxPGProperty class to handle angles.
Definition: pg_properties.h:80
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
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition: pg_properties.h:47
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:54
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aType)
Definition: pg_properties.h:46
std::unique_ptr< REGEX_VALIDATOR > m_regExValidator
Definition: pg_properties.h:53
wxValidator * DoGetValidator() const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
Definition: pg_properties.h:64
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
Definition: pg_properties.h:70
wxString ValueToString(wxVariant &aValue, int aFlags=0) const override
PGPROPERTY_STRING(const wxString &aLabel=wxPG_LABEL, const wxString &aName=wxPG_LABEL, const wxString &aValue=wxEmptyString)
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:119
The common library.
wxPGProperty * PGPropertyFactory(const PROPERTY_BASE *aProperty, EDA_DRAW_FRAME *aFrame)
Customized abstract wxPGProperty class to handle coordinate/size units.