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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGET_SEQ_GRAPHICS___CLAYOUTGROUP__HPP
2 #define GUI_WIDGET_SEQ_GRAPHICS___CLAYOUTGROUP__HPP
3 
4 /* $Id: layout_group.hpp 44204 2019-11-14 20:16:52Z filippov $
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  */
32 
33 #include <corelib/ncbistr.hpp>
34 #include <gui/gui_export.h>
35 #include <gui/opengl/gltypes.hpp>
40 #include <gui/gui.hpp>
41 #include <gui/utils/rgba_color.hpp>
42 
44 
45 class CBoundaryParams;
46 
47 ///////////////////////////////////////////////////////////////////////////////
48 /// CLayoutGroup is a container of CSeqGlyphs (layout objects). Itself is
49 /// one type of many layout objects. It simply takes a set of layout objects,
50 /// and generates layout based on the given layout policy.
51 ///
52 
54 {
55 public:
57 
59  virtual ~CLayoutGroup(void) {}
60 
61  /// @name ICompostion interface implementation.
62  /// @{
63  /// Return the object list.
64  const TObjectList& GetChildren() const;
65  TObjectList& GetChildren();
66 
67  /// Get total number of children.
68  size_t GetChildrenNum() const;
69 
70  /// Get the layout object at index 'idx'.
71  CConstRef<CSeqGlyph> GetChild(int idx) const;
72 
73  /// Get the layout object at index 'idx'.
74  CRef<CSeqGlyph> GetChild(int idx);
75 
76  /// Get the child index.
77  /// @return -1 if there is no such object.
78  int GetIndex(const CSeqGlyph* obj) const;
79 
80  /// Remove a layout object.
81  bool Remove(CSeqGlyph* obj);
82 
83  /// Replace a child at index 'idx'.
84  bool Replace(CSeqGlyph* obj, int idx);
85 
86  /// Insert a layout object before the given index.
87  /// If index is out of bound, the object is added to the end.
88  void Insert(int at, CSeqGlyph* obj);
89 
90  /// Insert a layout object before the given layout object.
91  /// If no matched at_obj found, the object will be added to the end.
92  void Insert(const CSeqGlyph* at_obj, CSeqGlyph* obj);
93 
94  /// Insert a layout object after the given layout object.
95  /// If no matched at_obj found, the object will be added to the end.
96  void InsertAft(const CSeqGlyph* at_obj, CSeqGlyph* obj);
97 
98  /// Append a layout object to the end.
99  void PushBack(CSeqGlyph* obj);
100 
101  void PushFront(CSeqGlyph* obj);
102 
103  void Set(const TObjectList& objs);
104 
105  void Append(TObjectList& objs);
106 
107  TObjectList& SetChildren();
108 
109  void Clear();
110  /// @}
111 
112  /// @name CSeqGlyph interface implementation
113  /// @{
114  virtual void Update(bool layout_only);
115  virtual CRef<CSeqGlyph> HitTest(const TModelPoint& p);
116  virtual bool HitTestHor(TSeqPos x, const CObject *obj);
117  virtual bool Intersects(const TModelRect& rect, TConstObjects& objs) const;
118  virtual void GetHTMLActiveAreas(TAreaVector* p_areas) const;
119  virtual bool Accept(IGlyphVisitor* visitor);
120  /// @}
121 
122 
123 
124  /// Set composition boundary parameters.
125  /// The settings is not required. It will only be used when there is a
126  /// need to show the bounding box for this composition.
127  void SetConfig(const CBoundaryParams* conf);
128 
129  /// Set policy on how to deploy the layout of its children.
130  void SetLayoutPolicy(ILayoutPolicy* policy);
131 
132  /// update group's bounding box only.
133  void UpdateBoundingBox();
134 
135  /// update group's bounding box only, and its
136  /// parent layout.
137  void UpdateLayout();
138 
139  /// Return true if there are 0 or 1 children, or all children are features
140  /// of the same type (e.g. all introns)
141  bool AllChildrenSameType() const;
142 
143  /// master glyph has some special meaning (e.g. represents feature that is a parent of all other features
144  /// represented by glyphs of the layout)
145  /// there is no requirement for a layout to have a master object but if there is one then
146  /// it is supposed to be among children (calling SetAsMaster() does _not_ insert it to the child list)
147  void SetAsMaster(CRef<CSeqGlyph> master) { m_MasterGlyph = master; }
148  bool IsMaster(const CSeqGlyph* glyph) const { return m_MasterGlyph.GetPointerOrNull() == glyph; }
149  void HideMaster(bool hidden = true) { m_HideMaster = hidden; }
150  bool IsMasterHidden() const { return m_HideMaster; }
151 
152  // enable these methods to put a breakpoint into
153 // virtual void SetHeight(TModelUnit h) {
154 // CSeqGlyph::SetHeight(h);
155 // };
156 // virtual TModelUnit GetHeight() const {
157 // return CSeqGlyph::GetHeight();
158 // };
159 
160  /// set "RelatedGlyphSelected" in CLayoutGroup-based glyph hierarchies
161  /// everywhere in the hierarchy containing the given glyph
162  static void PropagateRelatedSelection(bool isSelected, CSeqGlyph* pGlyph, CSeqGlyph* pGlyphFrom = NULL);
163 
164  void SetLinkedFeat(ELinkedFeatDisplay LinkedFeat) { m_LinkedFeat = LinkedFeat; }
165  ELinkedFeatDisplay GetLinkedFeat() const { return m_LinkedFeat; }
166 
167 
168 protected:
169  /// @name CSeqGlyph virtual methods.
170  /// @{
171  virtual void x_Draw() const;
172  virtual void x_UpdateBoundingBox();
173  /// override x_DrawHighlight() to do nothing.
174  virtual void x_DrawHighlight() const {}
175  /// @}
176 
177  void x_DrawBoundary() const;
178 
179  /// determines whether the glyph should be drawn or not at all (currently children of unselected parents when m_LinkedFeat
180  /// is set to "Expandable")
181  bool x_isDrawn() const;
182  bool x_HasExpandedChildren() const;
183 private:
186  CConstRef<CBoundaryParams> m_Config; ///< boundary settings
189 
190  /// linkage mode for the track where this glyph is residing
192 };
193 
194 
195 ///////////////////////////////////////////////////////////////////////////////
196 /// IBoundaryParams
197 ///
198 class CBoundaryParams : public CObject
199 {
200 public:
204  , m_FgColor(0.0f, 0.0f, 0.0f, 0.0f)
205  , m_BgColor(1.0f, 1.0f, 1.0f, 1.0f)
206  , m_LineWidth(1.0)
207  , m_Padding(2)
208  {}
209 
210  CBoundaryParams(bool show_boundary, bool show_bg, const CRgbaColor& fg,
211  const CRgbaColor& bg, TModelUnit w, int padding = 2)
212  : m_ShowBoundary(show_boundary)
213  , m_ShowBackground(show_bg)
214  , m_FgColor(fg)
215  , m_BgColor(bg)
216  , m_LineWidth(w)
217  , m_Padding(padding)
218  {}
219 
220  /// @name accessors
221  /// @{
222  bool ShowBoundary() const { return m_ShowBoundary; }
223  bool ShowBackground() const { return m_ShowBackground; }
224  const CRgbaColor& GetBgColor() const { return m_BgColor; }
225  const CRgbaColor& GetFgColor() const { return m_FgColor; }
226  TModelUnit GetLineWidth() const { return m_LineWidth; }
227  int GetPadding() const {return m_Padding; }
228  /// @}
229 
230  /// @name mutators
231  /// @{
232  void SetShowBoundary(bool flag) { m_ShowBoundary = flag; }
233  void SetShowBackground(bool flag) { m_ShowBackground = flag; }
234  void SetBgColor(const CRgbaColor& flag) { m_BgColor = flag; }
235  void SetFgColor(const CRgbaColor& flag) { m_FgColor = flag; }
236  void SetLineWidth(TModelUnit flag) { m_LineWidth = flag; }
237  void SetPadding(int p) { m_Padding = p; }
238  /// @}
239 
240 private:
247 };
248 
249 ///////////////////////////////////////////////////////////////////////////////
250 /// CLayoutGroup inline methods
251 ///
252 inline
254 {
255  return m_Children;
256 }
257 inline
259 {
260  return m_Children;
261 }
262 
263 inline
265 {
266  return m_Children.size();
267 }
268 
269 inline
271 {
272  m_Config.Reset(conf);
273 }
274 
275 inline
277 {
278  m_Policy.Reset(policy);
279 }
280 
281 inline
283 {
284  m_Children.push_back(CRef<CSeqGlyph>(obj));
285  obj->SetParent(this);
287 }
288 
289 inline
291 {
292  m_Children.push_front(CRef<CSeqGlyph>(obj));
293  obj->SetParent(this);
295 }
296 
297 inline
299 {
300  m_Children = objs;
302  (*iter)->SetParent(this);
303  if (m_Context) (*iter)->SetRenderingContext(m_Context);
304  }
305 }
306 
307 inline
309 {
310  m_Children.insert(m_Children.end(), objs.begin(), objs.end());
311  NON_CONST_ITERATE(TObjectList, iter, objs) {
312  (*iter)->SetParent(this);
313  if (m_Context) (*iter)->SetRenderingContext(m_Context);
314  }
315 }
316 
317 inline
319 {
320  return m_Children;
321 }
322 
323 inline
325 {
326  m_Children.clear();
327 }
328 
329 inline
331 {
333 }
334 
335 inline
337 {
339 }
340 
342 
343 
344 #endif // GUI_WIDGET_SEQ_GRAPHICS___CLAYOUTGROUP__HPP
IBoundaryParams.
const CRgbaColor & GetBgColor() const
bool ShowBoundary() const
CRgbaColor m_FgColor
void SetLineWidth(TModelUnit flag)
int GetPadding() const
void SetFgColor(const CRgbaColor &flag)
CRgbaColor m_BgColor
TModelUnit m_LineWidth
void SetShowBackground(bool flag)
bool ShowBackground() const
void SetPadding(int p)
TModelUnit GetLineWidth() const
void SetBgColor(const CRgbaColor &flag)
const CRgbaColor & GetFgColor() const
CBoundaryParams(bool show_boundary, bool show_bg, const CRgbaColor &fg, const CRgbaColor &bg, TModelUnit w, int padding=2)
void SetShowBoundary(bool flag)
CConstRef –.
Definition: ncbiobj.hpp:1266
CLayoutGroup is a container of CSeqGlyphs (layout objects).
void UpdateBoundingBox()
update group's bounding box only.
TObjectList m_Children
void SetLayoutPolicy(ILayoutPolicy *policy)
Set policy on how to deploy the layout of its children.
ELinkedFeatDisplay m_LinkedFeat
linkage mode for the track where this glyph is residing
void HideMaster(bool hidden=true)
CRef< CSeqGlyph > m_MasterGlyph
void SetConfig(const CBoundaryParams *conf)
Set composition boundary parameters.
void PushBack(CSeqGlyph *obj)
Append a layout object to the end.
virtual ~CLayoutGroup(void)
void SetLinkedFeat(ELinkedFeatDisplay LinkedFeat)
TObjectList & SetChildren()
bool IsMasterHidden() const
virtual void x_UpdateBoundingBox()
Update the bounding box assuming children's sizes are fixed if any.
const TObjectList & GetChildren() const
CLayoutGroup inline methods.
void PushFront(CSeqGlyph *obj)
ELinkedFeatDisplay GetLinkedFeat() const
virtual void x_DrawHighlight() const
override x_DrawHighlight() to do nothing.
CConstRef< CBoundaryParams > m_Config
boundary settings
CIRef< ILayoutPolicy > m_Policy
void SetAsMaster(CRef< CSeqGlyph > master)
master glyph has some special meaning (e.g.
void Append(TObjectList &objs)
void Set(const TObjectList &objs)
size_t GetChildrenNum() const
Get total number of children.
void UpdateLayout()
update group's bounding box only, and its parent layout.
bool IsMaster(const CSeqGlyph *glyph) const
ILayoutPolicy::TObjectList TObjectList
CObject –.
Definition: ncbiobj.hpp:180
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
class CSeqGlyph defines an interface that wraps a rectilinear abstract object.
Definition: seq_glyph.hpp:82
CRenderingContext * m_Context
the rendering context
Definition: seq_glyph.hpp:346
virtual bool HitTestHor(TSeqPos x, const CObject *obj)
Definition: seq_glyph.cpp:115
virtual void x_OnLayoutChanged()
update the layout.
Definition: seq_glyph.cpp:353
virtual void x_Draw() const =0
The default renderer for this layout object.
void SetParent(CSeqGlyph *p)
Definition: seq_glyph.hpp:670
virtual CRef< CSeqGlyph > HitTest(const TModelPoint &p)
Hit testing.
Definition: seq_glyph.cpp:106
virtual void Update(bool)
Update content and layout including the bounding box.
Definition: seq_glyph.cpp:86
virtual bool Accept(IGlyphVisitor *visitor)
Interface for accepting an IGlyphVisitor.
Definition: seq_glyph.hpp:519
virtual bool Intersects(const TModelRect &rect, TConstObjects &objs) const
Intersect testing.
Definition: seq_glyph.cpp:120
virtual void GetHTMLActiveAreas(TAreaVector *) const
Get html active areas.
Definition: seq_glyph.hpp:148
virtual void x_UpdateBoundingBox()=0
Update the bounding box assuming children's sizes are fixed if any.
void SetRenderingContext(CRenderingContext *context)
Set the rendering context.
Definition: seq_glyph.hpp:684
Visitor interface for applying any potential actions or algorithms.
Definition: seq_glyph.hpp:384
class ILayoutPolicy defines the abstract interface required for generating layout based on a set of g...
list< CRef< CSeqGlyph > > TObjectList
The NCBI C++ standard methods for dealing with std::string.
ELinkedFeatDisplay
@ eLFD_Default
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
GLdouble TModelUnit
Definition: gltypes.hpp:48
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
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
#define NCBI_GUIWIDGETS_SEQGRAPHIC_EXPORT
Definition: gui_export.h:536
Defines to provide correct exporting from DLLs in Windows.
n padding
Modified on Fri Sep 20 14:58:18 2024 by modify_doxy.py rev. 669887