]> git.tdb.fi Git - r2c2.git/commitdiff
Convert Catalogue to a Collection
authorMikko Rasa <tdb@tdb.fi>
Sun, 4 May 2014 07:47:49 +0000 (10:47 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 4 May 2014 20:13:07 +0000 (23:13 +0300)
Since this involves changing the key from ArticleNumber to std::string,
existing layout and state files need to be adjusted by hand.

22 files changed:
locos.dat
source/3d/catalogue.cpp
source/3d/catalogue.h
source/designer/extendtool.cpp
source/engineer/newtraindialog.cpp
source/engineer/newvehicledialog.cpp
source/libr2c2/catalogue.cpp
source/libr2c2/catalogue.h
source/libr2c2/layout.cpp
source/libr2c2/layout.h
source/libr2c2/signaltype.h
source/libr2c2/terraintype.h
source/libr2c2/tracktype.cpp
source/libr2c2/tracktype.h
source/libr2c2/train.cpp
source/libr2c2/train.h
source/libr2c2/vehicletype.h
source/network/server.cpp
source/shoppinglist/main.cpp
terrain.dat
tracks.dat
wagons.dat

index 3547d51d1acad96902d4b867a6d14f945c3efbf9..bd3fdc2f9116d0c9f9e0b07584c3ac3b1bb0fb01 100644 (file)
--- a/locos.dat
+++ b/locos.dat
@@ -1,6 +1,6 @@
 scale 1 87;
 
-vehicle \39230
+vehicle "39230"
 {
        name "BR 23";
        locomotive true;
@@ -31,7 +31,7 @@ vehicle \39230
        };
 };
 
-vehicle \29820-02
+vehicle "29820-02"
 {
        name "BR 50";
        locomotive true;
@@ -282,7 +282,7 @@ vehicle \29820-02
        };
 };
 
-vehicle \29530-01
+vehicle "29530-01"
 {
        name "BR 86";
        locomotive true;
@@ -313,7 +313,7 @@ vehicle \29530-01
        };
 };
 
-vehicle \36850
+vehicle "36850"
 {
        name "BR 185";
        locomotive true;
@@ -343,7 +343,7 @@ vehicle \36850
        };
 };
 
-vehicle \37225-02
+vehicle "37225-02"
 {
        name "BR 194";
        locomotive true;
@@ -377,7 +377,7 @@ vehicle \37225-02
        };
 };
 
-vehicle \39410
+vehicle "39410"
 {
        name "BR E 41";
        locomotive true;
@@ -410,7 +410,7 @@ vehicle \39410
        };
 };
 
-vehicle \37574-01
+vehicle "37574-01"
 {
        name "BR E 03";
        locomotive true;
@@ -445,7 +445,7 @@ vehicle \37574-01
        };
 };
 
-vehicle \37504
+vehicle "37504"
 {
        // XXX The power car is really in the middle, but that configuration isn't supported yet
        name "BR 420 S-bahn";
@@ -480,7 +480,7 @@ vehicle \37504
        };
 };
 
-vehicle \37851
+vehicle "37851"
 {
        name "BR 150";
        locomotive true;
@@ -512,7 +512,7 @@ vehicle \37851
        };
 };
 
-vehicle \37968
+vehicle "37968"
 {
        name "BR 96";
        locomotive true;
index d84e2d0d5b1535709c2b924d028f0897fcaf75b4..f06356b367bd3ff8c5686465d33c9b751274923e 100644 (file)
@@ -16,12 +16,6 @@ Catalogue3D::Catalogue3D(Catalogue &c):
        src.add_directory(".");
        src.add_directory("data");
        add_source(src);
-
-       catalogue.signal_object_added.connect(sigc::mem_fun(this, &Catalogue3D::object_added));
-
-       const Catalogue::ObjectMap &objs = catalogue.get_all();
-       for(Catalogue::ObjectMap::const_iterator i=objs.begin(); i!=objs.end(); ++i)
-               object_added(*i->second);
 }
 
 Catalogue3D::~Catalogue3D()
@@ -30,19 +24,24 @@ Catalogue3D::~Catalogue3D()
                delete i->second;
 }
 
-void Catalogue3D::object_added(const ObjectType &ot)
+const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot)
 {
+       ObjectMap::iterator i = objects.find(&ot);
+       if(i!=objects.end())
+               return *i->second;
+
+       ObjectType3D *ot3d = 0;
        if(const TrackType *tt = dynamic_cast<const TrackType *>(&ot))
-       {
-               objects[&ot] = new TrackType3D(*this, *tt);
-               const TrackAppearance &appearance = tt->get_appearance();
-               if(!endpoint_meshes.count(&appearance))
-                       build_endpoint_mesh(appearance);
-       }
+               ot3d = new TrackType3D(*this, *tt);
        else if(const SignalType *st = dynamic_cast<const SignalType *>(&ot))
-               objects[&ot] = new SignalType3D(*this, *st);
+               ot3d = new SignalType3D(*this, *st);
        else if(const VehicleType *vt = dynamic_cast<const VehicleType *>(&ot))
-               objects[&ot] = new VehicleType3D(*this, *vt);
+               ot3d = new VehicleType3D(*this, *vt);
+       else
+               throw key_error(&ot);
+
+       objects[&ot] = ot3d;
+       return *ot3d;
 }
 
 const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot) const
@@ -50,8 +49,12 @@ const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot) const
        return *get_item(objects, &ot);
 }
 
-void Catalogue3D::build_endpoint_mesh(const TrackAppearance &appearance)
+const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance)
 {
+       EndpointMap::iterator i = endpoint_meshes.find(&appearance);
+       if(i!=endpoint_meshes.end())
+               return *i->second;
+
        const Profile &ballast_profile = appearance.get_ballast_profile();
        const Vector &ballast_min = ballast_profile.get_min_coords();
        const Vector &ballast_max = ballast_profile.get_max_coords();
@@ -76,6 +79,7 @@ void Catalogue3D::build_endpoint_mesh(const TrackAppearance &appearance)
        bld.end();
 
        endpoint_meshes[&appearance] = mesh;
+       return *mesh;
 }
 
 const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance) const
