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, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2011 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 <plot_common.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 
53 bool SCH_JUNCTION::Save( FILE* aFile ) const
54 {
55  bool success = true;
56 
57  if( fprintf( aFile, "Connection ~ %-4d %-4d\n", m_pos.x, m_pos.y ) == EOF )
58  {
59  success = false;
60  }
61 
62  return success;
63 }
64 
65 
67 {
68  return new SCH_JUNCTION( *this );
69 }
70 
71 
73 {
74  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T),
75  wxT( "Cannot swap junction data with invalid item." ) );
76 
77  SCH_JUNCTION* item = (SCH_JUNCTION*) aItem;
78  std::swap( m_pos, item->m_pos );
79 }
80 
81 
82 bool SCH_JUNCTION::Load( LINE_READER& aLine, wxString& aErrorMsg )
83 {
84  char name[256];
85  char* line = (char*) aLine;
86 
87  while( (*line != ' ' ) && *line )
88  line++;
89 
90  if( sscanf( line, "%255s %d %d", name, &m_pos.x, &m_pos.y ) != 3 )
91  {
92  aErrorMsg.Printf( wxT( "Eeschema file connection load error at line %d, aborted" ),
93  aLine.LineNumber() );
94  aErrorMsg << wxT( "\n" ) << FROM_UTF8( (char*) aLine );
95  return false;
96  }
97 
98  return true;
99 }
100 
101 
103 {
104  EDA_RECT rect;
105 
106  rect.SetOrigin( m_pos );
107  rect.Inflate( ( GetPenSize() + GetSymbolSize() ) / 2 );
108 
109  return rect;
110 }
111 
112 
113 void SCH_JUNCTION::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
114  GR_DRAWMODE aDrawMode, COLOR4D aColor )
115 {
116  COLOR4D color;
117 
118  if( aColor != COLOR4D::UNSPECIFIED )
119  color = aColor;
120  else
122 
123  GRSetDrawMode( aDC, aDrawMode );
124 
125  GRFilledCircle( aPanel->GetClipBox(), aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
126  ( GetSymbolSize() / 2 ), 0, color, color );
127 }
128 
129 
130 void SCH_JUNCTION::MirrorX( int aXaxis_position )
131 {
132  MIRROR( m_pos.y, aXaxis_position );
133 }
134 
135 
136 void SCH_JUNCTION::MirrorY( int aYaxis_position )
137 {
138  MIRROR( m_pos.x, aYaxis_position );
139 }
140 
141 
142 void SCH_JUNCTION::Rotate( wxPoint aPosition )
143 {
144  RotatePoint( &m_pos, aPosition, 900 );
145 }
146 
147 
148 void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
149 {
150  DANGLING_END_ITEM item( JUNCTION_END, this, m_pos );
151  aItemList.push_back( item );
152 }
153 
154 
155 bool SCH_JUNCTION::IsSelectStateChanged( const wxRect& aRect )
156 {
157  bool previousState = IsSelected();
158 
159  if( aRect.Contains( m_pos ) )
160  SetFlags( SELECTED );
161  else
162  ClearFlags( SELECTED );
163 
164  return previousState != IsSelected();
165 }
166 
167 
168 void SCH_JUNCTION::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
169 {
170  aPoints.push_back( m_pos );
171 }
172 
173 
175  SCH_SHEET_PATH* aSheetPath )
176 {
177  NETLIST_OBJECT* item = new NETLIST_OBJECT();
178 
179  item->m_SheetPath = *aSheetPath;
180  item->m_SheetPathInclude = *aSheetPath;
181  item->m_Comp = (SCH_ITEM*) this;
182  item->m_Type = NET_JUNCTION;
183  item->m_Start = item->m_End = m_pos;
184 
185  aNetListItems.push_back( item );
186 }
187 
188 
189 #if defined(DEBUG)
190 void SCH_JUNCTION::Show( int nestLevel, std::ostream& os ) const
191 {
192  // XML output:
193  wxString s = GetClass();
194 
195  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_pos << "/>\n";
196 }
197 #endif
198 
199 
200 bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const
201 {
202  EDA_RECT rect = GetBoundingBox();
203 
204  rect.Inflate( aAccuracy );
205 
206  return rect.Contains( aPosition );
207 }
208 
209 
210 bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
211 {
213  return false;
214 
215  EDA_RECT rect = aRect;
216 
217  rect.Inflate( aAccuracy );
218 
219  if( aContained )
220  return rect.Contains( GetBoundingBox() );
221 
222  return rect.Intersects( GetBoundingBox() );
223 }
224 
225 
226 bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
227 {
228  return m_pos == aPosition;
229 }
230 
231 
232 void SCH_JUNCTION::Plot( PLOTTER* aPlotter )
233 {
234  aPlotter->SetColor( GetLayerColor( GetLayer() ) );
235  aPlotter->Circle( m_pos, GetSymbolSize(), FILLED_SHAPE );
236 }
237 
239 {
240  return add_junction_xpm;
241 }
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
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
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...
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
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
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
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:833
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()
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
Class SCH_SHEET_PATH.
bool Save(FILE *aFile) const override
Function Save writes the data structures for this object out to a FILE in "*.sch" format...
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: plot_common.h:86
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.
const char * name
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
bool Load(LINE_READER &aLine, wxString &aErrorMsg) override
Function Load reads a schematic item from aLine in a .sch file.
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