KiCad PCB EDA Suite
edit_bitmap.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 (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 
29 #include <fctsys.h>
30 #include <sch_draw_panel.h>
31 #include <sch_view.h>
32 #include <sch_edit_frame.h>
33 #include <sch_bitmap.h>
34 #include <dialog_image_editor.h>
35 
36 #include <view/view_group.h>
37 
38 
40 {
41  wxFileDialog fileDlg( this, _( "Choose Image" ), wxEmptyString, wxEmptyString,
42  _( "Image Files " ) + wxImage::GetImageExtWildcard(),
43  wxFD_OPEN );
44 
45  if( fileDlg.ShowModal() != wxID_OK )
46  return nullptr;
47 
48  wxString fullFilename = fileDlg.GetPath();
49 
50  if( !wxFileExists( fullFilename ) )
51  {
52  wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
53  return nullptr;
54  }
55 
57 
58  SCH_BITMAP* image = new SCH_BITMAP( pos );
59 
60  if( !image->ReadImageFile( fullFilename ) )
61  {
62  wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
63  delete image;
64  return nullptr;
65  }
66 
67  image->SetFlags( IS_NEW );
68  PrepareMoveItem( image );
69 
70 // OnModify();
71  return image;
72 }
73 
74 
76 {
77  if( aItem->GetFlags( ) == 0 )
78  SaveCopyInUndoList( aItem, UR_ROTATED, false, aItem->GetPosition() );
79 
80  aItem->Rotate( aItem->GetPosition() );
81 
82  RefreshItem( aItem );
83  OnModify();
84 }
85 
86 
87 void SCH_EDIT_FRAME::MirrorImage( SCH_BITMAP* aItem, bool Is_X_axis )
88 {
89  if( aItem->GetFlags( ) == 0 )
91 
92  if( Is_X_axis )
93  aItem->MirrorX( aItem->GetPosition().y );
94  else
95  aItem->MirrorY( aItem->GetPosition().x );
96 
97  RefreshItem( aItem );
98  OnModify();
99 }
100 
101 
103 {
104  // TODO: change image scale or more
105  DIALOG_IMAGE_EDITOR dlg( this, aItem->GetImage() );
106 
107  if( dlg.ShowModal() != wxID_OK )
108  return;
109 
110  // save old image in undo list if not already in edit
111  // or the image to be edited is part of a block
112  int mask = EDA_ITEM_ALL_FLAGS - ( SELECTED | HIGHLIGHTED | BRIGHTENED );
113  if( ( aItem->GetFlags() & mask ) == 0
115  {
116  SaveCopyInUndoList( aItem, UR_CHANGED );
117  }
118 
119  dlg.TransfertToImage( aItem->GetImage() );
120 
121  RefreshItem( aItem );
122  OnModify();
123 }
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:258
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen* and ...
void MirrorImage(SCH_BITMAP *aItem, bool Is_X_axis)
Mirror a bitmap.
Definition: edit_bitmap.cpp:87
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_bitmap.h:157
#define EDA_ITEM_ALL_FLAGS
Definition: base_struct.h:145
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
Definition: sch_bitmap.cpp:159
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_bitmap.cpp:166
#define SELECTED
Definition: base_struct.h:121
void PrepareMoveItem(SCH_ITEM *aItem)
Start moving aItem using the mouse.
Definition: schedit.cpp:762
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:65
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend=false, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:138
void RotateImage(SCH_BITMAP *aItem)
Definition: edit_bitmap.cpp:75
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
SCH_BITMAP * CreateNewImage(wxDC *aDC)
Definition: edit_bitmap.cpp:39
#define HIGHLIGHTED
item is drawn in normal colors, when the rest is darkened
Definition: base_struct.h:137
BLOCK_STATE_T GetState() const
void RefreshItem(SCH_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Definition: sch_bitmap.cpp:152
void EditImage(SCH_BITMAP *aItem)
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores an image file.
Definition: sch_bitmap.cpp:80
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.