KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_bitmap_overlay_panel.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) 2024 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef DRC_RE_BITMAP_OVERLAY_PANEL_H
21#define DRC_RE_BITMAP_OVERLAY_PANEL_H
22
23#include <map>
24#include <memory>
25#include <optional>
26#include <vector>
27
28#include <wx/bitmap.h>
29#include <wx/panel.h>
30
31#include <bitmaps.h>
35
36class wxControl;
37class wxCheckBox;
38class wxPaintEvent;
39class wxDPIChangedEvent;
40class wxSysColourChangedEvent;
41class wxFocusEvent;
42class UNIT_BINDER;
43
44
57class DRC_RE_BITMAP_OVERLAY_PANEL : public wxPanel,
59{
60public:
61 DRC_RE_BITMAP_OVERLAY_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY );
62
64
70 void SetBackgroundBitmap( BITMAPS aBitmap );
71
72 bool TransferDataToWindow() override;
73 bool TransferDataFromWindow() override;
74
78 void ClearFieldErrors();
79
86 void ShowFieldError( const wxString& aFieldId, const wxString& aMessage );
87
88protected:
97 template <typename T>
98 DRC_RE_OVERLAY_FIELD* AddControl( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition, T* aControl );
99
109 template <typename T>
110 DRC_RE_OVERLAY_FIELD* AddField( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition,
111 long aStyle = 0 );
112
123 template <typename T>
124 DRC_RE_OVERLAY_FIELD* AddFieldWithUnits( const wxString& aId,
125 const DRC_RE_FIELD_POSITION& aPosition,
126 UNIT_BINDER* aUnitBinder,
127 long aStyle = 0 );
128
137 DRC_RE_OVERLAY_FIELD* AddCheckbox( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition );
138
142 void LoadBitmap();
143
147 void PositionFields();
148
153 void SetMinimumHeightDIP( int aHeight ) { m_minHeightDIP = aHeight; }
154
160 void SetupFieldStyling( wxControl* aControl );
161
162private:
163 void OnPaint( wxPaintEvent& aEvent );
164 void OnDPIChanged( wxDPIChangedEvent& aEvent );
165 void OnThemeChange( wxSysColourChangedEvent& aEvent );
166
167 wxColour pageBackground() const;
168
169 std::optional<int> roomBeforeNextField( const DRC_RE_OVERLAY_FIELD* aField ) const;
170 void OnFieldFocus( wxFocusEvent& aEvent );
171 void OnFieldBlur( wxFocusEvent& aEvent );
172
178 void PositionLabel( DRC_RE_OVERLAY_FIELD* aField );
179
186
187protected:
188 wxBitmap m_bitmap;
192
193 std::vector<std::unique_ptr<DRC_RE_OVERLAY_FIELD>> m_fields;
194 std::map<wxString, DRC_RE_OVERLAY_FIELD*> m_fieldIdMap;
195};
196
197
198template <typename T>
200 const DRC_RE_FIELD_POSITION& aPosition, T* aControl )
201{
202 // Create the overlay field wrapper
203 auto field = std::make_unique<DRC_RE_OVERLAY_FIELD>( this, aId, aControl, aPosition );
204 DRC_RE_OVERLAY_FIELD* fieldPtr = field.get();
205
206 // Set up styling
207 SetupFieldStyling( aControl );
208
209 if( !aPosition.tooltipText.IsEmpty() )
210 aControl->SetToolTip( aPosition.tooltipText );
211
212 // Position the field (yCenter is vertical mid-point of the control)
213 int height = aControl->GetBestSize().GetHeight();
214 int width = aPosition.xEnd - aPosition.xStart;
215 wxPoint pos( aPosition.xStart, aPosition.yCenter - ( height + 1 ) / 2 );
216 wxSize size( width, height );
217 aControl->SetPosition( pos );
218 aControl->SetSize( size );
219
220 // Create labels if specified
221 fieldPtr->CreateLabels();
222
223 if( fieldPtr->HasLabel() )
224 PositionLabel( fieldPtr );
225
226 if( fieldPtr->HasPrefixLabel() )
227 PositionPrefixLabel( fieldPtr );
228
229 // Store in collections
230 m_fieldIdMap[aId] = fieldPtr;
231 m_fields.push_back( std::move( field ) );
232
233 return fieldPtr;
234}
235
236
237template <typename T>
239 const DRC_RE_FIELD_POSITION& aPosition, long aStyle )
240{
241 // Create the control
242 T* control = new T( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, aStyle );
243
244 return AddControl( aId, aPosition, control );
245}
246
247
248template <typename T>
250 const DRC_RE_FIELD_POSITION& aPosition,
251 UNIT_BINDER* aUnitBinder,
252 long aStyle )
253{
254 // Create the field using the base AddField method
255 DRC_RE_OVERLAY_FIELD* field = AddField<T>( aId, aPosition, aStyle );
256
257 // Associate the unit binder for value conversion
258 field->SetUnitBinder( aUnitBinder );
259
260 return field;
261}
262
263#endif // DRC_RE_BITMAP_OVERLAY_PANEL_H
BITMAPS
A list of all bitmap identifiers.
DRC_RE_OVERLAY_FIELD * AddCheckbox(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition)
Create and position a checkbox control on the bitmap overlay.
void LoadBitmap()
Load the appropriate bitmap variant for the current theme and DPI.
void OnThemeChange(wxSysColourChangedEvent &aEvent)
wxBitmap m_bitmap
Current background bitmap.
DRC_RE_OVERLAY_FIELD * AddControl(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, T *aControl)
Position a control on the bitmap overlay.
void OnDPIChanged(wxDPIChangedEvent &aEvent)
void SetMinimumHeightDIP(int aHeight)
Asks for a panel taller than its illustration.
void PositionLabel(DRC_RE_OVERLAY_FIELD *aField)
Position a label relative to its field control based on the label position setting.
DRC_RE_OVERLAY_FIELD * AddField(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, long aStyle=0)
Create and position a field control on the bitmap overlay.
std::optional< int > roomBeforeNextField(const DRC_RE_OVERLAY_FIELD *aField) const
void SetupFieldStyling(wxControl *aControl)
Apply transparent styling to a field control.
std::map< wxString, DRC_RE_OVERLAY_FIELD * > m_fieldIdMap
Field ID to field lookup.
void ShowFieldError(const wxString &aFieldId, const wxString &aMessage)
Show an error indicator on the specified field.
int m_minHeightDIP
Height a subclass asks for, in DIP.
void SetBackgroundBitmap(BITMAPS aBitmap)
Set the background bitmap for this panel.
wxSize m_logicalBitmapSize
Bitmap size in logical pixels.
DRC_RE_BITMAP_OVERLAY_PANEL(wxWindow *aParent, wxWindowID aId=wxID_ANY)
void ClearFieldErrors()
Clear error indicators from all fields.
BITMAPS m_bitmapId
BITMAPS enum value.
void PositionFields()
Position all fields based on the current scale factor.
DRC_RE_OVERLAY_FIELD * AddFieldWithUnits(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, UNIT_BINDER *aUnitBinder, long aStyle=0)
Create and position a field control with unit binding.
std::vector< std::unique_ptr< DRC_RE_OVERLAY_FIELD > > m_fields
All overlay fields.
void PositionPrefixLabel(DRC_RE_OVERLAY_FIELD *aField)
Position a prefix label to the left of its field control.
Wraps a wxControl positioned over a bitmap overlay panel.
void CreateLabels()
Create and associate labels with this field.
void SetUnitBinder(UNIT_BINDER *aBinder)
Associate a UNIT_BINDER for unit conversion.
Specifies the position and size of a field overlaid on a constraint bitmap.
int xEnd
Right edge X coordinate where the field ends.
int xStart
Left edge X coordinate where the field starts.
int yCenter
Vertical center Y coordinate of the field.
wxString tooltipText
Optional tooltip shown on the control.