forked from KiCad/kicad-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsch_bus_entry.cpp
681 lines (509 loc) · 20.1 KB
/
sch_bus_entry.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2024 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
*/
#include <sch_draw_panel.h>
#include <bitmaps.h>
#include <core/mirror.h>
#include <schematic.h>
#include <geometry/shape_segment.h>
#include <sch_bus_entry.h>
#include <sch_edit_frame.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <project/net_settings.h>
#include <project/project_file.h>
#include <settings/color_settings.h>
#include <netclass.h>
#include <trigo.h>
#include <board_item.h>
#include <connection_graph.h>
#include "sch_painter.h"
#include "plotters/plotter.h"
SCH_BUS_ENTRY_BASE::SCH_BUS_ENTRY_BASE( KICAD_T aType, const VECTOR2I& pos, bool aFlipY ) :
SCH_ITEM( nullptr, aType )
{
m_pos = pos;
m_size.x = schIUScale.MilsToIU( DEFAULT_SCH_ENTRY_SIZE );
m_size.y = schIUScale.MilsToIU( DEFAULT_SCH_ENTRY_SIZE );
m_stroke.SetWidth( 0 );
m_stroke.SetLineStyle( LINE_STYLE::DEFAULT );
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
if( aFlipY )
m_size.y *= -1;
m_isDanglingStart = m_isDanglingEnd = true;
m_lastResolvedWidth = schIUScale.MilsToIU( DEFAULT_WIRE_WIDTH_MILS );
m_lastResolvedLineStyle = LINE_STYLE::SOLID;
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
}
SCH_BUS_WIRE_ENTRY::SCH_BUS_WIRE_ENTRY( const VECTOR2I& pos, bool aFlipY ) :
SCH_BUS_ENTRY_BASE( SCH_BUS_WIRE_ENTRY_T, pos, aFlipY )
{
m_layer = LAYER_WIRE;
m_connected_bus_item = nullptr;
m_lastResolvedWidth = schIUScale.MilsToIU( DEFAULT_WIRE_WIDTH_MILS );
m_lastResolvedLineStyle = LINE_STYLE::SOLID;
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
}
SCH_BUS_WIRE_ENTRY::SCH_BUS_WIRE_ENTRY( const VECTOR2I& pos, int aQuadrant ) :
SCH_BUS_ENTRY_BASE( SCH_BUS_WIRE_ENTRY_T, pos, false )
{
switch( aQuadrant )
{
case 1: m_size.x *= 1; m_size.y *= -1; break;
case 2: m_size.x *= 1; m_size.y *= 1; break;
case 3: m_size.x *= -1; m_size.y *= 1; break;
case 4: m_size.x *= -1; m_size.y *= -1; break;
default: wxFAIL_MSG( wxS( "SCH_BUS_WIRE_ENTRY ctor: unexpected quadrant" ) );
}
m_layer = LAYER_WIRE;
m_connected_bus_item = nullptr;
m_lastResolvedWidth = schIUScale.MilsToIU( DEFAULT_WIRE_WIDTH_MILS );
m_lastResolvedLineStyle = LINE_STYLE::SOLID;
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
}
SCH_BUS_BUS_ENTRY::SCH_BUS_BUS_ENTRY( const VECTOR2I& pos, bool aFlipY ) :
SCH_BUS_ENTRY_BASE( SCH_BUS_BUS_ENTRY_T, pos, aFlipY )
{
m_layer = LAYER_BUS;
m_connected_bus_items[0] = nullptr;
m_connected_bus_items[1] = nullptr;
m_lastResolvedWidth = schIUScale.MilsToIU( DEFAULT_WIRE_WIDTH_MILS );
m_lastResolvedLineStyle = LINE_STYLE::SOLID;
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
}
EDA_ITEM* SCH_BUS_WIRE_ENTRY::Clone() const
{
return new SCH_BUS_WIRE_ENTRY( *this );
}
EDA_ITEM* SCH_BUS_BUS_ENTRY::Clone() const
{
return new SCH_BUS_BUS_ENTRY( *this );
}
bool SCH_BUS_ENTRY_BASE::doIsConnected( const VECTOR2I& aPosition ) const
{
return ( m_pos == aPosition || GetEnd() == aPosition );
}
VECTOR2I SCH_BUS_ENTRY_BASE::GetEnd() const
{
return VECTOR2I( m_pos.x + m_size.x, m_pos.y + m_size.y );
}
void SCH_BUS_ENTRY_BASE::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
SCH_BUS_ENTRY_BASE* item = dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem );
wxCHECK_RET( item, wxT( "Cannot swap bus entry data with invalid item." ) );
std::swap( m_pos, item->m_pos );
std::swap( m_size, item->m_size );
std::swap( m_stroke, item->m_stroke );
std::swap( m_lastResolvedWidth, item->m_lastResolvedWidth );
std::swap( m_lastResolvedLineStyle, item->m_lastResolvedLineStyle );
std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
}
std::vector<int> SCH_BUS_ENTRY_BASE::ViewGetLayers() const
{
if( Type() == SCH_BUS_BUS_ENTRY_T )
return { LAYER_BUS, LAYER_NET_COLOR_HIGHLIGHT, LAYER_SELECTION_SHADOWS };
return { LAYER_WIRE, LAYER_NET_COLOR_HIGHLIGHT, LAYER_SELECTION_SHADOWS };
}
const BOX2I SCH_BUS_ENTRY_BASE::GetBoundingBox() const
{
BOX2I bbox( m_pos );
bbox.SetEnd( GetEnd() );
bbox.Normalize();
bbox.Inflate( ( GetPenWidth() / 2 ) + 1 );
return bbox;
}
COLOR4D SCH_BUS_ENTRY_BASE::GetBusEntryColor() const
{
if( m_stroke.GetColor() != COLOR4D::UNSPECIFIED )
m_lastResolvedColor = m_stroke.GetColor();
else if( IsConnectable() && !IsConnectivityDirty() )
m_lastResolvedColor = GetEffectiveNetClass()->GetSchematicColor();
return m_lastResolvedColor;
}
void SCH_BUS_ENTRY_BASE::SetPenWidth( int aWidth )
{
m_stroke.SetWidth( aWidth );
m_lastResolvedWidth = aWidth;
}
int SCH_BUS_ENTRY_BASE::GetPenWidth() const
{
return m_lastResolvedWidth;
}
void SCH_BUS_ENTRY_BASE::SetBusEntryColor( const COLOR4D& aColor )
{
m_stroke.SetColor( aColor );
m_lastResolvedColor = aColor;
}
LINE_STYLE SCH_BUS_ENTRY_BASE::GetLineStyle() const
{
if( m_stroke.GetLineStyle() != LINE_STYLE::DEFAULT )
m_lastResolvedLineStyle = m_stroke.GetLineStyle();
else if( IsConnectable() && !IsConnectivityDirty() )
m_lastResolvedLineStyle = (LINE_STYLE) GetEffectiveNetClass()->GetLineStyle();
return m_lastResolvedLineStyle;
}
void SCH_BUS_ENTRY_BASE::SetLineStyle( LINE_STYLE aStyle )
{
m_stroke.SetLineStyle( aStyle );
m_lastResolvedLineStyle = aStyle;
}
int SCH_BUS_WIRE_ENTRY::GetPenWidth() const
{
if( m_stroke.GetWidth() > 0 )
m_lastResolvedWidth = m_stroke.GetWidth();
else if( IsConnectable() && !IsConnectivityDirty() )
m_lastResolvedWidth = GetEffectiveNetClass()->GetWireWidth();
return m_lastResolvedWidth;
}
int SCH_BUS_BUS_ENTRY::GetPenWidth() const
{
if( m_stroke.GetWidth() > 0 )
m_lastResolvedWidth = m_stroke.GetWidth();
else if( IsConnectable() && !IsConnectivityDirty() )
m_lastResolvedWidth = GetEffectiveNetClass()->GetBusWidth();
return m_lastResolvedWidth;
}
void SCH_BUS_WIRE_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
{
DANGLING_END_ITEM item( WIRE_ENTRY_END, this, m_pos );
aItemList.push_back( item );
DANGLING_END_ITEM item1( WIRE_ENTRY_END, this, GetEnd() );
aItemList.push_back( item1 );
}
void SCH_BUS_BUS_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
{
DANGLING_END_ITEM item( BUS_ENTRY_END, this, m_pos );
aItemList.push_back( item );
DANGLING_END_ITEM item1( BUS_ENTRY_END, this, GetEnd() );
aItemList.push_back( item1 );
}
void SCH_BUS_ENTRY_BASE::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
{
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = ( GetBusEntryColor() == COLOR4D::UNSPECIFIED )
? aSettings->GetLayerColor( m_layer )
: GetBusEntryColor();
VECTOR2I start = m_pos + aOffset;
VECTOR2I end = GetEnd() + aOffset;
int penWidth = ( GetPenWidth() == 0 ) ? aSettings->GetDefaultPenWidth() : GetPenWidth();
if( GetLineStyle() <= LINE_STYLE::FIRST_TYPE )
{
GRLine( DC, start.x, start.y, end.x, end.y, penWidth, color );
}
else
{
SHAPE_SEGMENT segment( start, end );
STROKE_PARAMS::Stroke( &segment, GetLineStyle(), penWidth, aSettings,
[&]( const VECTOR2I& a, const VECTOR2I& b )
{
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
} );
}
}
void SCH_BUS_ENTRY_BASE::MirrorVertically( int aCenter )
{
MIRROR( m_pos.y, aCenter );
m_size.y = -m_size.y;
}
void SCH_BUS_ENTRY_BASE::MirrorHorizontally( int aCenter )
{
MIRROR( m_pos.x, aCenter );
m_size.x = -m_size.x;
}
void SCH_BUS_ENTRY_BASE::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
{
RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
RotatePoint( &m_size.x, &m_size.y, aRotateCCW ? ANGLE_90 : ANGLE_270 );
}
bool SCH_BUS_WIRE_ENTRY::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
std::vector<DANGLING_END_ITEM>& aItemListByPos,
const SCH_SHEET_PATH* aPath )
{
bool previousStateStart = m_isDanglingStart;
bool previousStateEnd = m_isDanglingEnd;
m_isDanglingStart = m_isDanglingEnd = true;
// Store the connection type and state for the start (0) and end (1)
bool has_wire[2] = { false };
bool has_bus[2] = { false };
for( unsigned ii = 0; ii < aItemListByType.size(); ii++ )
{
DANGLING_END_ITEM& item = aItemListByType[ii];
if( item.GetItem() == this )
continue;
switch( item.GetType() )
{
case WIRE_END:
if( m_pos == item.GetPosition() )
has_wire[0] = true;
else if( GetEnd() == item.GetPosition() )
has_wire[1] = true;
break;
case BUS_END:
{
// The bus has created 2 DANGLING_END_ITEMs, one per end.
DANGLING_END_ITEM& nextItem = aItemListByType[++ii];
if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), m_pos ) )
has_bus[0] = true;
else if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), GetEnd() ) )
has_bus[1] = true;
}
break;
default:
break;
}
}
// A bus-wire entry is connected at both ends if it has a bus and a wire on its
// ends. Otherwise, we connect only one end (in the case of a wire-wire or bus-bus)
if( ( has_wire[0] && has_bus[1] ) || ( has_wire[1] && has_bus[0] ) )
m_isDanglingEnd = m_isDanglingStart = false;
else if( has_wire[0] || has_bus[0] )
m_isDanglingStart = false;
else if( has_wire[1] || has_bus[1] )
m_isDanglingEnd = false;
return (previousStateStart != m_isDanglingStart) || (previousStateEnd != m_isDanglingEnd);
}
bool SCH_BUS_BUS_ENTRY::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
std::vector<DANGLING_END_ITEM>& aItemListByPos,
const SCH_SHEET_PATH* aPath )
{
bool previousStateStart = m_isDanglingStart;
bool previousStateEnd = m_isDanglingEnd;
m_isDanglingStart = m_isDanglingEnd = true;
// TODO: filter using get_lower as we only use one item type
for( unsigned ii = 0; ii < aItemListByType.size(); ii++ )
{
DANGLING_END_ITEM& item = aItemListByType[ii];
if( item.GetItem() == this )
continue;
switch( item.GetType() )
{
case BUS_END:
{
// The bus has created 2 DANGLING_END_ITEMs, one per end.
DANGLING_END_ITEM& nextItem = aItemListByType[++ii];
if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), m_pos ) )
m_isDanglingStart = false;
if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), GetEnd() ) )
m_isDanglingEnd = false;
}
break;
default:
break;
}
}
return (previousStateStart != m_isDanglingStart) || (previousStateEnd != m_isDanglingEnd);
}
bool SCH_BUS_ENTRY_BASE::IsDangling() const
{
return m_isDanglingStart || m_isDanglingEnd;
}
std::vector<VECTOR2I> SCH_BUS_ENTRY_BASE::GetConnectionPoints() const
{
return { m_pos, GetEnd() };
}
bool SCH_BUS_ENTRY_BASE::HasConnectivityChanges( const SCH_ITEM* aItem,
const SCH_SHEET_PATH* aInstance ) const
{
// Do not compare to ourself.
if( aItem == this )
return false;
const SCH_BUS_ENTRY_BASE* busEntry = dynamic_cast<const SCH_BUS_ENTRY_BASE*>( aItem );
// Don't compare against a different SCH_ITEM.
wxCHECK( busEntry, false );
if( GetPosition() != busEntry->GetPosition() )
return true;
return GetEnd() != busEntry->GetEnd();
}
wxString SCH_BUS_WIRE_ENTRY::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
{
return wxString( _( "Bus to Wire Entry" ) );
}
wxString SCH_BUS_BUS_ENTRY::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
{
return wxString( _( "Bus to Bus Entry" ) );
}
BITMAPS SCH_BUS_WIRE_ENTRY::GetMenuImage() const
{
return BITMAPS::add_line2bus;
}
BITMAPS SCH_BUS_BUS_ENTRY::GetMenuImage() const
{
return BITMAPS::add_bus2bus;
}
bool SCH_BUS_ENTRY_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{
// Insure minimum accuracy
if( aAccuracy == 0 )
aAccuracy = ( GetPenWidth() / 2 ) + 4;
return TestSegmentHit( aPosition, m_pos, GetEnd(), aAccuracy );
}
bool SCH_BUS_ENTRY_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
BOX2I rect = aRect;
rect.Inflate( aAccuracy );
if( aContained )
return rect.Contains( GetBoundingBox() );
return rect.Intersects( GetBoundingBox() );
}
void SCH_BUS_ENTRY_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
{
if( aBackground )
return;
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
COLOR4D color = ( GetBusEntryColor() == COLOR4D::UNSPECIFIED )
? renderSettings->GetLayerColor( m_layer ) : GetBusEntryColor();
int penWidth = ( GetPenWidth() == 0 ) ? renderSettings->GetDefaultPenWidth() : GetPenWidth();
penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
aPlotter->SetCurrentLineWidth( penWidth );
aPlotter->SetColor( color );
aPlotter->SetDash( penWidth, GetLineStyle() );
aPlotter->MoveTo( m_pos );
aPlotter->FinishTo( GetEnd() );
aPlotter->SetDash( penWidth, LINE_STYLE::SOLID );
}
void SCH_BUS_ENTRY_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
std::vector<MSG_PANEL_ITEM>& aList )
{
wxString msg;
switch( GetLayer() )
{
default:
case LAYER_WIRE: msg = _( "Wire" ); break;
case LAYER_BUS: msg = _( "Bus" ); break;
}
aList.emplace_back( _( "Bus Entry Type" ), msg );
SCH_CONNECTION* conn = nullptr;
if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
conn = Connection();
if( conn )
{
conn->AppendInfoToMsgPanel( aList );
if( !conn->IsBus() )
aList.emplace_back( _( "Resolved Netclass" ), GetEffectiveNetClass()->GetName() );
}
}
bool SCH_BUS_ENTRY_BASE::operator <( const SCH_ITEM& aItem ) const
{
if( Type() != aItem.Type() )
return Type() < aItem.Type();
auto symbol = static_cast<const SCH_BUS_ENTRY_BASE*>( &aItem );
if( GetLayer() != symbol->GetLayer() )
return GetLayer() < symbol->GetLayer();
if( GetPosition().x != symbol->GetPosition().x )
return GetPosition().x < symbol->GetPosition().x;
if( GetPosition().y != symbol->GetPosition().y )
return GetPosition().y < symbol->GetPosition().y;
if( GetEnd().x != symbol->GetEnd().x )
return GetEnd().x < symbol->GetEnd().x;
return GetEnd().y < symbol->GetEnd().y;
}
bool SCH_BUS_WIRE_ENTRY::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const
{
// Don't generate connections between bus entries and buses, since there is
// a connectivity change at that point (e.g. A[7..0] to A7)
if( ( aItem->Type() == SCH_LINE_T ) &&
( static_cast<const SCH_LINE*>( aItem )->GetLayer() == LAYER_BUS ) )
{
return false;
}
// Same for bus junctions
if( ( aItem->Type() == SCH_JUNCTION_T ) &&
( static_cast<const SCH_JUNCTION*>( aItem )->GetLayer() == LAYER_BUS_JUNCTION ) )
{
return false;
}
// Don't generate connections between bus entries and bus labels that happen
// to land at the same point on the bus wire as this bus entry
if( ( aItem->Type() == SCH_LABEL_T ) &&
SCH_CONNECTION::IsBusLabel( static_cast<const SCH_LABEL*>( aItem )->GetText() ) )
{
return false;
}
// Don't generate connections between two bus-wire entries
if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
return false;
return true;
}
bool SCH_BUS_ENTRY_BASE::operator==( const SCH_ITEM& aItem ) const
{
if( Type() != aItem.Type() )
return false;
const SCH_BUS_ENTRY_BASE* symbol = static_cast<const SCH_BUS_ENTRY_BASE*>( &aItem );
if( GetLayer() != symbol->GetLayer() )
return false;
if( GetPosition() != symbol->GetPosition() )
return false;
if( GetEnd() != symbol->GetEnd() )
return false;
return true;
}
double SCH_BUS_ENTRY_BASE::Similarity( const SCH_ITEM& aItem ) const
{
if( aItem.Type() != Type() )
return 0.0;
if( m_Uuid == aItem.m_Uuid )
return 1.0;
const SCH_BUS_ENTRY_BASE& other = static_cast<const SCH_BUS_ENTRY_BASE&>( aItem );
if( GetLayer() != other.GetLayer() )
return 0.0;
if( GetPosition() != other.GetPosition() )
return 0.0;
return 1.0;
}
static struct SCH_BUS_ENTRY_DESC
{
SCH_BUS_ENTRY_DESC()
{
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
REGISTER_TYPE( SCH_BUS_WIRE_ENTRY );
REGISTER_TYPE( SCH_BUS_BUS_ENTRY );
REGISTER_TYPE( SCH_BUS_ENTRY_BASE );
propMgr.InheritsAfter( TYPE_HASH( SCH_BUS_ENTRY_BASE ), TYPE_HASH( SCH_ITEM ) );
propMgr.InheritsAfter( TYPE_HASH( SCH_BUS_WIRE_ENTRY ), TYPE_HASH( SCH_BUS_ENTRY_BASE ) );
propMgr.InheritsAfter( TYPE_HASH( SCH_BUS_BUS_ENTRY ), TYPE_HASH( SCH_BUS_ENTRY_BASE ) );
ENUM_MAP<LINE_STYLE>& plotDashTypeEnum = ENUM_MAP<LINE_STYLE>::Instance();
if( plotDashTypeEnum.Choices().GetCount() == 0 )
{
plotDashTypeEnum.Map( LINE_STYLE::DEFAULT, _HKI( "Default" ) )
.Map( LINE_STYLE::SOLID, _HKI( "Solid" ) )
.Map( LINE_STYLE::DASH, _HKI( "Dashed" ) )
.Map( LINE_STYLE::DOT, _HKI( "Dotted" ) )
.Map( LINE_STYLE::DASHDOT, _HKI( "Dash-Dot" ) )
.Map( LINE_STYLE::DASHDOTDOT, _HKI( "Dash-Dot-Dot" ) );
}
// TODO: Maybe SCH_BUS_ENTRY_BASE should inherit from or mix in with SCH_LINE
void ( SCH_BUS_ENTRY_BASE::*lineStyleSetter )( LINE_STYLE ) =
&SCH_BUS_ENTRY_BASE::SetLineStyle;
propMgr.AddProperty( new PROPERTY_ENUM<SCH_BUS_ENTRY_BASE, LINE_STYLE>(
_HKI( "Line Style" ),
lineStyleSetter, &SCH_BUS_ENTRY_BASE::GetLineStyle ) );
propMgr.AddProperty( new PROPERTY<SCH_BUS_ENTRY_BASE, int>( _HKI( "Line Width" ),
&SCH_BUS_ENTRY_BASE::SetPenWidth, &SCH_BUS_ENTRY_BASE::GetPenWidth,
PROPERTY_DISPLAY::PT_SIZE ) );
propMgr.AddProperty( new PROPERTY<SCH_BUS_ENTRY_BASE, COLOR4D>( _HKI( "Color" ),
&SCH_BUS_ENTRY_BASE::SetBusEntryColor, &SCH_BUS_ENTRY_BASE::GetBusEntryColor ) );
}
} _SCH_BUS_ENTRY_DESC;