59 std::sort(m_SelectedIDs.begin(), m_SelectedIDs.end());
60 m_SelectedIDs.erase(std::unique(m_SelectedIDs.begin(), m_SelectedIDs.end()),
66 if (sel_set->
HasField(
"selection-name") &&
82 if (sel_set->
HasField(
"cluster-id") &&
86 if (sel_set->
HasField(
"selection-ids") &&
90 m_SelectedIDs.clear();
91 for (
size_t i = 0;
i<node_ids.size(); ++
i) {
92 m_SelectedIDs.push_back(node_ids[
i]);
104 uo_id->
SetStr(
"selection-set");
107 uo_sel_set->
AddField(
"selection-name", GetName());
111 uo_sel_set->
AddField(
"selected", GetSelected());
112 uo_sel_set->
AddField(
"cluster-id", GetClusterID());
115 vector<int> selected;
116 for (
size_t j = 0; j<GetSelectionSet().size(); ++j)
117 selected.push_back(
int(GetSelectionSet()[j]));
119 uo_sel_set->
AddField(
"selection-ids", selected);
129 for (
size_t i = 0;
i < m_SelectionSets.size(); ++
i) {
140 if (uo.
HasField(
"selection-sets") &&
144 m_SelectionSets.resize(sel_sets.size());
145 for (
size_t i = 0;
i < sel_sets.size(); ++
i) {
146 m_SelectionSets[
i].InitFromUserObject(sel_sets[
i]);
149 x_SyncSelectionSets(tree_model);
151 SetSelectionSetProperty(tree_model);
157 if (uo.
HasField(
"selection-sets")) {
158 CUser_object::TData::iterator it = uo.
SetData().begin();
159 while (it != uo.
SetData().end()) {
160 if ((*it)->IsSetLabel() && (*it)->GetLabel().IsStr() &&
161 (*it)->GetLabel().GetStr() ==
"selection-sets") {
169 if (m_SelectionSets.size() > 0) {
172 vector< CRef<CUser_object> > uo_sets;
174 for (
size_t i = 0;
i < m_SelectionSets.size(); ++
i) {
177 uo_sets.push_back(uo_sel_set);
179 uo.
AddField(
"selection-sets", uo_sets);
185 for (
auto& sel_set : m_SelectionSets) {
186 sel_set.RemoveDuplicateIDs();
194 for (
size_t i = 0;
i<m_SelectionSets.size(); ++
i) {
195 if (m_SelectionSets[
i].GetSelected()) {
196 int id = m_SelectionSets[
i].GetClusterID();
197 cluster_id_to_selection_map[id] =
i;
201 return cluster_id_to_selection_map;
208 size_t num_nodes = tree_model->
GetSize();
216 for (
size_t i = 0;
i<num_nodes; ++
i) {
220 if (
n.GetValue().HasSelClusters())
221 n.GetValue().GetSelClusters().clear();
222 n.GetValue().GetBioTreeFeatureList().RemoveFeature(sel_feat_id);
225 string cid =
n.GetValue().GetBioTreeFeatureList().GetFeatureValue(cluster_id);
229 if (sel_id || errno == 0)
232 n.GetValue().SetClusterID(cluster_id);
233 n.GetValue().SetClusterColorIdx(-1);
237 if (
n.GetValue().HasNodeMarker())
238 n.GetValue().GetMarkerColors().clear();
239 const string& marker =
n.GetValue().GetBioTreeFeatureList().GetFeatureValue(marker_feat_id);
241 if (!marker.empty()) {
242 n.GetValue().SetMarkerColors(marker);
245 catch (std::exception&){}
251 for (
size_t i = 0;
i<m_SelectionSets.size(); ++
i) {
252 if (m_SelectionSets[
i].GetSelected()) {
253 int cluster_id = m_SelectionSets[
i].GetClusterID();
257 for (
size_t j = 0; j<m_SelectionSets[
i].GetSelectionSet().
size(); ++j) {
258 objects::CNode::TId node_id = m_SelectionSets[
i].GetSelectionSet()[j];
269 if (sel_clusters.length() > 0)
281 for (
size_t i = 0;
i < m_SelectionSets.size(); ++
i) {
282 if (m_SelectionSets[
i].GetName() == set_name) {
292 size_t set_idx = GetSelectionSet(set_name);
294 if (set_idx !=
size_t(-1))
295 return m_SelectionSets[set_idx];
297 vector<CRgbaColor> current_colors;
298 int max_cluster_id = 500;
299 for (
size_t i = 0;
i < m_SelectionSets.size(); ++
i) {
300 current_colors.push_back(m_SelectionSets[
i].
GetColor());
301 max_cluster_id =
std::max(m_SelectionSets[
i].GetClusterID(), max_cluster_id);
306 vector<objects::CNode::TId> ids;
311 m_SelectionSets.push_back(new_set);
312 return m_SelectionSets[m_SelectionSets.size() - 1];
317 size_t set_idx = GetSelectionSet(set_name);
319 if (set_idx !=
size_t(-1))
320 return m_SelectionSets[set_idx];
322 vector<objects::CNode::TId> ids;
326 m_SelectionSets.push_back(new_set);
327 return m_SelectionSets[m_SelectionSets.size() - 1];
335 float num_colors = (float)current_colors.size();
336 float color_step = num_colors ? (180.0f / num_colors) : 0;
337 float rotate_angle = color_step + 100.0f;
339 float max_color_dist = 0.0f;
344 for (
size_t i = 0;
i < 2 * current_colors.size(); ++
i) {
347 while (c_dist < 0.7f) {
352 float min_color_dist = 1e10f;
355 for (
size_t j = 0; j < current_colors.size(); ++j) {
357 if (dist < min_color_dist) {
358 min_color_dist = dist;
364 if (min_color_dist > max_color_dist) {
365 max_color_dist = min_color_dist;
383 for (
size_t i = 0;
i<m_SelectionSets.size(); ++
i) {
385 vector<objects::CNode::TId> selected = m_SelectionSets[
i].GetSelectionSet();
386 m_SelectionSets[
i].GetSelectionSet().clear();
388 for (
size_t j = 0; j<selected.size(); ++j) {
389 objects::CNode::TId node_id = selected[j];
393 m_SelectionSets[
i].GetSelectionSet().push_back(node_id);
398 vector<CPhyloSelectionSet> selection_sets = m_SelectionSets;
399 m_SelectionSets.clear();
401 for (
size_t i = 0;
i<selection_sets.size(); ++
i) {
402 if (selection_sets[
i].GetSelectionSet().
size() > 0) {
403 m_SelectionSets.push_back(selection_sets[
i]);
412 sel_set->SetClusterID(start_id--);
TSelClusterIDs & GetSelClusters()
CBioTreeFeatureList & GetBioTreeFeatureList()
void InitFromUserObject(CPhyloTree *tree_model, const objects::CBioTreeContainer_Base::TUser &uo)
CRgbaColor PickBestColor(const vector< CRgbaColor > ¤t_colors)
void SetSelectionSetProperty(CPhyloTree *tree_model)
void RenumberClusterIDs(int start_id)
Update all cluster ids using the starting-id as the lowest value.
void SaveToUserObject(objects::CBioTreeContainer_Base::TUser &uo)
size_t GetSelectionSet(const string &set_name)
Returns size_t(-1) if the name set_name is not an existing selection set.
map< int, size_t > GetClusterToSelectionMap()
CPhyloSelectionSet & AddSet(const string &set_name)
Add the new set set_name and return it. If it already exists, just return it.
void RemoveDuplicateIDs()
Remove duplicate IDs from individual sets.
void x_SyncSelectionSets(CPhyloTree *tree_model)
bool operator==(const CPhyloSelectionSetMgr &rhs) const
vector< CPhyloSelectionSet > m_SelectionSets
void SetColor(const CRgbaColor &c)
CRef< objects::CUser_object > SaveToUserObject() const
void SetClusterID(int cid)
CRgbaColor m_SelectionColor
void InitFromUserObject(CRef< objects::CUser_object > sel_set)
vector< objects::CNode::TId > m_SelectedIDs
bool operator==(const CPhyloSelectionSet &rhs) const
call RemoveDuplicateIDs first which sorts and removes dups
void RemoveDuplicateIDs()
remove duplicates form m_SelectedIDs. should be called before operator==
Tree subclass also has functions and data needed for rendering and selection.
TTreeIdx FindNodeById(TID id) const
Return index of the node with the given id or Null().
CBioTreeFeatureDictionary & GetFeatureDict()
Return feature dictionary.
class CRgbaColor provides a simple abstraction for managing colors.
TData & GetValue()
Return the value object for the node.
static TTreeIdx Null()
Return the index value that represents a NULL node.
size_t GetSize() const
Get the number of nodes currently in the array.
TNodeType & GetNode(TTreeIdx idx)
Return a reference to the node at the given index.
bool HasField(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Verify that a named field exists.
CUser_object & AddField(const string &label, const string &value, EParseField parse=eParse_String)
add a data field to the user object that holds a given value
const CUser_field & GetField(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Access a named field in this user object.
CRgbaColor & GetColor(CSeqFeatData::ESubtype subtype)
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
static CRgbaColor RotateColor(const CRgbaColor &c, float degrees)
Rotate the hue of the color by degrees.
static float ColorDistance(const CRgbaColor &c1, const CRgbaColor &c2)
returns the distance in the RGB color cube between the two colors, scaled to a range [0,...
void Reset(void)
Reset reference object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
@ fConvErr_NoThrow
Do not throw an exception on error.
unsigned int TBioTreeFeatureId
Feature Id.
void SetFeature(TBioTreeFeatureId id, const string &value)
Set feature value, feature if exists replaced, if not added.
TBioTreeFeatureId Register(const string &feature_name)
Register new feature, return its id.
const string & GetFeatureValue(TBioTreeFeatureId id) const
Get feature value by id.
const TStr & GetStr(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
TBool GetBool(void) const
Get the variant data.
bool IsInt(void) const
Check if variant Int is selected.
bool IsStr(void) const
Check if variant Str is selected.
TData & SetData(void)
Assign a value to Data data member.
TInt GetInt(void) const
Get the variant data.
TStr & SetStr(void)
Select the variant.
bool IsInts(void) const
Check if variant Ints is selected.
bool IsObjects(void) const
Check if variant Objects is selected.
TReal GetReal(void) const
Get the variant data.
void SetType(TType &value)
Assign a value to Type data member.
bool IsReal(void) const
Check if variant Real is selected.
bool IsBool(void) const
Check if variant Bool is selected.
const TInts & GetInts(void) const
Get the variant data.
const TObjects & GetObjects(void) const
Get the variant data.
constexpr auto sort(_Init &&init)
const struct ncbi::grid::netcache::search::fields::SIZE size