17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 02:49:19 +02:00

refactor(editor): split the vertical profile window

This commit is contained in:
maj00r
2026-10-04 00:48:42 +02:00
parent eb5b2e8919
commit 21082c4a5f
2 changed files with 54 additions and 33 deletions

View File

@@ -540,6 +540,9 @@ class editor_mode : public application_mode, private editor_track::observer
void profile_open_stored(std::size_t const Index);
void profile_edited();
void render_profile_window();
void render_profile_source();
bool render_profile_parameters();
void render_profile_issues();
void profile_open(TTrack *From, TTrack *To);
void profile_open_run(TTrack &Track);
void profile_resample();

View File

@@ -537,6 +537,48 @@ void editor_mode::render_profile_window()
ImGui::End();
return;
}
render_profile_source();
if (state.route.spans.empty())
{
ImGui::TextDisabled("Select a path in the viewport, then build the route along the line, or set its start and end paths (switches are passed through)");
if (state.picked_from != nullptr)
ImGui::Text("Start: %s", state.picked_from->name().c_str());
if (false == state.error.empty())
ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.3f, 1.0f), "%s", state.error.c_str());
ImGui::End();
return;
}
ImGui::Text("Route: %zu paths, %.2f m, %s ... %s", state.route.spans.size(), state.route.length, state.route.spans.front().track->name().c_str(), state.route.spans.back().track->name().c_str());
{
bool reversed;
auto const stored{profile_find(reversed)};
if (stored >= 0)
{
ImGui::TextDisabled("Design kept in %s%s", scene::Layers.layer(m_profiles[stored].layer).name.c_str(), state.changed ? ", changes go there on save" : "");
ImGui::SameLine();
if (ImGui::SmallButton("Forget the design"))
profile_forget();
}
else if (state.changed)
ImGui::TextDisabled("The design goes to the scenery file of the route on save");
}
if (render_profile_parameters())
profile_edited();
render_profile_canvas();
ImGui::Columns(2, "##profilecolumns", true);
render_profile_point();
ImGui::NextColumn();
render_profile_issues();
ImGui::Columns(1);
ImGui::End();
}
void editor_mode::render_profile_source()
{
auto &state{m_profile};
auto *selected{selected_track()};
if (ImGui::Button("Along the line from the selected path") && selected != nullptr)
profile_open_run(*selected);
@@ -566,31 +608,11 @@ void editor_mode::render_profile_window()
}
ImGui::TreePop();
}
if (state.route.spans.empty())
{
ImGui::TextDisabled("Select a path in the viewport, then build the route along the line, or set its start and end paths (switches are passed through)");
if (state.picked_from != nullptr)
ImGui::Text("Start: %s", state.picked_from->name().c_str());
if (false == state.error.empty())
ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.3f, 1.0f), "%s", state.error.c_str());
ImGui::End();
return;
}
ImGui::Text("Route: %zu paths, %.2f m, %s ... %s", state.route.spans.size(), state.route.length, state.route.spans.front().track->name().c_str(), state.route.spans.back().track->name().c_str());
{
bool reversed;
auto const stored{profile_find(reversed)};
if (stored >= 0)
{
ImGui::TextDisabled("Design kept in %s%s", scene::Layers.layer(m_profiles[stored].layer).name.c_str(), state.changed ? ", changes go there on save" : "");
ImGui::SameLine();
if (ImGui::SmallButton("Forget the design"))
profile_forget();
}
else if (state.changed)
ImGui::TextDisabled("The design goes to the scenery file of the route on save");
}
}
bool editor_mode::render_profile_parameters()
{
auto &state{m_profile};
auto &line{state.line};
bool changed{false};
ImGui::PushItemWidth(90.0f);
@@ -648,14 +670,12 @@ void editor_mode::render_profile_window()
if ((state.context.start_joined || state.context.end_joined) && ImGui::IsItemHovered())
ImGui::SetTooltip("Keeps the elevation of the joint and takes over the grade of the adjoining track,\n"
"with a vertical curve which starts right at the joint");
if (changed)
profile_edited();
return changed;
}
render_profile_canvas();
ImGui::Columns(2, "##profilecolumns", true);
render_profile_point();
ImGui::NextColumn();
void editor_mode::render_profile_issues()
{
auto &state{m_profile};
ImGui::Text("Largest departure from the track: %.3f m", state.departure);
ImGui::BeginChild("##profileissues", ImVec2(0.0f, 0.0f), false);
if (state.issues.empty())
@@ -681,8 +701,6 @@ void editor_mode::render_profile_window()
if (false == state.error.empty())
ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.3f, 1.0f), "%s", state.error.c_str());
ImGui::EndChild();
ImGui::Columns(1);
ImGui::End();
}
void editor_mode::render_profile_point()