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 
37 
40  m_sheet( aSheet ),
41  m_filenameTextSize( parent, m_filenameSizeLabel, m_filenameSizeCtrl, m_filenameSizeUnits, true ),
42  m_sheetnameTextSize( parent, m_sheetnameSizeLabel, m_sheetnameSizeCtrl, m_sheetnameSizeUnits, true )
43 {
45  m_textFileName->SetFocus();
46  m_sdbSizer1OK->SetDefault();
47 
48  // Normally, the file and sheet name are the "main" edited fields
49  // so put them first
55  } );
56 
58 
59  // Now all widgets have the size fixed, call FinishDialogSettings
61 
62  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier
63  * versions for the flex grid sizer in wxGTK that prevents the last
64  * column from being sized correctly. It doesn't cause any problems
65  * on win32 so it doesn't need to wrapped in ugly #ifdef __WXGTK__
66  * #endif.
67  * Still present in wxWidgets 3.0.2
68  */
69  Layout();
70  Fit();
71  SetMinSize( GetSize() );
72  GetSizer()->Fit( this );
73 }
74 
75 
77 {
78  // Filenames are stored using unix notation
79  wxString fname = m_sheet->GetFileName();
80 
81 #ifdef __WINDOWS__
82  fname.Replace( wxT("/"), wxT("\\") );
83 #endif
84  m_textFileName->SetValue( fname );
85 
86  m_textSheetName->SetValue( m_sheet->GetName() );
87 
90 
91  auto tstamp = wxString::Format( wxT( "%8.8lX" ), (unsigned long) m_sheet->GetTimeStamp() );
92  m_textCtrlTimeStamp->SetValue( tstamp );
93 
94  return true;
95 }
96 
97 
99 {
100  wxFileName fileName = GetFileName();
101  fileName.SetExt( SchematicFileExtension );
102 
103  if( !fileName.IsOk() )
104  {
105  DisplayError( this, _( "File name is not valid!" ) );
106  return false;
107  }
108 
109  // Duplicate sheet names are not valid.
110  SCH_SHEET_LIST hierarchy( g_RootSheet );
111  const SCH_SHEET* sheet = hierarchy.FindSheetByName( GetSheetName() );
112 
113  if( sheet && (sheet != m_sheet) )
114  {
115  DisplayError( this, wxString::Format( _( "A sheet named \"%s\" already exists." ),
116  GetSheetName() ) );
117  return false;
118  }
119 
120  return true;
121 }
122 
123 
125 {
126  // Filenames are stored using unix notation
127  wxString fname = m_textFileName->GetValue();
128  fname.Replace( wxT("\\"), wxT("/") );
129  return fname;
130 }
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:116
Class FILE_NAME_WITH_PATH_CHAR_VALIDATOR.
Definition: validators.h:78
int GetFileNameSize() const
Definition: sch_sheet.h:275
int GetSheetNameSize() const
Definition: sch_sheet.h:271
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
wxString GetName() const
Definition: sch_sheet.h:267
const std::string SchematicFileExtension
Definition of file extensions used in Kicad.
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
bool TransferDataFromWindow() override
DIALOG_SCH_SHEET_PROPS(SCH_EDIT_FRAME *parent, SCH_SHEET *aSheet)
Constructor.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:662
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)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:243
Custom text control validator definitions.