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-2017 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 <richio.h>
36 #include <plotter.h>
37 #include <bitmaps.h>
38 
39 #include <sch_junction.h>
40 #include <netlist_object.h>
41 #include <sch_connection.h>
42 
43 
44 int SCH_JUNCTION::m_symbolSize = Mils2iu( 40 ); // Default diameter of the junction symbol
45 
46 
48 {
49  return std::max( GetDefaultLineThickness(), m_symbolSize );
50 }
51 
52 
55 {
56  m_pos = pos;
58 }
59 
60 
62 {
63  return new SCH_JUNCTION( *this );
64 }
65 
66 
68 {
69  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T),
70  wxT( "Cannot swap junction data with invalid item." ) );
71 
72  SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
73  std::swap( m_pos, item->m_pos );
74 }
75 
76 
77 void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
78 {
79  aCount = 2;
80  aLayers[0] = LAYER_JUNCTION;
81  aLayers[1] = LAYER_SELECTION_SHADOWS;
82 }
83 
84 
86 {
87  EDA_RECT rect;
88 
89  rect.SetOrigin( m_pos );
90  rect.Inflate( ( GetPenSize() + GetEffectiveSymbolSize() ) / 2 );
91 
92  return rect;
93 }
94 
95 
96 void SCH_JUNCTION::Print( wxDC* aDC, const wxPoint& aOffset )
97 {
98  auto conn = Connection( *g_CurrentSheet );
99  COLOR4D color = GetLayerColor( ( conn && conn->IsBus() ) ? LAYER_BUS : m_Layer );
100 
101  GRFilledCircle( nullptr, aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
102  ( GetEffectiveSymbolSize() / 2 ), 0, color, color );
103 }
104 
105 
106 void SCH_JUNCTION::MirrorX( int aXaxis_position )
107 {
108  MIRROR( m_pos.y, aXaxis_position );
109 }
110 
111 
112 void SCH_JUNCTION::MirrorY( int aYaxis_position )
113 {
114  MIRROR( m_pos.x, aYaxis_position );
115 }
116 
117 
118 void SCH_JUNCTION::Rotate( wxPoint aPosition )
119 {
120  RotatePoint( &m_pos, aPosition, 900 );
121 }
122 
123 
124 void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
125 {
126  DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
127  aItemList.push_back( item );
128 }
129 
130 
131 void SCH_JUNCTION::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
132 {
133  aPoints.push_back( m_pos );
134 }
135 
136 
138  SCH_SHEET_PATH* aSheetPath )
139 {
140  NETLIST_OBJECT* item = new NETLIST_OBJECT();
141 
142  item->m_SheetPath = *aSheetPath;
143  item->m_SheetPathInclude = *aSheetPath;
144  item->m_Comp = (SCH_ITEM*) this;
146  item->m_Start = item->m_End = m_pos;
147 
148  aNetListItems.push_back( item );
149 }
150 
151 
152 #if defined(DEBUG)
153 void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
154 {
155  // XML output:
156  wxString s = GetClass();
157 
158  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
159 }
160 #endif
161 
162 
163 bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
164 {
165  EDA_RECT rect = GetBoundingBox();
166 
167  rect.Inflate( aAccuracy );
168 
169  return rect.Contains( aPosition );
170 }
171 
172 
173 bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
174 {
176  return false;
177 
178  EDA_RECT rect = aRect;
179 
180  rect.Inflate( aAccuracy );
181 
182  if( aContained )
183  return rect.Contains( GetBoundingBox() );
184 
185  return rect.Intersects( GetBoundingBox() );
186 }
187 
188 
189 bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
190 {
191  return m_pos == aPosition;
192 }
193 
194 
195 void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
196 {
197  aPlotter->SetColor( GetLayerColor( GetLayer() ) );
199 }
200 
201 
203 {
204  return add_junction_xpm;
205 }
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_junction.h:49
SCH_LAYER_ID m_Layer
Definition: sch_item.h:141
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
PNG memory record (file in memory).
Definition: bitmap_def.h:29
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors 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
Function GetConnectionPoints 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:131
int color
Definition: DXF_plotter.cpp:61
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i....
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
void Rotate(wxPoint aPosition) override
Function Rotate rotates 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
Function SwapData swap the internal data structures aItem with the schematic item.
SCH_SHEET_PATH m_SheetPath
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
void GRFilledCircle(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:619
EDA_ITEM * m_Comp
bool Contains(const wxPoint &aPoint) const
Function Contains.
bool doIsConnected(const wxPoint &aPosition) const override
Function doIsConnected provides the object specific test to see if it is connected to aPosition.
static int m_symbolSize
Definition: sch_junction.h:35
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...
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:123
void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Function GetNetListItem creates a new NETLIST_OBJECT for the schematic object and adds it to aNetList...
virtual int GetPenSize() const
Function GetPenSize virtual pure.
Definition: sch_item.h:231
#define NULL
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
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:129
SCH_SHEET_PATH.
const BITMAP_OPAQUE add_junction_xpm[1]
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers returns the layers the item is drawn on (which may be more than its "home" lay...
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieves the connection associated with this object in the given sheet Note: the returned value can ...
Definition: sch_item.cpp:128
wxPoint m_pos
Definition: sch_junction.h:34
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:212
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points.
Base plotter engine class.
Definition: plotter.h:103
SCH_JUNCTION(const wxPoint &pos=wxPoint(0, 0))
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:184
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
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
The common library.
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be connected ...
Definition: sch_item.h:67
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.
void Print(wxDC *aDC, const wxPoint &aOffset) override
Function Print Print a schematic item.
NETLIST_ITEM m_Type
static int GetEffectiveSymbolSize()
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:136
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
void Plot(PLOTTER *aPlotter) override
Function Plot plots 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:207
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39