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-2020 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 #include <sch_draw_panel.h>
30 #include <trigo.h>
31 #include <common.h>
32 #include <plotter.h>
33 #include <bitmaps.h>
34 #include <core/mirror.h>
35 #include <geometry/shape_rect.h>
36 #include <sch_painter.h>
37 #include <sch_junction.h>
38 #include <sch_connection.h>
39 #include <schematic.h>
41 
42 SCH_JUNCTION::SCH_JUNCTION( const wxPoint& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) :
44 {
45  m_pos = aPosition;
46  m_color = COLOR4D::UNSPECIFIED;
47  m_diameter = aDiameter;
48  m_layer = aLayer;
49 }
50 
51 
53 {
54  return new SCH_JUNCTION( *this );
55 }
56 
57 
59 {
60  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T),
61  wxT( "Cannot swap junction data with invalid item." ) );
62 
63  SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
64  std::swap( m_pos, item->m_pos );
65  std::swap( m_diameter, item->m_diameter );
66  std::swap( m_color, item->m_color );
67 }
68 
69 
70 void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
71 {
72  aCount = 2;
73  aLayers[0] = m_layer;
74  aLayers[1] = LAYER_SELECTION_SHADOWS;
75 }
76 
77 
79 {
80  int diameter;
81 
82  if( m_diameter != 0 )
83  diameter = m_diameter;
84  else if( Schematic() )
85  diameter = Schematic()->Settings().m_JunctionSize;
86  else
87  diameter = Mils2iu( DEFAULT_JUNCTION_DIAM );
88 
89  if( diameter != 1 ) // Diameter 1 means users doesn't want to draw junction dots
90  {
91  NETCLASSPTR netclass = NetClass();
92 
93  if( netclass )
94  diameter = std::max( diameter, KiROUND( netclass->GetWireWidth() * 1.7 ) );
95  }
96 
97  return SHAPE_CIRCLE( m_pos, std::max( diameter / 2, 1 ) );
98 }
99 
100 
102 {
103  EDA_RECT rect;
104 
105  rect.SetOrigin( m_pos );
106  rect.Inflate( getEffectiveShape().GetRadius() );
107 
108  return rect;
109 }
110 
111 
112 void SCH_JUNCTION::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
113 {
114  wxDC* DC = aSettings->GetPrintDC();
116 
117  if( color == COLOR4D::UNSPECIFIED )
118  color = aSettings->GetLayerColor( GetLayer() );
119 
120  SHAPE_CIRCLE circle = getEffectiveShape();
121 
122  GRFilledCircle( NULL, DC, (wxPoint) circle.GetCenter() + aOffset, circle.GetRadius(), color );
123 }
124 
125 
127 {
128  MIRROR( m_pos.y, aCenter );
129 }
130 
131 
133 {
134  MIRROR( m_pos.x, aCenter );
135 }
136 
137 
138 void SCH_JUNCTION::Rotate( wxPoint aCenter )
139 {
140  RotatePoint( &m_pos, aCenter, 900 );
141 }
142 
143 
144 void 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 
151 std::vector<wxPoint> SCH_JUNCTION::GetConnectionPoints() const
152 {
153  return { m_pos };
154 }
155 
156 
157 #if defined(DEBUG)
158 void 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 
170 {
171  if( m_color != COLOR4D::UNSPECIFIED )
172  return m_color;
173 
174  NETCLASSPTR netclass = NetClass();
175 
176  if( netclass )
177  return netclass->GetSchematicColor();
178 
179  return COLOR4D::UNSPECIFIED;
180 }
181 
182 
184 {
185  return getEffectiveShape().GetRadius() * 2;
186 }
187 
188 
189 bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
190 {
191  if( aAccuracy >= 0 )
192  return getEffectiveShape().Collide( SEG( aPosition, aPosition ), aAccuracy );
193  else
194  return aPosition == m_pos;
195 }
196 
197 
198 bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
199 {
201  return false;
202 
203  if( aContained )
204  {
205  EDA_RECT selRect = aRect;
206 
207  selRect.Inflate( aAccuracy );
208 
209  return selRect.Contains( GetBoundingBox() );
210  }
211  else
212  {
213  SHAPE_CIRCLE junction = getEffectiveShape();
214  SHAPE_RECT selRect( aRect.GetPosition(), aRect.GetWidth(), aRect.GetHeight() );
215 
216  return selRect.Collide( &junction, aAccuracy );
217  }
218 }
219 
220 
221 bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
222 {
223  return m_pos == aPosition;
224 }
225 
226 
227 void SCH_JUNCTION::Plot( PLOTTER* aPlotter ) const
228 {
229  auto* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
231 
232  if( color == COLOR4D::UNSPECIFIED )
233  color = settings->GetLayerColor( GetLayer() );
234 
235  aPlotter->SetColor( color );
236 
238 }
239 
240 
242 {
243  return BITMAPS::add_junction;
244 }
245 
246 
247 bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
248 {
249  if( Type() != aItem.Type() )
250  return Type() < aItem.Type();
251 
252  if( GetLayer() != aItem.GetLayer() )
253  return GetLayer() < aItem.GetLayer();
254 
255  auto junction = static_cast<const SCH_JUNCTION*>( &aItem );
256 
257  if( GetPosition().x != junction->GetPosition().x )
258  return GetPosition().x < junction->GetPosition().x;
259 
260  if( GetPosition().y != junction->GetPosition().y )
261  return GetPosition().y < junction->GetPosition().y;
262 
263  if( GetDiameter() != junction->GetDiameter() )
264  return GetDiameter() < junction->GetDiameter();
265 
266  return GetColor() < junction->GetColor();
267 }
268 
wxString GetClass() const override
Return the class name.
Definition: sch_junction.h:50
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:98
COLOR4D GetJunctionColor() const
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
COLOR4D m_color
Color of the junction. #COLOR4D::UNSPECIFIED is user default.
Definition: sch_junction.h:125
int GetRadius() const
Definition: shape_circle.h:107
void Rotate(wxPoint aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
virtual void SetColor(COLOR4D color)=0
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:129
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
int color
Definition: DXF_plotter.cpp:60
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:97
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
int GetWidth() const
Definition: eda_rect.h:114
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:126
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
int GetDiameter() const
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
#define DEFAULT_JUNCTION_DIAM
The default bus and wire enty size in mils.
const VECTOR2I GetCenter() const
Definition: shape_circle.h:112
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
virtual bool operator<(const SCH_ITEM &aItem) const override
void GRFilledCircle(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:617
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
SCH_JUNCTION(const wxPoint &aPosition=wxPoint(0, 0), int aDiameter=0, SCH_LAYER_ID aLayer=LAYER_JUNCTION)
COLOR4D GetColor() const
Definition: sch_junction.h:102
NETCLASSPTR NetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:145
SCH_LAYER_ID m_layer
Definition: sch_item.h:496
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:76
#define NULL
wxPoint GetPosition() const override
Definition: sch_junction.h:92
const wxPoint GetPosition() const
Definition: eda_rect.h:107
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
wxDC * GetPrintDC() const
SCH_LAYER_ID
Eeschema drawing layers.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: eda_item.h:116
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH)=0
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 GetHeight() const
Definition: eda_rect.h:115
wxPoint m_pos
Position of the junction.
Definition: sch_junction.h:123
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
Definition: seg.h:41
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Base plotter engine class.
Definition: plotter.h:121
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:155
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
Handle the component boundary box.
Definition: eda_rect.h:42
SHAPE_CIRCLE getEffectiveShape() const
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:68
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
The common library.
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:87
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: eda_item.h:118
STATUS_FLAGS m_flags
Definition: eda_item.h:531
int m_diameter
Diameter of the junction. Zero is user default.
Definition: sch_junction.h:124
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98