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

Go to the SVN repository for this file.

1 /* $Id: remove_text_inside_string_dlg.cpp 39649 2017-10-24 15:22:12Z 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, based on work of Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
37 
38 #include <wx/stattext.h>
39 #include <wx/button.h>
40 #include <wx/msgdlg.h>
41 
42 ////@begin XPM images
43 ////@end XPM images
44 
45 
47 
48 //USING_SCOPE(ncbi::objects);
49 
50 /*!
51  * CRemoveTextInsideStrDlg type definition
52  */
53 
54 IMPLEMENT_DYNAMIC_CLASS( CRemoveTextInsideStrDlg, CBulkCmdDlg )
55 
56 
57 /*!
58  * CRemoveTextInsideStrDlg event table definition
59  */
60 
61 BEGIN_EVENT_TABLE( CRemoveTextInsideStrDlg, CBulkCmdDlg )
62 
63 ////@begin CRemoveTextInsideStrDlg event table entries
64 ////@end CRemoveTextInsideStrDlg event table entries
66 
68 
69 
70 /*!
71  * CRemoveTextInsideStrDlg constructors
72  */
73 
75 {
76  Init();
77 }
78 
79 CRemoveTextInsideStrDlg::CRemoveTextInsideStrDlg( wxWindow* parent, IWorkbench* wb, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
80  : CBulkCmdDlg(wb)
81 {
82  Init();
83  Create(parent, id, caption, pos, size, style);
84 }
85 
86 
87 /*!
88  * CRemoveTextInsideStrDlg creator
89  */
90 
91 bool CRemoveTextInsideStrDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
92 {
93 ////@begin CRemoveTextInsideStrDlg creation
94  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
95  CBulkCmdDlg::Create( parent, id, caption, pos, size, style );
96 
98  if (GetSizer())
99  {
100  GetSizer()->SetSizeHints(this);
101  }
102  Centre();
103 ////@end CRemoveTextInsideStrDlg creation
104  return true;
105 }
106 
107 
108 /*!
109  * CRemoveTextInsideStrDlg destructor
110  */
111 
113 {
114 ////@begin CRemoveTextInsideStrDlg destruction
115 ////@end CRemoveTextInsideStrDlg destruction
116 }
117 
118 
119 /*!
120  * Member initialisation
121  */
122 
124 {
125 ////@begin CRemoveTextInsideStrDlg member initialisation
128  m_OkCancel = NULL;
129 ////@end CRemoveTextInsideStrDlg member initialisation
130  m_FieldFrom = NULL;
131 }
132 
133 
134 /*!
135  * Control creation for CRemoveTextInsideStrDlg
136  */
137 
139 {
140 ////@begin CRemoveTextInsideStrDlg content construction
141  CRemoveTextInsideStrDlg* itemCBulkCmdDlg1 = this;
142 
143  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
144  itemCBulkCmdDlg1->SetSizer(itemBoxSizer2);
145 
146  m_ParseOptions = new CParseTextOptionsDlg( itemCBulkCmdDlg1, ID_WINDOW2, wxDefaultPosition, wxSize(100, 100), wxSIMPLE_BORDER, true );
147  itemBoxSizer2->Add(m_ParseOptions, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
148 
149  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
150  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
151 
152  m_RemoveFirstOnly = new wxRadioButton( itemCBulkCmdDlg1, wxID_ANY, _("Remove first instance in each string"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
153  m_RemoveFirstOnly->SetValue(true);
154  itemBoxSizer3->Add(m_RemoveFirstOnly, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3);
155 
156  wxRadioButton *remove_all = new wxRadioButton( itemCBulkCmdDlg1, wxID_ANY, _("Remove all instances"), wxDefaultPosition, wxDefaultSize, 0 );
157  remove_all->SetValue(false);
158  itemBoxSizer3->Add(remove_all, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3);
159 
160  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
161  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
162 
163  m_FromFieldSizer = new wxBoxSizer(wxVERTICAL);
164  itemBoxSizer4->Add(m_FromFieldSizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
165 
166  wxStaticText* itemStaticText6 = new wxStaticText( itemCBulkCmdDlg1, wxID_STATIC, _("From"), wxDefaultPosition, wxDefaultSize, 0 );
167  m_FromFieldSizer->Add(itemStaticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
168 
169  m_OkCancel = new COkCancelPanel( itemCBulkCmdDlg1, ID_WINDOW13, wxDefaultPosition, wxSize(100, 100), 0 );
170  itemBoxSizer2->Add(m_OkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 2);
171 
172 ////@end CRemoveTextInsideStrDlg content construction
173 
174  vector<CFieldNamePanel::EFieldType> field_types;
175  // number of items that should not appear in the "TO" field choice list.
176  size_t not_TOList = 4;
177  field_types.push_back(CFieldNamePanel::eFieldType_Taxname);
178  field_types.push_back(CFieldNamePanel::eFieldType_Source);
179  field_types.push_back(CFieldNamePanel::eFieldType_Feature);
180  field_types.push_back(CFieldNamePanel::eFieldType_CDSGeneProt);
181  field_types.push_back(CFieldNamePanel::eFieldType_RNA);
182  field_types.push_back(CFieldNamePanel::eFieldType_Misc);
184  field_types.push_back(CFieldNamePanel::eFieldType_FileId);
185  field_types.push_back(CFieldNamePanel::eFieldType_GeneralId);
186  field_types.push_back(CFieldNamePanel::eFieldType_SeqId);
187  m_FieldFrom = new CFieldChoicePanel( this, field_types, false, false, wxID_ANY, wxDefaultPosition, wxSize(400, 150), 0 ); // true, false
188  m_FromFieldSizer->Add(m_FieldFrom, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
189 
190 }
191 
193 {
194  UpdateChildrenFeaturePanels(this->GetSizer());
195 }
196 
197 /*!
198  * Should we show tooltips?
199  */
200 
202 {
203  return true;
204 }
205 
206 /*!
207  * Get bitmap resources
208  */
209 
210 wxBitmap CRemoveTextInsideStrDlg::GetBitmapResource( const wxString& name )
211 {
212  // Bitmap retrieval
213 ////@begin CRemoveTextInsideStrDlg bitmap retrieval
214  wxUnusedVar(name);
215  return wxNullBitmap;
216 ////@end CRemoveTextInsideStrDlg bitmap retrieval
217 }
218 
219 /*!
220  * Get icon resources
221  */
222 
223 wxIcon CRemoveTextInsideStrDlg::GetIconResource( const wxString& name )
224 {
225  // Icon retrieval
226 ////@begin CRemoveTextInsideStrDlg icon retrieval
227  wxUnusedVar(name);
228  return wxNullIcon;
229 ////@end CRemoveTextInsideStrDlg icon retrieval
230 }
231 
232 
234 {
235  m_FieldFrom->SetFieldType(field_type);
236 
238  if (!string_constraint) {
239  m_ConstraintPanel->SetFieldType(field_type);
240  }
241  Layout();
242  Fit();
243  Refresh();
244 }
245 
246 
248 {
250 
252  string field1 = m_FieldFrom->GetFieldName();
253  if (NStr::IsBlank(field1)) {
254  m_ErrorMessage = "Must choose source field";
255  return cmd;
256  }
257 
258  CRef<edit::CStringConstraint> string_constraint(NULL);
259  CRef<CMiscSeqTableColumn> src_col(new CMiscSeqTableColumn(field1));
260  vector<CRef<edit::CApplyObject> > src_objects = src_col->GetApplyObjects(m_TopSeqEntry, kEmptyStr, string_constraint);
261  if (src_objects.size() == 0) {
262  wxMessageBox(wxT("No source objects found!"), wxT("Error"),
263  wxOK | wxICON_ERROR, NULL);
264  return cmd;
265  }
266 
267  CRef<CScope> scope(&m_TopSeqEntry.GetScope());
268 
269  // Construct command
270  cmd = new CCmdComposite("Remove Text Inside String");
271  CRef<edit::CParseTextOptions> parse_options(NULL);
272  parse_options = m_ParseOptions->GetParseOptions();
273  NON_CONST_ITERATE(vector<CRef<edit::CApplyObject> >, src_it, src_objects) {
274  if (!(*src_it)->PreExists()) {
275  continue;
276  }
277  string orig_val = src_col->GetVal((*src_it)->GetObject());
278  string new_val = m_ParseOptions->GetSelectedText(orig_val);
279  NStr::TruncateSpacesInPlace(new_val);
280  if (!NStr::IsBlank(new_val)) {
281  bool changed = false;
282  parse_options->RemoveSelectedText(orig_val,m_RemoveFirstOnly->GetValue());
283  NStr::TruncateSpacesInPlace(orig_val);
284  if (NStr::IsBlank(orig_val)) {
285  src_col->ClearVal((*src_it)->SetObject());
286  changed = true;
287  }
288  else if (src_col->SetVal((*src_it)->SetObject(), orig_val, edit::eExistingText_replace_old)) {
289  changed = true;
290  }
291 
292  if (changed) {
294  if (ecmd) {
295  cmd->AddCommand(*ecmd);
296  }
297  }
298  }
299  }
300 
301  return cmd;
302 }
303 
304 
306 {
307  return m_ErrorMessage;
308 }
309 
310 
311 static void s_AddwxSize(wxSize& orig, const wxSize& add, int borders)
312 {
313  if (orig.GetWidth() < add.GetWidth() + borders) {
314  orig.SetWidth(add.GetWidth() + borders);
315  }
316  orig.SetHeight(orig.GetHeight() + add.GetHeight() + borders);
317 }
318 
319 
321 {
322  /* wxSize min_size(0,0);
323  wxSize this_size(0,0);
324  size_t borders = 10;
325  s_AddwxSize(min_size, m_ParseOptions->GetSize(), borders);
326 
327  // get height of from and to, add only the taller
328  wxSize from_size(0,0);
329  if (m_FieldFrom) {
330  from_size = m_FieldFrom->GetSize();
331  s_AddwxSize(min_size, from_size, borders);
332  }
333 
334  if (m_OkCancel) {
335  s_AddwxSize(min_size, m_OkCancel->GetSize(), borders + 10);
336  }
337 
338  this->SetMinClientSize(min_size);*/
339  Layout();
340  Fit();
341  Refresh();
342 }
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
void UpdateChildrenFeaturePanels(wxSizer *sizer)
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)
CRef< edit::CStringConstraint > GetStringConstraint()
bool SetFieldType(CFieldNamePanel::EFieldType field_type)
vector< CRef< objects::edit::CApplyObject > > GetApplyObjects(objects::CBioseq_Handle bsh)
void ClearVal(CObject &object)
string GetVal(const CObject &object)
bool SetVal(CObject &object, const string &val, objects::edit::EExistingText existing_text)
string GetSelectedText(const string &input)
CRef< objects::edit::CParseTextOptions > GetParseOptions()
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
CFieldConstraintPanel * m_ConstraintPanel
void SetFromFieldType(CFieldNamePanel::EFieldType field_type)
void ProcessUpdateFeatEvent(wxCommandEvent &event)
void CreateControls()
Creates the controls and sizers.
void Init()
Initialises member variables.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=10161, const wxString &caption=_("Remove Text Inside String"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
static bool ShowToolTips()
Should we show tooltips?
virtual CRef< CCmdComposite > GetCommand()
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define EVT_UPDATE_FEATURE_LIST(id, fn)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#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
#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 void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
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()
CRef< CCmdComposite > GetCommandFromApplyObject(objects::edit::CApplyObject &obj)
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static void s_AddwxSize(wxSize &orig, const wxSize &add, int borders)
static static static wxID_ANY
@ eExistingText_replace_old
Modified on Fri Jun 14 16:51:55 2024 by modify_doxy.py rev. 669887