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 <fctsys.h>
27 #include <pcb_edit_frame.h>
28 #include <dialog_helpers.h>
29 #include <base_units.h>
30 #include <gr_basic.h>
31 #include <board_commit.h>
32 #include <class_board.h>
33 #include <class_pcb_target.h>
34 #include <pcbnew.h>
36 #include <widgets/unit_binder.h>
37 
38 
40 {
41 private:
44 
47 
48 public:
51 
52 private:
53  bool TransferDataToWindow() override;
54  bool TransferDataFromWindow() override;
55 };
56 
57 
59 {
60  DIALOG_TARGET_PROPERTIES dialog( this, aTarget );
61 
62  dialog.ShowModal();
63 }
64 
65 
68  m_Parent( aParent ),
69  m_Target( aTarget ),
70  m_Size( aParent, m_sizeLabel, m_sizeCtrl, m_sizeUnits, true ),
71  m_Thickness( aParent, m_thicknessLabel, m_thicknessCtrl, m_thicknessUnits, true )
72 {
73  m_sdbSizerButtsOK->SetDefault();
74 
76 
77  // Now all widgets have the size fixed, call FinishDialogSettings
79 }
80 
81 
83 {
86 
87  m_TargetShape->SetSelection( m_Target->GetShape() ? 1 : 0 );
88 
89  return true;
90 }
91 
92 
94 {
95  // Zero-size targets are hard to see/select.
96  if( !m_Size.Validate( Mils2iu( 1 ), INT_MAX ) )
97  return false;
98 
99  BOARD_COMMIT commit( m_Parent );
100  commit.Modify( m_Target );
101 
102  // Save old item in undo list, if is is not currently edited (will be later if so)
103  bool pushCommit = ( m_Target->GetEditFlags() == 0 );
104 
105  if( m_Target->GetEditFlags() != 0 ) // other edit in progress (MOVE, NEW ..)
106  m_Target->SetFlags( IN_EDIT ); // set flag in edit to force
107  // undo/redo/abort proper operation
108 
111  m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
112 
113  if( pushCommit )
114  commit.Push( _( "Modified alignment target" ) );
115 
116  return true;
117 }
118 
119 
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:118
Class DIALOG_TARGET_PROPERTIES_BASE.
Implementation of conversion functions that require both schematic and board internal units.
void SetSize(int aSize)
int GetSize() const
virtual bool Validate(int aMin, int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
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:118
DIALOG_TARGET_PROPERTIES(PCB_EDIT_FRAME *aParent, PCB_TARGET *aTarget)
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
int GetWidth() const
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:265
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:269
Helper dialog and control classes.
void SetShape(int aShape)
#define _(s)
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
int GetShape() const
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
void SetWidth(int aWidth)
PCB_TARGET class definition.