index 07f1535f2b30583d72ce554124cb4a9195ad5d09..d82529f9fec47e5ebb58a2912941aa8447474a4d 100644 (file)
@@ -15,28 +15,35 @@ class ObjectType3D;
 class Catalogue3D: public Msp::GL::Resources
 {
 private:
+       typedef std::map<const ObjectType *, ObjectType3D *> ObjectMap;
+       typedef std::map<const TrackAppearance *, Msp::GL::Mesh *> EndpointMap;
+
        Catalogue &catalogue;
        Msp::DataFile::DirectorySource src;
-       std::map<const ObjectType *, ObjectType3D *> objects;
-       std::map<const TrackAppearance *, Msp::GL::Mesh *> endpoint_meshes;
+       ObjectMap objects;
+       EndpointMap endpoint_meshes;
 
 public:
        Catalogue3D(Catalogue &);
        ~Catalogue3D();
 
        const Catalogue &get_catalogue() const { return catalogue; }
-private:
-       void object_added(const ObjectType &);
-public:
+
+       const ObjectType3D &get_3d(const ObjectType &);
        const ObjectType3D &get_3d(const ObjectType &) const;
 
        template<typename T>
        const typename TypeMap3D<T>::Type3D &get_3d(const T &ot) const
        { return dynamic_cast<const typename TypeMap3D<T>::Type3D &>(get_3d(static_cast<const ObjectType &>(ot))); }
 
+       template<typename T>
+       const typename TypeMap3D<T>::Type3D &get_3d(const T &ot)
+       { return dynamic_cast<const typename TypeMap3D<T>::Type3D &>(get_3d(static_cast<const ObjectType &>(ot))); }
+
 private:
        void build_endpoint_mesh(const TrackAppearance &);
 public:
+       const Msp::GL::Mesh &get_endpoint_mesh(const TrackAppearance &);
        const Msp::GL::Mesh &get_endpoint_mesh(const TrackAppearance &) const;
 };
 
index aac7672514a76ab7fc443042acea6752e600f5d2..c31c09f951149429182609d3ecaa7d9dd09aef27 100644 (file)
@@ -26,19 +26,18 @@ ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const s
                set_done(false);
        }
 
-       const Catalogue::ObjectMap &object_types = designer.get_catalogue().get_all();
-       for(Catalogue::ObjectMap::const_iterator i=object_types.begin(); i!=object_types.end(); ++i)
-               if(const TrackType *tt = dynamic_cast<const TrackType *>(i->second))
-               {
-                       const vector<TrackPart> &parts = tt->get_parts();
-                       if(parts.size()!=1)
-                               continue;
-                       if(parts.front().is_curved() || parts.front().is_dead_end())
-                               continue;
+       list<TrackType *> track_types = designer.get_catalogue().get_list<TrackType>();
+       for(list<TrackType *>::iterator i=track_types.begin(); i!=track_types.end(); ++i)
+       {
+               const vector<TrackPart> &parts = (*i)->get_parts();
+               if(parts.size()!=1)
+                       continue;
+               if(parts.front().is_curved() || parts.front().is_dead_end())
+                       continue;
 
-                       types_by_length[parts.front().get_length()] = tt;
-                       max_preference = max(max_preference, tt->get_autofit_preference());
-               }
+               types_by_length[parts.front().get_length()] = *i;
+               max_preference = max(max_preference, (*i)->get_autofit_preference());
+       }
 }
 
 ExtendTool::~ExtendTool()
index ef9fbf82b6dfe79a58924f65f5e34b610b31acd2..e0b4e1a279a4c51d7e3c396ad9ad392783cd3682 100644 (file)
@@ -42,11 +42,10 @@ NewTrainDialog::NewTrainDialog(Engineer &e):
 
        drp_protocol->set_selected_index(0);
 
-       const Catalogue::ObjectMap &obj_types = engineer.get_layout().get_catalogue().get_all();
-       for(Catalogue::ObjectMap::const_iterator i=obj_types.begin(); i!=obj_types.end(); ++i)
-               if(const VehicleType *vt = dynamic_cast<const VehicleType *>(i->second))
-                       if(vt->is_locomotive())
-                               loco_types.append(vt);
+       list<VehicleType *> veh_types = engineer.get_layout().get_catalogue().get_list<VehicleType>();
+       for(list<VehicleType *>::iterator i=veh_types.begin(); i!=veh_types.end(); ++i)
+               if((*i)->is_locomotive())
+                       loco_types.append(*i);
 }
 
 void NewTrainDialog::prefill(const Driver::DetectedLocomotive &loco)
index de4d14a7fda8786679bdfaff10bab774dea8402d..e9c537ee0c21f8b0a73a8b665ea542752a5a250c 100644 (file)
@@ -37,15 +37,14 @@ NewVehicleDialog::NewVehicleDialog(Train &t):
 
        dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_add"))->signal_clicked.connect(sigc::mem_fun(this, &NewVehicleDialog::add_clicked));
 
-       const Catalogue::ObjectMap &obj_types = train.get_layout().get_catalogue().get_all();
-       for(Catalogue::ObjectMap::const_iterator i=obj_types.begin(); i!=obj_types.end(); ++i)
-               if(const VehicleType *vt = dynamic_cast<const VehicleType *>(i->second))
-               {
-                       if(vt->is_locomotive())
-                               loco_types.append(vt);
-                       else
-                               wagon_types.append(vt);
-               }
+       list<VehicleType *> veh_types = train.get_layout().get_catalogue().get_list<VehicleType>();
+       for(list<VehicleType *>::iterator i=veh_types.begin(); i!=veh_types.end(); ++i)
+       {
+               if((*i)->is_locomotive())
+                       loco_types.append(*i);
+               else
+                       wagon_types.append(*i);
+       }
 }
 
 void NewVehicleDialog::toggle_list(bool show, GLtk::List *lst)
