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-2019 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>
42 
43 
46 {
47  m_pos = pos;
48  m_size = Mils2iu( 48 );
49 
51 }
52 
53 
55 {
56  return new SCH_NO_CONNECT( *this );
57 }
58 
59 
61 {
62  wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_NO_CONNECT_T),
63  wxT( "Cannot swap no connect data with invalid item." ) );
64 
65  SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
66  std::swap( m_pos, item->m_pos );
67  std::swap( m_size, item->m_size );
68 }
69 
70 
72 {
73  int delta = ( GetPenSize() + GetSize() ) / 2;
74  EDA_RECT box;
75 
76  box.SetOrigin( m_pos );
77  box.Inflate( delta );
78 
79  return box;
80 }
81 
82 
83 void SCH_NO_CONNECT::ViewGetLayers( int aLayers[], int& aCount ) const
84 {
85  aCount = 2;
86  aLayers[0] = LAYER_NOCONNECT;
87  aLayers[1] = LAYER_SELECTION_SHADOWS;
88 }
89 
90 
91 void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
92 {
93  DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
94  aItemList.push_back( item );
95 }
96 
97 
99 {
100  return GetDefaultLineThickness();
101 }
102 
103 
104 void SCH_NO_CONNECT::Print( wxDC* aDC, const wxPoint& aOffset )
105 {
106  int half = GetSize() / 2;
107  int width = GetDefaultLineThickness();
108  int pX = m_pos.x + aOffset.x;
109  int pY = m_pos.y + aOffset.y;
110 
112 
113  GRLine( nullptr, aDC, pX - half, pY - half, pX + half, pY + half, width, color );
114  GRLine( nullptr, aDC, pX + half, pY - half, pX - half, pY + half, width, color );
115 }
116 
117 
118 void SCH_NO_CONNECT::MirrorX( int aXaxis_position )
119 {
120  MIRROR( m_pos.y, aXaxis_position );
121 }
122 
123 
124 void SCH_NO_CONNECT::MirrorY( int aYaxis_position )
125 {
126  MIRROR( m_pos.x, aYaxis_position );
127 }
128 
129 
131 {
132  RotatePoint( &m_pos, aPosition, 900 );
133 }
134 
135 
136 void SCH_NO_CONNECT::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
137 {
138  aPoints.push_back( m_pos );
139 }
140 
141 
143  SCH_SHEET_PATH* aSheetPath )
144 {
145  NETLIST_OBJECT* item = new NETLIST_OBJECT();
146 
147  item->m_SheetPath = *aSheetPath;
148  item->m_SheetPathInclude = *aSheetPath;
149  item->m_Comp = this;
151  item->m_Start = item->m_End = m_pos;
152 
153  aNetListItems.push_back( item );
154 }
155 
156 
157 bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const
158 {
159  return m_pos == aPosition;
160 }
161 
162 bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
163 {
164  int delta = ( ( GetSize() + GetDefaultLineThickness() ) / 2 ) + aAccuracy;
165 
166  wxPoint dist = aPosition - m_pos;
167 
168  if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
169  return true;
170 
171  return false;
172 }
173 
174 
175 bool SCH_NO_CONNECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
176 {
177  EDA_RECT rect = aRect;
178 
179  rect.Inflate( aAccuracy );
180 
181  if( aContained )
182  return rect.Contains( GetBoundingBox() );
183 
184  return rect.Intersects( GetBoundingBox() );
185 }
186 
187 
188 void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter )
189 {
190  int delta = GetSize() / 2;
191  int pX, pY;
192 
193  pX = m_pos.x;
194  pY = m_pos.y;
195 
196  aPlotter->SetCurrentLineWidth( GetPenSize() );
197  aPlotter->SetColor( aPlotter->ColorSettings()->GetColor( LAYER_NOCONNECT ) );
198  aPlotter->MoveTo( wxPoint( pX - delta, pY - delta ) );
199  aPlotter->FinishTo( wxPoint( pX + delta, pY + delta ) );
200  aPlotter->MoveTo( wxPoint( pX + delta, pY - delta ) );
201  aPlotter->FinishTo( wxPoint( pX - delta, pY + delta ) );
202 }
203 
204 
206 {
207  return noconn_xpm;
208 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:283
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_def.h:29
static const int dist[10][10]
Definition: ar_matrix.cpp:326
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
wxPoint m_pos
Position of the no connect object.
int color
Definition: DXF_plotter.cpp:61
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.
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:131
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_SHEET_PATH m_SheetPath
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
EDA_ITEM * m_Comp
SCH_NO_CONNECT(const wxPoint &pos=wxPoint(0, 0))
bool Contains(const wxPoint &aPoint) const
Function Contains.
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.
NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a...
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:123
void Print(wxDC *aDC, const wxPoint &aOffset) override
Function Print Print a schematic item.
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
#define NULL
const BITMAP_OPAQUE noconn_xpm[1]
Definition: noconn.cpp:26
COLOR_SETTINGS * ColorSettings()
Definition: plotter.h:145
void SetLayer(SCH_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Definition: sch_item.h:231
int GetSize() const
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Helper for all the old plotting/printing code while it still exists.
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:230
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:273
Base plotter engine class.
Definition: plotter.h:104
COLOR4D GetColor(int aLayer) const
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
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...
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be connected ...
Definition: sch_item.h:76
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition of the NETLIST_OBJECT class.
NETLIST_ITEM m_Type
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
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.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40