File: SpecRec.cpp

package info (click to toggle)
pymol 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 42,288 kB
  • sloc: cpp: 476,472; python: 76,538; ansic: 29,510; javascript: 6,792; sh: 47; makefile: 24
file content (64 lines) | stat: -rw-r--r-- 1,364 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * (c) Schrodinger, Inc.
 */

#include "SpecRec.h"

#include <cstring>

/**
 * If name is "<group_name>.<base_name>" then return <base_name>, otherwise
 * just return name.
 */
const char* SpecRec::baseName() const
{
  if (auto const pos = std::strlen(group_name)) {
    if (std::strncmp(name, group_name, pos) == 0 && name[pos] == '.') {
      return name + pos + 1;
    }
  }

  return name;
}

/**
 * True if this record is a direct or indirect child of `other`.
 *
 * @pre ExecutiveUpdateGroups()
 */
bool SpecRec::isChildOf(SpecRec const* other) const
{
  return group == other || (group && group->isChildOf(other));
}

/**
 * True if this record is hidden from the object-menu-panel.
 *
 * @param hide_underscore_names Whether names that start with an underscore
 * should be hidden
 *
 * @pre ExecutiveUpdateGroups()
 */
bool SpecRec::isHidden(bool hide_underscore_names) const
{
  if (hide_underscore_names) {
    for (auto rec = this; rec; rec = rec->group) {
      if (rec->baseName()[0] == '_')
        return true;
    }
  }

  return false;
}

/**
 * Like isHidden() but assume that the parent group is not hidden.
 *
 * @pre Parent group is not hidden
 */
bool SpecRec::isHiddenNotRecursive(bool hide_underscore_names) const
{
  assert(!group || !group->isHidden(hide_underscore_names));

  return hide_underscore_names && baseName()[0] == '_';
}