index 572423a7f4048279d67b3b2027dc6979e384cc73..cfd5d6425f29d971bc116d96c72cfe0307eb4468 100644 (file)
@@ -15,28 +15,17 @@ namespace R2C2 {
 Catalogue::Catalogue():
        scale(1),
        layout(*this)
-{ }
-
-Catalogue::~Catalogue()
-{
-       for(ObjectMap::iterator i=objects.begin(); i!=objects.end(); ++i)
-               delete i->second;
-}
-
-void Catalogue::add(ObjectType &object)
 {
-       insert_unique(objects, object.get_article_number(), &object);
-       signal_object_added.emit(object);
-}
-
-const ObjectType &Catalogue::get(const ArticleNumber &art_nr) const
-{
-       return *get_item(objects, art_nr);
+       add_type<TrackType>();
+       add_type<SignalType>();
+       add_type<VehicleType>();
+       add_type<TerrainType>();
 }
 
 
 Catalogue::Loader::Loader(Catalogue &c):
-       DataFile::ObjectLoader<Catalogue>(c)
+       Collection::Loader(c),
+       cat(c)
 {
        add("layout", &Loader::layout);
        add("scale", &Loader::scale);
@@ -49,57 +38,49 @@ Catalogue::Loader::Loader(Catalogue &c):
 
 void Catalogue::Loader::layout()
 {
-       load_sub(obj.layout);
+       load_sub(cat.layout);
 }
 
 void Catalogue::Loader::scale(float n, float d)
 {
-       obj.scale = n/d;
+       cat.scale = n/d;
 }
 
-void Catalogue::Loader::signal(ArticleNumber art_nr)
+void Catalogue::Loader::signal(const string &n)
 {
-       if(obj.objects.count(art_nr))
-               throw key_error(art_nr);
-
-       RefPtr<SignalType> sig = new SignalType(art_nr);
+       RefPtr<SignalType> sig = new SignalType(n);
        load_sub(*sig);
-       obj.add(*sig.release());
+       cat.add(n, sig.get());
+       sig.release();
 }
 
-void Catalogue::Loader::terrain(ArticleNumber art_nr)
+void Catalogue::Loader::terrain(const string &n)
 {
-       if(obj.objects.count(art_nr))
-               throw key_error(art_nr);
-
-       RefPtr<TerrainType> ter = new TerrainType(art_nr);
+       RefPtr<TerrainType> ter = new TerrainType(n);
        load_sub(*ter);
-       obj.add(*ter.release());
+       cat.add(n, ter.get());
+       ter.release();
 }
 
-void Catalogue::Loader::track(ArticleNumber art_nr)
+void Catalogue::Loader::track(const string &n)
 {
-       if(obj.objects.count(art_nr))
-               throw key_error(art_nr);
-
-       RefPtr<TrackType> trk = new TrackType(art_nr, obj.appearance);
+       RefPtr<TrackType> trk = new TrackType(n, &cat.appearance);
        load_sub(*trk);
-       obj.add(*trk.release());
+       cat.add(n, trk.get());
+       trk.release();
 }
 
 void Catalogue::Loader::track_appearance()
 {
-       load_sub(obj.appearance);
+       load_sub(cat.appearance);
 }
 
-void Catalogue::Loader::vehicle(ArticleNumber art_nr)
+void Catalogue::Loader::vehicle(const string &n)
 {
-       if(obj.objects.count(art_nr))
-               throw key_error(art_nr);
-
-       RefPtr<VehicleType> veh = new VehicleType(art_nr);
+       RefPtr<VehicleType> veh = new VehicleType(n);
        load_sub(*veh);
-       obj.add(*veh.release());
+       cat.add(n, veh.get());
+       veh.release();
 }
 
 } // namespace R2C2
index 92d1149f1f4162a0030857782af9b95f472cc310..e8a474432251adfafec5e514fb794a93575e6942 100644 (file)
@@ -2,7 +2,7 @@
 #define LIBR2C2_CATALOGUE_H_
 
 #include <map>
-#include <msp/datafile/objectloader.h>
+#include <msp/datafile/collection.h>
 #include "articlenumber.h"
 #include "layout.h"
 #include "trackappearance.h"
@@ -11,47 +11,35 @@ namespace R2C2 {
 
 class ObjectType;
 
-class Catalogue
+class Catalogue: public Msp::DataFile::Collection
 {
 public:
-       class Loader: public Msp::DataFile::ObjectLoader<Catalogue>
+       class Loader: public Msp::DataFile::Collection::Loader
        {
+       private:
+               Catalogue &cat;
+
        public:
                Loader(Catalogue &);
        private:
                void layout();
                void scale(float, float);
-               void signal(ArticleNumber);
-               void terrain(ArticleNumber);
-               void track(ArticleNumber);
+               void signal(const std::string &);
+               void terrain(const std::string &);
+               void track(const std::string &);
                void track_appearance();
-               void vehicle(ArticleNumber);
+               void vehicle(const std::string &);
        };
 
-       typedef std::map<ArticleNumber, ObjectType *> ObjectMap;
-
-       sigc::signal<void, const ObjectType &> signal_object_added;
-
 private:
        float scale;
        TrackAppearance appearance;
-       ObjectMap objects;
        Layout layout;
 
 public:
        Catalogue();
-       ~Catalogue();
 
        float get_scale() const { return scale; }
-
-       void add(ObjectType &);
-       const ObjectType &get(const ArticleNumber &) const;
-       const ObjectMap &get_all() const { return objects; }
-
-       template<typename T>
-       const T &get(const ArticleNumber &an) const
-       { return dynamic_cast<const T &>(get(an)); }
-
        Layout &get_layout() { return layout; }
 };
 
index 43ce921475cf9971b3ff518f48cf6d5425aedf14..0901382b91d0f140bb8ddf39010bf41228b33bfb 100644 (file)
@@ -420,7 +420,7 @@ void Layout::save(const string &fn) const
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
                DataFile::Statement st("track");
-               st.append((*i)->get_type().get_article_number());
+               st.append(catalogue.get_name(&(*i)->get_type()));
                (*i)->save(st.sub);
                writer.write(st);
        }
@@ -429,7 +429,7 @@ void Layout::save(const string &fn) const
        for(set<Signal *>::const_iterator i=signals.begin(); i!=signals.end(); ++i)
        {
                DataFile::Statement st("signal");
-               st.append((*i)->get_type().get_article_number());
+               st.append(catalogue.get_name(&(*i)->get_type()));
                (*i)->save(st.sub);
                writer.write(st);
        }
@@ -438,7 +438,7 @@ void Layout::save(const string &fn) const
        for(set<Terrain *>::const_iterator i=terrains.begin(); i!=terrains.end(); ++i)
        {
                DataFile::Statement st("terrain");
-               st.append((*i)->get_type().get_article_number());
+               st.append(catalogue.get_name(&(*i)->get_type()));
                (*i)->save(st.sub);
                writer.write(st);
        }
@@ -490,7 +490,7 @@ void Layout::save_dynamic(const string &fn) const
        for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
                DataFile::Statement st("train");
-               st.append(i->second->get_locomotive_type().get_article_number());
+               st.append(catalogue.get_name(&i->second->get_locomotive_type()));
                st.append(i->second->get_address());
                st.append(i->second->get_protocol());
                i->second->save(st.sub);
@@ -594,21 +594,21 @@ void Layout::Loader::route()
        load_sub(*rte);
 }
 
