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.

116 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <pcb_edit_frame.h>
  26. #include <dialog_helpers.h>
  27. #include <base_units.h>
  28. #include <board_commit.h>
  29. #include <board.h>
  30. #include <pcb_target.h>
  31. #include <dialog_target_properties_base.h>
  32. #include <widgets/unit_binder.h>
  33. class DIALOG_TARGET_PROPERTIES : public DIALOG_TARGET_PROPERTIES_BASE
  34. {
  35. private:
  36. PCB_EDIT_FRAME* m_Parent;
  37. PCB_TARGET* m_Target;
  38. UNIT_BINDER m_Size;
  39. UNIT_BINDER m_Thickness;
  40. public:
  41. DIALOG_TARGET_PROPERTIES( PCB_EDIT_FRAME* aParent, PCB_TARGET* aTarget );
  42. ~DIALOG_TARGET_PROPERTIES() { }
  43. private:
  44. bool TransferDataToWindow() override;
  45. bool TransferDataFromWindow() override;
  46. };
  47. void PCB_EDIT_FRAME::ShowTargetOptionsDialog( PCB_TARGET* aTarget )
  48. {
  49. DIALOG_TARGET_PROPERTIES dialog( this, aTarget );
  50. dialog.ShowModal();
  51. }
  52. DIALOG_TARGET_PROPERTIES::DIALOG_TARGET_PROPERTIES( PCB_EDIT_FRAME* aParent, PCB_TARGET* aTarget ) :
  53. DIALOG_TARGET_PROPERTIES_BASE( aParent ),
  54. m_Parent( aParent ),
  55. m_Target( aTarget ),
  56. m_Size( aParent, m_sizeLabel, m_sizeCtrl, m_sizeUnits, true ),
  57. m_Thickness( aParent, m_thicknessLabel, m_thicknessCtrl, m_thicknessUnits, true )
  58. {
  59. m_sdbSizerButtsOK->SetDefault();
  60. SetInitialFocus( m_sizeCtrl );
  61. // Now all widgets have the size fixed, call FinishDialogSettings
  62. finishDialogSettings();
  63. }
  64. bool DIALOG_TARGET_PROPERTIES::TransferDataToWindow()
  65. {
  66. m_Size.SetValue( m_Target->GetSize() );
  67. m_Thickness.SetValue( m_Target->GetWidth() );
  68. m_TargetShape->SetSelection( m_Target->GetShape() ? 1 : 0 );
  69. return true;
  70. }
  71. bool DIALOG_TARGET_PROPERTIES::TransferDataFromWindow()
  72. {
  73. // Zero-size targets are hard to see/select.
  74. if( !m_Size.Validate( Mils2iu( 1 ), INT_MAX ) )
  75. return false;
  76. BOARD_COMMIT commit( m_Parent );
  77. commit.Modify( m_Target );
  78. // Save old item in undo list, if is is not currently edited (will be later if so)
  79. bool pushCommit = ( m_Target->GetEditFlags() == 0 );
  80. if( m_Target->GetEditFlags() != 0 ) // other edit in progress (MOVE, NEW ..)
  81. m_Target->SetFlags( IN_EDIT ); // set flag in edit to force
  82. // undo/redo/abort proper operation
  83. m_Target->SetWidth( m_Thickness.GetValue() );
  84. m_Target->SetSize( m_Size.GetValue() );
  85. m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
  86. if( pushCommit )
  87. commit.Push( _( "Modified alignment target" ) );
  88. return true;
  89. }