-
-
Notifications
You must be signed in to change notification settings - Fork 491
/
sch_bitmap.cpp
353 lines (263 loc) · 10.2 KB
/
sch_bitmap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2011 jean-pierre.charras
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file sch_bitmap.cpp
*/
#include "sch_bitmap.h"
#include <bitmap_base.h>
#include <bitmaps.h>
#include <base_units.h>
#include <common.h>
#include <core/mirror.h>
#include <eda_draw_frame.h>
#include <geometry/geometry_utils.h>
#include <plotters/plotter.h>
#include <sch_draw_panel.h>
#include <settings/color_settings.h>
#include <trigo.h>
#include <wx/mstream.h>
SCH_BITMAP::SCH_BITMAP( const VECTOR2I& pos ) :
SCH_ITEM( nullptr, SCH_BITMAP_T ),
m_referenceImage( schIUScale)
{
m_referenceImage.SetPosition( pos );
m_layer = LAYER_NOTES; // used only to draw/plot a rectangle,
// when a bitmap cannot be drawn or plotted
}
SCH_BITMAP::SCH_BITMAP( const SCH_BITMAP& aSchBitmap ) :
SCH_ITEM( aSchBitmap ),
m_referenceImage( aSchBitmap.m_referenceImage )
{
}
SCH_BITMAP& SCH_BITMAP::operator=( const SCH_ITEM& aItem )
{
wxCHECK_MSG( Type() == aItem.Type(), *this,
wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
GetClass() );
if( &aItem != this )
{
SCH_ITEM::operator=( aItem );
const SCH_BITMAP& bitmap = static_cast<const SCH_BITMAP&>( aItem );
m_referenceImage = bitmap.m_referenceImage;
}
return *this;
}
EDA_ITEM* SCH_BITMAP::Clone() const
{
return new SCH_BITMAP( *this );
}
void SCH_BITMAP::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( aItem->Type() == SCH_BITMAP_T,
wxString::Format( wxT( "SCH_BITMAP object cannot swap data with %s object." ),
aItem->GetClass() ) );
SCH_BITMAP* item = (SCH_BITMAP*) aItem;
m_referenceImage.SwapData( item->m_referenceImage );
}
const BOX2I SCH_BITMAP::GetBoundingBox() const
{
return m_referenceImage.GetBoundingBox();
}
void SCH_BITMAP::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
{
VECTOR2I pos = GetPosition() + aOffset;
m_referenceImage.GetImage().DrawBitmap( aSettings->GetPrintDC(), pos,
aSettings->GetBackgroundColor() );
}
VECTOR2I SCH_BITMAP::GetPosition() const
{
return m_referenceImage.GetPosition();
}
void SCH_BITMAP::SetPosition( const VECTOR2I& aPosition )
{
m_referenceImage.SetPosition( aPosition );
}
void SCH_BITMAP::Move( const VECTOR2I& aMoveVector )
{
SetPosition( GetPosition() + aMoveVector );
}
void SCH_BITMAP::MirrorVertically( int aCenter )
{
m_referenceImage.Flip( VECTOR2I( 0, aCenter ), FLIP_DIRECTION::TOP_BOTTOM );
}
void SCH_BITMAP::MirrorHorizontally( int aCenter )
{
m_referenceImage.Flip( VECTOR2I( aCenter, 0 ), FLIP_DIRECTION::LEFT_RIGHT );
}
void SCH_BITMAP::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
{
m_referenceImage.Rotate( aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
}
#if defined(DEBUG)
void SCH_BITMAP::Show( int nestLevel, std::ostream& os ) const
{
// XML output:
wxString s = GetClass();
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << GetPosition() << "/>\n";
}
#endif
bool SCH_BITMAP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{
return KIGEOM::BoxHitTest( aPosition, GetBoundingBox(), aAccuracy );
}
bool SCH_BITMAP::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
return KIGEOM::BoxHitTest( aRect, GetBoundingBox(), aContained, aAccuracy );
}
void SCH_BITMAP::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
{
if( aBackground )
{
m_referenceImage.GetImage().PlotImage(
aPlotter, GetPosition(), aPlotter->RenderSettings()->GetLayerColor( GetLayer() ),
aPlotter->RenderSettings()->GetDefaultPenWidth() );
}
}
BITMAPS SCH_BITMAP::GetMenuImage() const
{
return BITMAPS::image;
}
void SCH_BITMAP::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
{
aList.emplace_back( _( "Bitmap" ), wxEmptyString );
aList.emplace_back( _( "PPI" ),
wxString::Format( wxT( "%d " ), m_referenceImage.GetImage().GetPPI() ) );
aList.emplace_back( _( "Scale" ),
wxString::Format( wxT( "%f " ), m_referenceImage.GetImageScale() ) );
aList.emplace_back( _( "Width" ),
aFrame->MessageTextFromValue( m_referenceImage.GetSize().x ) );
aList.emplace_back( _( "Height" ),
aFrame->MessageTextFromValue( m_referenceImage.GetSize().y ) );
}
std::vector<int> SCH_BITMAP::ViewGetLayers() const
{
return { LAYER_DRAW_BITMAPS, LAYER_SELECTION_SHADOWS };
}
bool SCH_BITMAP::operator==( const SCH_ITEM& aItem ) const
{
if( Type() != aItem.Type() )
return false;
const SCH_BITMAP& bitmap = static_cast<const SCH_BITMAP&>( aItem );
return m_referenceImage == bitmap.m_referenceImage;
}
double SCH_BITMAP::Similarity( const SCH_ITEM& aItem ) const
{
if( Type() != aItem.Type() )
return 0.0;
if( m_Uuid == aItem.m_Uuid )
return 1.0;
const SCH_BITMAP& bitmap = static_cast<const SCH_BITMAP&>( aItem );
return m_referenceImage.Similarity( bitmap.m_referenceImage );
}
int SCH_BITMAP::GetTransformOriginOffsetX() const
{
return m_referenceImage.GetTransformOriginOffset().x;
}
void SCH_BITMAP::SetTransformOriginOffsetX( int aX )
{
VECTOR2I offset = m_referenceImage.GetTransformOriginOffset();
offset.x = aX;
m_referenceImage.SetTransformOriginOffset( offset );
}
int SCH_BITMAP::GetTransformOriginOffsetY() const
{
return m_referenceImage.GetTransformOriginOffset().y;
}
void SCH_BITMAP::SetTransformOriginOffsetY( int aY )
{
VECTOR2I offset = m_referenceImage.GetTransformOriginOffset();
offset.y = aY;
m_referenceImage.SetTransformOriginOffset( offset );
}
double SCH_BITMAP::GetImageScale() const
{
return m_referenceImage.GetImageScale();
}
void SCH_BITMAP::SetImageScale( double aScale )
{
m_referenceImage.SetImageScale( aScale );
}
int SCH_BITMAP::GetWidth() const
{
return m_referenceImage.GetImage().GetSize().x;
}
void SCH_BITMAP::SetWidth( int aWidth )
{
m_referenceImage.SetWidth( aWidth );
}
int SCH_BITMAP::GetHeight() const
{
return m_referenceImage.GetImage().GetSize().y;
}
void SCH_BITMAP::SetHeight( int aHeight )
{
m_referenceImage.SetHeight( aHeight );
}
static struct SCH_BITMAP_DESC
{
SCH_BITMAP_DESC()
{
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
REGISTER_TYPE( SCH_BITMAP );
propMgr.InheritsAfter( TYPE_HASH( SCH_BITMAP ), TYPE_HASH( SCH_ITEM ) );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>( _HKI( "Position X" ), &SCH_BITMAP::SetX,
&SCH_BITMAP::GetX,
PROPERTY_DISPLAY::PT_COORD ) );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>( _HKI( "Position Y" ), &SCH_BITMAP::SetY,
&SCH_BITMAP::GetY,
PROPERTY_DISPLAY::PT_COORD ) );
const wxString groupImage = _HKI( "Image Properties" );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, double>( _HKI( "Scale" ),
&SCH_BITMAP::SetImageScale,
&SCH_BITMAP::GetImageScale ),
groupImage );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>(
_HKI( "Transform Offset X" ),
&SCH_BITMAP::SetTransformOriginOffsetX,
&SCH_BITMAP::GetTransformOriginOffsetX,
PROPERTY_DISPLAY::PT_COORD, ORIGIN_TRANSFORMS::ABS_X_COORD ),
groupImage );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>(
_HKI( "Transform Offset Y" ),
&SCH_BITMAP::SetTransformOriginOffsetY,
&SCH_BITMAP::GetTransformOriginOffsetY,
PROPERTY_DISPLAY::PT_COORD, ORIGIN_TRANSFORMS::ABS_Y_COORD ),
groupImage );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>(
_HKI( "Width" ),
&SCH_BITMAP::SetWidth,
&SCH_BITMAP::GetWidth,
PROPERTY_DISPLAY::PT_COORD ),
groupImage );
propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>(
_HKI( "Height" ),
&SCH_BITMAP::SetHeight,
&SCH_BITMAP::GetHeight,
PROPERTY_DISPLAY::PT_COORD ),
groupImage );
}
} _SCH_BITMAP_DESC;