KiCad PCB EDA Suite
dialog_sch_sheet_props.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) 2009 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 2014-2019 KiCad Developers, see CHANGELOG.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 #include <dialog_sch_sheet_props.h>
26 
27 #include <wx/string.h>
28 
29 #include <confirm.h>
30 #include <validators.h>
32 
33 #include <widgets/tab_traversal.h>
34 
35 #include <sch_edit_frame.h>
36 #include <sch_sheet.h>
37 
38 
41  m_sheet( aSheet ),
42  m_filenameTextSize( parent, m_filenameSizeLabel, m_filenameSizeCtrl, m_filenameSizeUnits, true ),
43  m_sheetnameTextSize( parent, m_sheetnameSizeLabel, m_sheetnameSizeCtrl, m_sheetnameSizeUnits, true )
44 {
46  m_textFileName->SetFocus();
47  m_sdbSizer1OK->SetDefault();
48 
49  // Normally, the file and sheet name are the "main" edited fields
50  // so put them first
56  } );
57 
59 
60  // Now all widgets have the size fixed, call FinishDialogSettings
62 
63  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier
64  * versions for the flex grid sizer in wxGTK that prevents the last
65  * column from being sized correctly. It doesn't cause any problems
66  * on win32 so it doesn't need to wrapped in ugly #ifdef __WXGTK__
67  * #endif.
68  * Still present in wxWidgets 3.0.2
69  */
70  Layout();
71  Fit();
72  SetMinSize( GetSize() );
73  GetSizer()->Fit( this );
74 }
75 
76 
78 {
79  // Filenames are stored using unix notation
80  wxString fname = m_sheet->GetFileName();
81 
82 #ifdef __WINDOWS__
83  fname.Replace( wxT("/"), wxT("\\") );
84 #endif
85  m_textFileName->SetValue( fname );
86 
87  m_textSheetName->SetValue( m_sheet->GetName() );
88 
91 
92  auto tstamp = wxString::Format( wxT( "%8.8lX" ), (unsigned long) m_sheet->GetTimeStamp() );
93  m_textCtrlTimeStamp->SetValue( tstamp );
94 
95  return true;
96 }
97 
98 
100 {
101  wxFileName fileName = GetFileName();
102  fileName.SetExt( SchematicFileExtension );
103 
104  if( !fileName.IsOk() )
105  {
106  DisplayError( this, _( "File name is not valid!" ) );
107  return false;
108  }
109 
110  // Duplicate sheet names are not valid.
111  SCH_SHEET_LIST hierarchy( g_RootSheet );
112  const SCH_SHEET* sheet = hierarchy.FindSheetByName( GetSheetName() );
113 
114  if( sheet && (sheet != m_sheet) )
115  {
116  DisplayError( this, wxString::Format( _( "A sheet named \"%s\" already exists." ),
117  GetSheetName() ) );
118  return false;
119  }
120 
121  return true;
122 }
123 
124 
126 {
127  // Filenames are stored using unix notation
128  wxString fname = m_textFileName->GetValue();
129  fname.Replace( wxT("\\"), wxT("/") );
130  return fname;
131 }
Class SCH_SHEET_LIST.
Functions for manipulating tab traversal in forms and dialogs.
SCH_SHEET * FindSheetByName(const wxString &aSheetName)
Function FindSheetByName.
This file is part of the common library.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetControlsTabOrder(const std::vector< wxWindow * > &aControlsInTabOrder)
Set a list of controls to have a defined sequential tab order.
Schematic editor (Eeschema) main window.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:118
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:76
int GetFileNameSize() const
Definition: sch_sheet.h:268
int GetSheetNameSize() const
Definition: sch_sheet.h:265
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
wxString GetName() const
Definition: sch_sheet.h:262
const std::string SchematicFileExtension
Definition of file extensions used in Kicad.
timestamp_t GetTimeStamp() const
Definition: base_struct.h:216
bool TransferDataFromWindow() override
DIALOG_SCH_SHEET_PROPS(SCH_EDIT_FRAME *parent, SCH_SHEET *aSheet)
Constructor.
#define _(s)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:204
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:629
Class DIALOG_SCH_SHEET_PROPS_BASE.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:243
Custom text control validator definitions.