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

Go to the SVN repository for this file.

1 /* $Id: wiggle_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>
33 ////@begin includes
34 ////@end includes
35 
36 #include "wiggle_export_page.hpp"
39 
40 #include <wx/sizer.h>
41 #include <wx/stattext.h>
42 #include <wx/bmpbuttn.h>
43 #include <wx/valgen.h>
44 #include <wx/valtext.h>
45 #include <wx/textctrl.h>
46 #include <wx/icon.h>
47 #include <wx/bitmap.h>
48 #include <wx/filedlg.h>
49 #include <wx/msgdlg.h>
50 #include <wx/artprov.h>
51 #include <wx/valnum.h>
52 
54 
55 ////@begin XPM images
56 ////@end XPM images
57 
60 
61 IMPLEMENT_DYNAMIC_CLASS( CWiggleExportPage, wxPanel )
62 
63 BEGIN_EVENT_TABLE( CWiggleExportPage, wxPanel )
64 
65 ////@begin CWiggleExportPage event table entries
67 
68 ////@end CWiggleExportPage event table entries
69 
71 
73 {
74  Init();
75 }
76 
77 CWiggleExportPage::CWiggleExportPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
78 {
79  Init();
80  Create(parent, id, pos, size, style);
81 }
82 
83 bool CWiggleExportPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
84 {
85 ////@begin CWiggleExportPage creation
86  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
87  wxPanel::Create( parent, id, pos, size, style );
88 
90  if (GetSizer())
91  {
92  GetSizer()->SetSizeHints(this);
93  }
94  Centre();
95 ////@end CWiggleExportPage creation
96  return true;
97 }
98 
100 {
101 ////@begin CWiggleExportPage destruction
102 ////@end CWiggleExportPage destruction
103 }
104 
106 {
107 ////@begin CWiggleExportPage member initialisation
108  m_ObjectSel = NULL;
112  m_FromCtrl = NULL;
113  m_ToCtrl = NULL;
115 ////@end CWiggleExportPage member initialisation
116 }
117 
119 {
120 ////@begin CWiggleExportPage content construction
121  CWiggleExportPage* itemPanel1 = this;
122 
123  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
124  itemPanel1->SetSizer(itemBoxSizer2);
125 
126  m_ObjectSel = new CObjectListWidget( itemPanel1, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
127  itemBoxSizer2->Add(m_ObjectSel, 1, wxGROW|wxALL, 0);
128 
129  m_BinSizePanel = new wxStaticBox(itemPanel1, wxID_ANY, _("Recalculate Bin Size"));
130  wxStaticBoxSizer* itemStaticBoxSizer4 = new wxStaticBoxSizer(m_BinSizePanel, wxHORIZONTAL);
131  itemBoxSizer2->Add(itemStaticBoxSizer4, 0, wxGROW|wxALL, 0);
132 
133  m_BinSizeLabel = new wxStaticText( itemPanel1, wxID_STATIC, _("Graph bin size (bases):"), wxDefaultPosition, wxDefaultSize, 0 );
134  itemStaticBoxSizer4->Add(m_BinSizeLabel, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM, 5);
135 
136  m_BinSizeCtrl = new wxSpinCtrl( itemPanel1, ID_SPINCTRL, _T("1000"), wxDefaultPosition, wxSize(itemPanel1->ConvertDialogToPixels(wxSize(60, -1)).x, -1), wxSP_ARROW_KEYS, 1, 1000000, 1000 );
137  itemStaticBoxSizer4->Add(m_BinSizeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
138 
139  wxStaticBox* itemStaticBoxSizer7Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Sequence Range (blank for the whole sequence)"));
140  wxStaticBoxSizer* itemStaticBoxSizer7 = new wxStaticBoxSizer(itemStaticBoxSizer7Static, wxHORIZONTAL);
141  itemStaticBoxSizer7Static->Show(false);
142  itemBoxSizer2->Add(itemStaticBoxSizer7, 0, wxGROW|wxALL, 0);
143 
144  wxStaticText* itemStaticText8 = new wxStaticText( itemPanel1, wxID_STATIC, _("From:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
145  itemStaticText8->Show(false);
146  itemStaticBoxSizer7->Add(itemStaticText8, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
147 
148  m_FromCtrl = new wxTextCtrl( itemPanel1, ID_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
149  m_FromCtrl->Show(false);
150  itemStaticBoxSizer7->Add(m_FromCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
151 
152  wxStaticText* itemStaticText10 = new wxStaticText( itemPanel1, wxID_STATIC, _("To:"), wxDefaultPosition, wxDefaultSize, 0 );
153  itemStaticText10->Show(false);
154  itemStaticBoxSizer7->Add(itemStaticText10, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM, 5);
155 
156  m_ToCtrl = new wxTextCtrl( itemPanel1, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
157  m_ToCtrl->Show(false);
158  itemStaticBoxSizer7->Add(m_ToCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
159 
160  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
161  itemBoxSizer2->Add(itemBoxSizer12, 0, wxGROW|wxALL, 0);
162 
163  wxStaticText* itemStaticText13 = new wxStaticText( itemPanel1, wxID_STATIC, _("File name"), wxDefaultPosition, wxDefaultSize, 0 );
164  itemBoxSizer12->Add(itemStaticText13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
165 
166  m_FileNameCtrl = new wxTextCtrl( itemPanel1, ID_TEXTCTRL6, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
167  itemBoxSizer12->Add(m_FileNameCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
168 
169  wxBitmapButton* itemBitmapButton15 = new wxBitmapButton( itemPanel1, ID_BITMAPBUTTON, itemPanel1->GetBitmapResource(wxT("menu::open")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
170  itemBitmapButton15->SetHelpText(_("Select ASN.1 File"));
172  itemBitmapButton15->SetToolTip(_("Select ASN.1 File"));
173  itemBoxSizer12->Add(itemBitmapButton15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
174 
175  // Set validators
176  m_BinSizeCtrl->SetValidator( wxGenericValidator(& GetData().m_BinSize) );
177  m_FromCtrl->SetValidator( wxTextValidator(wxFILTER_NONE, & GetData().m_From) );
178  m_ToCtrl->SetValidator( wxTextValidator(wxFILTER_NONE, & GetData().m_To) );
179  m_FileNameCtrl->SetValidator( wxTextValidator(wxFILTER_NONE, & GetData().m_FileName) );
180 ////@end CWiggleExportPage content construction
181 
182  m_SaveFile.reset(new CSaveFileHelper(this, *m_FileNameCtrl));
183 
184 }
185 
187 {
188  return true;
189 }
190 wxBitmap CWiggleExportPage::GetBitmapResource( const wxString& name )
191 {
192  return wxArtProvider::GetBitmap(name);
193 }
194 wxIcon CWiggleExportPage::GetIconResource( const wxString& name )
195 {
196  // Icon retrieval
197 ////@begin CWiggleExportPage icon retrieval
198  wxUnusedVar(name);
199  return wxNullIcon;
200 ////@end CWiggleExportPage icon retrieval
201 }
202 
203 static const char* kObjectList = "ObjectList";
204 
205 void CWiggleExportPage::SetRegistryPath(const string& path)
206 {
207  m_RegPath = path;
208 }
209 
211 {
212  if (!m_RegPath.empty()) {
214  string reg_path = CGuiRegistryUtil::MakeKey(m_RegPath, kObjectList);
215  CRegistryWriteView table_view = gui_reg.GetWriteView(reg_path);
216  m_ObjectSel->SaveTableSettings(table_view);
217  }
218 }
219 
221 {
222  if (!m_RegPath.empty()) {
224  string reg_path;
225  CRegistryReadView table_view;
226 
228  table_view = gui_reg.GetReadView(reg_path);
229  m_ObjectSel->LoadTableSettings(table_view);
230  }
231 }
232 
233 void CWiggleExportPage::OnSelectFileClick( wxCommandEvent& event )
234 {
236  m_SaveFile->ShowSaveDialog(CFileExtensions::kWIG);
237 }
238 
240 {
241  if (!wxPanel::TransferDataToWindow())
242  return false;
243 
246 
247  // Hide BinSize control if there are no BAM graph in the selected objects
248  bool is_bam = false;
249  for (auto&& obj : m_data.m_Objects) {
250  auto seq_annot = dynamic_cast<const CSeq_annot*>(obj.object.GetPointer());
251  if (!seq_annot)
252  continue;
253  string bam_data;
254  string bam_index;
255  string assembly;
256  if (CBamUtils::GetCoverageGraphInfo(*seq_annot, bam_data, bam_index, assembly)) {
257  is_bam = true;
258  break;
259  }
260  }
261  if (!is_bam) {
262  m_BinSizeLabel->Hide();
263  m_BinSizeCtrl->Hide();
264  m_BinSizePanel->Hide();
265  }
266  return true;
267 }
268 
270 {
271  if (!wxPanel::TransferDataFromWindow())
272  return false;
273 
276 
277  if (objects.empty()) {
278  wxMessageBox(wxT("Please, select at least one object to export"), wxT("Error"),
279  wxOK | wxICON_ERROR, this);
280  FindWindow(ID_PANEL2)->SetFocus();
281  return false;
282  }
283 
285 
286  wxString path(GetData().GetFileName());
288  return m_SaveFile->Validate(path);
289 }
290 
static bool GetCoverageGraphInfo(const objects::CSeq_annot &seq_annot, string &bam_data, string &bam_index, string &assembly)
Definition: bam_utils.cpp:261
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
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CObjectListWidget * m_ObjectSel
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
static bool ShowToolTips()
virtual bool TransferDataToWindow()
virtual void SaveSettings() const
CWiggleExportParams m_data
The data edited by this window.
void OnSelectFileClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BITMAPBUTTON
wxStaticText * m_BinSizeLabel
std::unique_ptr< CSaveFileHelper > m_SaveFile
virtual bool TransferDataFromWindow()
wxStaticBox * m_BinSizePanel
virtual void SetRegistryPath(const string &path)
bool Create(wxWindow *parent, wxWindowID id=ID_CWIGGLEEXPORTPAGE, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(267, 185), long style=wxTAB_TRAVERSAL)
virtual void LoadSettings()
CWiggleExportParams & GetData()
Data access.
TConstScopedObjects m_Objects
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
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
#define _ASSERT
USING_SCOPE(objects)
static const char * kObjectList
Modified on Sun Mar 03 03:13:01 2024 by modify_doxy.py rev. 669887