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.

124 lines
3.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 jean-pierre.charras
  5. * Copyright (C) 2012-2016 KiCad Developers, see change_log.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. /**
  25. * @file edit_bitmap.cpp
  26. */
  27. #include <fctsys.h>
  28. #include <sch_draw_panel.h>
  29. #include <sch_view.h>
  30. #include <sch_edit_frame.h>
  31. #include <sch_bitmap.h>
  32. #include <dialog_image_editor.h>
  33. #include <view/view_group.h>
  34. SCH_BITMAP* SCH_EDIT_FRAME::CreateNewImage( wxDC* aDC )
  35. {
  36. wxFileDialog fileDlg( this, _( "Choose Image" ), wxEmptyString, wxEmptyString,
  37. _( "Image Files " ) + wxImage::GetImageExtWildcard(),
  38. wxFD_OPEN );
  39. if( fileDlg.ShowModal() != wxID_OK )
  40. return nullptr;
  41. wxString fullFilename = fileDlg.GetPath();
  42. if( !wxFileExists( fullFilename ) )
  43. {
  44. wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
  45. return nullptr;
  46. }
  47. wxPoint pos = GetCrossHairPosition();
  48. SCH_BITMAP* image = new SCH_BITMAP( pos );
  49. if( !image->ReadImageFile( fullFilename ) )
  50. {
  51. wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
  52. delete image;
  53. return nullptr;
  54. }
  55. image->SetFlags( IS_NEW );
  56. PrepareMoveItem( image );
  57. // OnModify();
  58. return image;
  59. }
  60. void SCH_EDIT_FRAME::RotateImage( SCH_BITMAP* aItem )
  61. {
  62. if( aItem->GetFlags( ) == 0 )
  63. SaveCopyInUndoList( aItem, UR_ROTATED, false, aItem->GetPosition() );
  64. aItem->Rotate( aItem->GetPosition() );
  65. RefreshItem( aItem );
  66. OnModify();
  67. }
  68. void SCH_EDIT_FRAME::MirrorImage( SCH_BITMAP* aItem, bool Is_X_axis )
  69. {
  70. if( aItem->GetFlags( ) == 0 )
  71. SaveCopyInUndoList( aItem, UR_CHANGED );
  72. if( Is_X_axis )
  73. aItem->MirrorX( aItem->GetPosition().y );
  74. else
  75. aItem->MirrorY( aItem->GetPosition().x );
  76. RefreshItem( aItem );
  77. OnModify();
  78. }
  79. bool SCH_EDIT_FRAME::EditImage( SCH_BITMAP* aItem )
  80. {
  81. // TODO: change image scale or more
  82. DIALOG_IMAGE_EDITOR dlg( this, aItem->GetImage() );
  83. if( dlg.ShowModal() != wxID_OK )
  84. return false;
  85. // save old image in undo list if not already in edit
  86. // or the image to be edited is part of a block
  87. int mask = EDA_ITEM_ALL_FLAGS - ( SELECTED | HIGHLIGHTED | BRIGHTENED );
  88. if( ( aItem->GetFlags() & mask ) == 0
  89. || GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
  90. {
  91. SaveCopyInUndoList( aItem, UR_CHANGED );
  92. }
  93. dlg.TransfertToImage( aItem->GetImage() );
  94. RefreshItem( aItem );
  95. OnModify();
  96. return true;
  97. }