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

Go to the SVN repository for this file.

1 /* $Id: general_panel.cpp 43053 2019-05-09 18:23:44Z filippov $
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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
34 #include <objects/general/Date.hpp>
39 #include <objmgr/bioseq_ci.hpp>
40 #include <objmgr/seqdesc_ci.hpp>
43 
44 #include <wx/datectrl.h>
45 #include <wx/sizer.h>
46 #include <wx/statbox.h>
47 #include <wx/stattext.h>
48 #include <wx/radiobut.h>
49 #include <wx/textctrl.h>
50 #include <wx/datetime.h>
51 #include <wx/icon.h>
52 
54 /*
55  * CGeneralPanel type definition
56  */
57 
58 IMPLEMENT_DYNAMIC_CLASS( CGeneralPanel, wxPanel )
59 
60 
61 /*
62  * CGeneralPanel event table definition
63  */
64 
65 BEGIN_EVENT_TABLE( CGeneralPanel, wxPanel )
66 
67 ////@begin CGeneralPanel event table entries
68  EVT_RADIOBUTTON( ID_SUBMITTER_IMMEDIATE, CGeneralPanel::OnSubmitterImmediateSelected )
69  EVT_RADIOBUTTON( ID_SUBMITTER_HUP, CGeneralPanel::OnSubmitterHupSelected )
70 ////@end CGeneralPanel event table entries
71 
73 
74 
75 /*
76  * CGeneralPanel constructors
77  */
78 
80 {
81  Init();
82 }
83 
84 CGeneralPanel::CGeneralPanel( wxWindow* parent, ICommandProccessor* cmdproc, objects::CSeq_entry_Handle seh,wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
85 : m_CmdProcessor(cmdproc), m_Seh(seh)
86 {
87  Init();
88  Create(parent, id, pos, size, style);
89 }
90 
91 
92 /*
93  * CGeneralPanel creator
94  */
95 
96 bool CGeneralPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
97 {
98 ////@begin CGeneralPanel creation
99  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
100  wxPanel::Create( parent, id, pos, size, style );
101 
102  CreateControls();
103  if (GetSizer())
104  {
105  GetSizer()->SetSizeHints(this);
106  }
107  Centre();
108 ////@end CGeneralPanel creation
109  return true;
110 }
111 
112 
113 /*
114  * CGeneralPanel destructor
115  */
116 
118 {
119 ////@begin CGeneralPanel destruction
120 ////@end CGeneralPanel destruction
121 }
122 
123 
124 /*
125  * Member initialisation
126  */
127 
129 {
130 ////@begin CGeneralPanel member initialisation
131  m_Bioproject = NULL;
132  m_Biosample = NULL;
134  m_HUP = NULL;
135  m_Label = NULL;
136  m_Date = NULL;
137 ////@end CGeneralPanel member initialisation
138 }
139 
140 
141 /*
142  * Control creation for CGeneralPanel
143  */
144 
146 {
147 ////@begin CGeneralPanel content construction
148  CGeneralPanel* itemPanel1 = this;
149 
150  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
151  itemPanel1->SetSizer(itemBoxSizer2);
152 
153  wxFlexGridSizer* itemFlexGridSizer1 = new wxFlexGridSizer(0, 2, 0, 0);
154  itemBoxSizer2->Add(itemFlexGridSizer1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
155 
156  wxStaticText* itemStaticText2 = new wxStaticText( itemPanel1, wxID_STATIC, _("BioProject"), wxDefaultPosition, wxDefaultSize, 0 );
157  itemFlexGridSizer1->Add(itemStaticText2, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
158 
159  wxStaticText* itemStaticText3 = new wxStaticText( itemPanel1, wxID_STATIC, _("BioSample"), wxDefaultPosition, wxDefaultSize, 0 );
160  itemFlexGridSizer1->Add(itemStaticText3, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
161 
162  m_Bioproject = new wxTextCtrl( itemPanel1, ID_SUBMITTER_BIOPROJECT, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0 );
163  itemFlexGridSizer1->Add(m_Bioproject, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
164 
165  m_Biosample = new wxTextCtrl( itemPanel1, ID_SUBMITTER_BIOSAMPLE, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0 );
166  itemFlexGridSizer1->Add(m_Biosample, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
167 
168  wxStaticBox* itemStaticBoxSizer1Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Release date"));
169  wxStaticBoxSizer* itemStaticBoxSizer1 = new wxStaticBoxSizer(itemStaticBoxSizer1Static, wxVERTICAL);
170  itemBoxSizer2->Add(itemStaticBoxSizer1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
171 
172  wxStaticText* itemStaticText1 = new wxStaticText( itemPanel1, wxID_STATIC, _("When should this submission be released to the public?"), wxDefaultPosition, wxDefaultSize, 0 );
173  itemStaticBoxSizer1->Add(itemStaticText1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
174 
175  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
176  itemStaticBoxSizer1->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
177 
178  m_ImmediateRelease = new wxRadioButton( itemPanel1, ID_SUBMITTER_IMMEDIATE, _("Immediately after processing"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
179  m_ImmediateRelease->SetValue(true);
180  itemBoxSizer3->Add(m_ImmediateRelease, 0, wxALIGN_LEFT|wxALL, 5);
181 
182  m_HUP = new wxRadioButton( itemPanel1, ID_SUBMITTER_HUP, _("On specified date or upon publication, whichever is first:"), wxDefaultPosition, wxDefaultSize, 0 );
183  m_HUP->SetValue(false);
184  itemBoxSizer3->Add(m_HUP, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
185 
186  m_Label = new wxStaticText( itemPanel1, wxID_STATIC, _("Release date*"), wxDefaultPosition, wxDefaultSize, 0 );
187  m_Label->Enable(false);
188  itemBoxSizer3->Add(m_Label, 0, wxALIGN_LEFT|wxALL|wxRESERVE_SPACE_EVEN_IF_HIDDEN, 5);
189 
190  m_Date = new wxDatePickerCtrl( itemPanel1, ID_DATEPICKERCTRL, wxDateTime(), wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN);
191  m_Date->Enable(false);
192  itemBoxSizer3->Add(m_Date, 0, wxALIGN_LEFT|wxALL, 5);
193 
194  wxStaticText* itemStaticText8 = new wxStaticText( itemPanel1, wxID_STATIC, _("Note: Please inform GenBank when the accession number or any portion\nof the sequence is published, as published data must be released."), wxDefaultPosition, wxDefaultSize, 0 );
195  itemStaticBoxSizer1->Add(itemStaticText8, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
196 
197 ////@end CGeneralPanel content construction
198 }
199 
200 /*
201  * Should we show tooltips?
202  */
203 
205 {
206  return true;
207 }
208 
209 /*
210  * Get bitmap resources
211  */
212 
213 wxBitmap CGeneralPanel::GetBitmapResource( const wxString& name )
214 {
215  // Bitmap retrieval
216 ////@begin CGeneralPanel bitmap retrieval
217  wxUnusedVar(name);
218  return wxNullBitmap;
219 ////@end CGeneralPanel bitmap retrieval
220 }
221 
222 /*
223  * Get icon resources
224  */
225 
226 wxIcon CGeneralPanel::GetIconResource( const wxString& name )
227 {
228  // Icon retrieval
229 ////@begin CGeneralPanel icon retrieval
230  wxUnusedVar(name);
231  return wxNullIcon;
232 ////@end CGeneralPanel icon retrieval
233 }
234 
235 
236 /*
237  * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_SUBMITTER_HUP
238  */
239 
240 void CGeneralPanel::OnSubmitterHupSelected( wxCommandEvent& event )
241 {
242  m_Label->Enable(true);
243  m_Date->Enable(true);
244 }
245 
246 /*
247  * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_SUBMITTER_IMMEDIATE
248  */
249 
250 void CGeneralPanel::OnSubmitterImmediateSelected( wxCommandEvent& event )
251 {
252  m_Label->Enable(false);
253  m_Date->Enable(false);
254 }
255 
256 void CGeneralPanel::ApplySubmitBlock(objects::CSubmit_block& block)
257 {
258  m_Block.Reset(&block);
260 
261 }
262 
263 void CGeneralPanel::ApplyDescriptor(objects::CSeqdesc& desc)
264 {
265  if (desc.IsUser() && desc.GetUser().GetObjectType() == objects::CUser_object::eObjectType_DBLink) {
266  m_Dblink.Reset(&desc);
268  }
269 }
270 
271 
273 {
274  m_ImmediateRelease->SetValue(true);
275  m_HUP->SetValue(false);
276  m_Date->Enable(false);
277  m_Bioproject->SetValue(wxT(""));
278  m_Biosample->SetValue(wxT(""));
279 }
280 
281 
283 {
284  if (m_Block && m_Block->IsSetHup() && m_Block->GetHup()) {
285  m_HUP->SetValue(true);
286  m_ImmediateRelease->SetValue(false);
287  m_Date->Enable(true);
288  if (m_Block->IsSetReldate() && m_Block->GetReldate().IsStd() &&
289  m_Block->GetReldate().GetStd().IsSetYear()) {
290  const auto& reldate = m_Block->GetReldate().GetStd();
291  int year = 1900;
292  int month = 1;
293  int day = 1;
294  if (reldate.IsSetYear())
295  year = reldate.GetYear();
296  if (reldate.IsSetMonth())
297  month = reldate.GetMonth();
298  if (reldate.IsSetDay())
299  day = reldate.GetDay();
300  wxDateTime dmy(day, wxDateTime::Month(wxDateTime::Jan + month - 1), year, 0, 0, 0, 0);
301  m_Date->SetValue(dmy);
302  }
303  }
304 }
305 
306 
308 {
309  if (m_Dblink) {
310  const objects::CUser_object& user = m_Dblink->GetUser();
311  vector<string> bioprojects = objects::edit::CDBLink::GetBioProject(user);
312  string project_val = NStr::Join(bioprojects, ";");
313  m_Bioproject->SetValue(ToWxString(project_val));
314 
315  vector<string> biosamples = objects::edit::CDBLink::GetBioSample(user);
316  string biosample_val = NStr::Join(biosamples, ";");
317  m_Biosample->SetValue(ToWxString(biosample_val));
318  }
319 
320 }
321 
322 
324 {
325  x_Reset();
326 
328 
330  return true;
331 }
332 
333 
334 void SetField(objects::CUser_object& user, const string& field_name, const string& val)
335 {
336  vector<string> val_list;
337  NStr::Split(val, ";", val_list);
338  if (val_list.size() > 0) {
339  objects::CUser_field& field = user.SetField(field_name);
340  field.ResetData();
341  for (auto it : val_list) {
342  field.SetData().SetStrs().push_back(it);
343  }
344  }
345  else {
346  user.RemoveNamedField(field_name);
347  }
348 
349 }
350 
351 
353 {
354  if (!wxPanel::TransferDataFromWindow()) {
355  return false;
356  }
357 
358  if (m_Block) {
359  if (m_HUP->GetValue()) {
360  m_Block->SetHup(true);
361  wxDateTime dt = m_Date->GetValue();
362  m_Block->SetReldate().SetStd().SetYear(dt.GetYear());
363  m_Block->SetReldate().SetStd().SetMonth(dt.GetMonth() - wxDateTime::Jan + 1);
364  m_Block->SetReldate().SetStd().SetDay(dt.GetDay());
365  }
366  else {
367  m_Block->SetHup(false);
368  }
369  }
370 
371  if (m_Dblink) {
372  objects::CUser_object& user = m_Dblink->SetUser();
373 
374  string biosample_val = ToStdString(m_Biosample->GetValue());
375  SetField(user, "BioSample", biosample_val);
376 
377  string bioproject_val = ToStdString(m_Bioproject->GetValue());
378  SetField(user, "BioProject", bioproject_val);
379  }
380  return true;
381 }
382 
384 {
385  if (!m_Dblink)
386  return;
387 
388  CRef<objects::CSeqdesc> empty(new objects::CSeqdesc());
389  empty->SetUser().SetObjectType(objects::CUser_object::eObjectType_DBLink);
390 
391  if (m_Dblink->Equals(*empty))
392  return;
393 
394  CRef<CCmdComposite> cmd(new CCmdComposite("update dblink"));
395  bool any_changes = false;
396 
397  for (objects::CBioseq_CI bi(m_Seh, objects::CSeq_inst::eMol_na); bi; ++bi)
398  {
399  bool found = false;
400  for (objects::CSeqdesc_CI di(*bi, objects::CSeqdesc::e_User); di; ++di)
401  {
402  if (di && di->IsUser() && di->GetUser().GetObjectType() == objects::CUser_object::eObjectType_DBLink)
403  {
404 
405  // edit existing descriptor
406  CRef<objects::CSeqdesc> cpy(new objects::CSeqdesc());
407  cpy->Assign(*m_Dblink);
408  if (!di->Equals(*cpy))
409  {
410  CRef<CCmdChangeSeqdesc> chg(new CCmdChangeSeqdesc(di.GetSeq_entry_Handle(), *di, *cpy));
411  cmd->AddCommand(*chg);
412  any_changes = true;
413  }
414  found = true;
415  }
416  }
417 
418  if (!found)
419  {
420  // create new source descriptor on this sequence or on the nuc-prot that contains it
421  CRef<objects::CSeqdesc> new_desc(new objects::CSeqdesc());
422 
423  new_desc->Assign(*m_Dblink);
424  objects::CBioseq_set_Handle parent = bi->GetParentBioseq_set();
425  auto entry = bi->GetParentEntry();
426  if (parent && parent.IsSetClass() && parent.GetClass() == objects::CBioseq_set::eClass_nuc_prot)
427  entry = parent.GetParentEntry();
428  CIRef<IEditCommand> cmdAddDesc(new CCmdCreateDesc(entry, *new_desc));
429  cmd->AddCommand(*cmdAddDesc);
430  any_changes = true;
431  }
432  }
433 
434  if (any_changes)
435  {
437  }
438 }
439 
441 {
442  if (!TransferDataFromWindow())
443  return;
446 }
447 
virtual bool TransferDataToWindow()
virtual bool TransferDataFromWindow()
void OnSubmitterHupSelected(wxCommandEvent &event)
wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_SUBMITTER_HUP
CRef< objects::CSubmit_block > m_Block
CGeneralPanel()
Constructors.
void x_UpdateDescControls()
void x_UpdateBlockControls()
void OnSubmitterImmediateSelected(wxCommandEvent &event)
wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_SUBMITTER_IMMEDIATE
CRef< objects::CSeqdesc > m_Dblink
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
~CGeneralPanel()
Destructor.
static bool ShowToolTips()
Should we show tooltips?
wxDatePickerCtrl * m_Date
objects::CSeq_entry_Handle m_Seh
wxTextCtrl * m_Biosample
virtual void ApplySubmitBlock(objects::CSubmit_block &block)
wxRadioButton * m_ImmediateRelease
bool Create(wxWindow *parent, wxWindowID id=ID_CGENERALPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
virtual void ApplyCommand()
wxTextCtrl * m_Bioproject
wxRadioButton * m_HUP
ICommandProccessor * m_CmdProcessor
wxStaticText * m_Label
virtual void ApplyDescriptor(objects::CSeqdesc &desc)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void ApplyDescriptorCommand()
void Init()
Initialises member variables.
void CreateControls()
Creates the controls and sizers.
virtual void ApplySubmitCommand()=0
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
CSubmissionPageChangeListener * GetParentWizard(wxWindow *wnd) const
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
void SetField(objects::CUser_object &user, const string &field_name, const string &val)
#define NULL
Definition: ncbistd.hpp:225
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3457
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
n n n</style > n</header > n< body > n< h1 > PubSeq Gateway</h1 > n< p > Accession resolution and retrieval of bio sequences Retrieval of named annotations</p > n< table > n< tr > n< td > version</td > n< td ></td > n</tr > n< tr > n< td > build date</td > n< td > Jan
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Mar 01 10:05:32 2024 by modify_doxy.py rev. 669887