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#include <tool/tool_manager.h>
30#include <tool/actions.h>
31#include "teardrop.h"
33#include <widgets/unit_binder.h>
34
35
36// Curved shapes options. The actual value is the ORed of options
37#define CURVED_OPTION_NONE 0 /* No curved teardrop shape */
38#define CURVED_OPTION_ROUND 1 /* Curved teardrop shape for vias and round pad shapes */
39#define CURVED_OPTION_RECT 2 /* Curved teardrop shape for rect pad shapes */
40#define CURVED_OPTION_TRACK 4 /* Curved teardrop shape for track to track shapes */
41
43{
44public:
46 TEARDROP_DIALOG_BASE( aParent ),
47 m_brdSettings( nullptr ),
48 m_frame( aParent ),
55 {
56 // Setup actual bitmaps that cannot be set inside wxFormBuilder:
60
63
64 m_cbPadVia->SetValue( prmsList->m_TargetViasPads );
65 m_cbSmdSimilarPads->SetValue( prmsList->m_TargetPadsWithNoHole );
66 m_cbRoundShapesOnly->SetValue( prmsList->m_UseRoundShapesOnly );
67 m_cbTrack2Track->SetValue( prmsList->m_TargetTrack2Track );
68 m_cbPadsInZones->SetValue( prmsList->m_TdOnPadsInZones );
69
70 m_cbOptUseNextTrack->SetValue( prmsList->m_AllowUseTwoTracks );
71 m_spPointCount->SetValue( prmsList->m_CurveSegCount );
72
76 m_spTeardropLenPercentRound->SetValue( prms->m_LengthRatio*100 );
77 m_spTeardropSizePercentRound->SetValue( prms->m_HeightRatio*100 );
78 m_rbShapeRound->SetSelection( prms->IsCurved() );
80
81 prms = prmsList->GetParameters( TARGET_RECT );
84 m_spTeardropLenPercentRect->SetValue( prms->m_LengthRatio*100 );
85 m_spTeardropSizePercentRect->SetValue( prms->m_HeightRatio*100 );
86 m_rbShapeRect->SetSelection( prms->IsCurved() );
88
89 prms = prmsList->GetParameters( TARGET_TRACK );
92 m_spTeardropLenPercentTrack->SetValue( prms->m_LengthRatio*100 );
93 m_spTeardropSizePercentTrack->SetValue( prms->m_HeightRatio*100 );
94 m_rbShapeTrack->SetSelection( prms->IsCurved() );
96
97 // recalculate sizers, now the bitmap is initialized
99 }
100
102 {
104 }
105
110 {
111 int shape_seg_count = GetCurvePointCount();
113
114 prmsList->m_TargetViasPads = m_cbPadVia->GetValue();
115 prmsList->m_TargetPadsWithNoHole = m_cbSmdSimilarPads->GetValue();
116 prmsList->m_UseRoundShapesOnly = m_cbRoundShapesOnly->GetValue();
117 prmsList->m_TargetTrack2Track = m_cbTrack2Track->GetValue();
118 prmsList->m_TdOnPadsInZones = m_cbPadsInZones->GetValue();
119
120 prmsList->m_AllowUseTwoTracks = m_cbOptUseNextTrack->GetValue();
121 prmsList->m_CurveSegCount = m_spPointCount->GetValue();
122
128 prms->m_CurveSegCount = (CurvedShapeOption() & CURVED_OPTION_ROUND) ? shape_seg_count : 0;
129 prms->m_WidthtoSizeFilterRatio = m_spTeardropHDPercentRound->GetValue() / 100.0;
130
131 prms = prmsList->GetParameters( TARGET_RECT );
136 prms->m_CurveSegCount = (CurvedShapeOption() & CURVED_OPTION_RECT) ? shape_seg_count : 0;
137 prms->m_WidthtoSizeFilterRatio = m_spTeardropHDPercentRect->GetValue() / 100.0;
138
139 prms = prmsList->GetParameters( TARGET_TRACK );
144 prms->m_CurveSegCount = (CurvedShapeOption() & CURVED_OPTION_TRACK) ? shape_seg_count : 0;
145 prms->m_WidthtoSizeFilterRatio = m_spTeardropHDPercentTrack->GetValue() / 100.0;
146 }
147
149 {
150 int opt = 0;
151
152 if( m_rbShapeRound->GetSelection() )
153 opt |= CURVED_OPTION_ROUND;
154
155 if( m_rbShapeRect->GetSelection() )
156 opt |= CURVED_OPTION_RECT;
157
158 if( m_rbShapeTrack->GetSelection() )
159 opt |= CURVED_OPTION_TRACK;
160
161 return opt;
162 }
163
164 // Options for curved shapes
165 int GetCurvePointCount() { return m_spPointCount->GetValue(); }
166
167 // Getters for size parameters
168 double GetTeardropLenPercentRound() { return m_spTeardropLenPercentRound->GetValue()/100.0; }
169 double GetTeardropSizePercentRound() { return m_spTeardropSizePercentRound->GetValue()/100.0; }
172
173 double GetTeardropLenPercentRect() { return m_spTeardropLenPercentRect->GetValue()/100.0; }
174 double GetTeardropSizePercentRect() { return m_spTeardropSizePercentRect->GetValue()/100.0; }
177
178 double GetTeardropLenPercentTrack() { return m_spTeardropLenPercentTrack->GetValue()/100.0; }
179 double GetTeardropSizePercentTrack() { return m_spTeardropSizePercentTrack->GetValue()/100.0; }
182
183 // Optins to filter pads
184 bool TeardropOnPadVia() { return m_cbPadVia->GetValue(); }
185 bool IncludeNotPTH() { return m_cbSmdSimilarPads->GetValue(); }
186 bool RoundShapesOnly() { return m_cbRoundShapesOnly->GetValue(); }
187
188 bool CanUseTwoTracks() { return m_cbOptUseNextTrack->GetValue(); }
189
190 bool TeardropOnTracks() { return m_cbTrack2Track->GetValue(); }
191
192private:
201};
202
203
204void PCB_EDIT_FRAME::OnRunTeardropTool( wxCommandEvent& event )
205{
206 TEARDROP_DIALOG dlg( this );
207
208 if( dlg.ShowModal() != wxID_OK )
209 return;
210
211 wxBusyCursor dummy;
212
213 BOARD_COMMIT committer( this );
214
216 TEARDROP_MANAGER trdm( GetBoard(), this );
217
218 int added_count = trdm.SetTeardrops( &committer, dlg.CanUseTwoTracks() );
219
221
224 m_infoBar->ShowMessageFor( wxString::Format( _( "%d teardrops created" ), added_count ),
225 1000, wxICON_EXCLAMATION );
226}
227
228
229void PCB_EDIT_FRAME::OnRemoveTeardropTool( wxCommandEvent& event )
230{
231 BOARD_COMMIT committer( this );
232 TEARDROP_MANAGER trdm( GetBoard(), this );
233
234 int count = trdm.RemoveTeardrops( &committer, true );
235
237 GetCanvas()->Refresh();
239
242 m_infoBar->ShowMessageFor( wxString::Format( _( "%d teardrops removed." ), count ),
243 1000, wxICON_EXCLAMATION );
244}
245
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:43
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:686
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
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:213
static const TOOL_EVENT ConnectivityChangedEvent
Selected item had a property changed (except movement)
Definition: actions.h:210
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
void RedrawRatsnest()
Return the bounding box of the view that should be used if model is not valid.
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.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
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: wx_infobar.cpp:289
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: wx_infobar.cpp:128
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:279
#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
std::vector< FAB_LAYER_COLOR > dummy
@ TARGET_ROUND
@ TARGET_RECT
@ TARGET_TRACK