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.

78 lines
2.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018-2022 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. #include <dialogs/dialog_image_properties.h>
  24. #include <dialogs/panel_image_editor.h>
  25. #include <sch_edit_frame.h>
  26. #include <sch_bitmap.h>
  27. #include <tool/tool_manager.h>
  28. #include <tool/actions.h>
  29. DIALOG_IMAGE_PROPERTIES::DIALOG_IMAGE_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_BITMAP* aBitmap ) :
  30. DIALOG_IMAGE_PROPERTIES_BASE( aParent ), m_frame( aParent ), m_bitmap( aBitmap ),
  31. m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
  32. m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit )
  33. {
  34. // Create the image editor page
  35. m_imageEditor = new PANEL_IMAGE_EDITOR( m_Notebook, aBitmap->GetImage() );
  36. m_Notebook->AddPage( m_imageEditor, _( "Image" ), false );
  37. m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
  38. m_posY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
  39. SetupStandardButtons();
  40. finishDialogSettings();
  41. }
  42. bool DIALOG_IMAGE_PROPERTIES::TransferDataToWindow()
  43. {
  44. m_posX.SetValue( m_bitmap->GetPosition().x );
  45. m_posY.SetValue( m_bitmap->GetPosition().y );
  46. return true;
  47. }
  48. bool DIALOG_IMAGE_PROPERTIES::TransferDataFromWindow()
  49. {
  50. if( m_imageEditor->TransferDataFromWindow() )
  51. {
  52. // Save old image in undo list if not already in edit
  53. if( m_bitmap->GetEditFlags() == 0 )
  54. m_frame->SaveCopyInUndoList( m_frame->GetScreen(), m_bitmap, UNDO_REDO::CHANGED, false,
  55. false );
  56. // Update our bitmap from the editor
  57. m_imageEditor->TransferToImage( m_bitmap->GetImage() );
  58. m_bitmap->SetPosition( VECTOR2I( m_posX.GetValue(), m_posY.GetValue() ) );
  59. return true;
  60. }
  61. return false;
  62. }