From 9b431e8bf34919eb61401cdaf3748afe2b91dc9d Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:15:06 +0100 Subject: [PATCH] feat(editor): the aerial photo under the track tool with no fiddling: kept per scenery, its area grown, failures told, 4K when zoomed in, no terrain question (#501) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(editor): track edits keep the joints, the norms, the records and the saved speed together - The cant typed in the inspector goes on into the track joined at that end, as the gizmo and the joints tool do it; the neighbours go into the same undo step. The joint stepped before. - A track laid on from a canted joint takes the cant off along the ramp the norms ask for at the speed (`alignment::cant_ramp_length`), not at a fixed 1.5 mm a metre whatever the speed and the norms: 120 mm at 100 km/h over 120 m, not 80 m. - Deleting a track of the line under the route tool keeps the laying norms. They went back to the defaults, and every later lay, extend and join used those. - The gauge is a paste group of its own, off by default: pasting how a track rides or sounds no longer changes its gauge. - The speed of a turntable set in the editor is the one saved. The editor changed the speed the turntable runs at, while the file keeps the limit it was loaded with. - Deleting a set of tracks does what Del does with each: a double switch, a slip and a crossover go whole, the records of the switches go with them, and the model and events of a turntable too. The records stayed behind and on saving were given to another switch, which then showed a wrong type. - Deleting a switch of a crossover takes the crossover out whole, as the connection tools do: the outer track of a crossover on a curve comes down by its lift and the record of the connection goes. Alone, the switch left the outer track up for good, and the connection to the next switch given its name. A switch bent out of the shape of its record is found by its name. Tests: a unit test of the norm ramp. The other changes are in the editor's UI, which the unit tests don't reach. * test(editor): self-test scripts that fail, a runner, and a case for each fix of the track editing The editor's self-test scripts only logged: nothing made a run fail. Now: - `expect` commands check the state and log `SELFTEST PASS` or `SELFTEST FAIL ... got X, expected Y`: the cant at a track end, the joint at an end (gap, angle, cant step), the records of a switch and the connections naming it, speed, gauge, a track present or removed, the laying norms' gauge, heights and lifts against a mark, whether a track is in the line under the route tool, and the includes of a turntable. A command no group takes counts as a failure, so a mistyped one can't make the checks after it pass. - At `quit` the result is logged, and a script whose expectations failed ends the editor with exit code 2 (a failed start stays 1; the simulator's test mode is unchanged). - The commit of the inspector's cant field is `track_cant_commit`, which the inspector and the `trackcant` command both call; `routegauge` sets the laying norms as the route tool does, and `tracksetdelete` deletes a set of tracks by name. - `tests/editor/run.py` runs each script of `tests/editor/cases` on a copy of the fixture scenery in the game folder, with a wall-time limit and a memory cap, reads the exit code and the `SELFTEST` lines, and deletes the copy. A `#> reopen` line restarts the editor on the saved scenery. See `tests/editor/README.md`. - One case per fix of the track editing quick fixes (inspector cant, norms after deleting, the gauge paste group, turntable speed saved, deleting a set, a set with a double switch, a slip and a crossover, deleting a switch of a crossover, a bent switch). All pass; with the fixes reverted all fail. * feat(editor): the track tool panels keep their fields, results and buttons within the panel - The card of the tool: after a long gesture the action goes under it, at its indent, when what is left of the row is narrower than 8 font sizes or the longest word of the action. It was squeezed into a sliver and broken in the middle of its words. - A click on the title row of the card folds it to that row (icon, name, family, key, and a small triangle marker) and opens it again. One flag for all the tools, kept with the editor settings (`track_card_folded` in eu07_editor.ini), open by default: the card took 250-300 px at the top of every tool and repeats the hint bar of the view. - The grade labels of the vertical profile, on the graph and in the view, write the per mille as the panel does (the translated "per mille", the per mille sign in Polish), not "o/oo". - The track analysis window: the thresholds of the speed check and of the joints keep to their widest name and a field of 10 font sizes where the window is wider than that, as docked across the bottom (`begin_fields_fitted`). The results are tables with each column as wide as what is in it: the speed check with its column names kept at the top as the list scrolls, the joints with the kind, the value and the two tracks next to each other. A click on a row shows it as before. - `same_line_if_fits` puts the next button beside the one before only when it fits in what is left of the line, at the start of the next line otherwise. Used where the route design puts buttons side by side, for "Forget the design" in the profile panel, which was cut off at the edge, and for the buttons of a switch in the inspector. - The laying options: the speed, the curve radius and the longest path are fields with the name on the left in two columns (`begin_fields`/`field_row`), as in the inspector, the route and the profile, the chips of the quick values under them. The segmented choices give the short names less of the room when a long one doesn't fit in its even share, and go on in a second bar when they don't fit side by side: "Through the clicked points" overflowed its third of the bar. * fix(editor): a switch laid gets the speed of its diverging track, one breaking a hard rule of ST-T1-A6 isn't laid - Every switch laid writes the speed of its diverging track (`velocity`): the switch tool on a straight, into a curve, from a free end and linked, a double switch, the switches of a slip, a switch given another template of the catalogue, and a switch moved along the curve it's bent into. A switch of the catalogue had no limit before, one copied from a switch of the scenery kept that one's, one laid without a track had the laying speed on both its tracks. The limit is for the diverging track alone (`velocity -V`); the own limit of the track it goes into stays for both where it's the lower. The switch tool says the speed and what gives it. - The speed is formula 9.9 of PKP PLK ST-T1-A6 the other way round, V = sqrt((I + D) r / 11.8), with the normal cant deficiency of the frog of table 9.7 (110 mm a fixed frog, 130 mm a movable nose), rounded down to the steps of the speed limits and no more than table 11.2 gives the basic switch. For the fixed frogs the formula gives table 11.2 itself (190 40, 300 50, 500 60, 760 80, 1200 100 km/h); the 2500-1:26.5 with a movable nose stays 130. A switch bent into a curve takes the radius of its diverging track from table 11.8 (one-sided r" = (Rr - t^2)/(R + r), two-sided (Rr + t^2)/(R - r)) and the cant of the line with its sign: leaning against the diverging track it takes speed away, where the speed check counted it as helping. Rz 60E1-190-1:9 bent out of the curve R 600 m with 60 mm: 30 km/h, not 40; the 60E1-500-1:12 of the review, out of R 1200 m with 60 mm: 60 km/h at its fixed frog (54 at I = 100 mm, the 0.65 m/s2 the editor took), not 107. - A switch breaking a hard rule isn't laid, the tracks left as they were, and the switch tool says why, with the value, the limit and the paragraph: the cant changing within it (11.4 pkt 7), a cant ramp ending within it or nearer than 6 m (9.6 pkt 16-17; one ending right at an end of the switch is let be, as the snapping of the start offers it), a double switch, a slip or a crossing bent (11.4 pkt 4), the curvature of its diverging or its main track turning from one side to the other (9.7 pkt 12, KZW II). They were warnings shown after the switch was laid, and on a straight the cant wasn't looked at at all. The line is looked at 10 m past the ends of the curve or the straight too, so the ramp on the straight before a curve counts. The previews show the refusals. - A switch moved along its straight or the curve it's bent into, a double switch moved along its straight, and a switch given another template go through the same checks; one breaking a rule stays as it is. - Warnings still: 1:9.403 and steeper than 1:9 bent (11.4 pkt 4c-d), a rule of the running and the main tracks, which the editor doesn't tell from the side ones, as the warning now says; the limits of table 11.9 and a cant over 100 mm in a bent switch (table 9.6), as before. Tests: unit tests of tables 11.8 and 11.9 (the least main radius bends the diverging track to the least radius the table gives), table 9.7, the speeds of table 11.2 by formula 9.9, the speed of a bent switch with the cant with its sign (the example of the review), the cant over a switch on a straight and a double switch bent. Editor cases `q2_1_switch_speed`, `q2_2_switch_refusals` and `q2_3_switch_move`, with `expect status` (the status of the switch tool) and `expect steps` (the undo steps), the fixture with a straight taking a cant on and a compound curve without cant. All pass; with the changes of the editor reverted all three fail. * test(editor): golden round trips of the tracks and of the //$ lines, the cant at the joints The safety net of the track editor before its domain model changes (E0 of editor-tracks-tests.md): what the editor reads from the scenery files and writes back is read, written and read again in tests/unit, with no game data. Tracks (test_track_text.cpp, data/tracks/). Entries written the way the game writes them, read by TTrack::Load() and written by export_as_text(), come out byte for byte the same, and read again give the same track field by field: plain tracks with all their attributes (events, speed, isolated, overhead, vradius, rail profile, friction cell), a curve with cant, radius, uneven, buckle, cwr and sleeper models, a bridge, switches with trackbed, frogs, movable nose, blades, uneven of both paths and timbers, a turntable, paths of pieces, the speeds +40, -40, 0.5, 0 and none of tracks, switches and turntables, a river, a tributary, a road and a crossing. What the game writes otherwise than given is checked as it is (table as turn, mountain as mountains, the length of the path, a switch heard from 10 m, the events in order, names in lower case, model paths with forward slashes, the texture length, rolls as floats, no overhead and no vradius left out). The seam: TTrack built from text with no scene. The engine stubs of the tests had none of it, so the tests link the few sources reading and writing a track takes (world/Track.cpp, Segment.cpp, TrackUneven.cpp, MemCell.cpp, scene/scenenode.cpp, utilities/Timer.cpp, rendering/geometrybank.cpp) and track_stubs.cpp stands in for the rest: a renderer keeping the materials by their names, and the scene, events, vehicles and the geometry of the rails, which reading and writing never reach and which stop the test with their name if one does. It tests the game's own Load() and export, where a parser of its own would have meant rewriting Load(), and changes no code of the game. The stub of basic_node::radius_() goes, scenenode.cpp brings the real one. The rails don't buckle in the tests (TrackBuckle.cpp needs the environment), the buckle declared is read and written either way; material names go through a stand-in, the game's material manager isn't tested here. The //$ lines (test_editor_records.cpp, data/records/). Their readers and writers were members of editor_mode, srk_tool and the stores, with the scene around them; they move as they were into editor/editorRecords.cpp, the one place each kind is read and written, which the stores call (and which the migration to the project file of E3 will need apart anyway). The methods of scene::layer_context move into scene/scenelayercontext.cpp so it links alone. Each kind, h r k p t w b s c o z, read from golden lines and written back comes out the same, in the coordinates of the file and of a file placed at an origin; //$e, the descriptions of the templates, read and saved by editor_includes in a template in a scratch folder, leaves the file as it was. Cant (test_cant.cpp). The paths an alignment lays roll by asin(cant/gauge), signed with the turn, back to the cant of the line at every end; a curve the other way rolls the other way. At a joint editor_track::match_rolls() gives the joined track the roll for the travel across it, turned where the paths face or stand back to back, and the track written keeps it. The inspector's own conversion on 1500 mm stays in its lambdas here; named, as editor_mode::cant_of_roll()/roll_of_cant(), it comes with the quick fixes. Known bugs found, tests of the change each (doctest::should_fail, passing until fixed, then reported to drop the decorator), data/tracks/known_lost.scn: - angle1/angle2 are read and dropped: not written back. - fouling1/fouling2 are read and dropped: not written back. - name@circuit: the circuit is taken out of the name with the letter before the @ ("tor1@iso1" becomes track "tor"; substr(0, i - 1)). - the attributes of the entry (gauge, friction, texture sizes, speed...) are written to 6 significant digits, a float has 9: more digits are lost on the first save. None in the //$ lines. Unit tests: 957 cases before, 974 after, all passing. * feat(editor): the norms of the track geometry, a module of their own: the profiles as tables, one engine Stage E1 of editor-tracks-domain.md (§3, §6): the norms stand on their own in editor/norms, with no scene, no tracks and no user interface, so they are tested whole in tests/unit. Nothing of the editor uses them yet but the report of the next commit; alignment::limits stays as the laying tools use it. - The profiles are tables of rows (normsTables.cpp). A row holds the limits of PREFER / WARN / BLOCK of one parameter where its conditions hold (a band of the speed, of the radius or of the load, main or side track, the traffic, a switch and its frog, a crossing, an expansion device, a platform, a station track, ballastless track, crest or sag), with the table or the paragraph of its document. Where several rows hold the strictest limit of each tier counts. A cell can be unconfirmed: it warns, never blocks. - PLK, ST-T1-A6 v1.0: P0 PREFER, P1 WARN, P2 BLOCK; tab. 8.1, 9.1, 9.2, 9.6 - 9.8, 9.10, 9.12 - 9.16, 10.1, 10.2, formula 9.8. - TSI only, Reg. 1299/2014 consolidated 28.9.2023: BLOCK; 4.2.3.3 - 4.2.3.5, 4.2.4.2 - 4.2.4.4. - EN 13803-1:2010 5.2.1 - 5.2.5: normal WARN, exceptional BLOCK. - CH, AB-EBV AB 17 (Normalspur, 1.7.2024): Grenzwert im Normalfall WARN, maximaler Grenzwert BLOCK. - In every profile the global hard limits of §6.3: the TSI rows and the cant gradient of 2.5 mm/m (EN 13803-1 5.2.5, the twist). - The line class: Vmax, Vmin of the slow trains (by tab. 8.1 when not given), passenger / mixed / freight, main or side track, the load, and what holds along the line (platform, station, ballastless, suburban, tilting). - One engine (normsEngine.cpp) over a line of elements (straights, transitions, arcs, the curvature changing evenly along each), its cant (points, a step being two at one chainage) and its grade line: I at Vmax and E at Vmin; dI/dt along the transitions and the ramps; ΔI at every jump of the curvature or of the cant, the jumps closer than the intermediate length of the profile (tab. 9.16) taken together while the deficiency keeps changing one way (9.11 pkt 8 - 13); dD/ds and dD/dt along the ramps, a step of the cant as its twist on the 5 m base; the lengths of the straights, arcs and transitions and the shift of the arc; R; D with (R - 50) / 1.5 and the least cant; Rv and the breaks of the grade over 2 per mille; the held grades. A finding names the parameter, the value, the limit, the tier, the profile, the source, confirmed or not, hard or not, and the chainage. The module makes no text, its users write the messages. - Areas (§6.4): the default profile of the scenery, areas outlined in the plan, lines by name (a line's own wins). An element with its ends under two profiles is checked against both, the worse kept (the stricter one); an arc across a boundary is a warning. - describe() reads a line from samples along it (the curvature, the cant and the grade simplified by Douglas and Peucker), with a precision of 0.2 % for the values measured on it. - The formulas of ST-T1-A6 9.1 - 9.10: Deq, Dreg, I, E, Dmin, Dmax, Rmin, V. The sources, and what they gave: - The cells of ST-T1-A6 spanning two or three columns (tab. 9.1, 9.6, 9.7, 9.13 - 9.15, 10.1, 10.2; §6.5 pkt 4) were read on the pages of the PDF. Tab. 9.15 has for the connections of tracks P0 = P1 = 80 mm at 100 < V <= 160 and 60 mm at 160 < V <= 200, P2 160 - 0.35 V; the table of §6.2 has P1 = 160 - 0.35 V there. Tab. 9.1 has P1 = P0 (one cell), not "-". - TSI tab. 8 (§6.5 pkt 3): the 153 mm spans both columns up to 300 km/h, 100 mm only above 300 km/h. - Unconfirmed, warning only: tab. 9.8, 5 < q <= 10, P0 95 mm, and tab. 9.7, movable frog 230 < V <= 250, P2 110 mm (as printed, out of line with the rows around them); EN 13803-2:2006+A1:2009 7.1.3, ΔI of the plain line 50 / 40 / 30 mm, read from a garbled preview. - Not there: ST-T1-A6 tab. 9.4 (a picture); EN 13803-1 dD/dt, dI/dt, ΔI in S&C, element lengths, Rv and grades (beyond the part of the standard published as its preview); AB-EBV a limit of the grade of a line, the least cant, the table of the buffer locking of 5.4.2; the TSI has no dD/ds, dD/dt nor dI/dt. DB (Ril 800.0110) is left out: it isn't published, its values are known from secondary sources only. - Simplified: the (R - 50) / 1.5 of the TSI holds for every R < 305 m of mixed and freight traffic, leaving out its condition of a ramp steeper than 1 mm/m; the intermediate element of tab. 9.16 between transitions is the one of tab. 9.1 at P2 (tab. 9.10 at P2 would do there); a switch has a fixed frog unless the track says it moves; the track is ballasted unless the class says not. Tests: test_norms_tables.cpp, every value of the PLK tables and of the TSI with its table in the name of the test, the edges of the bands (a speed on the boundary, R 300, 250 and 200 m), some of EN and AB-EBV; test_norms_engine.cpp, the examples of ST-T1-A6 (Z1-1, Z1-2, załącznik 2, the ramps of Z3-2 and Z3-3), I at Vmax and E at Vmin, ΔI of arcs turning alike and the other way, taken together over a short straight or not, dD/ds, dD/dt, a step of the cant, dI/dt, the lengths, the vertical curves, the areas and the boundary, describe(). * feat(editor): the norms checked on the tracks laid, read only: a Norms tab of the track analysis and its report The second half of E1: what the tracks of a scenery are against a profile of the norms, listed. Nothing of the tracks is changed. - editor/editorNormsReport: a line of paths sampled a metre apart, two samples at each joint, into what the norms read a line from: the plan, the curvature signed by the turn, the cant on the base of 1500 mm (as the simulator takes the rolls) signed by the side it leans to as the line runs, the grade, the speed of each path (a switch's for its diverging track alone too), and what the path is a part of (a switch, its diverging track, a curved switch, a movable frog, a crossing). The line described, checked, and each finding set back on its path with a point of it; its message, "cant ramp 3.00 mm/m, PLK allows at most 2.50 mm/m (tab. 9.12)", "break of the grade with no vertical curve, PLK asks for a radius of at least 2500 m (tab. 10.2)", through STR_C; the text of the report: the class, the elements, the cant, the grade line and the findings of each line. - The Norms tab of the track window, under More beside Speed and Joints, no key; its window is ###trackanalysis, as theirs. The line through the selected path (run_route, as the speed check walks it) or the whole scenery: the lines through the plain tracks, then each path of a switch none of them ran along, checked with the line it lies in and its own findings kept, a place two lines run through listed once. The profile (PLK by default) and the class of the line folded under a line saying it: the line speed for the tracks with none of their own (on by default: the speed of each track), the slow trains (tab. 8.1 by default), the traffic, main track or siding, the load, at a platform. The results in the table of the speed check and the joints, the worst first, coloured by the tier, the values above the recommended ones on a tick; a click on a row shows the place, the hard limits and the warnings are marked in the view. The icon is drawn into its own cell of editor_icons.png only (the generator has it): the sheet drawn again with this Pillow differs in other cells. - Self-test: normsreport [scope] [plk|tsi|en|ch] [km/h] writes the report to the file; expect findings ; the case e1_norms_report checks the curves k0..k3 of the fixture at 60 km/h against PLK and the whole scenery against the TSI. - Golden: data/norms/line.scn, a line of 14 tracks written by make_line.py there (curves with and without transitions, cant on and off a curve and along a straight, reverse curves 10 m apart, short straights, a grade with breaks), and its report against the four profiles in data/norms/line_report.txt; EU07_UNIT_TESTS_UPDATE_GOLDEN=1 writes it anew. A test lays a canted corner with the alignment of the editor and finds the samples leaning into it, both turns and run both ways, I = Deq - D. alignment::limits stays as the laying tools use it. Where its values differ from PLK P0: - unbalanced 0.6 m/s2 is I 92 mm on the 1500 mm base; P0 110 mm (P1 130) on the running lines, 80 on the sidings; - ramp_factor 10, a ramp of 1:(10 V), 1 mm/m at 100 km/h and 2.5 mm/m at 40 km/h, has no counterpart: P0 1.6 mm/m at any speed; - jerk 0.3 m/s3 is dI/dt 46 mm/s; P0 55 mm/s; - vertical_factor 0.4 V^2 and vertical_min 2000 m; P0 max(0.77 V^2, 5000 m) (P1 max(0.35 V^2, 5000), P2 max(0.25 V^2, 2000)); - arc_min 20 m and arc_min_factor 0.4 V; P0 max(0.35 V, 30 m) up to 120 km/h, 0.40 V up to 200 km/h, also for the straights, where tangent_min_time is 0; - the same: cant_max 150 mm (P0 = P1 = P2 on ballast), cant_rate 35 mm/s (P0 of tab. 9.13), the base of 1500 mm. * feat(editor): the elements and the line of the track geometry, a module of their own The first part of E2 (editor-tracks-domain.md §2 - §4): the geometry of a line computed in one place, editor/layout, standing on its own with no scene, no tracks and no user interface. Nothing of the editor uses it yet; the route design keeps its own solver. - layoutElements: the elements of a line, the straight, the arc, the clothoid (the curvature changing evenly, from any curvature to any other), the Bloss curve (3t^2 - 2t^3) and the cubic parabola (y = x^3 / 6RL by the abscissa, the length along it its own): the length, the curvature along, the point and the heading at a distance, a point offset from the axis, the shift of the arc. The local forms of the clothoid and the cubic parabola and the blossom of a Bezier curve are the ones of editorAlignment.cpp, moved here word for word; the alignment calls them, so the two agree to the bit and its tests run as before. - layoutLine: the line as a tangent polygon between the points of its two end nodes (it has no coordinates of its own there), its vertices with the radius, the transitions in and out and the cant, a grade line of breaks with their vertical curves, the shape of the transitions and of the cant ramps (linear or Bloss). solve() lays it: each curve fitted in the frame of its tangent point from its deflection (the arc what the transitions leave of it), the straights what the tangents leave of the sides, every element placed from the polygon so nothing drifts; the cant held along the arcs, ramped along the transitions, a step refused; the heights and the grades by the breaks. An end can go on from the curvature and the cant its node holds (a line split inside a curve): its curve begins right at the node. What can't be laid is an error with the vertex and the metres: curves overlapping, a curve starting before the start, transitions turning more than the tangents, a cant step, a vertical curve past the end. - described(): the line as the norms module reads it (elements, cant points, grade elements), a Bloss ramp seen by eight points so its steeper middle counts. preferred_curve(): the cant and the transition length the profile prefers for a radius at the line class, the deficiency, the excess and the greatest cant of PREFER, else of WARN, the transitions long enough for dD/ds, dD/dt and dI/dt. - norms::line_class compares by its values (operator==), the line keeping it compares whole. Tests (U): the clothoid, the cubic parabola, the Bloss curve and the arc against the series of the textbooks (the end point, the length of the parabola, the shift: L^2/24R and L^2/40R), the point as the integral of the heading, the circles alongside an arc, the curve of a vertex by its tangent length (R + p) tan(a/2) + x_m. * feat(editor): the nodes of the track geometry and the commands editing the lines, kept whole or refused, one step to undo Continues E2 (editor-tracks-domain.md §4 "Edycja = polecenie", §8): the lines meet at nodes, and every edit is a command which proposes a new state, has what depends on it laid again, is checked and kept, or refused with its reasons and nothing changed. - layoutNetwork: the node, its place (the only coordinates of the ends of the lines), the heading, the curvature, the cant and the grade, and the ends of the lines meeting there, each with its sense along the heading; the network of the nodes and the lines with the profiles of the norms by place and the identifiers handed out once, never again (an undone line made again is a new one). A transaction keeps each line and node the first time it touches it, so a change is rolled back whole or recorded. - settle(): the lines touched laid again; the nodes take the values of their ends (a free end follows its line, a node keeps the curvature and the cant a line going on from it reads), a line going on from a node whose curve changed is laid again. - check(): the invariants of the touched lines and nodes: laid, at their nodes, two ends at most on the two sides of a node (more is a turnout, E5), the heading the same within 1e-9 rad, the cant within 0.5 mm, the grade within the 2 per mille that needs no rounding; and the norms along the chains through the touched lines (the lines running on through the nodes as one line, the elements running on alike across a node as one, a jump of the curvature at a node a step of the deficiency the profile judges): BLOCK refuses, WARN and PREFER are told as notices. - layoutCommands: create a line between two new nodes; move a vertex; set its radius, transitions or cant; split a line at a chainage (the track kept as it was: on a straight, in an arc, in a clothoid with a straight ramp, the parts going on from the new node at its curvature and cant; refused inside a vertical curve and inside a Bloss or cubic parabola transition); join two free ends with a line solved between them (a straight, a curve where the tangents meet, or two curves, the largest radius which fits with the cant and the transitions the norms prefer, a grade line meeting the grades of the ends); delete a line (a node left with no end goes). The model keeps the network and the steps: undo and redo restore the snapshots of the lines and nodes a command touched, one step a command. Tests: the cases of each command, a refusal (a radius under the least, a cant over the greatest, curves overlapping, transitions too long) leaving the state as it was, a WARN radius kept with its notice, undo and redo, the track the same along a line split on a straight, in an arc and in a clothoid, a middle part deleted and joined again both ways round, a straight joining two ends on one straight. P: 300 random edits each with the seeds 20261123, 7 and 450 (moved vertices, new radii, transitions and cants, splits, joins, deletions, undo, redo): after each the invariants checked on their own (each element running on from the last, the cant running on, the ends of the lines at their nodes to the bit, the heading, the cant and the grade running on through the nodes) and no BLOCK along any chain; a refused command leaves the state as it was, an undo gives the state before the command. * feat(editor): the tracks of the simulator made of the lines of the track geometry, within half a millimetre The last part of E2a (editor-tracks-domain.md §3 and §5): the generator, the layer between the domain and the simulator. A line is cut into cubic Bezier pieces, each one a track entry of the text TTrack::Load reads. Nothing of the editor writes them yet. - The pieces end at the elements, at the ends of the vertical curves and of the cant ramps; each one halved until the curve as the simulator draws it lies within 0.5 mm of the line, in the plan and in the height, and its cant within 2 mm of the line where the simulator turns the roll evenly; none longer than a track may be (400 m), none shorter than 10 cm. The handles of an arc are its own, 4/3 tan(turn / 4) R; a transition takes the handles which give the curve the curvatures of the line at its ends (G2 Hermite, by Newton's method, those of an arc where it finds none near them); a cubic parabola is the cubic Bezier curve it is, cut by its blossom; a straight of an even grade has no control vectors, as the simulator draws it. A piece TTrack would take for a straight (its 2 cm check of the control vector) is one, close enough or halved. - The rolls and the heights come from the functions of the line, the radius from the element: an arc's own, the sharpest over a transition, 0 on a straight. A piece ends at a node with the numbers of the node, its place, its heading and its cant, so the tracks on both sides of it have the same numbers to the bit; the numbers are written in the shortest form which reads back to the same double. - The names come from the identifiers: _, the element the straight leading to a vertex (s7, se to the end) or the transition in, the arc or the transition out of a vertex (v7i, v7a, v7o); a change of a curve leaves the names of the pieces of the others. - The joints of old tracks as hard points of the pieces, keeping their names and events, are E6 (§10): generator_options has their place, a line given any is refused rather than made without them. Tests: the pieces of lines of clothoids, Bloss curves and cubic parabolas, of R 190 m and of 5 km with vertical curves, each measured both ways (the points of the curve set square onto the line, and the points of the line against the nearest of the curve, searched on its own): within 1 mm, the farthest 0.35 mm (0.45 mm with Bloss curves). G: a line split on a straight and in an arc, its tracks written and read back by TTrack::Load (the E0 seam): the ends at the nodes and between the pieces the same to the bit on both sides, the rolls and the headings of the control vectors too, the curve within 1 mm of the line, the radius of the element; a line laid the other way through its nodes; the names unique and kept by a change of another curve; the E6 hook refusing. * lang(editor): Polish for the strings of the switch rules and the norms of the track geometry 62 entries the stages of the track editing added without a translation: the crossover taken out whole (#450), the refusals and the speed of the switches (#454), the Norms tab and its report (#456), in the terms of ST-T1-A6 (niedomiar, nadmiar przechyłki). Also "Other switches of a connection##connectionsecond": field_row looks the label up with its id, which the file had only without it. * feat(editor): the first steps in the inspector, one way to start, the line laid summed up The first steps of the editor, after the first-run pass at 1920x1080 and 1366x768 (P1 of the plan of the editor's interface): - The tutorial no longer opens by itself as a window over the middle of the view (at 1366x768 over all of it, its close button under the tool row). With nothing selected, the inspector shows a compact "First steps" card: the lesson of the tool in use, its steps to try ticked as they're reached, the links "Show the lesson", "The camera" (the first lesson) and "Hide" (the setting first_steps, which the checkbox of the window now names "Show the first steps in the inspector"). Opened, the window of the lesson goes into the corner of the view by the inspector, below the rows of the menu and the tools; moved, it stays between them and the status line, as high as that room at most, the lesson scrolled inside. Its close button is always within reach. - The lesson follows the tool: the select tool of Tracks opens "Laying track" until its steps are done, so a new scenery opened in Tracks starts there, not with the camera, which stays the first page and a link of the card. - An empty scenery in Tracks with nothing selected: "The scenery has no tracks yet" and one highlighted button, "Lay the first track (L)"; the tutorial is the card under it, a "Tutorial" link when the card is hidden. With tracks, the select tool keeps its hints and a plain "Lay a track (L)". - "Without terrain", the answer to the question of the terrain at the first L, turns off the terrain made of the terrain model by itself: under the tracks as they're laid (the checkbox of the layers) and around the camera within the download area (the checkbox of the terrain panel), stops putting the squares of the area into the cache, a square on its way giving way at once, and drops the squares waiting. Kept on, the model went on being asked for, and offline the log filled with "NMT square ... not fetched: WinHTTP error"; now nothing is asked for after the answer. "Load the terrain" turns both on again. The squares of the area go to the cache, and the aerial photos ask for the model to lie on, only while some terrain is made of the model by itself. The question stands in the middle of the view, the window of the lesson waiting meanwhile. The warning of no ground under the mouse shows only while the pointer is over the view and the terrain is to be there. - The tooltip of the line being laid names the panel the rest of its warnings are in ("listed in the tool options"): the translation of the text before said "in the panel on the right", the panel is on the left. - While the pointer is over a panel, the line being laid stays as it was: the point of the cursor, the free end it snaps to and its height aren't taken from where the pointer is under the panel, which added a leg there with curves and warnings of its own. A drag begun in the view goes on over a panel. - After Enter the inspector sums up the line laid: its tracks, length and curves, those below the norms in orange, and what comes next, "A switch (T)" and "Save (Ctrl+S)". It stays while the last track is the selection the laying left; a click on a track shows the sheet of that track. The switch tool with nothing clicked shows the same, not the sheet of the last track laid. - A switch the switch tool refuses is told in its panel and by the cursor, no longer in the status line and the layers window as well, where it stayed after the next switch was laid. Why a branch couldn't lead into a free end goes into the panel with the rest; a switch laid takes the note by the cursor away. - The panel of the lay tool fits one screen at 1366x768: what the tool is for is the tooltip of the title of its card, the paragraph of the radius at the bends the tooltip of its "?" (which still opens the lesson), "This speed also on from a track with a speed of its own" is under More settings; the mode, the speed and the height stay up front. - The layout made on the first start: the side columns 22% of the width, at least 300 px, at most the 400 and 460 px they had and 30%; at 1366 px the view has about 766 px instead of 557. The tool options take 60% of the left column, and in a window under 800 px high the layers are a tab beside them, the tool options shown, so the panel of a tool has the whole column. The line of the keys of the surroundings goes on under itself at the edge of the panel. Layouts kept in imgui.ini are left as they are. - The names of the period of the day, the season and the weather in Weather and time, and the type of a node in the inspector of the surroundings, go through the translations ("(day)", "(autumn)", "(scattered)", "Typ: track" before). The degree sign of the air temperature is written as its UTF-8 bytes: CMakeLists.txt sets COMPILE_OPTIONS of eu07 and eu07_core after add_compile_options("/utf-8"), which drops /utf-8, so MSVC writes the "°" of a literal as the single byte 0xB0 of the ANSI code page, not UTF-8, and ImGui drew '?'. - Self-tests: the expectations statuslacks, refusal, statusline, laycursor and terrain, the command nmtquestion, and the cases fs_1_preview_over_panel, fs_2_switch_refusal_cleared and fs_3_without_terrain. lang/editor_pl.po: the Polish of the new texts (the card of the first steps, the summary of the line laid, "Lay the first track", the names of the periods, seasons and weathers and of the node types), the entries of the texts replaced given their new English ("Show the first steps in the inspector", "and %zu more, listed in the tool options", "Lay the first track (L)" in place of "Or start with:"), and "(do transmisji)" in place of the English "(stream)" of the drawn cursor. * feat(editor): the speed of the diverging track of a switch, one rule for the editor and the domain model The formula Q2 gave the editor (editor_mode::branch_speed_of) taken out into a pure function of the switch curve module, which the domain model of the track geometry (editor/layout, E2b) calls for its turnouts too, so the two write the same speed. - switch_curve::branch_speed(): of the basic switch of R and 1:n, its main track bent by table 11.8, the cant with its sign toward the side the diverging track leaves to: formula 9.9 with the normal deficiency of the frog (table 9.7), rounded down to the steps of the speed limits, no more than table 11.2 gives the basic switch. It reports the radius, the cant into the turn, the deficiency, the formula, the rounded speed and the table, which the editor's message tells. - switch_curve::basic_speed(): table 11.2, moved from editor_track::diverging_speed(), which now returns it. - switch_curve::written_velocity(): the one velocity a switch keeps, the main limit for both where it's the lower, else the diverging one below 0; write_switch_speed() calls it. - speed_check::suggested() inline in editorSpeed.hpp, so the switch curve module takes it in the unit tests, which don't build the checks of the speed. The editor computes the same numbers the same way: the basic radius and the bent main radius as before (bent only where the type is known), the cant toward the diverging side the same product, its sign flipped by the bent radius as before (a multiplication by -1, exact), then the same calls in the same order. tests/unit/test_switch_curve.cpp unchanged and passing. Tests (U): the examples of Q2 through branch_speed (Rz 60E1-500-1:12 outward in R 1200 m with 60 mm 60 km/h, inward 60 by the table; Rz 60E1-190-1:9 in R 600 m with 60 mm 30 and 40 km/h), the table of the basic switches, a movable nose kept to 130 km/h, a diverging track bent straight, the editor's table the same, the velocity written. * feat(editor): the turnouts of the track geometry, laid into a line, moved, changed and taken out, their legs nodes E2b (editor-tracks-domain.md §2, §4 "Rozjazd", §7, §8): a turnout is an aggregate of the domain model, laid from the catalogue the editor lays its switches from, its rules invariants which refuse. - layoutTurnout: the type of the catalogue (switch_design::catalogue(), Id-4) as the model lays it: R, 1:n, a, b, the main length, the lead and the parts of the diverging track, the movable nose, the blades; the ordinary switches whose diverging track leaves tangentially, the double, symmetric and secant ones refused with the reason (E5). The diverging track laid off the start along the turnout: on a straight the curve of the type; bent with the main track the curve of the basic switch of the radius of table 11.8 (switch_curve::bent_radius), over the length which keeps its turn off the main track, so the angle of the frog stays 1:n, the lead and the straight through the frog bent along with the main track; the cant of the main track all along it, the grade of its start. The speeds: the diverging one by switch_curve::branch_speed (the rule the editor writes), the main one the line's, bent no faster than the deficiency of the frog lets it; the velocity written by the same rule as the editor's. - The turnout: its type, hand, direction along the line, its start, the ends of its two tracks (nodes), its main and diverging track (lines it owns), derived: the kilometrage of its start, the bending, the cant, the speeds. The network keeps the turnouts with the lines and the nodes, in the snapshots of undo and in the transactions; settle() has a turnout whose main track or start changed lay its diverging track again, move the node at its end and lay again the lines going on from there. - The nodes: three ends at the start of a turnout, its two tracks on one side of it; the start of a diverging track tells its node nothing (the node keeps the curvature of the main track) and runs on into no line, the end of one sets its node. - check(): the turnouts whose tracks or legs are touched, their invariants (the legs, the tracks, the main track as long as the type) and the rules of Q2 and 11.4 through switch_curve::check (the curvature of each track of one sign, KZW II refused; the cant the same over it; the ends of the ramps at its ends or 6 m off it), a switch of 1:9.403 or steeper than 1:9 bent in a main track refused (the model knows a main track from a side one, where the editor only warns), table 11.9 and a transition under it as warnings. The norms of the E1 module with the switch context: the elements of a turnout track are a connection of tracks of their frog (fixed or movable nose: the deficiency of tab. 9.7), bent or not (the cant of tab. 9.6), at its speeds; the chain of the line runs through the main track, the element cut by a turnout open. BLOCK findings are kept apart from the broken invariants (verdict::blocks). - The commands: insert a turnout at a chainage of a line (cut at its legs, the part between them its main track), move it along its line (the lines on both sides and its main track one line again, cut anew, the ids kept, a line going on from the end of its diverging track carried with it), change its type or hand, remove it (the line one again where it can be: the merge laid and kept only where it's the same track within a micrometre). The tracks of a turnout aren't split, deleted or edited as lines; a line is joined to the free side of a turnout's start, or to the end of its diverging track from a straight (the curvature stepping there). Tests: U: the types laid and refused; the legs on a straight against the catalogue for four types both hands both ways (the main track a + b, the tangent of the diverging end meeting the main track at R tan(a/2), Id-4's a within half a millimetre, the angle 1:n, the speeds of table 11.2); Rz 60E1-500-1:12 bent outward and inward into R 1200 m with 60 mm (r" 857.8 m and 352.7 m, 60 km/h, the angle of the frog kept, the cant over it); refusals: KZW II, a ramp under it and 3 m off it, a 1:7.5 bent in a main track (laid in a side track), no type, no hand, no room; moved, changed, turned, taken out with the line laid again within a micrometre, each a step to undo; a line from the diverging end carried along. P: 250 random edits with turnouts each, seeds 20261124, 31 and 977 (laid, moved, changed, taken out, with vertices moved and set, splits, joins, deletions, undo, redo): the invariants after each (the legs and the nodes whole, three ends only at a start, the velocity by the rule), no BLOCK, a refusal changing nothing, an undo exact. * feat(editor): the edits E2a left: vertices, the grade line, the class and the profile of a line, a join from a curve, no new BLOCK The rest of the list E2a left for E2b (editor-tracks-domain.md §8), commands of the domain model of the track geometry like the others: kept whole or refused with the reasons, one step to undo. - insert_vertex (after a vertex, or after the start, with its radius, transitions and cant, its id given) and remove_vertex. - set_grades: the breaks of the grade line with their heights and vertical radii; checked by the solver (overlapping vertical curves) and the norms. - set_line_class and set_line_profile: the class of a line (its speed, traffic, main or side track) and a profile of the norms of its own (the line's own wins over the areas, as norms::area_map has it); a chain of the norms doesn't run on into a line of another profile of its own. The tracks of a turnout take a class too, their speeds derived again. - join_ends from a free end in a curve (a line cut inside one): one curve where the tangents meet, going on from the curve at the end, its arc of the radius there with no transition (or, where that doesn't fit, a radius the norms prefer and a transition from the curvature of the end), the transition at the straight end as long as makes the curve begin right at the curved end (bisected to the bit), refused where both ends lie in curves or the curve would turn the other way. The original join and this one lay the new line the same way (add_joined). - edit_policy::no_new_block for old tracks (stage E6): an edit is refused by a BLOCK finding only where it adds one; one there before, of the same parameter on the same stretch (the elements within 1.5 m, the findings carry their element as points of the plan) and no worse, doesn't refuse; the same rule of the same turnout neither. The invariants refuse in any case. model(network) takes a network over as it is, the norms not asked. Tests: U: a vertex put in and another after it, both taken out, the line as it was; a grade break and its vertical curve, two overlapping and one of no radius refused; a class of 200 km/h refused on curves fine at 80, one of 60 kept; R 280 m at 80 km/h warned by PLK, not by the TSI as the line's own profile; a line joined to a free end in an arc going on from it with the transition the part taken away had, the track the same within a micrometre; both ends in curves refused; R 170 m laid by the TSI and judged by PLK: an edit refused when any BLOCK refuses, kept with no_new_block, a sharper curve and a cant past (R - 50) / 1.5 refused, a wider curve kept. P: 250 random edits of an old track breaking the norms (curves laid for 80 km/h judged at 120), seed 4242, with no_new_block: no BLOCK finding over all the network which wasn't there before, a refusal changing nothing, an undo exact; the random edits with turnouts put vertices into straight lines and take them out. * feat(editor): the switch tracks of the simulator made of the turnouts of the track geometry, the legs at their nodes to the bit The generator (editor-tracks-domain.md §5, "Rozjazdy") makes a turnout one switch track entry TTrack::Load reads: the paths of its main and its diverging track, each from the start of the turnout. - Each path the pieces of its line as the generator cuts any line (within 0.5 mm of the elements, the rolls and the heights from the line), turned round where the main track runs against the turnout, written as pieces1/pieces2; the path itself the curve between their ends and headings for the versions which know only the path, or the one piece where one makes it. The ends of both paths are the numbers of the nodes of the legs, so the tracks on the other side of them meet them to the bit. - velocity as the speed rule gives it (the main limit for both where it's the lower, else the diverging one below 0), frogs, the movable nose and the blades of the type where it has them; the name , t by default. - A track of a turnout isn't made as a line of its own; generate_all() makes the lines, then the turnouts. Tests (G): turnouts on a straight with a grade (a 1:12 to the left along the line, a 1:9 to the right against it, a 1:26.5 with a movable nose) and one bent outward into R 1200 m with 60 mm, written and read back: both paths from the start node, the main one to the end of the main track, the diverging one to its end, to the bit; the pieces as written, joined to the bit, each within 0.5 mm of its line both ways (the farthest 6e-6 mm: short arcs of one Bezier curve each); the radius of the bent diverging curve; the velocity, the movable nose and the frogs read back; the tracks of the lines on the other side of the legs ending there with the same numbers and rolls (of the other sign where they meet head on). The diverging track of Rz 60E1-2500-1:26,5 as the simulator draws it within the chord offsets of Id-4 (30 m chords, 41 to 49 mm in the middle): 45.0 mm all along, 130 km/h on it. Left for E5: the catalogue as a data file (now switch_design::catalogue() in code), the double, symmetric and secant switches, the bending exact everywhere (now table 11.8 for the curve of the basic switch, the rest of the diverging track bent with the main one, a main track on a transition taken at its mean curvature), the connection solver (crossovers, the spacing measured along). * feat(editor): the project file of the track geometry, one per map, of a schema of its own The first part of E3 (editor-tracks-domain.md §9): the domain of the editor written next to the scenery, the .scn and .scm files staying what the simulator reads. editor/project/projectFile reads and writes it, nothing else does; nothing of the editor uses it yet. - .eu07proj next to the file of the map, shared by the scenarios of the map; plain text, a line a record, the version of the schema on the first line. Version 1: eu07proj 1 next node 9 line 8 vertex 1 turnout 3 norms plk area granica ch 4 -500 0 -100 0 -100 400 -500 400 lineprofile 91 en13803 class 1 vmax 80 vmin 0 traffic mixed track main load 5 features 0 node 3 at 300 101.2 0 heading 1 0 curvature 0 cant 0 grade 0.004 ends 3 1 end 1 2 start 1 4 start 1 line 1 from 1 to 3 class 1 chainage 0 transition clothoid ramp linear continues 0 0 turnout 0 profile tsi vertex 2 at 0 800 radius 300 in 60 out 60 cant 40 grade 200 101.5 5000 end turnouts turnout 1 type Rz%2060E1-500-1:12 hand 1 direction 1 start 3 main 2 4 diverging 4 5 chainage 300 radii 0 500 cant 0 speeds 80 60 velocity -60 movable 0 end anchors ... end kept for E6 as read, empty in version 1 generated ... end the tracks the generator wrote (the next commit) legacy h trasa/tory.scm line 1 [why ...] / | / end the //$ lines read when the map was first opened The profile of the scenery, the areas and the lines by name; the classes of the lines, each one once, the lines naming theirs; the nodes with all they hold, the ends in their order; the lines with their vertices, grade breaks, shapes, chainage, turnout and profile of their own; the turnouts of E2b with their legs, their tracks and what they derive. Numbers in the shortest form which reads back to the same double, names and files with %20 for a blank. - Read: the lines laid between their nodes as read, then the diverging tracks laid by their turnouts off the main tracks, the nodes and the turnouts as written; what refers to what checked (a line's ends held once by its nodes, the classes there, the turnouts and their tracks each of the other); a file of a newer schema refused before anything of it is read, with the reason, as is one which isn't a project file, has a record not of its version or a section not ended. Saved through a file next to it put in its place. - The identifiers handed out are kept (next), so none is handed out again after a load, whatever was deleted before the save: layout::network gets handed() and hand_out(), the turnouts' counter with them; nothing else of editor/layout changes. Tests: G: a network edited by the model (a line deleted between two) written, read and written again: the same text, the lines laid again the same to the bit as the model laid them; two turnouts, one against the line, and a line of a profile of its own: the same to the bit, the diverging tracks too (the network as settle() leaves it: the model lays the diverging track of a turnout against the line before the node at its start takes the grade of the line beyond it, 1e-16 off); the golden file of data/project/ read and written back the same, with the line ends of windows too; the anchors kept as read. A newer schema, an empty file, not a project file, broken records (a turnout whose track isn't its among them) refused cleanly. U: the identifiers after the last line is deleted, a save and a load: the next line, its nodes and its vertices numbered past them. * feat(editor): the tracks the generator wrote kept by their checksums, a track changed by hand marking its line Continues E3 (editor-tracks-domain.md §9, "Ręczna zmiana wygenerowanego węzła ... wykrywana po sumie kontrolnej"): the generated section of the project file and what the scenery files hold of it now. Nothing of the editor writes the tracks yet (E4). - generated: a record a track the generator wrote, its name, its line, the file it's written into and the FNV-1a checksum (64 bits) of its text as the simulator reads it: the words joined by one blank, the comments left out, so the line ends and the blanks another tool writes aren't a change; the switch track of a turnout kept by the main track of the turnout. track l1_s11 line 1 file trasa/tory.scm sum 0123456789abcdef switch t1 line 2 file trasa/tory.scm sum 00000000000000ff hand 3 record_generated() puts the pieces of a line, or the switch track of a turnout, in the place of the ones the project had of it; find_hand_changes() looks the names up in the text of the files now: a text of another checksum, or a track gone, or a file which can't be read; mark_hand_changes() marks their lines changed by hand (hand , kept by the file), may_overwrite() tells the editor to leave them, until the line is written again by the editor (the author decided). - editor/project/sceneryText: the text of the scenery files read as cParser and state_serializer read it, with no scene: the words (blanks and semicolons between them, // and /* */ comments, the quotes), the node of a name and its words up to the end word of its type, and the statements of a scenery with its includes followed relative to the scenery folder (the words of each file taken as they're needed, the includes no deeper than 32), the parameters of a template in place of (p1)..., the placement of origin, rotate and scale at each include, the terrain files passed over for a binary terrain. The scenario index and the migration read the files with it. Tests: U: two lines generated into one file among other nodes: as written nothing is changed, through the project file too; the speed of a track of the second line edited: that line and that track told, marked changed by hand once, kept by the file, the first line not; written again, not marked. The switch track of a turnout: its speed edited marks its main track. Blanks doubled, the line ends of windows and comments inside a track aren't a change; a track taken away, a file which can't be read are. The node of a name found by the words. * feat(editor): the //$ lines of an old scenery taken into the project file when its map is first opened Continues E3 (editor-tracks-domain.md §9 "Migracja", §10): what the //$ lines describe of the track geometry becomes the lines and the nodes of the domain where the domain lays it as the editor laid it; the rest is kept in the project file as it was written. The lines stay in the scenery files, untouched; the scenery files aren't written. - //$h, an alignment: a line between two nodes at its ends, its vertices where the design puts them (from the tangents of the ends for one, by the offsets for the first and the last of more), their radii, transitions and cants, the shape of the transitions, the origin as the chainage of the start, the speed as the highest of the class; a curve going on from the adjoining track as an end going on from the curvature and the cant of its node. Not a compound curve, two transitions with no arc between them, cant ramps of its own, a curve turning the longer way, a curve going on from a switch, a design kept for a part of its line, nor one the domain lays to a length 5 mm off the old one: kept as it was, with why. The free ends of two lines within 0.5 mm, running on from one another, join at a node (a turn of the headings over 1e-9 rad told). The record is kept whole in the project with the line it became: the points clicked, the old norms, the pieces and the fit have no place in the domain yet. - //$p, a grade line along such a line (its ends and length within 5 cm, either way): its breaks with their vertical curves as the breaks of the line, the heights of its ends as those of the nodes; not one with a break of no vertical curve, or along no line, or one the line can't be laid with. Kept whole too. - //$r switches (E5), //$k the kilometrage of the railway lines (the line's own chainage is the //$h origin), //$t the tracks fitted, //$w the tracks sharing a grade line, //$b the objects bound to the tracks (E6, the anchors), //$s the stations (E7): no place in the domain yet, kept as they were, a block a kind a file. //$c, //$o, //$z, what the editor keeps of itself, aren't taken. - The lines read as the editor reads them: the old letters of the marks under the new ones, the lines other tools put after the same marks (Rainsted's includes after //$r) left out. marked_files() finds the files of the map with their includes followed and the placement in effect at each; open_project() reads the project of the map, or makes it of the //$ lines and writes it where there's none. Tests: G: the sceneries of data/records/ made into a project: the alignment of clothoids a line within a millimetre of the old design along all of it, the one kept for a part of its line and the grade line along nothing kept with why, each other kind kept as the file has it and read back by editor_records as from the scenery, the camera, the orthophoto and the area left; written and read back the same. A map of data/project/migration (its tracks included at an origin) opened the first time: two alignments joined at a node in the world, the grade line of the second one its break and the heights of its ends, the one along the first refused for a break of no vertical curve, the compound curve kept; the scenery files byte for byte as they were; opened again, the file read and not made again. * feat(editor): the scenarios using a map and the tracks, events and memory cells they name in it The last part of E3 (editor-tracks-domain.md §0 pkt 7, §3 "Indeks scenariuszy"): a change of the map mustn't take away what a scenario relies on. Read only, from the text of the files as the simulator reads it; nothing of the editor asks it yet (E4, E7). - The scenarios are the *.scn files of the scenery folder. A quick look at the include words of the files, each file once for all of them, tells which may reach the file of the map; those are read whole (sceneryText), their includes followed with the parameters of the templates, the terrain passed over where the scenario has its binary terrain. A scenario uses the map where the file of the map is among its files. - What the map defines: the tracks, the events and the memory cells of the statements of its files. What a scenario names in it: of the statements outside the files of the map, the tracks the trainsets start on (anywhere, a scenario being its own map too) and the vehicles standing on their own; the events called by multiple events, by event launchers and by the tracks of the scenario; the cells and tracks acted on by the events (updatevalues, getvalues, copyvalues and its source, whois, logvalues; switch, trackvel, trackbuckle), checked by their conditions (memcompare, trackoccupied, trackfree) and by the launchers; the tracks of the scenario's cells and isolated circuits; the events named after a track of the map, :event1..., which the track calls. Each with what names it, the file and the line. The names as the parser makes them, A to Z small. - Not seen: the names the simulator makes (the tracks of the roads, the turntables), the scripts, the timetables, the commands the cells give the drivers, the random includes. Tests: U: data/project/index, a map of tracks, events and memory cells, some from a template included with parameters at an origin, and three scenarios: two using it (one through a file of its own) with their trainsets, vehicles, events, launchers, cells and isolated circuits, listed in full; the trainset on a track of the scenario, the names in comments, an event of none_ and a name of nothing left out; the scenario of another map with tracks of the same names not among them. The include tree read with the parameters and the placements; the words split as the parser splits them. * feat(editor): one card for the tools, one layout of the fields, windows of their own, one name for each thing The consistency pass of the editor's interface after its first steps (P2 of the plan of the editor's interface): - One card for the tool in use in every field of work. The card of the track tools (its icon, name, family and key, what the tool is for, the mouse and the keys drawing its gestures, the link to all the shortcuts) is a component of its own, render_tool_card, fed by the tracks as before and now by the surroundings, the roads and the terrain: their tools, kept in one table each with their icons, keys, tooltips and gestures for the toolbar and the card, had a plain heading and a line of keys or a few rows of gestures there. The tool options of the surroundings are headed by the field of work as the others are. The card is folded to its title row unless the user opened it, for all the tools: what the tool is for shows over the title, a click opens the gestures, which are in the strip under the view of the tracks as well. Kept with the settings of the editor under the key tool_card_folded, so the open card the tracks had by default before stays behind. - One layout of the fields: the name on the left, the field on the right (begin_fields and field_row, as in the inspector of the tracks) in the inspector of the surroundings (the name, the position, the rotation, the scale), Weather and time, Change history, the settings of the orthophoto and the settings of the editor. The square buttons of the download area go on to the next line at the edge, the last one was cut off. - Windows of their own, which don't hide the inspector: Editor settings, Weather and time and the orthophoto settings float over the view, opened in its top left corner below the rows of the tools and kept between them and the status line, as the window of a lesson is. They were tabs over the inspector, and the orthophoto settings unfolded inside the layers; Map > Orthophoto settings..., the button of the terrain tools and the button in the layers open the window now. - One list of the objects of the scenery: Windows > Scene Hierarchy, a plain list of the same nodes, is gone; Windows > Scene opens the Scene tab (by layer and group, with the filter) and brings it forward when it lies behind the layers. - One name for each thing, in the menus, the toolbar, the panels, the tutorial and F1: the orthophoto ("Ortofotomapa (zdjęcia lotnicze z geoportal.gov.pl)" where it's introduced, "ortofotomapa" in the rest, for "zdjęcia lotnicze", "ortofoto" and "zdjęcie"), the terrain model ("Teren z map (NMT)" for "Prawdziwy teren z map", "model terenu", "prawdziwy teren", "Teren z NMT"), the plan tool ("Plan", the lesson "Correcting a curve" and the section of F1 "Plan of a curve" before), the area fill (the terrain's "Fill" is "Area fill" as in the surroundings, with the icon of it, Water without). The texts of the laying, whose panel is to be redone, are left as they are. - The node bank: a model clicked with the select tool of the surroundings arms the insert tool with it (the click did nothing before), the random model of a set is left off then. A model inserted where there's no ground under the cursor stands at the height 0 where the cursor points, or in front of the camera when it points above the horizon, and the status says where; it stood at the point the renderer last had under the cursor, out of sight. The search field of the bank has no name beside it, which was cut to its first letter. - The settings in one place: Editor settings holds the movement and the speed of the camera (as View > Camera speed), the gizmo and the colours, the terrain made of the terrain model by itself (as in the layers and the download area) and the maximum placement distance (as in Change history). - F1 and the menus: Esc closes the window of the shortcuts, before anything else; the window stays in the work area as the window of a lesson; the menus are opaque, the windows under them showed through. - What the first steps left: with an empty scenery the panel in the middle of the view gives way to the inspector, which says the same with the button of the lay tool and the first steps; it's drawn only while the inspector isn't seen. A switch whose speed limits its diverging track alone shows that speed under its empty speed field ("The diverging track 40 km/h, the main one no limit"), read only; the field alone said no limit. - Self-tests: the command bankpick, the expectations tool, window and selected, the cases c_1_bank_card_arms_insert and c_2_esc_closes_shortcuts. lang/editor_pl.po: the Polish of the new texts (the cards of the tools, the windows, the fields, the notices), the entries of the texts renamed given their new English, those no longer used taken out, and the names unified in the Polish of the orthophoto and of the terrain model. * feat(editor): the lay tool a step at a time, its settings folded while the points are clicked While the points of a line were clicked, the same things were told in four places at once: the card of the tool with seven gestures, the panel (the points not laid, the buttons, the modes with their explanation, the speed with its chips, the height, the curves with their legend), six lines by the cursor with the full texts of the norms, and the gestures again in the bar under the view. The panel of the lay tool now goes by states, each with one line of what to do now at its top (editor-lay-flow.md): - Ready, nothing clicked: "Click on the ground or at a free end of a track" (with a curve traced: "Click points along the curve on the photo"), and the three settings: the shape [Straights | Curve], with what it makes of the points under the "?" beside it (a click opens its lesson), the radii of a curve traced in the same place, the speed (the field and its chips), the height [Fitted | Point to point | Flat]. The rest under More settings, the pieces added at the free end of the selected track there too. - Clicking, a point or more: "Click the next bends" and the keys "Enter lays, Backspace takes back a point, Esc drops". The line in one line, "Length 300 m, 2 curves, slowest 35 km/h", and a badge, green "meets the norms" or orange "2 curves below the norms for 100 km/h"; "details" (or the badge) opens the curves one by one, the breaches of the norms in their words, how the curves go on from those of the tracks joined, the speed designed for, the grades and what the norms say where the line goes on from a switch. The legend of the labels is by the cursor over a curve. [Lay (Enter)] as the main button and [Drop]. The settings folded to one line, "Straights, 100 km/h, through the points" (a curve traced with its radii), a pencil at its end opening them. The details open under it all, so the buttons stay where they are. - Laid: back to ready, with one line over the settings, "Laid 214 m (14 tracks), Ctrl+Z undoes" in green, the rest of what the laying told under "notes" beside it. It goes as the history moves on or back. - Dragged out of a free end: "Drag to lay from the end; let go to lay it", the line of its length and radius with the badge, the settings as the line of their summary. The drag tells the line laid as Enter does. - By the cursor, the leg drawn to it in a line or two: "straight 40 m", "curve R 76 m, up to 35 km/h" with the sign of a warning (drawn, the font has no glyph of it) and the line in orange where it's below the norms; joining a free end, the shape of the join, a line that can't be laid, Alt, the first Esc and what Tab switched to. The texts of the norms are in the details only. - The labels in the view short: "R 198, up to 60 km/h", orange below the norms; the straights as before. - The bar under the view shows the three gestures of the state: ready "LMB the first point, LMB on a free end from the end, Tab a curve from the photo"; clicking "LMB the next bend, Enter lay, Backspace take back". The rest of them in the card unfolded and in F1, Ctrl+Shift+wheel (the speed) added there; the length typed after the three. Nothing is taken away: what the panel showed is behind a fold, the pencil, the "?" or F1. The messages the lay tool logs for the self-tests keep their words, the line laid told as "Laid 214 m (14 tracks)" now. The flow: application/editorflow.h, the step line, the summary line with its pencil, the badge with its details, the message of one line with the rest in its tooltip, for the panels of other tools as well. Self-test: expect laypanel , and the case lf_1_lay_panel_states through the states, in straights and in a curve traced. lang/editor_pl.po: the Polish of the new texts as the spec words them; the laying texts of "the photo" named the orthophoto as the rest of the editor ("na ortofotomapie", "z ortofotomapy"). * feat(editor): the switch tool a step at a time, the template chosen as a line The panel of the switch tool goes by states as the lay tool's does, each with its step at the top (editor-lay-flow.md, second part): - Ready: "Press on a straight and drag along it and to the side" (a slip, a crossing and a connection with steps of their own). What to place as one bar, [Switch | Slip | Crossing], in place of the tiles in two rows. The rail of the track, or the rails [60E1 49E1 S42] where it doesn't tell its rail, and the speed on the diverging track as chips beside "Diverging speed (km/h)"; the template they pick as one line, "Rz 60E1-300-1:9, 50 km/h", its tooltip the lengths and the rest of its label, a pencil at its end opening the list of the templates and All templates under it. The gestures of placing are in the card and in the bar under the view, no longer rows in the panel; the template editor among More settings. - Dragging: "Let go to insert" and one line, "27.1 m, left, 40 km/h"; what keeps the switch from being laid (the rules a switch bent into a curve or laid on from a free end breaks) in one line in red, the switch moved back onto its straight or into its curve and the branch that doesn't fit into a track in orange. - Placed: "Switch z1 inserted, Ctrl+Z undoes" while the switch is the one the last step of the history laid, else "Switch z1: drag it along its track to move it". The sketch, its length and side in its tooltip; the speed chips and the template as the line with the pencil, as when placing; Flip the side. A switch with no drive says so with what puts one there; the name, the record, the angle, the drive, the frog and the check rails, the slide along its track and the note of the inspector are under Details, folded. What the tool told of it besides the step under it all. - Refused: the reason in red right under the step, the rest of a long one in its tooltip. The drive of the switch is drawn by a function of its own (render_switch_drive), no longer a lambda of the panel. The status of the switch tool is told in red while it's the refusal last told (m_switch.refusal), the expectations of the self-tests read it as before. The bar under the view keeps the gestures of the view first, "List in the panel" after them. Self-test: expect switchpanel , and the case lf_2_switch_panel_states: ready after a switch refused, placed after one laid, selected after another one laid since. lang/editor_pl.po: the Polish of the new texts. * feat(editor): the catalogue of the turnouts a data file, the switch tool and the domain model reading it The first part of E5 (editor-tracks-domain.md §7, "Katalog jako dane"): the types the editor lays its switches from were a table in switch_design::catalogue() and two in editor_track::standard_switch_templates(); now they are editor/data/turnouts.txt, one type a line, built into the executable as its text (CMakeLists.txt writes it out as editor_turnouts_txt.inc, as it does the icons), so the game data doesn't need it, and read once when first needed. - The format, which the templates of the user (eu07_switch_templates.txt) share: switch ... source . A type of the catalogue gives its geometry as the instruction does (type, rail, radius, ratio, a, b, diverging, the blades tangent or secant, the cut tip of the blade; stagger and the keys of the second switch of a double one; middle and the half length of a slip; fit for the three fitted to measured tangents), the parts made of it as before; a template of the user gives its parts. What §7 asks besides the geometry, - where the source has nothing: the frog (fixed or movable), the locks (Id-4 tab. 14-3), the drive, the speed of the diverging track (ST-T1-A6 tab. 11.2), the bending (tab. 11.9), the least spacing for a crossover (tab. 11.2) and the source of the values, unconfirmed ones said so: the cut tips of SKMd-4 (190, 300, 500, 1200 m; 760 m the editor's own), the secant blades of S42 at 25' and the one fitted for S42-140-1:7, the a and b of 2500-1:26,5, the slips' blades (not found), the tip of a blade with no data by the rule sqrt(2R 0.005) - 0.125. - read_designs() reads the format, a line which isn't one left out with why; catalogue() the switches as before, in the same order, slips() the slips and the crossings, catalogue_entries() all of them, read once (secant_blade() no longer builds the catalogue at each call). - The slip curve and slip_of() moved from editor_track to switch_design, which the domain model lays its slips with (E5); editor_track keeps the names. - A template of the user with a movable nose writes frog movable, which it lost before; without one the line is what the builds before wrote (they leave out a template with a key they don't know). The lines they wrote read as they did. Tests: U: every switch of the data file the same to the bit as the catalogue of the code (kept in the test as it was), the slips and the crossings as the switch tool had them; every line read, with its source; each switch against Id-4 and ST-T1-A6: R, 1:n, a, the main track a + b, the pre-blade stretch, the blades (the tip lead + cut where the sheets give it, about sqrt(2R 0.005) - 0.125 where they don't; secant at 25'), the speed of tab. 11.2, the bending of tab. 11.9, the spacing of tab. 11.2; the rule of the tip against the sheets (190 m +3 mm, 300 m +105 mm, 500 m -56 mm, 1200 m +3 mm; the 4.5 mm rule +60, +143, -44, -49 mm); a template keeping its movable nose, an old line read as before; lines left out with why. Unit tests 1070 -> 1077. * feat(editor): the double, symmetric and secant switches, the slips and the crossings of the catalogue in the domain model E5 (editor-tracks-domain.md §4 "Rozjazd", §7): every type of the catalogue is a turnout the model lays, its tracks lines it owns and its legs nodes, kept whole or refused like the ordinary switches E2b laid. E2b refused the rest with "stage E5". - Secant blades (S42): the diverging track runs along the main one for the pre-blade stretch and turns off it by the angle of the blades at their tips, the rest of 1:n on its arc; a turn inside the track, the node at the start keeping the heading of the main track. The generator ends a piece there with the heading of the element before it (unchanged where a line runs on in its heading). - Double switches (Rpd, Rpj, Rps): the main track cut at the start of the second switch, its node holding the main track, the main track of the second switch (main2) and its diverging track, to the other side or the same one, as switch_design::build() lays it. Written as the switch tool writes them: the first switch, a plain track of a metre before the second one (the simulation joins a switch to plain tracks only), the second switch. - Symmetric switches (Rls): both tracks turning off by half of the angle, to both sides, laid at a free end of a line, which they end (the line beyond it would have to turn at the node); not moved along the line. - Slips (Rkp, Rkpd) and diamond crossings (Skrz): the main track a part of the line, the crossing track across its middle at the angle of the slip between two nodes of its own, the slip curves from the start to the end of the crossing track and, of a double slip, from its start to the end of the main track; slip_of() lays the curves with the blades of the ordinary switch of the rail, radius and angle (no data of the slips' own blades was found), passing the crossing as near as the rails of the simulator's profile let them. The three with the blades outside of the diamond whose curves then reach past the half length of Id-4 (49E1 190-1:6,6, 300-1:9, 500-1:9, by up to 0.3 m) are laid as long as their curves. Written as the switch tool writes them: a switch at each leg a slip curve leaves, the tracks crossing and the middles of the slip curves plain tracks, the joints inside it the same numbers on both sides. - The rules: a double switch, a slip, a crossing (11.4 pkt 4 a, b) and a symmetric switch (no rule of table 11.8 for it) lie on straights only; an invariant, refused with the reason before anything is laid. The norms judge the tracks crossing at a slip or a crossing as crossings (no cant, tab. 9.6), its slip curves as diverging tracks. - The ends of the tracks of a turnout which carry no line through their node (the starts of the diverging tracks, the ends of the slip curves) are branch_end(); a node holds such an end beside a track of the same turnout on its side. settle() lays all the tracks a turnout lays itself (lay_tracks()), the nodes of its own where they end; lifting, moving, changing (to another kind too) and removing a turnout take all of them along. - The project file: the turnout record gets "second " and "crossing slip " where the turnout has them (diverging 0 0 for a crossing); version 1, unreleased, read as before without them. The generated section keeps each track a turnout is made of. - TSI INF 4.2.3.4(1), 150 m at least, judges the plain line, not the curves of switches (4.2.5): its hard row leaves out the tracks of the turnouts, so the industrial S42 switches of R 70 and 140 m are laid. Tests: U: every type of the catalogue laid (41 ordinary, 3 symmetric, 15 double, 18 slips, 20 crossings) on a straight to both sides along the line and against it, its legs where the catalogue puts them (the main track a + b, 1:n at the ends, the second switch at the stagger, the crossing track at the angle of the slip, half its length from the crossing), moved and taken out, the line one again, each a step to undo; the turn of the secant blades of S42-190-1:7 at the end of the pre-blade stretch; a double switch, two slips and a crossing refused in a curve, a secant S42 bent in a side track, a symmetric switch refused at the end of a curve. The three fitted to the tangents of S42-140-1:6,6 16/12 measured are refused by the norms (tab. 9.14) where the transition one is. P: 200 random edits with every type along arcs and transitions, seeds 5150, 2718 and 1618: the invariants after each, a refusal changing nothing, undone back to the start exactly. G: every type made into the tracks of the simulator and read back by TTrack::Load, the ends of the paths at the legs or at each other to the bit, the velocity and the frog; a double switch, a double slip and a crossing written to the project file and read back, their tracks laid again the same to the bit. The E2b case of the types refused now checks that they're laid. Unit tests 1077 -> 1086. * feat(editor): the bending of the turnouts exact: table 11.8 for the whole diverging track, the main track on a transition as it is E5 (editor-tracks-domain.md §4 "Rozjazd", §7 "Na łuku — łukowanie z dokładnym wzorem (tab. 11.8)"), what E2b left: table 11.8 for the curve of the basic switch only, the rest of the diverging track bent with the main track by the sum of the curvatures, a main track on a transition taken at its mean curvature, the sign of the curvature of the diverging track judged from headings sampled every half metre. - Table 11.8 written for the curvatures, r" = (R r -+ t^2) / (R +- r) as k" = (k + K) / (1 - k K t^2) with the tangent t of the basic switch, bends every curve of the diverging track and the ends of its transitions, each as long as keeps its turn off the main track (the angle of the frog); the curve of the basic switch keeps switch_curve::bent_radius(), the same numbers as before; a straight goes with the main track as before (the formula gives K for k = 0). On a straight nothing changes. - The frame of a turnout knows its main track: where its curvature changes under the turnout (a transition curve, or the end of one) the diverging track is laid in steps of 2 m at most, each one's curvature at its ends by the table with the curvature of the main track at the station it runs by (along the main track, its heading off the main one taken in), the turn of each part kept; the straights and the lead with the main track step by step too. - The curvature of a diverging track of one sign all along it, from its elements (9.7 pkt 12, 11.4 pkt 6): a BLOCK rule of the turnout in place of the sampled check of switch_curve (KZW II), which a short straight through the frog going the other way could slip through. Tests: U: a diverging track of a curve of 800 m, the curve of the basic switch of 500 m and a transition off it, bent with main tracks of 1200 m both ways and of 3000 m: each by the table with the tangent of the basic switch, the basic one the same as bent_radius(), each turning off as far as in the basic switch, on a straight to the bit as it was; Rz 60E1-500-1:12 60 m into a transition of 200 m to R 1200 m: laid in steps, its curvature at the start by the table with the main track's there, growing along it, the frog against the main track where it ends beside it at 1:12.0004 (1:11.9966 by the mean curvature, the end 27 mm apart), moved and back the same; Rz 60E1-190-1:9 bent two-sided refused, its curve turning off to its side and the straight through its frog the other way (KZW II), one-sided not. Unit tests 1086 -> 1089. * feat(editor): the solver of the connections of the tracks: a crossover between two lines, the norms of the straight and the spacing E5 (editor-tracks-domain.md §7 "Połącz tory", §8 "Połącz dwa końce ... odmowa ... z najlepszą propozycją"): editor/layout/layoutConnection plans a crossover between two lines running alongside, straight or curved, and the command connect_tracks lays it, one step to undo. - The first turnout where it's asked for, toward the other line; the second one on the other line running back, its diverging track facing the first one's, where the line between their ends turns by as much at both of them: on one straight between straights alongside (the headings of the ends within 1e-13 rad), one curve between curved lines. Found by the secant along the other line, each try the turnout laid in a copy of the network, so it's put as the command will put it. - The spacing of the lines measured along the whole crossover, a point every metre, not where it starts; the least of it against the least spacing of the type: of ST-T1-A6 tab. 11.2 where the catalogue gives it, or what its geometry needs with the least straight between its turnouts (crossover_spacing()), the larger. - The least straight between the turnouts from the norms: a new parameter of the E1 module, switch_straight, at the speed through them: max(0.15 V; 6) m in the running and the main tracks (11.3 pkt 7d, WARN), 30 m on a line of 160 km/h or more (pkt 7e, BLOCK; the new feature fast_line), 6 m recommended in the side tracks (pkt 7c). The solver asks for the normal limit. - Where they can't be met: refused with the reasons and the best which fits the spacing measured, a type of the catalogue of the rail of the one asked for before the others, the fastest; or that none fits, and the spacing the type asked for needs. - The line between the turnouts runs at the speed of their diverging tracks and is a part of the connection of the tracks for the norms (the feature switch_track of its class, which describe_chain() puts on its elements): an arc with no transitions nor cant where it isn't a straight, and the steps of the cant deficiency and the elements between them judged as in the tracks of turnouts (tab. 9.15, 9.16). Tests: U: crossovers of Rz 60E1-500-1:12 between straights 4.75 m apart, both ways to both sides: the spacing 4.75 m all along, the straight between the ends (4.75 m less twice the offset of an end) / sin(1:12), the norms' 9 m at 60 km/h, the ends facing each other on one straight, one step to undo; a line closing in on the other refused for its spacing along the crossover though wide enough at its start; 0.15 m short of the spacing for the 9 m straight refused with "11.3 pkt 7" and a type proposed, which then is laid; 30 m on a line of 160 km/h; Rz 60E1-760-1:14 refused at 4.74 m by tab. 11.2 though its geometry fits; between two curves of R 1200 and 1195.5 m 4.5 m apart (4.50086 to 4.50087 m along it), both turnouts bent, one curve turning by 0.6 degree between their ends; a slip, a line to itself, a line across and a type of none refused; the rows of switch_straight. Unit tests 1089 -> 1096. * feat(editor): the //$r switches of an old scenery on the lines of its alignments made turnouts of its project E5, what E3 left (editor-tracks-domain.md §9 "Migracja"): the //$r records were kept in the project file as a block a file; the switches among them which the domain can lay now become its turnouts when the map is first opened. - A switch or a double switch of the editor becomes a turnout where its record names a type of the catalogue (its type, rail, radius, ratio and a, b of an ordinary or a symmetric one; the first of the catalogue's order where a movable nose is the only difference, which the record doesn't keep), its start lies on a line made of an alignment within a centimetre and its direction along the line or against it, and its main track is bent as the record says the line is there (straight, or the radius within 5 %). It's laid into the line by the command insert_turnout, the hand of the record, with edit_policy::no_new_block: the old line may break the norms where nobody touched it, the turnout may add no BLOCK finding to it. - Its record goes on its own into the project with the main track of the turnout (as an //$h record keeps the line it became); the rest of the block stays as written, the comments with it, why each switch didn't become a turnout with it: a slip or a crossing (their records don't tell the side of the crossing track), a connection (the solver of the connections lays it anew), a lifted outer track, no type of the catalogue, no line under it, a bending other than the line's, or the reasons the command refused it for. A block none of whose switches became one is kept as before, with the reasons. Tests: U: an alignment of data/records with five //$r lines: two switches on its straight, along it and against it, to the left and to the right, made turnouts of their types at their starts (the structure whole, no reason); one beside the line, one of no type of the catalogue and a connection kept in the block with the comment, each with why; the two records each with the main track of its turnout; the project written and read back the same. The records of data/records and of the map of data/project/migration (no switch on a line) kept whole as before. Unit tests 1096 -> 1097. * feat(editor): the project of the map opened with the scenery and written with it, behind a setting of the editing on the model The first part of E4a (editor-tracks-domain.md §3, §9, §14): the domain model of E2 and the project file of E3 brought into the running editor, behind a setting, "Editing on the model (trial)" in the settings of the editor, off by default. Off, nothing of it runs and the editor is as it was. - editor/project/projectSession: the project of the map open in the editor, no scene. open() reads the project file of the map, or makes it of the //$ lines the first time (open_project of E3), and compares the tracks the generator wrote with the files as they are now: a track changed or gone outside the editor marks its line changed by hand. trial() tries a command on a copy of the network and tells the lines it lays anew or takes away (differences()), nothing changed; execute() carries it out, the lines of Overwrite no longer taken for changed by hand with it. A command kept is a step of the model's history with a token, which the editor's step of it takes back and brings again (undo(Token), redo(Token)): only the latest step kept, or taken back, can be, so the two histories can't go out of step; the marks of a change by hand go with the step. record_written() records the tracks of a line as the scenery save wrote them, save() writes the project with the network as it is, the records of the lines gone taken out. - The setting on, the project of the map (the file of the scenery opened, .eu07proj next to it) is opened with the scenery and written with it. The scenery save asks for the text of each track it writes (scene::node_layers::path_writer): a track the generator made, as long as nothing else changed it, is written as the generator made it (the numbers in the shortest form which reads back to the same double, not the 15 digits of the export), and its checksum recorded; one changed by the other tools is written by its own export and its line marked changed by hand. The tracks of the lines of the project are found in the scene by their names, with the text the file has for each (scene::node_layers::source() tells the file and the placement of a node). Tests: U: a map opened gets its project file; a command refused, tried or carried out, changes nothing and isn't a step; a command tried changes nothing, carried out tells its lines (new, split, a curve changed, deleted); the steps taken back and brought again by their tokens in the order of the history, another token refused, a command after an undo dropping the step taken back, the identifiers not given again; the tracks of two lines written and recorded, a reopen finding nothing changed and the line the same to the bit as the model laid it, a speed edited in the file marking its line alone, deleting it writing over it too, the mark taken off by a command writing over it and back with its undo, the records of a line deleted gone with it at the save. Self-test: modelediting <0|1> (the setting for the run, not kept), expect modellines, expect projectfile . lang/editor_pl.po: the Polish of the new texts. * feat(editor): a line laid in the straights, or the route design applied to old tracks, a line of the model, its tracks the generator's Continues E4a (editor-tracks-domain.md §3, the generator as the layer between the domain and the simulator; §4, §10): with the editing on the model on, the lines laid in the editor are lines of the model and their tracks its tracks; the old tracks stay as they are, the old tools edit them. - The lay tool in the straights: Enter lays the line its preview shows as a create_line command of the model, its vertices where the preview has them with their radii, transitions and cants, an even grade from end to end (the grade line through the model is E4b), the speed designed for as the class of the line. Refused, the panel tells why with the value, the limit and the paragraph, nothing is laid and the points are kept to be put right; kept, the generator makes its tracks, named after the line and its elements (l1_s11, l1_v1a1...), of the style of the track it goes on from or the lay tool's, one step of the history; what the norms warn of is told under it. A curve traced, a curve going on from the curve of a free end, a compound curve or one with cant ramps of its own are laid the old way, told why. - The route design applied to old tracks makes them a line of the model in their place, one step: not through switches, nor tracks with events or in isolated circuits (their events would be lost until E6), nor a line with a grade line of its own; those are laid the old way, told why. - A track the model made is marked as its line's: the inspector shows "Line L1 (managed)". Ctrl+Z takes the command back with its tracks, Ctrl+Y brings it again: the editor's step keeps the token of the model's step (EditorSnapshot::model_token). - editor_track::load_entry: a track of the entry the generator wrote, its numbers as written. Self-test: a track named @., modeltracks, expect managed, expect modelends (the tracks of each line from end to end at the numbers of its nodes and at each other, to the bit), expect hand. The cases m_0_setting_off (the setting off: no project, old tracks), m_1_lay_managed (a line laid is a line of the model, the project file written next to the copy of the scenery, the ends to the bit before and after a reopen, nothing changed by hand), m_7_plan_converts (the route design applied to a1..a3 makes them a line, Ctrl+Z brings them back). lang/editor_pl.po: the Polish of the new texts. * feat(editor): the curves of a line of the model changed in the route design as its commands, refused with the reasons; split, join, delete Continues E4a (editor-tracks-domain.md §4 "Edycja = polecenie", §8): a line of the model is edited through its commands, each kept whole or refused with the reasons, one step of the history. - The route design opened on a track of a line of the model shows the line as the model has it, its curves with their radii, transitions and cants. The preview is the route design's as before; applied, each change is a command of the model: a vertex moved (move_vertex), its radius, transitions or cant typed (set_vertex). A command refused changes nothing and the panel tells why, with the value, the limit and the paragraph ("cant 200, the limit 150 (ST-T1-A6 tab. 9.6)"); one kept is laid, one step, and what the norms warn of, or would prefer, is the quality line of the panel. Curves added or taken out aren't applied to a line of the model yet. - Under the line in the panel: split it at a distance from its start, join its free end to the free end of the nearest other line of the model (a new line solved between them), delete it; Del on one of its tracks deletes the line too. - A command which lays anew, or takes away, a line whose tracks were changed by hand (found so in the files when the map was opened, or changed in the editor by the other tools since the model made them) asks first, in a window naming the line: keep the change by hand, and nothing is done; or overwrite it, the line laid anew and no longer taken for changed by hand. Self-test: modelplan , routeradius|routecant , routemove, modelsplit, modeljoin, modeldelete, modelselect, modeldel, modelanswer , modelmark; expect modelrefused, modelmessage, modelvertex, modelsame, question. The cases m_2_plan_refusal (a cant of 200 mm refused with its reason, nothing changed; a wider curve laid in one step), m_3_model_undo (a command taken back and brought again with its tracks, a split taken back, the project saved after an undo read back as it was), m_4_hand_change (a track's speed changed in the inspector: kept, nothing changes; overwritten, laid anew; a change by hand saved found after a reopen), m_6_split_join (two lines joined, the new one split and deleted, each a step). lang/editor_pl.po: the Polish of the new texts. * feat(editor): the scenarios naming a track looked through before it goes, the index of the map built in the background and kept The last part of E4a (editor-tracks-domain.md §0 pkt 7; §8, deleting a line): with the editing on the model on, a track a scenario of the map names goes, or is renamed, only when the user says so. - editor/project/scenarioIndexCache: the scenario index of E3 built on a thread of its own as the map is opened, and kept: in memory, and in a file of the cache of the user between the sessions (scenario_index/.txt; not for the self-tests), for as long as the *.scn files of the folder are the ones it was built of (their names, sizes and times); on a big map it takes minutes, once. The editor doesn't wait for it to close. users_of() tells the scenarios naming the tracks, with what names them and where. - Del on an old track with a name, on a set of them, or on a track of a line of the model (its line goes), the route design applied to old tracks, and a track renamed in the inspector (editor_mode::track_rename) wait for the index ("Checking the scenarios": cancel, or go on without checking), then go at once where no scenario names the tracks, or ask: "Track used by 2 scenarios", each scenario with the trainsets, events and the rest naming the track, the file and the line; delete (rename) anyway, or cancel and nothing changes. - The self-tests: the scenarios of the map of the fixture, tests/editor/scenery/autotest_editor..scn, copied by run.py next to the copy of the fixture as autotest_editor__.scn, naming that copy (autotest_editor.uses.scn: a trainset on s1, an event on d2). The index of the fixture's map over the scenarios of the game's folder takes about 80 s. Tests: U: the index written and read back with its fingerprint, other versions refused; the users of a track by its name as the simulator compares it; built once in the background, given again for the scenarios as they are, built again when one changed, read from the file of the cache in the next session, built for another map. Self-test: modelwait, modelrename, expect question [n]; the case m_5_index_delete (Del on s1 asks: cancelled it stays, confirmed it goes; d2 renamed the same; a3 and a line of the model go at once); m_6 and m_7 wait for the index. lang/editor_pl.po: the Polish of the new texts. * feat(editor): the old tracks recognized as lines of the domain: the curves read off the curvature, fitted by least squares, the deviation measured The first part of E6 (editor-tracks-domain.md §10 "Automatyczne przejęcie odcinka", editor-tracks-tests.md §4 "E6"): a chain of the paths of an old scenery, Bezier curves drawn by hand or by older tools, made a line of the domain (editor/layout/layoutRecognition). Model only, nothing of the editor asks it yet. - The chain sampled along its arc length in the plan, every metre for the fit and every half metre for the deviation, each joint with the turn of the heading there: the point, the heading and the curvature of the Bezier curve as the simulator draws it, the cant of the roll turned evenly with the parameter as the simulator turns it (1500 mm sin roll, of the other sign where a path runs against the chain). - The curves found where the curvature changes: the heading differenced over 30 m (the noise of the ends of the old paths, written to the millimetre, and the ripple of the Bezier curves evened out), runs of one sign past 1/5000 m; a run whose curvature falls to a third of what it is on both sides cut in two; the arc of each where the curvature is half of it or more (the area over that width is the turn), its transitions where it rises from a tenth to nine tenths, the window taken off; a turn of more than a quarter of a circle laid as curves of a quarter at most. A turn of more than 5 mrad at one joint making up a curve is a kink (told, laid as the shortest curve which fits); an arc whose halves differ by a quarter is a compound curve (told, laid as one). - Each curve a vertex of the domain, clothoid - arc - clothoid, its point where the straights fitted around it cross; then the points, the radii and the transitions of all of them fitted by least squares to the offsets of the points of the chain from the line the domain lays (Levenberg-Marquardt, the Jacobian by differences over the points each parameter moves; the transitions by their squares, since what a transition moves the curve by grows with its square; the points and the radii first, then all of it). An end held by what stays beyond it (a switch, an old track not taken over) keeps the first or the last vertex on its heading. The curves the curvature doesn't show (a radius over 5 km, a turn spread over the joints) are added where the line keeps off the points by the tolerance, six at most; the small turns of old tracks laid jagged, joint by joint, are left out where the line keeps nearer without them; where it keeps more than a metre off, the plan of the added curves alone is tried; a vertex whose tangents cross behind the curve tells nothing of it, and a vertex no radius lays is taken out. - The cant of each vertex fitted to the rolls along its arc and its transitions; a cant the rolls ramp up with no transition under it is fitted again with transitions as long as the ramps, kept where the line keeps nearer so. The grade line: the heights as straight grades within 1 cm (Douglas and Peucker), the heights of the breaks by least squares, each vertical curve the largest of the usual radii which keeps within it. - The deviation measured densely: each point of the chain every half metre set square onto the line, the farthest and the root mean square of the distance in the plan, of the height and of the cant, where the farthest is. The tolerance of a takeover with no question (takeover_tolerance): 20 mm in the plan and in the height, as the simulator itself joins the ends of the tracks within 2 cm, so the tracks made again lie where the simulator takes the old ones to be; 10 mm of the cant, 0.4 degree of the roll, under the half degree many old files round the rolls to. The norms aren't asked here. Tests: U: three curves (R 800 m with clothoids of 80 m and 60 mm, R 600 m with 60 and 70 m and 90 mm, R 1500 m with none) and a grade line with two breaks, cut at random places 8 to 25 m apart, each piece a Bezier curve, the joints shaken by up to 4 mm across and in height, the rolls rounded to the tenth of a degree, seeds 1101, 2202 and 3303: the radii within 1 %, the transitions within 3 m or moving the arc within 5 mm of where the laid ones move it, the cants within 3 mm, the deviation within the tolerance; the same walked the other way round, the transitions swapped. A kink of 0.6 degree at a joint told and laid within the tolerance; an arc of 11 km found where the curvature shows none; an end held in a heading 2 mrad off the chain kept to 1e-9 rad. Unit tests 1101 -> 1103. * feat(editor): the joints of old tracks as hard points of the pieces, the names, events and circuits of the old tracks kept by the lines E6 (editor-tracks-domain.md §5 "Podział na kawałki zachowuje miejsca...", §10 "Stare złącza jako twarde punkty podziału"), the hook of the generator E2a left (generator_options::hard_splits, a line given any refused). - A line keeps the old tracks it was taken over from (line::hard_splits): where along it the stretch of each begins, its name, the words of its entry before the path (the width, the friction, ... the visibility and the materials) and after it (the speed, the events, the isolated circuits and the rest), whether it ran against the line. In the line rather than in the options of the generator, so a command which cuts or joins lines carries them and an undo puts them back: a line cut (split_line, a turnout laid into it) gives those past the cut to the part after it, and the old track cut in two keeps its name and its events on the part it ran into first, the other part a stretch of it the generator names (continued); two lines joined, the second one's after the first one's. - The generator ends the pieces at each joint inside the line (a joint stays, a break of the elements next to it gives way) and writes the pieces of a stretch as the old track was: its name on the piece it ran into first with all its attributes, _2, _3... on the others with them but its events (an event of a track is called once), its surface, the path written the way it ran (event1 and event2, the sign of the rolls); an old track of no name named by the generator, its events kept. A line with none is made as before. - The project file: "old reversed <0|1> continued <0|1> surface attributes " in the block of a line; version 1, unreleased, read as before without them. Tests: G: a line of three curves given three old tracks (one named with its events and its circuit, one of no name, one which ran against the line): the pieces end at the joints, each name once, the attributes of the first on its first piece and without its event on the others, the event of the unnamed one once, the one which ran against the line written from the end of the line; written into the project file and read back the same. It takes the place of the E2a case of the hook refusing. Unit tests 1103 -> 1103. * feat(editor): the old tracks of a scenery chained and taken over as lines by one command of the model, the norms told, not refusing E6 (editor-tracks-domain.md §10): a set of old tracks made lines of the domain in one step to undo (editor/layout/layoutLegacy and the command take_over). Model only: the question with a preview before and after is the editor's, after E4a. - legacy_track: an old track as its entry has it, in the world, with no scene: its name, its paths, the words before and after them. walk_chains(): the plain tracks of the set chained the way a train runs them (the chain walking of the old digitization, kept): a track joined at an end to exactly one other plain track of the set, within the 2 cm the simulator joins them within, goes on into it; a switch, a track not taken over, a fork or a free end ends the chain, held in the heading of the main path of the switch or of the track holding it, which the line runs on from. Each chain runs from its end the smaller in x, then in z, whichever track it was found from. - plan_takeover(): each chain recognized (layoutRecognition), its held ends kept, the old tracks along it as its hard splits (a track named none of no name), the class of its line of the highest speed of its tracks; the deviation of each line and the worst of all; silent where each line keeps within the tolerance. Nothing is laid. - take_over, a command of the model: the lines between new nodes at the ends of their old tracks, their vertices, grade lines and old tracks as recognized. The invariants refuse it as they refuse any command; the norms don't: the BLOCK limits the old tracks pass are told in outcome::broken (an old track may break the norms where nobody touched it, improving it is a separate decision; edits of the lines after it are judged by edit_policy::no_new_block). take_over_tracks() executes it and returns the deviation of each line and whether the takeover is silent, for the question. - A switch stays an old track, a fixed constraint: the lines end at its legs in its headings. Its type recognized in the catalogue and the switch laid into the line as a turnout, so the line runs on through it, is left for later. Tests: U: the line of three curves cut into old tracks, each written the way it was: the tracks in three random orders, seeds 4401, 5502 and 6603, the walk starting from another one of them each time: the same line, its vertices to 1e-6 m and its radii and transitions to 1e-9, the same old tracks at the same chainages. Unit tests 1103 -> 1104. * feat(editor): an old scenery read with no scene, its lineside objects anchored to the lines with a confidence, the anchors in the project file The rest of E6a (editor-tracks-domain.md §2 "Kotwica", §3 "Otoczenie", §9, §10 "Powiązania otoczenia ... z oceną pewności; wątpliwe pokazane do przejrzenia; przewody wiązane ze słupami"). - editor/project/legacyScenery: the tracks of the railway (normal and switch) and the lineside objects (models, wires, memory cells, event launchers) of a scenery read from the text of its files with their includes, as the simulator places them: the tracks and the wires moved by the origin only, the rest by the origin, the rotation and the scale (sceneryText now tells the placement in effect at each statement). The tracks naming an object: a memory cell's own, and those whose events (event0 to eventall2 of their entries, the events :eventN) act on it, multiple events followed four deep. The kind of an object by its file and name, as the binding of the editor tells it (infra::classify). - editor/layout/layoutAnchors: an anchor puts an object along a line: its chainage, the offset to the left of the line (below 0 to the right), the height above it, its turn against the heading there; a wire by its four points, bound to the poles its ends hang on (a pole, or a model the names take for a part of the catenary, within 8 m of each end, along the same line). infer_anchors() anchors every object within 30 m of a line to the nearest one, with a confidence from 0 to 1 and the reasons for it: named by a track of a line, 0.95 at least (0.85 where another line is nearer, half of the fit where the line named isn't near); else how its distance fits its kind (a signal 0 to 6 m, a sign or a pole 1.5 to 8 m, a wire 0 to 1.5 m, equipment 0 to 3 m, logic and the rest 0 to 15 m, the environment at half), a third past the end of a line or 15 m above or below it, half where another line is as near within a metre, 0.8 for a sign, a signal or a pole turned more than 10 degree off square to the track; a wire on poles at both ends 0.9 at least, on none 0.7 of what it had. Below 0.6 doubtful, to be looked over. place() puts the object where it stands along its line now; follow() after a change of the network: an anchor whose line is there keeps its chainage, one whose line is gone (cut, joined, taken by a turnout) is anchored again where it stood, to the line there now; the anchors whose objects move, with where to. Moving the nodes of the scene, and taking the anchors back with an undo, is the editor's. - take_over_tracks() given the objects of the scenery anchors them to the lines it laid, the old tracks naming them by the lines they became, and lists the doubtful ones, with the deviations, for the question. - The project file: the anchors section, reserved and empty in version 1 so far, holds the anchors: "anchor group at yaw line chainage offset height turn confidence points ... poles ... [why ]". The schema stays 1: it's unreleased and the section was empty. - The //$b bindings of the old editor (the same mechanism along the paths of the tracks) aren't made anchors yet. Tests: G: data/takeover/old.scn, written by make_old.py (a line of 26 tracks with a curve of R 500 m, clothoids of 60 m and 80 mm, a break of the grade with no vertical curve, tracks of no name and written backwards, events and an isolated circuit; a switch at its end and a line on from each of its legs; a signal named by the events of a track and its memory cell, a pole every 50 m and the wires between them, hectometre posts, a tree 25 m off, a cabinet between two lines): read with no scene; its plain tracks taken over as three lines with no question, R 500 m, the clothoids and the cant read back within 1 and 5 %, the lines held at the legs of the switch in its headings, one step undone and done again the same; the tracks made again ending at the old joints, each old name once, the events and the circuit on their pieces, also after the curve was made 20 m wider; written into the project file and read back. The signal and its memory cell anchored with 0.9 or more, the poles with 1, every wire bound to its two poles, the tree and the cabinet doubtful; the curve made wider: the objects along it follow at their chainages and offsets, the signal on the straight before it stays; the anchors written into the project file and read back. The case of the project file which kept the section of the anchors as text reads and writes two anchors now. Unit tests 1104 -> 1108. * test(editor): the recognition of old tracks measured on sceneries of the game, read only, skipped unless asked for editor-tracks-tests.md §4 "E6", the measure: tests/unit/test_takeover_measure.cpp, a case skipped by default (it needs the data of the game, so it isn't a test of the build), run as EU07_TAKEOVER_MEASURE=";;..." eu07_unit_tests --no-skip --test-case="takeover measure*" It reads the tracks of each file with its includes, takes all the plain ones over in a plan (nothing laid, nothing written) and prints the lines made, how far they keep off their old tracks in the plan, the height and the cant, how many would be taken over with no question and why the others ask it, what the domain lays otherwise (kinks, compound curves, cants with no transition), the worst lines; EU07_TAKEOVER_TRACK= prints the curves found and the vertices of the line of a track. Measured on the game data, read only (baltyk/baltyk_torowisko.scm, l02/l02_tory.scm, linia61/l61_tory.scm, lk197/lk197_tory_uniwersalne.scm, drawinowo/tory.scm, calkowo_v2/v2_tory.scm): 31 411 tracks (2 111 switches), 3 594 lines of 30 297 tracks, 1 477 km, 2 chains not laid, 8 minutes. With no question 3 112 lines (87 %) but 591 km (40 %): the short tracks of the stations fit within 5 mm, the long lines drawn by hand ask. The farthest in the plan: up to 5 mm 2 890 lines, 10 mm 195, 20 mm 113, 50 mm 134, 100 mm 97, 500 mm 99, more 66 (bulging Bezier curves, compound curves of stations, a few tracks of no sense). The question for 482: the plan 297, the height 74 (buffer stops of tracks climbing a metre), the cant 12, more than one 99. * feat(editor): the messages of the model of the track geometry and of its norms told in the language of the editor The first part of E4b (editor-tracks-domain.md §8; E4a left the messages of the model in English): what the model refuses a command for, and what the norms warn of, reach the user through the catalogue of the editor, the model staying as it is, English and pure. - The editor layer formats them: a message of the model is matched against the forms it's made by (a BLOCK limit along a line, a finding of the norms with its value, limit and paragraph, a rule of a turnout, a line or a vertex which can't be laid, the solver of the connections and its proposal...), the form of the catalogue (STR) filled with its numbers and names, the parts which are messages of their own (the name of a parameter of the norms, what a line or a turnout is refused for) shown so in turn; a whole message the catalogue has, as it is. One with no form stays English. - The editing on the model keeps both: what the model told, English, for the log and the self-tests, and what the user reads, in the route design, the lay tool and the panels of E4b. The window of the application is split off editormodemodel.cpp into editormodemodel.h, shared by the files of E4b. Self-test: expect modelmessage holds or lacks the text in either of them, so the cases run in any language. lang/editor_pl.po: the Polish of the forms and of the names of the parameters of the norms the editor hadn't yet. * feat(editor): the switches of the switch tool on the lines of the model its turnouts, inserted, moved, changed and taken out by its commands Continues E4a (editor-tracks-domain.md §7, §8; stage E4b): with the editing on the model on, a switch dragged on a track of a line of the model is a turnout of the catalogue of the model, and so on, each a command, refused with the reasons or one step of the history. The switches of the old tracks are laid the old way. - The drag of the switch tool, let go on a line of the model (on a straight or along a curve), is insert_turnout: the type of the catalogue the template is of (a template of the user's own isn't), its start where it was pressed, its chainage on the line (layout::chainage_of), the side of the drag its hand, the way it was dragged its direction. While it's dragged the panel tells in its red line why the model would refuse it, tried on a copy; let go, a refusal is told there with the value, the limit and the paragraph ("(9.6 pkt 16)"), nothing changed. Laid: its switch track made by the generator (t), selected, the panel placed, its speed told. - A turnout of the model selected: the inspector shows its type, side, speeds and bending, the templates of its kind of the catalogue (change_turnout), the other side (change_turnout of the hand), moved by a distance (move_turnout), taken out (remove_turnout). The slide of the switch tool moves it, another template changes it, Del takes it out (after the scenarios are looked through), each a command. Plan on a track of a turnout doesn't open: the turnout is edited through itself. - A crossover dragged between two lines of the model is connect_tracks of the solver of the connections; refused, the solver's best proposal is told with the reasons ("Proposal: Rz 60E1-300-1:9 needs them 4.498 m apart"). - The tracks after a command: of a turnout one of whose tracks changed, its tracks of the simulator made again whole, kept by its main track (kind switch, the plain tracks of a double switch, a slip or a crossing with them); written with the scenery as the generator made them, recorded in the project with their kind and the file each went into (session::record_written of pieces of several files), found again when the map is opened, nothing taken for changed by hand. project::session::generate(turnout_id). Self-test: modelturnoutside ; expect modelproposal , expect handlines ; expect modelends checks the paths of the switch tracks at the numbers of the nodes; a crossover of the connection command between two lines of the model goes to the solver of the model. The cases m_8_turnout (a turnout dragged on, taken back and brought again, moved, given another type and side, taken out by Del; one 2 m off the end of a cant ramp refused, nothing changed; saved and found after a reopen) and m_9_crossover (a crossover between lines 4.75 m apart, one between lines 4 m apart refused with the proposal). Tests: U: the chainage of a point on a line and its distance; the switch track of a turnout made by the session, the tracks of a line written into two files recorded. lang/editor_pl.po: the Polish of the new texts. * feat(editor): the grade line of a line of the model drawn in the profile tool, its command Continues E4b (editor-tracks-domain.md §8, "Zmień załom lub Rv niwelety"): with the editing on the model on, the profile tool opened on a track of a line of the model is the profile of the whole line, its points the breaks of the grade line as the model has them with their vertical radii, the heights of the ends its nodes'. - Applied, the points between the ends are set_grades of the line (chainages along it, the route run along it or against it), a break with no radius given the one the line needs; the model is the judge of it, before the checks of the profile tool: refused, nothing changes and the profile tells why in red; kept, one step, the tracks made anew, the profile read again from the model, what the norms warn of under it. The heights of the ends aren't changed here: a line of the model keeps the heights of its nodes. Self-test: modelgrade (a break put into the grade line of the profile opened on the line, applied), expect modelgrades . The case m_10_grade_curves (a break 1 m up taken back and brought again; one too near the end to be rounded refused, nothing changed). lang/editor_pl.po: the Polish of the new text. * feat(editor): the vertices of a line of the model dragged on the map, the line as the model would lay it shown before they're let go Continues E4b (editor-tracks-domain.md §0 pkt 2, §8 "Przesuń wierzchołek", "Zmień R / L / D wierzchołka"): the route design opened on a line of the model has its handles on the map, a vertex and the grip of the radius of each curve. - While a handle is dragged the change is tried on a copy of the network as it goes: the line as the model would lay it drawn over the map, green, or red where it's refused, and by the mouse and in the panel why it's refused or what the norms say of it ("The norms: 2 notes"). Let go, it's one command of the model: move_vertex for a vertex moved, set_vertex for a radius dragged; a vertex moved and its curve changed at once one set_vertex with its place (layout::set_vertex::point), one step. The first and the last vertex of a line of two or more go along the tangents of its ends, as the route design drags them. - No gizmo on the tracks of a line of the model, nor the points of their paths dragged by hand: the line is edited through the route design. The gizmo stays for the old tracks and the models. Self-test: modelplan opens the route design in the field of the tracks; expect modelvertexat , expect modelpreview . The case m_11_vertex_drag (the vertex dragged with the mouse, the preview told while it's held, one step). Tests: U: a vertex moved and its curve changed by one set_vertex, one step, taken back. lang/editor_pl.po: the Polish of the new texts. * feat(editor): curves added to a line of the model and taken out, a line laid on from its free end sharing the node there Continues E4b (editor-tracks-domain.md §4, §8): two edits E4a left. - The route design of a line of the model adds a curve at a distance from its start (insert_vertex: a vertex on the leg of the tangents there, no curve until it's dragged off the line, then of the radius of the lay tool) and takes the curve of a vertex out (remove_vertex), a command each, the design read again from the model; a handle dragged told above them. - The lay tool laying from the free end of a line of the model, or to one, makes the new line go on from the node of that end, shared, not a free node of its own beside it: create_line given the node (layout::create_line::start_node, end_node: a free end of a line of its own, the line leaving it along its heading or against it as its first leg does), its leg there put onto the tangent of the node, so the line goes on with no kink. Its tracks and the other line's end at the numbers of the node, to the bit, also after a save and a reopen. Self-test: modelvertexadd , modelvertexdel ; expect modelvertices , expect modelnodes . The cases m_10_grade_curves (a curve added, bent, taken out, a step each) and m_12_lay_from_end (a line laid on from a free end shares its node, the ends to the bit after a reopen). Tests: U: a line laid on from the free end of another one and back from its start share the nodes, a node of two ends no free end, a kink refused, undone the node free again. lang/editor_pl.po: the Polish of the new texts. * feat(editor): the parallel tool beside a line of the model lays a line of the model, its arcs concentric Continues E4b (editor-tracks-domain.md §8, "Odsuń tor równoległy"): with the editing on the model on, the parallel tool beside a track of a line of the model lays a new line of the model at the spacing, one create_line, checked by the norms. - editor/layout/layoutParallel: the line alongside a line, pure: the legs of the tangents offset, the vertices where the offset legs meet, the arcs concentric with the line's, the radius less on the inside of a curve and more on the outside, the transitions recomputed from the shift of the arc so the centre stays the line's; the cant and the class of the line, its grade breaks at the same share of the length. In a curve the spacing is widened by the widening of the gauge of both tracks on the sides facing each other (PLK tom II annex 1, gauge::curve_widening, under R 250 m), where the transitions of the curve can take it; where they can't, told so. The norms of the track geometry have no spacing of their own yet. - The tool tells the line laid, the spacing in each curve widened, what the norms warn of; refused, why, nothing changed. Self-test: expect modelspacing . The case m_13_parallel (a line laid on the inside of the curve of a line of the model, 4.5 m on the straight and in the arc, one step). Tests: U: the line alongside a straight and alongside three curves on both sides, laid, the arcs concentric within 2 mm; alongside a curve of R 200 m the spacing widened by the gauges, the transitions longer on the inside and shorter on the outside; not widened where a curve has no transitions, told why. lang/editor_pl.po: the Polish of the new texts. * fix(editor): the tracks of a line of the model saved into a file under an origin aren't taken for changed by hand The last part of E4b (E4a left it): a track the generator made, written into a layer of another placement than the one its entry was made for (a file under an origin), went by its own export, recorded by none, and the scenery opened again took its line for changed by hand. - project::moved_entry: the entry of a track of the generator, a plain track or a switch track, as written into a file of another placement: the points of its paths moved by the difference of the origins, in the shortest form of the generator, the control vectors as they are. The save writes it so and records it, the track keeps it as its text for the next save; reopened, the checksums of the file are the ones recorded. Self-test: tests/editor/run.py takes a line `#> append ` of a case, added at the end of the copy of the fixture. The case m_14_layer_origin (a line of the model laid under origin 2000 0 0, saved, reopened, saved again and reopened: nothing changed by hand). Tests: U: the entry of a track moved for a file under an origin, its control vectors as they were; not moved, the checksum the same. * feat(editor): the assumptions of the project asked for at the start, what's drawn, kept with the map editor-project-setup.md: a new user drew with no word of what: the norms, the speed, the gauge and the rail lay about the panels, set on the way. Now one short step, "What do you draw?" (Co rysujesz?), one screen of defaults and one button: - The fields: the norms (PLK ST-T1-A6, TSI alone, EN 13803, CH; PLK by default, no "none": a fictional scenery has a profile too), the speed of the line (chips 40..200, 100 km/h), the traffic, a main or a side track, the gauge (1435 / 1520 / 1000 / 750 / 600 mm), the rail (60E1 / 49E1 / S42), the look of the tracks under More (the rails and the trackbed as now where left empty). application/editorsetupui.* draws them for all three places below. - Asked for as the last step of the wizard of a new scenery (4., or 2. for a fictional one; its button Start: create and open in the editor), which writes them into the new scenery; and in a scenery with none, as a card in the inspector of the tracks in place of the first steps, until its Start. Changed later in their window, Assumptions of the project, from the editor settings or the line of them under the first steps in Tracks; a change checks the lines laid before against them, the report in the window of the norms, nothing laid changed by it. - Kept with the map (editor/editorProjectSetup.*, one record "setup norms plk speed 100 traffic mixed track main gauge 1435 rail 60E1"): in its project file where it has one (a record of its own; the profile of the scenery the model judges by set with it), else in the scenery as //$u lines, which the simulator skips and the scene layers keep as a mark of the editor. Read when the map is opened, the project file first. A scenery saved without them holds nothing new. - The defaults of the tools from them: the speed of the laying and of the route design, the gauge and the rails and the trackbed of the tracks laid, the norms checked against, the rail of the switch tool and the usual switch of the rail for the speed on its diverging track (the closest speed, the ratio usual for it). A route with no speed of its own takes the speed of the assumptions. Self-test: setup [ ]..., setupwindow [close]; expect setup none| , expect setupmark , expect layspeed . The cases ps_1_setup_saved (set, saved into the scenery, read back after a reopen) and ps_2_setup_project (into the project file with the editing on the model, read from there after a reopen with it off). Tests: U: the record written and read back, the defaults, what it can't read, the class of the line, kept in the project file. lang/editor_pl.po: the Polish of the new texts. * feat(editor): the aerial photo turned on or off kept per scenery, //$g of the scenery first for its origin The photo on or off is the scenery's now, as the user left it in it: a global off kept by the editor no longer hides the photo of a scenery the wizard made with //$o on 1, and the old global choice is left behind. With nothing chosen in the scenery it's as the scenery keeps it, else off, and the terrain model turns it on where the scenery lies on the map. The origin of the scenery is taken from //$g of its file before the one the editor remembered for a scenery of that name, or wrote into //$o with it; where they're apart by more than a metre the status line says so, and the settings of the orthophoto tell that an origin typed there is for the session. The rules the photo goes by stand on their own (editorPhotoRules), with their unit tests; the settings of the editor are read and written through a stream, so they're tested without the user's file. * feat(editor): the downloads of the aerial photo look after themselves: the area grown at its edge, the failures told and tried again, 4K zoomed in The download area grows by itself where the camera or the laying comes within a tile of its edge: the tiles of 5 x 5 around them added to its tiles, as one outline along the grid with its holes filled, now and then (5 s apart at least) and not past 1600 tiles; the status line tells it, and the limit once. The area is saved with the scenery as before. A tile which failed is tried again later and later, up to 5 min apart, and never given up for good, around the camera and in the area alike. The ones failed are outlined red in the view, and the status bar tells how many with the reason in plain words (no connection, the server didn't answer, ...) in place of the code of WinHTTP, and Retry (Ponów) at once. The 4K photos (6 cm/px) of the tiles next to the camera come by themselves with the view zoomed in to 15 cm a pixel, and go again past 25 cm, within the limits on the 4K downloads as they were; the area is put into the cache in the products of the setting alone. * feat(editor): the tracks laid drawn over the aerial photo in the top view zoomed in as well The photo is drawn over the view, the 3d tracks under it: zoomed in under 0.5 m a pixel they were left to the 3d tracks and the photo dimmed them. With the photo shown over the view the tracks are drawn over it there too, as their two rails in the colour of the rails of the top view where they're apart on the screen, so the tracks laid and the ones of the photo are seen together; the tracks being laid are drawn after them, on top. How many were drawn in the last frame is kept for the self-test. * feat(editor): no question of the terrain at the first L, it loads in the background and the photo doesn't wait for it The first L in a new scenery with no tracks nor terrain asked in a window whether to load the terrain. Now nothing is asked: where the scenery lies on the map the terrain model loads in the background around it, as the answer Load the terrain did, and a line in the panel of the laying says "Terrain: loading..." with Without terrain, which stops it as that answer did; it goes once the terrain is in. A scenery not placed on the map has Place it... there, to Terrain (F5). Whether a new scenery gets its terrain by itself is a checkbox of the settings of the terrain loading, where the window had it. A download of the model that failed is told there, and in the banner of the loading and the terrain panel, in plain words as the photo tells its own, not as the code of WinHTTP (which stays in the log). A tile of the photo no longer waits for the chunks of the terrain still to come under it: it lies flat at the height of the ground found last (of the layer before any was) and goes onto the ground as it comes. The window and its strings are gone. * feat(editor): the aerial photo in the toolbar of the tracks with its opacity, ~ the scenery's choice and in F1 The toolbar of the tracks has the photo: its button shows or hides it for the scenery, as the user's choice, and while it's shown over the view a slider of its opacity is beside it, kept with the editor. ~ (and Ctrl+~, which turns it on to hurry the view's tiles) count as the user's choice now: turned off with ~, the terrain model made afterwards no longer turned it on again behind the user. ~ and Ctrl+~ are listed in F1 with the camera. * feat(editor): the aerial photos on the map of the wizard, from the service the photo under the scenery comes from The map the centre of a new scenery is clicked on (and the one of the terrain panel) showed the base map of OpenStreetMap alone. Zoomed in to 40 m a pixel or finer it shows the orthophoto of GUGiK now, the same WMS as the photo under the scenery in the editor; further out the map, with "Zoom in for the photos" while the photos are chosen. Map | Photos in its corner switches between them, the photos chosen at first. Whose the picture is, is told by the line under the steps of the wizard and, for the photos, in the corner of the map: GUGiK, geoportal.gov.pl, or OpenStreetMap for the map. * test(editor): the cases of the aerial photo with no fuss, and fs_3 with the line in place of the question ph_1: the photo turned off with the button of the toolbar stays off over the wizard's //$o on 1 when the scenery is opened again, on again after the next. ph_2: the first L in a scenery placed on the map asks nothing, the terrain loads in the background with its line in the panel of the laying, Without terrain stops it. ph_3: the tracks drawn over the photo in the top view zoomed in under 0.5 m a pixel, not without the photo. ph_4: the button and ~ are the user's choice, the terrain of the model made afterwards doesn't turn the photo on again, F1 opens. fs_3 still checks the answer Without terrain, now the button of the line which took the place of the question in a window, and that no window asks. New for the scripts: expect photo , expect terrain , toolbar , orthophoto forget, and the key grave (~) for tap. * fix(editor): the panels of the editor opaque, the 3d scene doesn't show through the docks around the view The 3d scene is drawn under the whole window and the windows took the opacity of the simulator's interface (ui.bg.opacity, 0.65 in the ini of the game): the tracks and the models beside the view showed through the docks around it. The editor's windows are opaque now; the ones over the view meant to be seen through set their own alpha as before. The simulator keeps ui.bg.opacity for its own interface. * test(editor): a mistyped track fails the self-test, indented comments are skipped, case 7b checks the switch got bent - A blank line or an indented `#` comment in a script is no longer a command no group takes. - `trackcant`, `routegauge` and `tracksetdelete` with a track that isn't there count as a failed expectation. - `expect shaped `: 7b checks that the gizmo drag bent the switch out of its record before deleting it. - The ramp-length loop of test_alignment counts in an integer (Sonar S2193). * test(editor): the entries known to be lost are checked apart from should_fail, the cant test says where the inspector conversion is tested - A normal test checks that known_lost.scn and each of its entries are there and read, so the should_fail tests can't pass for data gone missing. - The comment of test_cant.cpp said the tests of cant_of_roll()/roll_of_cant() are here; they are the self-test case 1_inspector_cant.txt, as the unit tests don't link the editor. * fix(editor): TSI and EN take close jumps of the cant deficiency together, the norms queue keeps its own span after a delete - TSI INF and EN 13803 limit an abrupt change of the cant deficiency but give no intermediate length, so two jumps a few metres apart were each checked alone: at km 478 of the golden line CH reported 191 mm over the TSI limit, TSI itself nothing. With no intermediate length in the profiles of the element, the longest any profile asks for is taken. The golden report changes that way: TSI gets the 191 mm hard limit at km 478, EN reports it instead of 106 and 85 mm one by one. - forget() moves the span whose findings alone are kept (a diverging track) down by the spans removed before it, and drops a queued line whose own span was removed, instead of leaving the index on another span. - The report test of R 400 / 80 mm runs at 90 km/h and requires the finding: at 80 km/h there was none and the check never ran. * fix(editor): the norms see a Bloss transition as it is, a line splits at the tangent point of an arc with no transitions - A Bloss transition went to the norms as an even one: 60 m into R 600 m at 100 km/h showed 63 mm/s of deficiency change, where its middle reaches 109 mm/s, past the hard limit of 80 mm/s, so the edit wasn't blocked. norms::element::bloss makes the engine follow 3t^2 - 2t^3 of the curvature, look at the transition in eight pieces, and take the shift as L^2 / 40R instead of L^2 / 24R. Two Bloss halves no longer run on into one element of the chain. - split_line right at the tangent point of an arc without transitions was refused ("the tangent there doesn't cross the tangents of the curve"): the curvature there is already the arc's, so it now takes the start or the end of the curve. - Sonar: the chain walk, describe_chain and check_norms check the lines they look up (S2259), join_ends returns when an end isn't found rather than when a reason was given (S836), the test loops count in integers (S2193), the seeded generator of the random edits is marked (S2245). * fix(editor): the answer Without terrain keeps to the scenery open, the settings stay as they were nmt_decline_offer() turned off terrain_while_laying and terrain_model().area in the settings of the editor and saved them, so one Without terrain for a scratch scenery left the terrain off for every scenery opened later. The answer now holds for the scenery open only (nmt_state::declined, read through nmt_area()); the checkbox of the terrain panel shows it and, ticked, turns the terrain on again and keeps it in the settings. The nmtquestion self-test no longer writes the tester's settings, and fails the run if the answer changed them. * fix(editor): no diverging track is laid from a main track that isn't laid, a switch track with no pieces isn't written - lay_diverging() didn't look at turnout_frame::valid: with the main track unsolved the diverging track was laid from the origin and settle moved its end node there. Edits were rolled back by the check, but nothing refused it at its source. It now returns an error, for every caller. - whole_path() took Pieces.front() of a track the cutter gave no pieces of; the switch track is refused with the reason. - Sonar: the turnout lookups of the node and network checks are guarded (S2259), the search of the free transition and the test loops count in integers (S2193; 2 m steps, the same values as their sum), the seeded generator of the turnout edits is marked (S2245). * fix(editor): file names outside the code page don't crash the project, includes are found in any case, a project file cut short isn't put in place - The scenario index made a string of the name of every file in the folder, which throws on Windows for a name the ANSI code page can't hold (the class of GE#560). It looks at the extension first and leaves out a .scn the game couldn't open by its name either; the messages of the project file show paths as UTF-8. - The includes are read with the FileCased() fallback of the game (scenery_text::file_text), so on Linux an include written in another case no longer drops the scenario from the index, skips the migration of its file or marks its tracks as changed by hand. - save() closes the file before looking at it: a failed last flush no longer renames a truncated .new over the project. - "next node 0" is refused instead of wrapping to 0xffffffff. - open_project() writes no .eu07proj when there were no //$ lines to migrate, and asks exists() without throwing. * fix(editor): the checkbox of the terrain around the camera in the layers shows the answer Without terrain of the scenery open * fix(editor): the lay panel says "Laid" only while the step it was laid with is on top of the history lay_panel_state() told the line laid from laid_step == m_history.size(). Lay, Ctrl+Z, then any one-step edit made the size the same again, and the panel said "Laid … Ctrl+Z undoes" for a line that was gone; at the cap of 200 steps it stayed "laid" for good. The panel now compares the serial of the step on top of the history (EditorSnapshot::serial), which each step made has of its own. * fix(editor): migrated switches leave to the side their records say, bent ones migrate, a record fitting two types isn't guessed - The migration mapped L to hand 1, but switch_store::classify() writes R where the diverging end lies to the positive cross of the direction, which is the side of hand 1 of the domain (its curvature above 0 turns that way). Every migrated switch came out mirrored, and the test checked hand == 1 for an L record without looking at where the diverging end lies. R is hand 1 now, and the test checks the side of the diverging end. - classify() writes a switch bent into a curve as Rlj or Rld with the radius of the ordinary switch it's bent from; the catalogue has it as an Rz, so no bent switch could migrate. They're looked up as Rz. - catalogue_type() took the first loose match. A movable nose isn't in the record, so the ordinary frog is taken where the catalogue has both; a record fitting two other types (the variants of an Rpd) is kept as it was, why with it. - Slips and crossings are kept as they were, as the header of the migration says. - Smaller: the type looked up is checked before its length is read; new diverging, slip and crossing tracks get the chainage of the turnout as a diverging track had before; the walk of a bent transition stops on a step that turned nothing instead of dividing by it. - Sonar: the leg check skips an end whose turnout isn't found (S2259), the spacing of a crossover is measured in whole steps counted in an integer (S2193), the seeded generator of the turnout kinds test is marked (S2245). * fix(editor): a save writing some tracks of a line keeps the records of the others, a plan edit refused in part changes nothing - record_written() erased every record of the line and added only the pieces written in this save, while the scenery writes only the tracks changed since. After a gizmo move and Ctrl+Z on one track of a line, the next save kept a record of that track alone: on reopening the line owned one track, and the next Plan edit left the others as duplicates. The records of the tracks the line still has and this save didn't write now stay. - model_run() kept each command before trying the next: with the radius of one vertex carried out and the cant of the next refused, the first stayed changed under "Refused, nothing changed". Several commands are now all tried on a copy first. - The fingerprint of the scenario index made a string of every file name before its .scn filter, which throws on Windows outside of the code page, on a detached thread (the class of GE#560). The extension is looked at first, as in the index itself; scenery_text::name_of() and has_extension() are shared by both. - A Del deferred by the check of the scenarios reads Shift as it was at the key press, not at the click on "go on". - open_project() writes no project file for a map with nothing to migrate (#461): the session test expects that. * fix(editor): the pieces of a cut old track get its events as the simulator fires them, its joints follow a line laid anew - keep_old_tracks() kept all the events on the first piece of an old track. The simulator fires event1 as a vehicle enters a track at its Point2, event2 at its Point1 and event0 while it stands on it (TrkFoll.cpp), so with a 120 m track cut into 40 and 80 m a train running towards Point1 got event1 about 80 m late, and one standing on the second piece no event0. Now each piece gets event0/eventall0, the piece at Point1 event2/eventall2 and the piece at Point2 event1/eventall1. The keywords are compared in any case, as the simulator lowers its tokens. - The joints of the old tracks kept their chainages through move_vertex, set_vertex, insert_vertex and remove_vertex: widening a 90° curve by 20 m shortens the line by about 8.6 m, and a joint past the new end was dropped, a short buffer-stop or signal track there with its name, events and circuit. Each joint now goes to the point of the new line nearest to where it was. solved_line::nearest() is shared with the crossover planner. - Sonar: the seeded generators of the takeover tests are marked (S2245), two dereferences after a REQUIRE too (S2259). * fix(editor): the plan preview follows a drag of the first or last vertex, "This path" lays beside the path alone, Esc clears the preview - model_plan_preview() keyed on vertex.position, which a drag of the first or the last vertex of a line with two or more curves doesn't change (it moves vertex.offset along the tangent of the end): the green or red line and the text of the norms froze after the first frame, and the release could be refused where the preview showed it within the norms. The key has the offset now. - parallel_build() laid the whole line with model_parallel beside a managed line whatever the scope, so "This path" on a 50 m track of a 2 km line previewed 50 m and laid 2 km. The model's parallel line is laid for the scope of the whole line only. - Esc during a handle drag restored the design but left the preview of the model on screen. * fix(editor): the assumptions of the project aren't lost with a project not saved, a texture field cleared is the lay tool's own again - With the editing on the model, setup_store() took the //$u lines out of the scenery and left the assumptions to the project of the model, which is written after the scenery and may fail to be: then they were in neither. The scenery keeps the line as well; the project's is read first, as before. - A texture typed into the assumptions and cleared again left the lay tool with the one typed: empty is the tool's own. * fix(editor): a photo origin aligned by hand isn't overridden by //$g, the 4K photos of the zoom take the tile under the camera alone - //$g of the scenery file went before the origin of //$o, also where the user had aligned the photo by hand in the editor: the alignment was gone on the next opening. An origin typed in the editor is written into //$o with the word "aligned", and such an origin goes before //$g. The word is optional: a release before it passes it over and reads the origin as before, and an //$o without it is read as before. "Use it" (the origin of //$g) takes the word off. - The zoom turned the 4K photos on for the 3 x 3 tiles around the camera, as the setting for them does: up to about 0.75 GB of the memory of the graphics card, unasked. By the zoom alone the 4K photo is the tile under the camera (about 85 MB); the setting keeps the 3 x 3. * fix(editor): a map opened on the model gets its project file also with nothing to migrate open_project() writes no project file when there are no //$ lines to migrate (#461), but the editing on the model relies on the map having its project file from the start: the self-test cases m_1_lay_managed and ps_2_setup_project failed with it absent. session::open() writes it when it isn't there. * fix(editor): the assumptions go into the project of the model, and back into the scenery only while it isn't saved The earlier fix kept the //$u line in the scenery whenever the editing is on the model, so ps_2_setup_project found the assumptions in the scenery where the project should hold them alone. They are taken out of the scenery again as before; when the scenery or the project of the model then fails to be saved, they go back into the scenery with its next save and stay there until the project is saved. * test(editor): nmtsettings grow sets the terrain while laying for the run only, the tester's eu07_editor.ini left as it was, as area does * fix(editor): the anchors section keeps its blank lines and comments, a reason keeps its blanks, a scenery including itself is told - The section kept for the anchors is written back as it was read: its blank lines and its # comments were dropped before the section was looked at. - The reason of a legacy record is the rest of the line as written, its blanks kept: joined with one blank, a reason of two blanks came back changed after a save and a load. - A file of a scenery including itself, on its own or through others, is told and not read again; before, only the depth of 32 stopped it. * test(editor): lf_1 opens the settings of the lay tool from the line of their summary and folds them again, through a new laysettings command * test(editor): the migration takes a bent switch (Rlj) for the Rz it's bent from, and keeps an Rpd record two types of the catalogue fit with why * fix(editor): a Plan apply is one step to undo, the setting of the model is taken when the scenery is opened, tracks taken away by hand are a change by hand - The commands of one Plan apply after the first are joined to it: one Ctrl+Z takes back the whole apply, none leaves the line half edited. - The setting "Editing on the model" is taken when the scenery is opened and kept for the session; changed meanwhile, the panel says it takes effect with the next scenery. Turned on later, an edit made the old way before was written back as the file had it; turned off before a save, the scenery was saved without its project. - A line of the model some of whose tracks another tool took away (a switch put in) counts as changed by hand, as it does after a reopen: each track knows how many tracks its line was made of. - A self-test which doesn't set the model leaves it off, whatever the tester's own eu07_editor.ini has. - What the generator can't make as the line has it is told with the notices of the command, not only logged. * fix(editor): an object past a split goes onto the part beyond it, the joints follow every line laid again, the old tracks read in any case and named apart - follow() anchors an object again also where its line now ends before it: a split keeps the id for the part before it, so an object past the split was clamped onto the end of that part. - The joints of the old tracks follow every line settle() lays again with a reshaping command, not only the line the command names: a taken-over line going on from a turnout of the line edited kept its joints at their old chainages. - velocity and none of an old track are read in any case, as the simulator lowers its tokens. - A line merged with one with no old tracks where it starts keeps that part out of the old tracks, rather than giving it the name and the circuit of the last old track of the first line. - _2... of the pieces of an old track pass over the names other old tracks of the line have. - The old records of a line are refused on read where they aren't on the line or not in their order. * fix(editor): the hand of a turnout commented as the code has it, an Apply with no edit adds no step, a profile opened drops the error of the one before, tests of the side - The comments of layoutCommands.hpp and layoutNetwork.hpp give hand 1 as right and -1 as left, as the migration and the inspector have it since #464 (R of a switch record). - The grade line of a line of the model applied with no edit: the breaks compared within a micrometre, the chainages having gone to the route and back; compared exactly, it added a step. - profile_open() clears the error of the route opened before. - Self-test expectations: modelpreview current (the preview worked out for the design as it is now, m_11), modelspacing signed by the side (m_13 to the right, -4.5 m), modelside of a switch (m_8 right, then left after the side is changed). * fix(editor): a project of the map not saved tells to save again while the assumptions of the project are in neither file * fix(editor): the area tiles failing offline logged once and retried on their own schedule, the terrain loads once the scenery is placed, failed tiles outlined on the ground - A tile of the download area failing again and again is logged the first time only; each retry wrote a line, the whole area every 5 min offline. - The queue of the area holds the tiles still to be fetched: the ones fetched go from it before a retry is added, it no longer grows by each retry. - A growth of the area keeps the tries of the tiles which failed, for the same photos: the ones waiting for their next try go on waiting, not asked for again all at once with the backoff started over. - "Place it..." in the line of the terrain: once the scenery is placed on the map, its terrain loads as the offer has it, and the line says so; it said the scenery wasn't placed and nothing loaded. - In the 3D view the outlines of the failed tiles lie on the ground the draped photo lies on, not at the height of the layer. - area_grow() looks at the area every 5 s whatever comes of it; set only by a growth, it ran every frame once 5 s had passed. * fix(editor): the outlines of the failed photo tiles don't keep the ground cache growing With the photo draped, the 3D view and the tiles failing (offline), draw_orthophoto_failures asked ground_heights for the corners of up to 400 tiles every frame. That gathered a 256 m ground tile per frame without end, and since every tile it asked for was used in that frame, the eviction stopped and the ground cache grew past its limit over the download area. The heights under the corners are now kept per failed tile. Two tiles are asked for a frame: one with a corner not found yet each second, one found all round each 30 s, as the ground under it may have come or changed since. The entries of the tiles no longer failing are dropped, and all of them when the photo is off or nothing fails. A corner not found yet is drawn at the height of the layer, as before. --- CMakeLists.txt | 1 + application/editorgestures.h | 2 +- application/editormode.cpp | 286 ++++++++++++++++-- application/editormode.h | 40 ++- application/editormodelay.cpp | 1 + application/editormodenmt.cpp | 182 ++++------- application/editormodeselftest.cpp | 10 +- application/editormodeselftestexpect.cpp | 19 +- application/editormodeselftestterrain.cpp | 23 +- application/editormodetrackux.cpp | 9 +- application/editormodeviewport.cpp | 59 ++++ application/editoruilayer.cpp | 2 + application/editoruilayer.h | 6 + application/scriptedinput.cpp | 2 +- application/uilayer.cpp | 17 +- application/uilayer.h | 5 +- editor/editorGeoMap.cpp | 70 ++++- editor/editorGeoMap.hpp | 15 +- editor/editorOrthophoto.cpp | 171 ++++++++--- editor/editorOrthophoto.hpp | 35 ++- editor/editorPhotoRules.cpp | 283 +++++++++++++++++ editor/editorPhotoRules.hpp | 88 ++++++ editor/editorRecords.cpp | 8 +- editor/editorRecords.hpp | 6 +- editor/editorSettings.cpp | 42 ++- editor/editorSettings.hpp | 16 +- lang/editor_pl.po | 133 ++++++-- launcher/scenery_wizard.cpp | 3 +- tests/editor/README.md | 14 +- tests/editor/cases/fs_3_without_terrain.txt | 8 +- tests/editor/cases/ph_1_photo_per_scenery.txt | 33 ++ .../editor/cases/ph_2_terrain_no_question.txt | 31 ++ tests/editor/cases/ph_3_tracks_over_photo.txt | 19 ++ tests/editor/cases/ph_4_toolbar_toggle.txt | 29 ++ tests/unit/CMakeLists.txt | 4 + tests/unit/test_photo_rules.cpp | 236 +++++++++++++++ 36 files changed, 1642 insertions(+), 266 deletions(-) create mode 100644 editor/editorPhotoRules.cpp create mode 100644 editor/editorPhotoRules.hpp create mode 100644 tests/editor/cases/ph_1_photo_per_scenery.txt create mode 100644 tests/editor/cases/ph_2_terrain_no_question.txt create mode 100644 tests/editor/cases/ph_3_tracks_over_photo.txt create mode 100644 tests/editor/cases/ph_4_toolbar_toggle.txt create mode 100644 tests/unit/test_photo_rules.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 33b764052..151b43f62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,6 +242,7 @@ set(SOURCES "editor/editorInfra.cpp" "editor/editorTerrainStreamer.cpp" "editor/editorOrthophoto.cpp" +"editor/editorPhotoRules.cpp" "editor/editorHttp.cpp" "editor/editorNmt.cpp" "editor/editorGeoMap.cpp" diff --git a/application/editorgestures.h b/application/editorgestures.h index 59c73aa63..c2d3710f6 100644 --- a/application/editorgestures.h +++ b/application/editorgestures.h @@ -99,7 +99,7 @@ struct gesture_word // "Ctrl+wheel", "Shift+click x4", "Drag a point", "Q W E": the keys and the parts of the mouse it names, the rest as text inline std::vector gesture_words(std::string const &Keys) { - static char const *const keys[]{"Ctrl", "Shift", "Alt", "Esc", "Del", "Enter", "Backspace", "Tab", "Space", "Home", "End", "PrtScr"}; + static char const *const keys[]{"Ctrl", "Shift", "Alt", "Esc", "Del", "Enter", "Backspace", "Tab", "Space", "Home", "End", "PrtScr", "~"}; auto const mouse = [](std::string const &Word) -> std::string { if (Word == "LMB" || Word == "click" || Word == "Click" || Word == "Press") return "LMB"; diff --git a/application/editormode.cpp b/application/editormode.cpp index f8f368761..516dbb276 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -31,6 +31,7 @@ extern char **environ; #include "application/application.h" #include "editor/editorKilometrage.hpp" #include "editor/editorSettings.hpp" +#include "editor/editorPhotoRules.hpp" #include "editor/editorModelSets.hpp" #include "editor/editorTrackPresets.hpp" #include "editor/editorIncludeInfo.hpp" @@ -67,6 +68,7 @@ extern char **environ; #include "utilities/Logs.h" #include #include +#include #include #include #include @@ -632,6 +634,7 @@ editor_mode::editor_mode() { road_select(nullptr); ground_sources(m_orthophoto); ui()->set_base_layers([this]() { render_base_layers(); }); + ui()->set_status_extra([this]() { render_orthophoto_status(); }); editor_track::observe(this); } @@ -643,10 +646,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; @@ -1646,6 +1647,8 @@ bool editor_mode::update() m_ortho_resident = resident; m_ortho_waiting = waiting; steps.step("terrain"); + orthophoto_zoom(); + area_grow(); m_orthophoto.update(Camera.Pos); steps.step("orthophoto"); update_wms_layers(); @@ -1657,6 +1660,7 @@ bool editor_mode::update() auto *background{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())}; background->PushClipRect(ImVec2(editor_ui::view_min().x, editor_ui::view_min().y), ImVec2(editor_ui::view_max().x, editor_ui::view_max().y), true); draw_orthophoto(); + draw_orthophoto_failures(); draw_nmt_pending(); area_update(); draw_download_area(); @@ -1792,7 +1796,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(); @@ -1934,6 +1937,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 @@ -2571,32 +2583,47 @@ void editor_mode::load_orthophoto_settings() config.drape = stored.drape; config.lift = stored.lift; config.in_scene = stored.in_scene; - config.north = 0.0; - config.east = 0.0; m_georeference_read = false; read_georeference(); - if (false == std::as_const(EditorSettings).orthophoto_origin(scenery, config.north, config.east) && m_georeference) - { - config.north = m_georeference_origin.x; - config.east = m_georeference_origin.y; - } - auto enabled{m_orthophoto.enabled()}; + std::optional remembered; + if (double north{0.0}, east{0.0}; std::as_const(EditorSettings).orthophoto_origin(scenery, north, east)) + remembered = glm::dvec2{north, east}; + // the scenery's own line: whether the photo is on, the wizard writes it on, and the origin the editor wrote along + std::optional scenery_on; + std::optional marked_origin; + bool marked_aligned{false}; m_orthophoto_mark.clear(); - if (auto const marked{scene::Layers.empty() ? std::vector{} : scene::Layers.marked(scene::layer_handle{1}, "//$o")}; false == marked.empty() && editor_orthophoto::read_mark(marked.front(), config, enabled)) + if (auto const marked{scene::Layers.empty() ? std::vector{} : scene::Layers.marked(scene::layer_handle{1}, "//$o")}; false == marked.empty()) { - m_orthophoto_mark = marked.front(); - m_orthophoto.enabled(enabled); - m_orthophoto_chosen = true; - WriteLog(format("Editor: the map settings of the scenery, orthophoto %s", enabled ? "on" : "off")); + editor_orthophoto::config mark; + bool on{false}; + if (editor_orthophoto::read_mark(marked.front(), mark, on)) + { + m_orthophoto_mark = marked.front(); + scenery_on = on; + if (mark.north != 0.0 || mark.east != 0.0) + marked_origin = glm::dvec2{mark.north, mark.east}; + marked_aligned = mark.aligned; + } } - // the user's choice stands over the scenery's; turned on only where the scenery lies on the map, a fictional one has nothing to - // show, and there it's left to the terrain model once the scenery is placed - if (auto const on{stored.on}; on.has_value() && (false == *on || config.north != 0.0 || config.east != 0.0)) + // //$g of the scenery file first: an origin the editor remembers for a scenery of the same name made elsewhere doesn't move it. One + // aligned by hand in the editor, //$o says so, goes before it + auto const origin{photo_rules::choose_origin(m_georeference ? std::optional{m_georeference_origin} : std::nullopt, marked_origin, remembered, marked_aligned)}; + config.north = origin.origin.x; + config.east = origin.origin.y; + config.aligned = marked_aligned && origin.from == photo_rules::origin_source::mark; + m_georeference_differs = origin.differs > photo_rules::origin_tolerance ? origin.differs : 0.0; + if (m_georeference_differs > 0.0) { - m_orthophoto.enabled(*on); - m_orthophoto_chosen = true; - WriteLog(format("Editor: the orthophoto %s, as the user left it", *on ? "on" : "off")); + WriteLog(format("Editor: the orthophoto laid out by //$g of the scenery file, the origin kept before was %.1f m off it", m_georeference_differs)); + ui()->set_status(format(STR_C("Photo: laid out by //$g of the scenery file; the origin kept before was %.0f m off it"), m_georeference_differs)); } + // on or off as the user left it in this scenery, else as the scenery keeps it; nothing said, off, and the terrain model turns + // it on where the scenery lies on the map + auto const switched{photo_rules::photo_on(std::as_const(EditorSettings).orthophoto_on(scenery), scenery_on)}; + m_orthophoto_chosen = switched.chosen; + m_orthophoto.enabled(switched.on); + WriteLog(format("Editor: the orthophoto %s%s", switched.on ? "on" : "off", false == switched.chosen ? ", nothing chosen in the scenery" : "")); m_orthophoto.settings(config); m_orthophoto_origin_edit = {config.north, config.east}; // the area the imagery and the terrain model are downloaded in, none in a scenery which has none @@ -2627,8 +2654,12 @@ void editor_mode::choose_orthophoto(bool const On) { m_orthophoto.enabled(On); m_orthophoto_chosen = true; - EditorSettings.orthophoto().on = On; - EditorSettings.save(); + // the scenery's: the photo of another one, the wizard's turned on, isn't turned off by it + if (false == m_orthophoto_scenery.empty()) + { + EditorSettings.orthophoto_on(m_orthophoto_scenery, On); + EditorSettings.save(); + } } void editor_mode::keep_nmt_settings() @@ -2689,6 +2720,8 @@ void editor_mode::render_orthophoto_ui() { config.north = m_orthophoto_origin_edit.x; config.east = m_orthophoto_origin_edit.y; + // aligned by hand: kept so in //$o, which //$g of the scenery file doesn't override when the scenery is opened again + config.aligned = true; changed = true; persist = true; } @@ -2698,13 +2731,16 @@ void editor_mode::render_orthophoto_ui() ImGui::TextDisabled(STR_C("in the scenery file: Y (easting) %.0f m, X (northing) %.0f m"), m_georeference_origin.y, m_georeference_origin.x); if (config.north != m_georeference_origin.x || config.east != m_georeference_origin.y) { - ImGui::SameLine(); + // //$g goes first when the scenery is opened, unless the origin was aligned here by hand, which //$o keeps + if (false == config.aligned) + ImGui::TextColored(ImVec4(1.0f, 0.75f, 0.2f, 1.0f), "%s", STR_C("Opened again, the scenery is laid out by //$g of its file")); if (ImGui::SmallButton(STR_C("Use it"))) { m_orthophoto_origin_edit.x = m_georeference_origin.x; config.north = m_orthophoto_origin_edit.x; m_orthophoto_origin_edit.y = m_georeference_origin.y; config.east = m_orthophoto_origin_edit.y; + config.aligned = false; changed = true; persist = true; } @@ -2860,6 +2896,8 @@ void editor_mode::render_orthophoto_ui() changed = true; persist = true; } + if (false == config.hires) + ImGui::TextDisabled("%s", STR_C("With the view zoomed in to 15 cm a pixel they come by themselves next to the camera")); if (ImGui::IsItemHovered()) ImGui::SetTooltip(STR_C("4096 px tiles (~6 cm/px) from the high-resolution orthophoto, for the tiles around the camera.\n" "Areas it doesn't cover use the standard imagery. Each 4K tile takes ~85 MB of video memory.")); @@ -2903,6 +2941,188 @@ void editor_mode::draw_orthophoto() (*layer)->draw(projection, Camera.Pos, io.DisplaySize.x, io.DisplaySize.y); } +double editor_mode::view_metres_per_pixel() const +{ + auto const &io{ImGui::GetIO()}; + if (io.DisplaySize.y <= 0.0f) + return 0.0; + if (Global.EditorOrtho) + return 2.0 * static_cast(Global.EditorOrthoExtent) / io.DisplaySize.y; + // in the 3d view the ground under the camera, as far below it as the terrain or the photo there is + double ground{static_cast(m_orthophoto.settings().height)}; + if (double height; EditorTerrain.height_at(Camera.Pos.x, Camera.Pos.z, height)) + ground = height; + auto const above{Camera.Pos.y - ground}; + if (above <= 0.0) + return 0.0; + return above * 2.0 * std::tan(glm::radians(Global.FieldOfView / Global.ZoomFactor) * 0.5) / io.DisplaySize.y; +} + +void editor_mode::orthophoto_zoom() +{ + // the 4K photos of the tiles around the camera by themselves once the view shows the ground at 15 cm a pixel or finer; asked of the + // service as the setting for them asks, the tile under the camera alone (the setting for them takes the 3 x 3 around it), so the zoom + // doesn't take some 0.75 GB of the memory of the graphics card by itself + auto const wanted{m_orthophoto.enabled() && photo_rules::hires_wanted(view_metres_per_pixel(), m_orthophoto.zoom_hires())}; + if (wanted != m_orthophoto.zoom_hires()) + { + m_orthophoto.zoom_hires(wanted); + WriteLog(format("Editor: the 4K photos around the camera %s, the view at %.3f m a pixel", wanted ? "on" : "off", view_metres_per_pixel())); + } +} + +void editor_mode::area_grow() +{ + // the area is carried along where the photo is looked at or the tracks are laid, now and then: the tiles added go to the disk + // cache in the background, a few at a time, as the rest of the area + auto const now{ImGui::GetTime()}; + if (now - m_area_grow_time < 5.0 || m_area_drawing.active || m_orthophoto.area().empty() || (false == m_orthophoto.enabled() && false == m_lay.active)) + return; + // every 5 s, whatever comes of it: set only by a growth, an area which didn't grow, or at its limit, was rastered and flood filled + // every frame + m_area_grow_time = now; + auto const &config{m_orthophoto.settings()}; + if (config.north == 0.0 && config.east == 0.0) + return; + std::vector points{{Camera.Pos.x, Camera.Pos.z}}; + if (m_lay.active) + { + points.emplace_back(m_lay.mouse.x, m_lay.mouse.z); + if (false == m_lay.points.empty()) + points.emplace_back(m_lay.points.back().x, m_lay.points.back().z); + } + std::size_t constexpr limit{1600}; // tiles of 256 m: about 105 sq km + for (auto const &point : points) + { + auto const grown{photo_rules::grow_area(m_orthophoto.area(), m_orthophoto.to_puwg(point), editor_orthophoto::tile_size, 1, 2, limit)}; + if (grown.limited) + { + if (false == m_area_grow_limited) + { + m_area_grow_limited = true; + m_area_grow_time = now; + ui()->set_status(format(STR_C("Photo: the download area is at its limit of %zu tiles; draw it again where it's needed, in Map > Orthophoto settings..."), limit)); + } + return; + } + if (grown.polygon.empty()) + continue; + m_area_grow_time = now; + m_orthophoto.area(grown.polygon); + WriteLog(format("Editor: the download area grown by %zu tiles at %.0f %.0f, %zu in all", grown.added, point.x, point.y, grown.total)); + ui()->set_status(format(STR_P("Photo: the download area grown by %zu tile at its edge, %zu in all", "Photo: the download area grown by %zu tiles at its edge, %zu in all", grown.added), grown.added, grown.total)); + return; + } +} + +namespace +{ +// the failed tiles drawn, the first of them; those after aren't outlined +std::size_t constexpr orthophoto_failures_drawn = 400; +} // namespace + +void editor_mode::ground_orthophoto_failures(std::vector> const &Failed) const +{ + // the tiles no longer failing forgotten + std::set> failing; + for (auto const &tile : Failed) + failing.emplace(tile.first.x, tile.first.y); + std::erase_if(m_orthophoto_failure_ground, [&failing](auto const &Entry) { return false == failing.contains(Entry.first); }); + + // two tiles asked for a frame: those with a corner not found yet each second, those found all round each 30 s, as the ground + // under them may have come or changed since + double const now{ImGui::GetTime()}; + int asked{0}; + auto const count{std::min(Failed.size(), orthophoto_failures_drawn)}; + for (std::size_t index = 0; index < count && asked < 2; ++index) + { + auto const &[low, high]{Failed[index]}; + auto &entry{m_orthophoto_failure_ground[{low.x, low.y}]}; + auto const complete{std::ranges::all_of(entry.found, [](bool const Found) { return Found; })}; + if (now - entry.asked < (complete ? 30.0 : 1.0)) + continue; + entry.asked = now; + ++asked; + std::vector const above{{low.x, 10000.0, low.y}, {high.x, 10000.0, low.y}, {high.x, 10000.0, high.y}, {low.x, 10000.0, high.y}}; + std::vector found; + auto const ground{ground_heights(above, false, &found)}; + for (std::size_t corner = 0; corner < entry.heights.size(); ++corner) + { + if (found[corner] == 0) + continue; + entry.heights[corner] = ground[corner]; + entry.found[corner] = true; + } + } +} + +void editor_mode::draw_orthophoto_failures() const +{ + if (false == m_orthophoto.enabled()) + { + m_orthophoto_failure_ground.clear(); + return; + } + auto const failed{m_orthophoto.failed()}; + if (failed.empty()) + { + m_orthophoto_failure_ground.clear(); + return; + } + // the tiles which failed outlined in red, with a cross over them: there's no photo there yet, it's tried again by itself + screen_projection const projection; + auto *drawlist{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())}; + auto const height{static_cast(m_orthophoto.settings().height)}; + // in the 3D view on the ground, where the photo draped over it lies: at the height of the layer they stood off the tiles they mark + // where the terrain lies well above or below it. Seen from above the height doesn't matter + auto const grounded{m_orthophoto.settings().drape && false == Global.EditorOrtho}; + auto const colour{IM_COL32(240, 70, 60, 210)}; + if (grounded) + ground_orthophoto_failures(failed); + std::size_t drawn{0}; + for (auto const &[low, high] : failed) + { + if (++drawn > orthophoto_failures_drawn) + break; + std::array corners{{{low.x, height, low.y}, {high.x, height, low.y}, {high.x, height, high.y}, {low.x, height, high.y}}}; + if (auto const entry{grounded ? m_orthophoto_failure_ground.find({low.x, low.y}) : m_orthophoto_failure_ground.end()}; entry != m_orthophoto_failure_ground.end()) + { + for (std::size_t i = 0; i < corners.size(); ++i) + corners[i].y = entry->second.found[i] ? entry->second.heights[i] : corners[i].y; + } + for (int i = 0; i < 4; ++i) + projection.line(drawlist, corners[i], corners[(i + 1) % 4], colour, 2.0f); + projection.line(drawlist, corners[0], corners[2], (colour & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 110), 1.5f); + projection.line(drawlist, corners[1], corners[3], (colour & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 110), 1.5f); + } +} + +void editor_mode::render_orthophoto_status() +{ + // in the status bar, after the status: the tiles which failed, why, and the button trying them again at once + if (false == m_orthophoto.enabled()) + return; + auto const stats{m_orthophoto.stats()}; + auto const count{static_cast(stats.failed + stats.area_failed)}; + if (count == 0) + return; + ImGui::SameLine(0.0f, ImGui::GetFontSize()); + auto text{format(STR_P("Photos: %zu tile not downloaded", "Photos: %zu tiles not downloaded", count), count)}; + if (auto const reason{m_orthophoto.last_failure()}; false == reason.empty()) + text += std::string{" ("} + STR(reason) + ")"; + ImGui::TextColored(ImVec4(1.0f, 0.55f, 0.35f, 1.0f), "%s", text.c_str()); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("%s", STR_C("They're marked red in the view and tried again by themselves, later and later, up to 5 min apart")); + ImGui::SameLine(); + ImGui::TextDisabled("%s", "\xc2\xb7"); + ImGui::SameLine(); + if (ImGui::SmallButton(STR_C("Retry##photos"))) + { + m_orthophoto.retry_failed(); + orthophoto_hurry(); + } +} + void editor_mode::draw_ortho_compass() const { if (false == Global.EditorOrtho) @@ -6345,8 +6565,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; @@ -6656,7 +6875,9 @@ void editor_mode::render_shortcuts_window() {"RMB held, W S A D", "Fly forwards, back, left, right (arrows in the legacy scheme)"}, {"RMB held, E / Q", "Fly up / down (Page Up / Page Down in the legacy scheme)"}, {"F", "Fly to the selected"}, - {"O", "Top view, orthographic"}}}, + {"O", "Top view, orthographic"}, + {"~", "The aerial photo shown or hidden, kept with the scenery"}, + {"Ctrl+~", "The photos of what the camera sees downloaded before the rest"}}}, {"Ride along the track", {{"Y", "Ride along the track under the cursor, the tools working on; Y again leaves"}, {"RMB held, W / S", "Drive; Shift faster, Ctrl+W / Ctrl+Down much faster"}, @@ -7852,7 +8073,8 @@ void editor_mode::on_key(int const Key, int const Scancode, int const Action, in } if (false == anyModifier) { - m_orthophoto.enabled(false == m_orthophoto.enabled()); + // as the button of the toolbar: the scenery's, and the terrain model doesn't turn it on again behind the user + choose_orthophoto(false == m_orthophoto.enabled()); ui()->set_status(m_orthophoto.enabled() ? STR("Orthophoto on (~)") : STR("Orthophoto off (~)")); } break; @@ -8550,7 +8772,7 @@ void editor_mode::render_camera_settings(bool const Window) void editor_mode::orthophoto_hurry() { if (false == m_orthophoto.enabled()) - m_orthophoto.enabled(true); + choose_orthophoto(true); // what the camera sees of the ground: rays through a grid over the screen to the level of the ground under the camera, or as far // as the reach of the orthophoto along it where they don't come down to it (the sky) ImGuiIO const &io = ImGui::GetIO(); diff --git a/application/editormode.h b/application/editormode.h index 48062325b..129514670 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -557,7 +557,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 @@ -694,9 +695,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(); @@ -928,8 +930,33 @@ class editor_mode : public application_mode, private editor_track::observer, pri // the user turned the orthophoto on or off, or the scenery keeps it so: the terrain model made, or the area drawn, leaves it as it // is then, it turns it on only where nobody chose bool m_orthophoto_chosen{false}; - // the user turns the orthophoto on or off: kept with the editor, for every scenery + // the user turns the orthophoto on or off: kept with the editor, for the scenery void choose_orthophoto(bool const On); + // the 4K photos by themselves while the view is zoomed in to 15 cm a pixel; the m a pixel of the view, the top view's or of the + // ground under the camera + void orthophoto_zoom(); + double view_metres_per_pixel() const; + // the download area carried along where the camera or the laying comes near its edge, told in the status line + void area_grow(); + double m_area_grow_time{-100.0}; + bool m_area_grow_limited{false}; + // 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; + // the heights of the ground under the corners of the tiles which failed, outlined on it in the 3D view. A few tiles are asked for + // each frame, and a tile whose corners were found only again once in a while, so that the outlines don't keep the tiles of the + // ground in use every frame and their cache growing past its limit + struct orthophoto_failure_ground + { + std::array heights{}; + std::array found{}; + double asked{-1.0e9}; + }; + void ground_orthophoto_failures(std::vector> const &Failed) const; + mutable std::map, orthophoto_failure_ground> m_orthophoto_failure_ground; + 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 @@ -956,6 +983,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri void render_viewport_overlays(); // the tools of the field of work, in the order of the toolbar void work_area_tools(std::vector &Buttons); + // the button of the toolbar of the key or the name given clicked, for the self-test; false: none such + bool press_toolbar(std::string const &Name); // the tools of the field of work in the toolbar, as icons with their names void render_toolbar_tools(); // what the row of the toolbar holds, written at its left end: the fields of work, the tools @@ -969,6 +998,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri bool m_georeference{false}; glm::dvec2 m_georeference_origin{0.0}; // northing, easting std::string m_georeference_line; + // //$g and the origin remembered or the one of //$o were apart, by that many m; //$g taken. 0: they weren't + double m_georeference_differs{0.0}; void read_georeference(); void draw_orthophoto(); void draw_ortho_compass() const; @@ -2535,6 +2566,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri track_hover split_spot() const; void update_track_hover(); void draw_track_lines() const; + mutable std::size_t m_track_lines_drawn{0}; // the paths draw_track_lines drew in the last frame, for the self-test // what the colours of the tracks in the view tell enum class track_colouring { plain, radius, speed, grade }; track_colouring m_track_colouring{track_colouring::plain}; diff --git a/application/editormodelay.cpp b/application/editormodelay.cpp index cf3e5ef47..b8dd757e7 100644 --- a/application/editormodelay.cpp +++ b/application/editormodelay.cpp @@ -2606,6 +2606,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 576db215b..9620bade3 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 @@ -2180,7 +2114,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(); @@ -2554,7 +2488,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(); @@ -2580,6 +2514,10 @@ void editor_mode::nmt_place_scenery(glm::dvec2 const &Point) state.under = false; state.anchors.clear(); state.anchor_cells.clear(); + // the line in the panel of the laying waited for the scenery to be placed on the map: its terrain loads now, as the offer has it. + // Left so, the line said the scenery wasn't placed and nothing loaded + if (state.prompt && false == state.offer_loading && m_nmt.placed()) + nmt_accept_offer(); } void editor_mode::nmt_offer() @@ -2590,8 +2528,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() @@ -2602,9 +2552,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 where the settings had it - // off; the model of the download area is put into the cache again if it was stopped + 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; state.declined = false; EditorSettings.terrain_while_laying(true); @@ -2618,6 +2568,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. For this scenery only: @@ -2625,8 +2576,10 @@ void editor_mode::nmt_decline_offer() state.grow = false; state.declined = true; 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)"); } bool editor_mode::nmt_area() const @@ -2634,56 +2587,39 @@ bool editor_mode::nmt_area() const return false == m_nmt_state.declined && EditorSettings.terrain_model().area; } -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 88d8121b2..ad7466912 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -124,7 +124,10 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // terrainfill ... the area outlined filled, as the fill tool does it // terrainturn the textures of the palette entry turned // terrainwater [size] material and repeat of a body of water; terrainwaterdefault -// orthophoto [in scene 0|1] the imagery layer on, placed and fitted as given +// orthophoto [in scene 0|1] the imagery layer on, placed and fitted as given; orthophoto off: turned +// off as the user does it, for the scenery; orthophoto forget: what the editor keeps of the photo of +// the scenery (whether it's on, its origin) forgotten +// toolbar the button of the toolbar of the field of work with the key or the name clicked (toolbar ~: the photo) // orthoarea ... | clear the download area through the points of the world, as drawn on the map; orthoareapause 0|1 // orthohires 0|1 the 4K tiles on or off; orthostats logs the tiles, the area and the requests made // orthosettings [on|radius|opacity|lift|height|year|hires|drape|scene ]... the settings of the orthophoto changed as its @@ -181,7 +184,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // mouse , mouseat the cursor moved to the point of the window, or to where the point of the scene is seen, as the mouse moves it // glide [shot] the cursor led to where the point is seen in steps, frames apart, a screenshot after each step with shot // button , wheel the buttons and the wheel of the mouse, with the keys held -// press , release , tap a key held, let go, or both (ctrl, shift, alt, esc, enter, backspace, del, space, tab, a..z, 0..9, f1..f12) +// press , release , tap a key held, let go, or both (ctrl, shift, alt, esc, enter, backspace, del, space, tab, grave (~), a..z, 0..9, f1..f12) // softcursor <0|1> the cursor drawn into the picture, for screenshots // type the characters typed into the text field with the focus // screenshot @@ -196,7 +199,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 terrain made by itself as it was before that answer, which leaves the settings be // 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/editormodeselftestexpect.cpp b/application/editormodeselftestexpect.cpp index 346f52ae7..8f75e9f5e 100644 --- a/application/editormodeselftestexpect.cpp +++ b/application/editormodeselftestexpect.cpp @@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "utilities/utilities.h" #include "world/Track.h" +#include "imgui/imgui.h" #include #include @@ -421,7 +422,10 @@ void expect_terrain(std::string const &What, std::istringstream &Words, std::map auto const state{States.find(key)}; if (state == States.end()) { - expectation(false, What, "no state " + key, "grow, area or prompt"); + std::string keys; + for (auto const &[name, value] : States) + keys += (keys.empty() ? "" : ", ") + name; + expectation(false, What, "no state " + key, keys); return; } expectation(state->second == (wanted != 0), What, state->second ? "1" : "0", std::to_string(wanted)); @@ -506,7 +510,8 @@ struct shown_state std::string refusal; // by the cursor, while it's shown std::string status_line; glm::dvec3 lay_cursor{0.0}; - std::map terrain; // grow, area, prompt + std::map terrain; // grow, area, prompt, loading, question + std::map photo; // on, chosen, zoom4k, tracksover std::string tool; std::map windows; // shortcuts, settings, weather, orthophoto std::optional selected; // where the node selected stands @@ -527,6 +532,8 @@ bool expect_shown(std::string const &Kind, std::string const &What, std::istring expect_lay_cursor(What, Words, Shown.lay_cursor); else if (Kind == "terrain") expect_terrain(What, Words, Shown.terrain); + else if (Kind == "photo") + expect_terrain(What, Words, Shown.photo); else if (Kind == "tool") expect_tool(What, Words, Shown.tool); else if (Kind == "window") @@ -605,7 +612,13 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com else { shown_state shown{m_switch.status, ui()->refusal_shown(), ui()->status_line(), m_lay.mouse, - {{"grow", m_nmt_state.grow}, {"area", nmt_area()}, {"prompt", m_nmt_state.prompt}}, tool_name(ui()->mode()), + {{"grow", m_nmt_state.grow}, + {"area", nmt_area()}, + {"prompt", m_nmt_state.prompt}, + {"loading", m_nmt_state.offer_loading}, + {"question", ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId)}}, + {{"on", m_orthophoto.enabled()}, {"chosen", m_orthophoto_chosen}, {"zoom4k", m_orthophoto.zoom_hires()}, {"tracksover", m_track_lines_drawn > 0}}, + tool_name(ui()->mode()), {{"shortcuts", m_shortcuts_open}, {"settings", m_settings_open}, {"weather", m_environment_open}, {"orthophoto", m_orthophoto_window}}, std::nullopt, shown_lay_panel(), shown_switch_panel()}; if (m_node != nullptr) diff --git a/application/editormodeselftestterrain.cpp b/application/editormodeselftestterrain.cpp index 9a288ba96..58846bd71 100644 --- a/application/editormodeselftestterrain.cpp +++ b/application/editormodeselftestterrain.cpp @@ -63,6 +63,14 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co WriteLog("SELFTEST orthophoto off"); return selftest_result::handled; } + if (words.str().find(" forget") != std::string::npos) + { + // what the editor keeps of the photo of the scenery forgotten: its choice and its origin, as for a scenery never opened + EditorSettings.orthophoto_forget(m_orthophoto_scenery); + EditorSettings.save(); + WriteLog("SELFTEST orthophoto forget " + m_orthophoto_scenery); + return selftest_result::handled; + } int fit{1}; int inscene{0}; float height{0.0f}; @@ -76,6 +84,15 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co WriteLog(format("SELFTEST orthophoto at %.0f %.0f, radius %d, %s%s", config.north, config.east, config.radius, config.drape ? "fitted" : "flat", config.in_scene ? ", in the scene" : "")); return selftest_result::handled; } + if (command == "toolbar") + { + // the button of the toolbar of the key or the name given clicked + std::string name; + words >> name; + auto const pressed{press_toolbar(name)}; + WriteLog(format("SELFTEST toolbar %s: %s, orthophoto %d", name.c_str(), pressed ? "pressed" : "no such button", m_orthophoto.enabled() ? 1 : 0)); + return selftest_result::handled; + } if (command == "orthoarea") { // the download area through the points of the world (x, z), as drawn on the map; clear: none @@ -514,8 +531,10 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co std::string answer; words >> answer; auto const &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") { auto const kept{std::pair{EditorSettings.terrain_while_laying(), model.area}}; @@ -533,7 +552,7 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co m_nmt_state.grow = m_selftest.terrain_kept->first; m_nmt_state.declined = m_selftest.terrain_kept->second; } - 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, nmt_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, nmt_area() ? 1 : 0)); return selftest_result::handled; } if (command == "nmtgrow") diff --git a/application/editormodetrackux.cpp b/application/editormodetrackux.cpp index 1bf87e3cc..3da13f52b 100644 --- a/application/editormodetrackux.cpp +++ b/application/editormodetrackux.cpp @@ -204,8 +204,12 @@ void editor_mode::draw_track_lines() const { auto const metres{ortho_metres_per_pixel()}; auto const colouring{ui()->mode() == nodebank_panel::TRACK ? m_track_colouring : track_colouring::plain}; - // the top view of the rails alone draws them in a colour of their own, as on a plan: both rails where they're apart on the screen - auto const rails{metres > 0.0 && Global.EditorOrthoTracks > 1 && colouring == track_colouring::plain}; + // the top view of the rails alone draws them in a colour of their own, as on a plan: both rails where they're apart on the screen. + // Under the photo drawn over the view the tracks laid would be hidden or dimmed: they're drawn over it zoomed in as well, their + // rails where they're apart, so the photo and the tracks are seen together + auto const photo{metres > 0.0 && m_orthophoto.enabled() && false == m_orthophoto.settings().in_scene && m_orthophoto.settings().opacity > 0.0f}; + auto const rails{metres > 0.0 && colouring == track_colouring::plain && (Global.EditorOrthoTracks > 1 || (photo && metres < kLinesFrom))}; + m_track_lines_drawn = 0; if (metres < kLinesFrom && colouring == track_colouring::plain && false == rails) return; auto const &io{ImGui::GetIO()}; @@ -226,6 +230,7 @@ void editor_mode::draw_track_lines() const bezier const curve{path}; if (false == plan_near(curve, centre, reach)) continue; + ++m_track_lines_drawn; auto colour{rails ? railcolour : IM_COL32(235, 235, 235, 150)}; if (colouring == track_colouring::radius) { diff --git a/application/editormodeviewport.cpp b/application/editormodeviewport.cpp index b9d44ad4d..0658b1c6d 100644 --- a/application/editormodeviewport.cpp +++ b/application/editormodeviewport.cpp @@ -39,6 +39,10 @@ struct editor_tool_button bool group{false}; // a gap before it, it starts another group bool enabled{true}; ImU32 accent{0}; // the colour of the family of the tool, 0 if it has none + // a slider of the value 0..1 in its place, its label and the value in per cent in it: the action applies the value as it's + // dragged, Done once it's let go + float *value{nullptr}; + std::function done; }; namespace @@ -174,6 +178,22 @@ void editor_mode::work_area_tools(std::vector &Buttons) add(track_tab::signals, true); add(track_tab::kilometrage, false); add(track_tab::lineside, false); + // the photo the tracks are laid over: shown or hidden for the scenery (~), and how much it covers, at hand + auto const photo{m_orthophoto.enabled()}; + Buttons.push_back({icon::orthophoto, STR_C("Photo"), "~", STR_C("The aerial photo of geoportal.gov.pl under the scenery, shown or hidden in this scenery"), photo, + [this, photo]() { choose_orthophoto(false == photo); }, true}); + if (photo && false == m_orthophoto.settings().in_scene) + { + static float opacity{0.6f}; + opacity = m_orthophoto.settings().opacity; + Buttons.push_back({icon::count, STR_C("Opacity"), nullptr, STR_C("How much the photo covers the scenery under it"), false, [this]() { + auto config{m_orthophoto.settings()}; + config.opacity = opacity; + m_orthophoto.settings(config); + }}); + Buttons.back().value = &opacity; + Buttons.back().done = [this]() { save_orthophoto_settings(); }; + } auto const advanced{m_track_tab == track_tab::turntable || srk_tab() || vehicle || m_track_tab == track_tab::profile || m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::norms || m_gauge.is_open()}; auto const more{EditorSettings.track_tools_more()}; Buttons.push_back({icon::more, more ? STR_C("Less") : STR_C("More"), nullptr, STR_C("Turntable, stations and their signals, line block, trainset, profile, speed, joints, gauge"), more, [more]() { @@ -244,6 +264,21 @@ void editor_mode::work_area_tools(std::vector &Buttons) } } +bool editor_mode::press_toolbar(std::string const &Name) +{ + std::vector buttons; + work_area_tools(buttons); + for (auto const &button : buttons) + if ((button.key != nullptr && Name == button.key) || Name == button.label) + { + if (false == button.enabled || false == static_cast(button.action)) + return false; + button.action(); + return true; + } + return false; +} + editor_mode::section_tool const &editor_mode::surroundings_tool(nodebank_panel::edit_mode const Mode) { // in the order of the edit modes: select, copy to bank, insert, brush, area fill @@ -416,6 +451,9 @@ void editor_mode::render_toolbar_tools() return Button.picture == icon::count || Names == names::all || (Names == names::chosen && Button.chosen); }; auto const width = [&](tool_button const &Button, names const Names) { + // a slider keeps its width, its label in it + if (Button.value != nullptr) + return std::round(std::max(96.0f * s, ImGui::CalcTextSize(Button.label).x + ImGui::CalcTextSize(" 100%").x + 2.0f * pad)); if (false == named(Button, Names)) return std::max(buttonheight, iconside + pad); auto result{2.0f * pad + ImGui::CalcTextSize(Button.label).x}; @@ -451,6 +489,27 @@ void editor_mode::render_toolbar_tools() } auto const size{ImVec2(width(button, shown), buttonheight)}; ImVec2 const position{x, top}; + if (button.value != nullptr) + { + // in the middle of the row, as high as a field + ImGui::SetCursorScreenPos(ImVec2(position.x, std::round(top + (buttonheight - ImGui::GetFrameHeight()) * 0.5f))); + ImGui::PushID(static_cast(index)); + ImGui::SetNextItemWidth(size.x); + int percent{static_cast(std::lround(*button.value * 100.0f))}; + if (ImGui::SliderInt("##value", &percent, 0, 100, (std::string{button.label} + " %d%%").c_str())) + { + *button.value = static_cast(percent) / 100.0f; + if (button.action) + button.action(); + } + if (ImGui::IsItemDeactivatedAfterEdit() && button.done) + button.done(); + if (ImGui::IsItemHovered() && false == ImGui::IsItemActive()) + button_tooltip(button); + ImGui::PopID(); + x = position.x + size.x; + continue; + } ImGui::SetCursorScreenPos(position); ImGui::PushID(static_cast(index)); auto const clicked{ImGui::InvisibleButton("##tool", size)}; diff --git a/application/editoruilayer.cpp b/application/editoruilayer.cpp index 35bc83045..57fec257e 100644 --- a/application/editoruilayer.cpp +++ b/application/editoruilayer.cpp @@ -659,6 +659,8 @@ void editor_ui::render_() else ImGui::TextUnformatted(m_layerspanel.status.c_str()); } + if (m_statusextra) + m_statusextra(); if (m_node != nullptr) { auto const name{m_node->name().empty() ? std::string{STR_C("(no name)")} : m_node->name()}; diff --git a/application/editoruilayer.h b/application/editoruilayer.h index a6bbbf6ec..eaa1b881a 100644 --- a/application/editoruilayer.h +++ b/application/editoruilayer.h @@ -196,6 +196,8 @@ class editor_ui : public ui_layer // what the cursor tells while it's shown, and the status line; for the expectations of the self-test std::string refusal_shown() const; std::string const &status_line() const { return m_layerspanel.status; } + // what the mode draws in the status bar after the status, a lasting state with a button of its own + void set_status_extra(std::function Renderer) { m_statusextra = std::move(Renderer); } private: // methods @@ -212,6 +214,9 @@ class editor_ui : public ui_layer void render_windows_menu() override; void render_tools_menu() override; int palette() const override; + // the panels of the editor are opaque: the 3d scene, drawn under the whole window, doesn't show through the docks around the view; + // a window over the view which wants to be seen through says so itself (SetNextWindowBgAlpha) + float window_alpha() const override { return 1.0f; } void render_dockspace() override; void render_() override; // docks the windows of the editor in their default places @@ -251,6 +256,7 @@ class editor_ui : public ui_layer double m_refusaltime{-100.0}; bool m_refusalnotice{false}; // a warning rather than a refusal double m_statustime{-100.0}; + std::function m_statusextra; int m_savequeued{0}; // the frame of a save asked for from a field being typed in bool m_tooloptionsopen{true}; bool m_inspectoropen{true}; diff --git a/application/scriptedinput.cpp b/application/scriptedinput.cpp index 8f35d8cfe..63cc0ec66 100644 --- a/application/scriptedinput.cpp +++ b/application/scriptedinput.cpp @@ -29,7 +29,7 @@ namespace int key_named(std::string const &Name) { static std::map const names{{"ctrl", GLFW_KEY_LEFT_CONTROL}, {"shift", GLFW_KEY_LEFT_SHIFT}, {"alt", GLFW_KEY_LEFT_ALT}, {"esc", GLFW_KEY_ESCAPE}, {"enter", GLFW_KEY_ENTER}, {"backspace", GLFW_KEY_BACKSPACE}, - {"del", GLFW_KEY_DELETE}, {"space", GLFW_KEY_SPACE}, {"tab", GLFW_KEY_TAB}}; + {"del", GLFW_KEY_DELETE}, {"space", GLFW_KEY_SPACE}, {"tab", GLFW_KEY_TAB}, {"grave", GLFW_KEY_GRAVE_ACCENT}}; if (auto const found{names.find(Name)}; found != names.end()) return found->second; if (Name.size() == 1 && std::isalpha(static_cast(Name[0]))) diff --git a/application/uilayer.cpp b/application/uilayer.cpp index 080623689..e1ab267c6 100644 --- a/application/uilayer.cpp +++ b/application/uilayer.cpp @@ -30,6 +30,7 @@ ImGuiIO *ui_layer::m_imguiio{nullptr}; GLint ui_layer::m_textureunit{GL_TEXTURE0}; bool ui_layer::m_cursorvisible; int ui_layer::m_palette{0}; +float ui_layer::m_window_alpha{-1.0f}; ImFont *ui_layer::font_default{nullptr}; ImFont *ui_layer::font_mono{nullptr}; ImFont *ui_layer::font_loading{nullptr}; @@ -182,9 +183,10 @@ void create_viewport_window(ImGuiViewport *Viewport) } } // namespace -void ui_layer::imgui_colors(int const Palette) +void ui_layer::imgui_colors(int const Palette, float const WindowAlpha) { m_palette = Palette; + m_window_alpha = WindowAlpha; auto const rgb = [](int const Color, float const Alpha = 1.0f) { return ImVec4(((Color >> 16) & 0xff) / 255.0f, ((Color >> 8) & 0xff) / 255.0f, (Color & 0xff) / 255.0f, Alpha); }; @@ -204,7 +206,7 @@ void ui_layer::imgui_colors(int const Palette) colors[ImGuiCol_Text] = rgb(editor ? 0xe6e8eb : 0xffffff); colors[ImGuiCol_TextDisabled] = rgb(editor ? 0x8a929c : 0xa0a0a2); - colors[ImGuiCol_WindowBg] = rgb(panel, Global.UIBgOpacity); // ui.bg.opacity from config file + colors[ImGuiCol_WindowBg] = rgb(panel, WindowAlpha); // ui.bg.opacity from config file, unless the ui has its own colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_PopupBg] = rgb(base, 0.98f); colors[ImGuiCol_Border] = rgb(border); @@ -261,7 +263,7 @@ void ui_layer::imgui_colors(int const Palette) void ui_layer::imgui_style() { - imgui_colors(0); + imgui_colors(0, Global.UIBgOpacity); // flat, square elements with thin borders auto &style = ImGui::GetStyle(); @@ -539,11 +541,16 @@ void ui_layer::render_internal() } } +float ui_layer::window_alpha() const +{ + return Global.UIBgOpacity; +} + void ui_layer::begin_ui_frame() { // the colours follow the ui of the mode drawn - if (palette() != m_palette) - imgui_colors(palette()); + if (palette() != m_palette || window_alpha() != m_window_alpha) + imgui_colors(palette(), window_alpha()); begin_ui_frame_internal(); render_dockspace(); m_dockspaceframe = ImGui::GetFrameCount(); diff --git a/application/uilayer.h b/application/uilayer.h index 69c4e08d3..03eb2667a 100644 --- a/application/uilayer.h +++ b/application/uilayer.h @@ -79,7 +79,7 @@ public: static bool init( GLFWwindow *Window ); static void imgui_style(); // colours of the user interface: 0 the green ones shared with the starter, 1 the amber ones of the editor - static void imgui_colors(int const Palette); + static void imgui_colors(int const Palette, float const WindowAlpha); // assign texturing hardware unit static void set_unit( GLint const Textureunit ) { m_textureunit = GL_TEXTURE0 + Textureunit; } @@ -154,7 +154,10 @@ protected: { return 0; } + // how opaque the windows of this ui are: the setting of the simulator, ui.bg.opacity, unless the ui says otherwise + virtual float window_alpha() const; static int m_palette; // colours set at the moment + static float m_window_alpha; ui_log_panel m_logpanel { "Log", true }; bool m_suppress_menu = false; // if `true`, the menu at the top of the window will not be present bool m_menu_always = false; // if `true`, the menu is shown all the time, not only when the mouse is at the top of the window diff --git a/editor/editorGeoMap.cpp b/editor/editorGeoMap.cpp index 68b153559..f7ce4448e 100644 --- a/editor/editorGeoMap.cpp +++ b/editor/editorGeoMap.cpp @@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/. #include "stb/stb_image.h" #include +#include #include #include #include @@ -37,6 +38,8 @@ double constexpr kCentralMeridian{19.0}; glm::dvec2 const kPolandLow{140000.0, 120000.0}; glm::dvec2 const kPolandHigh{890000.0, 800000.0}; std::string const kMapService{"https://mapy.geoportal.gov.pl/wss/ext/OSM/BaseMap/service"}; +// the orthophoto of GUGiK, the service the photos under the scenery in the editor come from +std::string const kPhotoService{"https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMS/StandardResolution"}; double seconds() { @@ -179,6 +182,14 @@ void editor_map::release() m_texture = 0; } +void editor_map::photos(bool const Photos) +{ + if (Photos == m_photos) + return; + m_photos = Photos; + m_dirty = true; +} + void editor_map::pick(glm::dvec2 const &Point) { m_point = Point; @@ -248,7 +259,28 @@ bool editor_map::render(glm::vec2 const &Size) m_changed = seconds(); } } - auto const clicked{ImGui::IsItemDeactivated() && false == m_dragging}; + // the switch of the map and the photos in the top right corner: a click on it isn't a click on the map + auto const switch_labels{std::array{STR_C("Map"), STR_C("Photos")}}; + auto const pad{4.f}; + std::array switch_low{}; + std::array switch_high{}; + { + auto right{origin.x + Size.x - 6.f}; + for (int i = 1; i >= 0; --i) + { + auto const text{ImGui::CalcTextSize(switch_labels[i])}; + switch_high[i] = ImVec2(right, origin.y + 6.f + text.y + 2.f * pad); + switch_low[i] = ImVec2(right - text.x - 4.f * pad, origin.y + 6.f); + right = switch_low[i].x - 2.f; + } + } + auto const on_switch = [&](int const I) { return mouse.x >= switch_low[I].x && mouse.x < switch_high[I].x && mouse.y >= switch_low[I].y && mouse.y < switch_high[I].y; }; + auto clicked{ImGui::IsItemDeactivated() && false == m_dragging}; + if (clicked && (on_switch(0) || on_switch(1))) + { + photos(on_switch(1)); + clicked = false; + } if (clicked) { m_clicked = to_world(mouse); @@ -292,6 +324,33 @@ bool editor_map::render(glm::vec2 const &Size) drawlist->AddLine(ImVec2(at.x - 16.f, at.y), ImVec2(at.x + 16.f, at.y), colour, 2.f); drawlist->AddLine(ImVec2(at.x, at.y - 16.f), ImVec2(at.x, at.y + 16.f), colour, 2.f); } + // the switch drawn, the layer shown lit; the photos asked for but the map zoomed out too far for them told under it + for (int i = 0; i < 2; ++i) + { + auto const chosen{(i == 1) == m_photos}; + auto const over{hovered && on_switch(i)}; + drawlist->AddRectFilled(switch_low[i], switch_high[i], chosen ? IM_COL32(0, 120, 215, 235) : over ? IM_COL32(60, 60, 60, 220) : IM_COL32(0, 0, 0, 170), 4.f); + drawlist->AddText(ImVec2(switch_low[i].x + 2.f * pad, switch_low[i].y + pad), IM_COL32(255, 255, 255, 245), switch_labels[i]); + } + if (hovered && (on_switch(0) || on_switch(1))) + ImGui::SetTooltip("%s", STR_C("The aerial photos of geoportal.gov.pl, the same as under the scenery in the editor, once the map is zoomed in")); + // the photos shown: whose they are, in the corner under them, as the base map has it in its picture + if (m_texture != 0 && m_image_photo) + { + auto const text{STR_C("Imagery: GUGiK, geoportal.gov.pl")}; + auto const size{ImGui::CalcTextSize(text)}; + ImVec2 const at{origin.x + Size.x - size.x - 8.f, origin.y + Size.y - size.y - 6.f}; + drawlist->AddRectFilled(ImVec2(at.x - 4.f, at.y - 2.f), ImVec2(at.x + size.x + 4.f, at.y + size.y + 2.f), IM_COL32(0, 0, 0, 150), 3.f); + drawlist->AddText(at, IM_COL32(255, 255, 255, 220), text); + } + if (m_photos && m_scale > photo_scale) + { + auto const text{STR_C("Zoom in for the photos")}; + auto const size{ImGui::CalcTextSize(text)}; + ImVec2 const at{switch_high[1].x - size.x - 4.f, switch_high[1].y + 4.f}; + drawlist->AddRectFilled(ImVec2(at.x - 4.f, at.y - 2.f), ImVec2(at.x + size.x + 4.f, at.y + size.y + 2.f), IM_COL32(0, 0, 0, 170), 4.f); + drawlist->AddText(at, IM_COL32(255, 255, 255, 230), text); + } std::string info; if (hovered) { @@ -330,11 +389,15 @@ void editor_map::request(glm::vec2 const &Size) auto const high{m_centre + half}; char bbox[160]; std::snprintf(bbox, sizeof(bbox), "%.1f,%.1f,%.1f,%.1f", low.x, low.y, high.x, high.y); - auto const url{kMapService + "?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=osm&STYLES=&SRS=EPSG:2180&BBOX=" + bbox + "&WIDTH=" + std::to_string(width) + "&HEIGHT=" + std::to_string(height) + "&FORMAT=image/png"}; - m_request = std::async(std::launch::async, [url, low, high, closing = &m_closing]() { + // zoomed in the photos, as the orthophoto of the editor gives them; further out the map, the photos of a whole region aren't read + auto const photo{m_photos && m_scale <= photo_scale}; + auto const url{photo ? kPhotoService + "?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=Raster&STYLES=&SRS=EPSG:2180&BBOX=" + bbox + "&WIDTH=" + std::to_string(width) + "&HEIGHT=" + std::to_string(height) + "&FORMAT=image/jpeg" + : kMapService + "?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=osm&STYLES=&SRS=EPSG:2180&BBOX=" + bbox + "&WIDTH=" + std::to_string(width) + "&HEIGHT=" + std::to_string(height) + "&FORMAT=image/png"}; + m_request = std::async(std::launch::async, [url, low, high, photo, closing = &m_closing]() { image result; result.low = low; result.high = high; + result.photo = photo; std::vector data; thread_local editor_http::client client; if (false == client.get(url, data, result.error, [closing]() { return closing->load(); })) @@ -373,4 +436,5 @@ void editor_map::upload() m_texture = renderer != nullptr ? renderer->Create_Image(result.pixels.data(), result.width, result.height) : 0; m_image_low = result.low; m_image_high = result.high; + m_image_photo = result.photo; } diff --git a/editor/editorGeoMap.hpp b/editor/editorGeoMap.hpp index a1dd07124..fb527479f 100644 --- a/editor/editorGeoMap.hpp +++ b/editor/editorGeoMap.hpp @@ -31,8 +31,8 @@ bool in_poland(glm::dvec2 const &Point); } // namespace editor_geo -// the map of Poland to pick a place on: the base map of OpenStreetMap from geoportal.gov.pl, the wheel zooms it, a drag moves -// it, a click picks the place +// the map of Poland to pick a place on: the base map of OpenStreetMap from geoportal.gov.pl, or zoomed in the aerial photos of +// geoportal.gov.pl, the wheel zooms it, a drag moves it, a click picks the place class editor_map { public: @@ -63,6 +63,14 @@ class editor_map } // a line written at the bottom of the map, a word of what a click does there; empty: none void hint(std::string Text) { m_hint = std::move(Text); } + // the aerial photos of geoportal.gov.pl (the orthophoto the editor lays under the scenery, the same service) in place of the map + // where it's zoomed in enough to tell them apart; further out the map. Switched in the corner of the map + bool photos() const { return m_photos; } + // the image shown is of the photos, not of the map: whose it is, is told under it + bool photos_shown() const { return m_texture != 0 && m_image_photo; } + void photos(bool const Photos); + // m a pixel up to which the photos are shown, further out the map + static constexpr double photo_scale{40.0}; private: struct image @@ -73,6 +81,7 @@ class editor_map int height{0}; std::vector pixels; std::string error; + bool photo{false}; // of the aerial photos, not of the map }; void request(glm::vec2 const &Size); @@ -100,4 +109,6 @@ class editor_map std::vector m_outline; bool m_outline_closed{false}; std::string m_hint; + bool m_photos{true}; + bool m_image_photo{false}; // the image shown is of the photos, told under it }; diff --git a/editor/editorOrthophoto.cpp b/editor/editorOrthophoto.cpp index 4f41cf81b..d3ad6e2ab 100644 --- a/editor/editorOrthophoto.cpp +++ b/editor/editorOrthophoto.cpp @@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/. #include "editor/editorOrthophoto.hpp" #include "editor/editorHttp.hpp" #include "editor/editorGeometry.hpp" +#include "editor/editorPhotoRules.hpp" #include "editor/editorRecords.hpp" #include "rendering/renderer.h" @@ -761,12 +762,12 @@ bool editor_orthophoto::owns(gfx::geometry_handle const &Geometry) // the line of the scenery and its format: editor_records::orthophoto_line() and read_orthophoto() std::string editor_orthophoto::mark(config const &Config, bool const Enabled, bool const Origin) { - return editor_records::orthophoto_line(Enabled, Origin, Config.north, Config.east); + return editor_records::orthophoto_line(Enabled, Origin, Config.north, Config.east, Config.aligned); } bool editor_orthophoto::read_mark(std::string const &Text, config &Config, bool &Enabled) { - return editor_records::read_orthophoto(Text, Enabled, Config.north, Config.east); + return editor_records::read_orthophoto(Text, Enabled, Config.north, Config.east, &Config.aligned); } void editor_orthophoto::enabled(bool State) @@ -857,11 +858,27 @@ void editor_orthophoto::restart_prefetch() std::sort(keys.begin(), keys.end(), [&](tile_key const &A, tile_key const &B) { return distance(A) < distance(B); }); { std::lock_guard lock(m_mutex); + source const now{m_config.year, m_config.hires, m_config.service, m_config.layers}; + // the area grown, the photos the same: the tiles which failed keep their tries, and the ones waiting for the next one go on + // waiting, not asked for again all at once. Cleared, every growth started the backoff over, offline over and over + std::map> kept; + if (now == m_prefetch_source) + { + std::set const area(keys.begin(), keys.end()); + for (auto const &[key, retry] : m_prefetch_retry) + if (area.contains(key)) + kept.emplace(key, retry); + } + m_prefetch_failed.clear(); + for (auto const &[key, retry] : kept) + if (retry.second != std::numeric_limits::max()) + m_prefetch_failed.insert(key); + std::erase_if(keys, [this](tile_key const &Key) { return m_prefetch_failed.contains(Key); }); m_prefetch = std::move(keys); m_prefetch_next = 0; - m_prefetch_failed.clear(); + m_prefetch_retry = std::move(kept); m_prefetch_cached.clear(); - m_prefetch_source = source{m_config.year, m_config.hires, m_config.service, m_config.layers}; + m_prefetch_source = now; ++m_prefetch_generation; } m_wakeup.notify_all(); @@ -896,15 +913,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); @@ -975,13 +983,44 @@ void editor_orthophoto::retry_failed() // the tiles of the area which failed taken again { std::lock_guard lock(m_mutex); + m_prefetch.erase(m_prefetch.begin(), m_prefetch.begin() + static_cast(m_prefetch_next)); + m_prefetch_next = 0; for (auto const &key : m_prefetch_failed) m_prefetch.push_back(key); m_prefetch_failed.clear(); + m_prefetch_retry.clear(); + m_last_error.clear(); } m_wakeup.notify_all(); } +std::vector> editor_orthophoto::failed() const +{ + std::vector> result; + if (false == m_enabled) + return result; + std::set keys; + for (auto const &[key, t] : m_tiles) + if (t.failures > 0 && t.level == 0 && false == t.empty) + keys.insert(key); + { + std::lock_guard lock(m_mutex); + keys.insert(m_prefetch_failed.begin(), m_prefetch_failed.end()); + } + for (auto const &key : keys) + { + glm::dvec2 const corner = tile_corner(key); + result.emplace_back(corner - glm::dvec2{tile_size}, corner); + } + return result; +} + +std::string editor_orthophoto::last_failure() const +{ + std::lock_guard lock(m_mutex); + return m_last_error.empty() ? std::string{} : photo_rules::failure_reason(m_last_error); +} + editor_orthophoto::statistics editor_orthophoto::stats() const { statistics out; @@ -1022,11 +1061,11 @@ bool editor_orthophoto::outside_area(tile_key const &Key) const return false == m_area.empty() && 0 == m_area_tiles.count(Key); } -int editor_orthophoto::level_for(int Distance, bool Hires) +int editor_orthophoto::level_for(int Distance, int HiresReach) { // coarser imagery further away keeps the memory use of large radii in check - if (Distance <= 1) - return Hires ? hires_pixels : standard_pixels; + if (Distance <= HiresReach) + return hires_pixels; if (Distance <= 3) return standard_pixels; if (Distance <= 6) @@ -1034,6 +1073,13 @@ int editor_orthophoto::level_for(int Distance, bool Hires) return standard_pixels / 4; } +int editor_orthophoto::hires_reach() const +{ + if (m_config.hires) + return 1; + return m_zoom_hires ? 0 : -1; +} + editor_orthophoto::tile_key editor_orthophoto::camera_tile(glm::dvec3 const &Camera) const { double const east = m_config.east - Camera.x; @@ -1088,7 +1134,7 @@ void editor_orthophoto::schedule(tile_key const &Key, tile &Tile, int Level, std { std::lock_guard lock(m_mutex); m_queue.erase(std::remove_if(m_queue.begin(), m_queue.end(), [&](job const &Job) { return Job.key == Key; }), m_queue.end()); - m_queue.push_back(job{Key, Level, Alpha, source{m_config.year, m_config.hires, m_config.service, m_config.layers}, m_generation.load()}); + m_queue.push_back(job{Key, Level, Alpha, source{m_config.year, m_config.hires || m_zoom_hires, m_config.service, m_config.layers}, m_generation.load()}); } Tile.requested = Level; Tile.requested_alpha = Alpha; @@ -1117,8 +1163,9 @@ std::size_t editor_orthophoto::apply(result &Result, double Now) { if (current) { + // tried again later and later, never given up: the service comes back, or the connection does ++t.failures; - t.retry_at = (t.failures >= 5) ? std::numeric_limits::max() : Now + std::min(120.0, 5.0 * std::pow(2.0, t.failures - 1)); + t.retry_at = Now + photo_rules::retry_delay(t.failures); } return 0; } @@ -1220,6 +1267,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(); @@ -1333,11 +1381,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) { @@ -1373,6 +1425,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) @@ -1438,8 +1491,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}) @@ -1592,11 +1646,30 @@ void editor_orthophoto::update(glm::dvec3 const &Camera) return; tile_key const centre = camera_tile(Camera); - if (centre != m_camera_tile) { - m_camera_tile = centre; std::lock_guard lock(m_mutex); - m_focus = centre; + if (centre != m_camera_tile) + { + m_camera_tile = centre; + m_focus = centre; + } + // the tiles of the area which failed, tried again once their time comes; the ones fetched already go from the queue first, so it + // doesn't grow by each retry + bool again{false}; + for (auto it = m_prefetch_retry.begin(); it != m_prefetch_retry.end(); ++it) + if (it->second.second <= now && m_prefetch_failed.erase(it->first) > 0) + { + if (m_prefetch_next > 0) + { + m_prefetch.erase(m_prefetch.begin(), m_prefetch.begin() + static_cast(m_prefetch_next)); + m_prefetch_next = 0; + } + m_prefetch.push_back(it->first); + it->second.second = std::numeric_limits::max(); + again = true; + } + if (again) + m_wakeup.notify_all(); } int const radius = m_config.radius; auto const distance = [&](tile_key const &Key) { return std::max(std::abs(Key.first - centre.first), std::abs(Key.second - centre.second)); }; @@ -1645,12 +1718,11 @@ 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; - int const level = first_level(t, level_for(std::max(std::abs(dx), std::abs(dy)), m_config.hires)); + int const level = first_level(t, level_for(std::max(std::abs(dx), std::abs(dy)), hires_reach())); if (t.empty || (t.level == level && t.alpha == m_alpha) || (t.requested == level && t.requested_alpha == m_alpha) || now < t.retry_at) continue; schedule(key, t, level, m_alpha); @@ -1755,16 +1827,33 @@ void editor_orthophoto::worker() auto const ok{prefetch_tile(client, request, error, stopping)}; if (m_stop) return; - if (!ok) - ErrorLog("Editor orthophoto: tile " + std::to_string(prefetch->second) + "_" + std::to_string(prefetch->first) + " of the download area failed: " + error); - std::lock_guard lock(m_mutex); - if (prefetchgeneration == m_prefetch_generation) + // a tile failing again and again, offline say, is logged the first time: each retry logged, the log grew by the whole area + // every 5 min + bool again{false}; { - if (ok) - m_prefetch_cached.insert(*prefetch); - else - m_prefetch_failed.insert(*prefetch); + std::lock_guard lock(m_mutex); + if (prefetchgeneration == m_prefetch_generation) + { + if (ok) + { + m_prefetch_cached.insert(*prefetch); + m_prefetch_retry.erase(*prefetch); + } + else + { + // tried again later and later, up to 5 min apart, never given up + m_prefetch_failed.insert(*prefetch); + auto &retry{m_prefetch_retry[*prefetch]}; + again = retry.first > 0; + ++retry.first; + retry.second = steady_seconds() + photo_rules::retry_delay(retry.first); + if (error != "cancelled") + m_last_error = error; + } + } } + if (false == ok && false == again) + ErrorLog("Editor orthophoto: tile " + std::to_string(prefetch->second) + "_" + std::to_string(prefetch->first) + " of the download area failed: " + error); continue; } @@ -1794,7 +1883,14 @@ void editor_orthophoto::worker() if (m_stop) return; if (!out.ok && error != "superseded") + { ErrorLog(std::string("Editor orthophoto: tile ") + std::to_string(current.key.second) + "_" + std::to_string(current.key.first) + " failed: " + error); + if (error != "cancelled") + { + std::lock_guard lock(m_mutex); + m_last_error = error; + } + } if (out.ok && current.alpha < 255) for (std::size_t i = 3; i < picture.rgba.size(); i += 4) picture.rgba[i] = static_cast((picture.rgba[i] * current.alpha + 127u) / 255u); @@ -1852,7 +1948,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; @@ -1975,7 +2072,7 @@ bool editor_orthophoto::hurry_tile(tile_key const &Key, int const Distance) t.empty = true; if (t.empty) return false; - auto const level{first_level(t, level_for(Distance, m_config.hires))}; + auto const level{first_level(t, level_for(Distance, hires_reach()))}; t.retry_at = 0.0; if (t.level == level && t.alpha == m_alpha) return false; // already shown as it should be diff --git a/editor/editorOrthophoto.hpp b/editor/editorOrthophoto.hpp index b56052e7e..3a046d8ca 100644 --- a/editor/editorOrthophoto.hpp +++ b/editor/editorOrthophoto.hpp @@ -17,6 +17,7 @@ http://mozilla.org/MPL/2.0/. #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ class editor_orthophoto { double north{0.0}; // PUWG 1992 X (northing) of the scenery origin double east{0.0}; // PUWG 1992 Y (easting) of the scenery origin + bool aligned{false}; // the origin aligned by hand in the editor: //$o says so, and //$g of the scenery file doesn't override it int radius{2}; // tiles loaded around the camera tile (Chebyshev distance) float height{0.0f}; // world Y of the layer (with drape: only where no ground was found) float opacity{0.6f}; // 0..1 @@ -116,12 +118,18 @@ 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; } + bool zoom_hires() const { return m_zoom_hires; } + // the tiles around the camera, and the ones of the area, which failed and wait to be tried again: their rectangles (x, z) + std::vector> failed() const; + // why the last download that failed did, in plain words (an English message, see photo_rules::failure_reason); empty: none failed + std::string last_failure() const; // the area the imagery is downloaded in, a polygon of PUWG 1992 (easting, northing): its tiles go to the disk cache in the // background, the products the settings ask for, and no tile outside it is asked for around the camera. Empty: no area, the // tiles around the camera as before @@ -194,6 +202,8 @@ class editor_orthophoto bool hires{false}; std::string service; std::string layers; + + bool operator==(source const &) const = default; }; struct job @@ -242,6 +252,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; @@ -253,7 +264,10 @@ class editor_orthophoto bool scene_dirty{true}; // the shape needs to be rebuilt }; - static int level_for(int Distance, bool Hires); + static int level_for(int Distance, int HiresReach); + // how many tiles away from the camera the 4K photos reach: 1 with the setting for them, the 3 x 3 tiles around it; 0 by the zoom + // alone, the tile under the camera, about 85 MB of the memory of the graphics card rather than 0.75 GB; -1 none + int hires_reach() const; // the level a tile is asked for at first: a tile showing nothing yet takes the standard image before the 4K one static int first_level(tile const &Tile, int Level); // the tile is outside the download area set, which then has no imagery asked for it @@ -270,8 +284,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); @@ -291,7 +303,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 @@ -316,7 +330,10 @@ class editor_orthophoto std::vector m_prefetch; std::size_t m_prefetch_next{0}; std::set m_prefetch_failed; + // of the ones which failed, how many times they did and when they're tried again + std::map> m_prefetch_retry; std::set m_prefetch_cached; + std::string m_last_error; // the last failure, as the service or the connection told it bool m_prefetch_paused{false}; source m_prefetch_source; std::uint32_t m_prefetch_generation{0}; diff --git a/editor/editorPhotoRules.cpp b/editor/editorPhotoRules.cpp new file mode 100644 index 000000000..67b092b50 --- /dev/null +++ b/editor/editorPhotoRules.cpp @@ -0,0 +1,283 @@ +/* +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 "editor/editorPhotoRules.hpp" +#include "editor/editorGeometry.hpp" + +#include +#include +#include +#include +#include +#include + +namespace photo_rules +{ + +namespace +{ + +using square = std::pair; + +bool known(std::optional const &Origin) +{ + return Origin.has_value() && (Origin->x != 0.0 || Origin->y != 0.0); +} + +// the squares 4-connected, the holes in them filled; empty when they aren't one piece +std::set filled(std::set const &Squares) +{ + if (Squares.empty()) + return {}; + int constexpr steps[4][2]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; + { + std::set reached{*Squares.begin()}; + std::deque next{*Squares.begin()}; + while (false == next.empty()) + { + auto const at{next.front()}; + next.pop_front(); + for (auto const &step : steps) + if (square const beside{at.first + step[0], at.second + step[1]}; Squares.contains(beside) && reached.insert(beside).second) + next.push_back(beside); + } + if (reached.size() != Squares.size()) + return {}; + } + // the empty squares reached from beyond the edge of the box around them, the others are holes + square low{*Squares.begin()}; + square high{*Squares.begin()}; + for (auto const &at : Squares) + { + low = {std::min(low.first, at.first), std::min(low.second, at.second)}; + high = {std::max(high.first, at.first), std::max(high.second, at.second)}; + } + low = {low.first - 1, low.second - 1}; + high = {high.first + 1, high.second + 1}; + std::set outside{low}; + std::deque next{low}; + while (false == next.empty()) + { + auto const at{next.front()}; + next.pop_front(); + for (auto const &step : steps) + { + square const beside{at.first + step[0], at.second + step[1]}; + if (beside.first < low.first || beside.second < low.second || beside.first > high.first || beside.second > high.second || Squares.contains(beside)) + continue; + if (outside.insert(beside).second) + next.push_back(beside); + } + } + std::set result; + for (int y = low.second; y <= high.second; ++y) + for (int x = low.first; x <= high.first; ++x) + if (false == outside.contains({x, y})) + result.insert({x, y}); + return result; +} + +std::vector outline_of(std::set const &Squares, double const Size, double const Inset) +{ + // the edges along which a square of the set meets one which isn't, the set on their left: counter-clockwise around it + std::map edges; // from a corner to the next one + auto const add = [&](square const From, square const To) { edges[From] = To; }; + for (auto const &[x, y] : Squares) + { + if (false == Squares.contains({x, y - 1})) + add({x, y}, {x + 1, y}); + if (false == Squares.contains({x + 1, y})) + add({x + 1, y}, {x + 1, y + 1}); + if (false == Squares.contains({x, y + 1})) + add({x + 1, y + 1}, {x, y + 1}); + if (false == Squares.contains({x - 1, y})) + add({x, y + 1}, {x, y}); + } + if (edges.empty()) + return {}; + std::vector corners; + auto const first{edges.begin()->first}; + auto at{first}; + do + { + corners.push_back(at); + auto const found{edges.find(at)}; + if (found == edges.end() || corners.size() > edges.size()) + return {}; + at = found->second; + } while (at != first); + // one outline goes around all of them, there are no holes + if (corners.size() != edges.size()) + return {}; + std::vector result; + auto const count{corners.size()}; + for (std::size_t i = 0; i < count; ++i) + { + auto const &previous{corners[(i + count - 1) % count]}; + auto const &here{corners[i]}; + auto const &next{corners[(i + 1) % count]}; + glm::dvec2 const in{static_cast(here.first - previous.first), static_cast(here.second - previous.second)}; + glm::dvec2 const out{static_cast(next.first - here.first), static_cast(next.second - here.second)}; + // the corners along a straight edge left out + if (in == out) + continue; + // the edges in and out moved inwards, onto their left: the corner where they meet then + glm::dvec2 const left_in{-in.y, in.x}; + glm::dvec2 const left_out{-out.y, out.x}; + result.push_back(glm::dvec2{here.first * Size, here.second * Size} + (left_in + left_out) * Inset); + } + return result; +} + +} // namespace + +origin_choice choose_origin(std::optional const &Georeference, std::optional const &Mark, std::optional const &Remembered, bool const MarkAligned) +{ + origin_choice result; + if (MarkAligned && known(Mark)) + { + result.origin = *Mark; + result.from = origin_source::mark; + return result; + } + if (known(Georeference)) + { + result.origin = *Georeference; + result.from = origin_source::georeference; + for (auto const *other : {&Mark, &Remembered}) + if (known(*other)) + result.differs = std::max(result.differs, glm::distance(**other, *Georeference)); + return result; + } + if (known(Mark)) + { + result.origin = *Mark; + result.from = origin_source::mark; + } + else if (known(Remembered)) + { + result.origin = *Remembered; + result.from = origin_source::remembered; + } + return result; +} + +switched photo_on(std::optional const &User, std::optional const &Scenery) +{ + if (User.has_value()) + return {*User, true}; + if (Scenery.has_value()) + return {*Scenery, true}; + return {false, false}; +} + +double retry_delay(int const Failures) +{ + if (Failures <= 0) + return 0.0; + return std::min(retry_most, 5.0 * std::pow(2.0, std::min(Failures, 20) - 1)); +} + +bool hires_wanted(double const MetresPerPixel, bool const Now) +{ + if (MetresPerPixel <= 0.0) + return false; + return MetresPerPixel <= (Now ? hires_until : hires_from); +} + +std::string connection_reason(std::string const &Error) +{ + auto const has = [&](char const *Text) { return Error.find(Text) != std::string::npos; }; + // 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("12017") || has("onnect")) + return "the server can't be reached"; + 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 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")) + return "the photo came damaged"; + if (has("too large") || has("larger")) + return "the photo came too large"; + return "the download failed"; +} + +std::vector squares_outline(std::vector> const &Squares, double const Size, double const Inset) +{ + auto const whole{filled({Squares.begin(), Squares.end()})}; + if (whole.empty()) + return {}; + return outline_of(whole, Size, Inset); +} + +growth grow_area(std::vector const &Polygon, glm::dvec2 const &Point, double const Tile, int const Margin, int const Reach, std::size_t const Limit) +{ + growth result; + if (Polygon.size() < 3 || Tile <= 0.0) + return result; + auto const found{geometry::squares_in(Polygon, Tile)}; + std::set const area{found.begin(), found.end()}; + result.total = area.size(); + if (area.empty()) + return result; + square const centre{static_cast(std::floor(Point.x / Tile)), static_cast(std::floor(Point.y / Tile))}; + // far from the area the point is elsewhere, not at its edge: the area isn't carried after it + auto nearest{std::numeric_limits::max()}; + for (auto const &at : area) + nearest = std::min(nearest, std::max(std::abs(at.first - centre.first), std::abs(at.second - centre.second))); + if (nearest > Margin) + return result; + auto grown{area}; + for (int dy = -Reach; dy <= Reach; ++dy) + for (int dx = -Reach; dx <= Reach; ++dx) + grown.insert({centre.first + dx, centre.second + dy}); + if (grown.size() == area.size()) + return result; + auto const whole{filled(grown)}; + if (whole.empty()) + return result; + if (whole.size() > Limit) + { + result.limited = true; + return result; + } + // the polygon touches only the squares of the grid it's drawn over, a little inside their edges + result.polygon = outline_of(whole, Tile, std::min(1.0, Tile * 0.01)); + if (result.polygon.size() < 3) + { + result.polygon.clear(); + return result; + } + result.total = whole.size(); + result.added = whole.size() - area.size(); + return result; +} + +} // namespace photo_rules diff --git a/editor/editorPhotoRules.hpp b/editor/editorPhotoRules.hpp new file mode 100644 index 000000000..88b742ea8 --- /dev/null +++ b/editor/editorPhotoRules.hpp @@ -0,0 +1,88 @@ +/* +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 +#include +#include +#include +#include + +// the rules the aerial photo of the editor (editor_orthophoto) goes by, standing on their own: which origin of the scenery is +// taken, whether the photo is on, how the download area grows, when a tile is tried again, when the 4K photos come, and what a +// download that failed is told as +namespace photo_rules +{ + +// where the origin of the scenery comes from +enum class origin_source +{ + none, + georeference, // //$g of the scenery file, as Rainsted and the wizard write it + mark, // //$o of the scenery, written by the editor + remembered // the settings of the editor, per scenery +}; + +struct origin_choice +{ + glm::dvec2 origin{0.0}; // northing, easting + origin_source from{origin_source::none}; + // with //$g, how far the other origin known (the one remembered or the one of //$o) lies from it, the farther; 0 when none + double differs{0.0}; +}; + +// //$g goes first, as the file of the scenery says where it lies: an origin remembered by the editor for a scenery of the same name +// elsewhere, or one written into //$o with it, can't move it. Without //$g the editor's own //$o, then the one remembered. A //$o the +// user aligned by hand (MarkAligned, the word aligned in it) goes before //$g: the user moved the photo off it on purpose +origin_choice choose_origin(std::optional const &Georeference, std::optional const &Mark, std::optional const &Remembered, bool const MarkAligned = false); +// the origins further apart than that are told of +double constexpr origin_tolerance{1.0}; + +// the photo on or off: as the user left it in this scenery, else as the scenery keeps it (//$o on, the wizard writes it on), +// else off. Chosen: the terrain model doesn't turn it on by itself +struct switched +{ + bool on{false}; + bool chosen{false}; +}; +switched photo_on(std::optional const &User, std::optional const &Scenery); + +// a tile which failed is tried again after that many seconds, doubling from 5 s up to 5 min, and never given up for good +double retry_delay(int Failures); +double constexpr retry_most{300.0}; + +// the 4K photos (6 cm/px) by themselves when the view is zoomed in that far, m a pixel; off again only once zoomed out past the +// second value, so they don't come and go at the edge +double constexpr hires_from{0.15}; +double constexpr hires_until{0.25}; +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 +// tiles of the tiles of the area and the square isn't in it already; not past Limit tiles in all +struct growth +{ + std::vector polygon; // empty: the area stays as it is + std::size_t added{0}; // tiles + std::size_t total{0}; // tiles of the area grown, or of the area as it is when it can't grow + bool limited{false}; // it would grow past the limit +}; +growth grow_area(std::vector const &Polygon, glm::dvec2 const &Point, double Tile, int Margin, int Reach, std::size_t Limit); +// the outline of a set of squares of a grid of the size, 4-connected and with no holes, a little inside their edges (Inset m), so +// the squares it touches are the ones of the set and none beside; empty when the set isn't one piece +std::vector squares_outline(std::vector> const &Squares, double Size, double Inset); + +} // namespace photo_rules diff --git a/editor/editorRecords.cpp b/editor/editorRecords.cpp index 2bdf1825d..0795f1900 100644 --- a/editor/editorRecords.cpp +++ b/editor/editorRecords.cpp @@ -871,7 +871,7 @@ std::string camera_line(camera const &Camera) // //$o ------------------------------------------------------------------------------------------------------------------------------- // format of the line: on <0/1> [origin ] -std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East) +std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East, bool const Aligned) { // how the imagery is shown is the user's, kept with the editor (EditorSettings); the scenery keeps whether it's on and where the // scenery lies @@ -882,11 +882,13 @@ std::string orthophoto_line(bool const Enabled, bool const Origin, double const { std::snprintf(text, sizeof(text), " origin %.2f %.2f", North, East); result += text; + if (Aligned) + result += " aligned"; } return result; } -bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East) +bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East, bool *Aligned) { std::istringstream words{Line}; std::string key; @@ -898,6 +900,8 @@ bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, doub words >> Enabled; else if (key == "origin") words >> North >> East; + else if (key == "aligned" && Aligned != nullptr) + *Aligned = true; else continue; if (words.fail()) diff --git a/editor/editorRecords.hpp b/editor/editorRecords.hpp index 3cf25b761..e6e9dce29 100644 --- a/editor/editorRecords.hpp +++ b/editor/editorRecords.hpp @@ -136,8 +136,10 @@ std::string camera_line(camera const &Camera); // //$o, whether the orthophoto is on and, with Origin, where the scenery lies on the map, PUWG 1992 northing and easting; the settings // the older sceneries carry besides are passed over. returns: false if the line says none of it -std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East); -bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East); +// Aligned: the origin was aligned by hand in the editor, which //$g of the scenery file doesn't override; a release before it passes the +// word over +std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East, bool const Aligned = false); +bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East, bool *Aligned = nullptr); // //$z, the area the editor downloads the orthophoto and the terrain model in, PUWG 1992 easting northing: none, below 3 points std::vector area_lines(std::vector const &Polygon); diff --git a/editor/editorSettings.cpp b/editor/editorSettings.cpp index 380a0da36..34f90a5db 100644 --- a/editor/editorSettings.cpp +++ b/editor/editorSettings.cpp @@ -49,6 +49,7 @@ template void parse(std::string const &Text, Type_ &Out) } const std::string origin_prefix{"ortho_origin@"}; +const std::string on_prefix{"ortho_on@"}; const std::string offset_prefix{"nmt_offset@"}; // settings are whitespace separated key/value pairs, so the scenery name used in the key can't contain spaces @@ -107,7 +108,12 @@ bool editorSettings::load() std::ifstream stream(path); if (!stream.is_open()) return false; + read(stream); + return true; +} +void editorSettings::read(std::istream &stream) +{ std::string key, value; while (stream >> key >> value) { @@ -129,8 +135,10 @@ bool editorSettings::load() parse(value, m_orthophoto.lift); else if (key == "ortho_in_scene") m_orthophoto.in_scene = (value == "1"); - else if (key == "ortho_on") - m_orthophoto.on = (value == "1"); + // the photo turned on or off for every scenery, as an older editor kept it, is left behind: it's the scenery's now, and a + // global off hid the photo of the sceneries the wizard made with it on + else if (key.rfind(on_prefix, 0) == 0) + m_orthophoto_on[key] = (value == "1"); else if (key == "platform_edge") parse(value, m_platform_edge); else if (key == "signal_offset") @@ -238,7 +246,6 @@ bool editorSettings::load() m_terrain_model_offsets[key] = {offset, value.substr(separator + 1) == "1"}; } } - return true; } bool editorSettings::save() @@ -253,7 +260,12 @@ bool editorSettings::save() ErrorLog("failed to save editor settings"); return false; } + write(stream); + return true; +} +void editorSettings::write(std::ostream &stream) const +{ stream.imbue(std::locale::classic()); stream << "movement_scheme " << scheme_to_string(m_movement) << "\n"; stream << "ortho_radius " << m_orthophoto.radius << "\n"; @@ -264,8 +276,8 @@ bool editorSettings::save() stream << "ortho_drape " << (m_orthophoto.drape ? 1 : 0) << "\n"; stream << "ortho_lift " << m_orthophoto.lift << "\n"; stream << "ortho_in_scene " << (m_orthophoto.in_scene ? 1 : 0) << "\n"; - if (m_orthophoto.on.has_value()) - stream << "ortho_on " << (*m_orthophoto.on ? 1 : 0) << "\n"; + for (auto const &[key, on] : m_orthophoto_on) + stream << key << " " << (on ? 1 : 0) << "\n"; stream << "platform_edge " << m_platform_edge << "\n"; stream << "signal_offset " << m_signal_offset << "\n"; stream << "signal_plate_look " << m_signal_plate_look << "\n"; @@ -297,7 +309,25 @@ bool editorSettings::save() stream << origin.first << " " << origin.second.first << ";" << origin.second.second << "\n"; for (auto const &offset : m_terrain_model_offsets) stream << offset.first << " " << offset.second.first << ";" << (offset.second.second ? 1 : 0) << "\n"; - return true; +} + +std::optional editorSettings::orthophoto_on(std::string const &Scenery) const +{ + auto const lookup{m_orthophoto_on.find(scenery_key(on_prefix, Scenery))}; + if (lookup == m_orthophoto_on.end()) + return std::nullopt; + return lookup->second; +} + +void editorSettings::orthophoto_on(std::string const &Scenery, bool const On) +{ + m_orthophoto_on[scenery_key(on_prefix, Scenery)] = On; +} + +void editorSettings::orthophoto_forget(std::string const &Scenery) +{ + m_orthophoto_on.erase(scenery_key(on_prefix, Scenery)); + m_orthophoto_origins.erase(scenery_key(origin_prefix, Scenery)); } bool editorSettings::orthophoto_origin(std::string const &Scenery, double &North, double &East) const diff --git a/editor/editorSettings.hpp b/editor/editorSettings.hpp index 62720d534..c66bba7f5 100644 --- a/editor/editorSettings.hpp +++ b/editor/editorSettings.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -21,12 +22,15 @@ public: bool load(); bool save(); + // the settings as the file keeps them, read and written + void read(std::istream &Stream); + void write(std::ostream &Stream) const; movement_scheme movement() const { return m_movement; } void movement(movement_scheme scheme) { m_movement = scheme; } - // geoportal orthophoto layer (editor_orthophoto), how it's shown and whether it's on; the origin is kept per scenery, and the - // scenery keeps it too + // geoportal orthophoto layer (editor_orthophoto), how it's shown; whether it's on and the origin are kept per scenery, and the + // scenery keeps them too struct orthophoto_settings { int radius{2}; @@ -37,13 +41,16 @@ public: bool drape{true}; float lift{0.05f}; bool in_scene{false}; - // turned on or off by the user, for every scenery; none chosen yet: as the scenery keeps it, or the terrain model turns it on - std::optional on; }; orthophoto_settings &orthophoto() { return m_orthophoto; } // PUWG 1992 northing/easting of the scenery's (0,0,0) point; false when none was stored bool orthophoto_origin(std::string const &Scenery, double &North, double &East) const; void orthophoto_origin(std::string const &Scenery, double North, double East); + // the photo turned on or off by the user in the scenery; none: not chosen there yet, as the scenery keeps it + std::optional orthophoto_on(std::string const &Scenery) const; + void orthophoto_on(std::string const &Scenery, bool On); + // what's kept of the scenery's photo, its choice and its origin, forgotten + void orthophoto_forget(std::string const &Scenery); // the WMS layers the user added under the scenery, over the orthophoto, the top one first: the address of the service, the // layers asked of it, its title and terms as its capabilities gave them. Kept with the editor, not with the scenery struct wms_layer @@ -140,6 +147,7 @@ private: orthophoto_settings m_orthophoto; camera_settings m_camera; std::map> m_orthophoto_origins; + std::map m_orthophoto_on; std::vector m_wms_layers; double m_platform_edge{1.725}; double m_signal_offset{2.25}; diff --git a/lang/editor_pl.po b/lang/editor_pl.po index a7e20b842..a0b7b1eae 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" @@ -15379,3 +15361,118 @@ msgstr "Szyny##setuplook" msgid "Trackbed##setuplook" msgstr "Podsypka##setuplook" +# scenery editor: the aerial photo without fuss + +msgid "Photo: laid out by //$g of the scenery file; the origin kept before was %.0f m off it" +msgstr "Zdjęcie: ułożone według //$g pliku scenerii; zapamiętany wcześniej początek układu był o %.0f m dalej" + +msgid "Opened again, the scenery is laid out by //$g of its file" +msgstr "Po ponownym otwarciu sceneria będzie ułożona według //$g swojego pliku" + +msgid "With the view zoomed in to 15 cm a pixel they come by themselves next to the camera" +msgstr "Przy zbliżeniu widoku do 15 cm na piksel włączają się same przy kamerze" + +msgid "Photo: the download area is at its limit of %zu tiles; draw it again where it's needed, in Map > Orthophoto settings..." +msgstr "Zdjęcie: obszar pobierania doszedł do limitu %zu kafli; narysuj go na nowo tam, gdzie trzeba, w Mapa > Ustawienia ortofotomapy..." + +msgid "Photo: the download area grown by %zu tile at its edge, %zu in all" +msgid_plural "Photo: the download area grown by %zu tiles at its edge, %zu in all" +msgstr[0] "Zdjęcie: obszar pobierania powiększony przy krawędzi o %zu kafel, razem %zu" +msgstr[1] "Zdjęcie: obszar pobierania powiększony przy krawędzi o %zu kafle, razem %zu" +msgstr[2] "Zdjęcie: obszar pobierania powiększony przy krawędzi o %zu kafli, razem %zu" + +msgid "Photos: %zu tile not downloaded" +msgid_plural "Photos: %zu tiles not downloaded" +msgstr[0] "Zdjęcia: %zu kafla nie pobrano" +msgstr[1] "Zdjęcia: %zu kafli nie pobrano" +msgstr[2] "Zdjęcia: %zu kafli nie pobrano" + +msgid "They're marked red in the view and tried again by themselves, later and later, up to 5 min apart" +msgstr "Są zaznaczone w widoku na czerwono i ponawiane same, coraz rzadziej, najwyżej co 5 min" + +msgid "no connection to the internet: the name of the server isn't found" +msgstr "brak połączenia z internetem: nie znaleziono nazwy serwera" + +msgid "the server didn't answer in time" +msgstr "serwer nie odpowiedział na czas" + +msgid "the server can't be reached" +msgstr "nie można połączyć się z serwerem" + +msgid "the secure connection to the server failed" +msgstr "nie udało się nawiązać bezpiecznego połączenia z serwerem" + +msgid "the server is busy or out of order" +msgstr "serwer jest przeciążony albo nie działa" + +msgid "the server has no photo of the place" +msgstr "serwer nie ma zdjęcia tego miejsca" + +msgid "the server refused the request" +msgstr "serwer odrzucił żądanie" + +msgid "the server sent an error in place of the photo" +msgstr "serwer przysłał błąd zamiast zdjęcia" + +msgid "the photo came damaged" +msgstr "zdjęcie przyszło uszkodzone" + +msgid "the photo came too large" +msgstr "zdjęcie przyszło za duże" + +msgid "the download failed" +msgstr "pobieranie się nie udało" + +msgid "Retry##photos" +msgstr "Ponów##photos" + +msgid "The aerial photo shown or hidden, kept with the scenery" +msgstr "Zdjęcie lotnicze pokazane albo ukryte, zapamiętane dla scenerii" + +msgid "The photos of what the camera sees downloaded before the rest" +msgstr "Zdjęcia tego, co widzi kamera, pobierane przed resztą" + +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 "Photo" +msgstr "Zdjęcie" + +msgid "The aerial photo of geoportal.gov.pl under the scenery, shown or hidden in this scenery" +msgstr "Zdjęcie lotnicze z geoportal.gov.pl pod scenerią, pokazane albo ukryte w tej scenerii" + +msgid "How much the photo covers the scenery under it" +msgstr "Jak mocno zdjęcie przykrywa scenerię pod nim" + +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" + +msgid "Photos" +msgstr "Zdjęcia" + +msgid "The aerial photos of geoportal.gov.pl, the same as under the scenery in the editor, once the map is zoomed in" +msgstr "Zdjęcia lotnicze z geoportal.gov.pl, te same co pod scenerią w edytorze, po przybliżeniu mapy" + +msgid "Zoom in for the photos" +msgstr "Przybliż, by zobaczyć zdjęcia" diff --git a/launcher/scenery_wizard.cpp b/launcher/scenery_wizard.cpp index f982223ff..22b1e257b 100644 --- a/launcher/scenery_wizard.cpp +++ b/launcher/scenery_wizard.cpp @@ -267,7 +267,8 @@ void ui::scenerywizard_panel::render_form() wrapped(error_colour, m_status); ImGui::Spacing(); - wrapped_disabled(STR("Map: (c) OpenStreetMap contributors, served by geoportal.gov.pl")); + // whose the picture of the map is: the photos of GUGiK zoomed in, the base map of OpenStreetMap further out + wrapped_disabled(m_map.photos_shown() ? STR("Imagery: GUGiK, geoportal.gov.pl") : STR("Map: (c) OpenStreetMap contributors, served by geoportal.gov.pl")); } void ui::scenerywizard_panel::render_place() diff --git a/tests/editor/README.md b/tests/editor/README.md index f9ffa30b3..0c7325b6f 100644 --- a/tests/editor/README.md +++ b/tests/editor/README.md @@ -85,7 +85,8 @@ The expectations (`expect ...`), each logged as `SELFTEST PASS ` or | `expect refusal ` | what the cursor tells while it's shown (a refusal or a warning) holds the text, or doesn't | | `expect statusline ` | the status line of the editor (also shown in the layers window) holds the text, or doesn't | | `expect laycursor ` | the point the line of the lay tool goes to from its last point clicked, in the plan | -| `expect terrain <0\|1>` | the terrain model is made under the tracks as they're laid / around the camera within the download area / the question of the terrain of a new scenery is open | +| `expect terrain <0\|1>` | the terrain model is made under the tracks as they're laid / around the camera within the download area / the line of the terrain of a new scenery is shown in the panel of the laying / its terrain is being loaded in the background / a window asking (a modal popup) is open | +| `expect photo <0\|1>` | the aerial photo is shown / it was turned on or off by the user or the scenery (the terrain model leaves it be) / the 4K photos are asked for by themselves, the view zoomed in / the tracks were drawn over the view in the last frame (the top view) | | `expect laypanel ` | the state of the panel of the lay tool, as the step at its top tells it, and whether its settings are shown or folded to the line of their summary | | `expect switchpanel ` | the state of the panel of the switch tool, as the step at its top tells it | | `expect steps ` | the steps of the history Ctrl+Z takes back, the ones made together counted once: none made by a change refused | @@ -163,7 +164,7 @@ and the first steps in the editor (P1 of the plan of the editor's interface): | --- | --- | | `fs_1_preview_over_panel` | while the pointer is over a panel the line the lay tool shows stays as it was, no leg following the pointer under the panel; back over the view it follows again | | `fs_2_switch_refusal_cleared` | a switch refused is told in the panel of the switch tool and by the cursor, not in the status line as well, and what it told goes once the next switch is laid | -| `fs_3_without_terrain` | the answer Without terrain to the question of the terrain of a new scenery turns off the terrain made of the terrain model by itself: under the tracks as they're laid and around the camera within the download area | +| `fs_3_without_terrain` | Without terrain, the button of the line of the terrain of a new scenery (no question in a window any more), turns off the terrain made of the terrain model by itself: under the tracks as they're laid and around the camera within the download area | and the consistency of the interface of the editor (P2 of the plan of the editor's interface): @@ -204,6 +205,15 @@ and the rest of the editing on the model (E4b), with the setting on: | `m_13_parallel` | the parallel tool beside a line of the model lays a line of the model, its arc concentric at the spacing, one step | | `m_14_layer_origin` | a line of the model saved into a file under an origin and opened again: nothing taken for changed by hand, also after a second save | +and the aerial photo with no fuss (stage 3 of laying the tracks over the aerial photos): + +| case | checks | +| --- | --- | +| `ph_1_photo_per_scenery` | the photo turned on or off is the scenery's, kept with the editor: off over the wizard's `//$o on 1` after a reopen, on again after the next | +| `ph_2_terrain_no_question` | the first L in a new scenery placed on the map asks nothing: the terrain loads in the background, the line in the panel of the laying tells it, Without terrain stops it | +| `ph_3_tracks_over_photo` | in the top view zoomed in under 0.5 m a pixel the tracks are drawn over the photo; without the photo they aren't | +| `ph_4_toolbar_toggle` | the photo button of the toolbar of the tracks and ~ turn the photo on and off as the user's choice, the terrain of the model doesn't turn it on again; F1 lists ~ | + and the assumptions of the project and the norms enforced when laying (`editor-project-setup.md`): | case | checks | diff --git a/tests/editor/cases/fs_3_without_terrain.txt b/tests/editor/cases/fs_3_without_terrain.txt index b2b7c70d7..1a1711857 100644 --- a/tests/editor/cases/fs_3_without_terrain.txt +++ b/tests/editor/cases/fs_3_without_terrain.txt @@ -1,8 +1,9 @@ -# First steps: the answer Without terrain to the question of the terrain of a new empty scenery turns off the terrain made of the +# First steps: Without terrain, the button of the line of the terrain of a new empty scenery, turns off the terrain made of the # terrain model by itself: under the tracks as they're laid (the checkbox of the layers) and around the camera within the download # area (the checkbox of the terrain panel), so nothing of the model is asked for. For this scenery only: the settings, kept for the -# sceneries opened later, stay as they were (nmtquestion flat fails the run if they changed). The question asked as the first L -# in an empty scenery asks it (the fixture has tracks, so it isn't asked by itself) +# sceneries opened later, stay as they were (nmtquestion flat fails the run if they changed). The line is shown as the first L in an +# empty scenery shows it, in place of the question asked in a window before (the fixture has tracks, so it isn't shown by itself); the +# fixture isn't placed on the map, so nothing is loaded meanwhile wait 5 nmtsettings grow 1 wait 2 @@ -10,6 +11,7 @@ expect terrain grow 1 nmtquestion open wait 3 expect terrain prompt 1 +expect terrain question 0 nmtquestion flat wait 3 expect terrain prompt 0 diff --git a/tests/editor/cases/ph_1_photo_per_scenery.txt b/tests/editor/cases/ph_1_photo_per_scenery.txt new file mode 100644 index 000000000..9bb754db0 --- /dev/null +++ b/tests/editor/cases/ph_1_photo_per_scenery.txt @@ -0,0 +1,33 @@ +# The aerial photo is the scenery's. The wizard's //$o on 1 with nothing chosen in the scenery: on. Turned off with the button of the +# toolbar it stays off when the scenery is opened again, though the scenery says on; turned on again, on after a reopen. Kept with +# the editor, not with the save: the scenery isn't saved. The fixture isn't placed on the map, so no photo is downloaded +#> append //$o on 1 +wait 5 +# what an earlier run kept of the photo of this scenery forgotten +orthophoto forget +quit +#> reopen +wait 5 +expect photo on 1 +expect photo chosen 1 +tap f3 +wait 2 +toolbar ~ +wait 2 +expect photo on 0 +quit +#> reopen +wait 5 +# the user's off goes over the scenery's on +expect photo on 0 +tap f3 +wait 2 +toolbar ~ +wait 2 +expect photo on 1 +quit +#> reopen +wait 5 +expect photo on 1 +orthophoto forget +quit diff --git a/tests/editor/cases/ph_2_terrain_no_question.txt b/tests/editor/cases/ph_2_terrain_no_question.txt new file mode 100644 index 000000000..95304e3ef --- /dev/null +++ b/tests/editor/cases/ph_2_terrain_no_question.txt @@ -0,0 +1,31 @@ +# The first L in a new scenery asks nothing: where the scenery lies on the map the terrain loads in the background and a line in the +# panel of the laying tells it, with the button to go without; no window in the way of the laying. The fixture has tracks, so the +# offer is started as the first L starts it (nmtquestion open), after the scenery was placed on the map (in Warsaw, the photo of one tile) +wait 5 +nmtsettings grow 1 +wait 2 +tap f3 +wait 2 +tap l +wait 3 +orthophoto 482500 634000 0 1 0 +wait 3 +nmtquestion open +wait 5 +expect terrain question 0 +expect terrain prompt 1 +expect terrain loading 1 +expect laypanel ready shown +# the photo doesn't wait for the terrain: it's on and its tile asked for while the terrain is still to come +expect photo on 1 +# Without terrain: nothing of the model loaded any more, the line gone +nmtquestion flat +wait 3 +expect terrain prompt 0 +expect terrain loading 0 +expect terrain grow 0 +expect terrain area 0 +nmtquestion restore +wait 2 +orthophoto forget +quit diff --git a/tests/editor/cases/ph_3_tracks_over_photo.txt b/tests/editor/cases/ph_3_tracks_over_photo.txt new file mode 100644 index 000000000..c91ba5266 --- /dev/null +++ b/tests/editor/cases/ph_3_tracks_over_photo.txt @@ -0,0 +1,19 @@ +# In the top view the tracks laid are drawn over the photo, which is drawn over the view, also zoomed in (under 0.5 m a pixel, where they +# were left to the 3d tracks the photo covers): the rails of a1 at about 0.17 m a pixel. Without the photo no lines over them there. The +# origin is outside Poland, so no photo is downloaded +wait 5 +tap f3 +wait 2 +camera 0 200 50 0 0 50.5 +ortho 40 whole +wait 3 +orthophoto 50 50 0 1 0 +wait 3 +expect photo on 1 +expect photo tracksover 1 +orthophoto off +wait 3 +expect photo on 0 +expect photo tracksover 0 +orthophoto forget +quit diff --git a/tests/editor/cases/ph_4_toolbar_toggle.txt b/tests/editor/cases/ph_4_toolbar_toggle.txt new file mode 100644 index 000000000..7f44ff524 --- /dev/null +++ b/tests/editor/cases/ph_4_toolbar_toggle.txt @@ -0,0 +1,29 @@ +# The photo in the toolbar of the tracks: its button and ~ turn it on and off for the scenery, as the user's choice, and the terrain +# made of the model around the camera doesn't turn it on again behind the user (~ turned it off before without it counting as a choice, +# and the terrain turned it on again). ~ is in the shortcuts (F1). In Warsaw: the photo of one tile, the terrain of the model around +wait 5 +tap f3 +wait 2 +orthophoto 482500 634000 0 1 0 +wait 3 +expect photo on 1 +tap grave +wait 2 +expect photo on 0 +expect photo chosen 1 +nmtmake around 100 +wait 10 +expect photo on 0 +toolbar ~ +wait 2 +expect photo on 1 +toolbar ~ +wait 2 +expect photo on 0 +tap f1 +wait 3 +expect window shortcuts 1 +tap f1 +wait 2 +orthophoto forget +quit diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index e97797169..7c0f38716 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -37,6 +37,10 @@ add_executable(${UNIT_TESTS_NAME} "${CMAKE_SOURCE_DIR}/editor/editorHttp.cpp" # and the //$ lines it keeps in the scenery files, and the descriptions of the templates (//$e) "${CMAKE_SOURCE_DIR}/editor/editorRecords.cpp" + # the rules the aerial photo goes by: the origin, on or off, the download area grown, the tiles tried again, the 4K photos (test_photo_rules.cpp) + "${CMAKE_SOURCE_DIR}/editor/editorPhotoRules.cpp" + # and the settings of the editor as their file keeps them, read and written through a stream (the user's file isn't touched) + "${CMAKE_SOURCE_DIR}/editor/editorSettings.cpp" "${CMAKE_SOURCE_DIR}/scene/scenelayercontext.cpp" "${CMAKE_SOURCE_DIR}/editor/editorIncludeInfo.cpp" # the tracks read from the text of the scenery files and written back, with no scene (test_track_text.cpp): the track and diff --git a/tests/unit/test_photo_rules.cpp b/tests/unit/test_photo_rules.cpp new file mode 100644 index 000000000..cc5008a08 --- /dev/null +++ b/tests/unit/test_photo_rules.cpp @@ -0,0 +1,236 @@ +#include "stdafx.h" +#include "doctest.h" +#include "editor/editorGeometry.hpp" +#include "editor/editorPhotoRules.hpp" +#include "editor/editorRecords.hpp" +#include "editor/editorSettings.hpp" + +#include +#include +#include +#include + +namespace { + +using photo_rules::origin_source; + +std::set> squares(std::vector const &Polygon, double const Size) { + auto const found{geometry::squares_in(Polygon, Size)}; + return {found.begin(), found.end()}; +} + +// a square of tiles of 256 m, the tiles from First to Last along both axes +std::vector block(int const First, int const Last) { + double const low{First * 256.0 + 10.0}; + double const high{(Last + 1) * 256.0 - 10.0}; + return {{low, low}, {high, low}, {high, high}, {low, high}}; +} + +} // namespace + +TEST_CASE("photo: the photo turned on or off is the scenery's, kept with the editor") { + editorSettings settings; + CHECK_FALSE(settings.orthophoto_on("a").has_value()); + settings.orthophoto_on("a", false); + settings.orthophoto_on("b c", true); + CHECK(settings.orthophoto_on("a") == std::optional{false}); + CHECK(settings.orthophoto_on("b c") == std::optional{true}); + CHECK_FALSE(settings.orthophoto_on("d").has_value()); + + // written and read back, the scenery with a blank in its name too + std::stringstream file; + settings.write(file); + editorSettings again; + again.read(file); + CHECK(again.orthophoto_on("a") == std::optional{false}); + CHECK(again.orthophoto_on("b c") == std::optional{true}); + CHECK_FALSE(again.orthophoto_on("d").has_value()); + + again.orthophoto_forget("a"); + CHECK_FALSE(again.orthophoto_on("a").has_value()); +} + +TEST_CASE("photo: the global off of an older editor is left behind") { + std::istringstream file{"ortho_on 0\northo_opacity 0.4\n"}; + editorSettings settings; + settings.read(file); + CHECK_FALSE(settings.orthophoto_on("any").has_value()); + CHECK(settings.orthophoto().opacity == doctest::Approx(0.4f)); +} + +TEST_CASE("photo: on as the user left it in the scenery, else as the scenery keeps it, else off") { + // the wizard's //$o on 1 with nothing chosen by the user in the scenery: on + auto const wizard{photo_rules::photo_on(std::nullopt, true)}; + CHECK(wizard.on); + CHECK(wizard.chosen); + // turned off by the user in it: off, whatever the scenery says + CHECK_FALSE(photo_rules::photo_on(false, true).on); + CHECK(photo_rules::photo_on(true, false).on); + // nothing said: off, and the terrain model may turn it on + auto const none{photo_rules::photo_on(std::nullopt, std::nullopt)}; + CHECK_FALSE(none.on); + CHECK_FALSE(none.chosen); +} + +TEST_CASE("photo: //$g wins over the origin remembered and the one of //$o, the difference told") { + glm::dvec2 const g{500000.0, 600000.0}; + auto const choice{photo_rules::choose_origin(g, std::nullopt, glm::dvec2{510000.0, 600000.0})}; + CHECK(choice.from == origin_source::georeference); + CHECK(choice.origin == g); + CHECK(choice.differs == doctest::Approx(10000.0)); + + auto const same{photo_rules::choose_origin(g, g, g)}; + CHECK(same.differs == doctest::Approx(0.0)); + CHECK(same.differs <= photo_rules::origin_tolerance); + + auto const mark{photo_rules::choose_origin(g, glm::dvec2{500000.0, 600030.0}, std::nullopt)}; + CHECK(mark.from == origin_source::georeference); + CHECK(mark.differs == doctest::Approx(30.0)); + + // without //$g: the editor's //$o, then the one remembered + CHECK(photo_rules::choose_origin(std::nullopt, glm::dvec2{1.0, 2.0}, glm::dvec2{3.0, 4.0}).from == origin_source::mark); + auto const remembered{photo_rules::choose_origin(glm::dvec2{0.0}, std::nullopt, glm::dvec2{3.0, 4.0})}; + CHECK(remembered.from == origin_source::remembered); + CHECK(remembered.origin == glm::dvec2{3.0, 4.0}); + CHECK(photo_rules::choose_origin(std::nullopt, std::nullopt, std::nullopt).from == origin_source::none); + + // a //$o aligned by hand goes before //$g: the user moved the photo off it on purpose + auto const aligned{photo_rules::choose_origin(g, glm::dvec2{500000.0, 600030.0}, glm::dvec2{510000.0, 600000.0}, true)}; + CHECK(aligned.from == origin_source::mark); + CHECK(aligned.origin == glm::dvec2{500000.0, 600030.0}); + CHECK(aligned.differs == doctest::Approx(0.0)); +} + +TEST_CASE("photo: //$o says the origin was aligned by hand, which a release before it passes over") { + auto const line{editor_records::orthophoto_line(true, true, 500000.0, 600030.0, true)}; + CHECK(line == "on 1 origin 500000.00 600030.00 aligned"); + bool on{false}; + double north{0.0}; + double east{0.0}; + bool aligned{false}; + REQUIRE(editor_records::read_orthophoto(line, on, north, east, &aligned)); + CHECK(on); + CHECK(north == doctest::Approx(500000.0)); + CHECK(east == doctest::Approx(600030.0)); + CHECK(aligned); + // read as before without the word, and the word passed over where it isn't asked for + CHECK(editor_records::orthophoto_line(true, true, 500000.0, 600030.0) == "on 1 origin 500000.00 600030.00"); + bool again{false}; + REQUIRE(editor_records::read_orthophoto("on 1 origin 1.00 2.00", on, north, east, &again)); + CHECK_FALSE(again); + REQUIRE(editor_records::read_orthophoto(line, on, north, east)); + CHECK(east == doctest::Approx(600030.0)); +} + +TEST_CASE("photo: a tile which failed is tried again later and later, up to 5 min, never given up") { + CHECK(photo_rules::retry_delay(0) == doctest::Approx(0.0)); + CHECK(photo_rules::retry_delay(1) == doctest::Approx(5.0)); + CHECK(photo_rules::retry_delay(2) == doctest::Approx(10.0)); + CHECK(photo_rules::retry_delay(5) == doctest::Approx(80.0)); + CHECK(photo_rules::retry_delay(7) == doctest::Approx(300.0)); + CHECK(photo_rules::retry_delay(1000) == doctest::Approx(300.0)); + for (int failures = 1; failures < 40; ++failures) + CHECK(photo_rules::retry_delay(failures) <= photo_rules::retry_most); +} + +TEST_CASE("photo: the 4K photos come when the view is zoomed in to 15 cm a pixel, and go past 25 cm") { + CHECK(photo_rules::hires_wanted(0.10, false)); + CHECK(photo_rules::hires_wanted(0.15, false)); + CHECK_FALSE(photo_rules::hires_wanted(0.16, false)); + // on already: they stay a little further out + CHECK(photo_rules::hires_wanted(0.20, true)); + CHECK_FALSE(photo_rules::hires_wanted(0.26, true)); + // a view of no known size + CHECK_FALSE(photo_rules::hires_wanted(0.0, true)); +} + +TEST_CASE("photo: what a download that failed is told as") { + CHECK(photo_rules::failure_reason("WinHTTP error 12007") == "no connection to the internet: the name of the server isn't found"); + CHECK(photo_rules::failure_reason("WinHTTP error 12002") == "the server didn't answer in time"); + CHECK(photo_rules::failure_reason("WinHTTP error 12029") == "the server can't be reached"); + CHECK(photo_rules::failure_reason("HTTP 503") == "the server is busy or out of order"); + CHECK(photo_rules::failure_reason("HTTP 404") == "the server has no photo of the place"); + CHECK(photo_rules::failure_reason("unexpected response: = 4); + auto const tiles{squares(grown.polygon, 256.0)}; + // the old tiles all in, the new ones 2 tiles around the camera's, nothing else + for (int x = 0; x < 4; ++x) + for (int y = 0; y < 4; ++y) + CHECK(tiles.count({x, y}) == 1); + for (int x = 1; x <= 5; ++x) + for (int y = -1; y <= 3; ++y) + CHECK(tiles.count({x, y}) == 1); + CHECK(tiles.size() == grown.total); + CHECK(grown.total == 16 + 10 + 3); // the columns 4 and 5 of y -1..3, the row -1 of x 1..3 + CHECK(grown.added == grown.total - 16); + CHECK_FALSE(geometry::polygon_crosses_itself(grown.polygon)); +} + +TEST_CASE("photo: the download area stays where the camera is deep inside it or far from it") { + auto const area{block(0, 9)}; + // in the middle, the square around it inside + auto const inside{photo_rules::grow_area(area, {5.5 * 256.0, 5.5 * 256.0}, 256.0, 1, 2, 1000)}; + CHECK(inside.polygon.empty()); + CHECK(inside.total == 100); + // 3 tiles off its edge: elsewhere, not at its edge + auto const away{photo_rules::grow_area(area, {13.5 * 256.0, 5.5 * 256.0}, 256.0, 1, 2, 1000)}; + CHECK(away.polygon.empty()); + CHECK_FALSE(away.limited); + // no area: nothing to grow + CHECK(photo_rules::grow_area({}, {0.0, 0.0}, 256.0, 1, 2, 1000).polygon.empty()); +} + +TEST_CASE("photo: the download area doesn't grow past its limit") { + auto const area{block(0, 9)}; + auto const grown{photo_rules::grow_area(area, {9.5 * 256.0, 5.5 * 256.0}, 256.0, 1, 2, 105)}; + CHECK(grown.polygon.empty()); + CHECK(grown.limited); + CHECK(grown.total == 100); +} + +TEST_CASE("photo: an area grown across the mouth of a U takes the inside of the U in, no hole left") { + // a U of tiles: the columns 0 and 4 of y 0..4 and the row 0 between them; the camera over the mouth + std::vector> u; + for (int y = 0; y < 5; ++y) + u.insert(u.end(), {{0, y}, {4, y}}); + for (int x = 1; x < 4; ++x) + u.emplace_back(x, 0); + auto const outline{photo_rules::squares_outline(u, 256.0, 1.0)}; + REQUIRE(outline.size() == 8); + CHECK(squares(outline, 256.0).size() == 13); + auto const grown{photo_rules::grow_area(outline, {2.5 * 256.0, 5.5 * 256.0}, 256.0, 2, 2, 1000)}; + REQUIRE(grown.polygon.size() >= 4); + auto const tiles{squares(grown.polygon, 256.0)}; + // the square around the camera, x 0..4 and y 3..7, closes the U: its inside is taken in + for (int x = 0; x < 5; ++x) + for (int y = 0; y < 8; ++y) + CHECK(tiles.count({x, y}) == 1); + CHECK(tiles.size() == 40); + CHECK(grown.total == 40); + CHECK(grown.added == 27); +} + +TEST_CASE("photo: the outline of squares not in one piece is none") { + CHECK(photo_rules::squares_outline({{0, 0}, {2, 0}}, 256.0, 1.0).empty()); + auto const one{photo_rules::squares_outline({{3, 4}}, 256.0, 1.0)}; + REQUIRE(one.size() == 4); + CHECK(squares(one, 256.0) == std::set>{{3, 4}}); +}