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

Go to the SVN repository for this file.

1 /* $Id: citations_panel.cpp 47067 2022-06-29 15:20:07Z 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: Colleen Bollin
27  */
28 
29 
30 // Generated by DialogBlocks (unregistered), 29/12/2011 15:47:45
31 
32 #include <ncbi_pch.hpp>
33 #include <objects/seq/Pubdesc.hpp>
34 #include <objects/pub/Pub_set.hpp>
39 #include <objmgr/seqdesc_ci.hpp>
40 #include <objmgr/feat_ci.hpp>
43 #include <gui/objutils/utils.hpp>
44 
45 ////@begin includes
46 ////@end includes
47 
48 #include "citations_panel.hpp"
49 
50 ////@begin XPM images
51 ////@end XPM images
52 
55 
56 /*!
57  * CCitationsPanel type definition
58  */
59 
60 IMPLEMENT_DYNAMIC_CLASS( CCitationsPanel, wxPanel )
61 
62 
63 /*!
64  * CCitationsPanel event table definition
65  */
66 
67 BEGIN_EVENT_TABLE( CCitationsPanel, wxPanel )
68 
69 ////@begin CCitationsPanel event table entries
70 ////@end CCitationsPanel event table entries
71 
73 
74 
75 /*!
76  * CCitationsPanel constructors
77  */
78 
80 {
81  Init();
82 }
83 
84 CCitationsPanel::CCitationsPanel( wxWindow* parent, CSeq_feat& seq_feat, CScope& scope,
85  wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
86  : m_EditedFeat(new CSeq_feat()), m_Scope(&scope)
87 {
88  Init();
89  m_EditedFeat->Assign(seq_feat);
90 
91  Create(parent, id, pos, size, style);
92 }
93 
94 
95 /*!
96  * CCitationsPanel creator
97  */
98 
99 bool CCitationsPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
100 {
101 ////@begin CCitationsPanel creation
102  wxPanel::Create( parent, id, pos, size, style );
103 
104  CreateControls();
105  if (GetSizer())
106  {
107  GetSizer()->SetSizeHints(this);
108  }
109  Centre();
110 ////@end CCitationsPanel creation
111  return true;
112 }
113 
114 
115 /*!
116  * CCitationsPanel destructor
117  */
118 
120 {
121 ////@begin CCitationsPanel destruction
122 ////@end CCitationsPanel destruction
123 }
124 
125 
126 /*!
127  * Member initialisation
128  */
129 
131 {
132 ////@begin CCitationsPanel member initialisation
134  m_Sizer = NULL;
135 ////@end CCitationsPanel member initialisation
136 }
137 
138 
139 /*!
140  * Control creation for CCitationsPanel
141  */
142 
144 {
145 ////@begin CCitationsPanel content construction
146  // Generated by DialogBlocks, 11/01/2012 09:28:33 (unregistered)
147 
148  CCitationsPanel* itemPanel1 = this;
149 
150  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
151  itemPanel1->SetSizer(itemBoxSizer2);
152 
153  m_ScrolledWindow = new wxScrolledWindow( itemPanel1, ID_SCROLLEDWINDOW5, wxDefaultPosition, wxSize(100, 100), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
155  m_ScrolledWindow->SetToolTip(_("The use of citations on features is discouraged. Use this to indicate citations that apply specifically to this feature."));
156  itemBoxSizer2->Add(m_ScrolledWindow, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
157  m_ScrolledWindow->SetScrollbars(1, 1, 0, 0);
158  m_Sizer = new wxBoxSizer(wxVERTICAL);
159  m_ScrolledWindow->SetSizer(m_Sizer);
160 
161  m_ScrolledWindow->FitInside();
162 
163 ////@end CCitationsPanel content construction
164  // add citations
165  m_PubList.clear();
166 
167  int total_height = 0;
168  int total_width = 0;
169  int scroll_rate = 0;
170 
171  // first get descriptor pubs
173  if (bsh) {
174  CSeqdesc_CI di(bsh, CSeqdesc::e_Pub);
175  while (di) {
176  vector<TEntrezId> pmids;
177  vector<TEntrezId> muids;
178  vector<int> serials;
179  vector<string> published_labels;
180  vector<string> unpublished_labels;
181  GetPubdescLabels(di->GetPub(), pmids, muids, serials, published_labels, unpublished_labels);
182  bool can_cit = true;
183  if (pmids.size() > 0) {
184  CRef<CPub> pub(new CPub());
185  pub->SetPmid().Set(pmids[0]);
186  m_PubList.push_back(pub);
187  } else if (muids.size() > 0) {
188  CRef<CPub> pub(new CPub());
189  pub->SetMuid(muids[0]);
190  m_PubList.push_back(pub);
191  } else if (serials.size() > 0) {
192  CRef<CPub> pub(new CPub());
193  pub->SetGen().SetSerial_number(serials[0]);
194  m_PubList.push_back(pub);
195  } else if (published_labels.size() > 0) {
196  CRef<CPub> pub(new CPub());
197  pub->SetGen().SetCit(published_labels[0]);
198  m_PubList.push_back(pub);
199  } else if (unpublished_labels.size() > 0) {
200  CRef<CPub> pub(new CPub());
201  pub->SetGen().SetCit(unpublished_labels[0]);
202  m_PubList.push_back(pub);
203  } else {
204  can_cit = false;
205  }
206 
207  if (can_cit) {
208  string label = "";
210  if (NStr::IsBlank(label)) {
211  m_PubList.back()->GetLabel(&label, CPub::eContent, true);
212  }
213  wxCheckBox* checkbox = new wxCheckBox(m_ScrolledWindow, wxID_ANY, ToWxString(label));
214  m_Sizer->Add(checkbox);
215  m_Checkboxes.push_back(checkbox);
216  int win_height, win_width;
217  checkbox->GetSize(&win_width, &win_height);
218  total_height += win_height;
219  scroll_rate = win_height;
220  if (total_width < win_width) {
221  total_width = win_width;
222  }
223  }
224  ++di;
225  }
226  // now get pub features
228  while (fi) {
229  vector<TEntrezId> pmids;
230  vector<TEntrezId> muids;
231  vector<int> serials;
232  vector<string> published_labels;
233  vector<string> unpublished_labels;
234  GetPubdescLabels(fi->GetData().GetPub(), pmids, muids, serials, published_labels, unpublished_labels);
235  bool can_cit = true;
236  if (pmids.size() > 0) {
237  CRef<CPub> pub(new CPub());
238  pub->SetPmid().Set(pmids[0]);
239  m_PubList.push_back(pub);
240  } else if (muids.size() > 0) {
241  CRef<CPub> pub(new CPub());
242  pub->SetMuid(muids[0]);
243  m_PubList.push_back(pub);
244  } else if (serials.size() > 0) {
245  CRef<CPub> pub(new CPub());
246  pub->SetGen().SetSerial_number(serials[0]);
247  m_PubList.push_back(pub);
248  } else if (published_labels.size() > 0) {
249  CRef<CPub> pub(new CPub());
250  pub->SetGen().SetCit(published_labels[0]);
251  m_PubList.push_back(pub);
252  } else if (unpublished_labels.size() > 0) {
253  CRef<CPub> pub(new CPub());
254  pub->SetGen().SetCit(unpublished_labels[0]);
255  m_PubList.push_back(pub);
256  } else {
257  can_cit = false;
258  }
259 
260  if (can_cit) {
261  string label = "";
262  fi->GetData().GetPub().GetPub().GetLabel(&label);
263  if (NStr::IsBlank(label)) {
264  m_PubList.back()->GetLabel(&label, CPub::eContent, true);
265  }
266  wxCheckBox* checkbox = new wxCheckBox(m_ScrolledWindow, wxID_ANY, ToWxString(label));
267  m_Sizer->Add(checkbox);
268  m_Checkboxes.push_back(checkbox);
269  int win_height, win_width;
270  checkbox->GetSize(&win_width, &win_height);
271  total_height += win_height;
272  scroll_rate = win_height;
273  if (total_width < win_width) {
274  total_width = win_width;
275  }
276  }
277  ++fi;
278  }
279  }
280 
281  m_ScrolledWindow->SetVirtualSize(total_width, total_height);
282  m_ScrolledWindow->SetScrollRate(0, scroll_rate);
283  m_ScrolledWindow->FitInside();
284  Layout();
285 
286 // m_ScrolledWindow->SetSize(total_width + 20, 20 * scroll_rate);
287  m_ScrolledWindow->SetMinSize(wxSize(total_width + 20, 20 * scroll_rate));
288 }
289 
290 
291 static bool s_DoPubsMatch (const CCit_gen& a, const CCit_gen& b)
292 {
293  if (a.IsSetSerial_number() && b.IsSetSerial_number()
294  && a.GetSerial_number() == b.GetSerial_number()) {
295  return true;
296  } else if (a.IsSetSerial_number() || b.IsSetSerial_number()) {
297  return false;
298  } else if (a.IsSetCit() && b.IsSetCit()) {
299  string x = a.GetCit();
300  string y = b.GetCit();
301  return (NStr::StartsWith(x, y) || NStr::StartsWith(y, x));
302  } else {
303  return false;
304  }
305 }
306 
307 
308 bool s_DoPubsMatch (const CPub& a, const CPub& b)
309 {
310  if (a.IsGen() && b.IsGen()) {
311  return s_DoPubsMatch (a.GetGen(), b.GetGen());
312  } else if (a.IsPmid() && b.IsPmid()) {
313  return (a.GetPmid().Get() == b.GetPmid().Get());
314  } else if (a.IsMuid() && b.IsMuid()) {
315  return (a.GetMuid() == b.GetMuid());
316  } else{
317  return false;
318  }
319 }
320 
321 
323 {
324  if (!wxPanel::TransferDataToWindow())
325  return false;
326 
327  for (unsigned int i=0; i < m_Checkboxes.size(); i++) {
328  m_Checkboxes[i]->SetValue(false);
329  }
330 
331  if (m_EditedFeat->IsSetCit()) {
332  ITERATE( CPub_set::TPub, it, m_EditedFeat->GetCit().GetPub() ) {
333  for (unsigned int i = 0; i < m_PubList.size() && i < m_Checkboxes.size(); i++) {
334  if (s_DoPubsMatch(**it, *m_PubList[i])) {
335  m_Checkboxes[i]->SetValue(true);
336  break;
337  }
338  }
339  }
340  }
341 
342  return true;
343 }
344 
345 
347 {
348  if (!wxPanel::TransferDataFromWindow())
349  return false;
350 
351  m_EditedFeat->ResetCit();
352  for (unsigned int i = 0; i < m_PubList.size() && i < m_Checkboxes.size(); i++) {
353  if (m_Checkboxes[i]->GetValue()) {
354  CRef<CPub> cit(new CPub());
355  cit->Assign(*m_PubList[i]);
356  m_EditedFeat->SetCit().SetPub().push_back(cit);
357  }
358  }
359 
360  return true;
361 }
362 
363 
365 {
367  seq_feat.ResetCit();
368  if (m_EditedFeat->IsSetCit()) {
369  ITERATE( CPub_set::TPub, it, m_EditedFeat->GetCit().GetPub() ) {
370  CRef<CPub> cit(new CPub());
371  cit->Assign(**it);
372  seq_feat.SetCit().SetPub().push_back(cit);
373  }
374  }
375 }
376 
377 
378 /*!
379  * Should we show tooltips?
380  */
381 
383 {
384  return true;
385 }
386 
387 /*!
388  * Get bitmap resources
389  */
390 
391 wxBitmap CCitationsPanel::GetBitmapResource( const wxString& name )
392 {
393  // Bitmap retrieval
394 ////@begin CCitationsPanel bitmap retrieval
395  wxUnusedVar(name);
396  return wxNullBitmap;
397 ////@end CCitationsPanel bitmap retrieval
398 }
399 
400 /*!
401  * Get icon resources
402  */
403 
404 wxIcon CCitationsPanel::GetIconResource( const wxString& name )
405 {
406  // Icon retrieval
407 ////@begin CCitationsPanel icon retrieval
408  wxUnusedVar(name);
409  return wxNullIcon;
410 ////@end CCitationsPanel icon retrieval
411 }
412 
static CRef< CScope > m_Scope
User-defined methods of the data storage class.
User-defined methods of the data storage class.
USING_SCOPE(objects)
static bool s_DoPubsMatch(const CCit_gen &a, const CCit_gen &b)
CBioseq_Handle –.
virtual bool TransferDataFromWindow()
wxBoxSizer * m_Sizer
~CCitationsPanel()
Destructor.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void SetCitations(objects::CSeq_feat &seq_feat)
vector< wxCheckBox * > m_Checkboxes
wxScrolledWindow * m_ScrolledWindow
CCitationsPanel()
Constructors.
static bool ShowToolTips()
Should we show tooltips?
vector< CRef< objects::CPub > > m_PubList
virtual bool TransferDataToWindow()
void Init()
Initialises member variables.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=ID_CCITATIONSPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void CreateControls()
Creates the controls and sizers.
objects::CScope * m_Scope
CRef< objects::CSeq_feat > m_EditedFeat
CFeat_CI –.
Definition: feat_ci.hpp:64
Definition: Pub.hpp:56
@ eContent
Definition: Pub.hpp:66
CScope –.
Definition: scope.hpp:92
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
void GetLabel(string *const label, ELabelType label_type) const
Definition: Seqdesc.cpp:134
@ eContent
Definition: Seqdesc.hpp:61
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
objects::CBioseq_Handle GetBioseqForSeqFeat(const objects::CSeq_feat &f, objects::CScope &scope)
TPrim & Set(void)
Definition: serialbase.hpp:351
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
#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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5411
static const char label[]
void SetSerial_number(TSerial_number value)
Assign a value to Serial_number data member.
Definition: Cit_gen_.hpp:902
void SetCit(const TCit &value)
Assign a value to Cit data member.
Definition: Cit_gen_.hpp:597
TPmid & SetPmid(void)
Select the variant.
Definition: Pub_.hpp:690
TMuid & SetMuid(void)
Select the variant.
Definition: Pub_.hpp:615
list< CRef< CPub > > TPub
Definition: Pub_set_.hpp:159
TGen & SetGen(void)
Select the variant.
Definition: Pub_.cpp:173
void SetCit(TCit &value)
Assign a value to Cit data member.
Definition: Seq_feat_.cpp:170
void ResetCit(void)
Reset Cit data member.
Definition: Seq_feat_.cpp:165
@ e_Pub
publication applies to this seq
const TPub & GetPub(void) const
Get the variant data.
Definition: Seqdesc_.cpp:356
@ e_Pub
a reference to the publication
Definition: Seqdesc_.hpp:122
void GetPubdescLabels(const objects::CPubdesc &pd, vector< TEntrezId > &pmids, vector< TEntrezId > &muids, vector< int > &serials, vector< string > &published_labels, vector< string > &unpublished_labels)
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
unsigned int a
Definition: ncbi_localip.c:102
#define fi
static static static wxID_ANY
SAnnotSelector –.
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Sat Dec 02 09:22:26 2023 by modify_doxy.py rev. 669887