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 <macros.h>
35 
36 #include <sch_painter.h>
37 #include <sch_junction.h>
38 #include <sch_connection.h>
39 #include <schematic.h>
41 
42 
43 SCH_JUNCTION::SCH_JUNCTION( const wxPoint& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) :
45 {
46  m_pos = aPosition;
47  m_color = COLOR4D::UNSPECIFIED;
48  m_diameter = aDiameter;
49  m_Layer = aLayer;
50 }
51 
52 
54 {
55  return new SCH_JUNCTION( *this );
56 }
57 
58 
60 {
61  wxCHECK_RET( (aItem != NULL) && (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 
71 void 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  EDA_RECT rect;
82 
83  int size = Schematic() ? Schematic()->Settings().m_JunctionSize
84  : Mils2iu( DEFAULT_JUNCTION_DIAM );
85 
86  if( m_diameter != 0 )
87  size = m_diameter;
88 
89  rect.SetOrigin( m_pos );
90  rect.Inflate( ( GetPenWidth() + size ) / 2 );
91 
92  return rect;
93 }
94 
95 
96 void SCH_JUNCTION::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
97 {
98  wxDC* DC = aSettings->GetPrintDC();
100 
101  if( color == COLOR4D::UNSPECIFIED )
102  color = aSettings->GetLayerColor( GetLayer() );
103 
104  int diameter = Schematic() ? Schematic()->Settings().m_JunctionSize
105  : Mils2iu( DEFAULT_JUNCTION_DIAM );
106 
107  if( m_diameter != 0 )
108  diameter = m_diameter;
109 
110  GRFilledCircle( nullptr, DC, m_pos.x + aOffset.x, m_pos.y + aOffset.y, diameter / 2, 0,
111  color, color );
112 }
113 
114 
115 void SCH_JUNCTION::MirrorX( int aXaxis_position )
116 {
117  MIRROR( m_pos.y, aXaxis_position );
118 }
119 
120 
121 void SCH_JUNCTION::MirrorY( int aYaxis_position )
122 {
123  MIRROR( m_pos.x, aYaxis_position );
124 }
125 
126 
127 void SCH_JUNCTION::Rotate( wxPoint aPosition )
128 {
129  RotatePoint( &m_pos, aPosition, 900 );
130 }
131 
132 
133 void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
134 {
135  DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
136  aItemList.push_back( item );
137 }
138 
139 
140 std::vector<wxPoint> SCH_JUNCTION::GetConnectionPoints() const
141 {
142  return { m_pos };
143 }
144 
145 
146 #if defined(DEBUG)
147 void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
148 {
149  // XML output:
150  wxString s = GetClass();
151 
152  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter
153  << "/>\n";
154 }
155 #endif
156 
157 
159 {
160  if( m_color != COLOR4D::UNSPECIFIED )
161  return m_color;
162 
163  NETCLASSPTR netclass = NetClass();
164 
165  if( netclass )
166  return netclass->GetSchematicColor();
167 
168  return COLOR4D::UNSPECIFIED;
169 }
170 
171 
173 {
174  int diameter = m_diameter;
175 
176  if( diameter == 0 )
177  {
178  // Careful; preview items don't have schematics...
179  if( Schematic() )
180  diameter = Schematic()->Settings().m_JunctionSize;
181  else
182  diameter = DEFAULT_JUNCTION_DIAM * IU_PER_MILS;
183  }
184 
185  NETCLASSPTR netclass = NetClass();
186 
187  if( netclass )
188  diameter = std::max( diameter, KiROUND( netclass->GetWireWidth() * 1.7 ) );
189 
190  return std::max( diameter, 1 );
191 }
192 
193 
194 bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
195 {
196  EDA_RECT rect = GetBoundingBox();
197 
198  rect.Inflate( aAccuracy );
199 
200  return rect.Contains( aPosition );
201 }
202 
203 
204 bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
205 {
207  return false;
208 
209  EDA_RECT rect = aRect;
210 
211  rect.Inflate( aAccuracy );
212 
213  if( aContained )
214  return rect.Contains( GetBoundingBox() );
215 
216  return rect.Intersects( GetBoundingBox() );
217 }
218 
219 
220 bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
221 {
222  return m_pos == aPosition;
223 }
224 
225 
226 void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
227 {
228  auto* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
229  COLOR4D color = GetColor();
230 
231  if( color == COLOR4D::UNSPECIFIED )
232  color = settings->GetLayerColor( GetLayer() );
233 
234  aPlotter->SetColor( color );
235 
236  int diameter = Schematic() ? Schematic()->Settings().m_JunctionSize
237  : Mils2iu( DEFAULT_JUNCTION_DIAM );
238 
239  if( m_diameter != 0 )
240  diameter = m_diameter;
241 
242  aPlotter->Circle( m_pos, diameter, FILL_TYPE::FILLED_SHAPE );
243 }
244 
245 
247 {
248  return add_junction_xpm;
249 }
250 
251 
252 bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
253 {
254  if( Type() != aItem.Type() )
255  return Type() < aItem.Type();
256 
257  if( GetLayer() != aItem.GetLayer() )
258  return GetLayer() < aItem.GetLayer();
259 
260  auto junction = static_cast<const SCH_JUNCTION*>( &aItem );
261 
262  if( GetPosition().x != junction->GetPosition().x )
263  return GetPosition().x < junction->GetPosition().x;
264 
265  if( GetPosition().y != junction->GetPosition().y )
266  return GetPosition().y < junction->GetPosition().y;
267 
268  if( GetDiameter() != junction->GetDiameter() )
269  return GetDiameter() < junction->GetDiameter();
270 
271  return GetColor() < junction->GetColor();
272 }
273 
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_junction.h:53
SCH_LAYER_ID m_Layer
Definition: sch_item.h:199
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
COLOR4D m_color
Definition: sch_junction.h:38
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
PNG memory record (file in memory).
Definition: bitmap_def.h:29
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
virtual void SetColor(COLOR4D color)=0
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:124
int color
Definition: DXF_plotter.cpp:60
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
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.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
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
Function Contains.
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.
This file contains miscellaneous commonly used macros and functions.
SCH_JUNCTION(const wxPoint &aPosition=wxPoint(0, 0), int aDiameter=0, SCH_LAYER_ID aLayer=LAYER_JUNCTION)
COLOR4D GetColor() const
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:136
NETCLASSPTR NetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:161
#define NULL
wxPoint GetPosition() const override
Definition: sch_junction.h:95
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
SCH_LAYER_ID
Eeschema drawing layers.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: eda_item.h:115
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH)=0
const BITMAP_OPAQUE add_junction_xpm[1]
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
wxPoint m_pos
Definition: sch_junction.h:36
virtual int GetPenWidth() const
Definition: sch_item.h:296
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:279
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
Base plotter engine class.
Definition: plotter.h:131
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:165
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
STATUS_FLAGS m_Flags
Definition: eda_item.h:165
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
#define IU_PER_MILS
Definition: plotter.cpp:137
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
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:148
The common library.
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
Definition: eda_rect.cpp:150
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:85
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns 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:117
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100