KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_overlay_field.cpp
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
21
23#include <widgets/unit_binder.h>
24
25#include <wx/control.h>
26#include <wx/stattext.h>
27#include <wx/window.h>
28
29
30DRC_RE_OVERLAY_FIELD::DRC_RE_OVERLAY_FIELD( wxWindow* aParent, const wxString& aFieldId,
31 wxControl* aControl,
32 const DRC_RE_FIELD_POSITION& aPosition ) :
33 m_parent( aParent ),
34 m_fieldId( aFieldId ),
35 m_control( aControl ),
36 m_position( aPosition ),
37 m_getter( nullptr ),
38 m_setter( nullptr ),
39 m_unitBinder( nullptr ),
40 m_errorIcon( nullptr ),
41 m_label( nullptr ),
42 m_prefixLabel( nullptr )
43{
44}
45
46
48{
49 if( m_errorIcon )
50 {
51 m_errorIcon->Destroy();
52 m_errorIcon = nullptr;
53 }
54
55 if( m_label )
56 {
57 m_label->Destroy();
58 m_label = nullptr;
59 }
60}
61
62
63void DRC_RE_OVERLAY_FIELD::ShowError( const wxString& aMessage )
64{
65 if( !m_errorIcon )
67
68 m_errorIcon->SetWarning( aMessage );
69}
70
71
73{
74 if( m_errorIcon )
75 m_errorIcon->SetWarning( wxEmptyString );
76}
77
78
80{
81 return m_errorIcon && m_errorIcon->IsShown();
82}
83
84
86{
87 if( !m_getter )
88 return true;
89
90 try
91 {
92 double value = m_getter();
93
94 if( m_unitBinder )
95 {
96 m_unitBinder->SetDoubleValue( value );
97 }
98
99 return true;
100 }
101 catch( ... )
102 {
103 return false;
104 }
105}
106
107
109{
110 if( !m_setter )
111 return true;
112
113 try
114 {
115 if( m_unitBinder )
116 {
117 double value = m_unitBinder->GetDoubleValue();
118 m_setter( value );
119 }
120
121 return true;
122 }
123 catch( ... )
124 {
125 return false;
126 }
127}
128
129
131{
132 if( !m_label && !m_position.labelText.IsEmpty() && m_position.labelPosition != LABEL_POSITION::NONE
133 && GetControl()->GetLabel() != m_position.labelText )
134 {
135 m_label = new wxStaticText( m_parent, wxID_ANY, m_position.labelText );
136 }
137
138 if( !m_prefixLabel && !m_position.prefixText.IsEmpty() )
139 {
140 m_prefixLabel = new wxStaticText( m_parent, wxID_ANY, m_position.prefixText );
141 }
142}
void ShowError(const wxString &aMessage)
Show the error icon inside the right end of this field, with a tooltip listing the error.
wxStaticText * GetLabel() const
void CreateLabels()
Create and associate labels with this field.
bool TransferFromWindow()
Transfer data from the control to the model.
DRC_RE_OVERLAY_FIELD(wxWindow *aParent, const wxString &aFieldId, wxControl *aControl, const DRC_RE_FIELD_POSITION &aPosition)
Construct an overlay field wrapping an existing control.
bool TransferToWindow()
Transfer data from the model to the control.
DRC_RE_FIELD_POSITION m_position
void ClearError()
Hide the error icon.
FIELD_WARNING_ICON * m_errorIcon
Owned by the control's parent window, created on first error.
wxControl * GetControl() const
A warning icon drawn inside the right edge of a field, left of its dropdown button when it has one,...
Specifies the position and size of a field overlaid on a constraint bitmap.