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

Go to the SVN repository for this file.

1 #ifndef GUI_UTILS___LABEL__HPP
2 #define GUI_UTILS___LABEL__HPP
3 
4 /* $Id: label.hpp 36346 2016-09-15 17:56:22Z evgeniev $
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: Mike DiCuccio
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <serial/serialdef.hpp>
37 #include <objmgr/scope.hpp>
38 //#include <objects/seqfeat/Seq_feat.hpp>
39 #include <gui/gui.hpp>
40 
41 /** @addtogroup GUI_UTILS
42  *
43  * @{
44  */
45 
46 
48 
49 
50 class ILabelHandler;
51 
53 class CProjectItem;
55 
56 
58 {
59 public:
60  enum ELabelType {
61  eInvalid = -1,
70  eGi,
72 
74  };
75 
76  // retrieve a label for an object
77  static void GetLabel(
78  const CObject& obj,
79  string* label,
81  );
82 
83  static void GetLabel(
84  const CObject& obj,
85  string* label,
87  objects::CScope* scope
88  );
89 
90  // register handler classes that will be called when this interface
91  // is presented with an object for which a label is requested
92  static void RegisterLabelHandler(const string& type,
94  static void RegisterLabelHandler(const CTypeInfo& type,
96 
97  // Query to see whether a handler exists for a specific type
98  static bool HasHandler(const CTypeInfo& type);
99  static bool HasHandler(const string& type);
100 
101  static void RegisterTypeIcon(const string& user_type,
102  const string& user_subtype,
103  const string& icon_alias);
104  static string GetTypeIconAlias(const string& user_type,
105  const string& user_subtype);
106  static string GetTypeIconAlias(const string& user_type);
107 
108  static void GetIconAlias(const CObject& obj, string* alias,
109  objects::CScope* scope = NULL);
110 
111  /// truncate the label to some specific length with a desired leven of precision
112  /// algorithm tries to analyse the string, find punctuation and truncate on that
113  ///
114  /// @param label - string to truncate
115  /// @param length_limit - desired target length
116  /// @param length_tolerance - tolerance of error in number of characters, 0- no tolerance.
117  ///
118  static void TruncateLabel(string* label,
119  unsigned length_limit,
120  unsigned length_tolerance);
121 
122  static void SetLabelByData(objects::CProjectItem& item, objects::CScope* scope = NULL);
123 
124 private:
127 
130 };
131 
132 
133 ///////////////////////////////////////////////////////////////////////////////
134 /// ILabelHandler interface
135 class ILabelHandler: public CObject
136 {
137 public:
138  virtual void GetLabel(const CObject& obj, string* str,
140  objects::CScope* scope) const = 0;
141 };
142 
143 
144 /// Class to control runtime cache for description labels
145 /// label generation can be slow if we need to retrieve molecules, this
146 /// class controls session only runtime cache for the labels
147 ///
149 {
150 public:
151  /// Initialize cache instance (call once at gBench start)
152  static void InitCache();
153 
154  /// Stop cache instance (call once at gBench stop)
155  static void StopCache();
156 
157  /// Generate and cache description label for the specified gi
158  ///
159  static void CacheSeqId(const objects::CSeq_id& id, objects::CScope* scope);
160 
161  static void AddCaches(const map<TGi, string>& caches);
162 };
163 
164 
166 
167 
168 /* @} */
169 
170 #endif // GUI_UTILS___LABEL__HPP
Class to control runtime cache for description labels label generation can be slow if we need to retr...
Definition: label.hpp:149
Definition: label.hpp:58
CObject –.
Definition: ncbiobj.hpp:180
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
ILabelHandler interface.
Definition: label.hpp:136
Definition: map.hpp:338
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
static const char * str(char *buf, int n)
Definition: stats.c:84
@ eDefault
Definition: ncbi_types.h:112
#define NULL
Definition: ncbistd.hpp:225
map< string, string > TAliasMap
Definition: label.hpp:126
static void GetLabel(const CObject &obj, string *label, ELabelType type, objects::CScope *scope)
map< string, CRef< ILabelHandler > > TLabelMap
Definition: label.hpp:125
virtual void GetLabel(const CObject &obj, string *str, CLabel::ELabelType type, objects::CScope *scope) const =0
static TLabelMap sm_LabelMap
Definition: label.hpp:128
ELabelType
Definition: label.hpp:60
static TAliasMap sm_AliasMap
Definition: label.hpp:129
@ eContentAndProduct
Definition: label.hpp:71
@ eType
Definition: label.hpp:65
@ eUserSubtype
Definition: label.hpp:64
@ eUserTypeAndContent
Definition: label.hpp:66
@ eContent
Definition: label.hpp:62
@ eGi
Definition: label.hpp:70
@ eDescription
Definition: label.hpp:68
@ eUserType
Definition: label.hpp:63
@ eSymbolAlias
Definition: label.hpp:69
@ eDescriptionBrief
Definition: label.hpp:67
string GetLabel(const CSeq_id &id)
ELabelType
For compatibility with legacy code.
Definition: feature.hpp:85
@ eContent
Definition: feature.hpp:87
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_GUIOBJUTILS_EXPORT
Definition: gui_export.h:512
static const char label[]
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Definition: type.c:6
Modified on Fri Sep 20 14:58:09 2024 by modify_doxy.py rev. 669887