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

Go to the SVN repository for this file.

1 /* $Id: latlon_tool.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: Igor Filippov
27  */
28 #include <ncbi_pch.hpp>
30 #include <objmgr/feat_ci.hpp>
31 #include <objmgr/bioseq_ci.hpp>
42 #include <wx/msgdlg.h>
43 
45 
48 
49 
50 
51 IMPLEMENT_DYNAMIC_CLASS( CLatLonTool, wxDialog )
52 
53 BEGIN_EVENT_TABLE( CLatLonTool, wxDialog )
54 
55  EVT_BUTTON( wxID_OK, CLatLonTool::OnClickOk )
56 
57  EVT_BUTTON( wxID_CANCEL, CLatLonTool::OnClickCancel )
58 
59 
61 
63 {
64  Init();
65 }
66 
67 CLatLonTool::CLatLonTool( wxWindow* parent, CSeq_entry_Handle seh,
68  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) : m_TopSeqEntry(seh)
69 {
71  for ( ; b_iter ; ++b_iter )
72  {
73  m_Found = false;
74  x_FindBioSource(b_iter->GetSeq_entry_Handle());
75  if (!m_Found && b_iter->GetSeq_entry_Handle().HasParentEntry())
76  x_FindBioSource(b_iter->GetSeq_entry_Handle().GetParentEntry());
77  }
78 
79  Init();
80  Create(parent, id, caption, pos, size, style);
81 }
82 
83 
84 
85 
86 bool CLatLonTool::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
87 {
88  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
89  wxDialog::Create( parent, id, caption, pos, size, style );
90 
92  if (GetSizer())
93  {
94  GetSizer()->SetSizeHints(this);
95  }
96  Centre();
97  return true;
98 }
99 
100 
102 {
103 }
104 
105 
106 /*!
107  * Member initialisation
108  */
109 
111 {
112  m_Grid=NULL;
113 }
114 
115 
117 {
118  CLatLonTool* itemDialog1 = this;
119 
120  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
121  itemDialog1->SetSizer(itemBoxSizer2);
122 
123  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
124  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
125 
126  wxArrayString itemChoiceStrings, itemChoiceStringsWritable;
127 
128  if (m_LatLon.empty())
129  {
130  wxMessageBox(wxT("No LatLon records found"), wxT("Error"), wxOK | wxICON_ERROR);
131  NCBI_THROW( CException, eUnknown, "No LatLon records found" );
132  }
133 
135  if (values_table->GetNum_rows() < 1)
136  {
137  wxMessageBox(wxT("No LatLon records found or all records correctly formatted"), wxT("Error"), wxOK | wxICON_ERROR);
138  NCBI_THROW( CException, eUnknown, "No LatLon records found or all records correctly formatted" );
139  }
140  CRef<CSeq_table> choices = GetChoices(values_table);
141  int glyph_col = GetCollapsible();
142  m_GridPanel = new CSeqTableGridPanel(this, values_table, choices, glyph_col);
143  itemBoxSizer3->Add(m_GridPanel, 0, wxALIGN_TOP|wxALL, 5);
145  CSeqTableGrid *gridAdapter = new CSeqTableGrid(values_table);
146  m_Grid->SetTable(gridAdapter, true);
147  m_Grid->AutoSizeColumns();
148  int l_height = m_Grid->GetColLabelSize();
149  m_Grid->SetColLabelSize( 2 * l_height );
150 
151  int pos = 0;
152  ITERATE (CSeq_table::TColumns, it, values_table->GetColumns())
153  {
154  if (pos > 0)
155  {
156  if ((*it)->IsSetHeader() && (*it)->GetHeader().IsSetTitle() )
157  {
158  string title = (*it)->GetHeader().GetTitle();
159  if (!title.empty())
160  {
161  itemChoiceStrings.Add(wxString(title));
162  if (!IsReadOnlyColumn(title))
163  itemChoiceStringsWritable.Add(wxString(title));
164  }
165  if (IsReadOnlyColumn(title))
166  m_GridPanel->MakeColumnReadOnly(pos - 1, true);
167  }
168  }
169  pos++;
170  }
171 
172  if (glyph_col >= 0 && glyph_col+1 < m_Grid->GetNumberCols())
173  {
174  m_GridPanel->InitColumnCollapse(glyph_col+1);
175  }
176 
177 
178  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
179  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
180 
181  m_StringConstraintPanel = new CStringConstraintSelect( itemDialog1, m_GridPanel, itemChoiceStrings, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
182  itemBoxSizer4->Add(m_StringConstraintPanel, 0, wxALIGN_TOP|wxALL|wxFIXED_MINSIZE, 0);
183 
184  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
185  itemBoxSizer2->Add(itemBoxSizer13, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
186 
187  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
188  itemBoxSizer13->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
189 
190  wxButton* itemButton15 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
191  itemBoxSizer13->Add(itemButton15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
192 }
193 
195 {
196 
199  id_col->SetHeader().SetTitle(kSequenceIdColLabel);
200 
201  CRef<CSeqTable_column> expand_col(new CSeqTable_column());
202  expand_col->SetHeader().SetTitle("");
203  expand_col->SetHeader().SetField_name("expand");
204  expand_col->SetData().SetString();
205 
206  CRef<CSeqTable_column> current_col(new CSeqTable_column());
207  current_col->SetHeader().SetTitle("Current Lat-Lon");
208  current_col->SetHeader().SetField_name("current");
209  current_col->SetData().SetString();
210 
211  CRef<CSeqTable_column> suggested_col(new CSeqTable_column());
212  suggested_col->SetHeader().SetTitle("Suggested Correction");
213  suggested_col->SetHeader().SetField_name("suggested");
214  suggested_col->SetData().SetString();
215 
216 
217  // bogus column to include last, otherwise deletion of the previous column will not work
218  CRef<CSeqTable_column> bogus_col(new CSeqTable_column());
219  bogus_col->SetHeader().SetTitle("");
220  bogus_col->SetHeader().SetField_name("");
221  bogus_col->SetData().SetString();
222 
224  table->SetColumns().push_back(id_col);
225  table->SetColumns().push_back(expand_col);
226  table->SetColumns().push_back(current_col);
227  table->SetColumns().push_back(suggested_col);
228  table->SetColumns().push_back(bogus_col);
229 
230  size_t row = 0;
231 
232  for ( vector<string>::iterator fi = m_LatLon.begin(); fi != m_LatLon.end() ; ++fi )
233  {
234  string suggested = CSubSource::FixLatLonFormat(*fi,true);
235  if (suggested == *fi)
236  continue;
237  CRef<CSeq_id> id(new CSeq_id());
238  id->SetLocal().SetId(static_cast<CObject_id::TId>(row));
239  id_col->SetData().SetId().push_back(id);
240  expand_col->SetData().SetString().push_back("");
241  current_col->SetData().SetString().push_back(*fi);
242  suggested_col->SetData().SetString().push_back(suggested);
243  bogus_col->SetData().SetString().push_back("");
244  row++;
245  }
246 
247  table->SetNum_rows(static_cast<CSeq_table::TNum_rows>(row));
248 
249  return table;
250 }
251 
252 
254 {
255  bool select_all = false;
256  if (!m_Grid->IsSelection() && values_table->GetNum_rows() > 0)
257  {
258  if (wxMessageBox(ToWxString("Apply to all?"), wxT("Nothing is selected"), wxOK | wxCANCEL, NULL) == wxOK)
259  {
260  select_all = true;
261  }
262  }
263 
264  CRef<CCmdComposite> cmd(new CCmdComposite("LatLon Tool"));
266  m_Modified = false;
267  for (size_t row = 0; row < values_table->GetColumn("current").GetData().GetString().size(); ++row)
268  {
269  string current = values_table->GetColumn("current").GetData().GetString()[row];
270  string suggested = values_table->GetColumn("suggested").GetData().GetString()[row];
271  if (!current.empty() && !suggested.empty() && current != suggested && (m_Grid->IsInSelection(static_cast<int>(row),0) || select_all))
272  m_Current_to_Suggested[current] = suggested;
273  }
274 
275 
277  for ( ; b_iter ; ++b_iter )
278  {
279  m_Found = false;
281  if (!m_Found && b_iter->GetSeq_entry_Handle().HasParentEntry())
283  }
284 
285  return cmd;
286 }
287 
289 {
290  CRef<CSeq_table> values_table = m_GridPanel->GetValuesTable();
292  return cmd;
293 }
294 
296 {
297  return "Invalid operation in LatLon Tool";
298 }
299 
300 
301 /*!
302  * Should we show tooltips?
303  */
304 
306 {
307  return true;
308 }
309 
310 /*!
311  * Get bitmap resources
312  */
313 
314 wxBitmap CLatLonTool::GetBitmapResource( const wxString& name )
315 {
316  // Bitmap retrieval
317 ////@begin CLatLonTool bitmap retrieval
318  wxUnusedVar(name);
319  return wxNullBitmap;
320 ////@end CLatLonTool bitmap retrieval
321 }
322 
323 /*!
324  * Get icon resources
325  */
326 
327 wxIcon CLatLonTool::GetIconResource( const wxString& name )
328 {
329  // Icon retrieval
330 ////@begin CLatLonTool icon retrieval
331  wxUnusedVar(name);
332  return wxNullIcon;
333 ////@end CLatLonTool icon retrieval
334 }
335 
336 /*!
337  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
338  */
339 
340 void CLatLonTool::OnClickOk( wxCommandEvent& event )
341 {
342 ////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON in CLatLonTool.
343  // Before editing this code, remove the block markers.
344  event.Skip();
345 ////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON in CLatLonTool.
346 }
347 
348 /*!
349  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
350  */
351 
352 void CLatLonTool::OnClickCancel( wxCommandEvent& event )
353 {
354  bool modified = m_GridPanel->GetModified();
355  if (modified)
356  {
357  wxMessageDialog dlg(this,_("Discard modifications?"), _("Attention"),wxOK|wxCANCEL|wxCENTRE);
358  if (dlg.ShowModal() == wxID_OK)
359  {
360  event.Skip();
361  }
362  }
363  else
364  event.Skip();
365 
366 }
367 
369 {
370  FOR_EACH_SUBSOURCE_ON_BIOSOURCE(subsource, biosource)
371  {
372  if ((*subsource)->IsSetSubtype() && (*subsource)->GetSubtype() == CSubSource::eSubtype_lat_lon && (*subsource)->IsSetName())
373  {
374  string latlon = (*subsource)->GetName();
375  if (!latlon.empty())
376  {
377  m_LatLon.push_back(latlon);
378  m_Found = true;
379  }
380  }
381  }
382 }
383 
385 {
386  bool modified = false;
387  EDIT_EACH_SUBSOURCE_ON_BIOSOURCE(subsource, biosource)
388  {
389  if ((*subsource)->IsSetSubtype() && (*subsource)->GetSubtype() == CSubSource::eSubtype_lat_lon && (*subsource)->IsSetName())
390  {
391  string latlon = (*subsource)->GetName();
392  m_Found = true;
394  {
395  (*subsource)->SetName(m_Current_to_Suggested[latlon]);
396  modified = true;
397  }
398  }
399  }
400  return modified;
401 }
402 
404 {
405  if (!composite) {
407  if ((*it)->IsSource()) {
408  x_GatherLatLon((*it)->GetSource());
409  }
410  }
411  }
412  else {
414  if ((*it)->IsSource()) {
415  const CSeqdesc& orig_desc = **it;
416  CRef<CSeqdesc> new_desc(new CSeqdesc);
417  new_desc->Assign(orig_desc);
418  if (x_ApplyToBioSource(new_desc->SetSource())) {
420  CCmdChangeSeqdesc(m_TopSeqEntry.GetScope().GetSeq_entryHandle(se), orig_desc, *new_desc));
421  composite->AddCommand(*cmd);
422  }
423  }
424  }
425  }
426 
427  if (se.IsSet()) {
429  x_ApplyToDescriptors(**it, composite);
430  }
431  }
432 }
433 
435 {
436  x_ApplyToDescriptors(*(tse.GetCompleteSeq_entry()), composite);
437 
438  if (!composite) {
439  for (CFeat_CI feat_it(tse, SAnnotSelector(CSeqFeatData::e_Biosrc)); feat_it; ++feat_it) {
440  x_GatherLatLon(feat_it->GetData().GetBiosrc());
441  }
442  }
443  else {
444  for (CFeat_CI feat_it(tse, SAnnotSelector(CSeqFeatData::e_Biosrc)); feat_it; ++feat_it) {
445  CRef<CSeq_feat> new_feat(new CSeq_feat());
446  new_feat->Assign(feat_it->GetOriginalFeature());
447  if (x_ApplyToBioSource(new_feat->SetData().SetBiosrc())) {
448  CRef<CCmdChangeSeq_feat> cmd(new CCmdChangeSeq_feat(*feat_it, *new_feat));
449  composite->AddCommand(*cmd);
450  }
451  }
452  }
453 }
454 
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
void AddCommand(IEditCommand &command)
CFeat_CI –.
Definition: feat_ci.hpp:64
vector< string > m_LatLon
Definition: latlon_tool.hpp:96
bool x_ApplyToBioSource(objects::CBioSource &biosource)
CRef< CCmdComposite > GetCommand()
string GetErrorMessage()
map< string, string > m_Current_to_Suggested
Definition: latlon_tool.hpp:97
CLatLonTool()
Constructors.
Definition: latlon_tool.cpp:62
void x_FindBioSource(objects::CSeq_entry_Handle tse, CCmdComposite *composite=NULL)
void CreateControls()
Creates the controls and sizers.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool IsReadOnlyColumn(string column_name)
Definition: latlon_tool.hpp:78
CRef< objects::CSeq_table > GetChoices(CRef< objects::CSeq_table > values_table)
Definition: latlon_tool.hpp:74
static bool ShowToolTips()
Should we show tooltips?
int GetCollapsible()
Definition: latlon_tool.hpp:75
~CLatLonTool()
Destructor.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("LatLon Tool"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
Definition: latlon_tool.cpp:86
CRef< objects::CSeq_table > GetValuesTableFromSeqEntry()
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
CSeq_entry_Handle m_TopSeqEntry
Definition: latlon_tool.hpp:98
CStringConstraintSelect * m_StringConstraintPanel
void x_GatherLatLon(const objects::CBioSource &biosource)
void x_ApplyToDescriptors(const objects::CSeq_entry &se, CCmdComposite *composite)
void Init()
Initialises member variables.
CRef< CCmdComposite > GetCommandFromValuesTable(CRef< objects::CSeq_table >)
void OnClickOk(wxCommandEvent &event)
wxGrid * m_Grid
Definition: latlon_tool.hpp:95
void OnClickCancel(wxCommandEvent &event)
CSeqTableGridPanel * m_GridPanel
void MakeColumnReadOnly(int pos, bool val=true)
wxGrid * GetGrid(void)
void InitColumnCollapse(int col)
CRef< objects::CSeq_table > GetValuesTable()
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
const CSeqTable_column & GetColumn(CTempString column_name) const
Definition: Seq_table.cpp:65
static string FixLatLonFormat(string orig_lat_lon, bool guess=false)
Definition: SubSource.cpp:1862
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define wxFIXED_MINSIZE
const char * kSequenceIdColLabel
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
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
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
CSeq_entry_Handle GetSeq_entryHandle(CDataLoader *loader, const TBlobId &blob_id, EMissing action=eMissing_Default)
Get Seq-entry handle by its blob-id, with possible loading.
Definition: scope.cpp:113
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
CScope & GetScope(void) const
Get scope this handle belongs to.
bool HasParentEntry(void) const
Check if current seq-entry has a parent.
CSeq_entry_Handle GetParentEntry(void) const
Get parent Seq-entry handle.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ eSubtype_lat_lon
+/- decimal degrees
Definition: SubSource_.hpp:113
const TColumns & GetColumns(void) const
Get the Columns member data.
Definition: Seq_table_.hpp:433
void SetHeader(THeader &value)
Assign a value to Header data member.
vector< CRef< CSeqTable_column > > TColumns
Definition: Seq_table_.hpp:92
void SetData(TData &value)
Assign a value to Data data member.
TNum_rows GetNum_rows(void) const
Get the Num_rows member data.
Definition: Seq_table_.hpp:393
const TString & GetString(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
TSource & SetSource(void)
Select the variant.
Definition: Seqdesc_.cpp:572
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
USING_SCOPE(objects)
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
#define fi
Utility macros and typedefs for exploring NCBI objects from seqfeat.asn.
#define FOR_EACH_SUBSOURCE_ON_BIOSOURCE(Itr, Var)
FOR_EACH_SUBSOURCE_ON_BIOSOURCE EDIT_EACH_SUBSOURCE_ON_BIOSOURCE.
#define EDIT_EACH_SUBSOURCE_ON_BIOSOURCE(Itr, Var)
static static static wxID_ANY
#define FOR_EACH_SEQENTRY_ON_SEQSET(Itr, Var)
FOR_EACH_SEQENTRY_ON_SEQSET EDIT_EACH_SEQENTRY_ON_SEQSET.
#define FOR_EACH_SEQDESC_ON_SEQENTRY(Itr, Var)
FOR_EACH_SEQDESC_ON_SEQENTRY EDIT_EACH_SEQDESC_ON_SEQENTRY.
#define row(bind, expected)
Definition: string_bind.c:73
SAnnotSelector –.
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Sun Apr 21 03:40:06 2024 by modify_doxy.py rev. 669887