]> git.tdb.fi Git - r2c2.git/commitdiff
Support multiple TrackAppearances in Catalogue
authorMikko Rasa <tdb@tdb.fi>
Sun, 4 May 2014 09:11:37 +0000 (12:11 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 4 May 2014 20:13:08 +0000 (23:13 +0300)
source/libr2c2/catalogue.cpp
source/libr2c2/catalogue.h
source/libr2c2/tracktype.cpp
source/libr2c2/tracktype.h
tracks.dat

index cfd5d6425f29d971bc116d96c72cfe0307eb4468..2afe4eaa14885cee663de30af2475648e9486ab4 100644 (file)
@@ -20,6 +20,7 @@ Catalogue::Catalogue():
        add_type<SignalType>();
        add_type<VehicleType>();
        add_type<TerrainType>();
+       add_type<TrackAppearance>().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<TrackType> trk = new TrackType(n, &cat.appearance);
-       load_sub(*trk);
+       RefPtr<TrackType> 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<VehicleType> veh = new VehicleType(n);
index e8a474432251adfafec5e514fb794a93575e6942..cd59e9ca2922e06ac723af9f432fbb45de517403 100644 (file)
@@ -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:
index c2740f1d39b33ccfe10f819863ea26da220544f8..6b16c553809dc7941a9523aac7889ee34f8a4f34 100644 (file)
@@ -1,4 +1,5 @@
 #include <cmath>
+#include <msp/datafile/collection.h>
 #include <msp/geometry/union.h>
 #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<TrackType, ObjectType::Loader>(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);
index 2a116134d850b0353a0ba1f2586bea15caa52a2d..bccd10baadc0a4c551570ece52383b2b8998b915 100644 (file)
@@ -28,13 +28,20 @@ public:
 
        class Loader: public Msp::DataFile::DerivedObjectLoader<TrackType, ObjectType::Loader>
        {
+       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;
index 057b40ab7b998ef54fda88b9ea98d101bb8842a3..9a35bdea3c601ee7113da4a5d4511a4ff4dc3c47 100644 (file)
@@ -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