-
-
Notifications
You must be signed in to change notification settings - Fork 491
/
sch_junction.cpp
387 lines (283 loc) · 10.1 KB
/
sch_junction.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
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
* 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
*/
#include <sch_draw_panel.h>
#include <trigo.h>
#include <common.h>
#include <plotters/plotter.h>
#include <bitmaps.h>
#include <core/mirror.h>
#include <geometry/shape_rect.h>
#include <sch_painter.h>
#include <sch_junction.h>
#include <sch_edit_frame.h>
#include <sch_connection.h>
#include <schematic.h>
#include <settings/color_settings.h>
#include <connection_graph.h>
#include <string_utils.h>
SCH_JUNCTION::SCH_JUNCTION( const VECTOR2I& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) :
SCH_ITEM( nullptr, SCH_JUNCTION_T )
{
m_pos = aPosition;
m_color = COLOR4D::UNSPECIFIED;
m_diameter = aDiameter;
m_layer = aLayer;
m_lastResolvedDiameter = KiROUND( schIUScale.MilsToIU( DEFAULT_WIRE_WIDTH_MILS ) * 1.7 );
m_lastResolvedColor = COLOR4D::UNSPECIFIED;
}
EDA_ITEM* SCH_JUNCTION::Clone() const
{
return new SCH_JUNCTION( *this );
}
void SCH_JUNCTION::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_JUNCTION_T ),
wxT( "Cannot swap junction data with invalid item." ) );
SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
std::swap( m_pos, item->m_pos );
std::swap( m_diameter, item->m_diameter );
std::swap( m_color, item->m_color );
}
std::vector<int> SCH_JUNCTION::ViewGetLayers() const
{
return { m_layer, LAYER_SELECTION_SHADOWS };
}
SHAPE_CIRCLE SCH_JUNCTION::getEffectiveShape() const
{
if( m_diameter != 0 )
m_lastResolvedDiameter = m_diameter;
else if( Schematic() )
m_lastResolvedDiameter = Schematic()->Settings().m_JunctionSize;
else
m_lastResolvedDiameter = schIUScale.MilsToIU( DEFAULT_JUNCTION_DIAM );
if( m_lastResolvedDiameter != 1 ) // Diameter 1 means user doesn't want to draw junctions
{
// If we know what we're connected to, then enforce a minimum size of 170% of the
// connected wire width:
if( !IsConnectivityDirty() )
{
m_lastResolvedDiameter = std::max<int>( m_lastResolvedDiameter,
GetEffectiveNetClass()->GetWireWidth() * 1.7 );
}
}
return SHAPE_CIRCLE( m_pos, std::max( m_lastResolvedDiameter / 2, 1 ) );
}
const BOX2I SCH_JUNCTION::GetBoundingBox() const
{
BOX2I bbox( m_pos );
bbox.Inflate( getEffectiveShape().GetRadius() );
return bbox;
}
void SCH_JUNCTION::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
{
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = GetJunctionColor();
if( color == COLOR4D::UNSPECIFIED )
color = aSettings->GetLayerColor( GetLayer() );
SHAPE_CIRCLE circle = getEffectiveShape();
GRFilledCircle( DC, circle.GetCenter() + aOffset, circle.GetRadius(), 0, color, color );
}
void SCH_JUNCTION::MirrorVertically( int aCenter )
{
MIRROR( m_pos.y, aCenter );
}
void SCH_JUNCTION::MirrorHorizontally( int aCenter )
{
MIRROR( m_pos.x, aCenter );
}
void SCH_JUNCTION::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
{
RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
}
void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{
DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
aItemList.push_back( item );
}
std::vector<VECTOR2I> SCH_JUNCTION::GetConnectionPoints() const
{
return { m_pos };
}
#if defined(DEBUG)
void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
{
// XML output:
wxString s = GetClass();
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter
<< "/>\n";
}
#endif
void SCH_JUNCTION::SetDiameter( int aDiameter )
{
m_diameter = aDiameter;
m_lastResolvedDiameter = aDiameter;
}
COLOR4D SCH_JUNCTION::GetJunctionColor() const
{
if( m_color != COLOR4D::UNSPECIFIED )
m_lastResolvedColor = m_color;
else if( !IsConnectivityDirty() )
m_lastResolvedColor = GetEffectiveNetClass()->GetSchematicColor();
return m_lastResolvedColor;
}
void SCH_JUNCTION::SetColor( const COLOR4D& aColor )
{
m_color = aColor;
m_lastResolvedColor = aColor;
}
int SCH_JUNCTION::GetEffectiveDiameter() const
{
return getEffectiveShape().GetRadius() * 2;
}
bool SCH_JUNCTION::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{
if( aAccuracy >= 0 )
return getEffectiveShape().Collide( SEG( aPosition, aPosition ), aAccuracy );
else
return aPosition == m_pos;
}
bool SCH_JUNCTION::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
if( m_flags & STRUCT_DELETED || m_flags & SKIP_STRUCT )
return false;
if( aContained )
{
BOX2I selRect( aRect );
return selRect.Inflate( aAccuracy ).Contains( GetBoundingBox() );
}
else
{
SHAPE_CIRCLE junction = getEffectiveShape();
SHAPE_RECT selRect( aRect.GetPosition(), aRect.GetWidth(), aRect.GetHeight() );
return selRect.Collide( &junction, aAccuracy );
}
}
bool SCH_JUNCTION::HasConnectivityChanges( const SCH_ITEM* aItem,
const SCH_SHEET_PATH* aInstance ) const
{
// Do not compare to ourself.
if( aItem == this )
return false;
const SCH_JUNCTION* junction = dynamic_cast<const SCH_JUNCTION*>( aItem );
// Don't compare against a different SCH_ITEM.
wxCHECK( junction, false );
return GetPosition() != junction->GetPosition();
}
bool SCH_JUNCTION::doIsConnected( const VECTOR2I& aPosition ) const
{
return m_pos == aPosition;
}
void SCH_JUNCTION::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
{
if( aBackground )
return;
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
COLOR4D color = GetJunctionColor();
if( color == COLOR4D::UNSPECIFIED )
color = settings->GetLayerColor( GetLayer() );
aPlotter->SetColor( color );
aPlotter->Circle( m_pos, GetEffectiveDiameter(), FILL_T::FILLED_SHAPE );
}
BITMAPS SCH_JUNCTION::GetMenuImage() const
{
return BITMAPS::add_junction;
}
bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
{
if( Type() != aItem.Type() )
return Type() < aItem.Type();
if( GetLayer() != aItem.GetLayer() )
return GetLayer() < aItem.GetLayer();
const SCH_JUNCTION* junction = static_cast<const SCH_JUNCTION*>( &aItem );
if( GetPosition().x != junction->GetPosition().x )
return GetPosition().x < junction->GetPosition().x;
if( GetPosition().y != junction->GetPosition().y )
return GetPosition().y < junction->GetPosition().y;
if( GetDiameter() != junction->GetDiameter() )
return GetDiameter() < junction->GetDiameter();
return GetColor() < junction->GetColor();
}
void SCH_JUNCTION::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
{
aList.emplace_back( _( "Junction" ), wxEmptyString );
aList.emplace_back( _( "Size" ), aFrame->MessageTextFromValue( GetEffectiveDiameter() ) );
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" ),
UnescapeString( GetEffectiveNetClass()->GetName() ) );
}
}
}
bool SCH_JUNCTION::operator==( const SCH_ITEM& aOther ) const
{
if( Type() != aOther.Type() )
return false;
const SCH_JUNCTION& other = static_cast<const SCH_JUNCTION&>( aOther );
if( m_pos != other.m_pos )
return false;
if( m_diameter != other.m_diameter )
return false;
if( m_color != other.m_color )
return false;
return true;
}
double SCH_JUNCTION::Similarity( const SCH_ITEM& aOther ) const
{
if( m_Uuid == aOther.m_Uuid )
return 1.0;
if( aOther.Type() != Type() )
return 0.0;
const SCH_JUNCTION& other = static_cast<const SCH_JUNCTION&>( aOther );
double similarity = 1.0;
if( m_pos != other.m_pos )
similarity *= 0.9;
if( m_diameter != other.m_diameter )
similarity *= 0.9;
if( m_color != other.m_color )
similarity *= 0.9;
return similarity;
}
static struct SCH_JUNCTION_DESC
{
SCH_JUNCTION_DESC()
{
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
REGISTER_TYPE( SCH_JUNCTION );
propMgr.InheritsAfter( TYPE_HASH( SCH_JUNCTION ), TYPE_HASH( SCH_ITEM ) );
propMgr.AddProperty( new PROPERTY<SCH_JUNCTION, int>( _HKI( "Diameter" ),
&SCH_JUNCTION::SetDiameter, &SCH_JUNCTION::GetDiameter,
PROPERTY_DISPLAY::PT_SIZE ) );
propMgr.AddProperty( new PROPERTY<SCH_JUNCTION, COLOR4D>( _HKI( "Color" ),
&SCH_JUNCTION::SetColor, &SCH_JUNCTION::GetColor ) );
}
} _SCH_JUNCTION_DESC;