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-2018 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 <wx/string.h>
26 #include <sch_edit_frame.h>
27 #include <dialog_sch_sheet_props.h>
28 #include <validators.h>
30 #include <confirm.h>
31 
34  m_sheet( aSheet ),
35  m_filenameTextSize( parent, m_filenameSizeLabel, m_filenameSizeCtrl, m_filenameSizeUnits, true ),
36  m_sheetnameTextSize( parent, m_sheetnameSizeLabel, m_sheetnameSizeCtrl, m_sheetnameSizeUnits, true )
37 {
39  m_textFileName->SetFocus();
40  m_sdbSizer1OK->SetDefault();
41 
42  // Now all widgets have the size fixed, call FinishDialogSettings
44 
45  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier
46  * versions for the flex grid sizer in wxGTK that prevents the last
47  * column from being sized correctly. It doesn't cause any problems
48  * on win32 so it doesn't need to wrapped in ugly #ifdef __WXGTK__
49  * #endif.
50  * Still present in wxWidgets 3.0.2
51  */
52  Layout();
53  Fit();
54  SetMinSize( GetSize() );
55  GetSizer()->Fit( this );
56 }
57 
58 
60 {
61  // Filenames are stored using unix notation
62  wxString fname = m_sheet->GetFileName();
63 
64 #ifdef __WINDOWS__
65  fname.Replace( wxT("/"), wxT("\\") );
66 #endif
67  m_textFileName->SetValue( fname );
68 
69  m_textSheetName->SetValue( m_sheet->GetName() );
70 
73 
74  auto tstamp = wxString::Format( wxT( "%8.8lX" ), (unsigned long) m_sheet->GetTimeStamp() );
75  m_textCtrlTimeStamp->SetValue( tstamp );
76 
77  return true;
78 }
79 
80 
82 {
83  wxFileName fileName = GetFileName();
84  fileName.SetExt( SchematicFileExtension );
85 
86  if( !fileName.IsOk() )
87  {
88  DisplayError( this, _( "File name is not valid!" ) );
89  return false;
90  }
91 
92  // Duplicate sheet names are not valid.
93  SCH_SHEET_LIST hierarchy( g_RootSheet );
94  const SCH_SHEET* sheet = hierarchy.FindSheetByName( GetSheetName() );
95 
96  if( sheet && (sheet != m_sheet) )
97  {
98  DisplayError( this, wxString::Format( _( "A sheet named \"%s\" already exists." ),
99  GetSheetName() ) );
100  return false;
101  }
102 
103  return true;
104 }
105 
106 
108 {
109  // Filenames are stored using unix notation
110  wxString fname = m_textFileName->GetValue();
111  fname.Replace( wxT("\\"), wxT("/") );
112  return fname;
113 }
Class SCH_SHEET_LIST.
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...
Schematic editor (Eeschema) main window.
Class FILE_NAME_WITH_PATH_CHAR_VALIDATOR.
Definition: validators.h:78
int GetSheetNameSize() const
Definition: sch_sheet.h:271
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
const std::string SchematicFileExtension
The common library.
bool TransferDataFromWindow() override
int GetFileNameSize() const
Definition: sch_sheet.h:275
DIALOG_SCH_SHEET_PROPS(SCH_EDIT_FRAME *parent, SCH_SHEET *aSheet)
Constructor.
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:661
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
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...
wxString GetName() const
Definition: sch_sheet.h:267
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
Custom text control validator definitions.
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207