KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_no_connect.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) 2015 Jean-Pierre Charras, jp.charras at wanoadoo.fr
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.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
30#include <sch_draw_panel.h>
31#include <plotters/plotter.h>
32#include <bitmaps.h>
33#include <schematic.h>
34#include <sch_no_connect.h>
36#include <default_values.h> // For some default values
37#include <core/mirror.h>
38#include <trigo.h>
39#include <gr_basic.h>
40
41
43 SCH_ITEM( nullptr, SCH_NO_CONNECT_T )
44{
45 m_pos = pos;
47
49}
50
51
53{
54 return new SCH_NO_CONNECT( *this );
55}
56
57
59{
60 SCH_ITEM::SwapFlags( aItem );
61
62 wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ),
63 wxT( "Cannot swap no connect data with invalid item." ) );
64
65 SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
66 std::swap( m_pos, item->m_pos );
67 std::swap( m_size, item->m_size );
68}
69
70
72{
73 int delta = ( GetPenWidth() + GetSize() ) / 2;
74 BOX2I bbox( m_pos );
75
76 bbox.Inflate( delta );
77
78 return bbox;
79}
80
81
82void SCH_NO_CONNECT::ViewGetLayers( int aLayers[], int& aCount ) const
83{
84 aCount = 2;
85 aLayers[0] = LAYER_NOCONNECT;
86 aLayers[1] = LAYER_SELECTION_SHADOWS;
87}
88
89
90void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
91{
93 aItemList.push_back( item );
94}
95
96
98{
99 if( !Schematic() )
100 return 1;
101
102 return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
103}
104
105
106void SCH_NO_CONNECT::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
107 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
108{
109 wxDC* DC = aSettings->GetPrintDC();
110 int half = GetSize() / 2;
111 int penWidth = GetEffectivePenWidth( aSettings );
112 int pX = m_pos.x + aOffset.x;
113 int pY = m_pos.y + aOffset.y;
115
116 GRLine( DC, pX - half, pY - half, pX + half, pY + half, penWidth, color );
117 GRLine( DC, pX + half, pY - half, pX - half, pY + half, penWidth, color );
118}
119
120
122{
123 MIRROR( m_pos.y, aCenter );
124}
125
126
128{
129 MIRROR( m_pos.x, aCenter );
130}
131
132
133void SCH_NO_CONNECT::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
134{
135 RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_270 : ANGLE_90 );
136}
137
138
140 const SCH_SHEET_PATH* aInstance ) const
141{
142 // Do not compare to ourself.
143 if( aItem == this )
144 return false;
145
146 const SCH_NO_CONNECT* noConnect = dynamic_cast<const SCH_NO_CONNECT*>( aItem );
147
148 // Don't compare against a different SCH_ITEM.
149 wxCHECK( noConnect, false );
150
151 return GetPosition() != noConnect->GetPosition();
152}
153
154
155std::vector<VECTOR2I> SCH_NO_CONNECT::GetConnectionPoints() const
156{
157 return { m_pos };
158}
159
160
161bool SCH_NO_CONNECT::doIsConnected( const VECTOR2I& aPosition ) const
162{
163 return m_pos == aPosition;
164}
165
166
167bool SCH_NO_CONNECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
168{
169 int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
170
171 VECTOR2I dist = aPosition - m_pos;
172
173 if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
174 return true;
175
176 return false;
177}
178
179
180bool SCH_NO_CONNECT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
181{
182 BOX2I rect = aRect;
183
184 rect.Inflate( aAccuracy );
185
186 if( aContained )
187 return rect.Contains( GetBoundingBox() );
188
189 return rect.Intersects( GetBoundingBox() );
190}
191
192
193void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
194 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
195{
196 if( aBackground )
197 return;
198
199 int delta = GetSize() / 2;
200 int pX = m_pos.x;
201 int pY = m_pos.y;
202 int penWidth = GetEffectivePenWidth( getRenderSettings( aPlotter ) );
203
204 aPlotter->SetCurrentLineWidth( penWidth );
205 aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );
206 aPlotter->MoveTo( VECTOR2I( pX - delta, pY - delta ) );
207 aPlotter->FinishTo( VECTOR2I( pX + delta, pY + delta ) );
208 aPlotter->MoveTo( VECTOR2I( pX + delta, pY - delta ) );
209 aPlotter->FinishTo( VECTOR2I( pX - delta, pY + delta ) );
210}
211
212
214{
215 return BITMAPS::noconn;
216}
217
218
219bool SCH_NO_CONNECT::operator==( const SCH_ITEM& aOther ) const
220{
221 if( aOther.Type() != Type() )
222 return false;
223
224 const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
225
226 if( m_pos != other->m_pos )
227 return false;
228
229 return true;
230}
231
232
233double SCH_NO_CONNECT::Similarity( const SCH_ITEM& aOther ) const
234{
235 if( m_Uuid == aOther.m_Uuid )
236 return 1.0;
237
238 if( aOther.Type() != Type() )
239 return 0.0;
240
241 const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
242
243 if( m_pos != other->m_pos )
244 return 0.0;
245
246 return 1.0;
247}
int color
Definition: DXF_plotter.cpp:58
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:294
bool Contains(const Vec &aPoint) const
Definition: box2.h:158
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:95
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
const KIID m_Uuid
Definition: eda_item.h:485
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxDC * GetPrintDC() const
Base plotter engine class.
Definition: plotter.h:104
void MoveTo(const VECTOR2I &pos)
Definition: plotter.h:243
void FinishTo(const VECTOR2I &pos)
Definition: plotter.h:253
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:135
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void SetColor(const COLOR4D &color)=0
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:678
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:139
void SetLayer(SCH_LAYER_ID aLayer)
Definition: sch_item.h:290
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition: sch_item.cpp:343
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition: sch_item.cpp:464
bool operator==(const SCH_ITEM &aOther) const override
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
SCH_NO_CONNECT(const VECTOR2I &pos=VECTOR2I(0, 0))
int m_size
Size of the no connect object.
int GetSize() const
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
VECTOR2I m_pos
Position of the no connect object.
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
VECTOR2I GetPosition() const override
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
int GetPenWidth() const override
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
#define DEFAULT_NOCONNECT_SIZE
The default junction diameter in mils. (can be changed in preference menu)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:437
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:440
void GRLine(wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:171
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:395
@ LAYER_NOCONNECT
Definition: layer_ids.h:380
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:424
@ NO_CONNECT_END
Definition: sch_item.h:86
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
constexpr int delta
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:228
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:160
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588