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

Go to the SVN repository for this file.

1 /* $Id: layout_track_impl.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: Liangshou Wu
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
38 #include <gui/opengl/irender.hpp>
39 #include <gui/opengl/glutils.hpp>
40 #include <gui/opengl/glresmgr.hpp>
43 #include <gui/objutils/tooltip.hpp>
44 #include <gui/objutils/utils.hpp>
46 #include <math.h>
47 #include <corelib/ncbi_url.hpp>
48 
50 
51 static const int kIndent = 14; /// in pixel
52 static const int kInvalidIcon = -1;
53 
56 
58  : m_Order(-1)
59  , m_On(true)
60  , m_ShowFrame(false)
61  , m_Expanded(true)
62  , m_HighlightedIcon(kInvalidIcon)
63  , m_Attrs(fDefaultAttr)
64  , m_LTHost(NULL)
65  , m_Title(kEmptyStr)
66  , m_Msg(kEmptyStr)
67  , m_Progress(100)
68  , m_IndentLevel(0) // 0 means first level track
69  , m_ParentTrack(NULL)
70 {
71  SetRenderingContext(r_cntx);
72  x_RegisterIcon(SIconInfo(eIcon_Close, "Close", true, "track_close"));
73  x_RegisterIcon(SIconInfo(eIcon_Expand, "Collapse/Expand", true,
74  "track_expand", "track_collapse"));
75  // x_Validate("Constructor");
76 }
77 
78 
80 {
81  // x_Validate("Destructor");
82 }
83 
84 
85 
86 void CLayoutTrack::LoadProfile(const string& profile_str)
87 {
88  // cerr << "<<<< profile_str: " << profile_str << endl;
89  // x_Validate("LoadProfile in");
90  SetProfile(profile_str);
91  TKeyValuePairs settings;
92  CSGConfigUtils::ParseProfileString(profile_str, settings);
93  string profile = kEmptyStr;
94  if (settings.empty()) {
95  profile = profile_str;
96  } else {
97  TKeyValuePairs::iterator iter = settings.find("profile");
98  if (iter != settings.end()) {
99  profile = iter->second;
100  settings.erase(iter);
101  }
102 // iter = settings.find("comments");
103 // if (iter != settings.end()) {
104 // SetComments(iter->second);
105 // settings.erase(iter);
106 // }
107  }
108  x_LoadSettings(profile, settings);
109  // cerr << ">>>>" << endl;
110  // x_Validate("LoadProfile out");
111 }
112 
113 
115 {
116  // x_Validate("SaveProfile in");
117  TKeyValuePairs settings;
119  string preset_style = kEmptyStr;
120  if (settings.empty()) {
121  preset_style = GetProfile();
122  } else {
123  TKeyValuePairs::iterator iter = settings.find("profile");
124  if (iter != settings.end()) {
125  preset_style = iter->second;
126  }
127  }
128  x_SaveSettings(preset_style);
129  // x_Validate("SaveProfile out");
130 }
131 
132 
134 {
135  // x_Validate("SetTrackAttr in");
136  m_Attrs = flags;
137  if ( ! (m_Attrs & fCollapsible) ) {
140  }
141  // x_Validate("SetTrackAttr out");
142 }
143 
145 {
146  // x_Validate("CloseMe in");
147  SetShow(false);
148  ITrackContainer* parent = dynamic_cast<ITrackContainer*>(GetParentTrack());
149  if (parent) {
150  parent->CloseTrack(GetOrder());
151  }
152  // x_Validate("CloseMe out");
153 }
154 
155 
157 {
158  // x_Validate("ShowMe in");
159  SetShow(true);
160  x_Expand(true);
161  // x_Validate("ShowMe out");
162 }
163 
164 
166 {
167  // x_Validate("OnLeftDown inm");
168  bool consumed = false;
169  // do we have title bar at all
170  if (m_Attrs & fFrameVisible && m_ShowFrame) {
171  IRender& gl = GetGl();
172 
173  TModelPoint pp(p);
174  x_World2Local(pp);
175  int idx = x_HitIconTest(pp);
176  if (idx >= 0 && m_Icons[idx].m_Enabled) {
178  consumed = true;
179  } else if (m_gConfig->GetShowTrackMinusPlusSign()) {
180  TModelRect rcm;
181  x_GetTBRect(rcm);
183  TModelUnit half_size = gl.TextWidth(com_font, "+");
184  if (m_IndentLevel > 1) {
185  half_size *= 1.5;
186  }
187  half_size = m_Context->ScreenToSeq(half_size);
188 
189  TModelUnit center_x = rcm.Left() + half_size;
190  m_Context->AdjustToOrientation(center_x);
191  rcm.SetLeft(center_x - half_size);
192  rcm.SetRight(center_x + half_size);
193  if (PointInRect(pp, rcm)) {
195  consumed = true;
196  }
197  }
198  }
199  // x_Validate("OnLeftDown out");
200  return consumed;
201 }
202 
203 
205 {
206  // x_Validate("OnLeftDblClick in");
207  bool consumed = false;
208  // do we have title bar at all
209  if (m_Attrs & fFrameVisible && m_ShowFrame) {
210  TModelPoint pp(p);
211  x_World2Local(pp);
212  if (x_HitTitleBar(pp) && m_Attrs & fCollapsible) {
214  consumed = true;
215  }
216  }
217  // x_Validate("OnLeftDblClick out");
218  return consumed;
219 }
220 
221 /*
222 bool CLayoutTrack::// x_Validate(const string& sCodeLocation) const
223 {
224  if(this == NULL) {
225  LOG_POST(Error << sCodeLocation << ": CLayoutTrack is NULL");
226  return true;
227  }
228  if((int)m_On > 1 || (int)m_ShowFrame > 1 || (int)m_Expanded > 1) {
229  LOG_POST(Error << sCodeLocation << ": Broken CLayoutTrack: " << (void*)this);
230  return false;
231  }
232  LOG_POST(Error << sCodeLocation << ": Valid CLayoutTrack: " << (void*)this <<
233  ", id: " << m_Id << ", title: " << m_Title << ", def-title: " << m_DefaultTitle << ", msg: " << m_Msg <<
234  ", m_On: " << (int)m_On << ", ShowFrame: " << (int)m_ShowFrame << ", Expanded: " << (int)m_Expanded <<
235  ", validating its parent: " << (void*)m_ParentTrack.GetPointer());
236  if(m_ParentTrack.NotNull())
237  m_ParentTrack->// x_Validate("Parent of " + sCodeLocation);
238  return true;
239 }
240 */
242 {
243  // x_Validate("isRmtBased");
244  const CLayoutTrack* pLayoutTrack(GetParentTrack());
245  const CTrackContainer* pContainer(dynamic_cast<const CTrackContainer*>(pLayoutTrack));
246  if(pContainer == NULL) {
247  return false;
248  }
249  const CTrackContainer::TTrackProxies& proxies(pContainer->GetSubtrackProxies());
250 
251  ITERATE(CTrackContainer::TTrackProxies, iter, proxies) {
252  if((*iter)->GetTrack() == this) {
253  CTempTrackProxy::TAnnots annots((*iter)->GetAnnots());
254  for(auto annot: annots) {
255  if(CSeqUtils::isRmtAnnotName(annot)) {
256  return true;
257  }
258  }
259  if (!(*iter)->GetRemotePath().empty())
260  return true;
261  }
262  }
263  return false;
264 }
265 
267 {
268  // x_Validate("isRemotePath");
269  const CTrackContainer* pContainer(dynamic_cast<const CTrackContainer*>(GetParentTrack()));
270  if(pContainer == nullptr)
271  return false;
272 
273  const CTrackContainer::TTrackProxies& proxies(pContainer->GetSubtrackProxies());
274 
275  for (const auto& proxy : proxies) {
276  if(proxy->GetTrack() != this)
277  continue;
278 
279  const auto &path = proxy->GetRemotePath();
280  if (path.empty()) {
281  return false;
282  }
283  CUrl url(path);
284  string host = url.GetHost();
285  NStr::ToLower(host);
286  if (host == "ftp.ncbi.nlm.nih.gov") {
287  return false;
288  }
289 
290  return true;
291  }
292  return false;
293 }
294 
296 {
297  // x_Validate("InitHTMLActiveArea");
298  TModelUnit tb_height = x_GetTBHeight();
299 
300  CHTMLActiveArea area;
302  area.m_Flags =
307  if (!(m_Attrs & fNavigable))
309  area.m_Bounds.SetBottom(area.m_Bounds.Top() +
310  (TVPUnit)tb_height + (tb_height > 0.0 ? 2 : 0));
312  if(!x_IsNCBITrack() && !m_Title.empty()) {
313  area.m_Descr = m_Title + (m_isBlast ? "" : " (Non-NCBI data)");
314  }
315  p_areas->push_back(area);
316  return &p_areas->back();
317 }
318 
319 
321 {
322  // do we have title bar at all
323  if (m_Attrs & fFrameVisible && m_ShowFrame) {
324  m_ShowFrame = false;
326  }
327 }
328 
329 
331 {
332  // x_Validate("OnMotion in");
333  TModelPoint p(pt);
334  x_World2Local(p);
335  int pre_highlighted = m_HighlightedIcon;
336  bool was_shown = m_ShowFrame;
337  m_ShowFrame = false;
339  if (m_Attrs & fFrameVisible && x_HitTitleBar(p)) {
341  m_ShowFrame = true;
342  }
343  // x_Validate("OnMotion out");
344  return m_HighlightedIcon != pre_highlighted ||
345  was_shown != m_ShowFrame;
346 }
347 
348 
349 bool CLayoutTrack::NeedTooltip(const TModelPoint& p, ITooltipFormatter& tt, string& t_title) const
350 {
351  // x_Validate("NeedTooltip");
352  GetTooltip(p, tt, t_title);
353  return !tt.IsEmpty();
354 }
355 
356 
357 void CLayoutTrack::GetTooltip(const TModelPoint& /*p*/, ITooltipFormatter& tt, string& /*t_title*/) const
358 {
360  tt.AddRow(m_Icons[m_HighlightedIcon].m_Tooltip);
361  }
362  // x_Validate("GetTooltip");
363 }
364 
365 
367 {
368  CLogPerformance perfLog("CLayoutTrack::x_Draw()");
369  perfLog << "Title: " << GetFullTitle();
370  // x_Validate("x_Draw in");
371  if (m_On && x_Visible_V()) {
372  IRender& gl = GetGl();
373 
374  gl.PushMatrix();
375  gl.Translatef(0.0f, GetTop(), 0.0f);
376  if (m_Expanded) {
377  bool skip_content = m_Context->IsSkipContent() && dynamic_cast<const ITrackContainer*>(this) == 0;
378  if (!skip_content)
379  x_RenderContent();
380  }
381  if (x_ShowTitle() && !m_Context->IsSkipTitleBar()) {
383  }
384  gl.PopMatrix();
385  }
386  perfLog.Post(CRequestStatus::e200_Ok);
387  // x_Validate("x_Draw out");
388 }
389 
390 
392 {
393  // x_Validate("x_UpdateBoundingBox in");
394  SetHeight(0.0);
395  SetWidth(0.0);
396  if (!m_On) {
397  return;
398  }
400 
401  if (m_Attrs & fFullTrack) {
402  const TModelRange& vr = m_Context->GetVisibleRange();
403  SetLeft(vr.GetFrom());
404  SetWidth(vr.GetLength() - 1.0);
405  }
406  // x_Validate("x_UpdateBoundingBox out");
407 }
408 
409 
410 void CLayoutTrack::x_Expand(bool expand)
411 {
412  // x_Validate("x_Expand in");
413  if (m_Attrs & fCollapsible) {
414  m_Expanded = expand;
415  if (m_Expanded) {
416  Update(false);
417  }
419  }
420  // x_Validate("x_Expand out");
421 }
422 
423 
425 {
426  // x_Validate("x_ShowTitle");
427 //cerr << "CLayoutTrack::x_ShowTitle(): " << ((x_GetGlobalConfig()->GetShowComments() ||
428  // x_GetGlobalConfig()->ReserveCmmtSpace()) &&
429  // m_Attrs & fShowTitle &&
430  // ( (m_Attrs & fShowAlways && !m_gConfig->AutoHideTrack()) ||
431  // !x_Empty())) << endl;
432 
433  return (x_GetGlobalConfig()->GetShowComments() ||
434  x_GetGlobalConfig()->ReserveCmmtSpace()) &&
435  m_Attrs & fShowTitle &&
437  !x_Empty());
438 }
439 
440 
442 {
443  // x_Validate("x_GetTBHeight in");
444  IRender& gl = GetGl();
445 
446  if (m_On && x_ShowTitle()) {
448  CRef<CGlTextureFont> com_font = conf->GetCommentFont();
449  return gl.TextHeight(com_font) +
451  }
452  // x_Validate("x_GetTBHeight out");
453  return 0.0;
454 }
455 
456 
458 {
459  // x_Validate("x_OnLayoutChanged in");
461  if (m_LTHost && x_GetGlobalConfig()->GetBackgroundLoading()) {
463  }
464  // x_Validate("x_OnLayoutChanged out");
465 }
466 
467 
468 void CLayoutTrack::x_LoadSettings(const string& /*preset_style*/,
469  const TKeyValuePairs& /*settings*/)
470 {
471  // x_Validate("x_LoadSettings");
472 }
473 
474 
475 void CLayoutTrack::x_SaveSettings(const string& /*preset_style*/)
476 {
477  // x_Validate("x_SaveSettings");
478 }
479 
480 
482 {
483  // x_Validate("x_GetTBRect in");
484  bool compact = m_gConfig->GetSizeLevel() == "Compact";
485 
488  rect.Init(GetLeft() + indent, h, GetRight(),
490  // x_Validate("x_GetTBRect out");
491 }
492 
493 
495 {
496  // x_Validate("x_RenderProgressBar in");
497  IRender& gl = GetGl();
498 
499  TModelRect rect;
500  x_GetTBRect(rect);
501  TModelUnit len = m_Progress * 0.01 * rect.Width() * 0.5;
502  TModelUnit off_x = rect.Left() + len;
504  rect.SetLeft(-len);
505  rect.SetRight(len);
506  rect.Offset(off_x, 0.0);
507  gl.Color4f(0.6f, 0.6f, 0.9f, 0.4f);
508  m_Context->DrawQuad(rect);
509  // x_Validate("x_RenderProgressBar out");
510 }
511 
512 
514 {
515  // x_Validate("x_RenderTitleBar in");
516  IRender& gl = GetGl();
517 
519 
520  // render track frame
521  TModelRect rcm;
522  x_GetTBRect(rcm);
523  if (m_Attrs & fFrameVisible) {
524  TModelUnit left = rcm.Left();
525  TModelUnit right = rcm.Right();
528  TModelRect rcm_adj(left, rcm.Bottom(), right, rcm.Top());
529  if (m_ShowFrame && !gl.IsPrinterFriendly()) {
530  CRgbaColor dark_c = CRgbaColor(0.1f, 0.15f, 0.5f, 0.8f);
531  CRgbaColor light_c = CRgbaColor(0.77f, 0.85f, 1.0f, 0.8f);
532 
533  // draw the box surrounding the track content if not empty
534  if ( !x_Empty() ) {
536  TModelRect content_rc(GetLeft() + offset,
537  GetHeight(), GetRight() - offset, rcm.Bottom());
538  gl.ColorC(dark_c);
539  m_Context->DrawRect(content_rc);
540  }
541  // draw the shaded title bar
542 
543  m_Context->DrawShadedQuad(rcm_adj, dark_c, light_c, false);
544 
545  // draw the icons on right side of the title bar
546  int icon_num = static_cast<int>(m_Icons.size());
547  for (int idx = 0; idx < icon_num; ++idx) {
549  }
550  } else if (config->GetShowCommentBg()) {
551 
552  if (gl.IsPrinterFriendly()) {
553  const CGlPane* pane = m_Context->GetGlPane();
554  _ASSERT(pane);
555  TVPRect viewport = pane->GetViewport();
556  gl.BeginClippingRect(viewport.Left(), viewport.Top(), viewport.Width(), viewport.Height());
557  }
558 
559  if (x_IsNCBITrack()) {
560  m_Context->DrawShadedQuad(rcm_adj, config->GetTitleBackground(), CRgbaColor(1.0f, 1.0f, 1.0f, 0.0));
561  }
562  else {
563  m_Context->DrawShadedQuad(rcm_adj, config->GetNonNCBITitleBackground(), CRgbaColor(1.0f, 1.0f, 1.0f, 0.0));
564  }
565 
566  if (gl.IsPrinterFriendly()) {
567  gl.EndClippingRect();
568  }
569  }
570  }
571 
572  // render title
573  if (config->GetShowComments()) {
574  CRef<CGlTextureFont> com_font = config->GetCommentFont();
575  TModelUnit fs = gl.TextHeight(com_font);
576 
577  TModelUnit xM = rcm.Left();
578  string title = "";
580  bool compact = m_gConfig->GetSizeLevel() == "Compact";
581  if (compact || m_IndentLevel < 2) {
582  title = m_Expanded ? " - " : " + ";
583  } else {
584  title = m_Expanded ? " -- " : " ++ ";
585  }
586  }
587  title += GetFullTitle();
588  if (m_gConfig->GetShowMessage()) {
589  title += m_Msg;
590  }
591  title += x_GetHistMsg();
592 
593  if (m_Progress > 0 && m_Progress < 100) {
594  title += ": " + NStr::Int8ToString(m_Progress) + "%";
596  }
597 
598  if (m_ShowFrame && !gl.IsPrinterFriendly()) {
599  gl.Color3f(1.0f, 1.0f, 1.0f);
600  } else {
601  gl.ColorC(config->GetFGCommentColor());
602  }
603 
604  TModelUnit repeat_dist = config->GetCommentRepeatDist();
605  TModelUnit title_len = gl.TextWidth(com_font, title.c_str()) + 20.0;
606  repeat_dist = max(repeat_dist, title_len);
607  repeat_dist = m_Context->ScreenToSeq(repeat_dist);
608  int repeat_num = 1;
609  if (config->GetRepeatComment()) {
610  repeat_num = (int)ceil(fabs(rcm.Width() / repeat_dist));
611  } else {
612  // truncate the title if it is too long
613  TModelUnit max_title_w = max(50.0, m_Context->SeqToScreen(fabs(rcm.Width())) - 100.0);
614  title = com_font->Truncate(title, max_title_w);
615  }
616 
617  TModelUnit yM = rcm.Top() + fs + 1.0;
618 
619  for (int i = 0; i < repeat_num; ++i) {
620  TModelUnit x = xM;
622  m_Context->TextOut(com_font, title.c_str(), x, yM, false, false);
623  xM += repeat_dist;
624  }
625  }
626  // x_Validate("x_RenderTitleBar out");
627 }
628 
629 
631  bool highlighted,
632  bool lite_version) const
633 {
634  // x_Validate("x_RenderIcon in");
635  IRender& gl = GetGl();
636 
637  int idx = x_GetIconIdxById(id);
638  TModelRect rc_btn = x_GetIconRect(idx);
639  double coord = m_gConfig->GetIconSize() / 16.0;
640  TModelRect rc_coord(0.0, 1.0, coord, 1.0 - coord);
641  if (highlighted) {
642  //gl.Color3f(0.4f, 0.4f, 0.9f);
643  //m_Context->DrawQuad(rc_btn);
645  gl.Begin(GL_LINES);
646  gl.Color3f(1.0f, 1.0f, 1.0f);
647  gl.Vertex2d(rc_btn.Left() - offset, rc_btn.Top());
648  gl.Vertex2d(rc_btn.Right() - offset, rc_btn.Top());
649  gl.Vertex2d(rc_btn.Left() - offset, rc_btn.Top());
650  gl.Vertex2d(rc_btn.Left() - offset, rc_btn.Bottom());
651  gl.Color3f(0.1f, 0.1f, 0.1f);
652  gl.Vertex2d(rc_btn.Left() - offset, rc_btn.Bottom());
653  gl.Vertex2d(rc_btn.Right() - offset, rc_btn.Bottom());
654  gl.Vertex2d(rc_btn.Right() - offset, rc_btn.Top());
655  gl.Vertex2d(rc_btn.Right() - offset, rc_btn.Bottom());
656  gl.End();
657  gl.Color4f(0.6f, 0.6f, 1.0f, 0.6f);
658  m_Context->DrawQuad(rc_btn);
659  }
660 
662  CIRef<I3DTexture> tex;
663  if (x_GetIconState(id) == 0) {
664  if (lite_version && !m_Icons[idx].m_Icon1_lite.empty()) {
665  tex = sm_IconMap[m_Icons[idx].m_Icon1_lite];
666  } else {
667  tex = sm_IconMap[m_Icons[idx].m_Icon1];
668  }
669  } else {
670  tex = sm_IconMap[m_Icons[idx].m_Icon2];
671  }
672 
673  if (tex) {
674  CGlAttrGuard AttrGuard(GL_LINE_BIT);
675  gl.Enable(GL_TEXTURE_2D);
676  tex->MakeCurrent();
677  m_Context->DrawTexture(rc_btn, rc_coord);
678  gl.Disable(GL_TEXTURE_2D);
679  }
680  // x_Validate("x_RenderIcon out");
681 }
682 
683 
685 {
686  // x_Validate("x_OnIconClicked in");
687  switch (id) {
688  case eIcon_Close:
689  CloseMe();
690  break;
691  case eIcon_Expand:
693  break;
694  default:
695  _ASSERT(false);
696  // derived class must hanve handled other cases.
697  break;
698  }
699  // x_Validate("x_OnIconClicked out");
700 }
701 
702 
704 {
705  // x_Validate("x_GetIconState");
706  if (id == eIcon_Expand && !m_Expanded) {
707  return 1;
708  }
709  return 0;
710 }
711 
712 
714 {
715  TIcons::iterator iter = m_Icons.begin();
716  while (iter != m_Icons.end() && iter->m_Id != icon.m_Id) {
717  ++iter;
718  }
719  if (iter == m_Icons.end()) {
720  m_Icons.push_back(icon);
721  }
722  // x_Validate("x_RegisterIcon");
723 }
724 
725 
727 {
728  TIcons::iterator iter = m_Icons.begin();
729  while (iter != m_Icons.end() && iter->m_Id != id) {
730  ++iter;
731  }
732  if (iter != m_Icons.end()) {
733  m_Icons.erase(iter);
734  }
735  // x_Validate("x_DeregisterIcon");
736 }
737 
738 
739 void CLayoutTrack::x_EnableIcon(TIconID id, bool enabled)
740 {
741  TIcons::iterator iter = m_Icons.begin();
742  while (iter != m_Icons.end() && iter->m_Id != id) {
743  ++iter;
744  }
745  if (iter != m_Icons.end()) {
746  iter->m_Enabled = enabled;
747  }
748  // x_Validate("x_EnableIcon");
749 }
750 
751 
752 void CLayoutTrack::x_ShowIcon(TIconID id, bool shown)
753 {
754  TIcons::iterator iter = m_Icons.begin();
755  while (iter != m_Icons.end() && iter->m_Id != id) {
756  ++iter;
757  }
758  if (iter != m_Icons.end()) {
759  iter->m_Shown = shown;
760  }
761  // x_Validate("x_ShowIcon");
762 }
763 
764 
766 {
767  // x_Validate("x_HitIconTest");
768  int icon_num = static_cast<int>(m_Icons.size());
769  for (int idx = 0; idx < icon_num; ++idx) {
770  if (PointInRect(p, x_GetIconRect(idx))) {
771  return idx;
772  }
773  }
774  return kInvalidIcon;
775 }
776 
777 
779 {
780  // x_Validate("x_HitTitleBar in");
781  // No need to check title if there is no title bar
782  // however, feature panel has icons bar
783  // and hit test is suppposed to detect that
784 
785  if (!x_ShowTitle() && !(m_Attrs & fShowIcons))
786  return false;
788  return false;
789  TModelRect rc;
790  x_GetTBRect(rc);
791  TModelUnit left = rc.Left();
792  TModelUnit right = rc.Right();
795  rc.SetLeft(left);
796  rc.SetRight(right);
797  // x_Validate("x_HitTitleBar out");
798  return PointInRect(p, rc);
799 }
800 
801 
803 {
804  // x_Validate("x_RenderFrame");
805 
806 }
807 
808 
810 {
811  // x_Validate("x_GetIconRect in");
812  TModelRect rcm;
813  x_GetTBRect(rcm);
814  rcm.SetTop(rcm.Top() - m_gConfig->GetCommentTopMargin());
815  int size_y = m_gConfig->GetIconSize() / 2;
816  TModelUnit size_x = m_Context->ScreenToSeq(size_y);
817  TModelPoint off_seq;
818  off_seq.m_Y = floor(rcm.CenterPoint().Y() + 0.5);
819  size_y = min<int>(size_y, rcm.Bottom() - off_seq.m_Y);
820  off_seq.m_X = rcm.Right() - (idx * 3.0 + 2.0) * size_x;
822  rcm.Init(-size_x, size_y, size_x, -size_y);
824  const CGlPane* pane = m_Context->GetGlPane();
825  TVPPoint off_screen = pane->Project(off_seq.X(), off_seq.Y());
826  off_seq = pane->UnProject(off_screen.X(), off_screen.Y());
827  rcm.Offset(off_seq.X(), off_seq.Y());
828  // x_Validate("x_GetIconRect out");
829  return rcm;
830 }
831 
832 
834 {
835  TIcons::const_iterator iter = m_Icons.begin();
836  int idx = 0;
837  while (iter != m_Icons.end() && iter->m_Id != id) {
838  ++iter;
839  ++idx;
840  }
841  // x_Validate("x_GetIconIdxById");
842  if (iter != m_Icons.end()) {
843  return idx;
844  }
845  return kInvalidIcon;
846 }
847 
848 
850 {
851  RegisterIconImage("track_close", "track_close.png");
852  RegisterIconImage("track_expand", "track_collapse.png");
853  RegisterIconImage("track_collapse", "track_expand.png");
854  RegisterIconImage("track_content", "track_content.png");
855  RegisterIconImage("track_layout", "track_layout.png");
856  RegisterIconImage("track_settings", "track_settings.png");
857  RegisterIconImage("track_help", "track_help.png");
858 
859  // lite versions
860  RegisterIconImage("track_content_lite", "track_content_lite.png");
861  RegisterIconImage("track_layout_lite", "track_layout_lite.png");
862  RegisterIconImage("track_settings_lite", "track_settings_lite.png");
863  RegisterIconImage("track_help_lite", "track_help_lite.png");
864 }
865 
866 
868  const string& img_file)
869 {
871  // make sure not identical keys
872  _ASSERT(sm_IconMap.count(key) == 0);
873  CIRef<I3DTexture> tex;
874  wxString path = CSysPath::ResolvePath(wxT("<res>"), wxString::FromAscii(img_file.c_str()));
875  try {
876  // we are creating CGlTexture instance here, but not actual
877  // OpenGL texture object. CGlTexture::Load() will take care
878  // of this later on inside OpenGL rendering context.
879  CNcbiIfstream istr(path.fn_str(), ios::in|ios::binary);
880  tex.Reset(CGlResMgr::Instance().CreateTexture(istr, img_file));
881  tex->SetFilterMag(GL_NEAREST);
882  tex->SetFilterMin(GL_NEAREST);
883  tex->SetWrapS(GL_CLAMP);
884  tex->SetWrapT(GL_CLAMP);
885  tex->SetTexEnv(GL_REPLACE);
886  } catch (CException&) {
887  tex.Reset(NULL);
888  LOG_POST(Error << "CLayoutTrack::s_RegisterIconImage: " <<
889  "cannot read image from file " << path.ToUTF8());
890  }
891  if (tex) {
892  sm_IconMap[key] = tex;
893  }
894 }
895 
896 
898 {
900 
901  bool need_reload = false;
902  ITERATE (TTexMap, iter, sm_IconMap) {
903  if ( !iter->second ) return false;
904 
905  if ( !iter->second->IsValid() ) {
906  need_reload = true;
907  break;
908  }
909  }
910  if (need_reload) {
912  iter->second->Load();
913  }
914  }
915 
916  return true;
917 }
918 
919 
921  const TAnnotMetaDataList& src_annots,
922  const vector<string>& target_annots,
923  const string& annot_type,
924  const string& track_type,
925  TAnnotNameTitleMap& out_annots)
926 {
927  if (target_annots.empty() && annot_type.empty() && track_type.empty()) {
928  return;
929  }
930 
931  string track_type_l = track_type;
932  NStr::ToLower(track_type_l);
933  if (target_annots.empty()) {
934  // search annots based on annot_type and/or track_type
935  ITERATE (TAnnotMetaDataList, iter, src_annots) {
936  if (nullptr == iter->second)
937  continue;
938  bool matched = !annot_type.empty();
939  if (matched &&
940  !NStr::EqualNocase(annot_type, iter->second->m_AnnotType)) {
941  matched = false;
942  }
943  if (matched && !track_type_l.empty() &&
944  iter->second->m_Subtypes.count(track_type_l) == 0) {
945  matched = false;
946  }
947 
948  if (matched) {// && (*iter)->m_Requested) {
950  iter->second->m_Name, iter->second->m_Title));
951  }
952  }
953  } else {
954  set<string> annots;
955  ITERATE (vector<string>, iter, target_annots) {
956  if (CSeqUtils::IsNAA(*iter)) {
957  annots.insert(*iter);
958  }
959  }
960  ITERATE (set<string>, iter, annots) {
961  TAnnotMetaDataList::const_iterator s_iter = src_annots.find(*iter);
962  if (s_iter == src_annots.end()) continue;
963 
964  if (!annot_type.empty() && !s_iter->second->m_AnnotType.empty() &&
965  !NStr::EqualNocase(annot_type, s_iter->second->m_AnnotType)) {
966  continue;
967  }
968  if (!track_type_l.empty() && !s_iter->second->m_Subtypes.empty() &&
969  s_iter->second->m_Subtypes.count(track_type_l) == 0) {
970  continue;
971  }
973  s_iter->second->m_Name, s_iter->second->m_Title));
974  }
975  }
976 }
977 
978 
979 static const string kFilterSeparator = ":FILTER:";
980 
981 string ILayoutTrackFactory::MergeAnnotAndFilter(const string& annot,
982  const string& filter)
983 {
984  if (filter.empty()) {
985  return annot;
986  }
987 
988  return annot + kFilterSeparator + filter;
989 }
990 
991 
993 {
994  size_t pos = source.find(kFilterSeparator);
995  if (pos != string::npos) {
996  return source.substr(0, pos);
997  }
998  return source;
999 }
1000 
1001 
1003 {
1004  size_t pos = source.find(kFilterSeparator);
1005  if (pos != string::npos) {
1006  return source.substr(pos + kFilterSeparator.length());
1007  }
1008  return kEmptyStr;
1009 }
1010 
1012 {
1013  vector<string> data_types{ "asn1", "snp", "vcf" };
1014  _ASSERT(data_type < data_types.size());
1015  return data_types[data_type];
1016 }
1017 
CFastMutex –.
Definition: ncbimtx.hpp:667
CGlAttrGuard - guard class for restoring OpenGL attributes.
Definition: glutils.hpp:130
class CGlPane
Definition: glpane.hpp:62
string m_Descr
description that can be used as label or tooltip
@ fNoNavigation
track title won't show navigation controls
@ fNoPin
tooltip is not pinnable
@ fNoHighlight
no highlighting on mouse over
@ fTrack
track title bar
@ fNoSelection
the object can't be selected
int m_Flags
area flags, will need to replace m_Type
TTrackErrorStatus m_TrackErrorStatus
File Description:
virtual void x_RenderProgressBar() const
Method for rendering the job loading or layout generating progress.
void SetTrackAttr(TTrackAttrFlags flags)
virtual int x_GetIconState(TIconID id) const
Get current status for a given button.
int m_IndentLevel
track hierachy indentation level.
void x_DeregisterIcon(TIconID id)
deregister an icon if already registered.
virtual void x_UpdateBoundingBox()
Update the bounding box assuming children's sizes are fixed if any.
virtual void GetTooltip(const TModelPoint &p, ITooltipFormatter &tt, string &t_title) const
Get the tooltip if available.
bool m_Expanded
is this track in expanded state
bool isRemotePath() const
virtual bool x_ShowTitle() const
Need to preserve title space and show the title.
int x_HitIconTest(const TModelPoint &p) const
hit any icon?.
virtual bool OnLeftDblClick(const TModelPoint &p)
@ eIcon_Expand
expand/collapse icon
@ eIcon_Close
close icon
virtual void x_RenderContent() const =0
The content rendering must be implemented in the derived layout tracks.
static bool InitIconTextures()
initialize OpenGL ttexture objects for icons.
virtual bool NeedTooltip(const TModelPoint &p, ITooltipFormatter &tt, string &t_title) const
Check if need to show tooltip.
ILayoutTrackHost * m_LTHost
Top level host owning the tracks.
virtual void x_Expand(bool expand)
Collapse or expand the track.
string m_Msg
special message need to show on title bar
string m_Title
track title
static CFastMutex sm_Mutex
mutex guarding the icon texture map
virtual void x_GetTBRect(TModelRect &rc) const
Get title bar rectange exclude top margin.
bool m_ShowFrame
need to draw frame, not title
virtual void x_SaveSettings(const string &preset_style)
save the track settings to a profile string.
virtual void x_LoadSettings(const string &preset_style, const TKeyValuePairs &settings)
load the track settings.
virtual bool OnLeftDown(const TModelPoint &p)
bool m_On
is this track shown
CLayoutTrack * GetParentTrack()
void x_EnableIcon(TIconID id, bool enabled)
Enable/disable an existing icon.
void CloseMe()
close this track.
void x_OnLayoutChanged()
update the layout.
TTrackAttrFlags m_Attrs
various track attributes
virtual void x_RenderIcon(TIconID id, bool highlighted, bool lite_version=false) const
Render track icons.
virtual string x_GetHistMsg() const
Histogram configuration (linear, log, etc) is also on the title bar but multiple track types can have...
virtual void x_OnIconClicked(TIconID id)
Mouse left-click event handler on an icon.
void SetShow(bool shown)
set the flag only.
TIcons m_Icons
registered icon info
virtual bool x_Empty() const =0
int GetOrder() const
void LoadProfile(const string &profile_str)
set track profile and load settings.
@ fNavigable
Track has navigation controls.
@ fFrameVisible
track frame will be rendered when triggered.
@ fShowAlways
always be rendered even for an empty track.
@ fFullTrack
track occupying the full horizontal screen.
@ fShowIcons
Track has control icons at the bottom.
@ fCollapsible
can be collpased and expanded.
string TIconAlias
the icon alias used as a key
const string & GetProfile() const
virtual void x_RenderTitleBar() const
Method for rendering the track title bar.
unsigned TTrackAttrFlags
bool x_HitTitleBar(const TModelPoint &p) const
hit the title bar?.
TModelUnit x_GetTBHeight() const
Get title bar height including margin.
TTrackErrorStatus m_ErrorStatus
int x_GetIconIdxById(TIconID id) const
get icon index in the registed icons using its id.
static void RegisterIconImage(const TIconAlias &key, const string &img_file)
register the image for an icon.
int m_HighlightedIcon
the highlighted icon index
CConstRef< CSeqGraphicConfig > x_GetGlobalConfig() const
Method for getting global configuration from rendering context.
void SetProfile(const string &preset_style)
CLayoutTrack inline method implmentation.
int m_Progress
any job progress index (0 - 100)
static TTexMap sm_IconMap
only intialized once app-wise
bool OnMotion(const TModelPoint &pt)
bool x_IsNCBITrack() const
Indicates whether the track is NCBI track.
CRef< CSeqGraphicConfig > m_gConfig
global configuration.
int TIconID
use int as TIconID instead of EIconID.
TModelRect x_GetIconRect(int idx) const
string m_Id
track identifier
CLayoutTrack(CRenderingContext *r_cntx)
bool m_isBlast
true if the track is known to be generated and uploaded by BLAST
virtual string GetFullTitle() const
get a more meaningful title.
virtual void x_Draw() const
The default renderer for this layout object.
void x_ShowIcon(TIconID id, bool shown)
Show/hide an existing icon.
virtual CHTMLActiveArea * InitHTMLActiveArea(TAreaVector *p_areas) const
Initialize the HTML active area for a track.
bool isRmtBased() const
static void RegisterCommonIconImages()
register images for the common icons.
virtual ~CLayoutTrack()
void x_RegisterIcon(const SIconInfo &icon)
register track icons.
void x_RenderFrame() const
Method for rendering the track frame including the icons.
void Post(CRequestStatus::ECode status=CRequestStatus::e200_Ok)
CRenderingContext offers the basic context and utility methods for rendering layout objects in featur...
void TextOut(const CGlTextureFont *font, const char *text, TModelUnit x, TModelUnit y, bool center, bool adjust_flip=true) const
CGlPane * GetGlPane()
inline method implementations
const TModelUnit & GetOffset() const
void DrawShadedQuad(const TModelRect &rcm, const CRgbaColor &c1, const CRgbaColor &c2, bool shade_vert=true) const
const TModelRange & GetVisibleRange() const
void DrawRect(const TModelRect &rc) const
void DrawQuad(const TModelRect &rc, bool border=false) const
bool IsSkipControls() const
TModelUnit SeqToScreen(const TModelUnit &size) const
convert from sequence positions to screen pixels
TModelUnit ScreenToSeq(const TModelUnit &size) const
convert from screen pixels to sequence positions
bool IsSkipContent() const
bool IsSkipTitleBar() const
void DrawTexture(const TModelRect &rc, const TModelRect &rc_coord) const
void AdjustToOrientation(TModelUnit &x) const
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
static void ParseProfileString(const string &profile_str, TKeyValuePairs &settings)
void x_InitHTMLActiveArea(CHTMLActiveArea &area) const
initialize the basic information for a given active area.
Definition: seq_glyph.cpp:380
CRenderingContext * m_Context
the rendering context
Definition: seq_glyph.hpp:346
virtual void x_OnLayoutChanged()
update the layout.
Definition: seq_glyph.cpp:353
virtual void SetHeight(TModelUnit h)
Definition: seq_glyph.hpp:650
virtual TModelUnit GetRight() const
Definition: seq_glyph.hpp:603
static bool PointInRect(const TModelPoint &p, const TModelRect &rc)
Definition: seq_glyph.hpp:694
virtual void SetWidth(TModelUnit w)
Definition: seq_glyph.hpp:646
virtual void SetLeft(TModelUnit l)
Definition: seq_glyph.hpp:654
virtual TModelUnit GetTop() const
Definition: seq_glyph.hpp:599
virtual TModelUnit GetHeight() const
Definition: seq_glyph.hpp:587
virtual void Update(bool)
Update content and layout including the bounding box.
Definition: seq_glyph.cpp:86
bool x_Visible_V() const
is this glyph visible in vertical direction?
Definition: seq_glyph.cpp:403
virtual TModelUnit GetLeft() const
Definition: seq_glyph.hpp:595
vector< CHTMLActiveArea > TAreaVector
Definition: seq_glyph.hpp:84
void x_World2Local(TModelPoint &p) const
Transform the coordiante from world coord. to local coord.
Definition: seq_glyph.hpp:722
void SetRenderingContext(CRenderingContext *context)
Set the rendering context.
Definition: seq_glyph.hpp:684
CRef< CGlTextureFont > GetCommentFont() const
const string & GetSizeLevel() const
bool AutoHideTrack() const
bool GetShowTrackMinusPlusSign() const
float GetCommentBottomMargin() const
bool GetShowMessage() const
float GetCommentTopMargin() const
static wxString ResolvePath(const wxString &path, const wxString &rel_name)
Utility function to hide the platform specifics of locating our standard directories and files.
Definition: sys_path.cpp:106
vector< string > TAnnots
CTrackContainer - a track container in the form of layout track.
const TTrackProxies & GetSubtrackProxies() const
CTrackContainer inline methods.
CTempTrackProxy::TTrackProxies TTrackProxies
CUrl –.
Definition: ncbi_url.hpp:353
static string DataTypeToString(EDataType data_type)
static string ExtractFilterName(const string &source)
extract filter name from a source string.
static string ExtractAnnotName(const string &source)
extract anntation name from a source string.
static string MergeAnnotAndFilter(const string &annot, const string &filter)
create a new name based on annotation name and fitler string.
static void GetMatchedAnnots(const TAnnotMetaDataList &src_annots, const vector< string > &target_annots, const string &annot_type, const string &track_type, TAnnotNameTitleMap &out_annots)
Help function to find matched annotations.
virtual void LTH_OnLayoutChanged()=0
provides mouse coords in OpenGL viewport coord system
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:55
ITrackContainer The interface for layout track that is also a container of tracks.
virtual void CloseTrack(int order)=0
Close a track.
void erase(iterator pos)
Definition: map.hpp:167
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator end() const
Definition: map.hpp:152
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
bool empty() const
Definition: map.hpp:149
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
URL parsing classes.
static uch flags
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
int offset
Definition: replacements.h:160
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
#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
static bool IsNAA(const string &annot, bool isStrict=false)
check if a given annotation is a named annotation accession[.version][number] when isSctrict == false...
Definition: utils.cpp:796
static bool isRmtAnnotName(const string &sAnnotname)
check if a given annotation was created by a remote file pipeline
Definition: utils.cpp:813
GLdouble TModelUnit
Definition: gltypes.hpp:48
void SetRight(T right)
Definition: glrect.hpp:114
static CGlResMgr & Instance()
Definition: glresmgr.cpp:59
T X() const
Definition: glpoint.hpp:59
T Height() const
Definition: glrect.hpp:90
virtual void Translatef(GLfloat x, GLfloat y, GLfloat z)=0
virtual void Enable(GLenum glstate)=0
void Init()
Definition: glrect.hpp:62
virtual void Begin(GLenum mode)=0
Start rendering.
void SetBottom(T bottom)
Definition: glrect.hpp:113
T Top() const
Definition: glrect.hpp:84
virtual void BeginClippingRect(GLint x, GLint y, GLsizei width, GLsizei height)=0
void Color3f(GLfloat r, GLfloat g, GLfloat b)
Definition: irender.hpp:95
T Bottom() const
Definition: glrect.hpp:82
TModelPoint UnProject(TVPUnit m_x, TVPUnit m_y) const
Definition: glpane.cpp:738
void Offset(T d_x, T d_y)
Definition: glrect.hpp:186
T Width() const
Definition: glrect.hpp:86
IRender & GetGl()
convenience function for getting current render manager
void Vertex2d(GLdouble x, GLdouble y)
Definition: irender.hpp:185
T Right() const
Definition: glrect.hpp:83
TVPRect & GetViewport(void)
Definition: glpane.hpp:332
virtual TModelUnit TextHeight(const CGlTextureFont *font) const =0
virtual TModelUnit TextWidth(const CGlTextureFont *font, const char *text) const =0
virtual void PopMatrix()=0
CGlPoint< T > CenterPoint() const
Definition: glrect.hpp:94
T Left() const
Definition: glrect.hpp:81
T Y() const
Definition: glpoint.hpp:60
virtual void EndClippingRect()=0
virtual bool IsPrinterFriendly() const =0
virtual void End()=0
Finish rendering (create buffer and send to renderer)
int TVPUnit
Definition: gltypes.hpp:47
void Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
Definition: irender.hpp:97
void SetLeft(T left)
Definition: glrect.hpp:112
virtual void Disable(GLenum glstate)=0
glDisable()
virtual void ColorC(const CRgbaColor &c)=0
Set current color (glColor{3,4}{f,d}{v,})
void SetTop(T top)
Definition: glrect.hpp:115
virtual void PushMatrix()=0
string Truncate(const char *text, TModelUnit w, ETruncate trunc=eTruncate_Ellipsis) const
Truncate text to the secified width.
TVPPoint Project(TModelUnit m_x, TModelUnit m_y) const
Definition: glpane.cpp:691
virtual void AddRow(const string &sContents="", unsigned colspan=2)=0
add a row with a cell, spanning across all columns
virtual bool IsEmpty() const =0
Indicates if the tooltip is empty.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
position_type GetLength(void) const
Definition: range.hpp:158
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
Definition: ncbistr.hpp:5159
#define kEmptyStr
Definition: ncbistr.hpp:123
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
static string & ToLower(string &str)
Convert string to lower case – string& version.
Definition: ncbistr.cpp:405
const string & GetHost(void) const
Definition: ncbi_url.hpp:411
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
static const string kFilterSeparator
static const int kIndent
static const int kInvalidIcon
in pixel
int i
int len
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::KEY key
const CharType(& source)[N]
Definition: pointer.h:1149
#define fabs(v)
Definition: ncbi_dispd.c:46
T max(T x_, T y_)
std::istream & in(std::istream &in_, double &x_)
string indent(" ")
A help struct for storing information about a icon.
TIconID m_Id
must be unique within the context
#define _ASSERT
Modified on Wed Apr 17 13:10:31 2024 by modify_doxy.py rev. 669887