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 
42 
43 int SCH_JUNCTION::m_symbolSize = 40; // Default diameter of the junction symbol
44 
45 
47 {
49 }
50 
51 
53  SCH_ITEM( NULL, SCH_JUNCTION_T )
54 {
55  m_pos = pos;
57 }
58 
59 
61 {
62  return new SCH_JUNCTION( *this );
63 }
64 
65 
67 {
68  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T),
69  wxT( "Cannot swap junction data with invalid item." ) );
70 
71  SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
72  std::swap( m_pos, item->m_pos );
73 }
74 
75 
76 void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
77 {
78  aCount = 1;
79  aLayers[0] = LAYER_JUNCTION;
80 }
81 
82 
84 {
85  EDA_RECT rect;
86 
87  rect.SetOrigin( m_pos );
88  rect.Inflate( ( GetPenSize() + GetEffectiveSymbolSize() ) / 2 );
89 
90  return rect;
91 }
92 
93 
94 void SCH_JUNCTION::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
95  GR_DRAWMODE aDrawMode, COLOR4D aColor )
96 {
97  COLOR4D color;
98 
99  if( aColor != COLOR4D::UNSPECIFIED )
100  color = aColor;
101  else
103 
104  GRSetDrawMode( aDC, aDrawMode );
105 
106  GRFilledCircle( aPanel->GetClipBox(), aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
107  ( GetEffectiveSymbolSize() / 2 ), 0, color, color );
108 }
109 
110 
111 void SCH_JUNCTION::MirrorX( int aXaxis_position )
112 {
113  MIRROR( m_pos.y, aXaxis_position );
114 }
115 
116 
117 void SCH_JUNCTION::MirrorY( int aYaxis_position )
118 {
119  MIRROR( m_pos.x, aYaxis_position );
120 }
121 
122 
123 void SCH_JUNCTION::Rotate( wxPoint aPosition )
124 {
125  RotatePoint( &m_pos, aPosition, 900 );
126 }
127 
128 
129 void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
130 {
131  DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
132  aItemList.push_back( item );
133 }
134 
135 
136 bool SCH_JUNCTION::IsSelectStateChanged( const wxRect& aRect )
137 {
138  bool previousState = IsSelected();
139 
140  if( aRect.Contains( m_pos ) )
141  SetFlags( SELECTED );
142  else
143  ClearFlags( SELECTED );
144 
145  return previousState != IsSelected();
146 }
147 
148 
149 void SCH_JUNCTION::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
150 {
151  aPoints.push_back( m_pos );
152 }
153 
154 
156  SCH_SHEET_PATH* aSheetPath )
157 {
158  NETLIST_OBJECT* item = new NETLIST_OBJECT();
159 
160  item->m_SheetPath = *aSheetPath;
161  item->m_SheetPathInclude = *aSheetPath;
162  item->m_Comp = (SCH_ITEM*) this;
163  item->m_Type = NET_JUNCTION;
164  item->m_Start = item->m_End = m_pos;
165 
166  aNetListItems.push_back( item );
167 }
168 
169 
170 #if defined(DEBUG)
171 void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
172 {
173  // XML output:
174  wxString s = GetClass();
175 
176  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
177 }
178 #endif
179 
180 
181 bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
182 {
183  EDA_RECT rect = GetBoundingBox();
184 
185  rect.Inflate( aAccuracy );
186 
187  return rect.Contains( aPosition );
188 }
189 
190 
191 bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
192 {
194  return false;
195 
196  EDA_RECT rect = aRect;
197 
198  rect.Inflate( aAccuracy );
199 
200  if( aContained )
201  return rect.Contains( GetBoundingBox() );
202 
203  return rect.Intersects( GetBoundingBox() );
204 }
205 
206 
207 bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
208 {
209  return m_pos == aPosition;
210 }
211 
212 
213 void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
214 {
215  aPlotter->SetColor( GetLayerColor( GetLayer() ) );
217 }
218 
219 
221 {
222  return add_junction_xpm;
223 }
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_junction.h:48
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
SCH_LAYER_ID m_Layer
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
bool IsSelectStateChanged(const wxRect &aRect) override
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
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_types.h:43
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
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
bool Contains(const wxPoint &aPoint) const
Function Contains.
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:125
int color
Definition: DXF_plotter.cpp:62
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.
bool IsSelected() const
Definition: base_struct.h:224
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:124
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
SCH_SHEET_PATH m_SheetPath
virtual EDA_RECT * GetClipBox()
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
NETLIST_ITEM_T m_Type
int GetState(int type) const
Definition: base_struct.h:240
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
void GRFilledCircle(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:778
EDA_ITEM * m_Comp
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
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:39
This file contains miscellaneous commonly used macros and functions.
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:111
#define SELECTED
Definition: base_struct.h:121
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...
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:138
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:123
Class SCH_SHEET_PATH.
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...
wxPoint m_pos
Definition: sch_junction.h:38
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:97
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
SCH_JUNCTION(const wxPoint &pos=wxPoint(0, 0))
#define max(a, b)
Definition: auxiliary.h:86
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:178
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
The common library.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
Class DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be conn...
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.
static int GetEffectiveSymbolSize()
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
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.
virtual int GetPenSize() const
Function GetPenSize virtual pure.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39