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 #include <kiface_i.h>
27 #include <wx/string.h>
28 #include <confirm.h>
29 #include <validators.h>
31 #include <widgets/tab_traversal.h>
32 #include <sch_edit_frame.h>
33 #include <sch_sheet.h>
34 #include <bitmaps.h>
35 
38  m_sheet( aSheet ),
39  m_filenameTextSize( parent, m_filenameSizeLabel, m_filenameSizeCtrl, m_filenameSizeUnits, true ),
40  m_sheetnameTextSize( parent, m_sheetnameSizeLabel, m_sheetnameSizeCtrl, m_sheetnameSizeUnits, true )
41 {
43  m_textFileName->SetFocus();
44  m_sdbSizer1OK->SetDefault();
45 
46  m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
47 
48  // We can't set the tab order through wxWidgets due to shortcomings in their mnemonics
49  // implementation on MSW
50  m_tabOrder = {
58  };
59 
61 
62  // Now all widgets have the size fixed, call FinishDialogSettings
64 
65  /*
66  * This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for the flex
67  * grid sizer in wxGTK that prevents the last column from being sized correctly. It doesn't
68  * appear to cause any problems on other platforms so we don't use conditional compilation.
69  * Still present in wxWidgets 3.0.2
70  */
71  Layout();
72  Fit();
73  SetMinSize( GetSize() );
74  GetSizer()->Fit( this );
75 }
76 
77 
79 {
80  // Filenames are stored using unix notation
81  wxString fname = m_sheet->GetFileName();
82 
83 #ifdef __WINDOWS__
84  fname.Replace( wxT("/"), wxT("\\") );
85 #endif
86  m_textFileName->SetValue( fname );
87 
88  m_textSheetName->SetValue( m_sheet->GetName() );
89 
92 
93  auto tstamp = wxString::Format( wxT( "%8.8lX" ), (unsigned long) m_sheet->GetTimeStamp() );
94  m_textCtrlTimeStamp->SetValue( tstamp );
95 
96  return true;
97 }
98 
99 
101 {
102  wxFileName fileName = GetFileName();
103  fileName.SetExt( SchematicFileExtension );
104 
105  if( !fileName.IsOk() )
106  {
107  DisplayError( this, _( "File name is not valid!" ) );
108  return false;
109  }
110 
111  // Duplicate sheet names are not valid.
112  SCH_SHEET_LIST hierarchy( g_RootSheet );
113  const SCH_SHEET* sheet = hierarchy.FindSheetByName( GetSheetName() );
114 
115  if( sheet && (sheet != m_sheet) )
116  {
117  DisplayError( this, wxString::Format( _( "A sheet named \"%s\" already exists." ),
118  GetSheetName() ) );
119  return false;
120  }
121 
122  return true;
123 }
124 
125 
126 void DIALOG_SCH_SHEET_PROPS::OnBrowseClicked( wxCommandEvent& event )
127 {
128  // Build the absolute path of current sheet to preselect it when opening the dialog.
129  wxString path = Prj().AbsolutePath( m_textFileName->GetValue() );
130  wxFileName fn( path );
131 
132  wxFileDialog fileDialog( this, _( "Sheet File" ), fn.GetPath(), fn.GetFullName(),
133  SchematicFileExtension, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
134 
135  if( fileDialog.ShowModal() == wxID_OK )
136  {
137  fn.Assign( fileDialog.GetPath() );
138  fn.MakeRelativeTo( Prj().GetProjectPath() );
139 
140  m_textFileName->ChangeValue( fn.GetFullPath() );
141  }
142 }
143 
144 
146 {
147  // Filenames are stored using unix notation
148  wxString fname = m_textFileName->GetValue();
149  fname.Replace( wxT("\\"), wxT("/") );
150  return fname;
151 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:236
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.
std::vector< wxWindow * > m_tabOrder
Definition: dialog_shim.h:199
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.
void OnBrowseClicked(wxCommandEvent &event) override
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
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolu...
Definition: project.cpp:385
int GetFileNameSize() const
Definition: sch_sheet.h:278
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
int GetSheetNameSize() const
Definition: sch_sheet.h:275
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
wxString GetName() const
Definition: sch_sheet.h:272
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
const std::string SchematicFileExtension
Definition of file extensions used in Kicad.
timestamp_t GetTimeStamp() const
Definition: base_struct.h:216
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:209
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:646
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...
Custom text control validator definitions.