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 <fctsys.h>
30 #include <gr_basic.h>
31 #include <macros.h>
32 #include <sch_draw_panel.h>
33 #include <trigo.h>
34 #include <common.h>
35 #include <plotter.h>
36 #include <bitmaps.h>
37 
38 #include <sch_painter.h>
39 #include <sch_junction.h>
40 #include <netlist_object.h>
41 #include <sch_connection.h>
42 #include <schematic.h>
44 
45 
46 SCH_JUNCTION::SCH_JUNCTION( const wxPoint& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) :
48 {
49  m_pos = aPosition;
50  m_color = COLOR4D::UNSPECIFIED;
51  m_diameter = aDiameter;
52  m_Layer = aLayer;
53 }
54 
55 
57 {
58  return new SCH_JUNCTION( *this );
59 }
60 
61 
63 {
64  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T),
65  wxT( "Cannot swap junction data with invalid item." ) );
66 
67  SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
68  std::swap( m_pos, item->m_pos );
69  std::swap( m_diameter, item->m_diameter );
70  std::swap( m_color, item->m_color );
71 }
72 
73 
74 void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
75 {
76  aCount = 2;
77  aLayers[0] = m_Layer;
78  aLayers[1] = LAYER_SELECTION_SHADOWS;
79 }
80 
81 
83 {
84  EDA_RECT rect;
85 
86  int size = Schematic() ? Schematic()->Settings().m_JunctionSize
87  : Mils2iu( DEFAULT_JUNCTION_DIAM );
88 
89  if( m_diameter != 0 )
90  size = m_diameter;
91 
92  rect.SetOrigin( m_pos );
93  rect.Inflate( ( GetPenWidth() + size ) / 2 );
94 
95  return rect;
96 }
97 
98 
99 void SCH_JUNCTION::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
100 {
101  wxDC* DC = aSettings->GetPrintDC();
102  COLOR4D color = GetColor();
103 
104  if( color == COLOR4D::UNSPECIFIED )
105  color = aSettings->GetLayerColor( GetLayer() );
106 
107  int diameter = Schematic() ? Schematic()->Settings().m_JunctionSize
108  : Mils2iu( DEFAULT_JUNCTION_DIAM );
109 
110  if( m_diameter != 0 )
111  diameter = m_diameter;
112 
113  GRFilledCircle( nullptr, DC, m_pos.x + aOffset.x, m_pos.y + aOffset.y, diameter / 2, 0,
114  color, color );
115 }
116 
117 
118 void SCH_JUNCTION::MirrorX( int aXaxis_position )
119 {
120  MIRROR( m_pos.y, aXaxis_position );
121 }
122 
123 
124 void SCH_JUNCTION::MirrorY( int aYaxis_position )
125 {
126  MIRROR( m_pos.x, aYaxis_position );
127 }
128 
129 
130 void SCH_JUNCTION::Rotate( wxPoint aPosition )
131 {
132  RotatePoint( &m_pos, aPosition, 900 );
133 }
134 
135 
136 void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
137 {
138  DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
139  aItemList.push_back( item );
140 }
141 
142 
143 void SCH_JUNCTION::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
144 {
145  aPoints.push_back( m_pos );
146 }
147 
148 
150  SCH_SHEET_PATH* aSheetPath )
151 {
152  NETLIST_OBJECT* item = new NETLIST_OBJECT();
153 
154  item->m_SheetPath = *aSheetPath;
155  item->m_SheetPathInclude = *aSheetPath;
156  item->m_Comp = (SCH_ITEM*) this;
158  item->m_Start = item->m_End = m_pos;
159 
160  aNetListItems.push_back( item );
161 }
162 
163 
164 #if defined(DEBUG)
165 void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
166 {
167  // XML output:
168  wxString s = GetClass();
169 
170  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << ", " << m_diameter
171  << "/>\n";
172 }
173 #endif
174 
175 
177 {
178  NETCLASSPTR netclass = NetClass();
179 
180  if( netclass && netclass->GetSchematicColor() != COLOR4D::UNSPECIFIED )
181  return netclass->GetSchematicColor();
182 
183  return m_color;
184 }
185 
186 
188 {
189  int diameter = m_diameter;
190 
191  if( diameter == 0 )
192  {
193  // Careful; preview items don't have schematics...
194  if( Schematic() )
195  diameter = Schematic()->Settings().m_JunctionSize;
196  else
197  diameter = DEFAULT_JUNCTION_DIAM * IU_PER_MILS;
198  }
199 
200  NETCLASSPTR netclass = NetClass();
201 
202  if( netclass )
203  diameter = std::max( diameter, KiROUND( netclass->GetWireWidth() * 1.7 ) );
204 
205  return std::max( diameter, 1 );
206 }
207 
208 
209 bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
210 {
211  EDA_RECT rect = GetBoundingBox();
212 
213  rect.Inflate( aAccuracy );
214 
215  return rect.Contains( aPosition );
216 }
217 
218 
219 bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
220 {
222  return false;
223 
224  EDA_RECT rect = aRect;
225 
226  rect.Inflate( aAccuracy );
227 
228  if( aContained )
229  return rect.Contains( GetBoundingBox() );
230 
231  return rect.Intersects( GetBoundingBox() );
232 }
233 
234 
235 bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
236 {
237  return m_pos == aPosition;
238 }
239 
240 
241 void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
242 {
243  auto* settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
244  COLOR4D color = GetColor();
245 
246  if( color == COLOR4D::UNSPECIFIED )
247  color = settings->GetLayerColor( GetLayer() );
248 
249  aPlotter->SetColor( color );
250 
251  int diameter = Schematic() ? Schematic()->Settings().m_JunctionSize
252  : Mils2iu( DEFAULT_JUNCTION_DIAM );
253 
254  if( m_diameter != 0 )
255  diameter = m_diameter;
256 
257  aPlotter->Circle( m_pos, diameter, FILLED_SHAPE );
258 }
259 
260 
262 {
263  return add_junction_xpm;
264 }
265 
266 
267 bool SCH_JUNCTION::operator <( const SCH_ITEM& aItem ) const
268 {
269  if( Type() != aItem.Type() )
270  return Type() < aItem.Type();
271 
272  if( GetLayer() != aItem.GetLayer() )
273  return GetLayer() < aItem.GetLayer();
274 
275  auto junction = static_cast<const SCH_JUNCTION*>( &aItem );
276 
277  if( GetPosition().x != junction->GetPosition().x )
278  return GetPosition().x < junction->GetPosition().x;
279 
280  if( GetPosition().y != junction->GetPosition().y )
281  return GetPosition().y < junction->GetPosition().y;
282 
283  if( GetDiameter() != junction->GetDiameter() )
284  return GetDiameter() < junction->GetDiameter();
285 
286  return GetColor() < junction->GetColor();
287 }
288 
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_junction.h:53
SCH_LAYER_ID m_Layer
Definition: sch_item.h:192
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.
SCH_SHEET_PATH m_SheetPathInclude
virtual void SetColor(COLOR4D color)=0
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Add all the connection points for this item to aPoints.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:128
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:138
int color
Definition: DXF_plotter.cpp:61
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:116
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
SCH_SHEET_PATH m_SheetPath
#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:621
EDA_ITEM * m_Comp
bool Contains(const wxPoint &aPoint) const
Function Contains.
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.
NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a...
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:175
void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Create a new NETLIST_OBJECT for the schematic object and adds it to aNetListItems.
#define NULL
wxPoint GetPosition() const override
Definition: sch_junction.h:97
NETCLASSPTR NetClass() const
Definition: sch_item.cpp:160
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.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:126
SCH_LAYER_ID
Eeschema drawing layers.
SCH_SHEET_PATH.
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:289
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
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:114
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
STATUS_FLAGS m_Flags
Definition: base_struct.h:176
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:138
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: base_struct.h:159
The common library.
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
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.
Definition of the NETLIST_OBJECT class.
NETLIST_ITEM m_Type
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
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.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99