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

Go to the SVN repository for this file.

1 /* $Id: windowmasker_panel.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, Yury Voronov
27  */
28 
29 #include <ncbi_pch.hpp>
30 
37 
38 #include <objmgr/util/sequence.hpp>
39 #include <corelib/ncbifile.hpp>
40 #include <corelib/ncbireg.hpp>
41 
42 #include <wx/sizer.h>
43 #include <wx/statbox.h>
44 #include <wx/radiobox.h>
45 #include <wx/msgdlg.h>
46 #include <wx/stattext.h>
47 #include <wx/choice.h>
48 #include <wx/combobox.h>
49 #include <wx/checkbox.h>
50 #include <wx/imaglist.h>
51 #include <wx/filename.h>
52 #include <wx/dir.h>
53 
54 /*!
55  * CWindowMaskerPanel type definition
56  */
57 
60 
61 IMPLEMENT_DYNAMIC_CLASS( CWindowMaskerPanel, CAlgoToolManagerParamsPanel )
62 
63 
64 /*!
65  * CWindowMaskerPanel event table definition
66  */
67 
69 
70 ////@begin CWindowMaskerPanel event table entries
72 
73 ////@end CWindowMaskerPanel event table entries
74 
76 
77 
78 CWindowMaskerPanel::TMaskerPaths CWindowMaskerPanel::sm_MaskerPaths;
79 
80 /*!
81  * CWindowMaskerPanel constructors
82  */
83 
85  : m_AutoDelete(this)
86 {
87  Init();
88 }
89 
90 CWindowMaskerPanel::CWindowMaskerPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
91  : m_AutoDelete(this)
92 {
93  Init();
94  Create(parent, id, pos, size, style);
95 }
96 
97 
98 /*!
99  * CWindowMaskerPanel creator
100  */
101 
102 bool CWindowMaskerPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
103 {
104 ////@begin CWindowMaskerPanel creation
105  CAlgoToolManagerParamsPanel::Create( parent, id, pos, size, style );
106 
107  CreateControls();
108  if (GetSizer())
109  {
110  GetSizer()->SetSizeHints(this);
111  }
112  Centre();
113 ////@end CWindowMaskerPanel creation
114  return true;
115 }
116 
117 
118 /*!
119  * CWindowMaskerPanel destructor
120  */
121 
123 {
124 ////@begin CWindowMaskerPanel destruction
125 ////@end CWindowMaskerPanel destruction
126 }
127 
128 
129 /*!
130  * Member initialisation
131  */
132 
134 {
135 ////@begin CWindowMaskerPanel member initialisation
136  m_ObjectList = NULL;
138  m_WMStatic = NULL;
139  m_WMTaxIds = NULL;
140  m_WMDownload = NULL;
141 ////@end CWindowMaskerPanel member initialisation
142 }
143 
144 
145 /*!
146  * Control creation for CWindowMaskerPanel
147  */
148 
150 {
151 ////@begin CWindowMaskerPanel content construction
152  CWindowMaskerPanel* itemCAlgoToolManagerParamsPanel1 = this;
153 
154  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
155  itemCAlgoToolManagerParamsPanel1->SetSizer(itemBoxSizer2);
156 
157  m_ObjectList = new CObjectListWidget( itemCAlgoToolManagerParamsPanel1, ID_COBJECTLISTWIDGET, wxDefaultPosition, wxSize(300, 150), wxLC_REPORT );
158  itemBoxSizer2->Add(m_ObjectList, 1, wxGROW|wxALL, 5);
159 
160  m_WMStaticBoxSizer = new wxBoxSizer(wxHORIZONTAL);
161  itemBoxSizer2->Add(m_WMStaticBoxSizer, 0, wxGROW|wxALL, 5);
162 
163  m_WMStatic = new wxStaticText( itemCAlgoToolManagerParamsPanel1, wxID_STATIC, _("Mask using parameters for"), wxDefaultPosition, wxDefaultSize, 0 );
164  m_WMStaticBoxSizer->Add(m_WMStatic, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
165 
166  wxArrayString m_WMTaxIdsStrings;
167  m_WMTaxIds = new wxChoice( itemCAlgoToolManagerParamsPanel1, ID_CHOICE7, wxDefaultPosition, wxDefaultSize, m_WMTaxIdsStrings, 0 );
168  m_WMStaticBoxSizer->Add(m_WMTaxIds, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
169 
170  m_WMStaticBoxSizer->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
171 
172  m_WMDownload = new wxButton( itemCAlgoToolManagerParamsPanel1, ID_BUTTON5, _("Configure..."), wxDefaultPosition, wxDefaultSize, 0 );
173  m_WMStaticBoxSizer->Add(m_WMDownload, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
174 
175  wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxHORIZONTAL);
176  itemBoxSizer2->Add(itemBoxSizer9, 0, wxALIGN_LEFT|wxALL, 5);
177 
178  wxStaticText* itemStaticText10 = new wxStaticText( itemCAlgoToolManagerParamsPanel1, wxID_STATIC, _("Objects to Create"), wxDefaultPosition, wxDefaultSize, 0 );
179  itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
180 
181  wxArrayString itemComboBox11Strings;
182  itemComboBox11Strings.Add(_("Features representing masked regions"));
183  itemComboBox11Strings.Add(_("A sequence location representing masked regions"));
184  itemComboBox11Strings.Add(_("\"Both features and sequence location"));
185  wxComboBox* itemComboBox11 = new wxComboBox( itemCAlgoToolManagerParamsPanel1, ID_COMBOBOX2, wxEmptyString, wxDefaultPosition, wxDefaultSize, itemComboBox11Strings, wxCB_READONLY );
186  itemBoxSizer9->Add(itemComboBox11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
187 
188  wxCheckBox* itemCheckBox12 = new wxCheckBox( itemCAlgoToolManagerParamsPanel1, ID_LOCALRUN, _("Run tool as standalone"), wxDefaultPosition, wxDefaultSize, 0 );
189  itemCheckBox12->SetValue(true);
190  itemBoxSizer2->Add(itemCheckBox12, 0, wxALIGN_LEFT|wxALL, 5);
191 
192  // Set validators
193  itemComboBox11->SetValidator( wxGenericValidator(& GetData().m_OutputType) );
194  itemCheckBox12->SetValidator( wxGenericValidator(& GetData().m_Standalone) );
195 ////@end CWindowMaskerPanel content construction
196 
197  wxStaticText* loadingText = new wxStaticText(itemCAlgoToolManagerParamsPanel1, ID_LOADING_TEXT, wxT("Windomasker tax ID: none. Loading..."), wxDefaultPosition, wxDefaultSize, 0);
198  wxFont bold(wxNORMAL_FONT->GetPointSize(), wxNORMAL_FONT->GetFamily(), wxNORMAL_FONT->GetStyle(), wxFONTWEIGHT_BOLD, wxNORMAL_FONT->GetUnderlined(), wxNORMAL_FONT->GetFaceName());
199  loadingText->SetFont(bold);
200  loadingText->SetForegroundColour(*wxBLACK);
201  m_WMStaticBoxSizer->Add(loadingText, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
202  m_WMStaticBoxSizer->Hide(loadingText);
203 
204  m_WMStaticBoxSizer->Add(1, m_WMDownload->GetSize().GetHeight(), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
205 
206  CIndProgressBar* progress = new CIndProgressBar(itemCAlgoToolManagerParamsPanel1, ID_LOADING_PROGRESS, wxDefaultPosition, 100);
207  m_WMStaticBoxSizer->Add(progress, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5);
208  m_WMStaticBoxSizer->Hide(progress);
209 }
210 
211 
212 /*!
213  * Should we show tooltips?
214  */
215 
217 {
218  return true;
219 }
220 
221 /*!
222  * Get bitmap resources
223  */
224 
225 wxBitmap CWindowMaskerPanel::GetBitmapResource( const wxString& name )
226 {
227  // Bitmap retrieval
228 ////@begin CWindowMaskerPanel bitmap retrieval
229  wxUnusedVar(name);
230  return wxNullBitmap;
231 ////@end CWindowMaskerPanel bitmap retrieval
232 }
233 
234 /*!
235  * Get icon resources
236  */
237 
238 wxIcon CWindowMaskerPanel::GetIconResource( const wxString& name )
239 {
240  // Icon retrieval
241 ////@begin CWindowMaskerPanel icon retrieval
242  wxUnusedVar(name);
243  return wxNullIcon;
244 ////@end CWindowMaskerPanel icon retrieval
245 }
246 
247 void CWindowMaskerPanel::OnWMDownload(wxCommandEvent& event)
248 {
250  x_InitTaxons();
251 }
252 
253 static const char *kTableTag = "Table";
254 
256 {
257  if (!m_RegPath.empty()) {
259  string reg_path = CGuiRegistryUtil::MakeKey(m_RegPath, kTableTag);
260  CRegistryWriteView table_view = gui_reg.GetWriteView(reg_path);
261  m_ObjectList->SaveTableSettings(table_view);
262  }
263 }
264 
266 {
267  if (!m_RegPath.empty()) {
269  string reg_path;
270  CRegistryReadView table_view;
271 
273  table_view = gui_reg.GetReadView(reg_path);
274  m_ObjectList->LoadTableSettings(table_view);
275  }
276 }
277 
278 
280 {
281  if (m_InputObjects) {
284  }
285 
286  x_InitTaxons();
287 
288  return wxPanel::TransferDataToWindow();
289 }
290 
292 {
293  if (CTaxIdHelper::GetInstance().FillControl(this, *m_WMTaxIds, true, GetData().GetTaxId()))
294  x_ShowWM(true);
295  else
296  x_ShowWM(false);
297 }
298 
300 {
301  if (!local) return;
303  x_ShowWM(true);
304 }
305 
307 {
308  m_WMStaticBoxSizer->Show(FindWindow(ID_LOADING_TEXT), !show);
309  m_WMStaticBoxSizer->Show(FindWindow(ID_LOADING_PROGRESS), !show);
310 
311  m_WMStaticBoxSizer->Show(m_WMStatic, show);
312  m_WMStaticBoxSizer->Show(m_WMTaxIds, show);
313  m_WMStaticBoxSizer->Show(m_WMDownload, show);
314  GetSizer()->Layout();
315 }
316 
317 
318 /*!
319  * Transfer data from the window
320  */
321 
323 {
324  if (!wxPanel::TransferDataFromWindow())
325  return false;
326 
327  TConstScopedObjects selection;
328  m_ObjectList->GetSelection(selection);
329  if (selection.empty()) {
330  wxMessageBox(
331  wxT("Please, select sequences to mask."), wxT("Error"),
332  wxOK | wxICON_ERROR, this
333  );
334  m_ObjectList->SetFocus();
335  return false;
336  }
337  GetData().SetObjects() = selection;
338 
339  int taxId = 0, index = m_WMTaxIds->GetSelection();
340  if (wxNOT_FOUND != index)
341  taxId = (int)(size_t)m_WMTaxIds->GetClientData(index);
342 
343  if (taxId <= 0) {
344  wxMessageBox(
345  wxT("Please, select organism."), wxT("Error"),
346  wxOK | wxICON_ERROR, this
347  );
348  m_WMTaxIds->SetFocus();
349  return false;
350  }
351 
352  GetData().SetTaxId(taxId);
353 
354  return true;
355 }
356 
358 {
359  GetData().Init();
361 }
362 
CAlgoToolManagerParamsPanel.
string m_RegPath
registry path to the settings
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
bool FillControl(ICallback *callback, wxControlWithItems &ctrl, bool local, int selectTaxId)
static CTaxIdHelper & GetInstance()
static CWinMaskerFileStorage & GetInstance()
access the application-wide singleton
void x_ShowWM(bool show)
virtual void TaxonsLoaded(bool local)
static bool ShowToolTips()
Should we show tooltips?
CObjectListWidget * m_ObjectList
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
virtual bool TransferDataToWindow()
Transfer data to the window.
CWindowMaskerParams & GetData()
Data access.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void RestoreDefaults()
override in derived classes
void OnWMDownload(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON5
CWindowMaskerPanel()
Constructors.
~CWindowMaskerPanel()
Destructor.
void Init()
Initialises member variables.
TConstScopedObjects * m_InputObjects
virtual bool TransferDataFromWindow()
Transfer data from the window.
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=ID_CWINDOWMASKERPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
virtual void LoadSettings()
wxBoxSizer * m_WMStaticBoxSizer
virtual void SaveSettings() const
override in derived classes
void Init()
Initialises member variables.
TConstScopedObjects & SetObjects()
void LoadTableSettings(const CRegistryReadView &view, bool byName=false)
void SaveTableSettings(CRegistryWriteView &view, bool saveSorting=true) const
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define ID_BUTTON5
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
TTaxId GetTaxId(const CBioseq_Handle &handle)
return the tax-id associated with a given sequence.
Definition: sequence.cpp:274
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Process information in the NCBI Registry, including working with configuration files.
USING_SCOPE(objects)
static const char * kTableTag
#define local
Definition: zutil.h:33
Modified on Tue Apr 16 20:12:23 2024 by modify_doxy.py rev. 669887