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-2021 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 <sch_draw_panel.h>
31 #include <plotters/plotter.h>
32 #include <bitmaps.h>
33 #include <schematic.h>
34 #include <sch_no_connect.h>
36 #include <default_values.h> // For some default values
37 #include <core/mirror.h>
38 #include <trigo.h>
39 
40 
41 SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) :
42  SCH_ITEM( nullptr, SCH_NO_CONNECT_T )
43 {
44  m_pos = pos;
45  m_size = Mils2iu( DEFAULT_NOCONNECT_SIZE );
46 
48 }
49 
50 
52 {
53  return new SCH_NO_CONNECT( *this );
54 }
55 
56 
58 {
59  wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ),
60  wxT( "Cannot swap no connect data with invalid item." ) );
61 
62  SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
63  std::swap( m_pos, item->m_pos );
64  std::swap( m_size, item->m_size );
65 }
66 
67 
69 {
70  int delta = ( GetPenWidth() + GetSize() ) / 2;
71  EDA_RECT box;
72 
73  box.SetOrigin( m_pos );
74  box.Inflate( delta );
75 
76  return box;
77 }
78 
79 
80 void SCH_NO_CONNECT::ViewGetLayers( int aLayers[], int& aCount ) const
81 {
82  aCount = 2;
83  aLayers[0] = LAYER_NOCONNECT;
84  aLayers[1] = LAYER_SELECTION_SHADOWS;
85 }
86 
87 
88 void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
89 {
90  DANGLING_END_ITEM item( NO_CONNECT_END, this, m_pos );
91  aItemList.push_back( item );
92 }
93 
94 
96 {
97  if( !Schematic() )
98  return 1;
99 
100  return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
101 }
102 
103 
104 void SCH_NO_CONNECT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
105 {
106  wxDC* DC = aSettings->GetPrintDC();
107  int half = GetSize() / 2;
108  int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
109  int pX = m_pos.x + aOffset.x;
110  int pY = m_pos.y + aOffset.y;
111  COLOR4D color = aSettings->GetLayerColor( LAYER_NOCONNECT );
112 
113  GRLine( nullptr, DC, pX - half, pY - half, pX + half, pY + half, penWidth, color );
114  GRLine( nullptr, DC, pX + half, pY - half, pX - half, pY + half, penWidth, color );
115 }
116 
117 
119 {
120  MIRROR( m_pos.y, aCenter );
121 }
122 
123 
125 {
126  MIRROR( m_pos.x, aCenter );
127 }
128 
129 
130 void SCH_NO_CONNECT::Rotate( const wxPoint& aCenter )
131 {
132  RotatePoint( &m_pos, aCenter, 900 );
133 }
134 
135 
136 std::vector<wxPoint> SCH_NO_CONNECT::GetConnectionPoints() const
137 {
138  return { m_pos };
139 }
140 
141 
142 bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const
143 {
144  return m_pos == aPosition;
145 }
146 
147 
148 bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
149 {
150  int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
151 
152  wxPoint dist = aPosition - m_pos;
153 
154  if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
155  return true;
156 
157  return false;
158 }
159 
160 
161 bool SCH_NO_CONNECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
162 {
163  EDA_RECT rect = aRect;
164 
165  rect.Inflate( aAccuracy );
166 
167  if( aContained )
168  return rect.Contains( GetBoundingBox() );
169 
170  return rect.Intersects( GetBoundingBox() );
171 }
172 
173 
174 void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter ) const
175 {
176  int delta = GetSize() / 2;
177  int pX = m_pos.x;
178  int pY = m_pos.y;
179  int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
180 
181  aPlotter->SetCurrentLineWidth( penWidth );
182  aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT ) );
183  aPlotter->MoveTo( wxPoint( pX - delta, pY - delta ) );
184  aPlotter->FinishTo( wxPoint( pX + delta, pY + delta ) );
185  aPlotter->MoveTo( wxPoint( pX + delta, pY - delta ) );
186  aPlotter->FinishTo( wxPoint( pX - delta, pY + delta ) );
187 }
188 
189 
191 {
192  return BITMAPS::noconn;
193 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
int GetPenWidth() const override
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
wxPoint m_pos
Position of the no connect object.
int color
Definition: DXF_plotter.cpp:57
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:97
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:121
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
SCH_NO_CONNECT(const wxPoint &pos=wxPoint(0, 0))
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:275
int GetSize() const
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:212
wxDC * GetPrintDC() const
#define DEFAULT_NOCONNECT_SIZE
The default junction diameter in mils. (can be changed in preference menu)
virtual void SetColor(const COLOR4D &color)=0
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
Base plotter engine class.
Definition: plotter.h:121
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:156
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
int GetDefaultPenWidth() const
constexpr int delta
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:83
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:193
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
int m_size
Size of the no connect object.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103