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
27DIALOG_SET_OFFSET::DIALOG_SET_OFFSET( PCB_BASE_FRAME& aParent, VECTOR2I& aOffset, bool aClearToZero ) :
28 DIALOG_SET_OFFSET_BASE( &aParent ), m_clearToZero( aClearToZero ),
29 m_originalOffset( aOffset ), m_updatedOffset( aOffset ),
30 m_xOffset( &aParent, m_xLabel, m_xEntry, m_xUnit ),
31 m_yOffset( &aParent, m_yLabel, m_yEntry, m_yUnit ),
32 m_stateX( 0.0 ),
33 m_stateY( 0.0 ),
34 m_stateRadius( 0.0 ),
35 m_stateTheta( ANGLE_0 )
36{
39
41
42 updateDialogControls( m_polarCoords->IsChecked() );
43
44 if( m_clearToZero )
45 {
46 wxString text = _( "Clear" );
47 m_clearX->SetLabel( text );
48 m_clearY->SetLabel( text );
49
50 text = _( "Reset this value to zero." );
51 m_clearX->SetToolTip( text );
52 m_clearY->SetToolTip( text );
53 }
54 else
55 {
56 wxString text = _( "Reset" );
57 m_clearX->SetLabel( text );
58 m_clearY->SetLabel( text );
59
60 text = _( "Reset this value to the original value." );
61 m_clearX->SetToolTip( text );
62 m_clearY->SetToolTip( text );
63 }
64
66
68}
69
70
71void DIALOG_SET_OFFSET::OnTextFocusLost( wxFocusEvent& event )
72{
73 wxTextCtrl* obj = static_cast<wxTextCtrl*>( event.GetEventObject() );
74
75 if( obj->GetValue().IsEmpty() )
76 obj->SetValue( "0" );
77
78 event.Skip();
79}
80
81
82static void ToPolarDeg( double x, double y, double& r, EDA_ANGLE& q )
83{
84 // convert to polar coordinates
85 r = hypot( x, y );
86
87 q = ( r != 0 ) ? EDA_ANGLE( VECTOR2D( x, y ) ) : ANGLE_0;
88}
89
90
91void DIALOG_SET_OFFSET::OnClear( wxCommandEvent& event )
92{
93 if( m_clearToZero )
94 {
97
98 m_stateX = 0.0;
99 m_stateY = 0.0;
100 m_stateRadius = 0.0;
102 return;
103 }
104
105 const wxObject* const obj = event.GetEventObject();
106 VECTOR2I offset = m_originalOffset;
107 double r;
108 EDA_ANGLE q;
109 ToPolarDeg( offset.x, offset.y, r, q );
110
111 if( obj == m_clearX )
112 {
113 m_stateX = offset.x;
116
117 if( m_polarCoords->IsChecked() )
119 else
121 }
122 else if( obj == m_clearY )
123 {
124 m_stateY = offset.y;
127
128 if( m_polarCoords->IsChecked() )
130 else
132 }
133}
134
135void DIALOG_SET_OFFSET::OnPolarChanged( wxCommandEvent& event )
136{
137 bool newPolar = m_polarCoords->IsChecked();
138 double xOffset = m_xOffset.GetDoubleValue();
139 double yOffset = m_yOffset.GetDoubleValue();
140 updateDialogControls( newPolar );
141
142 if( newPolar )
143 {
144 if( xOffset != m_stateX || yOffset != m_stateY )
145 {
146 m_stateX = xOffset;
147 m_stateY = yOffset;
149
154 }
155 else
156 {
159 }
160 }
161 else
162 {
163 if( xOffset != m_stateRadius || yOffset != m_stateTheta.AsDegrees() )
164 {
165 m_stateRadius = xOffset;
166 m_stateTheta = EDA_ANGLE( yOffset, DEGREES_T );
169
174 }
175 else
176 {
179 }
180 }
181}
182
184{
185 if( aPolar )
186 {
187 m_xOffset.SetLabel( _( "Distance:" ) ); // Polar radius
188 m_yOffset.SetLabel( _( "Angle:" ) ); // Polar theta or angle
189 m_yOffset.SetUnits( EDA_UNITS::DEGREES );
190 m_clearX->SetToolTip( _( "Reset to the current distance from the reference position." ) );
191 m_clearY->SetToolTip( _( "Reset to the current angle from the reference position." ) );
192 }
193 else
194 {
195 m_xOffset.SetLabel( _( "Offset X:" ) );
196 m_yOffset.SetLabel( _( "Offset Y:" ) );
198 m_clearX->SetToolTip( _( "Reset to the current X offset from the reference position." ) );
199 m_clearY->SetToolTip( _( "Reset to the current Y offset from the reference position." ) );
200 }
201}
202
204{
207
208 return true;
209}
210
212{
215
216 return true;
217}
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:75
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:111
double Sin() const
Definition: eda_angle.h:178
double AsDegrees() const
Definition: eda_angle.h:116
double Cos() const
Definition: eda_angle.h:197
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:205
static void ToPolarDeg(double x, double y, double &r, EDA_ANGLE &q)
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:411
@ DEGREES_T
Definition: eda_angle.h:31
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694