-void Layout::Loader::signal(ArticleNumber art_nr)
+void Layout::Loader::signal(const string &n)
 {
-       Signal *sig = new Signal(obj, obj.catalogue.get<SignalType>(art_nr));
+       Signal *sig = new Signal(obj, obj.catalogue.get<SignalType>(n));
        load_sub(*sig);
 }
 
-void Layout::Loader::terrain(ArticleNumber art_nr)
+void Layout::Loader::terrain(const string &n)
 {
-       Terrain *ter = new Terrain(obj, obj.catalogue.get<TerrainType>(art_nr));
+       Terrain *ter = new Terrain(obj, obj.catalogue.get<TerrainType>(n));
        load_sub(*ter);
 }
 
-void Layout::Loader::track(ArticleNumber art_nr)
+void Layout::Loader::track(const string &n)
 {
-       Track *trk = new Track(obj, obj.catalogue.get<TrackType>(art_nr));
+       Track *trk = new Track(obj, obj.catalogue.get<TrackType>(n));
        load_sub(*trk);
        const set<Track *> &tracks = obj.objects.get<Track>();
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
@@ -616,9 +616,9 @@ void Layout::Loader::track(ArticleNumber art_nr)
                        trk->link_to(**i);
 }
 
-void Layout::Loader::train(ArticleNumber art_nr, unsigned addr, const std::string &proto)
+void Layout::Loader::train(const string &n, unsigned addr, const std::string &proto)
 {
-       Train *trn = new Train(obj, obj.catalogue.get<VehicleType>(art_nr), addr, proto);
+       Train *trn = new Train(obj, obj.catalogue.get<VehicleType>(n), addr, proto);
        load_sub(*trn);
 }
 
index 41de73d7dc11f9b46e3e209c318ff801a6c69851..887b2d189f453dcc2dab13e59316f0642ce54df5 100644 (file)
@@ -36,10 +36,10 @@ public:
                void beamgate();
                void clock();
                void route();
-               void signal(ArticleNumber);
-               void terrain(ArticleNumber);
-               void track(ArticleNumber);
-               void train(ArticleNumber, unsigned, const std::string &);
+               void signal(const std::string &);
+               void terrain(const std::string &);
+               void track(const std::string &);
+               void train(const std::string &, unsigned, const std::string &);
                void turnout(unsigned, unsigned);
                void zone();
        };
index 97de833d71b5b7cdf59b93e57438ff44d9f46e94..be3857a8da2a7186f6d1d966184813de8680d745 100644 (file)
@@ -37,7 +37,7 @@ private:
        std::string object;
 
 public:
-       SignalType(const ArticleNumber &);
+       SignalType(const ArticleNumber & = ArticleNumber());
 
        const IndicationList &get_indications() const { return indications; }
        const std::string &get_object() const { return object; }
index f0013ad425cfe4241ef6d6ed2edfc9482b2c0dfa..8bd59eaf8605d6347739a19543a0b5ac2c4f9c2b 100644 (file)
@@ -37,7 +37,7 @@ private:
        float elevation_granularity;
 
 public:
-       TerrainType(const ArticleNumber &);
+       TerrainType(const ArticleNumber & = ArticleNumber());
 
        unsigned get_n_surface_types() const { return surface_types.size(); }
        const SurfaceType &get_surface_type(unsigned) const;
index 3c6876b0cc8b5bd72a7e0f476f45b6d631f2aa6a..c2740f1d39b33ccfe10f819863ea26da220544f8 100644 (file)
@@ -8,16 +8,23 @@ using namespace Msp;
 
 namespace R2C2 {
 
-TrackType::TrackType(const ArticleNumber &an, const TrackAppearance &ta):
+TrackType::TrackType(const ArticleNumber &an, const TrackAppearance *ta):
        ObjectType(an),
        appearance(ta),
        state_bits(0),
        autofit_preference(1)
 { }
 
+const TrackAppearance &TrackType::get_appearance() const
+{
+       if(!appearance)
+               throw logic_error("no appearance");
+       return *appearance;
+}
+
 float TrackType::get_gauge() const
 {
-       return appearance.get_gauge();
+       return get_appearance().get_gauge();
 }
 
 float TrackType::get_total_length() const
index 9d167d18c7c91822ebd25b1dd047fc8a6233309e..2a116134d850b0353a0ba1f2586bea15caa52a2d 100644 (file)
@@ -41,7 +41,7 @@ public:
        };
 
 private:
