You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <eda_base_frame.h>
  25. #include <dialog_helpers.h>
  26. #include <base_units.h>
  27. /********************************************************/
  28. /* Class to display and edit a coordinated INCHES or MM */
  29. /********************************************************/
  30. EDA_POSITION_CTRL::EDA_POSITION_CTRL( wxWindow* parent, const wxString& title, const wxPoint& aPos,
  31. EDA_UNITS user_unit, wxBoxSizer* BoxSizer )
  32. {
  33. m_UserUnit = user_unit;
  34. m_TextX = new wxStaticText( parent, -1, title + wxS( " " ) + _( "X:" ) );
  35. BoxSizer->Add( m_TextX, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
  36. m_FramePosX = new wxTextCtrl( parent, -1, wxEmptyString, wxDefaultPosition );
  37. BoxSizer->Add( m_FramePosX, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
  38. m_TextY = new wxStaticText( parent, -1, title + wxS( " " ) + _( "Y:" ) );
  39. BoxSizer->Add( m_TextY, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
  40. m_FramePosY = new wxTextCtrl( parent, -1, wxEmptyString );
  41. BoxSizer->Add( m_FramePosY, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
  42. SetValue( aPos.x, aPos.y );
  43. }
  44. EDA_POSITION_CTRL::~EDA_POSITION_CTRL()
  45. {
  46. delete m_TextX;
  47. delete m_TextY;
  48. delete m_FramePosX;
  49. delete m_FramePosY;
  50. }
  51. /* Returns (in internal units) to coordinate between (in user units)
  52. */
  53. wxPoint EDA_POSITION_CTRL::GetValue() const
  54. {
  55. return wxPoint( ValueFromString( m_UserUnit, m_FramePosX->GetValue() ),
  56. ValueFromString( m_UserUnit, m_FramePosY->GetValue() ) );
  57. }
  58. void EDA_POSITION_CTRL::Enable( bool x_win_on, bool y_win_on )
  59. {
  60. m_FramePosX->Enable( x_win_on );
  61. m_FramePosY->Enable( y_win_on );
  62. }
  63. void EDA_POSITION_CTRL::SetValue( int x_value, int y_value )
  64. {
  65. m_FramePosX->SetValue( StringFromValue( m_UserUnit, x_value ) );
  66. m_FramePosY->SetValue( StringFromValue( m_UserUnit, y_value ) );
  67. }
  68. /*******************/
  69. /* EDA_SIZE_CTRL */
  70. /*******************/
  71. EDA_SIZE_CTRL::EDA_SIZE_CTRL( wxWindow* parent, const wxString& title, const wxSize& aSize,
  72. EDA_UNITS aUnit, wxBoxSizer* aBoxSizer )
  73. : EDA_POSITION_CTRL( parent, title, wxPoint( aSize.x, aSize.y ), aUnit, aBoxSizer )
  74. {
  75. }
  76. wxSize EDA_SIZE_CTRL::GetValue() const
  77. {
  78. wxPoint pos = EDA_POSITION_CTRL::GetValue();
  79. return wxSize( pos.x, pos.y );
  80. }