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

Go to the SVN repository for this file.

1 /* $Id: row_display_style.cpp 45367 2020-07-15 14:32:52Z shkeda $
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 #include <ncbi_pch.hpp>
32 #include <corelib/ncbistd.hpp>
33 
34 #include <util/static_map.hpp>
35 #include <gui/utils/rgba_color.hpp>
39 #include <math.h>
40 
42 
43 
45 : m_TextFont(CGlTextureFont::eFontFace_Helvetica, 12),
46  m_SeqFont(CGlTextureFont::eFontFace_Courier_Bold, 12),
47  m_ShowIdenticalBases(false),
48  m_ShowConsensus(false)
49 {
50  m_ColorMap[eText] = CRgbaColor(0.0f, 0.0f, 0.0f); // black
51  m_ColorMap[eBack] = CRgbaColor(1.0f, 1.0f, 1.0f); //
52  m_ColorMap[eSelectedText] = CRgbaColor(1.0f, 1.0f, 0.0f); // yellow
53  m_ColorMap[eSelectedBack] = CRgbaColor(0.75f, 0.75f, 0.75f); // gray
54  m_ColorMap[eFocusedBack] = CRgbaColor(0.0f, 0.0f, 0.5f); // dark blue
55  m_ColorMap[eFrame] = CRgbaColor(0.8f, 0.8f, 0.8f);
56  m_ColorMap[eAlignSegs] = CRgbaColor(0.8f, 0.8f, 0.8f); // light gray
57  m_ColorMap[eAlignSegsNoScores] = CRgbaColor(0.75f, 0.75f, 0.75f); // gray
58 
59  m_ColorMap[eSequence] = CRgbaColor(0.0f, 0.0f, 0.0f); // black
60 }
61 
62 // Option to Set an invalid font to start since opengl (pane) window may not
63 // yet be created and we need a valid opengl context.
65 : m_TextFont(force_font, 12),
66  m_SeqFont(force_font, 12),
67  m_ShowIdenticalBases(false),
68  m_ShowConsensus(false)
69 
70 {
71  m_ColorMap[eText] = CRgbaColor(0.0f, 0.0f, 0.0f); // black
72  m_ColorMap[eBack] = CRgbaColor(1.0f, 1.0f, 1.0f); //
73  m_ColorMap[eSelectedText] = CRgbaColor(1.0f, 1.0f, 0.0f); // yellow
74  m_ColorMap[eSelectedBack] = CRgbaColor(0.75f, 0.75f, 0.75f); // gray
75  m_ColorMap[eFocusedBack] = CRgbaColor(0.0f, 0.0f, 0.5f); // dark blue
76  m_ColorMap[eFrame] = CRgbaColor(0.8f, 0.8f, 0.8f);
77  m_ColorMap[eAlignSegs] = CRgbaColor(0.8f, 0.8f, 0.8f); // light gray
78  m_ColorMap[eAlignSegsNoScores] = CRgbaColor(0.75f, 0.75f, 0.75f); // gray
79 
80  m_ColorMap[eSequence] = CRgbaColor(0.0f, 0.0f, 0.0f); // black
81 }
82 
84 {
86  _ASSERT(it != m_ColorMap.end());
87  return it->second;
88 }
89 
90 
92 {
94 }
95 
96 
97 static const char* kDefDNAMethodTag = "Default DNA Scoring Method";
98 static const char* kDefProteinMethodTag = "Default Protein Scoring Method";
99 static const char* kDotImage = "dot_image";
100 
101 
103 {
104  m_ColorMap[type] = c;
105 }
106 
107 
108 void sReadFont(const CRegistryReadView& view, const string& key, CGlTextureFont& font)
109 {
110  static string s;
111  s = view.GetString(key, "");
112  if( ! s.empty()) {
114  unsigned int font_size = font.GetFontSize();
115 
116  // Reset font if it fails to read correctly. This was added after transition from
117  // CGlBitmap fonts to CGltexture fonts since the stored strings were incompatible
118  // and so fonts would not be created successfully from registry.
119  if (!font.FromString(s)) {
120  font.SetFontFace(face);
121  font.SetFontSize(font_size);
122  }
123  }
124 }
125 
126 // copied from gui/widgets/seq_graphic/config_utils.cpp
127 static void sGetFont(const CRegistryReadView& view,
128  const string& face_key,
129  const string& size_key,
130  CGlTextureFont& f)
131 {
133  view.GetString(face_key, "Helvetica"));
134  unsigned int font_size = (unsigned int)view.GetInt(size_key, 10);
135 
136  f.SetFontFace(font_face);
137  f.SetFontSize(font_size);
138 }
139 
140 static void sSetFont(CRegistryWriteView& view,
141  const string& face_key, const string& size_key,
142  const CGlTextureFont& f)
143 {
144  view.Set(face_key, CGlTextureFont::FaceToString(f.GetFontFace()));
145  view.Set(size_key, (int)f.GetFontSize());
146 }
147 
148 
150 {
151  static string s;
152  s = view.GetString(key, "");
153  if( ! s.empty()) {
154  m_ColorMap[type].FromString(s);
155  }
156 }
157 
158 static const char* kColNamesTag = "Column Names";
159 static const char* kColWidthsTag = "Column Tag";
160 static const char* kColVisibleTag = "Column Visible";
161 
163 {
166 // sReadFont(view, "Text Font", m_TextFont);
167  sGetFont(view, "TextFontFace", "TextFontSize", m_TextFont);
168 
171 // sReadFont(view, "Sequence Font", m_SeqFont);
172  sGetFont(view, "SeqFontFace", "SeqFontSize", m_SeqFont);
173 
174  m_ShowIdenticalBases = view.GetBool("Show Identical Bases", m_ShowIdenticalBases);
175  m_ShowConsensus = view.GetBool("Show Consensus", m_ShowConsensus);
176 
177  ReadColor(eText, view, "Text Color");
178  ReadColor(eBack, view, "Back Color");
179  ReadColor(eSelectedText, view, "Selected Text Color");
180  ReadColor(eSelectedBack, view, "Selected Back Color");
181  ReadColor(eFocusedBack, view, "Focused Back Color");
182  ReadColor(eFrame, view, "Frame Color");
183  ReadColor(eAlignSegs, view, "Align Segs Color");
184  ReadColor(eAlignSegsNoScores, view, "Align Segs No Scores Color");
185  ReadColor(eSequence, view, "Sequence Color");
186 
187  // loading column information;
188  vector<string> names;
189  vector<int> widths;
190  vector<int> visible;
191 
193  view.GetIntVec(kColWidthsTag, widths);
194  view.GetIntVec(kColVisibleTag, visible);
195 
196  m_Columns.clear();
197  if(names.size() == widths.size() && names.size() == visible.size()) {
198  size_t n = names.size();
199  m_Columns.resize(n);
200 
201  for( size_t i = 0; i < n; i++ ) {
202  SColumn& col = m_Columns[i];
203  col.m_Name = names[i];
204  // Set a minimal width to 10 pixels.
205  // The minimal width will also be enforced when users change
206  // the width, see row_display_style.cpp. We recover any
207  // zero-width settings saved before the minimal width is
208  // introduced.
209  col.m_Width = max(10, widths[i]);
210  col.m_Visible = visible[i] > 0;
211  }
212  }
213 
217 }
218 
219 
222 {
223 
224  sSetFont(view, "TextFontFace", "TextFontSize", m_TextFont);
225  sSetFont(view, "SeqFontFace", "SeqFontSize", m_SeqFont);
226 
227  view.Set("Show Identical Bases", m_ShowIdenticalBases);
228  view.Set("Show Consensus", m_ShowConsensus);
229 
230  view.Set("Text Color", m_ColorMap[eText].ToString());
231  view.Set("Back Color", m_ColorMap[eBack].ToString());
232  view.Set("Selected Text Color", m_ColorMap[eSelectedText].ToString());
233  view.Set("Selected Back Color", m_ColorMap[eSelectedBack].ToString());
234  view.Set("Focused Back Color", m_ColorMap[eFocusedBack].ToString());
235  view.Set("Frame Color", m_ColorMap[eFrame].ToString());
236  view.Set("Align Segs Color", m_ColorMap[eAlignSegs].ToString());
237  view.Set("Align Segs No Scores Color", m_ColorMap[eAlignSegsNoScores].ToString());
238  view.Set("Sequence Color", m_ColorMap[eSequence].ToString());
239 
240  // saving column information;
241  size_t n = m_Columns.size();
242  vector<string> names(n);
243  vector<int> widths(n);
244  vector<int> visible(n);
245 
246  for( size_t i = 0; i < n; i++ ) {
247  const SColumn& col = m_Columns[i];
248  names[i] = col.m_Name;
249  widths[i] = col.m_Width;
250  visible[i] = col.m_Visible ? 1 : 0;
251  }
252 
253  view.Set(kColNamesTag, names);
254  view.Set(kColWidthsTag, widths);
255  view.Set(kColVisibleTag, visible);
256 
257  // we should not overwrite setting that we do not really have
258  switch(type) {
259  case IAlnExplorer::fDNA:
261  break;
264  break;
265  default:
266  break;
267  }
268 }
269 
270 
271 ///////////////////////////////////////////////////////////////////////////////
272 /// CRowDisplayStyle
274 : m_WidgetStyle(NULL)
275 {
276 }
277 
278 
280 {
281 }
282 
283 
285 {
286  m_WidgetStyle = style;
287 }
288 
289 
291 {
292  return m_WidgetStyle->m_TextFont;
293 }
294 
295 
297 {
298  return m_WidgetStyle->m_SeqFont;
299 }
300 
302 {
304 }
305 
306 
308 {
309  return m_WidgetStyle->GetColor(type);
310 }
311 
313 {
314  if (m_gConfig == 0) {
318  m_gConfig->SetLabelPos("No label");
319  }
320  return m_gConfig;
321 }
322 
324 : m_WidgetStyle(NULL),
325  m_DefStyle(NULL)
326 {
327 }
328 
329 
331 {
332  delete m_DefStyle;
333 }
334 
335 
337 {
338  m_WidgetStyle = style;
339  if(m_DefStyle) {
341  }
342 }
343 
345 {
346  m_DefStyle = style;
347  if(m_DefStyle) {
349  }
350 }
351 
353 {
355  return (it == m_RowToStyle.end()) ? m_DefStyle : it->second;
356 }
357 
358 
360 {
362  if(it_t == m_TypeToStyle.end()) {
364  return (it == m_RowToStyle.end()) ? m_DefStyle : it->second;
365  } else {
366  return it_t->second;
367  }
368 }
369 
370 
372 {
373  _ASSERT(style);
375  m_RowToStyle[row] = style;
376 }
377 
378 
380 {
381  _ASSERT(style);
383  m_TypeToStyle[type] = style;
384 }
385 
386 
388 {
391 }
392 
393 
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
int GetInt(const string &key, int default_val=0) const
access a named key at this level, with no recursion
Definition: reg_view.cpp:230
bool GetBool(const string &key, bool default_val=false) const
Definition: reg_view.cpp:241
void GetIntVec(const string &key, vector< int > &val) const
Definition: reg_view.cpp:252
string GetString(const string &key, const string &default_val=kEmptyStr) const
Definition: reg_view.cpp:246
void GetStringVec(const string &key, vector< string > &val) const
Definition: reg_view.cpp:263
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
CRowDisplayStyle is a base class representing a display style for IAlignRow.
CRef< CSeqGraphicConfig > GetSeqGraphicConfig() const
virtual ~CRowDisplayStyle(void)
const CWidgetDisplayStyle * m_WidgetStyle
CRowDisplayStyle()
CRowDisplayStyle.
virtual const CRgbaColor & GetColor(TColorType type) const
CRef< CSeqGraphicConfig > m_gConfig
virtual bool GetShowIdenticalBases(void) const
virtual void SetWidgetStyle(const CWidgetDisplayStyle *style)
virtual const CGlTextureFont & GetTextFont(void) const
virtual const CGlTextureFont & GetSeqFont(void) const
void SetDefaultStyle(CRowDisplayStyle *style)
assumes ownership
TTypeToStyle m_TypeToStyle
overriden styles for rows
const CRowDisplayStyle * GetStyleForRow(TNumrow row) const
CRowDisplayStyle * m_DefStyle
void SetRowTypeStyle(int type, CRowDisplayStyle *style)
const CWidgetDisplayStyle * m_WidgetStyle
void SetRowStyle(TNumrow row, CRowDisplayStyle *style)
void SetWidgetStyle(const CWidgetDisplayStyle *style)
static bool IsBackgroundJob()
void SetLabelPos(const string &label_pos)
void SetBackgroundLoading(bool flag)
void LoadSettings()
update the cached settings.
CWidgetDisplayStyle is a collection of display properties common for all rows in the CAlnMultiWidget.
bool m_ShowIdenticalBases
sequence font
string m_DefProteinMethod
default scoring method for DNA alignments
void ReadColor(EColorType type, const CRegistryReadView &view, const string &key)
CGlTextureFont m_TextFont
void SaveSettings(CRegistryWriteView view, IAlnExplorer::EAlignType type)
void x_GetColor(EColorType type, const CRgbaColor &c)
void LoadSettings(const CRegistryReadView &view)
@ eAlignSegsNoScores
this color is used when scoring is enabled but
CGlTextureFont m_SeqFont
text font (description, positions etc.)
virtual const CRgbaColor & GetColor(EColorType type) const
string m_DotImage
default scoring method for protein alignments
virtual void SetColor(EColorType type, const CRgbaColor &color)
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const struct name_t names[]
#define false
Definition: bool.h:36
static int type
Definition: getdata.c:31
#define NULL
Definition: ncbistd.hpp:225
static string FaceToString(EFontFace face)
funtions below provide conversion of font parameters to strings and back.
void SetFontFace(EFontFace face, bool use_bitmap_overrides=true)
EFontFace GetFontFace() const
EFontFace
Set of pre-defined fonts for which we know we have valid font files.
void SetFontSize(unsigned int size)
Set/get font size in points.
static EFontFace FaceFromString(const string &str)
Selects a font face given a string or eFontFace_LastFont on failure.
unsigned int GetFontSize() const
bool FromString(const string &value)
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
n background color
int i
yy_size_t n
const struct ncbi::grid::netcache::search::fields::KEY key
T max(T x_, T y_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
static const char * kColVisibleTag
void sReadFont(const CRegistryReadView &view, const string &key, CGlTextureFont &font)
static const char * kColNamesTag
static void sGetFont(const CRegistryReadView &view, const string &face_key, const string &size_key, CGlTextureFont &f)
static void sSetFont(CRegistryWriteView &view, const string &face_key, const string &size_key, const CGlTextureFont &f)
static const char * kDefDNAMethodTag
static const char * kColWidthsTag
static const char * kDotImage
static const char * kDefProteinMethodTag
#define row(bind, expected)
Definition: string_bind.c:73
Definition: type.c:6
#define _ASSERT
string ToString(const wxRect &rc)
Definition: wx_utils.cpp:773
Modified on Mon May 20 05:06:14 2024 by modify_doxy.py rev. 669887