/* 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/. */ #include "stdafx.h" #include "application/editormode.h" #include "editor/editorSettings.hpp" #include "editor/editorGeometry.hpp" #include "application/application.h" #include "application/editoruilayer.h" #include "application/editorprojection.h" #include "simulation/simulation.h" #include "simulation/simulationtime.h" #include "scene/scenelayers.h" #include "utilities/Globals.h" #include "utilities/Logs.h" #include "world/Track.h" #include "world/TrackRails.h" #include "world/MemCell.h" #include "world/Event.h" #include "vehicle/DynObj.h" #include "model/AnimModel.h" #include "model/Model3d.h" #include "rendering/renderer.h" #include "world/Sweep.h" #include "input/keyboardinput.h" #include "launcher/textures_scanner.h" #include #include #include #include "editor/editorFormat.hpp" #include "editor/editorAlignmentStore.hpp" #include "editor/editorSwitchStore.hpp" #include "scene/sceneterrain.h" #include "editor/editorSpeed.hpp" #include #include #include #include #include #include #include "application/editormodeselftest.h" editor_mode::selftest_result editor_mode::selftest_switch(std::string const &command, std::istringstream &words) { // each switch: the tips of its blades and its drive from the joint before them; drivetips moves the drives there first if (command == "bladetips" || command == "drivetips") { if (command == "drivetips") WriteLog(format("SELFTEST drivetips: %zu moved", drives_to_blade_tips())); for (auto *track : simulation::Paths.sequence()) { if (track == nullptr || track->m_editorremoved || track->eType != tt_Switch || track->m_paths.size() < 2) continue; auto const start{track->m_paths[0].points[segment_data::point::start]}; std::string text{format("SELFTEST drive of %s: blades from %.3f m", track->name().c_str(), editor_track::blade_tip_of(*track))}; for (int path = 0; path < 2; ++path) if (auto const &shape{track->blade(path)}; shape.valid) text += format(", blade %d %.3f - %.3f m", path, shape.tip, shape.heel); if (auto const found{find_switch_drive(*track)}) text += format(", drive %.3f m from the joint", geometry::plan_distance(found->standing.location, start)); else text += ", no drive"; // how far apart the rail of the blade and the one it lies at are along the path, where the blades of a slip are shaped if (track->DoubleSlip()) for (int path = 0; path < 2; ++path) { auto const &shape{track->blade(path)}; auto const gap = [&](double const At) { auto const &gauge{shape.gauge}; auto const next{std::find_if(gauge.begin(), gauge.end(), [&](glm::dvec2 const &Sample) { return Sample.x >= At; })}; return next == gauge.end() ? (gauge.empty() ? -1.0 : gauge.back().y) : next->y; }; text += format(", path %d %s side %d gaps", path, shape.valid ? "shaped" : "not shaped", track->SwitchExtension->RightSwitch == (path == 0) ? 1 : -1); for (auto const at : {0.354, 1.0, 1.248, 2.0, 4.0, 6.0, 8.0, 9.4}) text += format(" %.1f:%.4f", at, gap(at)); } WriteLog(text); } return selftest_result::handled; } if (command == "curvedswitch") { std::string name; std::string label; glm::dvec3 at{0.0}; glm::dvec3 toward{0.0}; words >> name >> at.x >> at.z >> toward.x >> toward.z >> label; std::replace(label.begin(), label.end(), '_', ' '); m_node = simulation::Paths.find(name); ui()->set_node(m_node); show_track_tab(track_tab::turnout); arm_switch(); auto &tool{m_switch}; for (int i = 0; i < static_cast(tool.templates.size()); ++i) if (false == label.empty() && tool.templates[i].label.find(label) != std::string::npos) { tool.armed = i; break; } m_cursor_override = at; auto const started{start_switch_placement()}; m_cursor_override.reset(); if (false == started) { WriteLog("SELFTEST curvedswitch: not started, " + tool.status); return selftest_result::handled; } tool.mouse = glm::dvec3{toward.x, tool.point.y, toward.z}; finish_switch_placement(); WriteLog("SELFTEST curvedswitch " + (tool.armed >= 0 ? tool.templates[tool.armed].label : std::string{}) + ": " + tool.status); return selftest_result::handled; } if (command == "designer") { std::string list; int index{0}; auto &designer{m_switch_designer}; designer.pointed_test = -1; words >> list >> index >> designer.pointed_test; designer.open = list != "close"; designer.from_catalogue = list != "own"; designer.selected = index; switch_designs_load(); auto const &list_of{designer.from_catalogue ? designer.catalogue : designer.own}; if (designer.open && index >= 0 && index < static_cast(list_of.size())) { std::string problem; auto const shape{switch_design::build(list_of[index], problem)}; auto text{format("SELFTEST designer %s: a %.3f b %.3f 1:%.3f sharpest R %.1f, %.3f m beside the main one, %.3f m long, end %.3f; parts", list_of[index].name.c_str(), shape.a, shape.b, shape.ratio, shape.radius, shape.offset, shape.length, shape.paths.size() > 1 ? shape.paths[1].points[segment_data::point::end].z : 0.0)}; for (auto const &part : list_of[index].parts) text += format(" %.3f/R%.1f", part.length, part.radius1); WriteLog(text + " " + problem); } return selftest_result::handled; } if (command == "designerpick") { // the points of a switch clicked off the view for the template editor, by x z; finish: the template made of them auto &designer{m_switch_designer}; designer.open = true; designer.picking = true; for (glm::dvec2 point; words >> point.x >> point.y;) switch_designer_click({point.x, 0.0, point.y}); words.clear(); std::string finish; words >> finish; if (finish == "finish") { switch_designer_finish(); WriteLog("SELFTEST designerpick: " + designer.status); if (false == designer.from_catalogue && designer.selected >= 0 && designer.selected < static_cast(designer.own.size())) { auto text{std::string{"SELFTEST designerpick parts"}}; for (auto const &part : designer.own[designer.selected].parts) text += format(" %.3f/R%.1f..%.1f", part.length, part.radius1, part.radius2); WriteLog(text + format(", lead %.3f", designer.own[designer.selected].lead)); } } return selftest_result::handled; } if (command == "release") { m_switch.placing = false; lay_cancel(); m_cursor_override.reset(); return selftest_result::handled; } if (command == "hover") { glm::dvec3 at{0.0}; if (words >> at.x >> at.z) m_cursor_override = at; else m_cursor_override.reset(); return selftest_result::handled; } if (command == "layhold") { int layout{0}; words >> layout >> m_lay.radius; m_track_layout = static_cast(std::clamp(layout, 0, 3)); m_lay.active = true; lay_cancel(); std::vector points; for (glm::dvec3 point{0.0}; words >> point.x >> point.z;) points.push_back(point); for (std::size_t i = 0; i + 1 < points.size(); ++i) { auto point{points[i]}; point.y = 5000.0; std::vector found; auto const ground{ground_heights({point}, true, &found)}; point.y = found[0] != 0 ? ground[0] : m_lay.points.empty() ? 0.0 : m_lay.points.back().y; m_lay.mouse_snap = editor_track::find_free_end(nullptr, 1, point, 3.0, {}); m_lay.mouse = m_lay.mouse_snap.track != nullptr ? point : lay_bed(point); lay_click(); } if (false == points.empty()) m_cursor_override = points.back(); WriteLog("SELFTEST layhold: " + m_lay.status); return selftest_result::handled; } if (command == "switchkind") { // what the switch tool places, as chosen in its panel: single, slip, crossing or connection with the kind of it std::string word; int sub{0}; words >> word >> sub; auto const kind{word == "slip" ? switch_kind::slip : word == "crossing" ? switch_kind::crossing : word == "connection" ? switch_kind::connection : switch_kind::single}; m_switch.connection_kind = sub; choose_switch_kind(kind); WriteLog(format("SELFTEST switchkind %s: kind %d, connection %d, armed %d", word.c_str(), static_cast(current_switch_kind()), m_switch.connection, m_switch.armed)); return selftest_result::handled; } if (command == "connection" || command == "connectionplan" || command == "connectionhold") { std::string kindword; std::string label; std::string second; glm::dvec3 at{0.0}; glm::dvec3 toward{0.0}; words >> kindword >> at.x >> at.z >> toward.x >> toward.z >> label >> second; connection::kind kind{connection::kind::crossover}; // drag: a switch let go there as the mouse lets it go, the connection told by where auto const drag{kindword == "drag"}; if (kindword != "single" && false == drag && false == connection::parse(kindword, kind)) { WriteLog("SELFTEST connection: unknown kind " + kindword); return selftest_result::handled; } auto &tool{m_switch}; for (std::string key; words >> key;) { if (key == "radius") words >> tool.connection_radius; else if (key == "gap") words >> tool.connection_gap; else if (key == "together") words >> tool.connection_together; else if (key == "stub") words >> tool.connection_stub; else if (key == "spacings") { std::string value; words >> value; std::snprintf(tool.connection_spacings, sizeof(tool.connection_spacings), "%s", value.c_str()); } } show_track_tab(track_tab::turnout); arm_switch(); auto const find = [&](std::string Label) { std::replace(Label.begin(), Label.end(), '_', ' '); for (int i = 0; i < static_cast(tool.templates.size()); ++i) if (false == Label.empty() && Label != "-" && false == tool.templates[i].double_slip && false == tool.templates[i].twofold() && tool.templates[i].label.find(Label) != std::string::npos) return i; return -1; }; auto const first{find(label)}; if (first < 0) { WriteLog("SELFTEST connection: no template " + label); return selftest_result::handled; } tool.armed = first; tool.connection_second = find(second); tool.connection = kindword == "single" || drag ? -1 : static_cast(kind); auto const line{straight_near(at, {}, 3.0)}; // the track of the straight under the press TTrack *start{nullptr}; auto closest{3.0}; for (auto *track : line.tracks) if (auto const distance{geometry::plan_distance(editor_track::point_at(*track, editor_track::nearest_parameter(*track, at)), at)}; distance < closest) { closest = distance; start = track; } if (start == nullptr) { // along a curve: the track nearest to the press auto best{3.0}; for (auto *track : simulation::Paths.sequence()) { if (track == nullptr || track->m_editorremoved || track->eType != tt_Normal || track->m_paths.empty()) continue; auto const distance{geometry::plan_distance(editor_track::point_at(*track, editor_track::nearest_parameter(*track, at)), at)}; if (distance < best) { best = distance; start = track; } } } if (start == nullptr) { WriteLog("SELFTEST connection: no track at the start"); return selftest_result::handled; } m_node = start; ui()->set_node(m_node); m_cursor_override = at; auto const started{start_switch_placement()}; m_cursor_override.reset(); if (false == started) { auto const *selected{selected_track()}; WriteLog(format("SELFTEST connection: not started at %s (%d), armed %d, tab %d, straight of %zu tracks, %s", selected != nullptr ? selected->name().c_str() : "nothing", selected != nullptr ? static_cast(selected->eType) : -1, tool.armed, static_cast(m_track_tab), current_straight().tracks.size(), tool.status.c_str())); return selftest_result::handled; } tool.mouse = glm::dvec3{toward.x, tool.point.y, toward.z}; auto const log_records = [&]() { for (auto const &entry : switch_store::records()) if (entry.kind == "connection") { std::string parts; for (auto const &part : entry.parts) parts += ' ' + part; WriteLog(format("SELFTEST connection record %s %s: spacing %.3f, insert %.3f, parts%s", entry.type.c_str(), entry.name.c_str(), entry.a, entry.b, parts.c_str())); } }; if (drag) { recognise_connection(); WriteLog(std::string{"SELFTEST connection drag: "} + (tool.connection < 0 ? "a switch" : connection::word(static_cast(tool.connection))) + (tool.partner != nullptr ? " with " + tool.partner->name() : std::string{}) + (tool.connection == static_cast(connection::kind::double_crossover) ? format(", gap %.2f, together %d", tool.connection_gap, tool.connection_together ? 1 : 0) : std::string{})); if (tool.connection >= 0 && false == tool.curved) { connection::request request; connection::result plan; auto const valid{tool.partner != nullptr ? plan_partner_connection(request, plan) : plan_connection(request, plan)}; WriteLog("SELFTEST connection drag plan: " + (valid ? connection_readout(plan) : "invalid, " + plan.error)); for (auto const &entry : plan.switches) { auto const &start{entry.paths[0].points[segment_data::point::start]}; auto const &end{entry.paths[0].points[segment_data::point::end]}; WriteLog(format("SELFTEST connection switch on %d at %.3f, forward %d side %d: %.3f %.3f -> %.3f %.3f", entry.line, entry.along, entry.forward, entry.side, start.x, start.z, end.x, end.z)); } for (auto const &line : request.to) WriteLog(format("SELFTEST connection to the line from %.3f %.3f, %.1f m", line.start.x, line.start.z, line.length)); } finish_switch_placement(); WriteLog("SELFTEST connection built: " + tool.status); log_records(); return selftest_result::handled; } if (tool.curved) { finish_switch_placement(); WriteLog("SELFTEST connection along the curve: " + tool.status); return selftest_result::handled; } if (command == "connectionhold") { m_cursor_override = toward; WriteLog("SELFTEST connectionhold: " + tool.status); return selftest_result::handled; } connection::request request; connection::result plan; auto const valid{plan_connection(request, plan)}; WriteLog("SELFTEST connection " + kindword + ": " + (valid ? connection_readout(plan) : "invalid, " + plan.error)); for (auto const &entry : plan.switches) { auto const &start{entry.paths[0].points[segment_data::point::start]}; auto const &end{entry.paths[1].points[segment_data::point::end]}; WriteLog(format("SELFTEST connection switch on %d at %.3f, forward %d side %d%s: %.3f %.3f %.3f -> branch end %.3f %.3f %.3f", entry.line, entry.along, entry.forward, entry.side, entry.second ? " (second)" : "", start.x, start.y, start.z, end.x, end.y, end.z)); } for (auto const &insert : plan.inserts) { auto const &start{insert.points[segment_data::point::start]}; auto const &end{insert.points[segment_data::point::end]}; WriteLog(format("SELFTEST connection insert %.3f %.3f %.3f -> %.3f %.3f %.3f, %.3f m, R %.1f", start.x, start.y, start.z, end.x, end.y, end.z, geometry::bezier{insert}.plan_length(), std::abs(insert.radius))); } if (command == "connectionplan" || false == valid) { tool.placing = false; return selftest_result::handled; } insert_connection(); WriteLog("SELFTEST connection built: " + tool.status); log_records(); return selftest_result::handled; } if (command == "conecheck") { std::string name; words >> name; auto *track{simulation::Paths.find(name)}; if (track == nullptr || track->m_paths.size() < 2) { WriteLog("SELFTEST conecheck: no switch " + name); return selftest_result::handled; } geometry::bezier const main{track->m_paths[0]}; geometry::bezier const other{track->m_paths[1]}; std::string text; for (int i = 1; i <= 8; ++i) { auto const t{i * 0.125}; auto const point{other.point(t)}; double best{std::numeric_limits::max()}; double along{0.0}; for (int k = 0; k <= 2000; ++k) if (auto const distance{geometry::plan_distance(main.point(k / 2000.0), point)}; distance < best) { best = distance; along = k / 2000.0; } auto const base{main.point(along)}; auto const direction{glm::normalize(geometry::plan_of(main.first(along)))}; auto const lateral{(point.x - base.x) * -direction.y + (point.z - base.z) * direction.x}; auto const &path{track->m_paths[0]}; auto const roll{glm::radians(path.rolls[0] + (path.rolls[1] - path.rolls[0]) * along)}; auto const tangent{main.first(along)}; auto const beyond{(point.x - base.x) * direction.x + (point.z - base.z) * direction.y}; auto const cone{base.y + beyond * tangent.y / glm::length(geometry::plan_of(tangent)) - lateral * std::tan(roll)}; text += format(" [t %.3f off %.3f dy %.4f]", t, lateral, point.y - cone); } WriteLog("SELFTEST conecheck " + name + ":" + text); return selftest_result::handled; } // a walk along the tracks from the plain one nearest the point as an axle runs: along it (1) or against it (-1), on the path of a switch // it's set to, or the one come onto from its end; each track, the path of a switch and the way, END where no track goes on if (command == "pathwalk") { glm::dvec3 point{0.0}; double direction{1.0}; int steps{8}; words >> point.x >> point.z >> direction >> steps; TTrack *track{nullptr}; double nearest{1e9}; for (auto *candidate : simulation::Paths.sequence()) { if (candidate == nullptr || candidate->m_editorremoved || candidate->eType != tt_Normal || candidate->m_paths.empty()) continue; if (auto const d{geometry::plan_distance(editor_track::point_at(*candidate, editor_track::nearest_parameter(*candidate, point)), point)}; d < nearest) { nearest = d; track = candidate; } } std::string text{"SELFTEST pathwalk:"}; int path{-1}; for (int step = 0; step < steps && track != nullptr; ++step) { text += " " + track->name() + (path >= 0 ? "[" + std::to_string(path) + "]" : std::string{}) + (direction > 0 ? ">" : "<"); auto const side{direction > 0 ? 1 : -1}; auto const switched{track->eType == tt_Switch && path >= 0}; auto const joined{switched ? (side > 0 ? track->SwitchExtension->iNextDirection[path] : track->SwitchExtension->iPrevDirection[path]) : (side > 0 ? track->iNextDirection : track->iPrevDirection)}; auto *next{track->Connected(side, direction, switched ? path : -1)}; if (next == nullptr) { text += " END"; break; } path = next->eType == tt_Switch ? ((joined & 1) ? joined >> 1 : next->SwitchExtension->CurrentIndex) : -1; track = next; } WriteLog(text); return selftest_result::handled; } // the key H as pressed over the view: the selected switch thrown over if (command == "keyh") { auto const handled{track_shortcut(GLFW_KEY_H)}; auto const *track{selected_track()}; auto const switched{track != nullptr && track->eType == tt_Switch && track->SwitchExtension != nullptr}; WriteLog(format("SELFTEST keyh: %s, %s set to %d, blades at %.3f of %.3f", handled ? "thrown" : "not taken", track != nullptr ? track->name().c_str() : "-", switched ? track->SwitchExtension->CurrentIndex : -1, switched ? track->SwitchExtension->fOffset : 0.f, switched ? track->SwitchExtension->fDesiredOffset : 0.f)); return selftest_result::handled; } // where the blades of the switch are on their way over if (command == "blades") { std::string name; words >> name; auto const *track{simulation::Paths.find(name)}; if (track != nullptr && track->eType == tt_Switch && track->SwitchExtension != nullptr) WriteLog(format("SELFTEST blades %s: %.3f of %.3f", name.c_str(), track->SwitchExtension->fOffset, track->SwitchExtension->fDesiredOffset)); return selftest_result::handled; } if (command == "throw") { std::string name; int state{0}; words >> name >> state; auto *track{simulation::Paths.find(name)}; if (track != nullptr && track->eType == tt_Switch) { track->Switch(state, 0.f, 0.f); // the blades go over at once, the editor doesn't run the animations of the switches track->SwitchExtension->fOffset = track->SwitchExtension->fDesiredOffset; track->RaAnimate(); } WriteLog(format("SELFTEST throw %s %d%s", name.c_str(), state, track != nullptr && track->eType == tt_Switch ? "" : ": no such switch")); return selftest_result::handled; } if (command == "switchdrive") { int index{-1}; int side{0}; words >> index >> side; scan_switch_drives(); m_switch.drive = index; m_switch.drive_side = side; WriteLog("SELFTEST switchdrive: " + (index >= 0 && index < static_cast(m_switch.drives.size()) ? m_switch.drives[index].name : std::string{"none"})); return selftest_result::handled; } if (command == "drivechoice") { int index{-1}; int side{0}; words >> index >> side; scan_switch_drives(); m_switch.drive = index; m_switch.drive_side = side; m_switch.status.clear(); auto *track{selected_track()}; if (track != nullptr && track->eType == tt_Switch && false == track->m_editorremoved) apply_switch_drive_choice(*track); WriteLog("SELFTEST drivechoice: " + (track != nullptr ? track->name() : std::string{"no switch"}) + ", " + m_switch.status); return selftest_result::handled; } if (command == "drives") { std::string name; words >> name; scan_switch_drives(); std::string files; for (auto const &standing : standing_templates([](std::string const &File) { return File.find("napedy/") != std::string::npos; })) if (false == standing.values.empty() && standing.values[0] == name) { files += " " + standing.file; for (std::size_t i = 1; i < standing.values.size(); ++i) files += (i == 1 ? " (" : " ") + standing.values[i] + (i + 1 == standing.values.size() ? ")" : ""); } for (scene::instance_handle handle = 1; handle <= scene::Layers.instance_count(); ++handle) if (scene::Layers.tracked(handle) && scene::Layers.instance(handle).file != nullptr && scene::Layers.instance(handle).file->find("napedy") != std::string::npos) files += format(" [%d %s removed %d dead %d]", static_cast(handle), scene::Layers.instance(handle).file->c_str(), scene::Layers.instance(handle).removed ? 1 : 0, scene::Layers.instance(handle).dead ? 1 : 0); WriteLog("SELFTEST drives " + name + ": chosen " + (m_switch.drive >= 0 ? m_switch.drives[m_switch.drive].name : std::string{"none"}) + ", side " + std::to_string(m_switch.drive_side) + ", standing" + files + ", steps " + std::to_string(m_history.size())); return selftest_result::handled; } if (command == "driveflip") { std::string name; words >> name; auto *track{simulation::Paths.find(name)}; auto const done{track != nullptr && flip_switch_drive(*track)}; WriteLog("SELFTEST driveflip " + name + ": " + (done ? "done " : "failed ") + m_switch.status); return selftest_result::handled; } if (command == "driveput" || command == "drivefamily") { std::string name; int family{-1}; words >> name >> family; auto *track{simulation::Paths.find(name)}; auto const done{track != nullptr && (command == "driveput" ? place_switch_drive(*track) : replace_switch_drive(*track, family, false))}; WriteLog("SELFTEST " + command + " " + name + ": " + (done ? "done " : "failed ") + m_switch.status); return selftest_result::handled; } if (command == "drivetilt") { std::string name; words >> name; auto *model{simulation::Instances.find(name)}; auto *track{simulation::Paths.find(name.substr(0, name.find('_')))}; if (model == nullptr || track == nullptr) { WriteLog("SELFTEST drivetilt: no " + name); return selftest_result::handled; } auto const &path{track->m_paths[0]}; auto const transform{glm::dmat3(model->rotation_scale())}; auto const across{transform * glm::dvec3{1.0, 0.0, 0.0}}; auto const forward{transform * glm::dvec3{0.0, 0.0, 1.0}}; auto const direction{glm::normalize(glm::dvec2{forward.x, forward.z})}; auto const lateral{across.x * -direction.y + across.z * direction.x}; auto const cone{-lateral * std::tan(glm::radians(static_cast(path.rolls[0])))}; auto const control{path.points[segment_data::point::control1]}; auto const grade{control.y / std::hypot(control.x, control.z)}; WriteLog(format("SELFTEST drivetilt %s: angles %.3f %.3f %.3f, +x rises %.4f (cone %.4f), +z rises %.4f (grade %.4f), origin %.3f %.3f %.3f, points %.3f", name.c_str(), model->Angles().x, model->Angles().y, model->Angles().z, across.y, cone, forward.y, grade, model->location().x, model->location().y, model->location().z, path.points[segment_data::point::start].y)); return selftest_result::handled; } if (command == "switchfree") { // a switch with no track: pressed at the point, the direction of its main track toward the second one (none at a free end), let // go at the third one, whose side it takes; past its end from a free end it's bent, one: one-sided (Tab), shift: at a free end the // diverging track leads into it std::string label; glm::dvec3 press{0.0}; glm::dvec3 heading{0.0}; glm::dvec3 release{0.0}; words >> label >> press.x >> press.z >> heading.x >> heading.z >> release.x >> release.z; std::replace(label.begin(), label.end(), '_', ' '); auto oneside{false}; auto shift{false}; for (std::string flag; words >> flag;) { oneside |= flag == "one"; shift |= flag == "shift"; } auto &tool{m_switch}; show_track_tab(track_tab::turnout); tool.templates = editor_track::standard_switch_templates(); tool.collected = true; tool.connection = -1; tool.armed = -1; for (int i = 0; i < static_cast(tool.templates.size()); ++i) if (tool.templates[i].label.rfind(label, 0) == 0) { tool.armed = i; break; } // the free end taken where it was pressed, not by the mouse on the screen m_cursor_override = press; start_free_switch(press); m_cursor_override.reset(); if (false == tool.placing) { WriteLog("SELFTEST switchfree: not started, no template " + label + " or no free end near"); return selftest_result::handled; } if (tool.free_end.track == nullptr) tool.free_heading = glm::normalize(geometry::plan_of(heading - tool.point)); tool.mouse = glm::dvec3{release.x, tool.point.y, release.z}; tool.one_sided = oneside; // the free end the cursor is at found where it was let go, not by the mouse on the screen; Shift held as it's let go m_cursor_override = tool.mouse; auto &io{ImGui::GetIO()}; auto const shifted{io.KeyShift}; io.KeyShift = shift; tool.placing = false; finish_switch_placement(); io.KeyShift = shifted; m_cursor_override.reset(); WriteLog("SELFTEST switchfree" + (tool.free_end.track != nullptr ? " from " + tool.free_end.track->name() : std::string{}) + ": " + tool.status); if (auto const *track{selected_track()}; track != nullptr && track->eType == tt_Switch) for (std::size_t i = 0; i < track->m_paths.size(); ++i) { auto const &a{track->m_paths[i].points[segment_data::point::start]}; auto const &b{track->m_paths[i].points[segment_data::point::end]}; // the radius the path turns with from end to end, signed the way it turns geometry::bezier const curve{track->m_paths[i]}; auto const turn{geometry::signed_angle(geometry::plan_of(curve.first(0.0)), geometry::plan_of(curve.first(1.0)))}; WriteLog(format("SELFTEST switchfree path %s/%zu: %.3f %.3f %.3f -> %.3f %.3f %.3f, R %.1f, turning R %.1f", track->name().c_str(), i, a.x, a.y, a.z, b.x, b.y, b.z, static_cast(track->m_paths[i].radius), std::abs(turn) > 1e-6 ? curve.plan_length() / turn : 0.0)); } return selftest_result::handled; } if (command == "switchproblem") { // switchproblem