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 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
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
73std::vector<int> SCH_JUNCTION::ViewGetLayers() const
74{
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
113{
114 MIRROR( m_pos.y, aCenter );
115}
116
117
119{
120 MIRROR( m_pos.x, aCenter );
121}
122
123
124void SCH_JUNCTION::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
125{
126 RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
127}
128
129
130void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
131{
132 DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
133 aItemList.push_back( item );
134}
135
136
137std::vector<VECTOR2I> SCH_JUNCTION::GetConnectionPoints() const
138{
139 return { m_pos };
140}
141
142
143#if defined(DEBUG)
144void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
145{
146 // XML output:
147 wxString s = GetClass();
148
149 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter
150 << "/>\n";
151}
152#endif
153
154
155void SCH_JUNCTION::SetDiameter( int aDiameter )
156{
157 m_diameter = aDiameter;
158 m_lastResolvedDiameter = aDiameter;
159}
160
161
163{
164 if( m_color != COLOR4D::UNSPECIFIED )
166 else if( !IsConnectivityDirty() )
167 m_lastResolvedColor = GetEffectiveNetClass()->GetSchematicColor();
168
169 return m_lastResolvedColor;
170}
171
172
173void SCH_JUNCTION::SetColor( const COLOR4D& aColor )
174{
175 m_color = aColor;
176 m_lastResolvedColor = aColor;
177}
178
179
181{
182 return getEffectiveShape().GetRadius() * 2;
183}
184
185
186bool SCH_JUNCTION::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
187{
188 if( aAccuracy >= 0 )
189 return getEffectiveShape().Collide( SEG( aPosition, aPosition ), aAccuracy );
190 else
191 return aPosition == m_pos;
192}
193
194
195bool SCH_JUNCTION::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
196{
198 return false;
199
200 if( aContained )
201 {
202 BOX2I selRect( aRect );
203
204 return selRect.Inflate( aAccuracy ).Contains( GetBoundingBox() );
205 }
206 else
207 {
208 SHAPE_CIRCLE junction = getEffectiveShape();
209 SHAPE_RECT selRect( aRect.GetPosition(), aRect.GetWidth(), aRect.GetHeight() );
210
211 return selRect.Collide( &junction, aAccuracy );
212 }
213}
214
215
217 const SCH_SHEET_PATH* aInstance ) const
218{
219 // Do not compare to ourself.
220 if( aItem == this )
221 return false;
222
223 const SCH_JUNCTION* junction = dynamic_cast<const SCH_JUNCTION*>( aItem );
224
225 // Don't compare against a different SCH_ITEM.
226 wxCHECK( junction, false );
227
228 return GetPosition() != junction->GetPosition();
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 SCH_PLOT_OPTS& aPlotOpts,
239 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
240{
241 if( aBackground )
242 return;
243
244 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
246
247 if( color == COLOR4D::UNSPECIFIED )
248 color = settings->GetLayerColor( GetLayer() );
249
250 aPlotter->SetColor( color );
251
252 aPlotter->Circle( m_pos, GetEffectiveDiameter(), FILL_T::FILLED_SHAPE, 0 );
253}
254
255
257{
258 return BITMAPS::add_junction;
259}
260
261
262bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
263{
264 if( Type() != aItem.Type() )
265 return Type() < aItem.Type();
266
267 if( GetLayer() != aItem.GetLayer() )
268 return GetLayer() < aItem.GetLayer();
269
270 const SCH_JUNCTION* junction = static_cast<const SCH_JUNCTION*>( &aItem );
271
272 if( GetPosition().x != junction->GetPosition().x )
273 return GetPosition().x < junction->GetPosition().x;
274
275 if( GetPosition().y != junction->GetPosition().y )
276 return GetPosition().y < junction->GetPosition().y;
277
278 if( GetDiameter() != junction->GetDiameter() )
279 return GetDiameter() < junction->GetDiameter();
280
281 return GetColor() < junction->GetColor();
282}
283
284
285void SCH_JUNCTION::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
286{
287 aList.emplace_back( _( "Junction" ), wxEmptyString );
288
289 aList.emplace_back( _( "Size" ), aFrame->MessageTextFromValue( GetEffectiveDiameter() ) );
290
291 SCH_CONNECTION* conn = nullptr;
292
293 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
294 conn = Connection();
295
296 if( conn )
297 {
298 conn->AppendInfoToMsgPanel( aList );
299
300 if( !conn->IsBus() )
301 {
302 aList.emplace_back( _( "Resolved Netclass" ),
303 UnescapeString( GetEffectiveNetClass()->GetHumanReadableName() ) );
304 }
305 }
306}
307
308
309bool SCH_JUNCTION::operator==( const SCH_ITEM& aOther ) const
310{
311 if( Type() != aOther.Type() )
312 return false;
313
314 const SCH_JUNCTION& other = static_cast<const SCH_JUNCTION&>( aOther );
315
316 if( m_pos != other.m_pos )
317 return false;
318
319 if( m_diameter != other.m_diameter )
320 return false;
321
322 if( m_color != other.m_color )
323 return false;
324
325 return true;
326}
327
328
329double SCH_JUNCTION::Similarity( const SCH_ITEM& aOther ) const
330{
331 if( m_Uuid == aOther.m_Uuid )
332 return 1.0;
333
334 if( aOther.Type() != Type() )
335 return 0.0;
336
337 const SCH_JUNCTION& other = static_cast<const SCH_JUNCTION&>( aOther );
338
339 double similarity = 1.0;
340
341 if( m_pos != other.m_pos )
342 similarity *= 0.9;
343
344 if( m_diameter != other.m_diameter )
345 similarity *= 0.9;
346
347 if( m_color != other.m_color )
348 similarity *= 0.9;
349
350 return similarity;
351}
352
353
354static struct SCH_JUNCTION_DESC
355{
357 {
361
362 propMgr.AddProperty( new PROPERTY<SCH_JUNCTION, int>( _HKI( "Diameter" ),
364 PROPERTY_DISPLAY::PT_SIZE ) );
365
366 propMgr.AddProperty( new PROPERTY<SCH_JUNCTION, COLOR4D>( _HKI( "Color" ),
368
369 }
int color
Definition: DXF_plotter.cpp:63
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:114
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
constexpr const Vec & GetPosition() const
Definition: box2.h:211
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 size_type GetWidth() const
Definition: box2.h:214
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr bool Contains(const Vec &aPoint) const
Definition: box2.h:168
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:97
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:97
const KIID m_Uuid
Definition: eda_item.h:502
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:109
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:513
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.
Base plotter engine class.
Definition: plotter.h:121
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width)=0
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:152
virtual void SetColor(const COLOR4D &color)=0
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:317
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:168
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:212
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:347
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:309
bool IsConnectivityDirty() const
Definition: sch_item.h:555
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:318
SCH_LAYER_ID m_layer
Definition: sch_item.h:738
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.
VECTOR2I m_pos
Definition: sch_junction.h:148
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
virtual bool operator<(const SCH_ITEM &aItem) const override
int GetEffectiveDiameter() const
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
SHAPE_CIRCLE getEffectiveShape() const
SCH_JUNCTION(const VECTOR2I &aPosition=VECTOR2I(0, 0), int aDiameter=0, SCH_LAYER_ID aLayer=LAYER_JUNCTION)
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
COLOR4D m_lastResolvedColor
Definition: sch_junction.h:156
int m_diameter
Zero is user default.
Definition: sch_junction.h:149
bool operator==(const SCH_ITEM &aOther) const override
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:150
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
COLOR4D GetColor() const
Definition: sch_junction.h:119
int GetDiameter() const
Definition: sch_junction.h:114
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.
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
VECTOR2I GetPosition() const override
Definition: sch_junction.h:107
void SetColor(const COLOR4D &aColor)
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
int m_lastResolvedDiameter
Definition: sch_junction.h:155
wxString GetClass() const override
Return the class name.
Definition: sch_junction.h:50
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
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.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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:118
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:142
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
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 _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:416
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:439
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:484
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:45
#define TYPE_HASH(x)
Definition: property.h:72
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
@ JUNCTION_END
Definition: sch_item.h:82
static struct SCH_JUNCTION_DESC _SCH_JUNCTION_DESC
wxString UnescapeString(const wxString &aSource)
constexpr int MilsToIU(int mils) const
Definition: base_units.h:97
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_JUNCTION_T
Definition: typeinfo.h:160