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 The 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
29
30#include <sch_draw_panel.h>
31#include <plotters/plotter.h>
32#include <bitmaps.h>
33#include <schematic.h>
35#include <sch_no_connect.h>
37#include <default_values.h> // For some default values
38#include <core/mirror.h>
39#include <trigo.h>
40#include <gr_basic.h>
41
42
44 SCH_ITEM( nullptr, SCH_NO_CONNECT_T )
45{
46 m_pos = pos;
47 m_size = schIUScale.MilsToIU( DEFAULT_NOCONNECT_SIZE ); // Default no-connect symbol size.
48
50}
51
52
54{
55 return new SCH_NO_CONNECT( *this );
56}
57
58
60{
61 wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ),
62 wxT( "Cannot swap no connect data with invalid item." ) );
63
64 SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
65 std::swap( m_pos, item->m_pos );
66 std::swap( m_size, item->m_size );
67}
68
69
71{
72 int delta = ( GetPenWidth() + GetSize() ) / 2;
73 BOX2I bbox( m_pos );
74
75 bbox.Inflate( delta );
76
77 return bbox;
78}
79
80
81std::vector<int> SCH_NO_CONNECT::ViewGetLayers() const
82{
84}
85
86
87void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
88{
90 aItemList.push_back( item );
91}
92
93
95{
96 if( !Schematic() )
97 return 1;
98
99 return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
100}
101
102
104{
105 MIRROR( m_pos.y, aCenter );
106}
107
108
110{
111 MIRROR( m_pos.x, aCenter );
112}
113
114
115void SCH_NO_CONNECT::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
116{
117 RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
118}
119
120
122 const SCH_SHEET_PATH* aInstance ) const
123{
124 // Do not compare to ourself.
125 if( aItem == this )
126 return false;
127
128 const SCH_NO_CONNECT* noConnect = dynamic_cast<const SCH_NO_CONNECT*>( aItem );
129
130 // Don't compare against a different SCH_ITEM.
131 wxCHECK( noConnect, false );
132
133 return GetPosition() != noConnect->GetPosition();
134}
135
136
137std::vector<VECTOR2I> SCH_NO_CONNECT::GetConnectionPoints() const
138{
139 return { m_pos };
140}
141
142
143bool SCH_NO_CONNECT::doIsConnected( const VECTOR2I& aPosition ) const
144{
145 return m_pos == aPosition;
146}
147
148
149bool SCH_NO_CONNECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
150{
151 int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
152
153 VECTOR2I dist = aPosition - m_pos;
154
155 if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
156 return true;
157
158 return false;
159}
160
161
162bool SCH_NO_CONNECT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
163{
164 BOX2I rect = aRect;
165
166 rect.Inflate( aAccuracy );
167
168 if( aContained )
169 return rect.Contains( GetBoundingBox() );
170
171 return rect.Intersects( GetBoundingBox() );
172}
173
174
175bool SCH_NO_CONNECT::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
176{
177 return KIGEOM::BoxHitTest( aPoly, GetBoundingBox(), aContained );
178}
179
180
181void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
182 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
183{
184 if( aBackground )
185 return;
186
187 int delta = GetSize() / 2;
188 int pX = m_pos.x;
189 int pY = m_pos.y;
190 int penWidth = GetEffectivePenWidth( getRenderSettings( aPlotter ) );
191
192 aPlotter->SetCurrentLineWidth( penWidth );
193 aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );
194 aPlotter->MoveTo( VECTOR2I( pX - delta, pY - delta ) );
195 aPlotter->FinishTo( VECTOR2I( pX + delta, pY + delta ) );
196 aPlotter->MoveTo( VECTOR2I( pX + delta, pY - delta ) );
197 aPlotter->FinishTo( VECTOR2I( pX - delta, pY + delta ) );
198}
199
200
205
206
207bool SCH_NO_CONNECT::operator==( const SCH_ITEM& aOther ) const
208{
209 if( aOther.Type() != Type() )
210 return false;
211
212 const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
213
214 if( m_pos != other->m_pos )
215 return false;
216
217 return true;
218}
219
220
221double SCH_NO_CONNECT::Similarity( const SCH_ITEM& aOther ) const
222{
223 if( m_Uuid == aOther.m_Uuid )
224 return 1.0;
225
226 if( aOther.Type() != Type() )
227 return 0.0;
228
229 const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
230
231 if( m_pos != other->m_pos )
232 return 0.0;
233
234 return 1.0;
235}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:558
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:168
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:311
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition sch_item.h:96
const KIID m_Uuid
Definition eda_item.h:516
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
Base plotter engine class.
Definition plotter.h:121
void MoveTo(const VECTOR2I &pos)
Definition plotter.h:262
void FinishTo(const VECTOR2I &pos)
Definition plotter.h:272
RENDER_SETTINGS * RenderSettings()
Definition plotter.h:152
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void SetColor(const COLOR4D &color)=0
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.h:688
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:217
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:310
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:51
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:602
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.
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
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 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...
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
#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:413
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:416
a few functions useful in geometry calculations.
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:493
@ LAYER_NOCONNECT
Definition layer_ids.h:475
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:45
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
@ NO_CONNECT_END
Definition sch_item.h:87
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:229
@ SCH_NO_CONNECT_T
Definition typeinfo.h:162
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695