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 The 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 m_stateX( 0.0 ),
44 m_stateY( 0.0 ),
45 m_stateRadius( 0.0 ),
46 m_stateTheta( ANGLE_0 )
47{
50
52
53 // and set up the entries according to the saved options
55 updateDialogControls( m_polarCoords->IsChecked() );
56
59
60 if( m_clearToZero )
61 {
62 wxString text = _( "Clear" );
63 m_clearX->SetLabel( text );
64 m_clearY->SetLabel( text );
65
66 text = _( "Reset this value to zero." );
67 m_clearX->SetToolTip( text );
68 m_clearY->SetToolTip( text );
69 }
70 else
71 {
72 wxString text = _( "Reset" );
73 m_clearX->SetLabel( text );
74 m_clearY->SetLabel( text );
75
76 text = _( "Reset this value to the original value." );
77 m_clearX->SetToolTip( text );
78 m_clearY->SetToolTip( text );
79 }
80
82
84}
85
86
87void DIALOG_SET_OFFSET::OnTextFocusLost( wxFocusEvent& event )
88{
89 wxTextCtrl* obj = static_cast<wxTextCtrl*>( event.GetEventObject() );
90
91 if( obj->GetValue().IsEmpty() )
92 obj->SetValue( "0" );
93
94 event.Skip();
95}
96
97
98static void ToPolarDeg( double x, double y, double& r, EDA_ANGLE& q )
99{
100 // convert to polar coordinates
101 r = hypot( x, y );
102
103 q = ( r != 0 ) ? EDA_ANGLE( VECTOR2D( x, y ) ) : ANGLE_0;
104}
105
106
107void DIALOG_SET_OFFSET::OnClear( wxCommandEvent& event )
108{
109 if( m_clearToZero )
110 {
113
114 m_stateX = 0.0;
115 m_stateY = 0.0;
116 m_stateRadius = 0.0;
118 return;
119 }
120
121 const wxObject* const obj = event.GetEventObject();
122 VECTOR2I offset = m_originalOffset;
123 double r;
124 EDA_ANGLE q;
125 ToPolarDeg( offset.x, offset.y, r, q );
126
127 if( obj == m_clearX )
128 {
129 m_stateX = offset.x;
132
133 if( m_polarCoords->IsChecked() )
135 else
137 }
138 else if( obj == m_clearY )
139 {
140 m_stateY = offset.y;
143
144 if( m_polarCoords->IsChecked() )
146 else
148 }
149}
150
151void DIALOG_SET_OFFSET::OnPolarChanged( wxCommandEvent& event )
152{
153 bool newPolar = m_polarCoords->IsChecked();
154 double xOffset = m_xOffset.GetDoubleValue();
155 double yOffset = m_yOffset.GetDoubleValue();
156 updateDialogControls( newPolar );
157
158 if( newPolar )
159 {
160 if( xOffset != m_stateX || yOffset != m_stateY )
161 {
162 m_stateX = xOffset;
163 m_stateY = yOffset;
165
170 }
171 else
172 {
175 }
176 }
177 else
178 {
179 if( xOffset != m_stateRadius || yOffset != m_stateTheta.AsDegrees() )
180 {
181 m_stateRadius = xOffset;
182 m_stateTheta = EDA_ANGLE( yOffset, DEGREES_T );
185
190 }
191 else
192 {
195 }
196 }
197}
198
200{
201 if( aPolar )
202 {
203 m_xOffset.SetLabel( _( "Distance:" ) ); // Polar radius
204 m_yOffset.SetLabel( _( "Angle:" ) ); // Polar theta or angle
205 m_yOffset.SetUnits( EDA_UNITS::DEGREES );
206 m_clearX->SetToolTip( _( "Reset to the current distance from the reference position." ) );
207 m_clearY->SetToolTip( _( "Reset to the current angle from the reference position." ) );
208 }
209 else
210 {
211 m_xOffset.SetLabel( _( "Offset X:" ) );
212 m_yOffset.SetLabel( _( "Offset Y:" ) );
214 m_clearX->SetToolTip( _( "Reset to the current X offset from the reference position." ) );
215 m_clearY->SetToolTip( _( "Reset to the current Y offset from the reference position." ) );
216 }
217}
218
220{
223
224 return true;
225}
226
228{
231
232 return true;
233}
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:138
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:200
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:694