KiCad PCB EDA Suite
sch_junction.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) 2009 Jean-Pierre Charras, jp.charras at wanadoo.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
25#include <sch_draw_panel.h>
26#include <trigo.h>
27#include <common.h>
28#include <plotters/plotter.h>
29#include <bitmaps.h>
30#include <core/mirror.h>
31#include <geometry/shape_rect.h>
32#include <sch_painter.h>
33#include <sch_junction.h>
34#include <sch_connection.h>
35#include <schematic.h>
37#include <connection_graph.h>
38
39
40SCH_JUNCTION::SCH_JUNCTION( const VECTOR2I& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) :
41 SCH_ITEM( nullptr, SCH_JUNCTION_T )
42{
43 m_pos = aPosition;
44 m_color = COLOR4D::UNSPECIFIED;
45 m_diameter = aDiameter;
46 m_layer = aLayer;
47
49 m_lastResolvedColor = COLOR4D::UNSPECIFIED;
50}
51
52
54{
55 return new SCH_JUNCTION( *this );
56}
57
58
60{
61 wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_JUNCTION_T ),
62 wxT( "Cannot swap junction data with invalid item." ) );
63
64 SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
65 std::swap( m_pos, item->m_pos );
66 std::swap( m_diameter, item->m_diameter );
67 std::swap( m_color, item->m_color );
68}
69
70
71void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
72{
73 aCount = 2;
74 aLayers[0] = m_layer;
75 aLayers[1] = LAYER_SELECTION_SHADOWS;
76}
77
78
80{
81 if( m_diameter != 0 )
83 else if( Schematic() )
85 else
87
88 if( m_lastResolvedDiameter != 1 ) // Diameter 1 means user doesn't want to draw junctions
89 {
90 // If we know what we're connected to, then enforce a minimum size of 170% of the
91 // connected wire width:
92 if( !IsConnectivityDirty() )
93 {
95 GetEffectiveNetClass()->GetWireWidth() * 1.7 );
96 }
97 }
98
99 return SHAPE_CIRCLE( m_pos, std::max( m_lastResolvedDiameter / 2, 1 ) );
100}
101
102
104{
105 BOX2I bbox( m_pos );
106 bbox.Inflate( getEffectiveShape().GetRadius() );
107
108 return bbox;
109}
110
111
112void SCH_JUNCTION::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
113{
114 wxDC* DC = aSettings->GetPrintDC();
116
117 if( color == COLOR4D::UNSPECIFIED )
118 color = aSettings->GetLayerColor( GetLayer() );
119
121
122 GRFilledCircle( DC, circle.GetCenter() + aOffset, circle.GetRadius(), 0, color, color );
123}
124
125
127{
128 MIRROR( m_pos.y, aCenter );
129}
130
131
133{
134 MIRROR( m_pos.x, aCenter );
135}
136
137
138void SCH_JUNCTION::Rotate( const VECTOR2I& aCenter )
139{
140 RotatePoint( m_pos, aCenter, ANGLE_90 );
141}
142
143
144void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
145{
146 DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
147 aItemList.push_back( item );
148}
149
150
151std::vector<VECTOR2I> SCH_JUNCTION::GetConnectionPoints() const
152{
153 return { m_pos };
154}
155
156
157#if defined(DEBUG)
158void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
159{
160 // XML output:
161 wxString s = GetClass();
162
163 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter
164 << "/>\n";
165}
166#endif
167
168
169void SCH_JUNCTION::SetDiameter( int aDiameter )
170{
171 m_diameter = aDiameter;
172 m_lastResolvedDiameter = aDiameter;
173}
174
175
177{
178 if( m_color != COLOR4D::UNSPECIFIED )
180 else if( !IsConnectivityDirty() )
181 m_lastResolvedColor = GetEffectiveNetClass()->GetSchematicColor();
182
183 return m_lastResolvedColor;
184}
185
186
187void SCH_JUNCTION::SetColor( const COLOR4D& aColor )
188{
189 m_color = aColor;
190 m_lastResolvedColor = aColor;
191}
192
193
195{
196 return getEffectiveShape().GetRadius() * 2;
197}
198
199
200bool SCH_JUNCTION::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
201{
202 if( aAccuracy >= 0 )
203 return getEffectiveShape().Collide( SEG( aPosition, aPosition ), aAccuracy );
204 else
205 return aPosition == m_pos;
206}
207
208
209bool SCH_JUNCTION::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
210{
212 return false;
213
214 if( aContained )
215 {
216 BOX2I selRect( aRect );
217
218 return selRect.Inflate( aAccuracy ).Contains( GetBoundingBox() );
219 }
220 else
221 {
222 SHAPE_CIRCLE junction = getEffectiveShape();
223 SHAPE_RECT selRect( aRect.GetPosition(), aRect.GetWidth(), aRect.GetHeight() );
224
225 return selRect.Collide( &junction, aAccuracy );
226 }
227}
228
229
230bool SCH_JUNCTION::doIsConnected( const VECTOR2I& aPosition ) const
231{
232 return m_pos == aPosition;
233}
234
235
236void SCH_JUNCTION::Plot( PLOTTER* aPlotter, bool aBackground ) const
237{
238 if( aBackground )
239 return;
240
241 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
243
244 if( color == COLOR4D::UNSPECIFIED )
245 color = settings->GetLayerColor( GetLayer() );
246
247 aPlotter->SetColor( color );
248
250}
251
252
254{
256}
257
258
259bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
260{
261 if( Type() != aItem.Type() )
262 return Type() < aItem.Type();
263
264 if( GetLayer() != aItem.GetLayer() )
265 return GetLayer() < aItem.GetLayer();
266
267 const SCH_JUNCTION* junction = static_cast<const SCH_JUNCTION*>( &aItem );
268
269 if( GetPosition().x != junction->GetPosition().x )
270 return GetPosition().x < junction->GetPosition().x;
271
272 if( GetPosition().y != junction->GetPosition().y )
273 return GetPosition().y < junction->GetPosition().y;
274
275 if( GetDiameter() != junction->GetDiameter() )
276 return GetDiameter() < junction->GetDiameter();
277
278 return GetColor() < junction->GetColor();
279}
280
int color
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
@ add_junction
const Vec & GetPosition() const
Definition: box2.h:184
coord_type GetHeight() const
Definition: box2.h:188
coord_type GetWidth() const
Definition: box2.h:187
bool Contains(const Vec &aPoint) const
Definition: box2.h:141
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:82
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:498
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxDC * GetPrintDC() const
Base plotter engine class.
Definition: plotter.h:110
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:141
virtual void SetColor(const COLOR4D &color)=0
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:172
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:112
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:166
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:246
bool IsConnectivityDirty() const
Definition: sch_item.h:404
SCH_LAYER_ID m_layer
Definition: sch_item.h:482
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
VECTOR2I m_pos
Definition: sch_junction.h:136
virtual bool operator<(const SCH_ITEM &aItem) const override
int GetEffectiveDiameter() const
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
SHAPE_CIRCLE getEffectiveShape() const
SCH_JUNCTION(const VECTOR2I &aPosition=VECTOR2I(0, 0), int aDiameter=0, SCH_LAYER_ID aLayer=LAYER_JUNCTION)
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
COLOR4D m_lastResolvedColor
Definition: sch_junction.h:144
int m_diameter
Zero is user default.
Definition: sch_junction.h:137
void SetDiameter(int aDiameter)
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
COLOR4D m_color
#COLOR4D::UNSPECIFIED is user default.
Definition: sch_junction.h:138
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
COLOR4D GetColor() const
Definition: sch_junction.h:114
int GetDiameter() const
Definition: sch_junction.h:109
COLOR4D GetJunctionColor() const
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
VECTOR2I GetPosition() const override
Definition: sch_junction.h:102
void SetColor(const COLOR4D &aColor)
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
int m_lastResolvedDiameter
Definition: sch_junction.h:143
wxString GetClass() const override
Return the class name.
Definition: sch_junction.h:50
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: seg.h:42
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
Definition: shape_circle.h:77
int GetRadius() const
Definition: shape_circle.h:108
const VECTOR2I GetCenter() const
Definition: shape_circle.h:113
bool Collide(const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
Definition: shape_rect.h:109
The common library.
#define DEFAULT_JUNCTION_DIAM
The default bus and wire entry size in mils.
#define DEFAULT_WIRE_WIDTH_MILS
The default bus width in mils. (can be changed in preference menu)
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:414
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
@ FILLED_SHAPE
void GRFilledCircle(wxDC *aDC, const VECTOR2I &aPos, int aRadius, int aWidth, const COLOR4D &aStrokeColor, const COLOR4D &aFillColor)
Draw a circle onto the drawing context aDC centered at the user coordinates (x,y).
Definition: gr_basic.cpp:360
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:381
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
@ JUNCTION_END
Definition: sch_item.h:67
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183
@ SCH_JUNCTION_T
Definition: typeinfo.h:141
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:80