diff --git a/application/editormode.cpp b/application/editormode.cpp index ff1742edf..acca8d0d2 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -645,10 +645,8 @@ void editor_mode::ground_sources(editor_orthophoto &Layer) gather_ground_triangles(Min, Max, true, 50.0f, Out, true, Heightmap); }); Layer.height_source([](double const X, double const Z, double &Height) { return EditorTerrain.height_at(X, Z, Height); }); - // with the heightmap terrain, a new tile waits while a chunk under it is still to come; where none is nor will be, or the walk of - // the chunks doesn't reach, it lies on the other ground or on the NMT guess as before. A scenery without it as before - Layer.coming_source([](glm::dvec2 const &Min, glm::dvec2 const &Max) { return EditorTerrain.active() && EditorTerrain.ground_coming(Min, Max); }); - // the imagery often comes before the terrain made from the model: it lies where the terrain will be + // a tile doesn't wait for the chunks of the heightmap terrain still to come under it: it lies flat meanwhile, and goes onto them as + // they come. The imagery often comes before the terrain made from the model: it lies where the terrain will be Layer.guess_source([this](double const X, double const Z, double &Height) { if (nmt_ground(X, Z, Height)) return true; @@ -1797,7 +1795,6 @@ bool editor_mode::update() render_open_scenery_popup(); render_shortcuts_window(); render_first_steps(); - render_nmt_prompt(); render_nmt_banner(); render_nmt_buried(); render_empty_scenery_hint(); @@ -1932,6 +1929,15 @@ void editor_mode::render_terrain_loading() ImGui::SameLine(); ImGui::TextDisabled("%s", STR_C("(within the download area, there is none)")); } + // no question asked: the terrain of a new scenery comes as its first track is laid, unless this is off + bool offer{EditorSettings.terrain_offer()}; + if (ImGui::Checkbox(STR_C("The terrain loaded by itself as the first track of a new scenery is laid"), &offer)) + { + EditorSettings.terrain_offer(offer); + EditorSettings.save(); + } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("%s", STR_C("In the background, where the scenery lies on the map; the panel of the laying tells it, with the button to go without it")); } namespace @@ -6482,8 +6488,7 @@ void editor_mode::render_first_steps() } note_first_steps(); follow_tutorial(); - // the question of the terrain of a new scenery isn't drawn over the window: the window waits for the answer - if (false == m_first_steps_open || m_nmt_state.prompt) + if (false == m_first_steps_open) { m_first_steps_shown = 0; return; diff --git a/application/editormode.h b/application/editormode.h index 1c7adf75d..2b2986293 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -548,7 +548,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::vector anchors; // x, z of a place of the tracks, the formation there less the model std::map, std::vector> anchor_cells; // the anchors in squares of the plan bool offered{false}; // the terrain was offered to the scenery begun without it - bool prompt{false}; // the offer is shown + bool prompt{false}; // the line of the offer is shown in the panel of the laying + bool offer_loading{false}; // and the terrain of the offer is being loaded bool moving{false}; // the place being picked again char place[96]{}; // typed: degrees or PUWG 1992 int shown{-1}; // the frame the terrain panel showed how far the work got @@ -685,9 +686,10 @@ class editor_mode : public application_mode, private editor_track::observer, pri bool nmt_busy() const; // the terrain made so far stays, what's waiting is dropped, the grade lines not fitted yet are left void nmt_stop(); - // a scenery begun from nothing, with no tracks nor terrain, is asked as the first track is laid whether it wants the terrain + // a scenery begun from nothing, with no tracks nor terrain, has the terrain loaded in the background as the first track is laid, + // where it lies on the map, with no question in the way: a line of the panel of the laying tells it, with the button to go without void nmt_offer(); - void render_nmt_prompt(); + void nmt_offer_start(); // the place picked in the terrain window: the terrain model and the orthophoto take it void nmt_place_scenery(glm::dvec2 const &Point); void nmt_accept_offer(); @@ -930,6 +932,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri // the tiles of the photo which failed: marked red in the view, counted in the status bar with the button trying them again void draw_orthophoto_failures() const; void render_orthophoto_status(); + // the terrain loaded in the background as the first track of a new scenery is laid, told in a line of the panel of the laying with + // the button to go without it + void render_nmt_offer_line(); int m_orthophoto_frame{-10}; bool orthophoto_settings_open() const; // view menu: the top view, the lanes of the roads, the structure gauge, the environment diff --git a/application/editormodelay.cpp b/application/editormodelay.cpp index 9b4935ab2..f66a49468 100644 --- a/application/editormodelay.cpp +++ b/application/editormodelay.cpp @@ -2601,6 +2601,7 @@ void editor_mode::render_lay_ui() auto &tool{m_lay}; auto const state{lay_panel_state()}; render_lay_step(state); + render_nmt_offer_line(); if (state == lay_state::clicking || state == lay_state::extending) { render_lay_quality(); diff --git a/application/editormodenmt.cpp b/application/editormodenmt.cpp index 2f0b6cb1d..ac2136a3d 100644 --- a/application/editormodenmt.cpp +++ b/application/editormodenmt.cpp @@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/. #include "editor/editorFormat.hpp" #include "editor/editorGeometry.hpp" #include "editor/editorKilometrage.hpp" +#include "editor/editorPhotoRules.hpp" #include "editor/editorSettings.hpp" #include "model/AnimModel.h" #include "utilities/Globals.h" @@ -68,84 +69,17 @@ bool rail(TTrack const &Track) return geometry::plan_distance(path.points[segment_data::point::start], path.points[segment_data::point::end]) <= broken_path; } -// a choice of the new scenery as a card: a sketch of the ground a track lies on, the name and what it means; true when clicked. -// the real terrain: hills under an aerial photo, the track along them; none: the flat plane at 0 drawn as a grid -bool ground_card(char const *Id, char const *Title, char const *Text, bool const Hills, bool const Enabled, float const Width) +// why the model wasn't fetched: a failure of the connection or of the service told in plain words, as the photo tells its own, as +// a sentence of its own (the code of WinHTTP is in the log); the messages of the model itself as they are +std::string nmt_error_text(std::string const &Error) { - auto const font{ImGui::GetFontSize()}; - auto const pad{std::round(font * 0.6f)}; - auto const sketch{std::round(font * 4.0f)}; - auto const wrap{Width - 2.0f * pad}; - auto const title{ImGui::CalcTextSize(Title, nullptr, false, wrap)}; - auto const text{ImGui::CalcTextSize(Text, nullptr, false, wrap)}; - auto const height{pad + sketch + pad * 0.6f + title.y + pad * 0.3f + text.y + pad}; - auto const top{ImGui::GetCursorScreenPos()}; - ImGui::BeginDisabled(false == Enabled); - auto const clicked{ImGui::InvisibleButton(Id, ImVec2(Width, height))}; - ImGui::EndDisabled(); - auto const hovered{Enabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)}; - auto *list{ImGui::GetWindowDrawList()}; - ImVec2 const bottom{top.x + Width, top.y + height}; - auto const rounding{std::round(font * 0.4f)}; - auto const accent{family_colour(0)}; - list->AddRectFilled(top, bottom, ImGui::GetColorU32(hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), rounding); - list->AddRect(top, bottom, hovered ? accent : ImGui::GetColorU32(ImGuiCol_Border), rounding, 0, hovered ? 2.0f : 1.0f); - auto const alpha{Enabled ? 1.0f : 0.35f}; - auto const tint = [&](ImU32 const Colour) { return (Colour & ~IM_COL32_A_MASK) | (static_cast(((Colour >> IM_COL32_A_SHIFT) & 0xFF) * alpha) << IM_COL32_A_SHIFT); }; - ImVec2 const low{top.x + pad, top.y + pad}; - ImVec2 const high{top.x + Width - pad, top.y + pad + sketch}; - list->AddRectFilled(low, high, tint(IM_COL32(20, 26, 34, 255)), rounding * 0.6f); - list->PushClipRect(low, high, true); - int constexpr steps{48}; - auto const x_of = [&](float const Share) { return low.x + (high.x - low.x) * Share; }; - if (Hills) - { - auto const ground = [](float const Share) { return 0.45f + 0.18f * std::sin(Share * 7.0f + 0.4f) + 0.08f * std::sin(Share * 17.0f); }; - std::vector line; - for (int i = 0; i <= steps; ++i) - { - auto const share{static_cast(i) / steps}; - line.emplace_back(x_of(share), low.y + (high.y - low.y) * ground(share)); - } - // the strips under the line drawn without the soft edges, else seams show between them - auto const flags{list->Flags}; - list->Flags &= ~ImDrawListFlags_AntiAliasedFill; - for (int i = 0; i < steps; ++i) - list->AddQuadFilled(line[i], line[i + 1], ImVec2(line[i + 1].x, high.y), ImVec2(line[i].x, high.y), tint(IM_COL32(70, 110, 55, 200))); - list->Flags = flags; - list->AddPolyline(line.data(), static_cast(line.size()), tint(IM_COL32(150, 200, 110, 255)), 0, 1.5f); - // the track goes along the ground, a little above it on embankments, below it in cuttings - std::vector track; - for (int i = 0; i <= steps; ++i) - { - auto const share{static_cast(i) / steps}; - auto const smooth{0.45f + 0.09f * std::sin(share * 7.0f + 0.4f)}; - track.emplace_back(x_of(share), low.y + (high.y - low.y) * smooth - 2.0f); - } - list->AddPolyline(track.data(), static_cast(track.size()), tint(IM_COL32(235, 235, 235, 255)), 0, 2.5f); - } - else - { - auto const horizon{low.y + (high.y - low.y) * 0.35f}; - auto const grid{tint(IM_COL32(120, 130, 150, 120))}; - for (int i = 0; i <= 4; ++i) - { - auto const t{static_cast(i) / 4.0f}; - auto const y{horizon + (high.y - horizon) * t * t}; - list->AddLine(ImVec2(low.x, y), ImVec2(high.x, y), grid); - } - auto const middle{(low.x + high.x) * 0.5f}; - for (int i = -6; i <= 6; ++i) - list->AddLine(ImVec2(middle + i * (high.x - low.x) * 0.06f, horizon), ImVec2(middle + i * (high.x - low.x) * 0.22f, high.y), grid); - auto const level{horizon + (high.y - horizon) * 0.45f}; - list->AddLine(ImVec2(low.x, level), ImVec2(high.x, level), tint(IM_COL32(235, 235, 235, 255)), 2.5f); - } - list->PopClipRect(); - auto y{high.y + pad * 0.6f}; - list->AddText(nullptr, 0.0f, ImVec2(low.x, y), tint(ImGui::GetColorU32(ImGuiCol_Text)), Title, nullptr, wrap); - y += title.y + pad * 0.3f; - list->AddText(nullptr, 0.0f, ImVec2(low.x, y), tint(ImGui::GetColorU32(ImGuiCol_TextDisabled)), Text, nullptr, wrap); - return clicked && Enabled; + auto const reason{photo_rules::connection_reason(Error)}; + if (reason.empty()) + return STR(Error); + auto text{STR(reason)}; + if (false == text.empty() && text.front() >= 'a' && text.front() <= 'z') + text.front() = static_cast(text.front() - 'a' + 'A'); + return text; } // what a way of putting the tracks and the terrain together does, drawn along a track: onto, the track goes along the hills of @@ -2175,7 +2109,7 @@ void editor_mode::render_nmt_banner() bool again{false}; if (auto const error{m_nmt.error(&again)}; false == error.empty()) { - ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.3f, 1.0f), "%s", STR(error).c_str()); + ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.3f, 1.0f), "%s", nmt_error_text(error).c_str()); if (again) { ImGui::SameLine(); @@ -2549,7 +2483,7 @@ void editor_mode::render_nmt_ui() if (auto const error{m_nmt.error(&again)}; false == error.empty()) { ImGui::PushTextWrapPos(0.0f); - ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.3f, 1.0f), "%s", STR(error).c_str()); + ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.3f, 1.0f), "%s", nmt_error_text(error).c_str()); ImGui::PopTextWrapPos(); if (again && ImGui::Button(STR_C("Try again"))) m_nmt.retry(); @@ -2585,8 +2519,20 @@ void editor_mode::nmt_offer() state.offered = true; if (m_streamer.resident() > 0 || std::any_of(simulation::Paths.sequence().begin(), simulation::Paths.sequence().end(), [](TTrack const *Track) { return Track != nullptr && rail(*Track); })) return; + nmt_offer_start(); +} + +void editor_mode::nmt_offer_start() +{ + auto &state{m_nmt_state}; nmt_locate(); + // no question in the way of the first track: where the scenery lies on the map the terrain loads in the background, and the photo + // lies flat meanwhile; the line in the panel of the laying tells it, with the button to go without state.prompt = true; + state.offer_loading = false; + if (m_nmt.placed()) + nmt_accept_offer(); + WriteLog(format("Editor: NMT - the terrain of the new scenery %s", state.offer_loading ? "loaded in the background" : "not loaded, the scenery isn't placed on the map"), logtype::generic); } void editor_mode::nmt_accept_offer() @@ -2597,9 +2543,9 @@ void editor_mode::nmt_accept_offer() // no tracks to fit to: the heights of the model as they are state.offset = 0.0; nmt_make(nmt_keys_around()); - state.prompt = false; - // the terrain goes on under the tracks as they're laid and around the camera, as the answer says, also after the other answer was - // given for a scenery before; the model of the download area is put into the cache again if that answer stopped it + state.offer_loading = true; + // the terrain goes on under the tracks as they're laid and around the camera, also after the scenery before went without it; the + // model of the download area is put into the cache again if that stopped it state.grow = true; EditorSettings.terrain_while_laying(true); EditorSettings.terrain_model().area = true; @@ -2612,6 +2558,7 @@ void editor_mode::nmt_decline_offer() { auto &state{m_nmt_state}; state.prompt = false; + state.offer_loading = false; // nothing of the model loaded any more: not under the tracks as they're laid, as the checkbox of the layers turns it off, nor around // the camera within the download area, as the checkbox of the terrain panel does, nor the squares of the download area into the // cache. Kept on, they went on being loaded, and where there's no network their requests failed in the log @@ -2620,60 +2567,45 @@ void editor_mode::nmt_decline_offer() EditorSettings.terrain_model().area = false; EditorSettings.save(); m_nmt.prefetch({}); - // nor the squares asked for meanwhile, as the aerial photos asked for them to lie on + // nor the squares asked for meanwhile, as the aerial photos asked for them to lie on, nor the chunks waiting for them m_nmt.cancel(); + state.pending.clear(); + state.status = STR("Without terrain: the tracks lie on the flat plane; the terrain can be loaded later in Terrain (F5)"); } -void editor_mode::render_nmt_prompt() +void editor_mode::render_nmt_offer_line() { auto &state{m_nmt_state}; - char const *const title{STR_C("Terrain for the new scenery###nmtoffer")}; if (false == state.prompt) + return; + if (state.offer_loading && false == nmt_busy() && state.pending.empty()) { - // answered by the self-test, not by a card of its own: the question is closed, or it would hold the input as a modal - if (ImGui::IsPopupOpen(title) && ImGui::BeginPopupModal(title, nullptr, ImGuiWindowFlags_NoResize)) - { - ImGui::CloseCurrentPopup(); - ImGui::EndPopup(); - } + // in: the line goes, the terrain is there to be seen + state.prompt = false; + state.offer_loading = false; return; } - if (false == ImGui::IsPopupOpen(title)) - ImGui::OpenPopup(title); - // in the middle of the view, not of the screen with the docks; the window of the lesson waits meanwhile, not to lie under it - ImGui::SetNextWindowPos(ImVec2((editor_ui::view_min().x + editor_ui::view_max().x) * 0.5f, (editor_ui::view_min().y + editor_ui::view_max().y) * 0.5f), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); - ImGui::SetNextWindowSize(ImVec2(520.0f * Global.ui_scale, 0.0f)); - if (false == ImGui::BeginPopupModal(title, nullptr, ImGuiWindowFlags_NoResize)) - return; - ImGui::TextWrapped("%s", STR_C("The scenery has no terrain yet. Load the terrain model and the aerial photos around here? The tracks laid then go along the real ground.")); - bool const placed{m_nmt.placed()}; - if (false == placed) - render_nmt_place(false, false); - auto const known{placed || m_nmt_map.picked()}; - ImGui::Spacing(); - auto const gap{std::round(ImGui::GetFontSize() * 0.6f)}; - auto const width{std::floor((ImGui::GetContentRegionAvail().x - gap) * 0.5f)}; - if (ground_card("##terrain", STR_C("Load the terrain"), STR_C("The terrain model and the aerial photos of geoportal.gov.pl around here; the tracks go along the real ground"), true, known, width)) + ImGui::AlignTextToFramePadding(); + if (state.offer_loading) { - nmt_accept_offer(); - ImGui::CloseCurrentPopup(); + if (auto const error{m_nmt.error()}; false == error.empty()) + ImGui::TextColored(ImVec4(1.0f, 0.6f, 0.3f, 1.0f), "%s %s", STR_C("Terrain:"), nmt_error_text(error).c_str()); + else + ImGui::TextDisabled("%s", STR_C("Terrain: loading...")); + item_tooltip("The terrain model of geoportal.gov.pl around here, in the background: the tracks laid meanwhile go onto it once it's in, the photo lies flat till then"); } - if (false == known) - item_tooltip("Pick where the scenery lies first"); - ImGui::SameLine(0.0f, gap); - if (ground_card("##flat", STR_C("Without terrain"), STR_C("The tracks lie on the flat plane at the height 0; the terrain can be loaded later in Terrain (F5)"), false, true, width)) + else { + ImGui::TextDisabled("%s", STR_C("Terrain: the scenery isn't placed on the map")); + ImGui::SameLine(); + if (ImGui::SmallButton(STR_C("Place it..."))) + choose_work_area(work_area::terrain); + item_tooltip("In Terrain (F5): the middle of the scenery clicked on the map, then its terrain and photos can be loaded"); + } + ImGui::SameLine(); + if (ImGui::SmallButton(STR_C("Without terrain"))) nmt_decline_offer(); - ImGui::CloseCurrentPopup(); - } - ImGui::Spacing(); - bool ask{EditorSettings.terrain_offer()}; - if (ImGui::Checkbox(STR_C("Ask with every new scenery"), &ask)) - { - EditorSettings.terrain_offer(ask); - EditorSettings.save(); - } - ImGui::EndPopup(); + item_tooltip("The tracks lie on the flat plane at the height 0; the terrain can be loaded later in Terrain (F5)"); } std::size_t editor_mode::nmt_join_ends() diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index ead90fb56..beac5837d 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -194,7 +194,8 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // turntables the height of each turntable and of the model in its pit, and the heights of the tracks running up // to it out along their lines from the rim, against the model there // nmtstate logs how far the tracks going onto the terrain model are -// nmtquestion the question of the terrain of a new scenery opened, or answered without terrain as its card does; +// nmtquestion the terrain of a new scenery offered as the first L offers it (loaded in the background where the +// scenery is placed, the line in the panel of the laying), or gone without as its button does; // restore: the settings of the terrain made by itself put back as they were before that answer // gradelines the grade line each track shares written to the file, for a map of them // fitreport to the file: the tracks off the terrain model, the switches off their plane, the rails on common timbers apart in height diff --git a/application/editormodeselftestterrain.cpp b/application/editormodeselftestterrain.cpp index cdacd84e8..354f98a4e 100644 --- a/application/editormodeselftestterrain.cpp +++ b/application/editormodeselftestterrain.cpp @@ -518,8 +518,10 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co std::string answer; words >> answer; auto &model{EditorSettings.terrain_model()}; + // as the first L in a new scenery: the line of the offer in the panel of the laying, the terrain loaded in the background where + // the scenery is placed, no question asked if (answer == "open") - m_nmt_state.prompt = true; + nmt_offer_start(); else if (answer == "flat") { m_selftest.terrain_kept = std::pair{m_nmt_state.grow, model.area}; @@ -532,7 +534,7 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co EditorSettings.terrain_while_laying(m_nmt_state.grow); EditorSettings.save(); } - WriteLog(format("SELFTEST nmtquestion %s: prompt %d, terrain while laying %d, around the camera %d", answer.c_str(), m_nmt_state.prompt ? 1 : 0, m_nmt_state.grow ? 1 : 0, model.area ? 1 : 0)); + WriteLog(format("SELFTEST nmtquestion %s: prompt %d, loading %d, terrain while laying %d, around the camera %d", answer.c_str(), m_nmt_state.prompt ? 1 : 0, m_nmt_state.offer_loading ? 1 : 0, m_nmt_state.grow ? 1 : 0, model.area ? 1 : 0)); return selftest_result::handled; } if (command == "nmtgrow") diff --git a/editor/editorOrthophoto.cpp b/editor/editorOrthophoto.cpp index 35caa78cb..ac6b43383 100644 --- a/editor/editorOrthophoto.cpp +++ b/editor/editorOrthophoto.cpp @@ -898,15 +898,6 @@ void editor_orthophoto::ground_arrived() } } -bool editor_orthophoto::waits_for_ground(tile_key const &Key) const -{ - // a tile laid out already stays, sampled again when its ground comes (ground_came) - if (!m_coming || m_tiles.contains(Key)) - return false; - glm::dvec2 const corner = tile_corner(Key); - return m_coming(corner - glm::dvec2{tile_size}, corner); -} - bool editor_orthophoto::ground_came(tile_key const &Key, tile const &Tile) const { glm::dvec2 const corner = tile_corner(Key); @@ -1252,6 +1243,7 @@ void editor_orthophoto::sample_ground(tile_key const &Key, tile &Tile) { Tile.grounded = true; Tile.guessed = false; + Tile.flat.reset(); Tile.scene_dirty = true; Tile.heights.clear(); Tile.surface.clear(); @@ -1365,11 +1357,15 @@ void editor_orthophoto::sample_ground(tile_key const &Key, tile &Tile) heights[static_cast(j) * samples + i] = y; } } - // nothing to go by yet: the tile stays flat at the layer height, and is sampled again when something comes + // nothing to go by yet: the tile lies flat at the height of the ground found last, or of the layer before any was, and is + // sampled again when something comes Tile.guessed = true; missing = std::count(heights.begin(), heights.end(), no_height); if (missing == heights.size()) + { + Tile.flat = m_known_height; return; + } } while (missing > 0) { @@ -1405,6 +1401,7 @@ void editor_orthophoto::sample_ground(tile_key const &Key, tile &Tile) auto const range = std::minmax_element(Tile.heights.begin(), Tile.heights.end()); Tile.height_min = *range.first; Tile.height_max = *range.second; + m_known_height = 0.5f * (Tile.height_min + Tile.height_max); } void editor_orthophoto::remove_shape(tile &Tile) @@ -1470,8 +1467,9 @@ void editor_orthophoto::build_shape(tile_key const &Key, tile &Tile) } else { - // flat quad at the layer height, triangles facing up like the draped surface - double const y = m_config.height; + // flat quad at the layer height, or at the height of the ground found last where there's none yet under it, triangles facing + // up like the draped surface + double const y = (m_config.drape && Tile.flat.has_value()) ? *Tile.flat : m_config.height; glm::dvec3 const nw(corner.x, y, corner.y), ne(corner.x - tile_size, y, corner.y); glm::dvec3 const sw(corner.x, y, corner.y - tile_size), se(corner.x - tile_size, y, corner.y - tile_size); for (auto const &point : {nw, sw, ne, se, ne, sw}) @@ -1690,8 +1688,7 @@ void editor_orthophoto::update(glm::dvec3 const &Camera) } continue; } - if (waits_for_ground(key)) - continue; + // laid out at once, whether its ground has come or not: it lies flat till it does, then goes onto it tile &t = m_tiles[key]; if (!in_service_area(key.first, key.second)) t.empty = true; @@ -1915,7 +1912,8 @@ void editor_orthophoto::draw(glm::mat4 const &ViewProjection, glm::dvec3 const & continue; bool const draped = m_config.drape && !t.heights.empty(); - double const flat = m_config.height; + // with no ground under it yet, laid onto the ground, at the height of the ground found last + double const flat = (m_config.drape && t.flat.has_value()) ? *t.flat : m_config.height; double const lift = m_config.lift; double const ylo = draped ? t.height_min + lift : flat; double const yhi = draped ? t.height_max + lift : flat; diff --git a/editor/editorOrthophoto.hpp b/editor/editorOrthophoto.hpp index b6b1f2c8b..2a138d77a 100644 --- a/editor/editorOrthophoto.hpp +++ b/editor/editorOrthophoto.hpp @@ -117,12 +117,10 @@ class editor_orthophoto void ground_source(ground_query Query) { m_ground = std::move(Query); } void height_source(height_query Query) { m_height = std::move(Query); } // the heights the ground will have where there's none yet, as of the terrain model on its way: a tile laid out before its - // ground comes lies there, or level with the tiles beside, rather than at the height of the layer far below or above + // ground comes lies there, or level with the tiles beside, rather than at the height of the layer far below or above. A tile + // doesn't wait for its ground: with nothing to go by it lies flat at the height of the ground last found, and goes onto the + // ground once it comes void guess_source(height_query Query) { m_guess = std::move(Query); } - // true while the ground under an XZ rectangle (Min/Max are x,z) is still to come. A new tile there waits for it, rather than - // being laid out at the height of the layer; elsewhere it lies on whatever ground there is, or on the guess, as without it - using coming_query = std::function; - void coming_source(coming_query Query) { m_coming = std::move(Query); } // the 4K photos asked for around the camera by themselves, the view zoomed in (see photo_rules::hires_wanted), besides the setting // for them; the download area is put into the cache in the products of the setting alone void zoom_hires(bool const Hires) { m_zoom_hires = Hires; } @@ -251,6 +249,7 @@ class editor_orthophoto float height_max{0.0f}; std::vector surface; // upward facing ground triangles clipped to the tile (3 vertices each) bool guessed{false}; // no ground under it when sampled: the heights guessed, from the terrain model or the tiles beside + std::optional flat; // nothing at all to go by when sampled: flat at the height of the ground found last // the points of the grid of the heights the ground didn't answer when sampled (rows north->south, as heights): filled from // the points beside or guessed, and sampled again once the ground comes under one of them std::vector unanswered; @@ -279,8 +278,6 @@ class editor_orthophoto void sample_ground(tile_key const &Key, tile &Tile); // the ground has come under a point of the tile which had none when it was sampled bool ground_came(tile_key const &Key, tile const &Tile) const; - // a new tile isn't asked for yet: the ground under it is still to come - bool waits_for_ground(tile_key const &Key) const; // the height of the ground sampled under a tile beside Own at the point, the tiles with guessed heights left out bool sampled_height(tile_key const &Own, double const X, double const Z, float &Height) const; void build_shape(tile_key const &Key, tile &Tile); @@ -300,8 +297,9 @@ class editor_orthophoto ground_query m_ground; height_query m_height; height_query m_guess; - coming_query m_coming; bool m_zoom_hires{false}; + // the height of the ground found last under a tile: a tile with no ground under it yet lies there + std::optional m_known_height; scene::basic_region *m_region{nullptr}; // region the scene geometry was put into std::multimap m_free_chunks; // geometry chunks by capacity, reused between tiles // the scene opacity is baked into the textures, which means reading the tiles again; applied once the value settles diff --git a/editor/editorPhotoRules.cpp b/editor/editorPhotoRules.cpp index cff68a271..9837fc8ce 100644 --- a/editor/editorPhotoRules.cpp +++ b/editor/editorPhotoRules.cpp @@ -186,23 +186,34 @@ bool hires_wanted(double const MetresPerPixel, bool const Now) return MetresPerPixel <= (Now ? hires_until : hires_from); } -std::string failure_reason(std::string const &Error) +std::string connection_reason(std::string const &Error) { auto const has = [&](char const *Text) { return Error.find(Text) != std::string::npos; }; - if (has("12007") || has("resolve") || has("12005")) + // the errors of WinHTTP (12xxx) and of curl, and the status of HTTP + if (has("12007") || has("12005") || has("resolve")) return "no connection to the internet: the name of the server isn't found"; if (has("12002") || has("imed out") || has("Timeout")) return "the server didn't answer in time"; - if (has("12029") || has("12030") || has("12031") || has("12152") || has("onnect")) + if (has("12029") || has("12030") || has("12031") || has("12152") || has("12017") || has("onnect")) return "the server can't be reached"; - if (has("12175") || has("12157") || has("12045") || has("SSL") || has("certificate")) + if (has("12175") || has("12157") || has("12045") || has("12037") || has("12038") || has("12044") || has("SSL") || has("certificate")) return "the secure connection to the server failed"; if (has("HTTP 5")) return "the server is busy or out of order"; - if (has("HTTP 404")) - return "the server has no photo of the place"; if (has("HTTP 4")) return "the server refused the request"; + if (has("WinHTTP")) + return "the download failed"; + return {}; +} + +std::string failure_reason(std::string const &Error) +{ + auto const has = [&](char const *Text) { return Error.find(Text) != std::string::npos; }; + if (has("HTTP 404")) + return "the server has no photo of the place"; + if (auto const connection{connection_reason(Error)}; false == connection.empty()) + return connection; if (has("unexpected response")) return "the server sent an error in place of the photo"; if (has("decoding")) diff --git a/editor/editorPhotoRules.hpp b/editor/editorPhotoRules.hpp index 7a47337bb..b2f3f05ca 100644 --- a/editor/editorPhotoRules.hpp +++ b/editor/editorPhotoRules.hpp @@ -65,6 +65,9 @@ bool hires_wanted(double MetresPerPixel, bool Now); // what a download that failed is told as, in plain words (an English message to be translated); the raw error is in the log std::string failure_reason(std::string const &Error); +// of these, the failures of the connection and of the server alone, whatever was downloaded (the terrain model too); empty: the +// error isn't one of them +std::string connection_reason(std::string const &Error); // the download area grown to where the camera or the laying goes: the tiles of the polygon (PUWG easting, northing) and the square of // Reach tiles around the point, as one outline along the grid of the tiles, its holes filled. Only when the point is within Margin diff --git a/lang/editor_pl.po b/lang/editor_pl.po index c5c75b459..351325561 100644 --- a/lang/editor_pl.po +++ b/lang/editor_pl.po @@ -6060,24 +6060,12 @@ msgstr ". To za dużo: położenie scenerii jest pewnie złe, sprawdź ortofotom msgid "There's terrain there already" msgstr "Tam już jest teren" -msgid "Terrain for the new scenery###nmtoffer" -msgstr "Teren dla nowej scenerii###nmtoffer" - -msgid "The scenery has no terrain yet. Load the terrain model and the aerial photos around here? The tracks laid then go along the real ground." -msgstr "Sceneria nie ma jeszcze terenu. Wczytać teren z map (NMT) i ortofotomapę wokół tego miejsca? Tory układane potem pójdą po nim" - msgid "Where is it? PUWG 1992 of this point, X to the north and Y to the east, as geoportal.gov.pl gives them:" msgstr "Gdzie to jest? Współrzędne PUWG 1992 tego miejsca, X na północ i Y na wschód, jak podaje geoportal.gov.pl:" -msgid "Load the terrain" -msgstr "Wczytaj teren z map" - msgid "Without terrain" msgstr "Bez terenu" -msgid "Ask with every new scenery" -msgstr "Pytaj przy każdej nowej scenerii" - msgid "Fetching the terrain model under the tracks: %zu squares left" msgstr "Pobieranie NMT pod torami: zostało %zu kwadratów" @@ -7290,9 +7278,6 @@ msgstr "pochylenie" msgid "cant" msgstr "przechyłka" -msgid "The terrain model and the aerial photos of geoportal.gov.pl around here; the tracks go along the real ground" -msgstr "Teren z map (NMT) i ortofotomapa z geoportal.gov.pl wokół tego miejsca; tory pójdą po prawdziwym terenie" - msgid "Type where the scenery lies first" msgstr "Najpierw wpisz, gdzie leży sceneria" @@ -10077,9 +10062,6 @@ msgstr "Kwadrat 2 km wokół kamery" msgid "The squares of the model the service didn't give are asked for again; it happens by itself every 15 s too" msgstr "Ponownie prosi serwis o brakujące fragmenty NMT; samo dzieje się to też co 15 s" -msgid "Pick where the scenery lies first" -msgstr "Najpierw wskaż, gdzie leży sceneria" - msgid "The scenery has no terrain yet" msgstr "Sceneria nie ma jeszcze terenu" @@ -15437,3 +15419,30 @@ msgstr "pobieranie się nie udało" msgid "Retry##photos" msgstr "Ponów##photos" + +msgid "The terrain loaded by itself as the first track of a new scenery is laid" +msgstr "Teren wczytywany sam przy układaniu pierwszego toru nowej scenerii" + +msgid "In the background, where the scenery lies on the map; the panel of the laying tells it, with the button to go without it" +msgstr "W tle, tam gdzie sceneria leży na mapie; mówi o tym panel układania, z przyciskiem, by obejść się bez terenu" + +msgid "Without terrain: the tracks lie on the flat plane; the terrain can be loaded later in Terrain (F5)" +msgstr "Bez terenu: tory leżą na płaszczyźnie; teren możesz wczytać później w dziale Teren (F5)" + +msgid "Terrain:" +msgstr "Teren:" + +msgid "Terrain: loading..." +msgstr "Teren: wczytuję…" + +msgid "The terrain model of geoportal.gov.pl around here, in the background: the tracks laid meanwhile go onto it once it's in, the photo lies flat till then" +msgstr "Teren z map (NMT) z geoportal.gov.pl wokół tego miejsca, w tle: tory ułożone w tym czasie trafią na niego, gdy dojdzie, a zdjęcie do tego czasu leży płasko" + +msgid "Terrain: the scenery isn't placed on the map" +msgstr "Teren: sceneria nie leży na mapie" + +msgid "Place it..." +msgstr "Wskaż miejsce…" + +msgid "In Terrain (F5): the middle of the scenery clicked on the map, then its terrain and photos can be loaded" +msgstr "W dziale Teren (F5): kliknij środek scenerii na mapie, potem możesz wczytać jej teren i zdjęcia" diff --git a/tests/unit/test_photo_rules.cpp b/tests/unit/test_photo_rules.cpp index f577a6f7c..232e7a008 100644 --- a/tests/unit/test_photo_rules.cpp +++ b/tests/unit/test_photo_rules.cpp @@ -126,6 +126,17 @@ TEST_CASE("photo: what a download that failed is told as") { CHECK(photo_rules::failure_reason("something else") == "the download failed"); } +TEST_CASE("photo: the failures of the connection told alike for the terrain model, its own messages left as they are") { + CHECK(photo_rules::connection_reason("WinHTTP error 12002") == "the server didn't answer in time"); + CHECK(photo_rules::connection_reason("WinHTTP error 12007") == "no connection to the internet: the name of the server isn't found"); + CHECK(photo_rules::connection_reason("WinHTTP error 12030") == "the server can't be reached"); + CHECK(photo_rules::connection_reason("WinHTTP error 12175") == "the secure connection to the server failed"); + CHECK(photo_rules::connection_reason("HTTP 503") == "the server is busy or out of order"); + CHECK(photo_rules::connection_reason("HTTP 404") == "the server refused the request"); + CHECK(photo_rules::connection_reason("WinHTTP error 12345") == "the download failed"); + CHECK(photo_rules::connection_reason("The service gave no terrain model").empty()); +} + TEST_CASE("photo: the download area grows by the square around the camera at its edge") { // 4 x 4 tiles, the camera in the tile at the east edge auto const area{block(0, 3)};