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

Go to the SVN repository for this file.

1 /* $Id: layout_policy.cpp 40918 2018-04-30 18:19:04Z 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: Liangshou Wu
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbiutil.hpp>
36 
38 
39 
40 ///////////////////////////////////////////////////////////////////////////////
41 /// CLayoutPolicy
42 ///////////////////////////////////////////////////////////////////////////////
43 
45  TLayout& layout,
47  size_t group_size, int vert_space) const
48 {
49 
50  _ASSERT(group_size > 0);
51  // create sub-groups
52  typedef vector<TLayoutRow*> TLayoutRows;
53  typedef vector<TLayoutRows> TLayouts;
54  CLayoutGroup::TObjectList& objs(orig_group.GetChildren());
55 
56  TLayouts layouts;
57  TLayoutRows layout_rows;
58  layout_rows.reserve(group_size);
59  size_t curr_row = 0;
60  NON_CONST_ITERATE (TLayout, iter, layout) {
61  if (curr_row >= group_size) {
62  layouts.push_back(layout_rows);
63  layout_rows.clear();
64  curr_row = 0;
65  } else {
66  ++curr_row;
67  }
68  layout_rows.push_back(&*iter);
69  }
70 
71  if (!layout_rows.empty()) {
72  layouts.push_back(layout_rows);
73  }
74 
75  if (layouts.size() == 1) {
76  x_SetObjectPos(layout, bound);
77  return;
78  }
79 
80  objs.clear();
81 
82  CRef<CBoundaryParams> params(
83  new CBoundaryParams(false, false, CRgbaColor(0.3f, 0.3f, 1.0f),
84  CRgbaColor(0.5f, 0.5f, 1.0f, 0.4f), 2.0, 0));
85  // showing the group boundary for debuging
86  // params->SetShowBoundary(true);
87 
88  NON_CONST_ITERATE (TLayouts, iter, layouts) {
89  CLayoutGroup* group = new CLayoutGroup(orig_group.GetLinkedFeat());
90  if(orig_group.GetLevel() != -1) {
91  group->SetLevel(orig_group.GetLevel()+1);
92  }
93  objs.push_back(CRef<CSeqGlyph>(group));
94  group->SetLayoutPolicy(const_cast<ILayoutPolicy*>(this));
95 
96  TModelUnit height = 0.0;
97  TModelUnit max_h = 0.0;
98  TModelUnit left = DBL_MAX;
99  TModelUnit right = 0.0;
100  for (auto& row : *iter) {
101  height += vert_space;
102  for (auto& obj : *row) {
103  group->PushBack(obj);
104  obj->SetTop(height);
105  max_h = max(max_h, obj->GetHeight());
106  left = min(left, obj->GetLeft());
107  right = max(right, obj->GetRight());
108  }
109  height += max_h;
110  max_h = 0.0;
111  }
112  group->SetHeight(height);
113  group->SetLeft(left);
114  group->SetWidth(right - left);
115  group->SetConfig(params);
116  }
117 }
118 
119 
IBoundaryParams.
CLayoutGroup is a container of CSeqGlyphs (layout objects).
void SetLayoutPolicy(ILayoutPolicy *policy)
Set policy on how to deploy the layout of its children.
void SetConfig(const CBoundaryParams *conf)
Set composition boundary parameters.
void PushBack(CSeqGlyph *obj)
Append a layout object to the end.
const TObjectList & GetChildren() const
CLayoutGroup inline methods.
ELinkedFeatDisplay GetLinkedFeat() const
ILayoutPolicy::TObjectList TObjectList
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
virtual void SetHeight(TModelUnit h)
Definition: seq_glyph.hpp:650
int GetLevel() const
Definition: seq_glyph.hpp:286
virtual void SetWidth(TModelUnit w)
Definition: seq_glyph.hpp:646
virtual void SetLeft(TModelUnit l)
Definition: seq_glyph.hpp:654
void SetLevel(int Level)
Definition: seq_glyph.hpp:287
class ILayoutPolicy defines the abstract interface required for generating layout based on a set of g...
virtual void x_SetObjectPos(TLayout &layout, SBoundingBox &bound) const
Set the objects' position (Y), and update the bounding box of the group (of all objects).
vector< TLayoutRow > TLayout
void x_SeparateObjects(CLayoutGroup &group, TLayout &layout, SBoundingBox &bound, size_t group_size, int vert_space) const
Separate objects into multiple sub-groups.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
GLdouble TModelUnit
Definition: gltypes.hpp:48
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
Useful/utility classes and methods.
T max(T x_, T y_)
T bound(T x_, T xlo_, T xhi_)
T min(T x_, T y_)
#define _ASSERT
Modified on Wed Feb 28 07:13:25 2024 by modify_doxy.py rev. 669887