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

Go to the SVN repository for this file.

1 /* $Id: experiment_list_panel.cpp 47479 2023-05-02 13:24:02Z ucko $
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 #include <ncbi_pch.hpp>
31 ////@begin includes
32 ////@end includes
33 
36 
37 ////@begin XPM images
38 ////@end XPM images
39 
42 
43 /*!
44  * CExperimentListPanel type definition
45  */
46 
47 IMPLEMENT_DYNAMIC_CLASS( CExperimentListPanel, CFormattedQualPanel )
48 
49 
50 /*!
51  * CExperimentListPanel event table definition
52  */
53 
54 BEGIN_EVENT_TABLE( CExperimentListPanel, CFormattedQualPanel )
55 
56 ////@begin CExperimentListPanel event table entries
57 ////@end CExperimentListPanel event table entries
58 
60 
62 
63 
64 /*!
65  * CExperimentListPanel constructors
66  */
67 
69 {
70  Init();
71 }
72 
73 CExperimentListPanel::CExperimentListPanel( wxWindow* parent, CSerialObject& object, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
74 {
75  Init();
76  m_AllowUpdates = true;
77  m_Object = dynamic_cast<CSeq_feat*>(&object);
78  const CSeq_feat& seqfeat = dynamic_cast<const CSeq_feat&>(*m_Object);
79  m_EditedFeat.Reset((CSerialObject*)CSeq_feat::GetTypeInfo()->Create());
80  m_EditedFeat->Assign(seqfeat);
81  Create(parent, id, pos, size, style);
82 }
83 
84 
85 /*!
86  * CExperimentListPanel creator
87  */
88 
89 bool CExperimentListPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
90 {
91 ////@begin CExperimentListPanel creation
92  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
93  CFormattedQualPanel::Create( parent, id, pos, size, style );
94 
96  if (GetSizer())
97  {
98  GetSizer()->SetSizeHints(this);
99  }
100  Centre();
101 ////@end CExperimentListPanel creation
102  return true;
103 }
104 
105 
106 /*!
107  * CExperimentListPanel destructor
108  */
109 
111 {
112 ////@begin CExperimentListPanel destruction
113 ////@end CExperimentListPanel destruction
114 }
115 
116 
117 /*!
118  * Member initialisation
119  */
120 
122 {
123 ////@begin CExperimentListPanel member initialisation
125  m_Sizer = NULL;
126 ////@end CExperimentListPanel member initialisation
127 }
128 
129 
130 /*!
131  * Control creation for CExperimentListPanel
132  */
133 
135 {
136 ////@begin CExperimentListPanel content construction
137  CExperimentListPanel* itemCFormattedQualPanel1 = this;
138 
139  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
140  itemCFormattedQualPanel1->SetSizer(itemBoxSizer2);
141 
142  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
143  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_LEFT|wxALL, 0);
144 
145  wxStaticText* itemStaticText4 = new wxStaticText( itemCFormattedQualPanel1, wxID_STATIC, _("Category"), wxDefaultPosition, wxSize(120, -1), 0 );
146  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
147 
148  wxStaticText* itemStaticText5 = new wxStaticText( itemCFormattedQualPanel1, wxID_STATIC, _("Experiment"), wxDefaultPosition, wxSize(250, -1), 0 );
149  itemBoxSizer3->Add(itemStaticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
150 
151  wxStaticText* itemStaticText6 = new wxStaticText( itemCFormattedQualPanel1, wxID_STATIC, _("PMID or doi (optional)"), wxDefaultPosition, wxSize(120, -1), 0 );
152  itemBoxSizer3->Add(itemStaticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
153 
154  m_ScrolledWindow = new wxScrolledWindow( itemCFormattedQualPanel1, ID_SCROLLEDWINDOW, wxDefaultPosition, wxSize(300, 300), wxSUNKEN_BORDER|wxVSCROLL|wxTAB_TRAVERSAL );
155  itemBoxSizer2->Add(m_ScrolledWindow, 0, wxALIGN_LEFT|wxALL|wxFIXED_MINSIZE, 0);
156  m_ScrolledWindow->SetScrollbars(1, 1, 0, 0);
157  m_Sizer = new wxFlexGridSizer(0, 2, 0, 0);
158  m_ScrolledWindow->SetSizer(m_Sizer);
159 
160  m_ScrolledWindow->FitInside();
161 
162 ////@end CExperimentListPanel content construction
163 }
164 
165 
166 /*!
167  * Should we show tooltips?
168  */
169 
171 {
172  return true;
173 }
174 
175 /*!
176  * Get bitmap resources
177  */
178 
179 wxBitmap CExperimentListPanel::GetBitmapResource( const wxString& name )
180 {
181  // Bitmap retrieval
182 ////@begin CExperimentListPanel bitmap retrieval
183  wxUnusedVar(name);
184  return wxNullBitmap;
185 ////@end CExperimentListPanel bitmap retrieval
186 }
187 
188 /*!
189  * Get icon resources
190  */
191 
192 wxIcon CExperimentListPanel::GetIconResource( const wxString& name )
193 {
194  // Icon retrieval
195 ////@begin CExperimentListPanel icon retrieval
196  wxUnusedVar(name);
197  return wxNullIcon;
198 ////@end CExperimentListPanel icon retrieval
199 }
200 
201 
203 {
205  panel->SetValue(value);
206  m_Sizer->Add(panel, 0, wxGROW);
207 
208  wxHyperlinkCtrl* itemHyperlinkCtrl = new wxHyperlinkCtrl( m_ScrolledWindow, wxID_ANY,
209  wxT("Delete"), wxT(""), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
210  m_Sizer->Add(itemHyperlinkCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT, 5);
211 
212  x_AdjustForControl(panel, itemHyperlinkCtrl);
213 }
214 
215 
217 {
218  if (!wxPanel::TransferDataToWindow())
219  return false;
220 
221  m_AllowUpdates = false;
222 
223  m_TotalHeight = 0;
224  m_TotalWidth = 0;
225  m_ScrollRate = 0;
226  m_MinHeight = 0;
227  m_NumRows = 0;
228  bool add_last_blank = true;
229 
230  Freeze();
231  while (m_Sizer->GetItemCount() > 0) {
232  int pos = 0;
233  m_Sizer->GetItem(pos)->DeleteWindows();
234  m_Sizer->Remove(pos);
235  }
236  m_Sizer->Clear(true);
237  CSeq_feat& edited_feat = dynamic_cast<CSeq_feat&>(*m_EditedFeat);
238  if (edited_feat.IsSetQual()) {
239  CSeq_feat::TQual::iterator qual = edited_feat.SetQual().begin();
240  while (qual != edited_feat.SetQual().end()) {
241  if ((*qual)->IsSetQual() && NStr::EqualNocase((*qual)->GetQual(), "experiment")) {
242  string value = "";
243  if ((*qual)->IsSetVal()) {
244  value = (*qual)->GetVal();
245  }
246  if (keep_blanks || !NStr::IsBlank(value)) {
248  if (NStr::IsBlank(value)) {
249  add_last_blank = false;
250  } else {
251  add_last_blank = true;
252  }
253  }
254  }
255  qual++;
256  }
257  }
258  // add blank
259  if (add_last_blank) {
260  x_AddExperiment("");
261  }
262 
263  int win_height, win_width;
264  m_ScrolledWindow->SetVirtualSize(m_TotalWidth, m_TotalHeight);
265  m_ScrolledWindow->GetSize(&win_width, &win_height);
266  m_ScrolledWindow->SetScrollRate(0, m_ScrollRate);
267  m_ScrolledWindow->GetSize(&win_width, &win_height);
268  m_ScrolledWindow->FitInside();
269 // m_ScrolledWindow->GetSize(&win_width, &win_height);
270  Layout();
271 // m_ScrolledWindow->SetSize(m_TotalWidth + 20, 4 * m_MinHeight);
272  m_ScrolledWindow->SetMinSize(wxSize(m_TotalWidth + 20, 4 * m_MinHeight));
273  m_ScrolledWindow->GetSize(&win_width, &win_height);
274  Thaw();
275  m_AllowUpdates = true;
276  return true;
277 }
278 
279 
281 {
282  return x_SetExperiments();
283 }
284 
285 
286 
287 bool CExperimentListPanel::x_GetExperiments(bool keep_blanks, int skip_index)
288 {
289  if (!wxPanel::TransferDataFromWindow())
290  return false;
291 
292  CSeq_feat& edited_feat = dynamic_cast<CSeq_feat&>(*m_EditedFeat);
293  edited_feat.ResetQual();
294 
295  int pos = 0;
296  wxSizerItemList::iterator node = m_Sizer->GetChildren().begin();
297  for (; node != m_Sizer->GetChildren().end(); ++node) {
298  wxWindow *w = (*node)->GetWindow();
299  if (!w) {
300  continue;
301  }
302  CSingleExperimentPanel* singlequal_panel = dynamic_cast<CSingleExperimentPanel*> (w);
303  if (singlequal_panel) {
304  if (pos != skip_index) {
305  string value = singlequal_panel->GetValue();
306  if (keep_blanks || !NStr::IsBlank(value)) {
307  CRef<CGb_qual> edited_qual (new CGb_qual("experiment", value));
308  edited_feat.SetQual().push_back(edited_qual);
309  }
310  }
311  pos++;
312  }
313  }
314  return true;
315 }
316 
317 
319 {
320  return x_GetExperiments();
321 }
322 
323 
325 {
326  if (!m_AllowUpdates) {
327  return;
328  }
329  // is the row being changed the last one?
330  wxSizerItemList& itemList = m_Sizer->GetChildren();
331  auto num_items = itemList.size();
332  if (num_items > 1 && wnd == (itemList[num_items - 2])->GetWindow()) {
333 
334 // x_GetExperiments(true);
335 // x_SetExperiments(true);
336  x_AddExperiment("");
337  int win_height, win_width;
338  m_ScrolledWindow->SetVirtualSize(m_TotalWidth, m_TotalHeight);
339  m_ScrolledWindow->GetSize(&win_width, &win_height);
340  m_ScrolledWindow->SetScrollRate(0, m_ScrollRate);
341  m_ScrolledWindow->GetSize(&win_width, &win_height);
342  m_ScrolledWindow->FitInside();
343 // m_ScrolledWindow->GetSize(&win_width, &win_height);
344  Layout();
345 // m_ScrolledWindow->SetSize(m_TotalWidth + 20, 4 * m_MinHeight);
346  m_ScrolledWindow->SetMinSize(wxSize(m_TotalWidth + 20, 4 * m_MinHeight));
347  m_ScrolledWindow->GetSize(&win_width, &win_height);
348  }
349 }
350 
351 
352 void CExperimentListPanel::PopulateGBQuals(objects::CSeq_feat& seq_feat)
353 {
355  CSeq_feat& edited_feat = dynamic_cast<CSeq_feat&>(*m_EditedFeat);
356  RemoveRepresentedQuals(seq_feat, "experiment");
357 
358  for (CSeq_feat::TQual::iterator qual = edited_feat.SetQual().begin();
359  qual != edited_feat.SetQual().end();
360  qual++) {
361  if ((*qual)->IsSetQual() && !NStr::IsBlank((*qual)->GetQual())
362  && NStr::EqualNocase((*qual)->GetQual(), "experiment")
363  && (*qual)->IsSetVal() && !NStr::IsBlank((*qual)->GetVal())) {
364  CRef<CGb_qual> new_qual(new CGb_qual());
365  new_qual->Assign(**qual);
366 
367  seq_feat.SetQual().push_back(new_qual);
368  }
369  }
370 }
371 
372 
373 int CExperimentListPanel::x_FindRow(wxWindow* wnd, wxSizerItemList& itemList)
374 {
375  if (NULL == wnd)
376  return -1;
377 
378  // start with -1, first qual found will bump it to 0
379  int row_num = -1;
380  for(wxSizerItemList::iterator it = itemList.begin(); it != itemList.end(); ++it) {
381  wxWindow* child = (**it).GetWindow();
382  if (child && child == wnd)
383  return row_num;
384 
385  CFormattedQualPanel* qual = dynamic_cast<CFormattedQualPanel*> (child);
386  if (qual) {
387  row_num++;
388  }
389  }
390 
391  return -1;
392 }
393 
394 
395 void CExperimentListPanel::OnDelete (wxHyperlinkEvent& event)
396 {
397  // find the control, remove it and the item before it, reset the scrolling
398  wxWindow* wnd = (wxWindow*)event.GetEventObject();
399  if (wnd == NULL) {
400  return;
401  }
402  wxSizerItemList& itemList = m_Sizer->GetChildren();
403  int row = x_FindRow (wnd, itemList);
404  if (row > -1) {
405  x_GetExperiments(true, row);
406  x_SetExperiments(true);
407  }
408 }
409 
410 
bool x_GetExperiments(bool keep_blanks=false, int skip_index=-1)
void PopulateGBQuals(objects::CSeq_feat &seq_feat)
virtual void OnChildChange(wxWindow *wnd)
static bool ShowToolTips()
Should we show tooltips?
void x_AddExperiment(string value)
void OnDelete(wxHyperlinkEvent &event)
wxScrolledWindow * m_ScrolledWindow
virtual bool TransferDataFromWindow()
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
int x_FindRow(wxWindow *wnd, wxSizerItemList &itemList)
bool Create(wxWindow *parent, wxWindowID id=ID_CINFERENCELISTPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CRef< CSerialObject > m_EditedFeat
CExperimentListPanel()
Constructors.
void CreateControls()
Creates the controls and sizers.
void Init()
Initialises member variables.
bool x_SetExperiments(bool keep_blanks=false)
@Gb_qual.hpp User-defined methods of the data storage class.
Definition: Gb_qual.hpp:61
static void RemoveRepresentedQuals(objects::CSeq_feat &feat, const string &qual_name)
virtual void x_AdjustForControl(CQualListItemPanel *panel, wxHyperlinkCtrl *itemHyperlinkCtrl)
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Base class for all serializable objects.
Definition: serialbase.hpp:150
virtual void SetValue(string val)
char value[7]
Definition: config.c:431
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define wxFIXED_MINSIZE
USING_SCOPE(objects)
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5352
bool IsSetQual(void) const
qualifiers Check if a value has been assigned to Qual data member.
Definition: Seq_feat_.hpp:1135
TQual & SetQual(void)
Assign a value to Qual data member.
Definition: Seq_feat_.hpp:1153
void ResetQual(void)
Reset Qual data member.
Definition: Seq_feat_.cpp:136
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
Modified on Sat Dec 09 04:48:37 2023 by modify_doxy.py rev. 669887