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

Go to the SVN repository for this file.

1 /* $Id: lowercase_qualifiers.cpp 42449 2019-02-27 20:41:38Z 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: Igor Filippov
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
34 
35 #include <objmgr/bioseq_handle.hpp>
43 
44 #include <wx/stattext.h>
45 #include <wx/textctrl.h>
46 #include <wx/choice.h>
47 #include <wx/combobox.h>
48 #include <wx/msgdlg.h>
49 
50 ////@begin XPM images
51 ////@end XPM images
52 
55 
56 /*!
57  * CLowerQuals type definition
58  */
59 
60 IMPLEMENT_DYNAMIC_CLASS( CLowerQuals, CBulkCmdDlg )
61 
62 
63 /*!
64  * CLowerQuals event table definition
65  */
66 
67 BEGIN_EVENT_TABLE( CLowerQuals, CBulkCmdDlg )
68 
69 ////@begin CLowerQuals event table entries
71 ////@end CLowerQuals event table entries
73 
74 
75 /*!
76  * CLowerQuals constructors
77  */
78 
80 {
81  Init();
82 }
83 
84 CLowerQuals::CLowerQuals( wxWindow* parent, IWorkbench* wb, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
85  : CBulkCmdDlg(wb)
86 {
87  Init();
88  Create(parent, id, caption, pos, size, style);
89 }
90 
91 
92 /*!
93  * CLowerQuals creator
94  */
95 
96 bool CLowerQuals::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
97 {
98 ////@begin CLowerQuals creation
99  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
100  CBulkCmdDlg::Create( parent, id, caption, pos, size, style );
101 
102  CreateControls();
103  if (GetSizer())
104  {
105  GetSizer()->SetSizeHints(this);
106  }
107  Centre();
108 ////@end CLowerQuals creation
109  return true;
110 }
111 
112 
113 /*!
114  * CLowerQuals destructor
115  */
116 
118 {
119 ////@begin CLowerQuals destruction
120 ////@end CLowerQuals destruction
121 }
122 
123 
124 /*!
125  * Member initialisation
126  */
127 
129 {
130 ////@begin CLowerQuals member initialisation
131  m_FieldType = NULL;
132  m_OkCancel = NULL;
133 ////@end CLowerQuals member initialisation
134 }
135 
136 
137 /*!
138  * Control creation for CLowerQuals
139  */
140 
142 {
143 ////@begin CLowerQuals content construction
144  CLowerQuals* itemCBulkCmdDlg1 = this;
145 
146  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
147  itemCBulkCmdDlg1->SetSizer(itemBoxSizer2);
148 
150 
151  vector<CFieldNamePanel::EFieldType> field_types;
152  field_types.push_back(CFieldNamePanel::eFieldType_Taxname);
153  field_types.push_back(CFieldNamePanel::eFieldType_Source);
154  field_types.push_back(CFieldNamePanel::eFieldType_Misc);
155  field_types.push_back(CFieldNamePanel::eFieldType_Feature);
156  field_types.push_back(CFieldNamePanel::eFieldType_CDSGeneProt);
157  field_types.push_back(CFieldNamePanel::eFieldType_RNA);
158  field_types.push_back(CFieldNamePanel::eFieldType_MolInfo);
159  field_types.push_back(CFieldNamePanel::eFieldType_Pub);
160  field_types.push_back(CFieldNamePanel::eFieldType_DBLink);
161  field_types.push_back(CFieldNamePanel::eFieldType_SeqId);
162  m_FieldType = new CFieldChoicePanel( itemCBulkCmdDlg1, field_types, true, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
163  itemBoxSizer2->Add(m_FieldType, 1, wxGROW|wxALL|wxFIXED_MINSIZE, 0);
165 
166  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
167  itemBoxSizer2->Add(itemBoxSizer6, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 0);
168 
169  wxRadioButton* itemRadioButton1 = new wxRadioButton( itemCBulkCmdDlg1, wxID_ANY, _("Descriptors and Features"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
170  itemRadioButton1->SetValue(true);
171  itemBoxSizer6->Add(itemRadioButton1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
172 
173  m_RadioDesc = new wxRadioButton( itemCBulkCmdDlg1, wxID_ANY, _("Descriptors only"));
174  m_RadioDesc->SetValue(false);
175  itemBoxSizer6->Add(m_RadioDesc, 0, wxALIGN_CENTER_VERTICAL |wxALL, 5);
176 
177  m_RadioFeat = new wxRadioButton( itemCBulkCmdDlg1, wxID_ANY, _("Features only"));
178  m_RadioFeat->SetValue(false);
179  itemBoxSizer6->Add(m_RadioFeat, 0, wxALIGN_CENTER_VERTICAL |wxALL, 5);
180 
181  m_CapChangeOptions = new CCapChangePanel( itemCBulkCmdDlg1, wxID_ANY, wxDefaultPosition, wxSize(100, 100), wxNO_BORDER); // wxSIMPLE_BORDER
182  itemBoxSizer2->Add(m_CapChangeOptions, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
183  m_CapChangeOptions-> m_CapNochange->SetValue(false);
184  m_CapChangeOptions->m_CapTolower->SetValue(true);
185 
186  m_OkCancel = new COkCancelPanel( itemCBulkCmdDlg1, wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0 );
187  itemBoxSizer2->Add(m_OkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
188 
189 ////@end CLowerQuals content construction
190 }
191 
192 /*!
193  * Should we show tooltips?
194  */
195 
197 {
198  return true;
199 }
200 
201 /*!
202  * Get bitmap resources
203  */
204 
205 wxBitmap CLowerQuals::GetBitmapResource( const wxString& name )
206 {
207  // Bitmap retrieval
208 ////@begin CLowerQuals bitmap retrieval
209  wxUnusedVar(name);
210  return wxNullBitmap;
211 ////@end CLowerQuals bitmap retrieval
212 }
213 
214 /*!
215  * Get icon resources
216  */
217 
218 wxIcon CLowerQuals::GetIconResource( const wxString& name )
219 {
220  // Icon retrieval
221 ////@begin CLowerQuals icon retrieval
222  wxUnusedVar(name);
223  return wxNullIcon;
224 ////@end CLowerQuals icon retrieval
225 }
226 
227 
229 {
232  return cmd;
233 
234  CRef<edit::CStringConstraint> string_constraint(NULL);
235  string constraint_field = m_FieldType->GetFieldName(false);
237 
238  CRef<CMiscSeqTableColumn> col(new CMiscSeqTableColumn(constraint_field));
239 
241  CSeq_entry_Handle null_seh;
242  vector<CRef<edit::CApplyObject> > objs = col->GetApplyObjects(seh, constraint_field, string_constraint);
243  if (objs.empty())
244  {
245  wxMessageBox(wxT("No features found!"), wxT("Error"),
246  wxOK | wxICON_ERROR, NULL);
247  return cmd;
248  }
249 
250  cmd.Reset(new CCmdComposite("Lowercase Qualifiers"));
251  NON_CONST_ITERATE(vector<CRef<edit::CApplyObject> >, src_it, objs)
252  {
253  if (!(*src_it)->PreExists())
254  {
255  continue;
256  }
257  string val = col->GetVal((*src_it)->GetObject());
258  string new_val = val;
259  const CSeqdesc * desc = dynamic_cast<const CSeqdesc *>((*src_it)->GetOriginalObject());
260  const CSeq_feat* feat = dynamic_cast<const CSeq_feat *>((*src_it)->GetOriginalObject());
261  bool is_src_org = false;
262  if (feat && feat->IsSetData() && feat->GetData().IsBiosrc() && feat->GetData().GetBiosrc().IsSetOrg())
263  is_src_org = true;
264  if (desc && desc->IsSource() && desc->GetSource().IsSetOrg())
265  is_src_org = true;
266  if (feat && m_RadioDesc->GetValue())
267  continue;
268  if (desc && m_RadioFeat->GetValue())
269  continue;
270 
271  if (is_src_org)
272  FixCapitalizationInString(null_seh, new_val, cap_change);
273  else
274  FixCapitalizationInString(seh, new_val, cap_change);
275 
276  if (val != new_val)
277  {
278  col->SetVal((*src_it)->SetObject(), new_val, edit::eExistingText_replace_old);
280  if (ecmd)
281  cmd->AddCommand(*ecmd);
282  }
283  }
284 
285  return cmd;
286 }
287 
288 
290 {
291  return m_ErrorMessage;
292 }
293 
294 void CLowerQuals::ProcessUpdateFeatEvent( wxCommandEvent& event )
295 {
296  UpdateChildrenFeaturePanels(this->GetSizer());
297 }
298 
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
bool GetTopLevelSeqEntryAndProcessor()
void UpdateChildrenFeaturePanels(wxSizer *sizer)
wxRadioButton * m_CapTolower
objects::ECapChange GetCapitalizationRequest()
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
bool SetFieldType(CFieldNamePanel::EFieldType field_type, bool is_pair=false)
void ProcessUpdateFeatEvent(wxCommandEvent &event)
CLowerQuals()
Constructors.
virtual string GetErrorMessage()
CFieldChoicePanel * m_FieldType
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=10147, const wxString &caption=_("Lowercase Qualifiers"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
virtual CRef< CCmdComposite > GetCommand()
~CLowerQuals()
Destructor.
wxRadioButton * m_RadioFeat
static bool ShowToolTips()
Should we show tooltips?
wxRadioButton * m_RadioDesc
COkCancelPanel * m_OkCancel
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void Init()
Initialises member variables.
CCapChangePanel * m_CapChangeOptions
vector< CRef< objects::edit::CApplyObject > > GetApplyObjects(objects::CBioseq_Handle bsh)
string GetVal(const CObject &object)
bool SetVal(CObject &object, const string &val, objects::edit::EExistingText existing_text)
CSeq_entry_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
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 wxFIXED_MINSIZE
static auto & FixCapitalizationInString
#define EVT_UPDATE_FEATURE_LIST(id, fn)
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#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
bool IsSetOrg(void) const
Check if a value has been assigned to Org data member.
Definition: BioSource_.hpp:497
bool IsSetData(void) const
the specific data Check if a value has been assigned to Data data member.
Definition: Seq_feat_.hpp:913
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TBiosrc & GetBiosrc(void) const
Get the variant data.
bool IsBiosrc(void) const
Check if variant Biosrc is selected.
const TSource & GetSource(void) const
Get the variant data.
Definition: Seqdesc_.cpp:566
bool IsSource(void) const
Check if variant Source is selected.
Definition: Seqdesc_.hpp:1190
END_EVENT_TABLE()
USING_SCOPE(objects)
CRef< CCmdComposite > GetCommandFromApplyObject(objects::edit::CApplyObject &obj)
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
@ eExistingText_replace_old
Modified on Fri Dec 08 08:23:40 2023 by modify_doxy.py rev. 669887