KiCad PCB EDA Suite
sch_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) 2011 jean-pierre.charras
5  * Copyright (C) 2011-2019 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 <plotter.h>
33 #include <trigo.h>
34 #include <macros.h>
35 #include <bitmaps.h>
36 #include <base_units.h>
37 
38 #include <sch_bitmap.h>
39 
40 #include <wx/mstream.h>
41 
42 
45 {
46  m_pos = pos;
47  m_Layer = LAYER_NOTES; // used only to draw/plot a rectangle,
48  // when a bitmap cannot be drawn or plotted
49  m_image = new BITMAP_BASE();
50 }
51 
52 
53 SCH_BITMAP::SCH_BITMAP( const SCH_BITMAP& aSchBitmap ) :
54  SCH_ITEM( aSchBitmap )
55 {
56  m_pos = aSchBitmap.m_pos;
57  m_Layer = aSchBitmap.m_Layer;
58  m_image = new BITMAP_BASE( *aSchBitmap.m_image );
59 }
60 
61 
63 {
64  wxCHECK_MSG( Type() == aItem.Type(), *this,
65  wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
66  GetClass() );
67 
68  if( &aItem != this )
69  {
70  SCH_ITEM::operator=( aItem );
71 
72  SCH_BITMAP* bitmap = (SCH_BITMAP*) &aItem;
73 
74  delete m_image;
75  m_image = new BITMAP_BASE( *bitmap->m_image );
76  m_pos = bitmap->m_pos;
77  }
78 
79  return *this;
80 }
81 
82 
83 bool SCH_BITMAP::ReadImageFile( const wxString& aFullFilename )
84 {
85  return m_image->ReadImageFile( aFullFilename );
86 }
87 
88 
90 {
91  return new SCH_BITMAP( *this );
92 }
93 
94 
96 {
97  wxCHECK_RET( aItem->Type() == SCH_BITMAP_T,
98  wxString::Format( wxT( "SCH_BITMAP object cannot swap data with %s object." ),
99  GetChars( aItem->GetClass() ) ) );
100 
101  SCH_BITMAP* item = (SCH_BITMAP*) aItem;
102  std::swap( m_pos, item->m_pos );
103  std::swap( m_image, item->m_image );
104 }
105 
106 
108 {
109  EDA_RECT rect = m_image->GetBoundingBox();
110 
111  rect.Move( m_pos );
112 
113  return rect;
114 }
115 
116 
117 void SCH_BITMAP::Print( wxDC* aDC, const wxPoint& aOffset )
118 {
119  wxPoint pos = m_pos + aOffset;
120 
121  m_image->DrawBitmap( aDC, pos );
122 }
123 
124 
125 wxSize SCH_BITMAP::GetSize() const
126 {
127  return m_image->GetSize();
128 }
129 
130 
131 void SCH_BITMAP::MirrorX( int aXaxis_position )
132 {
133  MIRROR( m_pos.y, aXaxis_position );
134  m_image->Mirror( true );
135 }
136 
137 
138 void SCH_BITMAP::MirrorY( int aYaxis_position )
139 {
140  MIRROR( m_pos.x, aYaxis_position );
141  m_image->Mirror( false );
142 }
143 
144 
145 void SCH_BITMAP::Rotate( wxPoint aPosition )
146 {
147  RotatePoint( &m_pos, aPosition, 900 );
148  m_image->Rotate( false );
149 }
150 
151 
152 #if defined(DEBUG)
153 void SCH_BITMAP::Show( int nestLevel, std::ostream& os ) const
154 {
155  // XML output:
156  wxString s = GetClass();
157 
158  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
159 }
160 #endif
161 
162 
163 bool SCH_BITMAP::HitTest( const wxPoint& aPosition, int aAccuracy ) const
164 {
165  EDA_RECT rect = GetBoundingBox();
166 
167  rect.Inflate( aAccuracy );
168 
169  return rect.Contains( aPosition );
170 }
171 
172 
173 bool SCH_BITMAP::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
174 {
175  EDA_RECT rect = aRect;
176 
177  rect.Inflate( aAccuracy );
178 
179  if( aContained )
180  return rect.Contains( GetBoundingBox() );
181 
182  return rect.Intersects( GetBoundingBox() );
183 }
184 
185 
186 void SCH_BITMAP::Plot( PLOTTER* aPlotter )
187 {
189  aPlotter, m_pos, aPlotter->ColorSettings()->GetColor( GetLayer() ), GetPenSize() );
190 }
191 
192 
194 {
195  return image_xpm;
196 }
197 
198 
200 {
201  aList.push_back( MSG_PANEL_ITEM( _( "Bitmap" ), wxEmptyString, RED ) );
202 
203  aList.push_back(
204  MSG_PANEL_ITEM( _( "Width" ), MessageTextFromValue( aUnits, GetSize().x ), RED ) );
205  aList.push_back(
206  MSG_PANEL_ITEM( _( "Height" ), MessageTextFromValue( aUnits, GetSize().y ), RED ) );
207 }
208 
209 
210 void SCH_BITMAP::ViewGetLayers( int aLayers[], int& aCount ) const
211 {
212  aCount = 2;
213  aLayers[0] = LAYER_DRAW_BITMAPS;
214  aLayers[1] = LAYER_SELECTION_SHADOWS;
215 }
EDA_UNITS
Definition: common.h:184
SCH_LAYER_ID m_Layer
Definition: sch_item.h:152
SCH_ITEM & operator=(const SCH_ITEM &aItem)
Definition: sch_bitmap.cpp:62
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
PNG memory record (file in memory).
Definition: bitmap_def.h:29
Implementation of conversion functions that require both schematic and board internal units.
to handle and draw images bitmaps
const BITMAP_OPAQUE image_xpm[1]
Definition: image.cpp:56
wxPoint m_pos
Definition: sch_bitmap.h:44
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
void Print(wxDC *aDC, const wxPoint &aOffset) override
Function Print Print a schematic item.
Definition: sch_bitmap.cpp:117
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_bitmap.cpp:193
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_bitmap.cpp:107
void Mirror(bool aVertically)
Function Mirror Mirror image vertically (i.e.
bool Contains(const wxPoint &aPoint) const
Function Contains.
const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
Definition: sch_bitmap.cpp:138
This file contains miscellaneous commonly used macros and functions.
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:51
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_bitmap.cpp:163
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_bitmap.cpp:145
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:123
virtual int GetPenSize() const
Function GetPenSize virtual pure.
Definition: sch_item.h:243
wxSize GetSize() const
Definition: sch_bitmap.cpp:125
#define NULL
wxSize GetSize() const
Function GetSize.
COLOR_SETTINGS * ColorSettings()
Definition: plotter.h:145
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_bitmap.cpp:95
Definition: colors.h:60
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
void GetMsgPanelInfo(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: sch_bitmap.cpp:199
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:224
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aUseMils, EDA_DATA_TYPE aType)
Definition: base_units.cpp:127
Base plotter engine class.
Definition: plotter.h:104
COLOR4D GetColor(int aLayer) const
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Definition: sch_bitmap.cpp:131
#define _(s)
Definition: 3d_actions.cpp:33
void PlotImage(PLOTTER *aPlotter, const wxPoint &aPos, KIGFX::COLOR4D aDefaultColor, int aDefaultPensize)
Function PlotImage Plot bitmap on plotter.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_bitmap.cpp:89
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:174
void DrawBitmap(wxDC *aDC, const wxPoint &aPos)
SCH_BITMAP(const wxPoint &pos=wxPoint(0, 0))
Definition: sch_bitmap.cpp:43
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores an image file.
Definition: sch_bitmap.cpp:83
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Definition: sch_bitmap.cpp:210
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
void Rotate(bool aRotateCCW)
Function Rotate Rotate image CW or CCW.
BITMAP_BASE * m_image
Definition: sch_bitmap.h:45
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_bitmap.h:86
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
Definition: sch_bitmap.cpp:186
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
wxImage * m_image
Definition: bitmap_base.h:56
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212