-       const TrackAppearance &appearance;
+       const TrackAppearance *appearance;
        std::vector<TrackPart> parts;
        std::vector<Endpoint> endpoints;
        unsigned state_bits;
@@ -49,9 +49,9 @@ private:
        std::string object;
 
 public:
-       TrackType(const ArticleNumber &, const TrackAppearance &);
+       TrackType(const ArticleNumber & = ArticleNumber(), const TrackAppearance * = 0);
 
-       const TrackAppearance &get_appearance() const { return appearance; }
+       const TrackAppearance &get_appearance() const;
        float get_gauge() const;
        float get_total_length() const;
        float get_path_length(int) const;
index b670d4137fc303df68b2e84ade2cc710d5a9c11a..6ba868461b6da2eb5e995673053eada3f55a6369 100644 (file)
@@ -385,9 +385,10 @@ void Train::save(list<DataFile::Statement> &st) const
 {
        st.push_back((DataFile::Statement("name"), name));
 
+       const Catalogue &cat = layout.get_catalogue();
        for(vector<Vehicle *>::const_iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
                if(i!=vehicles.begin())
-                       st.push_back((DataFile::Statement("vehicle"), (*i)->get_type().get_article_number()));
+                       st.push_back((DataFile::Statement("vehicle"), cat.get_name(&(*i)->get_type())));
 
        if(speed_quantizer)
        {
@@ -623,9 +624,9 @@ void Train::Loader::timetable()
        load_sub(*ttbl, obj.layout);
 }
 
-void Train::Loader::vehicle(ArticleNumber art_nr)
+void Train::Loader::vehicle(const string &n)
 {
-       const VehicleType &vtype = obj.layout.get_catalogue().get<VehicleType>(art_nr);
+       const VehicleType &vtype = obj.layout.get_catalogue().get<VehicleType>(n);
        Vehicle *veh = new Vehicle(obj.layout, vtype);
        obj.vehicles.back()->attach_back(*veh);
        obj.vehicles.push_back(veh);
index 6d9a20f7c2ee5b5ea5af15bf0e5b0629a070d7dc..113af0e09a3d424f5744406601d4c5640ce67730 100644 (file)
@@ -36,7 +36,7 @@ public:
                void quantized_speed();
                void router();
                void timetable();
-               void vehicle(ArticleNumber);
+               void vehicle(const std::string &);
        };
 
        sigc::signal<void, const std::string &> signal_name_changed;
index 789aeb3e59e7a6e8de0bce6c4b681573c19ff092..4a4d725cbab8daadabf7ec95cedf90017fa794a3 100644 (file)
@@ -180,7 +180,7 @@ private:
        float max_speed;
 
 public:
-       VehicleType(const ArticleNumber &);
+       VehicleType(const ArticleNumber & = ArticleNumber());
 
        bool is_locomotive() const { return locomotive; }
        unsigned get_max_function() const;
index aced6f7202f2e6dc894af1ec686fb4fb51a1c72f..a892dedd25a85c79e9ba8edd1f3c60db767855a6 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/refptr.h>
 #include <msp/net/inet.h>
 #include <msp/net/resolve.h>
+#include "libr2c2/catalogue.h"
 #include "libr2c2/driver.h"
 #include "libr2c2/route.h"
 #include "libr2c2/train.h"
@@ -74,7 +75,7 @@ void Server::train_added(Train &train)
 
        TrainInfoPacket pkt;
        pkt.address = train.get_address();
-       pkt.loco_type = train.get_locomotive_type().get_article_number().str();
+       pkt.loco_type = layout.get_catalogue().get_name(&train.get_locomotive_type());
        pkt.name = train.get_name();
        send(pkt);
 
@@ -169,6 +170,7 @@ void Server::Connection::handshake_done()
                        comm.send(pkt);
                }
 
+       const Catalogue &cat = server.layout.get_catalogue();
        const map<unsigned, Train *> &trains = server.layout.get_trains();
        for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
@@ -177,7 +179,7 @@ void Server::Connection::handshake_done()
                {
                        TrainInfoPacket pkt;
                        pkt.address = train.get_address();
-                       pkt.loco_type = train.get_locomotive_type().get_article_number().str();
+                       pkt.loco_type = cat.get_name(&train.get_locomotive_type());
                        pkt.name = train.get_name();
                        comm.send(pkt);
                }
index 4ebd956d824e7a73976fb3000e7c63094d44c7cb..276a4c7877d0f68ec68bc1302291c11995456216 100644 (file)
@@ -4,11 +4,9 @@
 #include <msp/datafile/loader.h>
 #include <msp/datafile/parser.h>
 #include <msp/io/print.h>
-#include "libr2c2/articlenumber.h"
 
 using namespace std;
 using namespace Msp;
-using namespace R2C2;
 
 class ShoppingList: public RegisteredApplication<ShoppingList>
 {
@@ -20,7 +18,7 @@ private:
        private:
                ShoppingList &sl;
 
-               void track(ArticleNumber, int);
+               void track(const string &, int);
        };
 
        class LayoutLoader: public DataFile::Loader
@@ -30,11 +28,11 @@ private:
        private:
                ShoppingList &sl;
 
-               void track(ArticleNumber);
+               void track(const string &);
        };
 
-       map<ArticleNumber, unsigned> inventory;
-       map<ArticleNumber, unsigned> layout;
+       map<string, unsigned> inventory;
+       map<string, unsigned> layout;
 
 public:
        ShoppingList(int, char **);
