-
-
Notifications
You must be signed in to change notification settings - Fork 491
/
sch_no_connect.cpp
245 lines (178 loc) · 6.35 KB
/
sch_no_connect.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
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanoadoo.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
*/
/**
* @file sch_no_connect.cpp
* @brief Class SCH_NO_CONNECT implementation.
*/
#include <sch_draw_panel.h>
#include <plotters/plotter.h>
#include <bitmaps.h>
#include <schematic.h>
#include <sch_no_connect.h>
#include <settings/color_settings.h>
#include <default_values.h> // For some default values
#include <core/mirror.h>
#include <trigo.h>
#include <gr_basic.h>
SCH_NO_CONNECT::SCH_NO_CONNECT( const VECTOR2I& pos ) :
SCH_ITEM( nullptr, SCH_NO_CONNECT_T )
{
m_pos = pos;
m_size = schIUScale.MilsToIU( DEFAULT_NOCONNECT_SIZE ); ///< No-connect symbol size.
SetLayer( LAYER_NOCONNECT );
}
EDA_ITEM* SCH_NO_CONNECT::Clone() const
{
return new SCH_NO_CONNECT( *this );
}
void SCH_NO_CONNECT::SwapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ),
wxT( "Cannot swap no connect data with invalid item." ) );
SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
std::swap( m_pos, item->m_pos );
std::swap( m_size, item->m_size );
}
const BOX2I SCH_NO_CONNECT::GetBoundingBox() const
{
int delta = ( GetPenWidth() + GetSize() ) / 2;
BOX2I bbox( m_pos );
bbox.Inflate( delta );
return bbox;
}
std::vector<int> SCH_NO_CONNECT::ViewGetLayers() const
{
return { LAYER_NOCONNECT, LAYER_SELECTION_SHADOWS };
}
void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
{
DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
aItemList.push_back( item );
}
int SCH_NO_CONNECT::GetPenWidth() const
{
if( !Schematic() )
return 1;
return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
}
void SCH_NO_CONNECT::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
{
wxDC* DC = aSettings->GetPrintDC();
int half = GetSize() / 2;
int penWidth = GetEffectivePenWidth( aSettings );
int pX = m_pos.x + aOffset.x;
int pY = m_pos.y + aOffset.y;
COLOR4D color = aSettings->GetLayerColor( LAYER_NOCONNECT );
GRLine( DC, pX - half, pY - half, pX + half, pY + half, penWidth, color );
GRLine( DC, pX + half, pY - half, pX - half, pY + half, penWidth, color );
}
void SCH_NO_CONNECT::MirrorVertically( int aCenter )
{
MIRROR( m_pos.y, aCenter );
}
void SCH_NO_CONNECT::MirrorHorizontally( int aCenter )
{
MIRROR( m_pos.x, aCenter );
}
void SCH_NO_CONNECT::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
{
RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
}
bool SCH_NO_CONNECT::HasConnectivityChanges( const SCH_ITEM* aItem,
const SCH_SHEET_PATH* aInstance ) const
{
// Do not compare to ourself.
if( aItem == this )
return false;
const SCH_NO_CONNECT* noConnect = dynamic_cast<const SCH_NO_CONNECT*>( aItem );
// Don't compare against a different SCH_ITEM.
wxCHECK( noConnect, false );
return GetPosition() != noConnect->GetPosition();
}
std::vector<VECTOR2I> SCH_NO_CONNECT::GetConnectionPoints() const
{
return { m_pos };
}
bool SCH_NO_CONNECT::doIsConnected( const VECTOR2I& aPosition ) const
{
return m_pos == aPosition;
}
bool SCH_NO_CONNECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{
int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
VECTOR2I dist = aPosition - m_pos;
if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
return true;
return false;
}
bool SCH_NO_CONNECT::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_NO_CONNECT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
{
if( aBackground )
return;
int delta = GetSize() / 2;
int pX = m_pos.x;
int pY = m_pos.y;
int penWidth = GetEffectivePenWidth( getRenderSettings( aPlotter ) );
aPlotter->SetCurrentLineWidth( penWidth );
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );
aPlotter->MoveTo( VECTOR2I( pX - delta, pY - delta ) );
aPlotter->FinishTo( VECTOR2I( pX + delta, pY + delta ) );
aPlotter->MoveTo( VECTOR2I( pX + delta, pY - delta ) );
aPlotter->FinishTo( VECTOR2I( pX - delta, pY + delta ) );
}
BITMAPS SCH_NO_CONNECT::GetMenuImage() const
{
return BITMAPS::noconn;
}
bool SCH_NO_CONNECT::operator==( const SCH_ITEM& aOther ) const
{
if( aOther.Type() != Type() )
return false;
const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
if( m_pos != other->m_pos )
return false;
return true;
}
double SCH_NO_CONNECT::Similarity( const SCH_ITEM& aOther ) const
{
if( m_Uuid == aOther.m_Uuid )
return 1.0;
if( aOther.Type() != Type() )
return 0.0;
const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
if( m_pos != other->m_pos )
return 0.0;
return 1.0;
}