17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-03 15:30:21 +01:00

fix(editor): a switch drive stands at the height given in its //$e description, switch: {height: ...} above the start point of the switch (rail foot): placed with a new switch, swapped for another drive or side, or following its switch; drive_headers.py writes height 0.15 for ele and ele1 and 0.05 for mech and mech1, whose models reach that far below the origin, so they stand on the sleepers; the drives with a counterweight (mech_*, mech2, 0.57 m down) keep 0, as all 1965 drives of the digitized lines do

This commit is contained in:
maj00r
2026-10-11 20:32:59 +02:00
parent b103a561e0
commit 71bdf8e284
5 changed files with 15 additions and 4 deletions

View File

@@ -933,6 +933,7 @@ class editor_mode : public application_mode, private editor_track::observer
{ {
std::string name; std::string name;
std::array<std::string, 4> files; std::array<std::string, 4> files;
std::array<double, 4> heights{};
bool preferred{false}; bool preferred{false};
}; };
std::vector<drive_family> drives; std::vector<drive_family> drives;

View File

@@ -6633,6 +6633,7 @@ void editor_mode::scan_switch_drives()
family = std::prev(tool.drives.end()); family = std::prev(tool.drives.end());
} }
family->files[hand * 2 + drive] = entry.file; family->files[hand * 2 + drive] = entry.file;
family->heights[hand * 2 + drive] = info.switch_height;
family->preferred |= info.switch_default; family->preferred |= info.switch_default;
} }
std::sort(tool.drives.begin(), tool.drives.end(), [](switch_tool::drive_family const &A, switch_tool::drive_family const &B) { return A.name < B.name; }); std::sort(tool.drives.begin(), tool.drives.end(), [](switch_tool::drive_family const &A, switch_tool::drive_family const &B) { return A.name < B.name; });
@@ -6714,6 +6715,7 @@ void editor_mode::switch_drives_committed(std::vector<TTrack *> const &Tracks)
std::string error; std::string error;
if (included.file == nullptr || false == editor_includes::load(*included.file, info, error)) if (included.file == nullptr || false == editor_includes::load(*included.file, info, error))
continue; continue;
location.y += m_switch.drives[family].heights[variant];
auto const local{location - included.context.offset}; auto const local{location - included.context.offset};
auto values{drive.values}; auto values{drive.values};
for (auto const &parameter : info.parameters) for (auto const &parameter : info.parameters)
@@ -6754,14 +6756,15 @@ bool editor_mode::place_switch_drive(TTrack &Switch)
return false; return false;
bool const driveright{(tool.drive_side == 0) == rightswitch}; bool const driveright{(tool.drive_side == 0) == rightswitch};
auto const &family{tool.drives[tool.drive]}; auto const &family{tool.drives[tool.drive]};
auto const index{(rightswitch ? 2 : 0) + (driveright ? 1 : 0)};
template_item item; template_item item;
item.file = family.files[(rightswitch ? 2 : 0) + (driveright ? 1 : 0)]; item.file = family.files[index];
if (item.file.empty()) if (item.file.empty())
{ {
tool.status = format(STR_C("The drive %s has no variant for a %s switch with the drive on the %s"), family.name.c_str(), rightswitch ? STR_C("right") : STR_C("left"), driveright ? STR_C("right") : STR_C("left")); tool.status = format(STR_C("The drive %s has no variant for a %s switch with the drive on the %s"), family.name.c_str(), rightswitch ? STR_C("right") : STR_C("left"), driveright ? STR_C("right") : STR_C("left"));
return false; return false;
} }
item.location = location; item.location = location + glm::dvec3{0.0, family.heights[index], 0.0};
item.yaw = yaw; item.yaw = yaw;
item.described = true; item.described = true;
item.track = Switch.name(); item.track = Switch.name();
@@ -6840,7 +6843,11 @@ bool editor_mode::replace_switch_drive(TTrack &Switch, int const Family, bool co
} }
if (drive_file(item.file) == found.file) if (drive_file(item.file) == found.file)
return false; return false;
item.location = found.location; glm::dvec3 location;
double yaw;
glm::dvec2 tilt;
bool rightswitch;
item.location = switch_drive_spot(Switch, location, yaw, tilt, rightswitch) ? location + glm::dvec3{0.0, tool.drives[family].heights[index], 0.0} : found.location;
item.yaw = found.yaw; item.yaw = found.yaw;
item.described = true; item.described = true;
item.track = Switch.name(); item.track = Switch.name();

View File

@@ -251,6 +251,7 @@ bool parse(template_text const &Text, include_info &Info, std::string &Error)
Info.switch_hand = drive["hand"].as<std::string>(""); Info.switch_hand = drive["hand"].as<std::string>("");
Info.switch_drive = drive["drive"].as<std::string>(""); Info.switch_drive = drive["drive"].as<std::string>("");
Info.switch_default = drive["default"].as<bool>(false); Info.switch_default = drive["default"].as<bool>(false);
Info.switch_height = drive["height"].as<double>(0.0);
} }
if (auto const signal{document["signal"]}; signal.IsDefined() && signal.IsMap()) if (auto const signal{document["signal"]}; signal.IsDefined() && signal.IsMap())
{ {

View File

@@ -38,6 +38,7 @@ struct include_info
std::string switch_hand; // a switch drive: side of the diverging track, left or right, looking from the start of the switch std::string switch_hand; // a switch drive: side of the diverging track, left or right, looking from the start of the switch
std::string switch_drive; // and the side the drive stands on std::string switch_drive; // and the side the drive stands on
bool switch_default{false}; // the drive put with a new switch until another is picked bool switch_default{false}; // the drive put with a new switch until another is picked
double switch_height{0.0};
double turntable_length{0.0}; double turntable_length{0.0};
int turntable_angles{0}; int turntable_angles{0};
int turntable_positions{0}; int turntable_positions{0};

View File

@@ -17,6 +17,7 @@ FOLDER = 'scenery/tory/napedy'
PATTERN = re.compile(r'^(ele1?|mech[12]?)-rz([lp])-([lp])((?:_[a-z]+)*)\.inc$') PATTERN = re.compile(r'^(ele1?|mech[12]?)-rz([lp])-([lp])((?:_[a-z]+)*)\.inc$')
KINDS = {'ele': 'elektryczny', 'mech': 'mechaniczny'} KINDS = {'ele': 'elektryczny', 'mech': 'mechaniczny'}
DEFAULT = 'ele' DEFAULT = 'ele'
HEIGHTS = {'ele': 0.15, 'ele1': 0.15, 'mech': 0.05, 'mech1': 0.05}
def examine(path, file): def examine(path, file):
@@ -49,7 +50,7 @@ def examine(path, file):
'name: ' + family, 'name: ' + family,
'category: switch drive', 'category: switch drive',
'description: "' + description + '"', 'description: "' + description + '"',
'switch: {hand: %s, drive: %s%s}' % (hand, side, ', default: true' if family == DEFAULT else ''), 'switch: {hand: %s, drive: %s, height: %s%s}' % (hand, side, HEIGHTS.get(family, 0), ', default: true' if family == DEFAULT else ''),
'params:', 'params:',
' - {id: 1, role: track, label: Switch}', ' - {id: 1, role: track, label: Switch}',
' - {id: 2, role: pos.x}', ' - {id: 2, role: pos.x}',