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

Go to the SVN repository for this file.

1 /* $Id: add_deflinedlg.cpp 41933 2018-11-15 16:32:34Z 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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 #include <objmgr/bioseq_ci.hpp>
32 #include <objmgr/seqdesc_ci.hpp>
33 #include <objmgr/scope.hpp>
34 
43 #include <wx/msgdlg.h>
44 
47 
48 
49 IMPLEMENT_DYNAMIC_CLASS( CAddDefLineDlg, CBulkCmdDlg )
50 
51 
52 BEGIN_EVENT_TABLE( CAddDefLineDlg, CBulkCmdDlg )
53 
55 
56 
57 
59 {
60  Init();
61 }
62 
63 CAddDefLineDlg::CAddDefLineDlg( wxWindow* parent, IWorkbench* wb, wxWindowID id,
64  const wxString& caption, const wxPoint& pos,
65  const wxSize& size, long style )
66 : CBulkCmdDlg(wb)
67 {
68  Init();
69  Create(parent, id, caption, pos, size, style);
70 }
71 
72 
73 bool CAddDefLineDlg::Create( wxWindow* parent, wxWindowID id,
74  const wxString& caption, const wxPoint& pos,
75  const wxSize& size, long style )
76 {
77 ////@begin CAddDefLineDlg creation
78  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
79  CBulkCmdDlg::Create(parent, id, caption, pos, size, style);
80 
82  if (GetSizer())
83  {
84  GetSizer()->SetSizeHints(this);
85  }
86  Centre();
87 ////@end CAddDefLineDlg creation
88  return true;
89 }
90 
92 {
93 
94 }
95 
96 
97 /*!
98  * Member initialisation
99  */
100 
102 {
103  m_Title = NULL;
104  m_OkCancel = NULL;
105 }
106 
107 
109 {
110 ////@begin CAddDefLineDlg content construction
111  CAddDefLineDlg* itemCBulkCmdDlg1 = this;
112 
113  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
114  itemCBulkCmdDlg1->SetSizer(itemBoxSizer2);
115 
116  wxStaticText* itemStaticText3 = new wxStaticText(itemCBulkCmdDlg1, wxID_STATIC, _("Title"), wxDefaultPosition, wxDefaultSize, 0);
117  itemBoxSizer2->Add(itemStaticText3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
118 
119  m_Title = new wxTextCtrl(itemCBulkCmdDlg1, ID_ADDDEFLINE_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(110, 55), wxTE_MULTILINE);
120  itemBoxSizer2->Add(m_Title, 0, wxGROW|wxALL, 5);
121 
122  m_OkCancel = new COkCancelPanel(itemCBulkCmdDlg1, ID_ADDDEFLINE_OKCANCEL, wxDefaultPosition, wxSize(100, 100), 0);
123  itemBoxSizer2->Add(m_OkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
124 
125 ////@end CAddDefLineDlg content construction
126 }
127 
128 
129 /*!
130  * Should we show tooltips?
131  */
132 
134 {
135  return true;
136 }
137 
138 
139 wxBitmap CAddDefLineDlg::GetBitmapResource( const wxString& name )
140 {
141  wxUnusedVar(name);
142  return wxNullBitmap;
143 }
144 
145 wxIcon CAddDefLineDlg::GetIconResource( const wxString& name )
146 {
147  wxUnusedVar(name);
148  return wxNullIcon;
149 }
150 
152 {
153  string new_title = ToStdString(m_Title->GetValue());
154  NStr::TruncateSpacesInPlace(new_title);
155  NStr::ReplaceInPlace(new_title, "\n", " ");
156 
157  if (NStr::IsBlank(new_title)){
158  m_ErrorMessage = "No text has been entered.";
159  return CRef<CCmdComposite>(NULL);
160  }
161  else {
162  string msg("You are manually editing a title. If you continue, the title will not be automatically\n"
163  "updated if the taxonomy information changes. Do you want to continue?");
164  if (wxNO == wxMessageBox(ToWxString(msg), wxT("Confirm"), wxYES_NO | wxICON_QUESTION)) {
165  return CRef<CCmdComposite>(NULL);
166  }
167  }
168 
169  int num_conflicts = CountDefLineConflicts(m_TopSeqEntry, new_title);
170  edit::EExistingText existing_text = x_GetExistingTextHandling (num_conflicts);
171  if (existing_text == edit::eExistingText_cancel || existing_text == edit::eExistingText_leave_old){
172  return CRef<CCmdComposite>(NULL);
173  }
174 
175  CRef<CCmdComposite> cmd(new CCmdComposite("Add definition line"));
176  UpdateAllDefinitionLine(m_TopSeqEntry, cmd, new_title, existing_text);
177 
178  return (cmd) ? cmd : CRef<CCmdComposite>(NULL);
179 }
180 
182 {
183  return m_ErrorMessage;
184 }
185 
186 
187 int CountDefLineConflicts(CSeq_entry_Handle entry, const string& title)
188 {
189  int count=0;
190  CBioseq_CI b_iter(entry, CSeq_inst::eMol_na);
191  for ( ; b_iter ; ++b_iter){
192  CSeqdesc_CI seqdesc(*b_iter, CSeqdesc::e_Title, 1);
193  while (seqdesc){
194  if (!NStr::IsBlank(seqdesc->GetTitle()) && !NStr::Equal(seqdesc->GetTitle(), title))
195  count++;
196  ++seqdesc;
197  }
198  }
199 
201  for ( ; set_ci ; ++set_ci){
202  if (set_ci->GetSet().IsSetClass() && CBioseq_set::NeedsDocsumTitle(set_ci->GetSet().GetClass())){
203  CSeqdesc_CI seqdesc(*set_ci, CSeqdesc::e_Title, 1);
204  while (seqdesc){
205  if (!NStr::IsBlank(seqdesc->GetTitle()) && !NStr::Equal(seqdesc->GetTitle(), title))
206  count++;
207  ++seqdesc;
208  }
209  }
210  }
211 
212  return count;
213 }
214 
215 bool UpdateAllDefinitionLine(CSeq_entry_Handle entry, CCmdComposite* composite, const string& title, edit::EExistingText existing_text)
216 {
217  bool modified = false;
219  for ( ; entry_ci ; ++entry_ci){
220  if (entry_ci->IsSeq() && entry_ci->GetSeq().IsNa()){
221  UpdateOneDefLine(entry_ci, composite, title, existing_text, modified);
222  }else if (entry_ci->IsSet() && entry_ci->GetSet().IsSetClass() && CBioseq_set::NeedsDocsumTitle(entry_ci->GetSet().GetClass())){
223  UpdateOneDefLine(entry_ci, composite, title, existing_text, modified);
224  }
225  }
226  return modified;
227 }
228 
229 void UpdateOneDefLine(const CSeq_entry_CI& entry_ci, CCmdComposite* composite, const string& title, edit::EExistingText existing_text, bool& modified)
230 {
231  CSeqdesc_CI seqdesc(*entry_ci, CSeqdesc::e_Title, 1);
232  if (seqdesc){
233  string new_title = seqdesc->GetTitle();
234  if (AddValueToString(new_title, title, existing_text)){
235  CRef<CSeqdesc> new_desc(new CSeqdesc());
236  new_desc->SetTitle(new_title);
237  CRef<CCmdChangeSeqdesc> cmd(new CCmdChangeSeqdesc(seqdesc.GetSeq_entry_Handle(), *seqdesc, *new_desc));
238  composite->AddCommand(*cmd);
239  modified = true;
240  }
241  ++seqdesc;
242  while (seqdesc){ //multiple titles will be deleted
243  composite->AddCommand(*CRef<CCmdDelDesc>(new CCmdDelDesc(*entry_ci, *seqdesc)) );
244  modified = true;
245  ++seqdesc;
246  }
247  }else{ // make a new title
248  CRef<CSeqdesc> new_desc(new CSeqdesc());
249  new_desc->SetTitle(title);
250  composite->AddCommand(*CRef<CCmdCreateDesc>(new CCmdCreateDesc(*entry_ci,*new_desc)));
251  modified = true;
252  }
253 
254  if (modified) {
255  for (CSeqdesc_CI desc_it(*entry_ci, CSeqdesc::e_User); desc_it; ++desc_it) {
256  if (desc_it->GetUser().GetObjectType() == CUser_object::eObjectType_AutodefOptions) {
257  CRef<CCmdDelDesc> cmddel(new CCmdDelDesc(*entry_ci, *desc_it));
258  composite->AddCommand(*cmddel);
259  }
260  }
261  }
262 
263 }
264 
266 {
267 
268  FOR_EACH_SEQDESC_ON_SEQENTRY (seqdesc, entry)
269  if ((*seqdesc)->IsTitle()){
270  CRef<CCmdDelDesc> cmddel(new CCmdDelDesc(seh.GetScope().GetSeq_entryHandle(entry), **seqdesc));
271  composite->AddCommand(*cmddel);
272  }
273 
274  if (entry.IsSet()){
275  FOR_EACH_SEQENTRY_ON_SEQSET (it, entry.GetSet())
276  RemoveTitlesSeqEntry(seh, **it, composite);
277  }
278 }
279 
281 
282 
283 
284 
USING_SCOPE(objects)
void RemoveTitlesSeqEntry(CSeq_entry_Handle seh, const CSeq_entry &entry, CCmdComposite *composite)
bool UpdateAllDefinitionLine(CSeq_entry_Handle entry, CCmdComposite *composite, const string &title, edit::EExistingText existing_text)
void UpdateOneDefLine(const CSeq_entry_CI &entry_ci, CCmdComposite *composite, const string &title, edit::EExistingText existing_text, bool &modified)
int CountDefLineConflicts(CSeq_entry_Handle entry, const string &title)
#define ID_ADDDEFLINE_OKCANCEL
#define ID_ADDDEFLINE_TEXTCTRL
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
virtual CRef< CCmdComposite > GetCommand()
void CreateControls()
Creates the controls and sizers.
wxTextCtrl * m_Title
void Init()
Initialises member variables.
static bool ShowToolTips()
Should we show tooltips?
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
virtual string GetErrorMessage()
COkCancelPanel * m_OkCancel
bool Create(wxWindow *parent, wxWindowID id=10262, const wxString &caption=_("Add Definition Line"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CAddDefLineDlg()
Constructors.
~CAddDefLineDlg()
Destructor.
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
bool NeedsDocsumTitle() const
Definition: Bioseq_set.cpp:343
objects::CSeq_entry_Handle m_TopSeqEntry
bool Create(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr)
string m_ErrorMessage
edit::EExistingText x_GetExistingTextHandling(int num_conflicts, bool allow_multiple=false)
void AddCommand(IEditCommand &command)
CSeq_entry_CI –.
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
@ eObjectType_AutodefOptions
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
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
TClass GetClass(void) const
TSet GetSet(void) const
TSeq GetSeq(void) const
bool IsSetClass(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
bool IsSet(void) const
bool IsNa(void) const
bool IsSeq(void) const
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Definition: seqdesc_ci.cpp:326
@ fIncludeGivenEntry
Include the top (given) entry.
@ fRecursive
Iterate recursively.
#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 void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3197
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
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3401
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
TTitle & SetTitle(void)
Select the variant.
Definition: Seqdesc_.hpp:1039
const TTitle & GetTitle(void) const
Get the variant data.
Definition: Seqdesc_.hpp:1032
@ e_User
user defined object
Definition: Seqdesc_.hpp:124
@ e_Title
a title for this sequence
Definition: Seqdesc_.hpp:115
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
#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.
EExistingText
@ eExistingText_cancel
@ eExistingText_leave_old
bool AddValueToString(string &str, const string &value, EExistingText existing_text)
Add text to an existing string, using the "existing_text" directive to combine new text with existing...
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Mon Mar 04 05:12:23 2024 by modify_doxy.py rev. 669887