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, jp.charras at wanoadoo.fr
5  * Copyright (C) 1992-2018 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 <sch_draw_panel.h>
34 #include <common.h>
35 #include <plotter.h>
36 #include <bitmaps.h>
37 
38 #include <general.h>
39 #include <sch_no_connect.h>
40 #include <netlist_object.h>
41 
42 
44  SCH_ITEM( NULL, SCH_NO_CONNECT_T )
45 {
46  m_pos = pos;
47  m_size = 48;
48 
50 }
51 
52 
54 {
55  return new SCH_NO_CONNECT( *this );
56 }
57 
58 
60 {
61  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_NO_CONNECT_T),
62  wxT( "Cannot swap no connect data with invalid item." ) );
63 
64  SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
65  std::swap( m_pos, item->m_pos );
66  std::swap( m_size, item->m_size );
67 }
68 
69 
71 {
72  int delta = ( GetPenSize() + GetSize() ) / 2;
73  EDA_RECT box;
74 
75  box.SetOrigin( m_pos );
76  box.Inflate( delta );
77 
78  return box;
79 }
80 
81 
82 void SCH_NO_CONNECT::ViewGetLayers( int aLayers[], int& aCount ) const
83 {
84  aLayers[0] = LAYER_NOCONNECT;
85  aCount = 1;
86 }
87 
88 
89 void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
90 {
91  DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
92  aItemList.push_back( item );
93 }
94 
95 
97 {
98  return GetDefaultLineThickness();
99 }
100 
101 
102 void SCH_NO_CONNECT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
103  GR_DRAWMODE aDrawMode, COLOR4D aColor )
104 {
105  int pX, pY;
106  int delta = GetSize() / 2;
107  int width = GetDefaultLineThickness();
108 
109  pX = m_pos.x + aOffset.x;
110  pY = m_pos.y + aOffset.y;
111 
112  COLOR4D color;
113 
114  if( aColor != COLOR4D::UNSPECIFIED )
115  color = aColor;
116  else
117  color = GetLayerColor( LAYER_NOCONNECT );
118 
119  GRSetDrawMode( aDC, aDrawMode );
120 
121  GRLine( aPanel->GetClipBox(), aDC, pX - delta, pY - delta, pX + delta, pY + delta,
122  width, color );
123  GRLine( aPanel->GetClipBox(), aDC, pX + delta, pY - delta, pX - delta, pY + delta,
124  width, color );
125 }
126 
127 
128 void SCH_NO_CONNECT::MirrorX( int aXaxis_position )
129 {
130  MIRROR( m_pos.y, aXaxis_position );
131 }
132 
133 
134 void SCH_NO_CONNECT::MirrorY( int aYaxis_position )
135 {
136  MIRROR( m_pos.x, aYaxis_position );
137 }
138 
139 
141 {
142  RotatePoint( &m_pos, aPosition, 900 );
143 }
144 
145 
146 bool SCH_NO_CONNECT::IsSelectStateChanged( const wxRect& aRect )
147 {
148  bool previousState = IsSelected();
149 
150  if( aRect.Contains( m_pos ) )
151  SetFlags( SELECTED );
152  else
153  ClearFlags( SELECTED );
154 
155  return previousState != IsSelected();
156 }
157 
158 
159 void SCH_NO_CONNECT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
160 {
161  aPoints.push_back( m_pos );
162 }
163 
164 
166  SCH_SHEET_PATH* aSheetPath )
167 {
168  NETLIST_OBJECT* item = new NETLIST_OBJECT();
169 
170  item->m_SheetPath = *aSheetPath;
171  item->m_SheetPathInclude = *aSheetPath;
172  item->m_Comp = this;
173  item->m_Type = NET_NOCONNECT;
174  item->m_Start = item->m_End = m_pos;
175 
176  aNetListItems.push_back( item );
177 }
178 
179 
180 bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const
181 {
182  return m_pos == aPosition;
183 }
184 
185 bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
186 {
187  int delta = ( ( GetSize() + GetDefaultLineThickness() ) / 2 ) + aAccuracy;
188 
189  wxPoint dist = aPosition - m_pos;
190 
191  if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
192  return true;
193 
194  return false;
195 }
196 
197 
198 bool SCH_NO_CONNECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
199 {
200  EDA_RECT rect = aRect;
201 
202  rect.Inflate( aAccuracy );
203 
204  if( aContained )
205  return rect.Contains( GetBoundingBox() );
206 
207  return rect.Intersects( GetBoundingBox() );
208 }
209 
210 
211 void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter )
212 {
213  int delta = GetSize() / 2;
214  int pX, pY;
215 
216  pX = m_pos.x;
217  pY = m_pos.y;
218 
219  aPlotter->SetCurrentLineWidth( GetPenSize() );
220  aPlotter->SetColor( GetLayerColor( GetLayer() ) );
221  aPlotter->MoveTo( wxPoint( pX - delta, pY - delta ) );
222  aPlotter->FinishTo( wxPoint( pX + delta, pY + delta ) );
223  aPlotter->MoveTo( wxPoint( pX + delta, pY - delta ) );
224  aPlotter->FinishTo( wxPoint( pX - delta, pY + delta ) );
225 }
226 
227 
229 {
230  return noconn_xpm;
231 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:251
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
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...
PNG memory record (file in memory).
Definition: bitmap_types.h:43
static const int dist[10][10]
Definition: ar_matrix.cpp:320
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
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.
int color
Definition: DXF_plotter.cpp:62
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
bool IsSelected() const
Definition: base_struct.h:224
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)
Definition: eda_rect.h:124
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
virtual EDA_RECT * GetClipBox()
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
NETLIST_ITEM_T m_Type
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
EDA_ITEM * m_Comp
#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.
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 SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
void SetLayer(SCH_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Class SCH_SHEET_PATH.
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:285
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: plotter.h:241
Base plotter engine class.
Definition: plotter.h:97
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.
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 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...
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:257
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.
int GetSize() const
Definition of the NETLIST_OBJECT class.
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.
int m_size
Size of the no connect object.
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