KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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_edit_frame.h>
35#include <sch_connection.h>
36#include <schematic.h>
38#include <connection_graph.h>
39#include <string_utils.h>
40
41
42SCH_JUNCTION::SCH_JUNCTION( const VECTOR2I& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) :
43 SCH_ITEM( nullptr, SCH_JUNCTION_T )
44{
45 m_pos = aPosition;
46 m_color = COLOR4D::UNSPECIFIED;
47 m_diameter = aDiameter;
48 m_layer = aLayer;
49
51 m_lastResolvedColor = COLOR4D::UNSPECIFIED;
52}
53
54
56{
57 return new SCH_JUNCTION( *this );
58}
59
60
62{
63 wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_JUNCTION_T ),
64 wxT( "Cannot swap junction data with invalid item." ) );
65
66 SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
67 std::swap( m_pos, item->m_pos );
68 std::swap( m_diameter, item->m_diameter );
69 std::swap( m_color, item->m_color );
70}
71
72
73void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
74{
75 aCount = 2;
76 aLayers[0] = m_layer;
77 aLayers[1] = LAYER_SELECTION_SHADOWS;
78}
79
80
82{
83 if( m_diameter != 0 )
85 else if( Schematic() )
87 else
89
90 if( m_lastResolvedDiameter != 1 ) // Diameter 1 means user doesn't want to draw junctions
91 {
92 // If we know what we're connected to, then enforce a minimum size of 170% of the
93 // connected wire width:
94 if( !IsConnectivityDirty() )
95 {
97 GetEffectiveNetClass()->GetWireWidth() * 1.7 );
98 }
99 }
100
101 return SHAPE_CIRCLE( m_pos, std::max( m_lastResolvedDiameter / 2, 1 ) );
102}
103
104
106{
107 BOX2I bbox( m_pos );
108 bbox.Inflate( getEffectiveShape().GetRadius() );
109
110 return bbox;
111}
112
113
114void SCH_JUNCTION::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
115{
116 wxDC* DC = aSettings->GetPrintDC();
118
119 if( color == COLOR4D::UNSPECIFIED )
120 color = aSettings->GetLayerColor( GetLayer() );
121
123
124 GRFilledCircle( DC, circle.GetCenter() + aOffset, circle.GetRadius(), 0, color, color );
125}
126
127
129{
130 MIRROR( m_pos.y, aCenter );
131}
132
133
135{
136 MIRROR( m_pos.x, aCenter );
137}
138
139
140void SCH_JUNCTION::Rotate( const VECTOR2I& aCenter )
141{
142 RotatePoint( m_pos, aCenter, ANGLE_90 );
143}
144
145
146void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
147{
148 DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
149 aItemList.push_back( item );
150}
151
152
153std::vector<VECTOR2I> SCH_JUNCTION::GetConnectionPoints() const
154{
155 return { m_pos };
156}
157
158
159#if defined(DEBUG)
160void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
161{
162 // XML output:
163 wxString s = GetClass();
164
165 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << wxS( ", " ) << m_diameter
166 << wxS( "/>\n" );
167}
168#endif
169
170
171void SCH_JUNCTION::SetDiameter( int aDiameter )
172{
173 m_diameter = aDiameter;
174 m_lastResolvedDiameter = aDiameter;
175}
176
177
179{
180 if( m_color != COLOR4D::UNSPECIFIED )
182 else if( !IsConnectivityDirty() )
183 m_lastResolvedColor = GetEffectiveNetClass()->GetSchematicColor();
184
185 return m_lastResolvedColor;
186}
187
188
189void SCH_JUNCTION::SetColor( const COLOR4D& aColor )
190{
191 m_color = aColor;
192 m_lastResolvedColor = aColor;
193}
194
195
197{
198 return getEffectiveShape().GetRadius() * 2;
199}
200
201
202bool SCH_JUNCTION::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
203{
204 if( aAccuracy >= 0 )
205 return getEffectiveShape().Collide( SEG( aPosition, aPosition ), aAccuracy );
206 else
207 return aPosition == m_pos;
208}
209
210
211bool SCH_JUNCTION::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
212{
214 return false;
215
216 if( aContained )
217 {
218 BOX2I selRect( aRect );
219
220 return selRect.Inflate( aAccuracy ).Contains( GetBoundingBox() );
221 }
222 else
223 {
224 SHAPE_CIRCLE junction = getEffectiveShape();
225 SHAPE_RECT selRect( aRect.GetPosition(), aRect.GetWidth(), aRect.GetHeight() );
226
227 return selRect.Collide( &junction, aAccuracy );
228 }
229}
230
231
232bool SCH_JUNCTION::doIsConnected( const VECTOR2I& aPosition ) const
233{
234 return m_pos == aPosition;
235}
236
237
238void SCH_JUNCTION::Plot( PLOTTER* aPlotter, bool aBackground ) const
239{
240 if( aBackground )
241 return;
242
243 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
245
246 if( color == COLOR4D::UNSPECIFIED )
247 color = settings->GetLayerColor( GetLayer() );
248
249 aPlotter->SetColor( color );
250
251 aPlotter->Circle( m_pos, GetEffectiveDiameter(), FILL_T::FILLED_SHAPE );
252}
253
254
256{
257 return BITMAPS::add_junction;
258}
259
260
261bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
262{
263 if( Type() != aItem.Type() )
264 return Type() < aItem.Type();
265
266 if( GetLayer() != aItem.GetLayer() )
267 return GetLayer() < aItem.GetLayer();
268
269 const SCH_JUNCTION* junction = static_cast<const SCH_JUNCTION*>( &aItem );
270
271 if( GetPosition().x != junction->GetPosition().x )
272 return GetPosition().x < junction->GetPosition().x;
273
274 if( GetPosition().y != junction->GetPosition().y )
275 return GetPosition().y < junction->GetPosition().y;
276
277 if( GetDiameter() != junction->GetDiameter() )
278 return GetDiameter() < junction->GetDiameter();
279
280 return GetColor() < junction->GetColor();
281}
282
283
284void SCH_JUNCTION::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
285{
286 aList.emplace_back( _( "Junction" ), wxEmptyString );
287
288 aList.emplace_back( _( "Size" ), aFrame->MessageTextFromValue( GetEffectiveDiameter() ) );
289
290 SCH_CONNECTION* conn = nullptr;
291
292 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
293 conn = Connection();
294
295 if( conn )
296 {
297 conn->AppendInfoToMsgPanel( aList );
298
299 if( !conn->IsBus() )
300 {
301 aList.emplace_back( _( "Resolved Netclass" ),
302 UnescapeString( GetEffectiveNetClass()->GetName() ) );
303 }
304 }
305}
306
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
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
The base class for create windows for drawing purpose.
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:480
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
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:205
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool IsBus() const
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
Schematic editor (Eeschema) main window.
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:113
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:174
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:249
bool IsConnectivityDirty() const
Definition: sch_item.h:416
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:147
SCH_LAYER_ID m_layer
Definition: sch_item.h:497
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
VECTOR2I m_pos
Definition: sch_junction.h:138
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:146
int m_diameter
Zero is user default.
Definition: sch_junction.h:139
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:140
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
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
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:145
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
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A lower-precision version of StringFromValue().
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)
#define _(s)
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:431
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
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:369
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:345
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:385
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
wxString UnescapeString(const wxString &aSource)
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:132
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:85