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

Go to the SVN repository for this file.

1 /* $Id: srcmod_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: Vasuki Palanigobu
27  */
28 
29 
30 // For compilers that support precompilation, includes "wx/wx.h".
31 #include "wx/wxprec.h"
32 
33 #ifdef __BORLANDC__
34 #pragma hdrstop
35 #endif
36 
37 #ifndef WX_PRECOMP
38 #include "wx/wx.h"
39 #endif
40 
41 ////@begin includes
42 ////@end includes
43 #include <ncbi_pch.hpp>
47 #include "srcmod_list_panel.hpp"
48 
51 
52 ////@begin XPM images
53 ////@end XPM images
54 
55 
56 /*
57  * CSrcModPanel type definition
58  */
59 
60 IMPLEMENT_DYNAMIC_CLASS( CSrcModPanel, wxPanel )
61 
62 
63 /*
64  * CSrcModPanel event table definition
65  */
66 
67 BEGIN_EVENT_TABLE( CSrcModPanel, wxPanel )
68 
69 ////@begin CSrcModPanel event table entries
71 
72 ////@end CSrcModPanel event table entries
74 
75 
76 /*
77  * CSrcModPanel constructors
78  */
79 
81 {
82  Init();
83 }
84 
85 CSrcModPanel::CSrcModPanel( wxWindow* parent, SModData mod_data, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
86 {
87  m_ModData = mod_data;
88  Init();
89  Create(parent, id, pos, size, style);
90 }
91 
92 
93 /*
94  * SrcModPanel creator
95  */
96 
97 bool CSrcModPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
98 {
99 ////@begin CSrcModPanel creation
100  wxPanel::Create( parent, id, pos, size, style );
101 
102  CreateControls();
103  if (GetSizer())
104  {
105  GetSizer()->SetSizeHints(this);
106  }
107  Centre();
108 ////@end CSrcModPanel creation
109  return true;
110 }
111 
112 
113 /*
114  * CSrcModPanel destructor
115  */
116 
118 {
119 ////@begin CSrcModPanel destruction
120 ////@end CSrcModPanel destruction
121 }
122 
123 
124 /*
125  * Member initialisation
126  */
127 
129 {
130 ////@begin CSrcModPanel member initialisation
131  m_Sizer = NULL;
132  m_SrcModName = NULL;
134 ////@end CSrcModPanel member initialisation
135  m_Editor = NULL;
136 }
137 
138 
139 /*
140  * Control creation for SrcModPanel
141  */
142 
144 {
145 ////@begin CSrcModPanel content construction
146  CSrcModPanel* itemPanel1 = this;
147 
148  m_Sizer = new wxBoxSizer(wxHORIZONTAL);
149  itemPanel1->SetSizer(m_Sizer);
150 
151  wxArrayString m_SrcModNameStrings = s_GetModifierList();
152  m_SrcModName = new wxComboBox( itemPanel1, ID_MODIFIER_NAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_SrcModNameStrings, wxCB_READONLY );
153  m_SrcModName->Bind(wxEVT_LEFT_DOWN, &CSrcModPanel::OnLeftDown, this);
154  m_SrcModName->Bind(wxEVT_LEFT_UP, &CSrcModPanel::OnLeftUp, this);
155 #ifdef __WXOSX_COCOA__
156  m_SrcModName->SetSelection(-1);
157 #endif
158  m_Sizer->Add(m_SrcModName, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
159 
160  m_Sizer->Add(300, 10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
161 
162 ////@end CSrcModPanel content construction
163 }
164 
165 
167 {
169  return false;
170  }
171  return COrgMod::IsDiscouraged(st, true);
172 }
173 
174 
176 {
178  return true;
179  }
180  return CSubSource::IsDiscouraged(st);
181 }
182 
183 
184 namespace {
185  wxString s_AdjustModNameForDisplay(const string& orig)
186  {
187  string adjusted = orig;
188  if (NStr::EqualNocase(adjusted, kNatHost)) {
189  adjusted = kHost;
190  }
191  return ToWxString(adjusted);
192  }
193 
194  wxString s_AdjustDisplayNameForModName(const wxString& display)
195  {
196  string adjusted = ToStdString(display);
197  if (NStr::EqualNocase(adjusted, kHost)) {
198  adjusted = ToWxString(kNatHost);
199  }
200  return adjusted;
201  }
202 
203  bool s_DoNotListSubSource(int st)
204  {
206  return true;
207  }
208  return CSubSource::IsDiscouraged(st);
209  }
210 
211 
212  bool s_DoNotListOrgMod(int st)
213  {
215  return false;
216  }
217  return COrgMod::IsDiscouraged(st, true);
218  }
219 }
220 
222 {
223  wxArrayString choices;
224  int i;
225  for (i = 0; i < objects::CSubSource::eSubtype_other; i++) {
226  try {
227  string qual_name = objects::CSubSource::GetSubtypeName(i);
228  if (!NStr::IsBlank(qual_name) && !DoNotListSubSrc(i)) {
229  choices.push_back(s_AdjustModNameForDisplay(qual_name));
230  }
231 
232  }
233  catch (const exception&) {
234  }
235  }
236  for (i = 0; i < objects::COrgMod::eSubtype_other; i++) {
237  try {
238  string qual_name = objects::COrgMod::GetSubtypeName(i);
239  if (!NStr::IsBlank(qual_name) && !s_DoNotListOrgMod(i)) {
240  // special case for nat-host
241  choices.push_back(s_AdjustModNameForDisplay(qual_name));
242  }
243 
244  }
245  catch (const exception&) {
246  }
247  }
248  choices.Sort();
249  return choices;
250 }
251 
252 
253 
255 {
256  string val = ToStdString(m_ModData.value);
257  if (m_Editor && m_Editor->GetEditorType() == editor_type && m_Editor->IsWellFormatted(val)) {
258  if (editor_type == CSrcModEditPanel::eCheckbox) {
259  m_Editor->SetValue("true");
260  OnEditorChange();
261  } else {
263  }
264  return;
265  }
266  auto old_editor_type = editor_type;
267  if (m_Editor)
268  old_editor_type = m_Editor->GetEditorType();
269  while (m_Sizer->GetItemCount() > 1) {
270  int pos = 1;
271  m_Sizer->GetItem(pos)->DeleteWindows();
272  m_Sizer->Remove(pos);
273  }
274  m_Editor = CSrcModEditFactory::Create(this, editor_type);
275  if (!m_Editor || !m_Editor->IsWellFormatted(val)) {
276  delete m_Editor;
278  editor_type = CSrcModEditPanel::eText;
279  }
280  if (m_Editor) {
281  m_Sizer->Add(m_Editor, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
282  if (editor_type == CSrcModEditPanel::eCheckbox) {
283  m_Editor->SetValue("true");
284  OnEditorChange();
285  } else if (old_editor_type != CSrcModEditPanel::eCheckbox) {
287  }
288  }
289  Layout();
290 
291 }
292 
293 
295 {
296  string mod_name = ToStdString(m_ModData.name);
297  m_SrcModName->SetValue(s_AdjustModNameForDisplay(mod_name));
298  if (NStr::IsBlank(mod_name)) {
299  return;
300  }
301 
303  bool is_subsource = objects::CSubSource::IsValidSubtypeName(mod_name, objects::CSubSource::eVocabulary_insdc);
304  if (is_subsource) {
305  CSubSource::TSubtype st = objects::CSubSource::GetSubtypeValue (mod_name, objects::CSubSource::eVocabulary_insdc);
307  }
308  else {
309  bool is_orgmod = objects::COrgMod::IsValidSubtypeName(mod_name, objects::COrgMod::eVocabulary_insdc);
310  if (is_orgmod) {
311  COrgMod::TSubtype st = objects::COrgMod::GetSubtypeValue(mod_name, objects::COrgMod::eVocabulary_insdc);
313  }
314  }
315  x_SetEditor(editor_type);
316 }
317 
318 
320 {
321  wxString mod = m_SrcModName->GetStringSelection();
322  m_ModData.name = s_AdjustDisplayNameForModName(mod);
323  if (m_Editor) {
325  }
326  return m_ModData;
327 }
328 
329 
330 /*
331  * Should we show tooltips?
332  */
333 
335 {
336  return true;
337 }
338 
339 /*
340  * Get bitmap resources
341  */
342 
343 wxBitmap CSrcModPanel::GetBitmapResource( const wxString& name )
344 {
345  // Bitmap retrieval
346 ////@begin CSrcModPanel bitmap retrieval
347  wxUnusedVar(name);
348  return wxNullBitmap;
349 ////@end CSrcModPanel bitmap retrieval
350 }
351 
352 /*
353  * Get icon resources
354  */
355 
356 wxIcon CSrcModPanel::GetIconResource( const wxString& name )
357 {
358  // Icon retrieval
359 ////@begin CSrcModPanel icon retrieval
360  wxUnusedVar(name);
361  return wxNullIcon;
362 ////@end CSrcModPanel icon retrieval
363 }
364 
365 
367 {
368  if (!m_Editor) {
369  return;
370  }
371  string val = m_Editor->GetValue();
372  if (NStr::IsBlank(val)) {
373  return;
374  }
375 
376  wxWindow* parent = this->GetParent();
377 
378  CSrcModListPanel* listpanel = dynamic_cast<CSrcModListPanel*>(parent);
379 
380  while (parent && !listpanel) {
381  parent = parent->GetParent();
382  listpanel = dynamic_cast<CSrcModListPanel*>(parent);
383  }
384 
385  if (!listpanel) {
386  return;
387  }
388  listpanel->AddLastSrcMod((wxWindow*)this);
389 }
390 
391 
392 /*
393  * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_MODIFIER_NAME
394  */
395 
396 void CSrcModPanel::OnModifierNameSelected( wxCommandEvent& event )
397 {
398  GetModifierData();
399  SetModifierData();
400 }
401 
402 void CSrcModPanel::OnLeftDown( wxMouseEvent& event)
403 {
404  m_Selected = ToStdString(m_SrcModName->GetStringSelection());
405  event.Skip();
406 }
407 
408 void CSrcModPanel::OnLeftUp( wxMouseEvent& event)
409 {
410  string current = ToStdString(m_SrcModName->GetString(m_SrcModName->GetCurrentSelection()));
411  m_SrcModName->SetSelection(m_SrcModName->GetCurrentSelection());
412  if ( ! NStr::Equal(current, m_Selected, NStr::eNocase)) {
413  GetModifierData();
414  SetModifierData();
415  }
416  event.Skip();
417 }
418 
419 
420 void CSrcModPanel::SetModifierData(const string& mod_name, const string& mod_val)
421 {
422  m_ModData.name = ToWxString(mod_name);
423  m_ModData.value = ToWxString(mod_val);
424  SetModifierData();
425 }
426 
427 
429 
static string GetSubtypeName(const CSubSource &qual)
static bool IsDiscouraged(const TSubtype stype, bool indexer=false)
Definition: OrgMod.cpp:159
static CSrcModEditPanel * Create(wxWindow *parent, CSrcModEditPanel::EEditorType editor_type)
static EEditorType GetEditorTypeForSubSource(objects::CSubSource::TSubtype st)
static EEditorType GetEditorTypeForOrgMod(objects::COrgMod::TSubtype st)
virtual string GetValue()=0
EEditorType GetEditorType()
virtual bool IsWellFormatted(const string &val)=0
virtual void SetValue(const string &val)=0
void AddLastSrcMod(wxWindow *link)
bool Create(wxWindow *parent, wxWindowID id=10013, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void OnEditorChange()
const SModData & GetModifierData()
void x_SetEditor(CSrcModEditPanel::EEditorType editor_type)
void Init()
Initialises member variables.
CSrcModPanel()
Constructors.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void SetModifierData()
virtual bool DoNotListOrgMod(int st)
static bool ShowToolTips()
Should we show tooltips?
SModData m_ModData
virtual bool DoNotListSubSrc(int st)
void OnLeftDown(wxMouseEvent &event)
wxArrayString s_GetModifierList()
CSrcModEditPanel * m_Editor
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnModifierNameSelected(wxCommandEvent &event)
wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_MODIFIER_NAME
void CreateControls()
Creates the controls and sizers.
void OnLeftUp(wxMouseEvent &event)
~CSrcModPanel()
Destructor.
wxComboBox * m_SrcModName
wxBoxSizer * m_Sizer
static bool IsDiscouraged(const TSubtype subtype)
Definition: SubSource.cpp:245
static void Init(void)
Definition: cursor6.c:76
const char * kNatHost
const char * kHost
#define NULL
Definition: ncbistd.hpp:225
#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 kEmptyStr
Definition: ncbistr.hpp:123
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:5353
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
@ eSubtype_fwd_primer_seq
sequence (possibly more than one; semicolon-separated)
Definition: SubSource_.hpp:117
@ eSubtype_old_name
Definition: OrgMod_.hpp:124
@ eSubtype_old_lineage
Definition: OrgMod_.hpp:123
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is orig
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
Int mod(Int i, Int j)
Definition: njn_integer.hpp:67
bool s_DoNotListOrgMod(int st)
USING_SCOPE(objects)
#define ID_MODIFIER_NAME
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sat Mar 02 10:52:59 2024 by modify_doxy.py rev. 669887