builder 和 运行时修改隔离开
This commit is contained in:
@@ -29,12 +29,12 @@
|
||||
namespace renderive::web {
|
||||
namespace {
|
||||
template <class Update>
|
||||
void update_axis_state(const std::shared_ptr<Abs_Axis>& axis, Update&& update) {
|
||||
if (const auto numeric = std::dynamic_pointer_cast<Axis>(axis)) {
|
||||
void update_axis_state(const renderive_Owner<Abs_Axis>& axis, Update&& update) {
|
||||
if (const auto numeric = renderive_dynamic_owner_cast<Axis>(axis)) {
|
||||
numeric->update([&](Axis_Properties& state) {
|
||||
std::forward<Update>(update)(static_cast<Axis_Base_Properties&>(state));
|
||||
});
|
||||
} else if (const auto time = std::dynamic_pointer_cast<Time_Axis>(axis)) {
|
||||
} else if (const auto time = renderive_dynamic_owner_cast<Time_Axis>(axis)) {
|
||||
time->update([&](auto& state) {
|
||||
std::forward<Update>(update)(static_cast<Axis_Base_Properties&>(state));
|
||||
});
|
||||
@@ -107,13 +107,24 @@ public:
|
||||
plot_.set_viewport_size({560, 320});
|
||||
root_ = plot_.root_renderable();
|
||||
root_->set_object_name("画布根节点");
|
||||
axes_node_ = plot_.create_renderable_node(root_, "坐标轴层");
|
||||
data_node_ = plot_.create_renderable_node(root_, "数据绘制层");
|
||||
overlay_node_ = plot_.create_renderable_node(root_, "交互覆盖层");
|
||||
axes_node_->set_cache_mode(Renderable_Cache_Mode::Local_Pixel);
|
||||
{
|
||||
auto attach = plot_.attach_builder();
|
||||
const auto make_group = [&](std::string name) {
|
||||
auto group = detail::make_renderable_group(true);
|
||||
group->set_object_name(std::move(name));
|
||||
attach.attach(group);
|
||||
attach.add_parent(::Scene_Base::Relationship::display, group, root_);
|
||||
attach.add_parent(::Scene_Base::Relationship::dependency, group, root_);
|
||||
return group;
|
||||
};
|
||||
axes_node_ = make_group("坐标轴层");
|
||||
data_node_ = make_group("数据绘制层");
|
||||
overlay_node_ = make_group("交互覆盖层");
|
||||
axes_node_->set_cache_mode(Renderable_Cache_Mode::Local_Pixel);
|
||||
build_axes(attach);
|
||||
build_primary(attach);
|
||||
}
|
||||
attach_performance_overlay(plot_);
|
||||
build_axes();
|
||||
build_primary();
|
||||
apply_layout();
|
||||
session_control_ = std::make_unique<Gallery_Session_Control<Scene_Type>>(
|
||||
plot_, *primary_, feedback_policy_);
|
||||
@@ -922,7 +933,7 @@ private:
|
||||
};
|
||||
write_web_performance_log(line.dump());
|
||||
}
|
||||
void build_axes() {
|
||||
void build_axes(::Scene_Base::Attach_Builder& attach) {
|
||||
constexpr Color axis_color{118, 145, 184, 255};
|
||||
Range coordinate_range{88'000'000.0, 108'000'000.0};
|
||||
if (case_id_ == "sweep_spectrum")
|
||||
@@ -930,7 +941,7 @@ private:
|
||||
else if (case_id_ == "constellation")
|
||||
coordinate_range = {-1.25, 1.25};
|
||||
if (case_id_ == "frequency_trace") {
|
||||
time_axis_ = Gallery_Time_Axis::Builder(axes_node_, Orientation::Horizontal)
|
||||
time_axis_ = Gallery_Time_Axis::Builder(axes_node_, Orientation::Horizontal, &attach)
|
||||
.set_visible_time_point_count(80)
|
||||
.set_tick_label_spacing_px(28)
|
||||
.set_time_format("mm:ss.zzz")
|
||||
@@ -938,7 +949,7 @@ private:
|
||||
.build();
|
||||
}
|
||||
else if (case_id_ == "sweep_spectrum" || case_id_ == "constellation") {
|
||||
numeric_domain_axis_ = Gallery_Axis::Builder(axes_node_, Orientation::Horizontal)
|
||||
numeric_domain_axis_ = Gallery_Axis::Builder(axes_node_, Orientation::Horizontal, &attach)
|
||||
.set_coord_range(coordinate_range)
|
||||
.set_use_wheel(true)
|
||||
.set_use_drag(true)
|
||||
@@ -946,7 +957,7 @@ private:
|
||||
.build();
|
||||
}
|
||||
else {
|
||||
frequency_domain_axis_ = Gallery_Frequency_Axis::Builder(axes_node_, Orientation::Horizontal)
|
||||
frequency_domain_axis_ = Gallery_Frequency_Axis::Builder(axes_node_, Orientation::Horizontal, &attach)
|
||||
.set_coord_range(coordinate_range)
|
||||
.set_use_wheel(true)
|
||||
.set_use_drag(true)
|
||||
@@ -954,7 +965,7 @@ private:
|
||||
.build();
|
||||
}
|
||||
if (case_id_ == "waterfall") {
|
||||
time_axis_ = Gallery_Time_Axis::Builder(axes_node_, Orientation::Vertical)
|
||||
time_axis_ = Gallery_Time_Axis::Builder(axes_node_, Orientation::Vertical, &attach)
|
||||
.set_visible_time_point_count(80)
|
||||
.set_tick_label_spacing_px(28)
|
||||
.set_time_format("mm:ss.zzz")
|
||||
@@ -967,21 +978,21 @@ private:
|
||||
value_range = {-1.0, 1.0};
|
||||
else if (case_id_ == "constellation")
|
||||
value_range = {-1.25, 1.25};
|
||||
value_axis_ = Gallery_Axis::Builder(axes_node_, Orientation::Vertical)
|
||||
value_axis_ = Gallery_Axis::Builder(axes_node_, Orientation::Vertical, &attach)
|
||||
.set_coord_range(value_range)
|
||||
.set_label_precision(case_id_ == "constellation" ? 2 : 0)
|
||||
.set_color(axis_color)
|
||||
.build();
|
||||
}
|
||||
if (case_id_ == "axis_lab") {
|
||||
time_axis_ = Gallery_Time_Axis::Builder(axes_node_, Orientation::Horizontal)
|
||||
time_axis_ = Gallery_Time_Axis::Builder(axes_node_, Orientation::Horizontal, &attach)
|
||||
.set_visible_time_point_count(80)
|
||||
.set_tick_label_spacing_px(28)
|
||||
.set_time_format("mm:ss.zzz")
|
||||
.set_color({69, 221, 190, 255})
|
||||
.build();
|
||||
}
|
||||
const auto style = [this](const std::shared_ptr<Abs_Axis>& axis) {
|
||||
const auto style = [this](const renderive_Owner<Abs_Axis>& axis) {
|
||||
if (!axis)
|
||||
return;
|
||||
update_axis_state(axis, [this](Axis_Base_Properties& value) {
|
||||
@@ -1001,9 +1012,9 @@ private:
|
||||
if (case_id_ == "axis_lab")
|
||||
style(time_axis_);
|
||||
}
|
||||
void build_primary() {
|
||||
void build_primary(::Scene_Base::Attach_Builder& attach) {
|
||||
if (case_id_ == "axis_lab") {
|
||||
primary_ = std::static_pointer_cast<Renderable>(frequency_domain_axis_);
|
||||
primary_ = renderive_static_owner_cast<Renderable>(frequency_domain_axis_);
|
||||
return;
|
||||
}
|
||||
if (case_id_ == "spectrum" || case_id_ == "selection_overlay") {
|
||||
@@ -1026,7 +1037,7 @@ private:
|
||||
properties.marker_pen = {color_from_hex("#ff7a59"), 1.2};
|
||||
properties.middle_frequency_pen = {color_from_hex("#6bc8ff"), 1.0, Line_Style::Dash};
|
||||
properties.sweep_region_brush = {color_from_hex("#293257", 80), Brush_Style::Solid};
|
||||
spectrum_ = Gallery_Spectrum::Builder{properties}.build(
|
||||
spectrum_ = Gallery_Spectrum::Builder{properties, &attach}.build(
|
||||
data_node_, frequency_domain_axis_, value_axis_);
|
||||
primary_ = spectrum_;
|
||||
if (case_id_ == "selection_overlay") {
|
||||
@@ -1034,7 +1045,7 @@ private:
|
||||
overlay.label_font = {12.0, 500, false};
|
||||
overlay.selection_brush = {color_from_hex("#173b66", 70), Brush_Style::Solid};
|
||||
overlay.selection_border_pen = {color_from_hex("#7dd3fc"), 1.0, Line_Style::Dash};
|
||||
selection_ = Gallery_Selection_Rectangle_Overlay::Builder{overlay}.build(
|
||||
selection_ = Gallery_Selection_Rectangle_Overlay::Builder{overlay, &attach}.build(
|
||||
overlay_node_, frequency_domain_axis_, value_axis_);
|
||||
primary_ = selection_;
|
||||
}
|
||||
@@ -1045,7 +1056,7 @@ private:
|
||||
properties.frequency_range = {88'000'000.0, 108'000'000.0};
|
||||
properties.power_range = {-120.0, -20.0};
|
||||
properties.frequency_bin_count = 256;
|
||||
waterfall_ = Gallery_Waterfall::Builder{properties}.build(
|
||||
waterfall_ = Gallery_Waterfall::Builder{properties, &attach}.build(
|
||||
data_node_, frequency_domain_axis_, time_axis_);
|
||||
primary_ = waterfall_;
|
||||
return;
|
||||
@@ -1057,7 +1068,7 @@ private:
|
||||
properties.frequency_point_size = 192;
|
||||
properties.power_point_size = 96;
|
||||
properties.attenuation_rate = 0.18;
|
||||
afterglow_ = Gallery_Afterglow::Builder{properties}.build(
|
||||
afterglow_ = Gallery_Afterglow::Builder{properties, &attach}.build(
|
||||
data_node_, frequency_domain_axis_, value_axis_);
|
||||
primary_ = afterglow_;
|
||||
return;
|
||||
@@ -1069,7 +1080,7 @@ private:
|
||||
properties.block_count = 8;
|
||||
properties.pen = {color_from_hex("#ffd166"), 1.8};
|
||||
properties.current_frequency_pen = {color_from_hex("#ff5d73"), 2.0};
|
||||
sweep_ = Gallery_Sweep_Spectrum::Builder{properties}.build(
|
||||
sweep_ = Gallery_Sweep_Spectrum::Builder{properties, &attach}.build(
|
||||
data_node_, numeric_domain_axis_, value_axis_);
|
||||
primary_ = sweep_;
|
||||
return;
|
||||
@@ -1078,7 +1089,7 @@ private:
|
||||
Frequency_Trace_Properties properties;
|
||||
properties.pen = {color_from_hex("#35e6b2"), 2.0, Line_Style::Solid,
|
||||
Line_Cap::Round, Line_Join::Round};
|
||||
trace_ = Gallery_Frequency_Trace::Builder{properties}.build(
|
||||
trace_ = Gallery_Frequency_Trace::Builder{properties, &attach}.build(
|
||||
data_node_, time_axis_, value_axis_);
|
||||
primary_ = trace_;
|
||||
return;
|
||||
@@ -1090,19 +1101,19 @@ private:
|
||||
properties.point_color = color_from_hex("#49e6c3");
|
||||
properties.anchor_color = color_from_hex("#ffd166");
|
||||
properties.point_lifetime_ms = 1800;
|
||||
constellation_ = Gallery_Constellation_Diagram::Builder{properties}.build(
|
||||
constellation_ = Gallery_Constellation_Diagram::Builder{properties, &attach}.build(
|
||||
data_node_, numeric_domain_axis_, value_axis_);
|
||||
primary_ = constellation_;
|
||||
}
|
||||
}
|
||||
std::shared_ptr<Abs_Axis> horizontal_axis() const {
|
||||
renderive_Owner<Abs_Axis> horizontal_axis() const {
|
||||
if (frequency_domain_axis_)
|
||||
return frequency_domain_axis_;
|
||||
if (numeric_domain_axis_)
|
||||
return numeric_domain_axis_;
|
||||
return time_axis_;
|
||||
}
|
||||
std::shared_ptr<Abs_Axis> vertical_axis() const {
|
||||
renderive_Owner<Abs_Axis> vertical_axis() const {
|
||||
if (case_id_ == "waterfall")
|
||||
return time_axis_;
|
||||
return value_axis_;
|
||||
@@ -1115,7 +1126,7 @@ private:
|
||||
const int bottom = 46;
|
||||
const int width = std::max(1, viewport.width - left - right);
|
||||
const int height = std::max(1, viewport.height - top - bottom);
|
||||
const auto layout_axis = [=](const std::shared_ptr<Abs_Axis>& target) {
|
||||
const auto layout_axis = [=](const renderive_Owner<Abs_Axis>& target) {
|
||||
if (!target)
|
||||
return;
|
||||
update_axis_state(target, [=](Axis_Base_Properties& axis) {
|
||||
@@ -1253,22 +1264,22 @@ private:
|
||||
Gallery_Controls controls_;
|
||||
std::chrono::steady_clock::time_point performance_started_;
|
||||
std::chrono::steady_clock::time_point last_performance_log_;
|
||||
std::shared_ptr<Renderable> root_;
|
||||
std::shared_ptr<Renderable> axes_node_;
|
||||
std::shared_ptr<Renderable> data_node_;
|
||||
std::shared_ptr<Renderable> overlay_node_;
|
||||
std::shared_ptr<Gallery_Axis> numeric_domain_axis_;
|
||||
std::shared_ptr<Gallery_Frequency_Axis> frequency_domain_axis_;
|
||||
std::shared_ptr<Gallery_Axis> value_axis_;
|
||||
std::shared_ptr<Gallery_Time_Axis> time_axis_;
|
||||
std::shared_ptr<Renderable> primary_;
|
||||
std::shared_ptr<Gallery_Spectrum> spectrum_;
|
||||
std::shared_ptr<Gallery_Waterfall> waterfall_;
|
||||
std::shared_ptr<Gallery_Frequency_Trace> trace_;
|
||||
std::shared_ptr<Gallery_Afterglow> afterglow_;
|
||||
std::shared_ptr<Gallery_Sweep_Spectrum> sweep_;
|
||||
std::shared_ptr<Gallery_Selection_Rectangle_Overlay> selection_;
|
||||
std::shared_ptr<Gallery_Constellation_Diagram> constellation_;
|
||||
renderive_Owner<Renderable> root_;
|
||||
renderive_Owner<Renderable> axes_node_;
|
||||
renderive_Owner<Renderable> data_node_;
|
||||
renderive_Owner<Renderable> overlay_node_;
|
||||
renderive_Owner<Gallery_Axis> numeric_domain_axis_;
|
||||
renderive_Owner<Gallery_Frequency_Axis> frequency_domain_axis_;
|
||||
renderive_Owner<Gallery_Axis> value_axis_;
|
||||
renderive_Owner<Gallery_Time_Axis> time_axis_;
|
||||
renderive_Owner<Renderable> primary_;
|
||||
renderive_Owner<Gallery_Spectrum> spectrum_;
|
||||
renderive_Owner<Gallery_Waterfall> waterfall_;
|
||||
renderive_Owner<Gallery_Frequency_Trace> trace_;
|
||||
renderive_Owner<Gallery_Afterglow> afterglow_;
|
||||
renderive_Owner<Gallery_Sweep_Spectrum> sweep_;
|
||||
renderive_Owner<Gallery_Selection_Rectangle_Overlay> selection_;
|
||||
renderive_Owner<Gallery_Constellation_Diagram> constellation_;
|
||||
std::uint64_t frame_index_{};
|
||||
std::uint64_t render_attempt_count_{};
|
||||
std::uint64_t successful_render_count_{};
|
||||
|
||||
Reference in New Issue
Block a user