NCBI C++ ToolKit
alnmulti_renderer.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef __GUI_WIDGETS_ALNMULTI___ALNMULTI_RENDERER__HPP
2 #define __GUI_WIDGETS_ALNMULTI___ALNMULTI_RENDERER__HPP
3 
4 /* $Id: alnmulti_renderer.hpp 45043 2020-05-14 15:23:30Z shkeda $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistl.hpp>
36 
37 
38 #include <gui/widgets/gl/ruler.hpp>
39 
41 
45 
46 //#include <gui/widgets/gl/graph_container.hpp>
48 
50 
51 
52 ////////////////////////////////////////////////////////////////////////////
53 /// IAlnMultiRendererContext - this interface represents context in which
54 /// CAlnMultiRenderer lives. It provides callbacks necessary for Renderer's
55 /// functioning.
56 
58 {
59 public:
62 
64  fShownElement_Header = 1,
65  fShownElement_Ruler = 2,
66  // Do not touch these enums, there are equivalents for them in row_display_style.hpp
67  // and in JavaScript client code
68  fShownElement_MasterRow = 4,
69  fShownElement_Alignment = 8,
70  fShownElement_Track = 16,
71  fShownElement_Main = 32, // as opposed to MasterRow, both on for legacy case
72  fShownElement_All = 0xffff
73  };
74 
75 
76 public:
78 
79  virtual const CGlPane& GetAlignPort() const = 0;
80  virtual TNumrow GetLinesCount() const = 0;
81  virtual bool IsRendererFocused() = 0;
82  virtual int GetFocusedItemIndex() const = 0;
83  virtual bool IsItemSelected(int index) const = 0;
84 
85  virtual IAlignRow* GetMasterRow() = 0;
86  virtual IAlignRow* GetConsensusRow() = 0;
87 
88  /// all Y coordinates are OpenGL Viewport coordinates (not widget coords)
89  /// "index" is a line index (not row in alignment)
90 
91  virtual IAlignRow* GetRowByLine(int index) = 0;
92  virtual int GetLineByRowNum(TNumrow row) const = 0;
93  virtual int GetLineByModelY(int y) const = 0;
94  virtual int GetLinePosY(int index) const = 0;
95  virtual int GetLineHeight(int index) const = 0;
96 
97  virtual bool SortByColumn(TColumnType type, bool ascending) = 0;
99 
100  virtual int GetShownElements() = 0;
101 };
102 
103 class ITooltipFormatter;
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// class CAlnMultiRenderer - renders multiple alignment represented by
107 /// IAlnMultiRendererContext (the Model).
108 ///
109 /// IAlnMultiRenderer renders a grid where rows corresponds to IAlignRow objects
110 /// and columns represent different types of information. Columns can be
111 /// configured using "Column management" API.
112 
114  : public IAlnMultiHeaderContext
115 {
116 public:
119  eHtmlArea_CheckBox
120  };
122  typedef vector<CHTMLActiveArea> TAreaVector;
123 
124 public:
125  /// Constructor, with column add, icons setup and resize
126  ///
127  CAlnMultiRenderer(const TVPRect& rc, bool add_columns = true);
128 
129  /// Empty object constructor -- for two-phase construction
130  /// call SetupColums() to finish the class construction process
132  virtual ~CAlnMultiRenderer();
133 
134  /// Adds default columns for the renderer, allows custom setup
135  /// (column icon override, etc)
136  ///
137  virtual void SetupColumns(const TVPRect& rc);
138 
139  void SetContext(IAlnMultiRendererContext* pContext);
140 
141  void SetBackColor(const CRgbaColor Color);
142  const CRgbaColor& GetBackColor() const;
143 
144  void SetMasterBackColor(const CRgbaColor Color);
145  const CRgbaColor& GetMasterBackColor() const;
146 
147  void SetFocused(bool b_set) { m_bFocused = b_set; }
148  void SetCgiMode(bool b_set) { m_bCgiMode = b_set; }
149 
150  virtual void Resize(const TVPRect& rc);
151  virtual TVPRect GetRect() const;
152 
153  virtual void Update(bool layout_only = false);
154  virtual void UpdateOnDataChanged();
155 
156  /// renders OpenGL graphics
157  virtual void Render();
158 
159  /// renders OpenGL graphics and generate CHTMLActiveArea objects
160  virtual void Render(TAreaVector& areas);
161 
162  virtual bool NeedTooltip(int vp_x, int vp_y);
163  virtual string GetTooltip(); // returns tooltip for previously tested position
164  // MSA method
165  virtual string GetAlignmentTooltip(int x, int y, IAlignRow* row, bool master);
166 
168 
169  CRuler& GetRuler();
170  CGlPane& GetRulerPane() { return m_RulerPane; }
171 
172  int GetRulerAreaHeight() const { return m_RulerRect.Height(); }
173  int GetMasterAreaHeight() const { return m_MasterRect.Height(); }
174  int GetListAreaHeight() const { return m_ListAreaRect.Height(); }
175  int GetHeaderAreaHeight() const { return m_HeaderRect.Height(); }
176  TVPRect GetMasterArea() const;
177 
178  int GetListTop() const;
179  int GetColumnIndexByType(TColumnType type) const;
180  TVPRect GetColumnRect(int i_col, bool include_header) const;
181  TVPRect GetColumnRectByType(TColumnType type, bool include_header) const;
182  TColumnType GetColumnTypeByIndex(int i_col) const;
183  TColumnType GetColumnTypeByX(int vp_x) const;
184 
185  /// return OpenGL viewport coordinate of the top pixel in the list area
186  int GetVPListTop() const;
187 
188  enum EHitResult {
193  eRows
194  };
195 
196  virtual int HitTest(int vp_x, int vp_y, int& col);
197 
198  void SetupPaneForColumn(CGlPane& pane, int i_col) const;
199  void AutoFitColumns(const CGlTextureFont& font, bool for_printer);
200 
201 
202  /// @name IAlnMultiHeaderContext implementation
203  /// @{
204  virtual int GetColumnsCount() const;
205  virtual const SColumn& GetColumn(int index) const;
206  virtual SColumn& GetColumn(int index);
207  virtual int GetColumnIndexByX(int x) const;
208  virtual int GetResizableColumnIndex() const;
209  /// @}
210 
211  /// @name Columns management
212  /// @{
213  /// Columns can be "fixed size" or "resizable". Fixed size columns are
214  /// rendered with specifed width. Remaining screen space is divided
215  /// between "resizable" columns proportionally to m_Share.
216 
217  int AddColumn();
218  int AddColumn(int width, const string& label, int data);
219  int InsertColumn(int pos, int width, const string& label, int data);
220  void SetResizableColumn(int index);
221 
222  void SetColumns(const vector<SColumn>& columns, int resizable_index);
223 
224  void SetColumnWidth(int index, int width);
225  void SetColumnPos(int index, int pos);
226  void SetColumnUserData(int index, int data);
227  void SetColumnVisible(int index, bool b_visible);
228  bool IsColumnVisible(int index) const;
229 
230  void SetColumnsByStyle(CWidgetDisplayStyle& style);
231  //void SetHiddenColumns(const vector<string>& labels);
232  void GetVisibleColumns(vector<string>& labels);
233 
234  void UpdateColumns(); // update positions
235  /// @}
236 
237 
238 
239 protected:
240  IAlnMultiRendererContext* x_GetContext() { return m_Context; }
241  const IAlnMultiRendererContext* x_GetContext() const { return m_Context; }
242 
243  void x_Layout();
244 
245  // Rendering functions
246  void x_Render(TAreaVector* p_areas);
247  void x_RenderHeader(TAreaVector* p_areas);
248  void x_RenderRuler(TAreaVector* p_areas);
249  void x_RenderItems(TAreaVector* p_areas);
250  void x_RenderItemsRange(int iFisrt, int iLast, TAreaVector* p_areas);
251  void x_RenderRow(IAlignRow* row, CGlPane& pane, int state, TVPUnit row_top, TAreaVector* areas);
252  void x_RenderMasterRow(TAreaVector* p_areas);
253  void x_PrepareMasterPane(CGlPane& pane);
254  void x_RenderAlignAreaTopLine();
255 
256  void x_ResetRowListMap();
257  void x_InvalidateRows(bool layout_only = false);
258  void x_PurgeRowListMap();
259 
260  int x_GetLineByWindowY(int WinY) const;
261  int x_GetLineByVPY(int vp_y) const;
262  TVPRect x_GetLineRect(int Index);
263 
265  {
266  return (IAlignRow::TColumnType) C.m_UserData;
267  }
268 
269  void x_LayoutColumns();
270 
271  string x_GetRowTooltip(const TVPPoint& pt, IAlignRow* p_row, int i_col, int vp_top_y);
272  void x_AddStatisticsRow(ITooltipFormatter &formatter, const string &tag, int part, int total);
273 
274 protected:
276  TVPRect m_rcBounds; // size of renderer in parents's coordinates
277 
280 
282 
285 
286  // Layout information
291 
293  typedef vector<SColumn> TColumnVector;
294 
295  TRowToList m_RowToList; // value == "true" if key has an OpenGL Display List
296  // columns
299 
300  bool m_bFocused; /// indicate whether it shoulde be rendered using "focused" color or not
301  bool m_bCgiMode = false; /// is it invoked by alnmulti.cgi
302 
305  //IAlignRow* m_TooltipRow;
308 
309 };
310 
311 
313 
314 #endif // __GUI_WIDGETS_ALNMULTI___ALNMULTI_RENDERER__HPP
CAlnMultiHeader.
class CAlnMultiRenderer - renders multiple alignment represented by IAlnMultiRendererContext (the Mod...
TVPPoint m_TooltipVPPos
is it invoked by alnmulti.cgi
const IAlnMultiRendererContext * x_GetContext() const
CAlnMultiHeader m_Header
TColumnType x_GetColumnType(const SColumn &C)
int GetHeaderAreaHeight() const
vector< SColumn > TColumnVector
IAlignRow::TColumnType TColumnType
CAlnMultiRenderer()
Empty object constructor – for two-phase construction call SetupColums() to finish the class construc...
IAlnMultiRendererContext * m_Context
IAlnMultiRendererContext * x_GetContext()
void SetFocused(bool b_set)
int GetMasterAreaHeight() const
CWeakIRef< IAlignRow > m_TooltipRow
int GetListAreaHeight() const
void SetCgiMode(bool b_set)
int GetRulerAreaHeight() const
vector< CHTMLActiveArea > TAreaVector
map< IAlignRow *, bool > TRowToList
class CGlPane
Definition: glpane.hpp:62
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
CRuler is a renderable object drawing a scale with position labels.
Definition: ruler.hpp:49
CWidgetDisplayStyle is a collection of display properties common for all rows in the CAlnMultiWidget.
Definition: svg.hpp:122
Interface IAlignRow - abstracts row rendering in Multiple Alignment Widget.
Definition: ialign_row.hpp:67
int TColumnType
Definition: ialign_row.hpp:70
IAlnMultiHeaderContext.
IAlnMultiRendererContext - this interface represents context in which CAlnMultiRenderer lives.
virtual IAlignRow * GetConsensusRow()=0
virtual int GetLineByRowNum(TNumrow row) const =0
virtual int GetShownElements()=0
virtual bool IsRendererFocused()=0
virtual bool IsItemSelected(int index) const =0
virtual const CGlPane & GetAlignPort() const =0
virtual bool SortByColumn(TColumnType type, bool ascending)=0
virtual int GetFocusedItemIndex() const =0
virtual IAlignRow * GetRowByLine(int index)=0
all Y coordinates are OpenGL Viewport coordinates (not widget coords) "index" is a line index (not ro...
virtual int GetLinePosY(int index) const =0
IAlnExplorer::TNumrow TNumrow
virtual int GetLineHeight(int index) const =0
virtual IAlnExplorer::ESortState GetColumnSortState(TColumnType type)=0
IAlignRow::TColumnType TColumnType
virtual IAlignRow * GetMasterRow()=0
virtual int GetLineByModelY(int y) const =0
virtual TNumrow GetLinesCount() const =0
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:55
#define C(s)
Definition: common.h:231
static const column_t columns[]
Definition: utf8_2.c:22
char data[12]
Definition: iconv.c:80
int TVPUnit
Definition: gltypes.hpp:47
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_ALNMULTIPLE_EXPORT
Definition: gui_export.h:520
static const char label[]
string GetHeader()
Definition: file_names.hpp:62
const char * tag
The NCBI C++/STL use hints.
#define row(bind, expected)
Definition: string_bind.c:73
SColumn describes a single column.
Definition: type.c:6
Modified on Sat May 18 11:41:45 2024 by modify_doxy.py rev. 669887