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

Go to the SVN repository for this file.

1 /* $Id: hit_matrix_pane.cpp 42775 2019-04-11 14:59:28Z katargir $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <corelib/ncbistl.hpp>
35 #include <corelib/ncbitime.hpp>
36 
41 
42 #include <gui/objutils/label.hpp>
43 #include <gui/utils/view_event.hpp>
44 
45 #include <gui/opengl/glresmgr.hpp>
46 
47 #include <objmgr/util/sequence.hpp>
48 
51 
52 BEGIN_EVENT_TABLE(CHitMatrixPane, CGlWidgetPane)
53  EVT_SIZE(CHitMatrixPane::OnSize)
55 
56 
58 : CGlWidgetPane(parent, wxID_ANY),
59  m_HorzSelHandler(eHorz),
60  m_VertSelHandler(eVert),
61  m_TooltipArea(0)
62 {
63  if(GetParent()) {
64  // TODO this is wrong, parent must establish conections
65  CHitMatrixWidget* parent = x_GetParent();
66  AddListener(parent, ePool_Parent);
67  }
68 
69  // setup Event Handlers
70  m_HorzSelHandler.SetHost(this);
71  x_RegisterHandler(&m_HorzSelHandler,
73  &m_Renderer.GetSubjectPane());
74 
75  m_VertSelHandler.SetHost(this);
76  x_RegisterHandler(&m_VertSelHandler,
78  &m_Renderer.GetQueryPane());
79 
80  CHitMatrixGraph& graph = m_Renderer.GetGraph();
81  graph.SetHost(this);
82  x_RegisterHandler(&graph, CHitMatrixRenderer::fMatrixArea, &m_Renderer.GetMatrixPane());
83 
84  m_MouseZoomHandler.SetHost(this);
85  x_RegisterHandler(&m_MouseZoomHandler, CHitMatrixRenderer::fMatrixArea, &m_Renderer.GetMatrixPane());
86 
87  m_TooltipHandler.SetMode(CTooltipHandler::eHideOnMove);
88  m_TooltipHandler.SetHost(this);
89  x_RegisterHandler(&m_TooltipHandler, CHitMatrixRenderer::fAllAreas,
90  &m_Renderer.GetMatrixPane());
91 }
92 
93 
95 {
96  CHitMatrixWidget* parent = x_GetParent();
97  if(parent) { // disconnect old parent
98  RemoveListener(parent);
99  }
100 }
101 
103 {
105  return TVPPoint(rc.Width(), rc.Height());
106 }
107 
108 
109 void CHitMatrixPane::OnSize(wxSizeEvent& event)
110 {
111  //Layout();
112  wxSize sz = GetSize();
113  m_Renderer.Resize(sz.x, sz.y, x_GetParent()->GetPort());
114 
115  event.Skip();
116 }
117 
118 
120 {
121  if (x_GetParent()) {
122  const CGlPane& VP = x_GetParent()->GetPort();
123 
124  // prepare CGlPanes
125  TModelRect rc_V = VP.GetVisibleRect();
126  rc_V.SetBottom(range.GetFrom());
127  rc_V.SetTop (range.GetTo());
128  x_GetParent()->ZoomRect(rc_V);
129  }
130 }
131 
132 
134 {
135  if (x_GetParent()) {
136  const CGlPane& VP = x_GetParent()->GetPort();
137 
138  // prepare CGlPanes
139  TModelRect rc_V = VP.GetVisibleRect();
140  rc_V.SetLeft (range.GetFrom());
141  rc_V.SetRight(range.GetTo());
142  x_GetParent()->ZoomRect(rc_V);
143  }
144 }
145 
146 
148 {
149  x_RenderContent();
150 }
151 
152 
154 {
155  _ASSERT(x_GetParent());
156 
159 }
160 
162 {
163  switch(seq) {
164  case eSubject:
166  case eQuery:
168  default:
169  _ASSERT(false);
171  }
172 }
173 
174 
176 {
177  switch(seq) {
178  case eSubject:
179  m_HorzSelHandler.SetSelection(coll, true);
180  break;
181  case eQuery:
182  m_VertSelHandler.SetSelection(coll, true);
183  break;
184  }
185 }
186 
187 
189 {
190  //TODO
192 }
193 
194 
196 {
197  set<const CSeq_align*> aligns; // selected aligns
198 
200 
201  // build a set of CSeq_aligns corresponding to selected glyphs
202  ITERATE(CHitMatrixPane::TElemGlyphSet, it_G, glyphs) {
203  const IHitElement& elem = (*it_G)->GetHitElem();
204  const IHit& hit = elem.GetHit();
205  aligns.insert(hit.GetSeqAlign());
206 
207  }
208 
209  objs.reserve(aligns.size());
210  ITERATE(set<const CSeq_align*>, it_align, aligns) {
211  objs.push_back(CConstRef<CObject>(*it_align));
212  }
213 }
214 
215 
216 void CHitMatrixPane::SetObjectSelection(const vector<const CSeq_align*> sel_aligns)
217 {
219 
220  typedef CHitMatrixGraph::THitGlyphVector TGlyphs;
221  const TGlyphs& glyphs = m_Renderer.GetGraph().GetGlyphs();
222  ITERATE(TGlyphs, it_G, glyphs) {
223  const CHitGlyph& glyph = **it_G;
224  const CSeq_align* align = glyph.GetHit().GetSeqAlign();
225 
226  if(std::find(sel_aligns.begin(), sel_aligns.end(), align)
227  != sel_aligns.end()) {
229  }
230  }
231 }
232 
234 {
235  return x_GetParent()->GetPort().GetViewport();
236 }
237 
238 
239 void CHitMatrixPane::RenderVectorGraphics(int vp_width, int vp_height)
240 {
241  if (!x_GetParent() || !x_GetParent()->GetDS())
242  return;
243 
244  m_Renderer.Render(x_GetParent()->GetPort(), true);
247 }
248 
250 {
251 }
252 
254 {
255 }
256 
258 {
259  if (!x_GetParent() || !x_GetParent()->GetDS())
260  return;
261 
263  GetRenderer( CGlResMgr::Instance().GetApiLevel());
264  if (mgr.IsNull()) {
265  LOG_POST(Error << "IRender object not available.");
266  return;
267  }
269 
273 }
274 
275 
277 {
278  return m_Renderer.GetAreaByVPPos(vp_x, vp_y);
279 }
280 
281 
283 {
284  CGlPane pane;
285  pane.EnableOffset(true);
286 
287  // horizontal selection
290  rc_vp.CombineWith(rc_gr);
291  pane.SetViewport(rc_vp);
292  CGlPane& subject_pane = m_Renderer.GetSubjectPane();
293  pane.SetModelLimitsRect(subject_pane.GetModelLimitsRect());
294  pane.SetVisibleRect(subject_pane.GetVisibleRect());
295 
296  if ( m_Renderer.GetMatrixPane().GetViewport().Width() < 10 ||
298  return;
299 
300  if(rc_vp.Width() > 0 && rc_vp.Height() > 0) {
302  }
304 
305  // vertical selection
308  rc_vp.CombineWith(rc_gr);
309  pane.SetViewport(rc_vp);
310  CGlPane& query_pane = m_Renderer.GetQueryPane();
311  pane.SetModelLimitsRect(query_pane.GetModelLimitsRect());
312  pane.SetVisibleRect(query_pane.GetVisibleRect());
313 
314  if(rc_vp.Width() > 0 && rc_vp.Height() > 0) {
316  }
318 }
319 
320 
322 {
323  IRender& gl = GetGl();
324  gl.Enable(GL_BLEND);
325  gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
326 
328 
329  gl.Disable(GL_BLEND);
330 }
331 
332 
334 {
335  IRender& gl = GetGl();
336  gl.Enable(GL_BLEND);
337  gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
338 
340  handler.Render(pane, option);
341 
342  gl.Disable(GL_BLEND);
343 }
344 
345 ////////////////////////////////////////////////////////////////////////////////
346 /// IMouseZoomHandlerHost implementation
347 
349 {
350  const CGlPane& VP = x_GetParent()->GetPort();
351 
352  switch(type) {
353  case eCurrent: return VP.GetScaleX();
354  case eMin: return VP.GetMinScaleX();
355  case eMax: return VP.GetZoomAllScaleX();
356  default: _ASSERT(false); return -1;
357  }
358 }
359 
360 
362 {
363  x_GetParent()->SetScaleX(scale, point);
364 }
365 
366 
368 {
369  x_GetParent()->ZoomRect(rc);
370 
371  // translate the notification to the standard message
373 }
374 
375 
377 {
378  x_GetParent()->ZoomPoint(point, factor);
379 
380  // translate the notification to the standard message
382 }
383 
384 
386 {
387  // translate the notification to the standard message
389 }
390 
391 
393 {
394  x_GetParent()->Scroll(d_x, d_y);
395 
396  // translate the notification to the standard message
398 }
399 
400 
402 {
403  return GetClientSize().y - 1 - y;
404 }
405 
406 
408 {
410  Send(&evt, ePool_Parent);
411 
412  Refresh();
413 }
414 
415 
417 {
418  return GetClientSize().y - 1 - y;
419 }
420 
421 
422 ////////////////////////////////////////////////////////////////////////////////
423 /// ISelHandlerHost implementation
425 {
427  Send(&evt, ePool_Parent);
428  Refresh();
429 }
430 
431 
433 {
434  switch(orient) {
435  case eHorz:
436  return m_Renderer.GetMatrixPane().UnProjectX(z);
437 
438  case eVert:
439  return m_Renderer.GetMatrixPane().UnProjectY(GetSize().y - z);
440 
441  default:
442  _ASSERT(false);
443  return -1;
444  }
445 }
446 
447 
449 {
450  switch(orient) {
451  case eHorz:
452  return m_Renderer.GetMatrixPane().ProjectX(z);
453 
454  case eVert:
455  return GetSize().y - m_Renderer.GetMatrixPane().ProjectY(z);
456 
457  default:
458  _ASSERT(false);
459  return -1;
460  }
461 }
462 
463 
464 ///////////////////////////////////////////////////////////////////////////////
465 /// ITooltip Implementation
466 /// TC_NeedTooltip() and TC_GetTooltip() is everything needed to show toolitps
467 /// in "active" mode
468 
469 bool CHitMatrixPane::TC_NeedTooltip(const wxPoint & pt)
470 {
472  int vp_y = GetSize().y - pt.y;
473 
474  return m_Renderer.NeedTooltip(m_TooltipArea, pt.x, vp_y);
475 }
476 
477 
478 string CHitMatrixPane::TC_GetTooltip(const wxRect & rect)
479 {
481 }
482 
483 
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
class CGlPane
Definition: glpane.hpp:62
virtual void Scroll(TModelUnit d_x, TModelUnit d_y)
virtual void NotifyVisibleRangeChanged()
virtual void ZoomRect(const TModelRect &rc)
virtual void ZoomPoint(const TModelPoint &point, TModelUnit factor, CGlPane::EZoomOptions=CGlPane::fZoomXY)
CGlWidgetPane represent a window component residing in CGlWidgetBase client area.
virtual int x_GetAreaByWindowPos(const wxPoint &pos)
CHitGlyph is a simple graphical object representing a Hit as a set of corresponding Hit Elements.
const IHit & GetHit() const
CHitMatrixGraph.
const TElemGlyphSet & GetSelectedGlyphs() const
void SelectGlyph(const CHitGlyph &glyph)
const THitGlyphVector & GetGlyphs() const
vector< CHitGlyph * > THitGlyphVector
void SetHost(IHitMatrixGraphHost *host)
class CHitMatrixPane
virtual void MZHH_EndOp() override
virtual int x_GetAreaByVPPos(TVPUnit vp_x, TVPUnit vp_y) override
void GetObjectSelection(TConstObjects &objs) const
CLinearSelHandler m_VertSelHandler
virtual TModelUnit SHH_GetModelByWindow(int z, EOrientation orient) override
CLinearSelHandler m_HorzSelHandler
virtual TVPPoint GetPortSize(void) override
returns size of the master pane in screen coordinates
void x_RenderMouseZoomHandler(CGlPane &pane)
void OnSize(wxSizeEvent &event)
CMouseZoomHandler m_MouseZoomHandler
virtual void MZHH_Scroll(TModelUnit d_x, TModelUnit d_y) override
virtual void RenderVectorGraphics(int vp_width, int vp_height) override
void SetSubjectVisibleRange(const TSeqRange &range)
virtual void AddTitle(bool b) override
CHitMatrixRenderer m_Renderer
void SetQueryVisibleRange(const TSeqRange &range)
virtual CHitMatrixRenderer & GetRenderer()
virtual string TC_GetTooltip(const wxRect &) override
Returns tooltip string and coordinates for area tootlip associated with.
virtual void MZHH_ZoomRect(const TModelRect &rc) override
CHitMatrixWidget * x_GetParent()
virtual void UpdateVectorLayout() override
ESequence
identifies one of the two sequences in the pane
virtual const TVPRect & GetViewportRect() const override
virtual void Update(void) override
virtual void SHH_OnChanged() override
ISelHandlerHost implementation.
virtual void HMGH_OnChanged(void) override
virtual bool TC_NeedTooltip(const wxPoint &) override
ITooltip Implementation TC_NeedTooltip() and TC_GetTooltip() is everything needed to show toolitps in...
virtual TVPUnit SHH_GetWindowByModel(TModelUnit z, EOrientation orient) override
virtual TVPUnit HMGH_GetVPPosByY(int y) const override
virtual TVPUnit MZHH_GetVPPosByY(int y) const override
converts window coord to Viewport coord
virtual void x_Render(void) override
CGlWidgetPane overridables.
virtual ~CHitMatrixPane()
void x_RenderContent(void)
virtual void MZHH_SetScale(TModelUnit scale, const TModelPoint &point) override
virtual TModelUnit MZHH_GetScale(EScaleType type) override
IMouseZoomHandlerHost implementation.
virtual void MZHH_ZoomPoint(const TModelPoint &point, TModelUnit factor) override
void SetRangeSelection(const TRangeColl &coll, ESequence seq)
void SetObjectSelection(const vector< const objects::CSeq_align * > sel_aligns)
const TRangeColl & GetRangeSelection(ESequence seq) const
CHitMatrixGraph & GetGraph()
virtual bool NeedTooltip(int area, int vp_x, int vp_y)
virtual int GetAreaByVPPos(TVPUnit vp_x, TVPUnit vp_y)
virtual void Update(IHitMatrixDataSource *ds, const CGlPane &port)
TVPRect GetRect(EArea area)
virtual void Render(const CGlPane &port, bool pdf=false)
virtual string GetTooltip(int area)
virtual void Resize(int w, int h, const CGlPane &port)
class CHitMatrixWidget
virtual IHitMatrixDataSource * GetDS()
virtual void SetScaleX(TModelUnit scale_x, const TModelPoint &point)
virtual CGlPane & GetPort()
implement these 2 functions in derived classes
Class CLinearSelHandler represents in GUI a one-dimnesional multi-segment selection.
void Render(CGlPane &Pane, ERenderingOption option=eActiveState)
void SetSelection(const TRangeColl &C, bool bRedraw)
const TRangeColl & GetSelection() const
virtual void Render(CGlPane &Pane)
@ eWidgetSelectionChanged
a view has been destroyed
Definition: view_event.hpp:55
IHitElement.
Definition: hit.hpp:50
virtual const IHit & GetHit() const =0
IHitMatrixDataSource - abstract Data Source for Hit Matrix Widget.
IHit.
Definition: hit.hpp:69
virtual const objects::CSeq_align * GetSeqAlign() const =0
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
size_type size() const
Definition: set.hpp:132
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
#define option
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
GLdouble TModelUnit
Definition: gltypes.hpp:48
void SetModelLimitsRect(const TModelRect &R)
Definition: glpane.hpp:342
void SetRight(T right)
Definition: glrect.hpp:114
static CGlResMgr & Instance()
Definition: glresmgr.cpp:59
T Height() const
Definition: glrect.hpp:90
void SetViewport(const TVPRect &R)
Definition: glpane.cpp:96
virtual void Enable(GLenum glstate)=0
CGlPoint< TVPUnit > TVPPoint
Definition: gltypes.hpp:50
void SetBottom(T bottom)
Definition: glrect.hpp:113
CGlRect & CombineWith(const CGlRect &r)
Definition: glrect.hpp:223
virtual void BlendFunc(GLenum sfactor, GLenum dfactor)=0
Options to be used when GL_BLEND is enabled.
T Width() const
Definition: glrect.hpp:86
TVPUnit ProjectX(TModelUnit m_x) const
Definition: glpane.cpp:661
IRender & GetGl()
convenience function for getting current render manager
TVPRect & GetViewport(void)
Definition: glpane.hpp:332
TVPUnit ProjectY(TModelUnit m_y) const
Definition: glpane.cpp:676
TModelUnit UnProjectX(TVPUnit m_x) const
Definition: glpane.cpp:706
TModelRect & GetModelLimitsRect(void)
Definition: glpane.hpp:347
TModelUnit UnProjectY(TVPUnit m_y) const
Definition: glpane.cpp:722
int TVPUnit
Definition: gltypes.hpp:47
TModelUnit GetZoomAllScaleX(void) const
Definition: glpane.cpp:133
void SetCurrentRenderer(CIRef< IRender > rm)
Set current renderer (rm must already be in m_Renderers)
Definition: glresmgr.cpp:281
void SetVisibleRect(const TModelRect &R)
Definition: glpane.cpp:113
void SetLeft(T left)
Definition: glrect.hpp:112
TModelRect & GetVisibleRect(void)
Definition: glpane.hpp:357
virtual void Disable(GLenum glstate)=0
glDisable()
TModelUnit GetMinScaleX(void) const
Definition: glpane.hpp:452
TModelUnit GetScaleX(void) const
Definition: glpane.cpp:118
void SetTop(T top)
Definition: glrect.hpp:115
EOrientation
Definition: gltypes.hpp:58
void EnableOffset(bool b_en=true)
Offset is used as a workaround for OpenGL precision problems emerging when size of visible range is s...
Definition: glpane.hpp:405
@ eHorz
Definition: gltypes.hpp:59
@ eVert
Definition: gltypes.hpp:60
virtual void RemoveListener(CEventHandler *listener)
Remove a listener.
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
virtual bool Send(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Sends an event synchronously.
@ eEvent_Message
message from one class to another
Definition: event.hpp:99
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
unsigned short GetPort() const
Get the listening port number back.
USING_SCOPE(objects)
END_EVENT_TABLE()
range(_Ty, _Ty) -> range< _Ty >
The NCBI C++/STL use hints.
Defines: CTimeFormat - storage class for time format.
static static static wxID_ANY
Definition: type.c:6
#define _ASSERT
Modified on Tue Apr 23 07:38:39 2024 by modify_doxy.py rev. 669887