@@ -59,37 +57,37 @@ ShoppingList::ShoppingList(int argc, char **argv)
 int ShoppingList::main()
 {
        IO::print("// Need to get:\n");
-       for(map<ArticleNumber, unsigned>::iterator i=layout.begin(); i!=layout.end(); ++i)
+       for(map<string, unsigned>::iterator i=layout.begin(); i!=layout.end(); ++i)
        {
-               map<ArticleNumber, unsigned>::iterator j=inventory.find(i->first);
+               map<string, unsigned>::iterator j=inventory.find(i->first);
                if(j!=inventory.end())
                {
                        if(j->second<i->second)
-                               IO::print("track \\%d %d;\n", i->first, i->second-j->second);
+                               IO::print("track \"%s\" %d;\n", i->first, i->second-j->second);
                }
                else
-                       IO::print("track \\%d %d;\n", i->first, i->second);
+                       IO::print("track \"%s\" %d;\n", i->first, i->second);
        }
 
        IO::print("// Pre-existing:\n");
-       for(map<ArticleNumber, unsigned>::iterator i=layout.begin(); i!=layout.end(); ++i)
+       for(map<string, unsigned>::iterator i=layout.begin(); i!=layout.end(); ++i)
        {
-               map<ArticleNumber, unsigned>::iterator j=inventory.find(i->first);
+               map<string, unsigned>::iterator j=inventory.find(i->first);
                if(j!=inventory.end())
-                       IO::print("track \\%d %d;\n", i->first, min(i->second, j->second));
+                       IO::print("track \"%s\" %d;\n", i->first, min(i->second, j->second));
        }
 
        IO::print("// Unused:\n");
-       for(map<ArticleNumber, unsigned>::iterator i=inventory.begin(); i!=inventory.end(); ++i)
+       for(map<string, unsigned>::iterator i=inventory.begin(); i!=inventory.end(); ++i)
        {
-               map<ArticleNumber, unsigned>::iterator j=layout.find(i->first);
+               map<string, unsigned>::iterator j=layout.find(i->first);
                if(j!=layout.end())
                {
                        if(j->second<i->second)
-                               IO::print("track \\%d %d;\n", i->first, i->second-j->second);
+                               IO::print("track \"%s\" %d;\n", i->first, i->second-j->second);
                }
                else
-                       IO::print("track \\%d %d;\n", i->first, i->second);
+                       IO::print("track \"%s\" %d;\n", i->first, i->second);
        }
 
        return 0;
@@ -118,9 +116,9 @@ ShoppingList::InventoryLoader::InventoryLoader(ShoppingList &s):
        add("track", &InventoryLoader::track);
 }
 
-void ShoppingList::InventoryLoader::track(ArticleNumber art_nr, int count)
+void ShoppingList::InventoryLoader::track(const string &n, int count)
 {
-       sl.inventory[art_nr] += count;
+       sl.inventory[n] += count;
 }
 
 
@@ -136,7 +134,7 @@ ShoppingList::LayoutLoader::LayoutLoader(ShoppingList &s):
        add("zone");
 }
 
-void ShoppingList::LayoutLoader::track(ArticleNumber art_nr)
+void ShoppingList::LayoutLoader::track(const string &n)
 {
-       ++sl.layout[art_nr];
+       ++sl.layout[n];
 }
index e32551d6da26eb6cf35fbb7f0c14e68a1162ebe8..073c5b75a61bd994547e0da6ac655dd092757c37 100644 (file)
@@ -1,4 +1,4 @@
-terrain \100001
+terrain "100001"
 {
        surface
        {
@@ -10,7 +10,7 @@ terrain \100001
 
 layout
 {
-       terrain \100001
+       terrain "100001"
        {
                position 0.1519720 0.2448861 0.000000;
                rotation 0.000000;
index 91224575a938fe9f20fc3aded18a8ca6dd70ab61..057b40ab7b998ef54fda88b9ea98d101bb8842a3 100644 (file)
@@ -42,7 +42,7 @@ track_appearance
 
 // Straight
 
-track \24064
+track "24064"
 {
        description "Straight, 64.3mm (R3-R4-R5)";
        part
@@ -51,7 +51,7 @@ track \24064
        };
 };
 
-track \24071
+track "24071"
 {
        description "Straight, 70.8mm (for slim turnouts)";
        part
@@ -61,7 +61,7 @@ track \24071
        autofit_preference 0;
 };
 
-track \24077
+track "24077"
 {
        description "Straight, 77.5mm (R1-R2-R3)";
        part
@@ -71,7 +71,7 @@ track \24077
        autofit_preference 2;
 };
 
-track \24094
+track "24094"
 {
        description "Straight, 94.2mm";
        part
@@ -81,7 +81,7 @@ track \24094
        autofit_preference 2;
 };
 
-track \24172
+track "24172"
 {
        description "Straight, 171.7mm";
        part
@@ -91,7 +91,7 @@ track \24172
        autofit_preference 2;
 };
 
-track \24188
+track "24188"
 {
        description "Straight, 188.3mm (turnout length)";
        part
@@ -101,7 +101,7 @@ track \24188
        autofit_preference 2;
 };
 
-track \24229
+track "24229"
 {
        description "Straight, 229.3mm";
        part
@@ -110,7 +110,7 @@ track \24229
        };
 };
 
-track \24236
+track "24236"
 {
        description "Straight, 236.1mm (slim turnout length)";
        part
@@ -119,7 +119,7 @@ track \24236
        };
 };
 
-track \24360
+track "24360"
 {
        description "Straight, 360mm";
        part
@@ -130,7 +130,7 @@ track \24360
 
 // Curves, R1
 
-track \24107
+track "24107"
 {
        description "Curve, R1 = 360mm, 7.5°";
        part
@@ -140,7 +140,7 @@ track \24107
        };
 };
 
-track \24115
+track "24115"
 {
        description "Curve, R1 = 360mm, 15°";
        part
@@ -150,7 +150,7 @@ track \24115
        };
 };
 
-track \24130
+track "24130"
 {
        description "Curve, R1 = 360mm, 30°";
        part
@@ -162,7 +162,7 @@ track \24130
 
 // Curves, R2
 
-track \24206
+track "24206"
 {
        description "Curve, R2 = 437.5mm, 5.7° (turnout to 30°)";
        part
@@ -172,7 +172,7 @@ track \24206
        };
 };
 
