KiCad PCB EDA Suite
sch_no_connect.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) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2015 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 
30 #include <fctsys.h>
31 #include <gr_basic.h>
32 #include <macros.h>
33 #include <class_drawpanel.h>
34 #include <common.h>
35 #include <plot_common.h>
36 #include <bitmaps.h>
37 
38 #include <general.h>
39 #include <sch_no_connect.h>
40 #include <class_netlist_object.h>
41 
42 
44  SCH_ITEM( NULL, SCH_NO_CONNECT_T )
45 {
46 #define DRAWNOCONNECT_SIZE 48 /* No symbol connection range. */
47  m_pos = pos;
49 #undef DRAWNOCONNECT_SIZE
50 
52 }
53 
54 
56 {
57  return new SCH_NO_CONNECT( *this );
58 }
59 
60 
62 {
63  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_NO_CONNECT_T),
64  wxT( "Cannot swap no connect data with invalid item." ) );
65 
66  SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
67  std::swap( m_pos, item->m_pos );
68  std::swap( m_size, item->m_size );
69 }
70 
71 
73 {
74  int delta = ( GetPenSize() + m_size.x ) / 2;
75  EDA_RECT box;
76 
77  box.SetOrigin( m_pos );
78  box.Inflate( delta );
79 
80  return box;
81 }
82 
83 
84 bool SCH_NO_CONNECT::Save( FILE* aFile ) const
85 {
86  bool success = true;
87 
88  if( fprintf( aFile, "NoConn ~ %-4d %-4d\n", m_pos.x, m_pos.y ) == EOF )
89  {
90  success = false;
91  }
92 
93  return success;
94 }
95 
96 
97 bool SCH_NO_CONNECT::Load( LINE_READER& aLine, wxString& aErrorMsg )
98 {
99  char name[256];
100  char* line = (char*) aLine;
101 
102  while( (*line != ' ' ) && *line )
103  line++;
104 
105  if( sscanf( line, "%255s %d %d", name, &m_pos.x, &m_pos.y ) != 3 )
106  {
107  aErrorMsg.Printf( wxT( "Eeschema file No Connect load error at line %d" ),
108  aLine.LineNumber() );
109  aErrorMsg << wxT( "\n" ) << FROM_UTF8( ((char*)aLine) );
110  return false;
111  }
112 
113  return true;
114 }
115 
116 
117 void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
118 {
119  DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
120  aItemList.push_back( item );
121 }
122 
123 
125 {
126  return GetDefaultLineThickness();
127 }
128 
129 
130 void SCH_NO_CONNECT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
131  GR_DRAWMODE aDrawMode, COLOR4D aColor )
132 {
133  int pX, pY;
134  int delta = m_size.x / 2;
135  int width = GetDefaultLineThickness();
136 
137  pX = m_pos.x + aOffset.x;
138  pY = m_pos.y + aOffset.y;
139 
140  COLOR4D color;
141 
142  if( aColor != COLOR4D::UNSPECIFIED )
143  color = aColor;
144  else
145  color = GetLayerColor( LAYER_NOCONNECT );
146 
147  GRSetDrawMode( aDC, aDrawMode );
148 
149  GRLine( aPanel->GetClipBox(), aDC, pX - delta, pY - delta, pX + delta, pY + delta,
150  width, color );
151  GRLine( aPanel->GetClipBox(), aDC, pX + delta, pY - delta, pX - delta, pY + delta,
152  width, color );
153 }
154 
155 
156 void SCH_NO_CONNECT::MirrorX( int aXaxis_position )
157 {
158  MIRROR( m_pos.y, aXaxis_position );
159 }
160 
161 
162 void SCH_NO_CONNECT::MirrorY( int aYaxis_position )
163 {
164  MIRROR( m_pos.x, aYaxis_position );
165 }
166 
167 
169 {
170  RotatePoint( &m_pos, aPosition, 900 );
171 }
172 
173 
174 bool SCH_NO_CONNECT::IsSelectStateChanged( const wxRect& aRect )
175 {
176  bool previousState = IsSelected();
177 
178  if( aRect.Contains( m_pos ) )
179  SetFlags( SELECTED );
180  else
181  ClearFlags( SELECTED );
182 
183  return previousState != IsSelected();
184 }
185 
186 
187 void SCH_NO_CONNECT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
188 {
189  aPoints.push_back( m_pos );
190 }
191 
192 
194  SCH_SHEET_PATH* aSheetPath )
195 {
196  NETLIST_OBJECT* item = new NETLIST_OBJECT();
197 
198  item->m_SheetPath = *aSheetPath;
199  item->m_SheetPathInclude = *aSheetPath;
200  item->m_Comp = this;
201  item->m_Type = NET_NOCONNECT;
202  item->m_Start = item->m_End = m_pos;
203 
204  aNetListItems.push_back( item );
205 }
206 
207 
208 bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const
209 {
210  return m_pos == aPosition;
211 }
212 
213 bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
214 {
215  int delta = ( ( m_size.x + GetDefaultLineThickness() ) / 2 ) + aAccuracy;
216 
217  wxPoint dist = aPosition - m_pos;
218 
219  if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
220  return true;
221 
222  return false;
223 }
224 
225 
226 bool SCH_NO_CONNECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
227 {
228  EDA_RECT rect = aRect;
229 
230  rect.Inflate( aAccuracy );
231 
232  if( aContained )
233  return rect.Contains( GetBoundingBox() );
234 
235  return rect.Intersects( GetBoundingBox() );
236 }
237 
238 
239 void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter )
240 {
241  int delta = m_size.x / 2;
242  int pX, pY;
243 
244  pX = m_pos.x;
245  pY = m_pos.y;
246 
247  aPlotter->SetCurrentLineWidth( GetPenSize() );
248  aPlotter->SetColor( GetLayerColor( GetLayer() ) );
249  aPlotter->MoveTo( wxPoint( pX - delta, pY - delta ) );
250  aPlotter->FinishTo( wxPoint( pX + delta, pY + delta ) );
251  aPlotter->MoveTo( wxPoint( pX + delta, pY - delta ) );
252  aPlotter->FinishTo( wxPoint( pX - delta, pY + delta ) );
253 }
254 
255 
257 {
258  return noconn_xpm;
259 }
260 
void FinishTo(const wxPoint &pos)
Definition: plot_common.h:241
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
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...
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
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
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
bool Load(LINE_READER &aLine, wxString &aErrorMsg) override
Function Load reads a schematic item from aLine in a .sch file.
SCH_SHEET_PATH m_SheetPathInclude
virtual void SetColor(COLOR4D color)=0
bool Contains(const wxPoint &aPoint) const
Function Contains.
wxPoint m_pos
Position of the no connect object.
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color)
Definition: gr_basic.cpp:352
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
wxSize m_size
Size of the no connect object.
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
static const int dist[10][10]
Definition: dist.cpp:57
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
#define DRAWNOCONNECT_SIZE
bool IsSelected() const
Definition: base_struct.h:221
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 SetOrigin(const wxPoint &pos)
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...
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
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
#define abs(a)
Definition: auxiliary.h:84
SCH_NO_CONNECT(const wxPoint &pos=wxPoint(0, 0))
static const int delta[8][2]
Definition: solve.cpp:112
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
This file contains miscellaneous commonly used macros and functions.
bool Save(FILE *aFile) const override
Function Save writes the data structures for this object out to a FILE in "*.sch" format...
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:120
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
void SetLayer(SCH_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
EDA_RECT * GetClipBox()
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
Class SCH_SHEET_PATH.
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
void MoveTo(const wxPoint &pos)
Definition: plot_common.h:231
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.
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.
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:151
The common library.
const char * name
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
Class DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be conn...
int GetPenSize() const override
Function GetPenSize virtual pure.
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
bool IsSelectStateChanged(const wxRect &aRect) override
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
bool doIsConnected(const wxPoint &aPosition) const override
Function doIsConnected provides the object specific test to see if it is connected to aPosition...
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39