From: Mikko Rasa Date: Sun, 4 May 2014 09:11:37 +0000 (+0300) Subject: Support multiple TrackAppearances in Catalogue X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=11c68656ac53318801dcb36078509a07ae2c2a94;p=r2c2.git Support multiple TrackAppearances in Catalogue --- diff --git a/source/libr2c2/catalogue.cpp b/source/libr2c2/catalogue.cpp index cfd5d64..2afe4ea 100644 --- a/source/libr2c2/catalogue.cpp +++ b/source/libr2c2/catalogue.cpp @@ -20,6 +20,7 @@ Catalogue::Catalogue(): add_type(); add_type(); add_type(); + add_type().keyword("track_appearance"); } @@ -32,7 +33,6 @@ Catalogue::Loader::Loader(Catalogue &c): add("signal", &Loader::signal); add("terrain", &Loader::terrain); add("track", &Loader::track); - add("track_appearance", &Loader::track_appearance); add("vehicle", &Loader::vehicle); } @@ -64,17 +64,12 @@ void Catalogue::Loader::terrain(const string &n) void Catalogue::Loader::track(const string &n) { - RefPtr trk = new TrackType(n, &cat.appearance); - load_sub(*trk); + RefPtr trk = new TrackType(n); + load_sub(*trk, cat); cat.add(n, trk.get()); trk.release(); } -void Catalogue::Loader::track_appearance() -{ - load_sub(cat.appearance); -} - void Catalogue::Loader::vehicle(const string &n) { RefPtr veh = new VehicleType(n); diff --git a/source/libr2c2/catalogue.h b/source/libr2c2/catalogue.h index e8a4744..cd59e9c 100644 --- a/source/libr2c2/catalogue.h +++ b/source/libr2c2/catalogue.h @@ -27,13 +27,11 @@ public: void signal(const std::string &); void terrain(const std::string &); void track(const std::string &); - void track_appearance(); void vehicle(const std::string &); }; private: float scale; - TrackAppearance appearance; Layout layout; public: diff --git a/source/libr2c2/tracktype.cpp b/source/libr2c2/tracktype.cpp index c2740f1..6b16c55 100644 --- a/source/libr2c2/tracktype.cpp +++ b/source/libr2c2/tracktype.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "trackappearance.h" #include "tracktype.h" @@ -8,9 +9,9 @@ using namespace Msp; namespace R2C2 { -TrackType::TrackType(const ArticleNumber &an, const TrackAppearance *ta): +TrackType::TrackType(const ArticleNumber &an): ObjectType(an), - appearance(ta), + appearance(0), state_bits(0), autofit_preference(1) { } @@ -221,10 +222,12 @@ TrackType::Endpoint::Endpoint(float x, float y, const Angle &d, unsigned p): { } -TrackType::Loader::Loader(TrackType &t): +TrackType::Loader::Loader(TrackType &t, Collection &c): DataFile::DerivedObjectLoader(t), + coll(c), state_bits_set(false) { + add("appearance", &TrackType::appearance); add("autofit_preference", &TrackType::autofit_preference); add("object", &TrackType::object); add("state_bits", &Loader::state_bits); diff --git a/source/libr2c2/tracktype.h b/source/libr2c2/tracktype.h index 2a11613..bccd10b 100644 --- a/source/libr2c2/tracktype.h +++ b/source/libr2c2/tracktype.h @@ -28,13 +28,20 @@ public: class Loader: public Msp::DataFile::DerivedObjectLoader { + public: + typedef Msp::DataFile::Collection Collection; + private: + Collection &coll; bool state_bits_set; public: - Loader(TrackType &); + Loader(TrackType &, Collection &); + + virtual Collection &get_collection() const { return coll; } private: virtual void finish(); + void appearance(const std::string &); void part(); void position(float, float, float); void state_bits(unsigned); @@ -49,7 +56,7 @@ private: std::string object; public: - TrackType(const ArticleNumber & = ArticleNumber(), const TrackAppearance * = 0); + TrackType(const ArticleNumber & = ArticleNumber()); const TrackAppearance &get_appearance() const; float get_gauge() const; diff --git a/tracks.dat b/tracks.dat index 057b40a..9a35bde 100644 --- a/tracks.dat +++ b/tracks.dat @@ -1,6 +1,6 @@ scale 1 87; -track_appearance +track_appearance "C" { gauge 16.5; rail_profile @@ -44,6 +44,7 @@ track_appearance track "24064" { + appearance "C"; description "Straight, 64.3mm (R3-R4-R5)"; part { @@ -53,6 +54,7 @@ track "24064" track "24071" { + appearance "C"; description "Straight, 70.8mm (for slim turnouts)"; part { @@ -63,6 +65,7 @@ track "24071" track "24077" { + appearance "C"; description "Straight, 77.5mm (R1-R2-R3)"; part { @@ -73,6 +76,7 @@ track "24077" track "24094" { + appearance "C"; description "Straight, 94.2mm"; part { @@ -83,6 +87,7 @@ track "24094" track "24172" { + appearance "C"; description "Straight, 171.7mm"; part { @@ -93,6 +98,7 @@ track "24172" track "24188" { + appearance "C"; description "Straight, 188.3mm (turnout length)"; part { @@ -103,6 +109,7 @@ track "24188" track "24229" { + appearance "C"; description "Straight, 229.3mm"; part { @@ -112,6 +119,7 @@ track "24229" track "24236" { + appearance "C"; description "Straight, 236.1mm (slim turnout length)"; part { @@ -121,6 +129,7 @@ track "24236" track "24360" { + appearance "C"; description "Straight, 360mm"; part { @@ -132,6 +141,7 @@ track "24360" track "24107" { + appearance "C"; description "Curve, R1 = 360mm, 7.5°"; part { @@ -142,6 +152,7 @@ track "24107" track "24115" { + appearance "C"; description "Curve, R1 = 360mm, 15°"; part { @@ -152,6 +163,7 @@ track "24115" track "24130" { + appearance "C"; description "Curve, R1 = 360mm, 30°"; part { @@ -164,6 +176,7 @@ track "24130" track "24206" { + appearance "C"; description "Curve, R2 = 437.5mm, 5.7° (turnout to 30°)"; part { @@ -174,6 +187,7 @@ track "24206" track "24207" { + appearance "C"; description "Curve, R2 = 437.5mm, 7.5°"; part { @@ -184,6 +198,7 @@ track "24207" track "24215" { + appearance "C"; description "Curve, R2 = 437.5mm, 15°"; part { @@ -194,6 +209,7 @@ track "24215" track "24224" { + appearance "C"; description "Curve, R2 = 437.5mm, 24.3° (turnout)"; part { @@ -204,6 +220,7 @@ track "24224" track "24230" { + appearance "C"; description "Curve, R2 = 437.5mm, 30°"; part { @@ -216,6 +233,7 @@ track "24230" track "24330" { + appearance "C"; description "Curve, R3 = 515mm, 30°"; part { @@ -228,6 +246,7 @@ track "24330" track "24430" { + appearance "C"; description "Curve, R4 = 579.3mm, 30°"; part { @@ -240,6 +259,7 @@ track "24430" track "24530" { + appearance "C"; description "Curve, R5 = 643.6mm, 30°"; part { @@ -252,6 +272,7 @@ track "24530" track "24912" { + appearance "C"; description "Curve, R = 1114.6mm, 12.1° (slim turnout)"; part { @@ -264,6 +285,7 @@ track "24912" track "24671" { + appearance "C"; description "Curved turnout, left"; part { @@ -287,6 +309,7 @@ track "24671" track "24672" { + appearance "C"; description "Curved turnout, right"; part { @@ -312,6 +335,7 @@ track "24672" track "24611" { + appearance "C"; description "Turnout, left"; part { @@ -328,6 +352,7 @@ track "24611" track "24612" { + appearance "C"; description "Turnout, right"; part { @@ -344,6 +369,7 @@ track "24612" track "24630" { + appearance "C"; description "Turnout, 3-way"; part { @@ -366,6 +392,7 @@ track "24630" track "24624" { + appearance "C"; description "Turnout, double slip"; state_bits 1; part @@ -398,6 +425,7 @@ track "24624" track "24711" { + appearance "C"; description "Slim turnout, left"; part { @@ -414,6 +442,7 @@ track "24711" track "24712" { + appearance "C"; description "Slim turnout, right"; part { @@ -432,6 +461,7 @@ track "24712" track "24640" { + appearance "C"; description "Crossing, 24.3°"; part { @@ -446,6 +476,7 @@ track "24640" track "24649" { + appearance "C"; description "Crossing, 48.6°"; part { @@ -460,6 +491,7 @@ track "24649" track "24740" { + appearance "C"; description "Slim crossing, 12.1°"; part { @@ -476,6 +508,7 @@ track "24740" track "24977" { + appearance "C"; description "Bumper"; object "bumper.object"; part