KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_target_properties.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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <pcb_edit_frame.h>
27#include <base_units.h>
28#include <board_commit.h>
29#include <pcb_target.h>
31#include <widgets/unit_binder.h>
32
33
51
52
54{
55 DIALOG_TARGET_PROPERTIES dialog( this, aTarget );
56
57 dialog.ShowModal();
58}
59
60
63 m_Parent( aParent ),
64 m_Target( aTarget ),
67{
69
71
72 // Now all widgets have the size fixed, call FinishDialogSettings
74}
75
76
78{
79 m_Size.SetValue( m_Target->GetSize() );
80 m_Thickness.SetValue( m_Target->GetWidth() );
81
82 m_TargetShape->SetSelection( m_Target->GetShape() ? 1 : 0 );
83
84 return true;
85}
86
87
89{
90 // Zero-size targets are hard to see/select.
91 if( !m_Size.Validate( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 1 ), INT_MAX ) )
92 return false;
93
94 BOARD_COMMIT commit( m_Parent );
95 commit.Modify( m_Target );
96
97 // Save old item in undo list, if it's not currently edited (will be later if so)
98 bool pushCommit = ( m_Target->GetEditFlags() == 0 );
99
100 if( m_Target->GetEditFlags() != 0 ) // other edit in progress (MOVE, NEW ..)
101 m_Target->SetFlags( IN_EDIT ); // set flag IN_EDIT to force
102 // undo/redo/abort proper operation
103
104 m_Target->SetWidth( m_Thickness.GetIntValue() );
105 m_Target->SetSize( m_Size.GetIntValue() );
106 m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
107
108 if( pushCommit )
109 commit.Push( _( "Edit Alignment Target" ) );
110
111 return true;
112}
113
114
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:82
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
DIALOG_TARGET_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Target Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_TARGET_PROPERTIES(PCB_EDIT_FRAME *aParent, PCB_TARGET *aTarget)
The main frame for Pcbnew.
void ShowTargetOptionsDialog(PCB_TARGET *aTarget)
#define _(s)
#define IN_EDIT
Item currently edited.
constexpr int Mils2IU(const EDA_IU_SCALE &aIuScale, int mils)
Definition eda_units.h:166