KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_set_offset.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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include "dialog_set_offset.h"
25
26
28{
29 bool polarCoords = false;
30 double entry1 = 0.0;
31 double entry2 = 0.0;
32};
33
35
36
38 bool aClearToZero ) :
39 DIALOG_SET_OFFSET_BASE( &aParent ), m_clearToZero( aClearToZero ),
40 m_originalOffset( aOffset ), m_updatedOffset( aOffset ),
41 m_xOffset( &aParent, m_xLabel, m_xEntry, m_xUnit ),
42 m_yOffset( &aParent, m_yLabel, m_yEntry, m_yUnit )
43{
46
48
49 // and set up the entries according to the saved options
51 updateDialogControls( m_polarCoords->IsChecked() );
52
55
56 if( m_clearToZero )
57 {
58 wxString text = _( "Clear" );
59 m_clearX->SetLabel( text );
60 m_clearY->SetLabel( text );
61
62 text = _( "Reset this value to zero." );
63 m_clearX->SetToolTip( text );
64 m_clearY->SetToolTip( text );
65 }
66 else
67 {
68 wxString text = _( "Reset" );
69 m_clearX->SetLabel( text );
70 m_clearY->SetLabel( text );
71
72 text = _( "Reset this value to the original value." );
73 m_clearX->SetToolTip( text );
74 m_clearY->SetToolTip( text );
75 }
76
78
80}
81
82
83void DIALOG_SET_OFFSET::OnTextFocusLost( wxFocusEvent& event )
84{
85 wxTextCtrl* obj = static_cast<wxTextCtrl*>( event.GetEventObject() );
86
87 if( obj->GetValue().IsEmpty() )
88 obj->SetValue( "0" );
89
90 event.Skip();
91}
92
93
94static void ToPolarDeg( double x, double y, double& r, EDA_ANGLE& q )
95{
96 // convert to polar coordinates
97 r = hypot( x, y );
98
99 q = ( r != 0 ) ? EDA_ANGLE( VECTOR2D( x, y ) ) : ANGLE_0;
100}
101
102
103void DIALOG_SET_OFFSET::OnClear( wxCommandEvent& event )
104{
105 if( m_clearToZero )
106 {
109
110 m_stateX = 0.0;
111 m_stateY = 0.0;
112 m_stateRadius = 0.0;
114 return;
115 }
116
117 const wxObject* const obj = event.GetEventObject();
118 VECTOR2I offset = m_originalOffset;
119 double r;
120 EDA_ANGLE q;
121 ToPolarDeg( offset.x, offset.y, r, q );
122
123 if( obj == m_clearX )
124 {
125 m_stateX = offset.x;
128
129 if( m_polarCoords->IsChecked() )
131 else
133 }
134 else if( obj == m_clearY )
135 {
136 m_stateY = offset.y;
139
140 if( m_polarCoords->IsChecked() )
142 else
144 }
145}
146
147void DIALOG_SET_OFFSET::OnPolarChanged( wxCommandEvent& event )
148{
149 bool newPolar = m_polarCoords->IsChecked();
150 double xOffset = m_xOffset.GetDoubleValue();
151 double yOffset = m_yOffset.GetDoubleValue();
152 updateDialogControls( newPolar );
153
154 if( newPolar )
155 {
156 if( xOffset != m_stateX || yOffset != m_stateY )
157 {
158 m_stateX = xOffset;
159 m_stateY = yOffset;
161
166 }
167 else
168 {
171 }
172 }
173 else
174 {
175 if( xOffset != m_stateRadius || yOffset != m_stateTheta.AsDegrees() )
176 {
177 m_stateRadius = xOffset;
178 m_stateTheta = EDA_ANGLE( yOffset, DEGREES_T );
181
186 }
187 else
188 {
191 }
192 }
193}
194
196{
197 if( aPolar )
198 {
199 m_xOffset.SetLabel( _( "Distance:" ) ); // Polar radius
200 m_yOffset.SetLabel( _( "Angle:" ) ); // Polar theta or angle
201 m_yOffset.SetUnits( EDA_UNITS::DEGREES );
202 m_clearX->SetToolTip( _( "Reset to the current distance from the reference position." ) );
203 m_clearY->SetToolTip( _( "Reset to the current angle from the reference position." ) );
204 }
205 else
206 {
207 m_xOffset.SetLabel( _( "Offset X:" ) );
208 m_yOffset.SetLabel( _( "Offset Y:" ) );
210 m_clearX->SetToolTip( _( "Reset to the current X offset from the reference position." ) );
211 m_clearY->SetToolTip( _( "Reset to the current Y offset from the reference position." ) );
212 }
213}
214
216{
219
220 return true;
221}
222
224{
227
228 return true;
229}
Class DIALOG_SET_OFFSET_BASE.
virtual bool TransferDataToWindow() override
virtual void OnPolarChanged(wxCommandEvent &event) override
void updateDialogControls(bool aPolar)
virtual void OnTextFocusLost(wxFocusEvent &event) override
virtual bool TransferDataFromWindow() override
DIALOG_SET_OFFSET(PCB_BASE_FRAME &aFrame, VECTOR2I &aOffset, bool aClearToZero)
const VECTOR2I m_originalOffset
virtual void OnClear(wxCommandEvent &event) override
VECTOR2I & m_updatedOffset
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:130
double Sin() const
Definition: eda_angle.h:170
double AsDegrees() const
Definition: eda_angle.h:113
double Cos() const
Definition: eda_angle.h:189
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetUnits(EDA_UNITS aUnits)
Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DE...
virtual EDA_ANGLE GetAngleValue()
virtual double GetDoubleValue()
Return the current value in Internal Units.
virtual void SetAngleValue(const EDA_ANGLE &aValue)
void SetLabel(const wxString &aLabel)
virtual void SetDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:199
static SET_OFFSET_OPTIONS s_savedOptions
static void ToPolarDeg(double x, double y, double &r, EDA_ANGLE &q)
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
@ DEGREES_T
Definition: eda_angle.h:31
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690