mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-01 09:12:08 +01:00
feat(editor): vertical profile editor, grade lines kept in the scenery
This commit is contained in:
@@ -1021,6 +1021,8 @@ bool editor_mode::update()
|
||||
draw_build_overlay();
|
||||
draw_track_hints();
|
||||
render_track_window();
|
||||
draw_profile_overlay();
|
||||
render_profile_window();
|
||||
}
|
||||
|
||||
// --- area fill: outline overlay while the mode is active (its settings are drawn in the node bank window) ---
|
||||
@@ -1633,6 +1635,8 @@ void editor_mode::save()
|
||||
}
|
||||
}
|
||||
|
||||
if (m_profile.changed)
|
||||
profile_store();
|
||||
auto const result = scene::Layers.save(rootstatements);
|
||||
if (result.success && false == rootstatements.empty())
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "editor/editorOrthophoto.hpp"
|
||||
#include "editor/editorTrack.hpp"
|
||||
#include "editor/editorAlignment.hpp"
|
||||
#include "editor/editorProfile.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
@@ -477,6 +478,73 @@ class editor_mode : public application_mode
|
||||
void toggle_straight_set(TTrack &Track);
|
||||
void draw_track_hints();
|
||||
bool m_route_tab{true};
|
||||
|
||||
// vertical profile (grade line) along a route
|
||||
struct profile_state
|
||||
{
|
||||
bool open{false};
|
||||
TTrack *from{nullptr};
|
||||
TTrack *to{nullptr};
|
||||
TTrack *picked_from{nullptr};
|
||||
TTrack *picked_to{nullptr};
|
||||
double run_length{3000.0};
|
||||
editor_track::route route;
|
||||
std::vector<editor_track::route_sample> samples;
|
||||
std::vector<double> terrain; // NaN where there's no terrain
|
||||
profile::line line;
|
||||
profile::context context;
|
||||
std::vector<profile::issue> issues;
|
||||
double origin{0.0}; // chainage of the start of the route
|
||||
double departure{0.0}; // largest difference between the grade line and the track
|
||||
double view_from{0.0};
|
||||
double view_to{100.0};
|
||||
double view_centre{0.0};
|
||||
float exaggeration{20.0f};
|
||||
bool show_terrain{true};
|
||||
bool show_track{true};
|
||||
bool show_plan{true};
|
||||
int selected{-1};
|
||||
int dragging{-1};
|
||||
int curve_grip{-1};
|
||||
bool panning{false};
|
||||
bool changed{false};
|
||||
double hover{-1.0};
|
||||
std::string status;
|
||||
std::string error;
|
||||
};
|
||||
profile_state m_profile;
|
||||
// grade lines designed in the editor, kept in the scenery files as "//$p" comment lines
|
||||
struct stored_profile
|
||||
{
|
||||
scene::layer_handle layer{null_handle};
|
||||
double length{0.0};
|
||||
glm::dvec3 start{0.0}, end{0.0}, middle{0.0}; // of the route, world space
|
||||
double origin{0.0};
|
||||
profile::line line;
|
||||
};
|
||||
std::vector<stored_profile> m_profiles;
|
||||
bool m_profiles_loaded{false};
|
||||
void profile_library_load();
|
||||
void profile_library_mark(std::vector<scene::layer_handle> Layers);
|
||||
int profile_find(bool &Reversed) const;
|
||||
bool profile_restore();
|
||||
void profile_store();
|
||||
void profile_forget();
|
||||
void profile_open_stored(std::size_t const Index);
|
||||
void profile_edited();
|
||||
void render_profile_window();
|
||||
void profile_open(TTrack *From, TTrack *To);
|
||||
void profile_open_run(TTrack &Track);
|
||||
void profile_resample();
|
||||
void profile_recognize();
|
||||
void profile_check();
|
||||
void profile_apply();
|
||||
void profile_fit_view();
|
||||
void profile_after_undo();
|
||||
void render_profile_canvas();
|
||||
void render_profile_point();
|
||||
void draw_profile_overlay() const;
|
||||
|
||||
bool m_route_gizmo_using{false};
|
||||
glm::mat4 m_route_gizmo{1.0f};
|
||||
float m_track_snap_radius{1.0f};
|
||||
|
||||
1189
application/editormodeprofile.cpp
Normal file
1189
application/editormodeprofile.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,7 @@ http:
|
||||
#include "stdafx.h"
|
||||
#include "application/editormode.h"
|
||||
#include "application/editoruilayer.h"
|
||||
#include "application/editorprojection.h"
|
||||
|
||||
#include "utilities/Globals.h"
|
||||
#include "rendering/renderer.h"
|
||||
@@ -31,54 +32,6 @@ http:
|
||||
namespace
|
||||
{
|
||||
|
||||
class screen_projection
|
||||
{
|
||||
public:
|
||||
screen_projection()
|
||||
{
|
||||
ImGuiIO const &io = ImGui::GetIO();
|
||||
m_size = io.DisplaySize;
|
||||
m_camera = GfxRenderer->Camera_Position();
|
||||
float const aspect = m_size.y > 0.0f ? m_size.x / m_size.y : 1.0f;
|
||||
m_viewprojection = editor_mode::projection_matrix(aspect) * GfxRenderer->Camera_View_Matrix();
|
||||
}
|
||||
|
||||
glm::vec4 clip(glm::dvec3 const &Point) const
|
||||
{
|
||||
return m_viewprojection * glm::vec4(glm::vec3(Point - m_camera), 1.0f);
|
||||
}
|
||||
ImVec2 screen(glm::vec4 const &Clip) const
|
||||
{
|
||||
return ImVec2((Clip.x / Clip.w * 0.5f + 0.5f) * m_size.x, (0.5f - Clip.y / Clip.w * 0.5f) * m_size.y);
|
||||
}
|
||||
bool project(glm::dvec3 const &Point, ImVec2 &Screen) const
|
||||
{
|
||||
auto const c = clip(Point);
|
||||
if (c.w < kNear)
|
||||
return false;
|
||||
Screen = screen(c);
|
||||
return true;
|
||||
}
|
||||
void line(ImDrawList *Drawlist, glm::dvec3 const &A, glm::dvec3 const &B, ImU32 const Color, float const Thickness) const
|
||||
{
|
||||
glm::vec4 a = clip(A);
|
||||
glm::vec4 b = clip(B);
|
||||
if (a.w < kNear && b.w < kNear)
|
||||
return;
|
||||
if (a.w < kNear)
|
||||
a = glm::mix(a, b, (kNear - a.w) / (b.w - a.w));
|
||||
else if (b.w < kNear)
|
||||
b = glm::mix(b, a, (kNear - b.w) / (a.w - b.w));
|
||||
Drawlist->AddLine(screen(a), screen(b), Color, Thickness);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr float kNear{0.1f};
|
||||
ImVec2 m_size;
|
||||
glm::dvec3 m_camera;
|
||||
glm::mat4 m_viewprojection;
|
||||
};
|
||||
|
||||
glm::dvec3 path_point(segment_data const &Path, double const T)
|
||||
{
|
||||
auto const &p0 = Path.points[segment_data::point::start];
|
||||
@@ -452,6 +405,7 @@ void editor_mode::restore_track_snapshot(EditorSnapshot const &Snapshot, std::ve
|
||||
m_node = tracks.empty() || tracks.front()->m_editorremoved ? nullptr : tracks.front();
|
||||
ui()->set_node(m_node);
|
||||
straight_refresh();
|
||||
profile_after_undo();
|
||||
}
|
||||
|
||||
void editor_mode::render_track_ui()
|
||||
@@ -459,6 +413,13 @@ void editor_mode::render_track_ui()
|
||||
ImGui::TextDisabled("LMB on a path opens its editor: straight, curve or switch");
|
||||
if (ImGui::Button("Open the editor window"))
|
||||
m_track_window_open = true;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Vertical profile (grade line)"))
|
||||
{
|
||||
if (auto *track{selected_track()}; track != nullptr && m_profile.route.spans.empty())
|
||||
profile_open_run(*track);
|
||||
m_profile.open = true;
|
||||
}
|
||||
if (ImGui::CollapsingHeader("Straights in the scenery"))
|
||||
render_straights_ui();
|
||||
render_switch_ui();
|
||||
@@ -507,6 +468,8 @@ void editor_mode::render_track_window()
|
||||
if (ImGui::SmallButton("Edit points and parameters of the single path"))
|
||||
m_track_tab = track_tab::path;
|
||||
}
|
||||
if (ImGui::SmallButton("Vertical profile along this line") && selected_track() != nullptr)
|
||||
profile_open_run(*selected_track());
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -990,6 +953,7 @@ void editor_mode::route_apply()
|
||||
if (std::none_of(states.begin(), states.end(), [&](auto const &Entry) { return Entry.first == track; }))
|
||||
states.emplace_back(track, editor_track::capture(*track));
|
||||
auto pieces{alignment::pieces(route.result, route.design, chain.tracks.size())};
|
||||
editor_track::keep_heights(chain, pieces);
|
||||
auto relaid{editor_track::relay(chain, pieces)};
|
||||
auto const added{relaid.size()};
|
||||
created.insert(created.end(), relaid.begin(), relaid.end());
|
||||
@@ -1232,11 +1196,6 @@ void editor_mode::render_route_gizmo()
|
||||
else
|
||||
vertex.position = point;
|
||||
}
|
||||
if (std::abs(moved.y - position.y) > 1e-3)
|
||||
{
|
||||
vertex.auto_elevation = false;
|
||||
vertex.elevation = moved.y;
|
||||
}
|
||||
route_update();
|
||||
}
|
||||
|
||||
@@ -1308,8 +1267,6 @@ void editor_mode::render_route_ui()
|
||||
changed |= ImGui::InputDouble("Cant change rate (mm/s)", &norms.cant_rate, 0.0, 0.0, "%.0f");
|
||||
changed |= ImGui::InputDouble("Cant ramp 1:(k*V), k", &norms.ramp_factor, 0.0, 0.0, "%.1f");
|
||||
changed |= ImGui::InputDouble("Unbalanced acc. change rate (m/s3)", &norms.jerk, 0.0, 0.0, "%.2f");
|
||||
changed |= ImGui::InputDouble("Vertical curve R >= k*V^2, k", &norms.vertical_factor, 0.0, 0.0, "%.2f");
|
||||
changed |= ImGui::InputDouble("Vertical curve R min (m)", &norms.vertical_min, 0.0, 0.0, "%.0f");
|
||||
changed |= ImGui::InputDouble("Straight between curves (s of travel)", &norms.tangent_min_time, 0.0, 0.0, "%.1f");
|
||||
ImGui::PopItemWidth();
|
||||
norms.gauge = std::max(100.0, norms.gauge);
|
||||
@@ -1401,16 +1358,11 @@ void editor_mode::render_route_ui()
|
||||
changed |= ImGui::InputDouble("Transition out (m)", &vertex.transition_out, 0.0, 0.0, "%.1f");
|
||||
changed |= ImGui::InputDouble("Cant (mm)", &vertex.cant, 0.0, 0.0, "%.0f");
|
||||
changed |= ImGui::Checkbox("Turn the longer way (over 180 deg)", &vertex.reverse_turn);
|
||||
changed |= ImGui::Checkbox("Elevation from the ends", &vertex.auto_elevation);
|
||||
if (false == vertex.auto_elevation)
|
||||
changed |= ImGui::InputDouble("Elevation (m)", &vertex.elevation, 0.0, 0.0, "%.3f");
|
||||
changed |= ImGui::InputDouble("Vertical curve R (0: min)", &vertex.vertical_radius, 0.0, 0.0, "%.0f");
|
||||
ImGui::PopItemWidth();
|
||||
vertex.radius = std::max(1.0, vertex.radius);
|
||||
vertex.transition_in = std::max(0.0, vertex.transition_in);
|
||||
vertex.transition_out = std::max(0.0, vertex.transition_out);
|
||||
vertex.cant = std::max(0.0, vertex.cant);
|
||||
vertex.vertical_radius = std::max(0.0, vertex.vertical_radius);
|
||||
if (ImGui::SmallButton("Apply recommended for V"))
|
||||
{
|
||||
route_recommend(vertex);
|
||||
@@ -2260,6 +2212,7 @@ void editor_mode::straight_reshape(editor_track::straight const &Line, double co
|
||||
return;
|
||||
}
|
||||
auto pieces{alignment::pieces(m_route.result, m_route.design, m_route.chain.tracks.size())};
|
||||
editor_track::keep_heights(m_route.chain, pieces);
|
||||
auto created{editor_track::relay(m_route.chain, pieces)};
|
||||
editor_track::commit(tracks);
|
||||
for (auto const &entry : splitstates)
|
||||
|
||||
63
application/editorprojection.h
Normal file
63
application/editorprojection.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "application/editormode.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
// world to screen projection of the current camera, for overlays drawn with ImGui
|
||||
class screen_projection
|
||||
{
|
||||
public:
|
||||
screen_projection()
|
||||
{
|
||||
ImGuiIO const &io = ImGui::GetIO();
|
||||
m_size = io.DisplaySize;
|
||||
m_camera = GfxRenderer->Camera_Position();
|
||||
float const aspect = m_size.y > 0.0f ? m_size.x / m_size.y : 1.0f;
|
||||
m_viewprojection = editor_mode::projection_matrix(aspect) * GfxRenderer->Camera_View_Matrix();
|
||||
}
|
||||
|
||||
glm::vec4 clip(glm::dvec3 const &Point) const
|
||||
{
|
||||
return m_viewprojection * glm::vec4(glm::vec3(Point - m_camera), 1.0f);
|
||||
}
|
||||
ImVec2 screen(glm::vec4 const &Clip) const
|
||||
{
|
||||
return ImVec2((Clip.x / Clip.w * 0.5f + 0.5f) * m_size.x, (0.5f - Clip.y / Clip.w * 0.5f) * m_size.y);
|
||||
}
|
||||
bool project(glm::dvec3 const &Point, ImVec2 &Screen) const
|
||||
{
|
||||
auto const c = clip(Point);
|
||||
if (c.w < kNear)
|
||||
return false;
|
||||
Screen = screen(c);
|
||||
return true;
|
||||
}
|
||||
void line(ImDrawList *Drawlist, glm::dvec3 const &A, glm::dvec3 const &B, ImU32 const Color, float const Thickness) const
|
||||
{
|
||||
glm::vec4 a = clip(A);
|
||||
glm::vec4 b = clip(B);
|
||||
if (a.w < kNear && b.w < kNear)
|
||||
return;
|
||||
if (a.w < kNear)
|
||||
a = glm::mix(a, b, (kNear - a.w) / (b.w - a.w));
|
||||
else if (b.w < kNear)
|
||||
b = glm::mix(b, a, (kNear - b.w) / (a.w - b.w));
|
||||
Drawlist->AddLine(screen(a), screen(b), Color, Thickness);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr float kNear{0.1f};
|
||||
ImVec2 m_size;
|
||||
glm::dvec3 m_camera;
|
||||
glm::mat4 m_viewprojection;
|
||||
};
|
||||
Reference in New Issue
Block a user