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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___FEATURE_TRACK__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___FEATURE_TRACK__HPP
3 
4 /* $Id: feature_track.hpp 46676 2021-08-27 22:14:42Z 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: Liangshou Wu
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <gui/utils/extension.hpp>
44 
47 
48 
50 
51 class CLinkedFeatsGroup;
52 class CHistogramGlyph;
53 
54 
55 class CFeatJobResult;
56 
57 ///////////////////////////////////////////////////////////////////////////////
58 /// CFeatureTrack --
59 ///
60 
62  public CDataTrack, public IAsn1Generator, public IFeatureTrackBase
63 {
64  friend class CFeatureTrackFactory;
65 
66 public:
67  enum ELayout {
68  eLayout_None, ///< unassigned layout
69  eLayout_Packed, ///< pack all feature into a histogram
70  eLayout_OneLine, ///< pack all feature into one line
71  eLayout_AdaptiveLayered, ///< adaptively switch between packed and layered
72  eLayout_AdaptiveInline, ///< adaptively switch between packed and inline
73  eLayout_ExpandedLayered, ///< show all features with layered layout
74  eLayout_ExpandedColumn, ///< show all features with column layout
75  eLayout_ExpandedByPos, ///< show all features, one per row sorted by pos
76  eLayout_ExpandedBySize, ///< one feature per row sorted by size
77  eLayout_Default = eLayout_AdaptiveLayered
78  };
79 
80  enum EAlignIconID {
81  eIcon_Score = eIcon_MaxTrackIconID + 1
82  };
83 
84  static ELayout LayoutStrToValue(const string& layout);
85  static const string& LayoutValueToStr(ELayout layout);
86 
87  static ELinkedFeatDisplay LinkedFeatDisplayStrToValue(const string& linked_feat);
88  static const string& LinkedFeatDisplayValueToStr(ELinkedFeatDisplay linked_feat);
89 
91  virtual ~CFeatureTrack();
92 
93  /// @name CLayoutTrack public methods.
94  /// @{
95  virtual const CTrackTypeInfo& GetTypeInfo() const;
96  virtual string GetFullTitle() const;
97  /// @}
98 
100  virtual CConstRef<CSGGenBankDS> GetDataSource() const;
101 
102  /// @name IAsn1Generator interface implementation
103  /// @{
104  void GenerateAsn1(objects::CSeq_entry& seq_entry, TSeqRange range);
105 
106  // if true, this track should be handled by stage 2
107  virtual bool BypassStage1() { return false; }
108 
109  // estimate number of features in the specified range
110  // returns true if range is acceptable for downloads
111  // if false, sMsg will contain a message that can be shown to the user
112  virtual bool CheckRange(TSeqRange range, string&, size_t&) { return true; }
113  /// @}
114 
115  void SetAnnot(const string& annot);
116  void ExcludeAnnotName(const string& annot);
117  void SetFeatSubtype(int subtype);
118  void SetLayout(ELayout layout);
119 
120  int GetFeatSubtype() const;
121  virtual void GetFeatSubtypes(set<objects::CSeqFeatData::ESubtype> &subtypes) const {subtypes.insert(static_cast<objects::CSeqFeatData::ESubtype>(m_Subtype));}
122  virtual string GetAnnot() const {return m_Annot;}
123 
124  // enable these methods to put a breakpoint into
125 // virtual void SetHeight(TModelUnit h) {
126 // CSeqGlyph::SetHeight(h);
127 // };
128 // virtual TModelUnit GetHeight() const {
129 // return CSeqGlyph::GetHeight();
130 // };
131 
132 protected:
133  /// @name CLayoutTrack virtual methods overloading.
134  /// @{
135  virtual void x_LoadSettings(const string& /*preset_style*/,
136  const TKeyValuePairs& settings);
137 
138  /// save part of settings to a profile string.
139  /// Only the potential settings changed by users will be saved.
140  virtual void x_SaveSettings(const string& /*preset_style*/);
141 
142  virtual void x_ParseSettings(const TKeyValuePairs& settings);
143 
144  virtual void x_OnIconClicked(TIconID id);
145  /// @}
146 
147  /// @name CDataTrack pure virtual interfaces
148  /// @{
149  virtual void x_UpdateData();
150  virtual void x_OnJobCompleted(CAppJobNotification& notify);
151  /// @}
152 
153  virtual void x_LoadFeatures(const TSeqRange& range, int feat_limit);
154 
155 private:
156  /// @name prohibited copy constructor and assignment operator.
157  /// @{
160  /// @}
161 
162 protected:
163 
164  void x_AddFeaturesLayout(const CSGJobResult& result);
165 
166  bool x_NeedHighlight(const CSeqGlyph::TObjects& objs) const;
167  bool x_NeedHighlight(const CSeqGlyph* glyph) const;
168 
169  /// rearrange the child features if necessary.
170  /// regrouping may mean removing child features,
171  /// removing parent feature or packing all child
172  /// features together.
173  void x_RegroupFeats(CSeqGlyph::TObjects& objs, ELinkedFeatDisplay link_mode);
174 
175  /// initialize all children.
176  /// return true if one of the children needs to be highlighted
177  bool x_InitGlyphs_Recursive(CSeqGlyph::TObjects& objs,
178  int curr_level, bool compact_mode);
179 
180  void x_ExtracGlyphs_Recursive(CSeqGlyph::TObjects& objs,
181  CLinkedFeatsGroup* feat_group);
182  void x_CountFeats_recursive(const CSeqGlyph::TObjects& objs,
183  int& count, bool is_overview);
184 
185  void x_OnContentIconClicked();
186  void x_OnLayoutIconClicked();
187  void x_InitLayoutPolicy(CLayoutGroup& group, ELinkedFeatDisplay link_mode);
188  virtual void x_OnLayoutPolicyChanged();
189 
190  void x_AdjustFeatureLayout();
191 
192  bool x_HasLinkedFeats() const;
193  void x_SortFeaturesByWeight(CSeqGlyph::TObjects& objs) const;
194 
195  void x_AddHistogram(CHistogramGlyph* hist, int layout = -1);
196 
197  string m_AnnotName;
198  string m_Annot;
199  string m_Subtitle;
201  objects::SAnnotSelector m_FeatSel;
203 
204  /// maximal number of features shown in on track.
205  /// -1 means no limitation
207  /// Feature number threshold between compact mode and non-compact mode.
208  /// Maximal number of features shown in the non-compact mode
210  /// Maximal number of feature rows in one feature track.
211  int m_MaxRow;
212  /// Maximal feature group pixel height in adaptive mode
213  int m_MaxAdaptiveHeight = 400;
214 
217 
218  /// An independent histogram threshold used by SViewer.
219  /// It differs from m_FeatLimits which tries to capture all
220  /// possible rendering layouts.
221  /// 0 means this value has no any effect.
231 };
232 
233 
234 ///////////////////////////////////////////////////////////////////////////////
235 ///
236 ///
237 ///
239 {
240 public:
242 };
243 
244 
245 ///////////////////////////////////////////////////////////////////////////////
246 /// CFeatureTrackFactory
247 ///
249  public CObject,
250  public ILayoutTrackFactory,
251  public ITrackConfigurable,
252  public IExtension
253 {
254 public:
256  m_DefaultLayout(CFeatureTrack::eLayout_AdaptiveLayered),
257  m_DefaultLinkedFeat(ELinkedFeatDisplay::eLFD_Packed) {}
258 
259  /// create a layout track based on the input objects and extra parameters.
260  virtual TTrackMap CreateTracks(
261  SConstScopedObject& object,
262  ISGDataSourceContext* ds_context,
263  CRenderingContext* r_cntx,
264  const SExtraParams& params = SExtraParams(),
265  const TAnnotMetaDataList& src_annots = TAnnotMetaDataList()) const;
266 
267  virtual void GetMatchedAnnots(
268  const TAnnotMetaDataList& src_annots,
269  const ILayoutTrackFactory::SExtraParams& params,
270  TAnnotNameTitleMap& out_annots) const;
271 
272  virtual void CloneTrack(const CLayoutTrack* track,
273  CTempTrackProxy* track_proxy) const;
274 
275  virtual bool UnderstandLevel() const
276  { return true; }
277 
278  // this track supports export to ASN1
279  // this means that it is able to accept a NULL as
280  // CRenderingContext in a call to CreateTracks()
281  // the track constructor is also able to accept a NULL as well
282  // and the track implements IAsn1Generator interface
283  virtual bool SupportsExportToAsn1() const { return true; }
284 
285  virtual bool NeedBackgroundInit() const
286  { return true; }
287 
288  virtual const CTrackTypeInfo& GetThisTypeInfo() const
289  { return GetTypeInfo(); }
290 
291  static const CTrackTypeInfo& GetTypeInfo()
292  { return CFeatureTrack::m_TypeInfo; }
293 
294  /// @name ITrackConfigurable interface implementation
295  /// @{
297  GetSettings(const string& profile,
298  const TKeyValuePairs& settings,
299  const CTempTrackProxy* track_proxy) const;
300  /// @}
301 
302  /// @name IExtension interface implementation
303  /// @{
304  virtual string GetExtensionIdentifier() const;
305  virtual string GetExtensionLabel() const;
306  /// @}
307 protected:
309  x_GetSettings(const TKeyValuePairs& settings, const CTempTrackProxy* track_proxy, bool is_intron_track) const;
312 };
313 
314 //
315 //class CFeatureTrackConfig : public CObject
316 //{
317 //public:
318 // CFeatureTrackConfig() {}
319 //
320 // void LoadSettings(CConstRef<CSeqGraphicConfig> g_conf,
321 // const string& reg_path);
322 // void SaveSettings(CConstRef<CSeqGraphicConfig> g_conf,
323 // const string& reg_path) const;
324 //};
325 
326 ///////////////////////////////////////////////////////////////////////////////
327 /// CFeatureTrack inline methods
328 ///
329 inline /*virtual*/
331 {
333 }
334 
335 inline /*virtual*/
337 {
339 }
340 
341 inline
343 {
344  m_Layout = layout;
345 }
346 
347 inline
349 {
350  return m_Subtype;
351 }
352 
353 inline
355 {
356  return m_HasLinkedFeats;
357 }
358 
359 
361 
362 #endif // GUI_WIDGETS_SEQ_GRAPHIC___FEATURE_TRACK__HPP
CAppJobNotification Notification send by CAppJobEventTranslator.
CConstRef –.
Definition: ncbiobj.hpp:1266
CDataTrack - a abstract base class for layout tracks which need to deal with background data retrieva...
Definition: data_track.hpp:55
virtual CRef< CSGGenBankDS > GetDataSource()=0
Method for accessing the data source.
virtual void x_UpdateData()=0
update track content.
virtual void x_OnJobCompleted(CAppJobNotification &notify)=0
CFeatureTrackFactory.
static const CTrackTypeInfo & GetTypeInfo()
virtual bool NeedBackgroundInit() const
Background track initialization.
CFeatureTrack::ELayout m_DefaultLayout
ELinkedFeatDisplay m_DefaultLinkedFeat
virtual const CTrackTypeInfo & GetThisTypeInfo() const
virtual bool UnderstandLevel() const
Have any concept of level.
virtual bool SupportsExportToAsn1() const
CFeatureTrack –.
virtual string GetAnnot() const
int m_FeatLimits
maximal number of features shown in on track.
int GetFeatSubtype() const
virtual void GetFeatSubtypes(set< objects::CSeqFeatData::ESubtype > &subtypes) const
CRef< CLayeredLayout > m_GroupLayered
virtual CRef< CSGGenBankDS > GetDataSource()
CFeatureTrack inline methods.
CRef< CColumnLayout > m_Column
CSeqGraphicConfig::TFeatSubtype m_Subtype
CRef< CSGFeatureDS > m_DS
objects::SAnnotSelector m_FeatSel
virtual bool CheckRange(TSeqRange range, string &, size_t &)
void SetLayout(ELayout layout)
CRef< CLayeredLayout > m_LinkedGroup
CRef< CCompactLayout > m_Compact
bool x_HasLinkedFeats() const
CRef< CSimpleLayout > m_GroupSimple
int m_MaxRow
Maximal number of feature rows in one feature track.
size_t m_HistThreshold
An independent histogram threshold used by SViewer.
CFeatureTrack(const CFeatureTrack &)
CFeatureTrack & operator=(const CFeatureTrack &)
CRef< CBoundaryParams > m_GroupConfig
static CTrackTypeInfo m_TypeInfo
@ eLayout_ExpandedColumn
show all features with column layout
@ eLayout_AdaptiveInline
adaptively switch between packed and inline
@ eLayout_Packed
pack all feature into a histogram
@ eLayout_ExpandedLayered
show all features with layered layout
@ eLayout_OneLine
pack all feature into one line
@ eLayout_AdaptiveLayered
adaptively switch between packed and layered
@ eLayout_ExpandedByPos
show all features, one per row sorted by pos
@ eLayout_None
unassigned layout
@ eLayout_ExpandedBySize
one feature per row sorted by size
ELinkedFeatDisplay m_LinkedFeat
virtual bool BypassStage1()
int m_CompactThreshold
Feature number threshold between compact mode and non-compact mode.
virtual const CTrackTypeInfo & GetTypeInfo() const
CJobResultBase – the basic job result class holding a token.
CLayoutGroup is a container of CSeqGlyphs (layout objects).
File Description:
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 void x_OnIconClicked(TIconID id)
Mouse left-click event handler on an icon.
virtual string GetFullTitle() const
get a more meaningful title.
CLinkedFeatsGroup is a container class contains related features.
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
CRenderingContext offers the basic context and utility methods for rendering layout objects in featur...
CSGFeatureDS.
Definition: feature_ds.hpp:49
CSGJobResult – the data structure holding the seqgraphic job results.
class CSeqGlyph defines an interface that wraps a rectilinear abstract object.
Definition: seq_glyph.hpp:82
list< CRef< CSeqGlyph > > TObjects
Definition: seq_glyph.hpp:85
int TFeatSubtype
we use int instead of CSeqFeatData::ESubtype for two reasons:
File Description:
CTrackTypeInfo - holds description of a layout track type.
IAsn1Generator interface for tracks capable of generating an ASN1 seq_entry for their data.
virtual void GenerateAsn1(objects::CSeq_entry &seq_entry, TSeqRange range)=0
IExtension IExtension interface represents an abstract pluggable component.
Definition: extension.hpp:57
IFeatureTrackBase –.
ILayoutTrackFactory.
ISGDSManager is seqgraphic data source manage that serves as an data source context.
ITrackConfigurable interface for tracks that are configurable.
map< string, string > TKeyValuePairs
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
ELinkedFeatDisplay
@ eLFD_Packed
objects::CSeqFeatData::ESubtype GetFeatSubtype(const string &feat_type)
Definition: macro_util.cpp:350
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#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_SEQGRAPHIC_EXPORT
Definition: gui_export.h:536
range(_Ty, _Ty) -> range< _Ty >
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
extra parameter for initializing a track.
else result
Definition: token2.c:20
Modified on Sat Apr 27 11:19:11 2024 by modify_doxy.py rev. 669887