-
Notifications
You must be signed in to change notification settings - Fork 233
Expand file tree
/
Copy pathquantity.cpp
More file actions
86 lines (57 loc) · 2.02 KB
/
quantity.cpp
File metadata and controls
86 lines (57 loc) · 2.02 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
#include "polyscope/quantity.h"
#include "imgui.h"
#include "polyscope/messages.h"
#include "polyscope/polyscope.h"
#include "polyscope/structure.h"
namespace polyscope {
// === General Quantities
// (subclasses could be a structure-specific quantity or a floating quantity)
Quantity::Quantity(std::string name_, Structure& parentStructure_, bool dominates_)
: parent(parentStructure_), name(name_), enabled(uniquePrefix() + "enabled", false), dominates(dominates_) {
validateName(name);
// Hack: if the quantity pulls enabled=true from the cache, need to make sure the logic from setEnabled(true) happens,
// so toggle it real quick
if (isEnabled()) {
setEnabled(false);
setEnabled(true);
}
}
Quantity::~Quantity() {};
void Quantity::draw() {}
void Quantity::drawDelayed() {}
void Quantity::drawPick() {}
void Quantity::drawPickDelayed() {}
void Quantity::buildUI() {
// NOTE: duplicated here and in the FloatingQuantity version
if (ImGui::TreeNode(niceName().c_str())) {
// Enabled checkbox
bool enabledLocal = enabled.get();
if (ImGui::Checkbox("Enabled", &enabledLocal)) {
setEnabled(enabledLocal);
}
// Call custom UI
this->buildCustomUI();
ImGui::TreePop();
}
}
void Quantity::buildCustomUI() {}
void Quantity::buildPickUI(size_t localPickInd) {}
bool Quantity::isEnabled() { return enabled.get(); }
void Quantity::setEnabled(bool newEnabled) {
if (newEnabled == enabled.get()) return;
enabled = newEnabled;
// Dominating quantities need to update themselves as their parent's dominating quantity
if (dominates) {
if (newEnabled == true) {
parent.setDominantQuantity(this);
} else {
parent.clearDominantQuantity();
}
}
requestRedraw();
}
void Quantity::refresh() { requestRedraw(); }
std::string Quantity::niceName() { return name; }
std::string Quantity::uniquePrefix() { return parent.uniquePrefix() + name + "#"; }
} // namespace polyscope