KiCad PCB EDA Suite
dialog_teardrop.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) 2021 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2021-2022 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
25
27#include <board_commit.h>
28#include <bitmaps.h>
29
30#include "teardrop.h"
32#include <widgets/unit_binder.h>
33
34
35// Curved shapes options. The actual value is the ORed of options
36#define CURVED_OPTION_NONE 0 /* No curved teardrop shape */
37#define CURVED_OPTION_ROUND 1 /* Curved teardrop shape for vias and round pad shapes */
38#define CURVED_OPTION_RECT 2 /* Curved teardrop shape for rect pad shapes */
39#define CURVED_OPTION_TRACK 4 /* Curved teardrop shape for track to track shapes */
40
42{
43public:
45 TEARDROP_DIALOG_BASE( aParent ),
46 m_brdSettings( nullptr ),
47 m_frame( aParent ),
54 {
55 // Setup actual bitmaps that cannot be set inside wxFormBuilder:
59
62
63 m_cbPadVia->SetValue( prmsList->m_TargetViasPads );
64 m_cbSmdSimilarPads->SetValue( prmsList->m_TargetPadsWithNoHole );
65 m_cbRoundShapesOnly->SetValue( prmsList->m_UseRoundShapesOnly );
66 m_cbTrack2Track->SetValue( prmsList->m_TargetTrack2Track );
67 m_cbPadsInZones->SetValue( prmsList->m_TdOnPadsInZones );
68
69 m_cbOptUseNextTrack->SetValue( prmsList->m_AllowUseTwoTracks );
70 m_spPointCount->SetValue( prmsList->m_CurveSegCount );
71
75 m_spTeardropLenPercentRound->SetValue( prms->m_LengthRatio*100 );
76 m_spTeardropSizePercentRound->SetValue( prms->m_HeightRatio*100 );
77 m_rbShapeRound->SetSelection( prms->IsCurved() );
79
80 prms = prmsList->GetParameters( TARGET_RECT );
83 m_spTeardropLenPercentRect->SetValue( prms->m_LengthRatio*100 );
84 m_spTeardropSizePercentRect->SetValue( prms->m_HeightRatio*100 );
85 m_rbShapeRect->SetSelection( prms->IsCurved() );
87
88 prms = prmsList->GetParameters( TARGET_TRACK );
91 m_spTeardropLenPercentTrack->SetValue( prms->m_LengthRatio*100 );
92 m_spTeardropSizePercentTrack->SetValue( prms->m_HeightRatio*100 );
93 m_rbShapeTrack->SetSelection( prms->IsCurved() );
95
96 // recalculate sizers, now the bitmap is initialized
98 }
99
101 {
103 }
104
109 {
110 int shape_seg_count = GetCurvePointCount();
112
113 prmsList->m_TargetViasPads = m_cbPadVia->GetValue();
114 prmsList->m_TargetPadsWithNoHole = m_cbSmdSimilarPads->GetValue();
115 prmsList->m_UseRoundShapesOnly = m_cbRoundShapesOnly->GetValue();
116 prmsList->m_TargetTrack2Track = m_cbTrack2Track->GetValue();
117 prmsList->m_TdOnPadsInZones = m_cbPadsInZones->GetValue();
118
119 prmsList->m_AllowUseTwoTracks = m_cbOptUseNextTrack->GetValue();
120 prmsList->m_CurveSegCount = m_spPointCount->GetValue();
121
127 prms->m_CurveSegCount = (CurvedShapeOption() & CURVED_OPTION_ROUND) ? shape_seg_count : 0;
128 prms->m_WidthtoSizeFilterRatio = m_spTeardropHDPercentRound->GetValue() / 100.0;
129
130 prms = prmsList->GetParameters( TARGET_RECT );
135 prms->m_CurveSegCount = (CurvedShapeOption() & CURVED_OPTION_RECT) ? shape_seg_count : 0;
136 prms->m_WidthtoSizeFilterRatio = m_spTeardropHDPercentRect->GetValue() / 100.0;
137
138 prms = prmsList->GetParameters( TARGET_TRACK );
143 prms->m_CurveSegCount = (CurvedShapeOption() & CURVED_OPTION_TRACK) ? shape_seg_count : 0;
144 prms->m_WidthtoSizeFilterRatio = m_spTeardropHDPercentTrack->GetValue() / 100.0;
145 }
146
148 {
149 int opt = 0;
150
151 if( m_rbShapeRound->GetSelection() )
152 opt |= CURVED_OPTION_ROUND;
153
154 if( m_rbShapeRect->GetSelection() )
155 opt |= CURVED_OPTION_RECT;
156
157 if( m_rbShapeTrack->GetSelection() )
158 opt |= CURVED_OPTION_TRACK;
159
160 return opt;
161 }
162
163 // Options for curved shapes
164 int GetCurvePointCount() { return m_spPointCount->GetValue(); }
165
166 // Getters for size parameters
167 double GetTeardropLenPercentRound() { return m_spTeardropLenPercentRound->GetValue()/100.0; }
168 double GetTeardropSizePercentRound() { return m_spTeardropSizePercentRound->GetValue()/100.0; }
171
172 double GetTeardropLenPercentRect() { return m_spTeardropLenPercentRect->GetValue()/100.0; }
173 double GetTeardropSizePercentRect() { return m_spTeardropSizePercentRect->GetValue()/100.0; }
176
177 double GetTeardropLenPercentTrack() { return m_spTeardropLenPercentTrack->GetValue()/100.0; }
178 double GetTeardropSizePercentTrack() { return m_spTeardropSizePercentTrack->GetValue()/100.0; }
181
182 // Optins to filter pads
183 bool TeardropOnPadVia() { return m_cbPadVia->GetValue(); }
184 bool IncludeNotPTH() { return m_cbSmdSimilarPads->GetValue(); }
185 bool RoundShapesOnly() { return m_cbRoundShapesOnly->GetValue(); }
186
187 bool CanUseTwoTracks() { return m_cbOptUseNextTrack->GetValue(); }
188
189 bool TeardropOnTracks() { return m_cbTrack2Track->GetValue(); }
190
191private:
200};
201
202
203void PCB_EDIT_FRAME::OnRunTeardropTool( wxCommandEvent& event )
204{
205 TEARDROP_DIALOG dlg( this );
206
207 if( dlg.ShowModal() != wxID_OK )
208 return;
209
210 wxBusyCursor dummy;
211
212 BOARD_COMMIT committer( this );
213
215 TEARDROP_MANAGER trdm( GetBoard(), this );
216
217 int added_count = trdm.SetTeardrops( &committer, dlg.CanUseTwoTracks() );
218
221 m_infoBar->ShowMessageFor( wxString::Format( _( "%d Teardrops created" ), added_count ),
222 1000, wxICON_EXCLAMATION );
223}
224
225
226void PCB_EDIT_FRAME::OnRemoveTeardropTool( wxCommandEvent& event )
227{
228 BOARD_COMMIT committer( this );
229 TEARDROP_MANAGER trdm( GetBoard(), this );
230
231 int count = trdm.RemoveTeardrops( &committer, true );
232
235 m_infoBar->ShowMessageFor( wxString::Format( _( "%d Teardrops removed." ), count ),
236 1000, wxICON_EXCLAMATION );
237}
238
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
@ teardrop_track_sizes
@ teardrop_rect_sizes
@ teardrop_sizes
Container for design settings for a BOARD object.
TEARDROP_PARAMETERS_LIST * GetTeadropParamsList()
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:37
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:617
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
WX_INFOBAR * m_infoBar
BOARD * GetBoard() const
The main frame for Pcbnew.
void OnRunTeardropTool(wxCommandEvent &event)
run teardrop tool
void OnRemoveTeardropTool(wxCommandEvent &event)
Remove all teardrops.
Class TEARDROP_DIALOG_BASE.
wxSpinCtrlDouble * m_spTeardropHDPercentRect
wxStaticText * m_stMaxLenRound
wxStaticBitmap * m_bitmapTdTrackInfo
wxSpinCtrlDouble * m_spTeardropSizePercentRect
wxStaticText * m_stMaxLenRect
wxStaticText * m_stMaxLenTrackUnits
wxStaticText * m_stMaxHeightTrackUnits
wxStaticText * m_stMaxHeightRoundUnits
wxStaticText * m_stMaxLenTrack
wxStaticText * m_stMaxLenRectUnits
wxSpinCtrlDouble * m_spTeardropLenPercentRect
wxStaticText * m_stTdMaxSizeRound
wxSpinCtrlDouble * m_spTeardropHDPercentRound
wxStaticText * m_stMaxHeightRectUnits
wxSpinCtrlDouble * m_spTeardropLenPercentTrack
wxStaticText * m_stTdMaxSizeRect
wxSpinCtrlDouble * m_spTeardropSizePercentRound
wxSpinCtrlDouble * m_spTeardropSizePercentTrack
wxStaticBitmap * m_bitmapTdCircularInfo
wxStaticBitmap * m_bitmapTdRectangularInfo
wxStaticText * m_stMaxLenRoundUnits
wxStaticText * m_stTdMaxSizeTrack
wxSpinCtrlDouble * m_spTeardropLenPercentRound
wxSpinCtrlDouble * m_spTeardropHDPercentTrack
UNIT_BINDER m_teardropMaxHeightSettingRound
double GetTeardropSizePercentRect()
UNIT_BINDER m_teardropMaxLenSettingRound
TEARDROP_DIALOG(PCB_EDIT_FRAME *aParent)
UNIT_BINDER m_teardropMaxLenSettingRect
void TransferToParamList()
Copy the settings from dialog to the current board settings.
double GetTeardropLenPercentRect()
double GetTeardropLenPercentRound()
UNIT_BINDER m_teardropMaxHeightSettingTrack
double GetTeardropLenPercentTrack()
UNIT_BINDER m_teardropMaxHeightSettingRect
BOARD_DESIGN_SETTINGS * m_brdSettings
UNIT_BINDER m_teardropMaxLenSettingTrack
PCB_EDIT_FRAME * m_frame
double GetTeardropSizePercentTrack()
double GetTeardropSizePercentRound()
TEARDROP_MANAGER manage and build teardrop areas A teardrop area is a polygonal area (a copper ZONE) ...
Definition: teardrop.h:80
int SetTeardrops(BOARD_COMMIT *aCommitter, bool aFollowTracks=true)
Set teardrops on a teardrop free board.
Definition: teardrop.cpp:93
int RemoveTeardrops(BOARD_COMMIT *aCommitter, bool aCommitAfterRemove)
Remove all teardrops.
Definition: teardrop.cpp:410
TEARDROP_PARAMETERS_LIST is a helper class to handle the list of TEARDROP_PARAMETERS needed to build ...
bool m_TargetPadsWithNoHole
True to create teardrops for pads without holes (SMD and others.
int m_CurveSegCount
the number of segments to apprximate a curve (Bezier curve) in a teardrop Must be > 2,...
bool m_TargetViasPads
True to create teardrops for vias and pads with holes.
bool m_UseRoundShapesOnly
True to create teardrops for round shapes only.
bool m_TargetTrack2Track
True to create teardrops at the end of a track connected to the end of another track having a differe...
bool m_TdOnPadsInZones
Pads inside a zone of the same net do not have teardrop added.
bool m_AllowUseTwoTracks
True to create teardrops using 2 track segments if the first in too small.
TEARDROP_PARAMETERS * GetParameters(TARGET_TD aTdType)
TEARDROP_PARAMETARS is a helper class to handle parameters needed to build teardrops for a board thes...
int m_CurveSegCount
number of segments to build the curved sides of a teardrop area must be > 2.
double m_HeightRatio
The height of a teardrop as ratio between height and size of pad/via.
int m_TdMaxHeight
max allowed height for teardrops in IU. <= 0 to disable
int m_TdMaxLen
the type of target for these parameters
double m_WidthtoSizeFilterRatio
The ratio (H/D) between the via/pad size and the track width max value to create a teardrop 1....
double m_LengthRatio
The length of a teardrop as ratio between length and size of pad/via.
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:286
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
Definition: infobar.cpp:128
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:276
#define CURVED_OPTION_TRACK
#define CURVED_OPTION_RECT
#define CURVED_OPTION_ROUND
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
@ TARGET_ROUND
@ TARGET_RECT
@ TARGET_TRACK