-track \24207
+track "24207"
 {
        description "Curve, R2 = 437.5mm, 7.5°";
        part
@@ -182,7 +182,7 @@ track \24207
        };
 };
 
-track \24215
+track "24215"
 {
        description "Curve, R2 = 437.5mm, 15°";
        part
@@ -192,7 +192,7 @@ track \24215
        };
 };
 
-track \24224
+track "24224"
 {
        description "Curve, R2 = 437.5mm, 24.3° (turnout)";
        part
@@ -202,7 +202,7 @@ track \24224
        };
 };
 
-track \24230
+track "24230"
 {
        description "Curve, R2 = 437.5mm, 30°";
        part
@@ -214,7 +214,7 @@ track \24230
 
 // Curves, R3
 
-track \24330
+track "24330"
 {
        description "Curve, R3 = 515mm, 30°";
        part
@@ -226,7 +226,7 @@ track \24330
 
 // Curves, R4
 
-track \24430
+track "24430"
 {
        description "Curve, R4 = 579.3mm, 30°";
        part
@@ -238,7 +238,7 @@ track \24430
 
 // Curves, R5
 
-track \24530
+track "24530"
 {
        description "Curve, R5 = 643.6mm, 30°";
        part
@@ -250,7 +250,7 @@ track \24530
 
 // Curves, slim turnout
 
-track \24912
+track "24912"
 {
        description "Curve, R = 1114.6mm, 12.1° (slim turnout)";
        part
@@ -262,7 +262,7 @@ track \24912
 
 // Curved turnouts, R1
 
-track \24671
+track "24671"
 {
        description "Curved turnout, left";
        part
@@ -285,7 +285,7 @@ track \24671
        };
 };
 
-track \24672
+track "24672"
 {
        description "Curved turnout, right";
        part
@@ -310,7 +310,7 @@ track \24672
 
 // Turnouts, R2
 
-track \24611
+track "24611"
 {
        description "Turnout, left";
        part
@@ -326,7 +326,7 @@ track \24611
        };
 };
 
-track \24612
+track "24612"
 {
        description "Turnout, right";
        part
@@ -342,7 +342,7 @@ track \24612
        };
 };
 
-track \24630
+track "24630"
 {
        description "Turnout, 3-way";
        part
@@ -364,7 +364,7 @@ track \24630
        };
 };
 
-track \24624
+track "24624"
 {
        description "Turnout, double slip";
        state_bits 1;
@@ -396,7 +396,7 @@ track \24624
 
 // Slim turnouts
 
-track \24711
+track "24711"
 {
        description "Slim turnout, left";
        part
@@ -412,7 +412,7 @@ track \24711
        };
 };
 
-track \24712
+track "24712"
 {
        description "Slim turnout, right";
        part
@@ -430,7 +430,7 @@ track \24712
 
 // Crossings
 
-track \24640
+track "24640"
 {
        description "Crossing, 24.3°";
        part
@@ -444,7 +444,7 @@ track \24640
        };
 };
 
-track \24649
+track "24649"
 {
        description "Crossing, 48.6°";
        part
@@ -458,7 +458,7 @@ track \24649
        };
 };
 
-track \24740
+track "24740"
 {
        description "Slim crossing, 12.1°";
        part
@@ -474,7 +474,7 @@ track \24740
 
 // Specials
 
-track \24977
+track "24977"
 {
        description "Bumper";
        object "bumper.object";
@@ -487,7 +487,7 @@ track \24977
 
 // Signals
 
-signal \7039
+signal "7039"
 {
        indication "Hp1"
        {
@@ -511,172 +511,172 @@ layout
                position -0.3876098 0.3496740 0.000000;
                rotation 1.570800;
        };
-       track \24115
+       track "24115"
        {
                position 0.0806517 0.139002 0;
                rotation 2.22529;
        };
-       track \24612
+       track "24612"
        {
                position -0.310086 -0.38055 0;
                rotation 1.5708;
        };
-       track \24172
+       track "24172"
        {
                position -0.232565 -0.0797749 0;
                rotation 1.5708;
        };
-       track \24611
+       track "24611"
        {
                position -0.387608 -0.380475 0;
                rotation 1.5708;
        };
-       track \24130
+       track "24130"
        {
                position 0.155044 -0.08015 0;
                rotation 1.5708;
        };
-       track \24230
+       track "24230"
        {
                position 0.232566 -0.0802249 0;
                rotation 1.5708;
        };
-       track \24107
+       track "24107"
        {
                position -0.0249545 0.231617 0;
                rotation 2.61799;
        };
-       track \24224
+       track "24224"
        {
                position -0.465131 -0.38055 0;
                rotation 1.5708;
        };
-       track \24330
+       track "24330"
        {
                position 0.310088 -0.0803 0;
                rotation 1.5708;
        };
-       track \24215
+       track "24215"
        {
                position 0.142158 0.186105 0;
                rotation 2.2253;
        };
-       track \24207
+       track "24207"
        {
                position 0.0138165 0.298658 0;
                rotation 2.61799;
        };
-       track \24711
+       track "24711"
        {
                position 0.374455 -0.381008 0;
                rotation 1.5708;
        };
-       track \24530
+       track "24530"
        {
                position 0.438821 -0.0809179 0;
                rotation 1.5708;
        };
-       track \24430
+       track "24430"
        {
                position 0.374455 -0.080609 0;
                rotation 1.5708;
        };
-       track \24630
+       track "24630"
        {
                position -0.19005 -0.380551 0;
                rotation 1.5708;
        };
-       track \24712
+       track "24712"
        {
                position 0.438821 -0.381316 0;
                rotation 1.5708;
        };
-       track \24624
+       track "24624"
        {
                position -0.0775215 -0.380625 0;
                rotation 1.5708;
        };
-       track \24640
+       track "24640"
        {
                position -0.232565 0.185972 0;
                rotation 1.5708;
        };
-       track \24671
+       track "24671"
        {
                position 0.0775225 -0.380624 0;
                rotation 1.5708;
        };
-       track \24977
+       track "24977"
        {
                position -0.465131 0.186196 0;
                rotation 1.5708;
        };
-       track \24672
+       track "24672"
        {
                position 0.155044 -0.380699 0;
                rotation 1.5708;
        };
-       track \24649
+       track "24649"
        {
                position -0.348827 0.194312 0;
                rotation 1.99491;
        };
-       track \24064
+       track "24064"
        {
                position 0.0775223 -0.080075 0;
                rotation 1.5708;
        };
-       track \24077
+       track "24077"
        {
                position -0.0775215 -0.079925 0;
                rotation 1.5708;
        };
-       track \24229
+       track "24229"
        {
                position -0.387609 -0.079626 0;
                rotation 1.5708;
        };
-       track \24071
+       track "24071"
        {
                position 2.56295e-07 -0.0799999 0;
                rotation 1.5708;
        };
-       track \24094
+       track "24094"
        {
                position -0.155042 -0.07985 0;
                rotation 1.5708;
        };
-       track \24188
+       track "24188"
        {
                position -0.310087 -0.0797 0;
                rotation 1.5708;
        };
-       track \24236
+       track "24236"
        {
                position -0.465131 -0.0795509 0;
                rotation 1.5708;
        };
-       track \24912
+       track "24912"
        {
                position 0.310088 -0.380699 0;
                rotation 1.5708;
        };
-       track \24206
+       track "24206"
        {
                position -0.446223 -0.161726 0;
                rotation 2.0944;
        };
-       track \24740
+       track "24740"
        {
                position -0.112537 0.138174 0;
                rotation 1.5708;
        };
-       track \24360
+       track "24360"
        {
                position -0.542646 -0.0794758 0;
                rotation 1.5708;
        };
-       signal \7039
+       signal "7039"
        {
                position -0.5020055 0.3153508 0.000000;
                rotation 1.570800;
index 4f0592cf63a4d934f7c80cf2fba6ec6bacbad04a..6e110682de47196b40dd898f0d057eb919008bb2 100644 (file)
@@ -1,6 +1,6 @@
 scale 1 87;
 
-vehicle \46274
+vehicle "46274"
 {
        name "Saar Railroad Gmhs 54";
 
@@ -15,7 +15,7 @@ vehicle \46274
        axle { position -31; wheel_diameter 10; };
 };
 
-vehicle \29820-02b
+vehicle "29820-02b"
 {
        name "BR 50 tender";
 
@@ -42,7 +42,7 @@ vehicle \29820-02b
        };
 };
 
-vehicle \4442
+vehicle "4442"
 {
        name "Z";
 
@@ -57,7 +57,7 @@ vehicle \4442
        axle { position -31; wheel_diameter 10; };
 };
 
-vehicle \29859b
+vehicle "29859b"
 {
        name "Zas";
 
@@ -82,7 +82,7 @@ vehicle \29859b
        };
 };
 
-vehicle \100004
+vehicle "100004"
 {
        name "Omm 52";
 
@@ -97,7 +97,7 @@ vehicle \100004
        axle { position -31; wheel_diameter 10; };
 };
 
-vehicle \47001
+vehicle "47001"
 {
        name "Rs 684";
 
@@ -124,7 +124,7 @@ vehicle \47001
        };
 };
 
-vehicle \48943
+vehicle "48943"
 {
        name "BTr 10";
 
@@ -139,7 +139,7 @@ vehicle \48943
        axle { position -23; wheel_diameter 10; };
 };
 
-vehicle \43222
+vehicle "43222"
 {
        name "B4üw 38 \"Schürzenwagen\"";
 
@@ -164,7 +164,7 @@ vehicle \43222
        };
 };
 
-vehicle \39230b
+vehicle "39230b"
 {
        name "BR 23 tender";
 
@@ -189,7 +189,7 @@ vehicle \39230b
        };
 };
 
