KiCad PCB EDA Suite
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 (C) 1992-2019 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 <dialog_helpers.h>
28 #include <base_units.h>
29 #include <board_commit.h>
30 #include <board.h>
31 #include <pcb_target.h>
33 #include <widgets/unit_binder.h>
34 
35 
37 {
38 private:
41 
44 
45 public:
48 
49 private:
50  bool TransferDataToWindow() override;
51  bool TransferDataFromWindow() override;
52 };
53 
54 
56 {
57  DIALOG_TARGET_PROPERTIES dialog( this, aTarget );
58 
59  dialog.ShowModal();
60 }
61 
62 
65  m_Parent( aParent ),
66  m_Target( aTarget ),
67  m_Size( aParent, m_sizeLabel, m_sizeCtrl, m_sizeUnits ),
68  m_Thickness( aParent, m_thicknessLabel, m_thicknessCtrl, m_thicknessUnits )
69 {
70  m_sdbSizerButtsOK->SetDefault();
71 
73 
74  // Now all widgets have the size fixed, call FinishDialogSettings
76 }
77 
78 
80 {
83 
84  m_TargetShape->SetSelection( m_Target->GetShape() ? 1 : 0 );
85 
86  return true;
87 }
88 
89 
91 {
92  // Zero-size targets are hard to see/select.
93  if( !m_Size.Validate( Mils2iu( 1 ), INT_MAX ) )
94  return false;
95 
96  BOARD_COMMIT commit( m_Parent );
97  commit.Modify( m_Target );
98 
99  // Save old item in undo list, if is is not currently edited (will be later if so)
100  bool pushCommit = ( m_Target->GetEditFlags() == 0 );
101 
102  if( m_Target->GetEditFlags() != 0 ) // other edit in progress (MOVE, NEW ..)
103  m_Target->SetFlags( IN_EDIT ); // set flag in edit to force
104  // undo/redo/abort proper operation
105 
108  m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
109 
110  if( pushCommit )
111  commit.Push( _( "Modified alignment target" ) );
112 
113  return true;
114 }
115 
116 
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
Class DIALOG_TARGET_PROPERTIES_BASE.
Implementation of conversion functions that require both schematic and board internal units.
void SetSize(int aSize)
Definition: pcb_target.h:61
int GetSize() const
Definition: pcb_target.h:62
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
void ShowTargetOptionsDialog(PCB_TARGET *aTarget)
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
DIALOG_TARGET_PROPERTIES(PCB_EDIT_FRAME *aParent, PCB_TARGET *aTarget)
int GetWidth() const
Definition: pcb_target.h:65
Helper dialog and control classes.
#define _(s)
void SetShape(int aShape)
Definition: pcb_target.h:58
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:158
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
int GetShape() const
Definition: pcb_target.h:59
The main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
virtual long long int GetValue()
Return the current value in Internal Units.
void SetWidth(int aWidth)
Definition: pcb_target.h:64
#define IN_EDIT
Item currently edited.