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 <class_drawpanel.h>
33 #include <trigo.h>
34 #include <common.h>
35 #include <richio.h>
36 #include <class_plotter.h>
37 #include <bitmaps.h>
38 
39 #include <sch_junction.h>
40 #include <class_netlist_object.h>
41 
42 
43 int SCH_JUNCTION::m_symbolSize = 40; // Default diameter of the junction symbol
44 
46  SCH_ITEM( NULL, SCH_JUNCTION_T )
47 {
48  m_pos = pos;
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 }
67 
68 
70 {
71  EDA_RECT rect;
72 
73  rect.SetOrigin( m_pos );
74  rect.Inflate( ( GetPenSize() + GetSymbolSize() ) / 2 );
75 
76  return rect;
77 }
78 
79 
80 void SCH_JUNCTION::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
81  GR_DRAWMODE aDrawMode, COLOR4D aColor )
82 {
83  COLOR4D color;
84 
85  if( aColor != COLOR4D::UNSPECIFIED )
86  color = aColor;
87  else
89 
90  GRSetDrawMode( aDC, aDrawMode );
91 
92  GRFilledCircle( aPanel->GetClipBox(), aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
93  ( GetSymbolSize() / 2 ), 0, color, color );
94 }
95 
96 
97 void SCH_JUNCTION::MirrorX( int aXaxis_position )
98 {
99  MIRROR( m_pos.y, aXaxis_position );
100 }
101 
102 
103 void SCH_JUNCTION::MirrorY( int aYaxis_position )
104 {
105  MIRROR( m_pos.x, aYaxis_position );
106 }
107 
108 
109 void SCH_JUNCTION::Rotate( wxPoint aPosition )
110 {
111  RotatePoint( &m_pos, aPosition, 900 );
112 }
113 
114 
115 void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
116 {
117  DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
118  aItemList.push_back( item );
119 }
120 
121 
122 bool SCH_JUNCTION::IsSelectStateChanged( const wxRect& aRect )
123 {
124  bool previousState = IsSelected();
125 
126  if( aRect.Contains( m_pos ) )
127  SetFlags( SELECTED );
128  else
129  ClearFlags( SELECTED );
130 
131  return previousState != IsSelected();
132 }
133 
134 
135 void SCH_JUNCTION::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
136 {
137  aPoints.push_back( m_pos );
138 }
139 
140 
142  SCH_SHEET_PATH* aSheetPath )
143 {
144  NETLIST_OBJECT* item = new NETLIST_OBJECT();
145 
146  item->m_SheetPath = *aSheetPath;
147  item->m_SheetPathInclude = *aSheetPath;
148  item->m_Comp = (SCH_ITEM*) this;
149  item->m_Type = NET_JUNCTION;
150  item->m_Start = item->m_End = m_pos;
151 
152  aNetListItems.push_back( item );
153 }
154 
155 
156 #if defined(DEBUG)
157 void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
158 {
159  // XML output:
160  wxString s = GetClass();
161 
162  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
163 }
164 #endif
165 
166 
167 bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
168 {
169  EDA_RECT rect = GetBoundingBox();
170 
171  rect.Inflate( aAccuracy );
172 
173  return rect.Contains( aPosition );
174 }
175 
176 
177 bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
178 {
180  return false;
181 
182  EDA_RECT rect = aRect;
183 
184  rect.Inflate( aAccuracy );
185 
186  if( aContained )
187  return rect.Contains( GetBoundingBox() );
188 
189  return rect.Intersects( GetBoundingBox() );
190 }
191 
192 
193 bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
194 {
195  return m_pos == aPosition;
196 }
197 
198 
199 void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
200 {
201  aPlotter->SetColor( GetLayerColor( GetLayer() ) );
202  aPlotter->Circle( m_pos, GetSymbolSize(), FILLED_SHAPE );
203 }
204 
205 
207 {
208  return add_junction_xpm;
209 }
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:212
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:38
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:296
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:138
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:235
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
void SetOrigin(const wxPoint &pos)
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
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
NETLIST_ITEM_T m_Type
int GetState(int type) const
Definition: base_struct.h:251
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
void GRFilledCircle(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:851
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:134
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:267
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:151
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:136
EDA_RECT * GetClipBox()
Class SCH_SHEET_PATH.
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...
Definition of the NETLIST_OBJECT class.
Base plotter engine class.
Definition: class_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))
static int GetSymbolSize()
Definition: sch_junction.h:53
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:189
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.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
The common library.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
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...
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