-vehicle \43800
+vehicle "43800"
 {
        name "B4nzb 64 \"Silberling\"";
 
@@ -217,7 +217,7 @@ vehicle \43800
        };
 };
 
-vehicle \47072
+vehicle "47072"
 {
        name "Sgns 691";
 
@@ -244,7 +244,7 @@ vehicle \47072
        };
 };
 
-vehicle \4624
+vehicle "4624"
 {
        name "Fals-u 176";
 
@@ -271,7 +271,7 @@ vehicle \4624
        };
 };
 
-vehicle \4423
+vehicle "4423"
 {
        name "Kklm 505";
 
@@ -286,7 +286,7 @@ vehicle \4423
        axle { position -31; wheel_diameter 10; };
 };
 
-vehicle \4410
+vehicle "4410"
 {
        name "Gs 210";
 
@@ -301,7 +301,7 @@ vehicle \4410
        axle { position -31; wheel_diameter 10; };
 };
 
-vehicle \46977
+vehicle "46977"
 {
        name "Rlmmso 56";
 
@@ -316,7 +316,7 @@ vehicle \46977
        axle { position -46; wheel_diameter 10; };
 };
 
-vehicle \4699
+vehicle "4699"
 {
        name "Pwg 14";
 
@@ -331,7 +331,7 @@ vehicle \4699
        axle { position -25; wheel_diameter 10; };
 };
 
-vehicle \46717
+vehicle "46717"
 {
        name "Railway crane";
 
@@ -347,7 +347,7 @@ vehicle \46717
        axle { position -21.5; wheel_diameter 10; };
 };
 
-vehicle \4690
+vehicle "4690"
 {
        name "Eaos 106";
 
@@ -375,7 +375,7 @@ vehicle \4690
        };
 };
 
-vehicle \37504b
+vehicle "37504b"
 {
        // XXX The power car is really in the middle, but that configuration isn't supported yet
        name "BR 421 S-bahn";
@@ -404,7 +404,7 @@ vehicle \37504b
        };
 };
 
-vehicle \37504c
+vehicle "37504c"
 {
        // XXX Better solution would be to allow flipping of vehicles
        name "BR 420 S-bahn";