NCBI C++ ToolKit
fasta_align_export_page.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: fasta_align_export_page.cpp 39666 2017-10-25 16:01:13Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Vladislav Evgeniev
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>////@begin includes
33 ////@end includes
34 
35 #include <wx/sizer.h>
36 #include <wx/checkbox.h>
37 #include <wx/choice.h>
38 #include <wx/bmpbuttn.h>
39 #include <wx/textctrl.h>
40 #include <wx/stattext.h>
41 #include <wx/valgen.h>
42 #include <wx/valtext.h>
43 #include <wx/msgdlg.h>
44 #include <wx/filedlg.h>
45 #include <wx/bitmap.h>
46 #include <wx/icon.h>
47 #include <wx/artprov.h>
48 #include <wx/stdpaths.h>
49 #include <wx/filename.h>
50 
52 
54 
57 
59 
60 IMPLEMENT_DYNAMIC_CLASS( CFastaAlignExportPage, wxPanel )
61 
62 BEGIN_EVENT_TABLE( CFastaAlignExportPage, wxPanel )
63 
64 ////@begin CFastaAlignExportPage event table entries
66 ////@end CFastaAlignExportPage event table entries
67 
68  EVT_LIST_ITEM_SELECTED(ID_PANEL4, CFastaAlignExportPage::OnObjectSelected)
69 
71 
73  m_FileSelected(false)
74 {
75  Init();
76 }
77 
78 CFastaAlignExportPage::CFastaAlignExportPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) :
79  m_FileSelected(false)
80 {
81  Init();
82  Create(parent, id, pos, size, style);
83 }
84 
85 bool CFastaAlignExportPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
86 {
87 ////@begin CFastaAlignExportPage creation
88  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
89  wxPanel::Create( parent, id, pos, size, style );
90 
92  if (GetSizer())
93  {
94  GetSizer()->SetSizeHints(this);
95  }
96  Centre();
97 ////@end CFastaAlignExportPage creation
98  return true;
99 }
100 
102 {
103 ////@begin CFastaAlignExportPage destruction
104 ////@end CFastaAlignExportPage destruction
105 }
106 
108 {
109 ////@begin CFastaAlignExportPage member initialisation
110  m_ObjectSel = NULL;
111 ////@end CFastaAlignExportPage member initialisation
112 }
113 
115 {
116 ////@begin CFastaAlignExportPage content construction
117  CFastaAlignExportPage* itemPanel1 = this;
118 
119  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
120  itemPanel1->SetSizer(itemBoxSizer2);
121 
122  m_ObjectSel = new CObjectListWidget( itemPanel1, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL|wxLC_SINGLE_SEL );
123  itemBoxSizer2->Add(m_ObjectSel, 1, wxGROW|wxALL, 0);
124 
125  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
126  itemBoxSizer2->Add(itemBoxSizer4, 0, wxGROW|wxALL, 0);
127 
128  wxStaticText* itemStaticText5 = new wxStaticText( itemPanel1, wxID_STATIC, _("File name"), wxDefaultPosition, wxDefaultSize, 0 );
129  itemBoxSizer4->Add(itemStaticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
130 
131  wxTextCtrl* itemTextCtrl6 = new wxTextCtrl( itemPanel1, ID_TEXTCTRL14, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
132  itemBoxSizer4->Add(itemTextCtrl6, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
133 
134  wxBitmapButton* itemBitmapButton7 = new wxBitmapButton( itemPanel1, ID_BITMAPBUTTON, itemPanel1->GetBitmapResource(wxT("menu::open")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
135  itemBitmapButton7->SetHelpText(_("Select File"));
137  itemBitmapButton7->SetToolTip(_("Select File"));
138  itemBoxSizer4->Add(itemBitmapButton7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
139 
140  // Set validators
141  itemTextCtrl6->SetValidator( wxTextValidator(wxFILTER_NONE, & GetData().m_FileName) );
142  // Connect events and objects
143  itemTextCtrl6->Connect(ID_TEXTCTRL14, wxEVT_CHAR, wxKeyEventHandler(CFastaAlignExportPage::OnFileNameEdited), NULL, this);
144 ////@end CFastaAlignExportPage content construction
145 
147 
148  m_SaveFile.reset(new CSaveFileHelper(this, *itemTextCtrl6));
149 }
150 
152 {
153  return true;
154 }
155 wxBitmap CFastaAlignExportPage::GetBitmapResource( const wxString& name )
156 {
157  return wxArtProvider::GetBitmap(name);
158 }
159 wxIcon CFastaAlignExportPage::GetIconResource( const wxString& name )
160 {
161  // Icon retrieval
162 ////@begin CFastaAlignExportPage icon retrieval
163  wxUnusedVar(name);
164  return wxNullIcon;
165 ////@end CFastaAlignExportPage icon retrieval
166 }
167 
169 {
170  if (!wxPanel::TransferDataFromWindow())
171  return false;
172 
175 
176  if (objects.empty()) {
177  wxMessageBox(wxT("Please, select an object to export"), wxT("Error"), wxOK | wxICON_ERROR, this);
178  FindWindow(ID_PANEL4)->SetFocus();
179  return false;
180  }
181 
182  GetData().SetObject() = objects[0];
183 
184  wxString path = GetData().GetFileName();
186  return m_SaveFile->Validate(path);
187 }
188 
189 
191 {
193 
194  if (1 == objects.size())
196 }
197 
198 
200 {
201  const char invalid_file_name_chars[] = { '~', '#', '%', '&', '*', '{', '}', '\\', ':', '<', '>', '?', '/', '+', '|', '"' };
202  for (char c : invalid_file_name_chars)
203  path.erase(std::remove(path.begin(), path.end(), c), path.end());
204  if (path[path.length() - 1] == '.')
205  path = path.substr(0, path.length() - 1);
206 
207 }
208 
209 
211 {
212  if (m_FileSelected)
213  return;
216  if (objects.empty())
217  return;
218 
219  long selected = m_ObjectSel->GetFirstSelected();
220  if (-1 == selected)
221  return;
222 
223  wxString label = m_ObjectSel->GetItemText(selected).ToStdString();
224 
225  if (label.empty())
226  return;
227 
229 
230  wxStandardPaths& standard_paths = wxStandardPaths::Get();
231  wxString path = standard_paths.GetDocumentsDir();
232  path += wxFileName::GetPathSeparator();
233  path += label;
234  path += ".fa";
235  GetData().SetFileName(path);
236  TransferDataToWindow();
237 }
238 
239 
240 static const char* kObjectList = "ObjectList";
241 
243 {
244  m_RegPath = path;
245 }
246 
248 {
249  if (!m_RegPath.empty()) {
251  string reg_path = CGuiRegistryUtil::MakeKey(m_RegPath, kObjectList);
252  CRegistryWriteView table_view = gui_reg.GetWriteView(reg_path);
253  m_ObjectSel->SaveTableSettings(table_view);
254  }
255 }
256 
258 {
259  if (!m_RegPath.empty()) {
261  string reg_path;
262  CRegistryReadView table_view;
263 
265  table_view = gui_reg.GetReadView(reg_path);
266  m_ObjectSel->LoadTableSettings(table_view);
267  }
268 }
269 
270 void CFastaAlignExportPage::OnSelectFileClick( wxCommandEvent& event )
271 {
273  if (m_SaveFile->ShowSaveDialog(CFileExtensions::kFASTA))
274  m_FileSelected = true;
275 }
276 
278 {
279  m_FileSelected = true;
280  event.Skip();
281  }
282 
CFastaAlignExportParams & GetData()
void OnFileNameEdited(wxKeyEvent &event)
void OnSelectFileClick(wxCommandEvent &event)
virtual void SetRegistryPath(const string &path)
IRegSettings.
void SetObjects(TConstScopedObjects &objects)
wxBitmap GetBitmapResource(const wxString &name)
void OnObjectSelected(wxListEvent &event)
wxIcon GetIconResource(const wxString &name)
virtual void SaveSettings() const
bool Create(wxWindow *parent, wxWindowID id=ID_CFASTAALIGNEXPORTPAGE, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
std::unique_ptr< CSaveFileHelper > m_SaveFile
void x_SanitizePath(wxString &path)
SConstScopedObject & SetObject()
static string MakeKey(const string &section, const string &key, const string &delim=CGuiRegistry::kDecimalDot)
create a key from a section and a subkey
Definition: registry.cpp:504
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
CObjectListWidget - mediator widget.
void DisableMultipleSelection(bool disabled=true)
void SetObjects(TConstScopedObjects &objects)
void GetSelection(TConstScopedObjects &objects)
ISelection-style API.
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
void LoadTableSettings(const CRegistryReadView &view, bool byName=false)
void SaveTableSettings(CRegistryWriteView &view, bool saveSorting=true) const
#define ID_BITMAPBUTTON
#define _(proto)
Definition: ct_nlmzip_i.h:78
static const char * kObjectList
#define false
Definition: bool.h:36
static void DLIST_NAME() remove(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:90
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static const char label[]
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const TYPE & Get(const CNamedParameterList *param)
const struct ncbi::grid::netcache::search::fields::SIZE size
#define _ASSERT
Modified on Sat May 04 13:19:26 2024 by modify_doxy.py rev. 669887