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

Go to the SVN repository for this file.

1 /* $Id: cds_exception_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: Roman Katargin
27  */
28 
29 
30 // Generated by DialogBlocks (unregistered), 22/12/2011 15:10:59
31 
32 #include <ncbi_pch.hpp>
33 ////@begin includes
34 ////@end includes
35 
36 #include "cds_exception_panel.hpp"
38 
39 
40 ////@begin XPM images
41 ////@end XPM images
42 
45 
46 /*!
47  * CCDSExceptionPanel type definition
48  */
49 
50 IMPLEMENT_DYNAMIC_CLASS( CCDSExceptionPanel, CQualListItemPanel )
51 
52 
53 /*!
54  * CCDSExceptionPanel event table definition
55  */
56 
57 BEGIN_EVENT_TABLE( CCDSExceptionPanel, CQualListItemPanel )
58 
59 ////@begin CCDSExceptionPanel event table entries
60 ////@end CCDSExceptionPanel event table entries
62 
64 
65 
66 /*!
67  * CCDSExceptionPanel constructors
68  */
69 
71 {
72  Init();
73 }
74 
75 CCDSExceptionPanel::CCDSExceptionPanel( wxWindow* parent, CSeq_feat& feat, CScope& scope,
76  wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
77 : m_Scope(&scope), m_EditedFeat(new CSeq_feat())
78 
79 {
81  Init();
82  m_EditedFeat->Assign (feat);
83  m_AllowUpdates = true;
84  Create(parent, id, pos, size, style);
85 }
86 
87 
88 /*!
89  * CCDSExceptionPanel creator
90  */
91 
92 bool CCDSExceptionPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
93 {
94 ////@begin CCDSExceptionPanel creation
95  CQualListItemPanel::Create( parent, id, pos, size, style );
96 
98  if (GetSizer())
99  {
100  GetSizer()->SetSizeHints(this);
101  }
102  Centre();
103 ////@end CCDSExceptionPanel creation
104  return true;
105 }
106 
107 
108 /*!
109  * CCDSExceptionPanel destructor
110  */
111 
113 {
114 ////@begin CCDSExceptionPanel destruction
115 ////@end CCDSExceptionPanel destruction
116 }
117 
118 
119 /*!
120  * Member initialisation
121  */
122 
124 {
125 ////@begin CCDSExceptionPanel member initialisation
126  m_LabelSizer = NULL;
128  m_Sizer = NULL;
129 ////@end CCDSExceptionPanel member initialisation
130 }
131 
132 
133 /*!
134  * Control creation for CCDSExceptionPanel
135  */
136 
138 {
139 ////@begin CCDSExceptionPanel content construction
140  // Generated by DialogBlocks, 27/12/2011 11:29:33 (unregistered)
141 
142  CCDSExceptionPanel* itemCQualListItemPanel1 = this;
143 
144  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
145  itemCQualListItemPanel1->SetSizer(itemBoxSizer2);
146 
147  m_LabelSizer = new wxBoxSizer(wxHORIZONTAL);
148  itemBoxSizer2->Add(m_LabelSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
149 
150  wxStaticText* itemStaticText4 = new wxStaticText( itemCQualListItemPanel1, wxID_STATIC, _("AA"), wxDefaultPosition, wxSize(40, -1), 0 );
151  m_LabelSizer->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
152 
153  wxStaticText* itemStaticText5 = new wxStaticText( itemCQualListItemPanel1, wxID_STATIC, _("Amino Acid"), wxDefaultPosition, wxSize(100, -1), 0 );
154  m_LabelSizer->Add(itemStaticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
155 
156  wxStaticText* itemStaticText6 = new wxStaticText( itemCQualListItemPanel1, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxSize(30, -1), 0 );
157  m_LabelSizer->Add(itemStaticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
158 
159  m_ScrolledWindow = new wxScrolledWindow( itemCQualListItemPanel1, ID_SCROLLEDWINDOW4, wxDefaultPosition, wxSize(100, 100), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
160  itemBoxSizer2->Add(m_ScrolledWindow, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
161  m_ScrolledWindow->SetScrollbars(1, 1, 0, 0);
162  m_Sizer = new wxFlexGridSizer(0, 2, 0, 0);
163  m_ScrolledWindow->SetSizer(m_Sizer);
164 
165  m_ScrolledWindow->FitInside();
166 
167 ////@end CCDSExceptionPanel content construction
168  m_ScrollRate = 0;
169  m_TotalHeight = 0;
170  m_TotalWidth = 0;
171  m_ScrollRate = 0;
172  m_MinHeight = 0;
173  m_MinWidth = 0;
174 }
175 
176 
178 {
180  m_Sizer->Add(row, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 0);
181  row->TransferDataToWindow();
182 
183  wxHyperlinkCtrl* itemHyperlinkCtrl = new wxHyperlinkCtrl( m_ScrolledWindow, wxID_ANY,
184  wxT("Delete"), wxT(""), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
185  m_Sizer->Add(itemHyperlinkCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 0);
186 
187  x_AdjustForControl (row, itemHyperlinkCtrl);
188 }
189 
190 
191 static bool s_IsEmpty (CRef<CCode_break> code_break)
192 {
193  if (!code_break) {
194  return true;
195  } else if (code_break->IsSetAa() && code_break->GetAa().Which() != CCode_break::C_Aa::e_not_set) {
196  return false;
197  } else if (code_break->IsSetLoc() && code_break->GetLoc().Which() != CSeq_loc::e_not_set) {
198  return false;
199  } else {
200  return true;
201  }
202 }
203 
204 
206 {
207  m_AllowUpdates = false;
208  Freeze();
209  bool need_last_blank = true;
210 
211  wxSizerItemList& itemList = m_Sizer->GetChildren();
212  wxSizerItemList::iterator ctrl_it = itemList.begin();
213  size_t ctrl_pos = 0;
214  CCdregion& cds = m_EditedFeat->SetData().SetCdregion();
215  if (cds.IsSetCode_break()) {
216  for (CCdregion::TCode_break::iterator x = cds.SetCode_break().begin();
217  x != cds.SetCode_break().end();
218  x++) {
219  CSingleCDSExceptionPanel* transl_except = NULL;
220  while (transl_except == NULL && ctrl_it != itemList.end()) {
221  transl_except = dynamic_cast<CSingleCDSExceptionPanel*> ((**ctrl_it).GetWindow());
222  ctrl_it++;
223  ctrl_pos++;
224  }
225 
226  if (transl_except == NULL) {
227  x_AddRow (*x);
228  ctrl_pos += 2;
229  } else {
230  transl_except->SetCodeBreak(*x);
231  transl_except->TransferDataToWindow();
232  ctrl_it++;
233  ctrl_pos++;
234  }
235 
236  if (s_IsEmpty(*x)) {
237  need_last_blank = false;
238  } else {
239  need_last_blank = true;
240  }
241  }
242  }
243  if (need_last_blank) {
244  CRef<CCode_break> last_code_break (new CCode_break());
245  CSingleCDSExceptionPanel* transl_except = NULL;
246  while (transl_except == NULL && ctrl_it != itemList.end()) {
247  transl_except = dynamic_cast<CSingleCDSExceptionPanel*> ((**ctrl_it).GetWindow());
248  ctrl_it++;
249  ctrl_pos++;
250  }
251 
252  if (transl_except == NULL) {
253  x_AddRow (last_code_break);
254  ctrl_pos += 2;
255  } else {
256  transl_except->SetCodeBreak(last_code_break);
257  ctrl_it++;
258  ctrl_pos++;
259  }
260  }
261 
262  // remove extra blanks (or blank out?)
263  while (itemList.size() > ctrl_pos) {
264  m_Sizer->GetItem(ctrl_pos)->DeleteWindows();
265  m_Sizer->Remove(static_cast<int>(ctrl_pos));
266  }
267 
268  int win_height, win_width;
269 
270  m_ScrolledWindow->SetVirtualSize(m_TotalWidth, m_TotalHeight);
271  m_ScrolledWindow->GetSize(&win_width, &win_height);
272  m_ScrolledWindow->SetScrollRate(0, m_ScrollRate);
273  m_ScrolledWindow->GetSize(&win_width, &win_height);
274  m_ScrolledWindow->FitInside();
275  m_ScrolledWindow->GetSize(&win_width, &win_height);
276  Layout();
277 
278  int display_rows = 12;
279 
280 // m_ScrolledWindow->SetSize(m_TotalWidth + 20, display_rows * m_ScrollRate);
281  m_ScrolledWindow->SetMinSize(wxSize(m_TotalWidth + 20, display_rows * m_ScrollRate));
282  Layout();
283  Thaw();
284  if (!wxPanel::TransferDataToWindow())
285  return false;
286  m_AllowUpdates = true;
287  return true;
288 }
289 
290 
292 {
293  if (!wxPanel::TransferDataFromWindow()) {
294  return false;
295  }
296 
297  CCdregion& edit_cds = m_EditedFeat->SetData().SetCdregion();
298  edit_cds.ResetCode_break();
299  wxSizerItemList::iterator node = m_Sizer->GetChildren().begin();
300  while (node != m_Sizer->GetChildren().end()) {
301  CSingleCDSExceptionPanel* row = dynamic_cast< CSingleCDSExceptionPanel* >((*node)->GetWindow());
302  if (row) {
303  row->TransferDataFromWindow();
304  CRef<CCode_break> code_break = row->GetCodeBreak();
305  edit_cds.SetCode_break().push_back(code_break);
306  }
307  ++node;
308  }
309  return true;
310 }
311 
312 
313 void CCDSExceptionPanel::SetExceptions(objects::CCdregion& cds)
314 {
315  // set exceptions
316  cds.ResetCode_break();
317  CCdregion& edit_cds = m_EditedFeat->SetData().SetCdregion();
318  if (edit_cds.IsSetCode_break()) {
319  for (CCdregion::TCode_break::iterator x = edit_cds.SetCode_break().begin();
320  x != edit_cds.SetCode_break().end();
321  x++) {
322  if (((*x)->IsSetAa() && (*x)->GetAa().Which() != CCode_break::C_Aa::e_not_set) && ((*x)->IsSetLoc() && (*x)->GetLoc().Which() != CSeq_loc::e_not_set)) {
323  CRef<CCode_break> code_break(new CCode_break());
324  code_break->Assign(**x);
325  cds.SetCode_break().push_back(code_break);
326  }
327  }
328  }
329 
330 }
331 
332 
334 {
335  if (!m_AllowUpdates) {
336  return;
337  }
338  // is the row being changed the last one?
339  wxSizerItemList& itemList = m_Sizer->GetChildren();
340  auto num_items = itemList.size();
341  if (num_items > 1 && wnd == (itemList[num_items - 2])->GetWindow()) {
344  }
345 }
346 
347 
348 /*!
349  * Should we show tooltips?
350  */
351 
353 {
354  return true;
355 }
356 
357 /*!
358  * Get bitmap resources
359  */
360 
361 wxBitmap CCDSExceptionPanel::GetBitmapResource( const wxString& name )
362 {
363  // Bitmap retrieval
364 ////@begin CCDSExceptionPanel bitmap retrieval
365  wxUnusedVar(name);
366  return wxNullBitmap;
367 ////@end CCDSExceptionPanel bitmap retrieval
368 }
369 
370 /*!
371  * Get icon resources
372  */
373 
374 wxIcon CCDSExceptionPanel::GetIconResource( const wxString& name )
375 {
376  // Icon retrieval
377 ////@begin CCDSExceptionPanel icon retrieval
378  wxUnusedVar(name);
379  return wxNullIcon;
380 ////@end CCDSExceptionPanel icon retrieval
381 }
382 
383 int CCDSExceptionPanel::x_FindRow(wxWindow* wnd, wxSizerItemList& itemList)
384 {
385  if (NULL == wnd)
386  return -1;
387 
388  // start with -1, first qual found will bump it to 0
389  int row_num = -1;
390  for(wxSizerItemList::iterator it = itemList.begin(); it != itemList.end(); ++it) {
391  wxWindow* child = (**it).GetWindow();
392  if (child && child == wnd)
393  return row_num;
394 
395  CSingleCDSExceptionPanel* qual = dynamic_cast<CSingleCDSExceptionPanel*> (child);
396  if (qual) {
397  row_num++;
398  }
399  }
400 
401  return -1;
402 }
403 
404 
405 void CCDSExceptionPanel::OnDelete (wxHyperlinkEvent& event)
406 {
407  // find the control, remove it and the item before it, reset the scrolling
408  wxWindow* wnd = (wxWindow*)event.GetEventObject();
409  if (wnd == NULL) {
410  return;
411  }
412 
413  CCdregion& edit_cds = m_EditedFeat->SetData().SetCdregion();
414  wxSizerItemList& itemList = m_Sizer->GetChildren();
415  int row = x_FindRow (wnd, itemList);
416  if (row > -1) {
418  if (edit_cds.IsSetCode_break()) {
419  int j = 0;
420  CCdregion::TCode_break::iterator x = edit_cds.SetCode_break().begin();
421  while (j != row && x != edit_cds.SetCode_break().end()) {
422  x++;
423  j++;
424  }
425  if (x != edit_cds.SetCode_break().end()) {
426  edit_cds.SetCode_break().erase(x);
427  }
429  }
430  }
431 }
432 
static CRef< CScope > m_Scope
USING_SCOPE(objects)
static bool s_IsEmpty(CRef< CCode_break > code_break)
~CCDSExceptionPanel()
Destructor.
wxScrolledWindow * m_ScrolledWindow
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
virtual bool TransferDataFromWindow()
objects::CScope * m_Scope
void Init()
Initialises member variables.
static bool ShowToolTips()
Should we show tooltips?
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=ID_CCDSEXCEPTIONPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
CCDSExceptionPanel()
Constructors.
CRef< objects::CSeq_feat > m_EditedFeat
wxFlexGridSizer * m_Sizer
int x_FindRow(wxWindow *wnd, wxSizerItemList &itemList)
void CreateControls()
Creates the controls and sizers.
virtual void OnChildChange(wxWindow *wnd)
void x_AddRow(CRef< objects::CCode_break > code_break)
void SetExceptions(objects::CCdregion &cds)
virtual bool TransferDataToWindow()
void OnDelete(wxHyperlinkEvent &event)
CCdregion –.
Definition: Cdregion.hpp:66
CCode_break –.
Definition: Code_break.hpp:66
virtual void x_AdjustForControl(CQualListItemPanel *panel, wxHyperlinkCtrl *itemHyperlinkCtrl)
CScope –.
Definition: scope.hpp:92
ESubtype GetSubtype(void) const
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
void SetCodeBreak(CRef< objects::CCode_break > code_break)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
E_Choice Which(void) const
Which variant is currently selected.
const TLoc & GetLoc(void) const
Get the Loc member data.
void ResetCode_break(void)
Reset Code_break data member.
Definition: Cdregion_.cpp:80
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
TCode_break & SetCode_break(void)
Assign a value to Code_break data member.
Definition: Cdregion_.hpp:739
bool IsSetAa(void) const
Check if a value has been assigned to Aa data member.
const TAa & GetAa(void) const
Get the Aa member data.
bool IsSetLoc(void) const
location of exception Check if a value has been assigned to Loc data member.
bool IsSetCode_break(void) const
individual exceptions Check if a value has been assigned to Code_break data member.
Definition: Cdregion_.hpp:721
@ e_not_set
No variant selected.
E_Choice Which(void) const
Which variant is currently selected.
Definition: Seq_loc_.hpp:475
@ e_not_set
No variant selected.
Definition: Seq_loc_.hpp:97
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
#define _ASSERT
Modified on Mon Jul 15 05:34:15 2024 by modify_doxy.py rev. 669887