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

Go to the SVN repository for this file.

1 /* $Id: cross_aln_widget.cpp 46045 2021-01-21 18:02:04Z grichenk $
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: Vlad Lebedev
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include "cross_aln_pane.hpp"
33 
35 
38 
41 
42 #include <gui/utils/menu_item.hpp>
43 #include <objmgr/util/sequence.hpp>
44 
45 #include <wx/sizer.h>
46 #include <wx/menu.h>
47 
49 
51 {
52  static bool initialized = false;
53  if (initialized)
54  return;
55  initialized = true;
56 
57  cmd_reg.RegisterCommand(eCmdZoomInQuery, "Zoom In Query", "Zoom In Query", "", "");
58  cmd_reg.RegisterCommand(eCmdZoomOutQuery, "Zoom Out Query", "Zoom Out Query", "", "");
59  cmd_reg.RegisterCommand(eCmdZoomAllQuery, "Zoom All Query", "Zoom All Query", "", "");
60  cmd_reg.RegisterCommand(eCmdZoomSeqQuery, "Zoom To Sequence Query", "Zoom To Sequence Query", "", "");
61 
62 
63  cmd_reg.RegisterCommand(eCmdZoomInSubject, "Zoom In Subject", "Zoom In Subject", "", "");
64  cmd_reg.RegisterCommand(eCmdZoomOutSubject, "Zoom Out Subject", "Zoom Out Subject", "", "");
65  cmd_reg.RegisterCommand(eCmdZoomAllSubject, "Zoom All Subject", "Zoom All Subject", "", "");
66  cmd_reg.RegisterCommand(eCmdZoomSeqSubject, "Zoom To Sequence Subject", "Zoom To Sequence Subject", "", "");
67 
68  cmd_reg.RegisterCommand(eCmdChooseSeq, "Choose Sequence To Display...", "Choose Sequence To Display...", "", "");
69 }
70 
71 static
72 WX_DEFINE_MENU(sPopupMenu)
79  WX_SUBMENU("Zoom Special")
92 
93 BEGIN_EVENT_TABLE(CCrossAlnWidget, CGlWidgetBase)
94  EVT_SIZE(CCrossAlnWidget::OnSize)
95  EVT_COMMAND_SCROLL(ID_SCROLLBAR_Q, CCrossAlnWidget::OnScrollQ)
96  EVT_COMMAND_SCROLL(ID_SCROLLBAR_S, CCrossAlnWidget::OnScrollS)
97 
98  EVT_CONTEXT_MENU(CCrossAlnWidget::OnContextMenu)
102 
106 
110 
111  EVT_MENU(eCmdZoomSeq, CCrossAlnWidget::OnZoomToSeq)
112  EVT_MENU(eCmdZoomSeqQuery, CCrossAlnWidget::OnZoomToSeq_Q)
114 
115  EVT_MENU(eCmdZoomSel, CCrossAlnWidget::OnZoomSelection)
116  EVT_UPDATE_UI(eCmdZoomSel, CCrossAlnWidget::OnUpdateZoomSelection)
117 
118  EVT_MENU(eCmdChooseSeq, CCrossAlnWidget::OnChooseSeq)
119  //EVT_MENU(eCmdColorUsingScore, CCrossAlnWidget::OnColorByScore)
120  //EVT_MENU(eCmdColorUsingSegments, CCrossAlnWidget::OnColorBySegments)
122 
123 
124 
125 
126 CCrossAlnWidget::CCrossAlnWidget(wxWindow* parent, wxWindowID id,
127  const wxPoint& pos, const wxSize& size, long style)
128  : CGlWidgetBase(parent, id, pos, size, style)
129 {
130 }
131 
132 
134 {
135 }
136 
137 
139 {
140  _ASSERT( ! x_GetPane());
141 
142  x_CreatePane();
143 
144  CGlWidgetPane* child_pane = x_GetPane();
145  _ASSERT(child_pane);
146 
147  wxFlexGridSizer* sizer = new wxFlexGridSizer(3, 1, 0, 0);
148  this->SetSizer(sizer);
149 
150  sizer->AddGrowableCol(0);
151  sizer->AddGrowableRow(1);
152 
153 
154  wxScrollBar* sb = new wxScrollBar(this, ID_SCROLLBAR_Q, wxDefaultPosition,
155  wxDefaultSize, wxSB_HORIZONTAL);
156  sizer->Add(sb, 0, wxEXPAND);
157 
158  sizer->Add(child_pane, 1, wxEXPAND);
159 
160  sb = new wxScrollBar(this, ID_SCROLLBAR_S, wxDefaultPosition,
161  wxDefaultSize, wxSB_HORIZONTAL);
162  sizer->Add(sb, 0, wxEXPAND);
163 }
164 
166 {
167  m_CrossPane.reset(new CCrossAlnPane(this));
168 }
169 
170 
172 {
173  return static_cast<CGlWidgetPane*>(m_CrossPane.get());
174 }
175 
176 
178 {
179 }
180 
181 
183 {
184  return m_Port;
185 }
186 
187 
189 {
190  return m_Port;
191 }
192 
193 
195 {
196  m_CrossPane->Update();
197  //x_UpdatePane();
200 }
201 
202 
204 {
205  //m_CrossPane->Update();
206 }
207 
208 
209 
210 void CCrossAlnWidget::OnUpdateZoomSelection(wxUpdateUIEvent& event)
211 {
212  const TRangeColl& sel1 = m_CrossPane->GetQueryRangeSelection();
213  const TRangeColl& sel2 = m_CrossPane->GetSubjectRangeSelection();
214 
215  bool en = sel1.size() || sel2.size();
216  event.Enable(en);
217 }
218 
219 
220 void CCrossAlnWidget::OnZoomSelection(wxCommandEvent& event)
221 {
222  const TRangeColl& sel1 = m_CrossPane->GetQueryRangeSelection();
223  const TRangeColl& sel2 = m_CrossPane->GetSubjectRangeSelection();
224 
225  if (sel1.size()) {
226  m_CrossPane->ZoomOnRange_Q(sel1.GetFrom(), sel1.GetToOpen());
227  }
228  if (sel2.size()) {
229  m_CrossPane->ZoomOnRange_S(sel2.GetFrom(), sel2.GetToOpen());
230  }
231 }
232 
233 
234 void CCrossAlnWidget::OnChooseSeq(wxCommandEvent& event)
235 {
236  CIRef<ICrossAlnDataSource> ds(m_CrossPane->GetDataSource());
237 
238  if (ds) {
239  // get current settings
240  const IHitSeqId* query_id = &ds->GetQueryId();
241  const IHitSeqId* subject_id = &ds->GetSubjectId();
242 
243  IHitMatrixDataSource::SParams old_params, params;
244  ds->GetParams(old_params);
245 
246  // create and show the Dialog
247  CwxChooseSeqDlg dlg(this);
248  dlg.SetTitle(wxT("Choose Alignments to Display..."));
249 
250  dlg.SetSeqs(ds);
251 
252  if(dlg.ShowModal() == wxID_OK) {
253  const IHitSeqId* new_subject_id = dlg.GetSubjectId();
254  const IHitSeqId* new_query_id = dlg.GetQueryId();
255  dlg.GetParams(params);
256 
257  if(! new_subject_id->Equals(*subject_id) ||
258  ! new_query_id->Equals(*query_id) || ! (old_params == params)) {
259  query_id = new_query_id;
260  subject_id = new_subject_id;
261 
262  if (!(old_params == params))
263  ds->SetParams(params, false);
264 
265  ds->SelectIds(*subject_id, *query_id);
266  m_CrossPane->SetDataSource(ds.GetPointer());
267 
268  Update(); // create new cross-alignment
269  //x_Update
270  }
271  }
272  }
273 }
274 
275 void CCrossAlnWidget::OnColorBySegments(wxCommandEvent& event)
276 {
277  m_CrossPane->ColorBySegments();
278 }
279 
280 
281 void CCrossAlnWidget::OnColorByScore(wxCommandEvent& event)
282 {
283  /*CCrossAlnDataSource* ds = m_CrossPane->GetDataSource();
284 
285  if(ds)
286  {
287  CConstRef<CObject_id> curr_sc_id = m_CrossPane->GetScoreId();
288  int i_curr_sc = -1; // index of the currently used score
289 
290  // fill the list with all available scores
291  int scores_n = ds->GetScoresCount();
292  vector<string> items;
293  for( int i = 0; i < scores_n; i++ ) {
294  const CObject_id& id = ds->GetScoreId(i);
295  if(curr_sc_id.NotEmpty() && curr_sc_id->Match(id)) {
296  i_curr_sc = i; // this one is current
297  }
298 
299  items.push_back(id.GetStr());
300  }
301 
302  // create and show the Dialog
303  CScoreDlg dlg;
304  dlg.SetTitle("Color by Score...");
305  dlg.SetItems(items, i_curr_sc);
306  dlg.CenterOnActive();
307 
308  if(dlg.ShowModal() == wxID_OK) {
309  int score_index = dlg.GetSelectedIndex();
310  if(score_index != i_curr_sc) { // things did change - update pane
311  CConstRef<CObject_id> id(&ds->GetScoreId(score_index));
312  m_CrossPane->ColorByScore(id);
313  }
314  }
315  }*/
316 }
317 
318 
319 // All
320 void CCrossAlnWidget::OnZoomAll(wxCommandEvent& event)
321 {
322  m_CrossPane->ZoomAll();
323 }
324 
325 
326 void CCrossAlnWidget::OnZoomIn(wxCommandEvent& event)
327 {
328  m_CrossPane->ZoomIn();
329 }
330 
331 
332 void CCrossAlnWidget::OnZoomOut(wxCommandEvent& event)
333 {
334  m_CrossPane->ZoomOut();
335 }
336 
337 
338 // Query
339 void CCrossAlnWidget::OnZoomAll_Q(wxCommandEvent& event)
340 {
341  m_CrossPane->ZoomAll_Q();
342 }
343 
344 
345 void CCrossAlnWidget::OnZoomIn_Q(wxCommandEvent& event)
346 {
347  m_CrossPane->ZoomIn_Q();
348 }
349 
350 
351 void CCrossAlnWidget::OnZoomOut_Q(wxCommandEvent& event)
352 {
353  m_CrossPane->ZoomOut_Q();
354 }
355 
356 
357 // Subject
358 void CCrossAlnWidget::OnZoomAll_S(wxCommandEvent& event)
359 {
360  m_CrossPane->ZoomAll_S();
361 }
362 
363 
364 void CCrossAlnWidget::OnZoomIn_S(wxCommandEvent& event)
365 {
366  m_CrossPane->ZoomIn_S();
367 }
368 
369 
370 void CCrossAlnWidget::OnZoomOut_S(wxCommandEvent& event)
371 {
372  m_CrossPane->ZoomOut_S();
373 }
374 
375 
376 
377 
378 void CCrossAlnWidget::OnSize(wxSizeEvent& event)
379 {
380  CGlWidgetBase::OnSize(event);
381 
382  CGlWidgetPane* child_pane = x_GetPane();
383  if (!child_pane)
384  return;
385 
386  int w, h;
387  child_pane->GetClientSize(&w, &h);
388 
389  TVPRect rcVP(0, 0, w - 1, h - 1);
390  //GetPort().SetViewport(rcVP);
391  //GetPort().AdjustToLimits();
392  if (!m_CrossPane->GetRDR())
393  {
394  return;
395  } else {
396  m_CrossPane->GetRDR()->SetViewport(rcVP);
397  }
398 
400  Refresh();
401 }
402 
403 
404 static const int kScrollRange = 1000000;
405 static const double kPageInc = 0.8;
406 
408 {
409  if (!m_CrossPane->GetRDR())
410  return;
411 
412  wxScrollBar* sbQ = (wxScrollBar*)FindWindow(ID_SCROLLBAR_Q);
413  wxScrollBar* sbS = (wxScrollBar*)FindWindow(ID_SCROLLBAR_S);
414 
415  const TModelRect& rcMQ = m_CrossPane->GetRDR()->GetRP_Q().GetModelLimitsRect();
416  const TModelRect& rcVQ = m_CrossPane->GetRDR()->GetRP_Q().GetVisibleRect();
417 
418  const TModelRect& rcMS = m_CrossPane->GetRDR()->GetRP_S().GetModelLimitsRect();
419  const TModelRect& rcVS = m_CrossPane->GetRDR()->GetRP_S().GetVisibleRect();
420 
421  if (sbQ) {
422  CNormalizer norm(rcMQ.Left(), rcMQ.Right(), kScrollRange);
423 
424  int position = norm.RealToInt(rcVQ.Left());
425  int thumb_size = norm.SizeToInt(rcVQ.Width());
426  int page_size = norm.SizeToInt(rcVQ.Width() * kPageInc);
427 
428  sbQ->SetScrollbar(position, thumb_size, kScrollRange, page_size);
429  }
430 
431  if (sbS) {
432  CNormalizer norm(rcMS.Left(), rcMS.Right(), kScrollRange);
433 
434  int position = norm.RealToInt(rcVS.Left());
435  int thumb_size = norm.SizeToInt(rcVS.Width());
436  int page_size = norm.SizeToInt(rcVS.Width() * kPageInc);
437 
438  sbS->SetScrollbar(position, thumb_size, kScrollRange, page_size);
439  }
440 }
441 
442 
443 void CCrossAlnWidget::OnScrollQ(wxScrollEvent& event)
444 {
445  bool lock = wxGetKeyState(WXK_SHIFT);
446  double pQ = m_CrossPane->NormalizeQ(event.GetPosition());
447 
448  m_CrossPane->Scroll(pQ, !lock ? pQ : 0);
449  m_CrossPane->Refresh();
451 }
452 
453 void CCrossAlnWidget::OnScrollS(wxScrollEvent& event)
454 {
455  bool lock = wxGetKeyState(WXK_SHIFT);
456  double pS = m_CrossPane->NormalizeS( event.GetPosition() );
457 
458  m_CrossPane->Scroll(!lock ? pS : 0, pS);
459  m_CrossPane->Refresh();
461 }
462 
463 
464 void CCrossAlnWidget::OnZoomToSeq(wxCommandEvent& event)
465 {
466  m_CrossPane->ZoomToSeq_Q();
467  m_CrossPane->ZoomToSeq_S();
468 }
469 
470 
471 void CCrossAlnWidget::OnZoomToSeq_Q(wxCommandEvent& event)
472 {
473  m_CrossPane->ZoomToSeq_Q();
474 }
475 
476 
477 void CCrossAlnWidget::OnZoomToSeq_S(wxCommandEvent& event)
478 {
479  m_CrossPane->ZoomToSeq_S();
480 }
481 
482 
484 {
485  m_CrossPane->SetDataSource(ds);
486 
487  x_Update();
488 }
489 
490 
492 {
494  const CGlPane& pane = m_CrossPane->GetRDR()->GetRP_S();
495  range.SetFrom((TSeqPos)pane.GetVisibleRect().Left());
496  range.SetTo ((TSeqPos)pane.GetVisibleRect().Right());
497  return range;
498 }
499 
500 
502 {
503  m_CrossPane->ZoomOnRange_S(range.GetFrom(), range.GetTo());
504 }
505 
506 
508 {
510  const CGlPane& pane = m_CrossPane->GetRDR()->GetRP_Q();
511  range.SetFrom((TSeqPos)pane.GetVisibleRect().Left());
512  range.SetTo ((TSeqPos)pane.GetVisibleRect().Right());
513  return range;
514 }
515 
516 
518 {
519  m_CrossPane->ZoomOnRange_Q(range.GetFrom(), range.GetTo());
520 }
521 
522 
525 {
526  return m_CrossPane->GetSubjectRangeSelection();
527 }
528 
529 
532 {
533  return m_CrossPane->GetQueryRangeSelection();
534 }
535 
536 
538 {
539  m_CrossPane->SetSubjectRangeSelection(coll);
540 }
541 
542 
544 {
545  m_CrossPane->SetQueryRangeSelection(coll);
546 }
547 
548 
550 {
551  m_CrossPane->ResetObjectSelection();
552 }
553 
554 
556 {
557  m_CrossPane->GetObjectSelection(objs);
558 }
559 
560 
561 void CCrossAlnWidget::SetObjectSelection(const vector<const CSeq_align*> sel_aligns)
562 {
563  m_CrossPane->SetObjectSelection(sel_aligns);
564 }
565 
566 
568 {
569  m_CrossPane->Update();
571  Refresh();
572 }
573 
574 
575 void CCrossAlnWidget::OnContextMenu(wxContextMenuEvent& event)
576 {
578  unique_ptr<wxMenu> menu(cmd_reg.CreateMenu(sPopupMenu));
579  PopupMenu(menu.get());
580 }
581 
582 
EVT_UPDATE_UI(eCmdAlnShowMethodsDlg, CAlnMultiWidget::OnUpdateShowMethodDlg) EVT_UPDATE_UI(eCmdMethodProperties
virtual void x_CreateControls()
creates Pane, Scrollbars and other child widgets, called from Create()
void OnSize(wxSizeEvent &event)
void SetDataSource(ICrossAlnDataSource *ds)
void SetSubjectRangeSelection(const TRangeColl &coll)
TSeqRange GetSubjectVisibleRange() const
void OnZoomToSeq(wxCommandEvent &event)
void OnZoomToSeq_S(wxCommandEvent &event)
void OnColorByScore(wxCommandEvent &event)
void OnUpdateZoomSelection(wxUpdateUIEvent &event)
virtual CGlWidgetPane * x_GetPane()
void OnZoomOut_Q(wxCommandEvent &event)
unique_ptr< CCrossAlnPane > m_CrossPane
void OnZoomAll_Q(wxCommandEvent &event)
void OnZoomAll(wxCommandEvent &event)
void OnContextMenu(wxContextMenuEvent &event)
void GetObjectSelection(TConstObjects &objs) const
void OnZoomSelection(wxCommandEvent &event)
void OnZoomIn_Q(wxCommandEvent &event)
virtual CGlPane & GetPort()
implement these 2 functions in derived classes
void SetQueryVisibleRange(const TSeqRange &range)
virtual ~CCrossAlnWidget()
void OnScrollS(wxScrollEvent &event)
void OnZoomAll_S(wxCommandEvent &event)
void SetSubjectVisibleRange(const TSeqRange &range)
void OnZoomOut_S(wxCommandEvent &event)
TSeqRange GetQueryVisibleRange() const
const TRangeColl & GetQueryRangeSelection() const
static void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
void OnColorBySegments(wxCommandEvent &event)
virtual void x_Update()
Update handlers.
virtual void x_SetPortLimits()
updates model limits of the Master CGlPane
const TRangeColl & GetSubjectRangeSelection() const
void OnChooseSeq(wxCommandEvent &event)
void OnZoomIn(wxCommandEvent &event)
void SetQueryRangeSelection(const TRangeColl &coll)
void SetObjectSelection(const vector< const objects::CSeq_align * > sel_aligns)
void OnZoomOut(wxCommandEvent &event)
void OnScrollQ(wxScrollEvent &event)
virtual void x_CreatePane()
factory method creating master pane, called form x_CreateControls()
virtual void x_UpdatePane()
void OnZoomToSeq_Q(wxCommandEvent &event)
void OnZoomIn_S(wxCommandEvent &event)
class CGlPane
Definition: glpane.hpp:62
class CGlWidgetBase
void OnSize(wxSizeEvent &event)
virtual void x_RedrawControls(void)
CGlWidgetPane represent a window component residing in CGlWidgetBase client area.
this class converts model units to the integers distribited in [0, m_IntRange] and vice versa
int RealToInt(double real)
int SizeToInt(double size)
size_type size() const
Definition: range_coll.hpp:98
position_type GetToOpen() const
Definition: range_coll.hpp:126
position_type GetFrom() const
Definition: range_coll.hpp:120
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
wxMenu * CreateMenu(const SwxMenuItemRec *items)
create a menu from a static definition (see WX_*_MENU macros)
Definition: ui_command.cpp:349
int RegisterCommand(CUICommand *cmd)
assumes ownership of the given object returns a command id (useful when registry is used for auto id ...
Definition: ui_command.cpp:198
const IHitSeqId * GetSubjectId()
const IHitSeqId * GetQueryId()
void SetSeqs(CIRef< IHitMatrixDataSource > ds)
void GetParams(IHitMatrixDataSource::SParams &params) const
IHitMatrixDataSource - abstract Data Source for Hit Matrix Widget.
IHitSeqId - abstract identifier of a sequence in an alignment.
virtual bool Equals(const IHitSeqId &id) const =0
static const int kScrollRange
static const double kPageInc
@ ID_SCROLLBAR_Q
@ ID_SCROLLBAR_S
@ eCmdZoomOutSubject
@ eCmdZoomAllSubject
@ eCmdZoomInQuery
@ eCmdZoomSeqSubject
@ eCmdZoomInSubject
@ eCmdZoomOutQuery
@ eCmdZoomSeqQuery
@ eCmdChooseSeq
@ eCmdZoomAllQuery
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
T Width() const
Definition: glrect.hpp:86
T Right() const
Definition: glrect.hpp:83
T Left() const
Definition: glrect.hpp:81
TModelRect & GetVisibleRect(void)
Definition: glpane.hpp:357
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
@ eCmdZoomIn
empty command
Definition: command.hpp:68
@ eCmdZoomOut
Definition: command.hpp:69
@ eCmdZoomSeq
Zoom to Selection.
Definition: command.hpp:74
@ eCmdZoomAll
Definition: command.hpp:70
@ eCmdZoomSel
Definition: command.hpp:73
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
range(_Ty, _Ty) -> range< _Ty >
const struct ncbi::grid::netcache::search::fields::SIZE size
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
#define _ASSERT
#define WX_DEFINE_MENU(name)
New macros for defining menus for use with CUICommandRegistry.
Definition: ui_command.hpp:266
#define WX_SUBMENU(label)
Definition: ui_command.hpp:288
#define WX_END_MENU()
Definition: ui_command.hpp:294
#define WX_MENU_ITEM(cmd)
Definition: ui_command.hpp:270
#define WX_MENU_SEPARATOR()
Definition: ui_command.hpp:282
#define WX_END_SUBMENU()
Definition: ui_command.hpp:291
#define const
Definition: zconf.h:232
Modified on Mon Jul 22 05:03:00 2024 by modify_doxy.py rev. 669887