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 <trigo.h>
32 #include <macros.h>
33 #include <bitmaps.h>
34 
35 #include <sch_bitmap.h>
36 
37 #include <wx/mstream.h>
38 
39 
40 SCH_BITMAP::SCH_BITMAP( const wxPoint& pos ) :
41  SCH_ITEM( NULL, SCH_BITMAP_T )
42 {
43  m_pos = pos;
44  m_Layer = LAYER_NOTES; // used only to draw/plot a rectangle,
45  // when a bitmap cannot be drawn or plotted
46  m_image = new BITMAP_BASE();
47 }
48 
49 
50 SCH_BITMAP::SCH_BITMAP( const SCH_BITMAP& aSchBitmap ) :
51  SCH_ITEM( aSchBitmap )
52 {
53  m_pos = aSchBitmap.m_pos;
54  m_Layer = aSchBitmap.m_Layer;
55  m_image = new BITMAP_BASE( *aSchBitmap.m_image );
56 }
57 
58 
60 {
61  wxCHECK_MSG( Type() == aItem.Type(), *this,
62  wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
63  GetClass() );
64 
65  if( &aItem != this )
66  {
67  SCH_ITEM::operator=( aItem );
68 
69  SCH_BITMAP* bitmap = (SCH_BITMAP*) &aItem;
70 
71  delete m_image;
72  m_image = new BITMAP_BASE( *bitmap->m_image );
73  m_pos = bitmap->m_pos;
74  }
75 
76  return *this;
77 }
78 
79 
80 bool SCH_BITMAP::ReadImageFile( const wxString& aFullFilename )
81 {
82  return m_image->ReadImageFile( aFullFilename );
83 }
84 
85 
87 {
88  return new SCH_BITMAP( *this );
89 }
90 
91 
93 {
94  wxCHECK_RET( aItem->Type() == SCH_BITMAP_T,
95  wxString::Format( wxT( "SCH_BITMAP object cannot swap data with %s object." ),
96  GetChars( aItem->GetClass() ) ) );
97 
98  SCH_BITMAP* item = (SCH_BITMAP*) aItem;
99  std::swap( m_pos, item->m_pos );
100  std::swap( m_image, item->m_image );
101 }
102 
103 
105 {
106  EDA_RECT rect = m_image->GetBoundingBox();
107 
108  rect.Move( m_pos );
109 
110  return rect;
111 }
112 
113 
114 void SCH_BITMAP::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset )
115 {
116  wxPoint pos = m_pos + aOffset;
117 
118  m_image->DrawBitmap( aDC, pos );
119 }
120 
121 
122 wxSize SCH_BITMAP::GetSize() const
123 {
124  return m_image->GetSize();
125 }
126 
127 
128 void SCH_BITMAP::MirrorX( int aXaxis_position )
129 {
130  MIRROR( m_pos.y, aXaxis_position );
131  m_image->Mirror( true );
132 }
133 
134 
135 void SCH_BITMAP::MirrorY( int aYaxis_position )
136 {
137  MIRROR( m_pos.x, aYaxis_position );
138  m_image->Mirror( false );
139 }
140 
141 
142 void SCH_BITMAP::Rotate( wxPoint aPosition )
143 {
144  RotatePoint( &m_pos, aPosition, 900 );
145  m_image->Rotate( false );
146 }
147 
148 
149 #if defined(DEBUG)
150 void SCH_BITMAP::Show( int nestLevel, std::ostream& os ) const
151 {
152  // XML output:
153  wxString s = GetClass();
154 
155  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
156 }
157 #endif
158 
159 
160 bool SCH_BITMAP::HitTest( const wxPoint& aPosition, int aAccuracy ) const
161 {
162  EDA_RECT rect = GetBoundingBox();
163 
164  rect.Inflate( aAccuracy );
165 
166  return rect.Contains( aPosition );
167 }
168 
169 
170 bool SCH_BITMAP::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
171 {
172  EDA_RECT rect = aRect;
173 
174  rect.Inflate( aAccuracy );
175 
176  if( aContained )
177  return rect.Contains( GetBoundingBox() );
178 
179  return rect.Intersects( GetBoundingBox() );
180 }
181 
182 
183 void SCH_BITMAP::Plot( PLOTTER* aPlotter )
184 {
185  m_image->PlotImage( aPlotter, m_pos, GetLayerColor( GetLayer() ), GetPenSize() );
186 }
187 
188 
189 BITMAP_DEF SCH_BITMAP::GetMenuImage() const
190 {
191  return image_xpm;
192 }
193 
194 
195 void SCH_BITMAP::ViewGetLayers( int aLayers[], int& aCount ) const
196 {
197  aCount = 1;
198  aLayers[0] = LAYER_DRAW_BITMAPS;
199 }
SCH_LAYER_ID m_Layer
Definition: sch_item.h:119
SCH_ITEM & operator=(const SCH_ITEM &aItem)
Definition: sch_bitmap.cpp:59
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
to handle and draw images bitmaps
wxPoint m_pos
Definition: sch_bitmap.h:44
void PlotImage(PLOTTER *aPlotter, const wxPoint &aPos, COLOR4D aDefaultColor, int aDefaultPensize)
Function PlotImage Plot bitmap on plotter.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_bitmap.cpp:189
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_bitmap.cpp:104
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:135
This file contains miscellaneous commonly used macros and functions.
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:46
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:160
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_bitmap.cpp:142
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:122
virtual int GetPenSize() const
Function GetPenSize virtual pure.
Definition: sch_item.h:212
wxSize GetSize() const
Definition: sch_bitmap.cpp:122
wxSize GetSize() const
Function GetSize.
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_bitmap.cpp:92
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
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:193
Base plotter engine class.
Definition: plotter.h:97
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:100
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:128
Class 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:86
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
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:140
void DrawBitmap(wxDC *aDC, const wxPoint &aPos)
SCH_BITMAP(const wxPoint &pos=wxPoint(0, 0))
Definition: sch_bitmap.cpp:40
bool ReadImageFile(const wxString &aFullFilename)
Function ReadImageFile Reads and stores in memory an image file.
Definition: bitmap_base.cpp:81
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores an image file.
Definition: sch_bitmap.cpp:80
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Definition: sch_bitmap.cpp:195
void Rotate(bool aRotateCCW)
Function Rotate Rotate image CW or CCW.
BITMAP_BASE * m_image
Definition: sch_bitmap.h:45
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset) override
Function Draw Draw a schematic item.
Definition: sch_bitmap.cpp:114
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_bitmap.h:99
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
Definition: sch_bitmap.cpp:183
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:51
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204