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

Go to the SVN repository for this file.

1 /* $Id: asn_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: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>////@begin includes
33 ////@end includes
34 
35 #include "asn_export_page.hpp"
36 
37 #include <wx/sizer.h>
38 #include <wx/stattext.h>
39 #include <wx/bmpbuttn.h>
40 #include <wx/radiobox.h>
41 #include <wx/valgen.h>
42 #include <wx/valtext.h>
43 #include <wx/icon.h>
44 #include <wx/bitmap.h>
45 #include <wx/textctrl.h>
46 #include <wx/filedlg.h>
47 #include <wx/msgdlg.h>
48 #include <wx/artprov.h>
49 
51 
52 ////@begin XPM images
53 ////@end XPM images
54 
56 
57 IMPLEMENT_DYNAMIC_CLASS( CAsnExportPage, wxPanel )
58 
59 BEGIN_EVENT_TABLE( CAsnExportPage, wxPanel )
60 
61 ////@begin CAsnExportPage event table entries
63 
64 ////@end CAsnExportPage event table entries
65 
67 
69 {
70  Init();
71 }
72 
73 CAsnExportPage::CAsnExportPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, long style )
74 {
75  Init();
76  Create(parent, id, pos, style);
77 }
78 
79 bool CAsnExportPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, long style )
80 {
81  wxPanel::Create( parent, id, pos, wxSize(0,0), style );
82  Hide();
83 
85  if (GetSizer())
86  {
87  GetSizer()->SetSizeHints(this);
88  }
89  Centre();
90 
91  return true;
92 }
93 
95 {
96 ////@begin CAsnExportPage destruction
97 ////@end CAsnExportPage destruction
98 }
99 
101 {
102 ////@begin CAsnExportPage member initialisation
103  m_ObjectSel = NULL;
105 ////@end CAsnExportPage member initialisation
106 }
107 
109 {
110 ////@begin CAsnExportPage content construction
111  CAsnExportPage* itemPanel1 = this;
112 
113  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
114  itemPanel1->SetSizer(itemBoxSizer2);
115 
116  m_ObjectSel = new CObjectListWidget( itemPanel1, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
117  itemBoxSizer2->Add(m_ObjectSel, 1, wxGROW|wxALL, 0);
118 
119  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
120  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_LEFT|wxALL, 0);
121 
122  wxArrayString itemRadioBox5Strings;
123  itemRadioBox5Strings.Add(_("&Text"));
124  itemRadioBox5Strings.Add(_("&Binary"));
125  wxRadioBox* itemRadioBox5 = new wxRadioBox( itemPanel1, ID_RADIOBOX3, _("ASN Type"), wxDefaultPosition, wxDefaultSize, itemRadioBox5Strings, 1, wxRA_SPECIFY_ROWS );
126  itemRadioBox5->SetSelection(0);
127  itemBoxSizer4->Add(itemRadioBox5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
128 
129  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
130  itemBoxSizer2->Add(itemBoxSizer6, 0, wxGROW|wxALL, 0);
131 
132  wxStaticText* itemStaticText7 = new wxStaticText( itemPanel1, wxID_STATIC, _("File name"), wxDefaultPosition, wxDefaultSize, 0 );
133  itemBoxSizer6->Add(itemStaticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
134 
135  m_FileNameCtrl = new wxTextCtrl( itemPanel1, ID_TEXTCTRL6, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
136  itemBoxSizer6->Add(m_FileNameCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
137 
138  wxBitmapButton* itemBitmapButton9 = new wxBitmapButton( itemPanel1, ID_BITMAPBUTTON, itemPanel1->GetBitmapResource(wxT("menu::open")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
139  itemBitmapButton9->SetHelpText(_("Select ASN.1 File"));
141  itemBitmapButton9->SetToolTip(_("Select ASN.1 File"));
142  itemBoxSizer6->Add(itemBitmapButton9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
143 
144  // Set validators
145  itemRadioBox5->SetValidator( wxGenericValidator(& GetData().m_AsnType) );
146  m_FileNameCtrl->SetValidator( wxTextValidator(wxFILTER_NONE, & GetData().m_FileName) );
147 ////@end CAsnExportPage content construction
148 
149  m_SaveFile.reset(new CSaveFileHelper(this, *m_FileNameCtrl));
150 }
151 
153 {
154  return true;
155 }
156 wxBitmap CAsnExportPage::GetBitmapResource( const wxString& name )
157 {
158  return wxArtProvider::GetBitmap(name);
159 }
160 wxIcon CAsnExportPage::GetIconResource( const wxString& name )
161 {
162  // Icon retrieval
163 ////@begin CAsnExportPage icon retrieval
164  wxUnusedVar(name);
165  return wxNullIcon;
166 ////@end CAsnExportPage icon retrieval
167 }
168 
170 {
171  if (!wxPanel::TransferDataToWindow())
172  return false;
173 
176 
177  return true;
178 }
180 {
181  if (!wxPanel::TransferDataFromWindow())
182  return false;
183 
186 
187  if (objects.empty()) {
188  wxMessageBox(wxT("Please, select at least one object to export"), wxT("Error"),
189  wxOK | wxICON_ERROR, this);
190  FindWindow(ID_PANEL2)->SetFocus();
191  return false;
192  }
193 
195 
196  wxString path = GetData().GetFileName();
198  return m_SaveFile->Validate(path);
199 }
200 
201 static const char* kObjectList = "ObjectList";
202 
203 void CAsnExportPage::SetRegistryPath(const string& path)
204 {
205  m_RegPath = path;
206 }
207 
209 {
210  if (!m_RegPath.empty()) {
212  string reg_path = CGuiRegistryUtil::MakeKey(m_RegPath, kObjectList);
213  CRegistryWriteView table_view = gui_reg.GetWriteView(reg_path);
214  m_ObjectSel->SaveTableSettings(table_view);
215  }
216 }
217 
219 {
220  if (!m_RegPath.empty()) {
222  string reg_path;
223  CRegistryReadView table_view;
224 
226  table_view = gui_reg.GetReadView(reg_path);
227  m_ObjectSel->LoadTableSettings(table_view);
228  }
229 }
230 
231 void CAsnExportPage::OnSelectFileClick( wxCommandEvent& WXUNUSED(event) )
232 {
234  m_SaveFile->ShowSaveDialog(CFileExtensions::kASN);
235 }
236 
static const char * kObjectList
virtual void LoadSettings()
wxIcon GetIconResource(const wxString &name)
virtual bool TransferDataToWindow()
virtual bool TransferDataFromWindow()
CAsnExportParams & GetData()
CAsnExportParams m_data
std::unique_ptr< CSaveFileHelper > m_SaveFile
wxBitmap GetBitmapResource(const wxString &name)
void OnSelectFileClick(wxCommandEvent &event)
static bool ShowToolTips()
wxTextCtrl * m_FileNameCtrl
CObjectListWidget * m_ObjectSel
virtual void SetRegistryPath(const string &path)
IRegSettings.
virtual void SaveSettings() const
bool Create(wxWindow *parent, wxWindowID id=ID_CASNEXPORTPAGE, const wxPoint &pos=wxDefaultPosition, long style=wxTAB_TRAVERSAL)
wxString GetFileName() const
TConstScopedObjects m_Objects
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 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 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
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
#define _ASSERT
Modified on Fri Sep 20 14:57:34 2024 by modify_doxy.py rev. 669887