KiCad PCB EDA Suite
Loading...
Searching...
No Matches
geom_field_helpers.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
22#include <widgets/unit_binder.h>
23
24#include <wx/gbsizer.h>
25#include <wx/stattext.h>
26#include <wx/textctrl.h>
27
28
29void AddXYPointToSizer( EDA_DRAW_FRAME& aFrame, wxGridBagSizer& aSizer, int row, int col,
30 const wxString& aName, bool aRelative,
31 std::vector<BOUND_CONTROL>& aBoundCtrls )
32{
33 // Name
34 // X [Ctrl] mm
35 // Y [Ctrl] mm
36 wxWindow* parent = aSizer.GetContainingWindow();
37
38 wxStaticText* titleLabel = new wxStaticText( parent, wxID_ANY, aName );
39 aSizer.Add( titleLabel, wxGBPosition( row, col ), wxGBSpan( 1, 3 ),
40 wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL | wxALL | wxEXPAND );
41 row++;
42
43 for( size_t coord = 0; coord < 2; ++coord )
44 {
45 wxStaticText* label = new wxStaticText( parent, wxID_ANY, coord == 0 ? _( "X:" ) : _( "Y:" ) );
46 aSizer.Add( label, wxGBPosition( row, col ), wxDefaultSpan,
47 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT, col > 0 ? 20 : 5 );
48
49 wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, "" );
50 aSizer.Add( ctrl, wxGBPosition( row, col + 1 ), wxDefaultSpan,
51 wxEXPAND | wxALIGN_CENTER_VERTICAL, 5 );
52
53 wxStaticText* units = new wxStaticText( parent, wxID_ANY, _( "mm" ) );
54 aSizer.Add( units, wxGBPosition( row, col + 2 ), wxDefaultSpan,
55 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
56
57 auto binder = std::make_unique<UNIT_BINDER>( &aFrame, label, ctrl, units );
58
59 if( aRelative )
60 binder->SetCoordType( coord == 0 ? ORIGIN_TRANSFORMS::REL_X_COORD : ORIGIN_TRANSFORMS::REL_Y_COORD );
61 else
62 binder->SetCoordType( coord == 0 ? ORIGIN_TRANSFORMS::ABS_X_COORD : ORIGIN_TRANSFORMS::ABS_Y_COORD );
63
64 aBoundCtrls.push_back( BOUND_CONTROL{ std::move( binder ), ctrl } );
65 row++;
66 }
67
68 if( !aSizer.IsColGrowable( col + 1 ) )
69 aSizer.AddGrowableCol( col + 1 );
70}
71
72
73void AddFieldToSizer( EDA_DRAW_FRAME& aFrame, wxGridBagSizer& aSizer, int row, int col,
74 const wxString& aName, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType,
75 bool aIsAngle, std::vector<BOUND_CONTROL>& aBoundCtrls )
76{
77 // Name: [Ctrl] mm
78 wxWindow* parent = aSizer.GetContainingWindow();
79
80 wxStaticText* label = new wxStaticText( parent, wxID_ANY, aName + wxS( ":" ) );
81 aSizer.Add( label, wxGBPosition( row, col ), wxDefaultSpan,
82 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT, col > 0 ? 20 : 5 );
83
84 wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY );
85 aSizer.Add( ctrl, wxGBPosition( row, col + 1 ), wxDefaultSpan,
86 wxEXPAND | wxALIGN_CENTER_VERTICAL, 5 );
87
88 wxStaticText* units = new wxStaticText( parent, wxID_ANY, _( "mm" ) );
89 aSizer.Add( units, wxGBPosition( row, col + 2 ), wxDefaultSpan,
90 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
91
92 auto binder = std::make_unique<UNIT_BINDER>( &aFrame, label, ctrl, units );
93 binder->SetCoordType( aCoordType );
94
95 if( aIsAngle )
96 {
97 binder->SetPrecision( 4 );
98 binder->SetUnits( EDA_UNITS::DEGREES );
99 }
100
101 aBoundCtrls.push_back( BOUND_CONTROL{ std::move( binder ), ctrl } );
102
103 if( !aSizer.IsColGrowable( col + 1 ) )
104 aSizer.AddGrowableCol( col + 1 );
105}
The base class for create windows for drawing purpose.
COORD_TYPES_T
The supported Display Origin Transform types.
#define _(s)
void AddXYPointToSizer(EDA_DRAW_FRAME &aFrame, wxGridBagSizer &aSizer, int row, int col, const wxString &aName, bool aRelative, std::vector< BOUND_CONTROL > &aBoundCtrls)
void AddFieldToSizer(EDA_DRAW_FRAME &aFrame, wxGridBagSizer &aSizer, int row, int col, const wxString &aName, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType, bool aIsAngle, std::vector< BOUND_CONTROL > &aBoundCtrls)