mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-30 03:50:30 +01:00
Editor: rebuild the plan library around a solved document, and bend turnouts onto curves
The library was a heap of half-built services - fitting, parallelism, niwelety, an SVG writer - that never met each other. In their place is one authored Document and one solver that lays it whole: tracks as element chains, turnouts placed on them, and a Solution that is rebuilt from scratch every time and never fed back into the document. What cannot be laid comes back as a diagnostic with the number in it rather than as silence or a fitted-away error. Turnouts are dimensioned the way the drawings dimension them. The blade follows Koc's rys. 5.9 - the curve is theoretically tangent to the opornica at PR, the blade starts at a with a planed nose of d, and A is where the rail stands u thick - and a + d derived that way lands on his tablica 5.1. Bending follows 5.3.6: it rotates the triangle OBC about the centre of the turnout, so the tangent t and the crossing angle stand and both radii follow from them. That is Koc's (5.7) and (5.8) without coding either, and it puts a symmetrically bent Rz 49E1-190-1:9 on the catalogue's Rlus 49E1-380,292-1:9. A rozjazd standing on a curve is bent onto it; one on a track drawn straight can carry a bend of its own. The szyny laczace take up the difference, because the switch and the frog are only bent, not re-cut. The plan panel draws all of it: the catalogue drawing of a type with its construction points, the theoretical arc dashed where no rail runs, and the blade nose as the straight it is cut as. Dragging a straight now stops where it would pull the track out from under a turnout. File format goes to m0s 6. Versions 3 to 5 still open.
This commit is contained in:
@@ -17,6 +17,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
#else
|
||||
#include <curl/curl.h>
|
||||
#endif
|
||||
|
||||
namespace editor
|
||||
@@ -127,9 +129,64 @@ bool http_get(std::string const &Url, std::vector<std::uint8_t> &Bytes, std::str
|
||||
|
||||
#else
|
||||
|
||||
bool http_get(std::string const &, std::vector<std::uint8_t> &, std::string &)
|
||||
// libcurl's write callback: appends one chunk of the body to the caller's buffer
|
||||
std::size_t append_body(char const *Data, std::size_t const Size, std::size_t const Count, void *Userdata)
|
||||
{
|
||||
return false; // no native transport on this platform yet
|
||||
auto &bytes = *static_cast<std::vector<std::uint8_t> *>(Userdata);
|
||||
auto const length = Size * Count;
|
||||
bytes.insert(bytes.end(), Data, Data + length);
|
||||
return length;
|
||||
}
|
||||
|
||||
// plain HTTPS GET, the same shape as the WinHttp one above: one request, one answer, nothing kept
|
||||
// between calls. libcurl wants its global init done once before any handle exists, and this is the
|
||||
// only place in the program that uses it, so a function-local static does the job thread-safely
|
||||
bool http_get(std::string const &Url, std::vector<std::uint8_t> &Bytes, std::string &Contenttype)
|
||||
{
|
||||
static bool const initialised = (curl_global_init(CURL_GLOBAL_DEFAULT) == CURLE_OK);
|
||||
if (false == initialised)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CURL *handle = curl_easy_init();
|
||||
if (handle == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Bytes.clear();
|
||||
curl_easy_setopt(handle, CURLOPT_URL, Url.c_str());
|
||||
curl_easy_setopt(handle, CURLOPT_USERAGENT, kUserAgent);
|
||||
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, append_body);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &Bytes);
|
||||
// a stuck transfer must not hold a worker forever; the caller retries
|
||||
curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 10L);
|
||||
curl_easy_setopt(handle, CURLOPT_TIMEOUT, 30L);
|
||||
// workers run on their own threads: keep libcurl off signals, which are process-wide
|
||||
curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);
|
||||
|
||||
bool ok = (curl_easy_perform(handle) == CURLE_OK);
|
||||
if (true == ok)
|
||||
{
|
||||
long status = 0;
|
||||
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &status);
|
||||
char const *type = nullptr;
|
||||
if ((curl_easy_getinfo(handle, CURLINFO_CONTENT_TYPE, &type) == CURLE_OK) && (type != nullptr))
|
||||
{
|
||||
Contenttype.assign(type);
|
||||
}
|
||||
ok = (status == 200) && (false == Bytes.empty());
|
||||
}
|
||||
if (false == ok)
|
||||
{
|
||||
Bytes.clear();
|
||||
}
|
||||
|
||||
curl_easy_cleanup(handle);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user