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

Go to the SVN repository for this file.

1 /* $Id: edit_history.cpp 46346 2021-03-25 13:58:47Z asztalos $
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: Igor Filippov
27  */
28 
29 
30 #include <ncbi_pch.hpp>
33 #include <objects/seq/Seq_hist.hpp>
35 #include <objects/general/Date.hpp>
36 #include <objmgr/scope.hpp>
37 #include <objmgr/seqdesc_ci.hpp>
38 #include <objmgr/util/sequence.hpp>
39 
40 #include <gui/objutils/label.hpp>
47 #include "growable_list.hpp"
48 
50 #include <wx/sizer.h>
51 #include <wx/checkbox.h>
52 
53 
54 
57 
58 
59 /*!
60  * CEditHistory type definition
61  */
62 
63 IMPLEMENT_DYNAMIC_CLASS( CEditHistory, wxDialog )
64 
65 
66 /*!
67  * CEditHistory event table definition
68  */
69 
70 BEGIN_EVENT_TABLE( CEditHistory, wxDialog )
71 
72 ////@begin CEditHistory event table entries
73 ////@end CEditHistory event table entries
74 
76 
77 
78 /*!
79  * CEditHistory constructors
80  */
81 
83 {
84  Init();
85 }
86 
87 
88 CEditHistory::CEditHistory( wxWindow* parent, CBioseq_Handle bsh,
89  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
90  : m_Bioseq(bsh)
91 {
92  Init();
93  Create(parent, id, caption, pos, size, style);
94 }
95 
96 
97 /*!
98  * CEditHistory creator
99  */
100 
101 bool CEditHistory::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
102 {
103 ////@begin CEditHistory creation
104  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
105  wxDialog::Create( parent, id, caption, pos, size, style );
106 
107  CreateControls();
108  if (GetSizer())
109  {
110  GetSizer()->SetSizeHints(this);
111  }
112  Centre();
113 
114 ////@end CEditHistory creation
115  return true;
116 }
117 
118 
119 /*!
120  * CEditHistory destructor
121  */
122 
124 {
125 ////@begin CEditHistory destruction
126 ////@end CEditHistory destruction
127 }
128 
129 
130 /*!
131  * Member initialisation
132  */
133 
135 {
136  m_Deleted = NULL;
142 }
143 
144 
145 /*!
146  * Control creation for CEditHistory
147  */
148 
150 {
151 ////@begin CEditHistory content construction
152  CEditHistory* itemDialog1 = this;
153 
154  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
155  itemDialog1->SetSizer(itemBoxSizer2);
156 
157  wxArrayString seq_ids_replaces;
158  wxArrayString seq_ids_replaced_by;
159  CRef<CDate> replaces_date(new CDate);
160  CRef<CDate> replaced_by_date(new CDate);
161  bool is_deleted = false;
162  CRef<CDate> deleted_date(new CDate);
163  if (m_Bioseq && m_Bioseq.IsSetInst_Hist())
164  {
165  CScope &scope = m_Bioseq.GetScope();
166  const CSeq_hist& hist = m_Bioseq.GetInst_Hist();
167  set<string> seq_ids;
168  {
169  const auto& ids = m_Bioseq.GetBioseqCore()->GetId();
170  for (const auto& id_it : ids) {
171  string label;
172  CLabel::GetLabel(id_it.GetObject(), &label, CLabel::eContent, &scope);
173  size_t pos = label.find('.');
174  if (pos != NPOS) {
175  label = label.substr(0, pos);
176  }
177  seq_ids.insert(label);
178  }
179  }
180 
181  if (hist.IsSetReplaces()) {
182  if (hist.GetReplaces().IsSetIds()) {
183  for (const auto& id_it : hist.GetReplaces().GetIds()) {
184  string id_label;
185  CLabel::GetLabel(*id_it, &id_label, CLabel::eContent, &scope);
186  size_t pos = id_label.find('.');
187  if (pos != NPOS) {
188  id_label = id_label.substr(0, pos);
189  }
190  bool match = false;
191  for (const auto& it : seq_ids) {
192  if (NStr::EqualCase(it, id_label)) {
193  match = true;
194  break;
195  }
196  }
197  if (!match) {
198  seq_ids_replaces.Add(ToWxString(id_label));
199  }
200  }
201  }
202  if (hist.GetReplaces().IsSetDate()) {
203  replaces_date->Assign(hist.GetReplaces().GetDate());
204  }
205  }
206 
207  if (hist.IsSetReplaced_by())
208  {
209  if (hist.GetReplaced_by().IsSetIds())
210  {
211  for(const auto& id_it : hist.GetReplaced_by().GetIds())
212  {
213  string str;
214  CLabel::GetLabel(*id_it, &str, CLabel::eContent, &scope);
215  seq_ids_replaced_by.Add(ToWxString (str));
216  }
217  }
218  if (hist.GetReplaced_by().IsSetDate())
219  {
220  replaced_by_date->Assign(hist.GetReplaced_by().GetDate());
221  }
222  }
223  if (hist.IsSetDeleted())
224  {
225  if (hist.GetDeleted().IsBool())
226  is_deleted = hist.GetDeleted().GetBool();
227  if (hist.GetDeleted().IsDate())
228  deleted_date->Assign(hist.GetDeleted().GetDate());
229  }
230  }
231  if (seq_ids_replaces.IsEmpty())
232  seq_ids_replaces.Add(wxEmptyString);
233  if (seq_ids_replaced_by.IsEmpty())
234  seq_ids_replaced_by.Add(wxEmptyString);
235 
236  wxStaticText* itemStaticText1 = new wxStaticText( itemDialog1, wxID_STATIC, _("Replaces Seq-id"), wxDefaultPosition, wxDefaultSize, 0 );
237  itemBoxSizer2->Add(itemStaticText1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
238 
239  m_IdListReplaces = new CGrowableListCtrl( itemDialog1,seq_ids_replaces, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
240  itemBoxSizer2->Add(m_IdListReplaces, 1, wxGROW|wxALL, 0);
241 
242  m_ReplacesDate = new CFlexibleDatePanel(itemDialog1, replaces_date);
243  itemBoxSizer2->Add(m_ReplacesDate, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
244 
245  wxStaticText* itemStaticText2 = new wxStaticText( itemDialog1, wxID_STATIC, _("Replaced By Seq-id"), wxDefaultPosition, wxDefaultSize, 0 );
246  itemBoxSizer2->Add(itemStaticText2, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
247 
248  m_IdListReplacedBy = new CGrowableListCtrl( itemDialog1,seq_ids_replaced_by, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
249  itemBoxSizer2->Add(m_IdListReplacedBy, 1, wxGROW|wxALL, 0);
250 
251  m_ReplacedByDate = new CFlexibleDatePanel(itemDialog1, replaced_by_date);
252  itemBoxSizer2->Add(m_ReplacedByDate, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
253 
254  wxStaticText* itemStaticText3 = new wxStaticText( itemDialog1, wxID_STATIC, _("Status"), wxDefaultPosition, wxDefaultSize, 0 );
255  itemBoxSizer2->Add(itemStaticText3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
256 
257  m_Deleted = new wxCheckBox( itemDialog1, wxID_ANY, _("Deleted"), wxDefaultPosition, wxDefaultSize, 0 );
258  itemBoxSizer2->Add(m_Deleted, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
259  m_Deleted->SetValue(is_deleted);
260 
261  m_DeletedDate = new CFlexibleDatePanel(itemDialog1, deleted_date);
262  itemBoxSizer2->Add(m_DeletedDate, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
263 
264 ////@end CEditHistory content construction
265  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
266  itemBoxSizer2->Add(itemBoxSizer6, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
267 
268  wxButton* itemButton7 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
269  itemBoxSizer6->Add(itemButton7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
270 
271  wxButton* itemButton8 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
272  itemBoxSizer6->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
273 
274 }
275 
276 
278 {
279  CRef<CCmdComposite> cmd(new CCmdComposite("Edit History"));
280 
281  CRef<CSeq_inst> new_inst(new CSeq_inst);
282  new_inst->Assign(m_Bioseq.GetBioseqCore()->GetInst());
283  new_inst->ResetHist();
284 
285  vector<string> replaces_ids;
286  m_IdListReplaces->GetItems(replaces_ids);
287  vector<string> replaced_ids;
288  m_IdListReplacedBy->GetItems(replaced_ids);
289 
290  for (size_t i = 0; i < replaces_ids.size(); i++)
291  {
292  CRef<CSeq_id> id(new CSeq_id(replaces_ids[i]));
293  new_inst->SetHist().SetReplaces().SetIds().push_back(id);
294  }
295 
296  for (size_t i = 0; i < replaced_ids.size(); i++)
297  {
298  CRef<CSeq_id> id(new CSeq_id(replaced_ids[i]));
299  new_inst->SetHist().SetReplaced_by().SetIds().push_back(id);
300  }
301 
302  if (m_ReplacesDate->GetDate())
303  new_inst->SetHist().SetReplaces().SetDate(*m_ReplacesDate->GetDate());
304  if (m_ReplacedByDate->GetDate())
305  new_inst->SetHist().SetReplaced_by().SetDate(*m_ReplacedByDate->GetDate());
306 
307  if (m_DeletedDate->GetDate())
308  new_inst->SetHist().SetDeleted().SetDate(*m_DeletedDate->GetDate());
309  if (m_Deleted->GetValue())
310  new_inst->SetHist().SetDeleted().SetBool(true);
311 
312  cmd->AddCommand(*CRef<CCmdChangeBioseqInst>(new CCmdChangeBioseqInst(m_Bioseq, *new_inst)));
313 
314  CSeq_entry_Handle seh = m_Bioseq.GetSeq_entry_Handle();
315  CRef<CSeqdesc> new_desc( new CSeqdesc );
316  CSeqdesc_CI desc_iter(seh, CSeqdesc::e_Genbank,1);
317  if (desc_iter)
318  {
319  new_desc->Assign(*desc_iter);
320  set<string> existing;
321  for (const auto &str : new_desc->GetGenbank().GetExtra_accessions())
322  {
323  existing.insert(str);
324  }
325  for (size_t i = 0; i < replaces_ids.size(); i++)
326  {
327  string str = replaces_ids[i];
328  if (existing.find(str) == existing.end())
329  {
330  new_desc->SetGenbank().SetExtra_accessions().push_back(str);
331  existing.insert(str);
332  }
333  }
334  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(desc_iter.GetSeq_entry_Handle(),*desc_iter, *new_desc));
335  cmd->AddCommand (*ecmd);
336  }
337  else
338  {
339  set<string> existing;
340  for (size_t i = 0; i < replaces_ids.size(); i++)
341  {
342  string str = replaces_ids[i];
343  if (existing.find(str) == existing.end())
344  {
345  new_desc->SetGenbank().SetExtra_accessions().push_back(str);
346  existing.insert(str);
347  }
348  }
349  cmd->AddCommand( *CRef<CCmdCreateDesc>(new CCmdCreateDesc(seh, *new_desc)) );
350  }
351 
352  return cmd;
353 }
354 
355 
356 /*!
357  * Should we show tooltips?
358  */
359 
361 {
362  return true;
363 }
364 
365 /*!
366  * Get bitmap resources
367  */
368 
369 wxBitmap CEditHistory::GetBitmapResource( const wxString& name )
370 {
371  // Bitmap retrieval
372 ////@begin CEditHistory bitmap retrieval
373  wxUnusedVar(name);
374  return wxNullBitmap;
375 ////@end CEditHistory bitmap retrieval
376 }
377 
378 /*!
379  * Get icon resources
380  */
381 
382 wxIcon CEditHistory::GetIconResource( const wxString& name )
383 {
384  // Icon retrieval
385 ////@begin CEditHistory icon retrieval
386  wxUnusedVar(name);
387  return wxNullIcon;
388 ////@end CEditHistory icon retrieval
389 }
390 
392 
393 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CBioseq_Handle –.
Definition: Date.hpp:53
wxCheckBox * m_Deleted
CFlexibleDatePanel * m_ReplacesDate
static bool ShowToolTips()
Should we show tooltips?
CRef< CCmdComposite > GetCommand()
CEditHistory()
Constructors.
~CEditHistory()
Destructor.
CFlexibleDatePanel * m_DeletedDate
CGrowableListCtrl * m_IdListReplacedBy
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Edit History"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
void Init()
Initialises member variables.
CGrowableListCtrl * m_IdListReplaces
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CFlexibleDatePanel * m_ReplacedByDate
objects::CBioseq_Handle m_Bioseq
CRef< objects::CDate > GetDate() const
void GetItems(vector< string > &items)
CScope –.
Definition: scope.hpp:92
CSeq_entry_Handle –.
CSeq_hist –.
Definition: Seq_hist.hpp:66
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
USING_SCOPE(objects)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
@ eContent
Definition: label.hpp:62
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Definition: seqdesc_ci.cpp:326
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NPOS
Definition: ncbistr.hpp:133
static bool EqualCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive equality of a substring with another string.
Definition: ncbistr.hpp:5325
static const char label[]
TExtra_accessions & SetExtra_accessions(void)
Assign a value to Extra_accessions data member.
Definition: GB_block_.hpp:460
const TExtra_accessions & GetExtra_accessions(void) const
Get the Extra_accessions member data.
Definition: GB_block_.hpp:454
bool IsSetDeleted(void) const
Check if a value has been assigned to Deleted data member.
Definition: Seq_hist_.hpp:567
bool IsSetReplaced_by(void) const
these seqs make this one obsolete Check if a value has been assigned to Replaced_by data member.
Definition: Seq_hist_.hpp:546
const TDeleted & GetDeleted(void) const
Get the Deleted member data.
Definition: Seq_hist_.hpp:579
bool IsSetIds(void) const
Check if a value has been assigned to Ids data member.
void SetHist(THist &value)
Assign a value to Hist data member.
Definition: Seq_inst_.cpp:164
TGenbank & SetGenbank(void)
Select the variant.
Definition: Seqdesc_.cpp:340
bool IsSetReplaces(void) const
seq makes these seqs obsolete Check if a value has been assigned to Replaces data member.
Definition: Seq_hist_.hpp:525
const TGenbank & GetGenbank(void) const
Get the variant data.
Definition: Seqdesc_.cpp:334
const TIds & GetIds(void) const
Get the Ids member data.
TBool GetBool(void) const
Get the variant data.
Definition: Seq_hist_.hpp:473
void ResetHist(void)
Reset Hist data member.
Definition: Seq_inst_.cpp:159
bool IsDate(void) const
Check if variant Date is selected.
Definition: Seq_hist_.hpp:494
bool IsSetDate(void) const
Check if a value has been assigned to Date data member.
const TReplaces & GetReplaces(void) const
Get the Replaces member data.
Definition: Seq_hist_.hpp:537
const TDate & GetDate(void) const
Get the Date member data.
const TReplaced_by & GetReplaced_by(void) const
Get the Replaced_by member data.
Definition: Seq_hist_.hpp:558
bool IsBool(void) const
Check if variant Bool is selected.
Definition: Seq_hist_.hpp:467
const TDate & GetDate(void) const
Get the variant data.
Definition: Seq_hist_.cpp:102
@ e_Genbank
GenBank specific info.
Definition: Seqdesc_.hpp:121
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
static static static wxID_ANY
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Sat May 25 14:22:37 2024 by modify_doxy.py rev. 669887