]> git.tdb.fi Git - r2c2.git/commitdiff
Move gauge to TrackAppearance
authorMikko Rasa <tdb@tdb.fi>
Sat, 3 May 2014 09:15:22 +0000 (12:15 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 3 May 2014 10:35:27 +0000 (13:35 +0300)
It may eventually be desirable to have multiple gauges in the same layout
(narrow-gauge trams together with a standard-gauge railway, for example),
and this is a necessary step towards that.

20 files changed:
locos.dat
source/3d/catalogue.cpp
source/3d/path.cpp
source/3d/tracktype.cpp
source/designer/cameracontroller.cpp
source/designer/extendtool.cpp
source/designer/movetool.cpp
source/designer/movetool.h
source/designer/svgexporter.cpp
source/designer/svgexporter.h
source/libr2c2/beamgate.cpp
source/libr2c2/catalogue.cpp
source/libr2c2/catalogue.h
source/libr2c2/signal.cpp
source/libr2c2/track.cpp
source/libr2c2/trackappearance.cpp
source/libr2c2/trackappearance.h
source/libr2c2/trackattachment.cpp
tracks.dat
wagons.dat

index dd2ebfe43258a984751a699661f7c44907d8522c..fb22469f3f9c2c97c02875be6ed1ea111b36e9cd 100644 (file)
--- a/locos.dat
+++ b/locos.dat
@@ -1,5 +1,4 @@
 scale 1 87;
-gauge 16.5;
 
 vehicle \39230
 {
index 2f932d62f1c6b6133c49958494b6b8e599ed2059..d84e2d0d5b1535709c2b924d028f0897fcaf75b4 100644 (file)
@@ -60,7 +60,7 @@ void Catalogue3D::build_endpoint_mesh(const TrackAppearance &appearance)
        const Vector &rail_min = rail_profile.get_min_coords();
        const Vector &rail_max = rail_profile.get_max_coords();
 
-       float gauge = catalogue.get_gauge();
+       float gauge = appearance.get_gauge();
 
        float width = max(max(-ballast_min.x, ballast_max.x)*2, gauge+(rail_max.x-rail_min.x)*2)+0.004;
        float height = ballast_max.y-ballast_min.y+rail_max.y-rail_min.y+0.01;
index f9e51f4974a790efa0fb51e141ee7256efebbd85..8c36a3088f249f65305e9c13c5ea4e0a7f1d1e7f 100644 (file)
@@ -59,7 +59,7 @@ void Path3D::set_color(const GL::Color &c)
 
 void Path3D::set_layer(float l)
 {
-       z_offs = l*layout.get_layout().get_catalogue().get_gauge()*0.01;
+       z_offs = l*track.get_track().get_type().get_appearance().get_gauge()*0.01;
 }
 
 void Path3D::path_changed(unsigned p)
index aad2ca898d1bc5ca9126ad5474a0c3bd3f2a52c6..b9ebc73c31708615536549b3e4a771c2a56b5ec1 100644 (file)
@@ -16,7 +16,6 @@ TrackType3D::TrackType3D(Catalogue3D &c, const TrackType &tt):
        own_data(false)
 {
        const TrackAppearance &appearance = tt.get_appearance();
-       const Catalogue &cat = catalogue.get_catalogue();
        const vector<TrackPart> &parts = tt.get_parts();
 
        const Profile &ballast_profile = appearance.get_ballast_profile();
@@ -34,7 +33,7 @@ TrackType3D::TrackType3D(Catalogue3D &c, const TrackType &tt):
        const Vector &tie_max = tie_profile.get_max_coords();
        float tie_h = tie_max.y-tie_min.y;
 
-       float gauge = cat.get_gauge();
+       float gauge = appearance.get_gauge();
 
        string obj_name = tt.get_object();
        if(!obj_name.empty())
index d4f828c134c16ceb3a34e6b420fc0f0c99692331..7b7e5f1339672d0dac127d8a5931a76d6f54ef57 100644 (file)
@@ -59,7 +59,8 @@ void CameraController::adjust_distance(float delta)
        const GL::Vector3 &pos = camera.get_position();
        const GL::Vector3 &look = camera.get_look_direction();
        float dist = get_distance();
-       float low = view.get_layout().get_layout().get_catalogue().get_gauge()*5;
+       // XXX This should probably depend on the layout contents in some way
+       float low = 0.1;
        if(dist+delta<low)
                delta = low-dist;
        camera.set_position(pos-look*delta);
index 163729e297509db776b64366f5d358796f60c466..54d3d10b8081dca2610f5f418470c6f0504f64e7 100644 (file)
@@ -52,7 +52,7 @@ ExtendTool::~ExtendTool()
 
 void ExtendTool::connect()
 {
-       float limit = designer.get_layout().get_catalogue().get_gauge()/10;
+       float limit;
 
        Track *start_track = 0;
        Track *end_track = 0;
@@ -62,6 +62,7 @@ void ExtendTool::connect()
        for(vector<TrackIter>::const_iterator i=unlinked_endpoints.begin(); i!=unlinked_endpoints.end(); ++i)
        {
                start_sn = (*i)->get_snap_node(i->entry());
+               limit = (*i)->get_type().get_appearance().get_gauge()/10;
                
                for(vector<TrackIter>::const_iterator j=i; ++j!=unlinked_endpoints.end(); )
                {
index 72bbc19ec3e8de206ccb64e3ce196e31709d7048..57f6216507e63c55a3d2157eaf519d6877b3f6ef 100644 (file)
@@ -36,13 +36,12 @@ void MoveTool::pointer_motion()
                i->object->set_rotation(i->original_rotation);
        }
 
-       float limit = max(designer.get_layout().get_catalogue().get_gauge(),
-               designer.get_camera_controller().get_view_scale()/100.0f);
+       float limit = designer.get_camera_controller().get_view_scale()/100.0f;
        MObject *snapped = 0;
        for(list<Boundary>::iterator i=boundaries.begin(); (!snapped && i!=boundaries.end()); ++i)
        {
                for(set<Object *>::const_iterator j=snap_targets.begin(); (!snapped && j!=snap_targets.end()); ++j)
-                       if((*i)->snap_to(**j, limit))
+                       if((*i)->snap_to(**j, (i->limit>0 ? max(i->limit, limit) : limit)))
                                snapped = i->object;
        }
 
@@ -65,5 +64,9 @@ void MoveTool::pointer_motion()
 
 MoveTool::Boundary::Boundary(MObject *o, unsigned i):
        object(o),
-       index(i)
-{ }
+       index(i),
+       limit(-1)
+{
+       if(Track *track = dynamic_cast<Track *>(object->object))
+               limit = track->get_type().get_appearance().get_gauge();
+}
index 548315e06444bd86df3edafd1ab7e175eb8960f6..afd556dea4dad798ee55503d2b5b165e3e5008e8 100644 (file)
@@ -10,6 +10,7 @@ private:
        {
                MObject *object;
                unsigned index;
+               float limit;
 
                Boundary(MObject *, unsigned);
 
index 74d9ccf0278be2779095a4f284076bbe38ddc7cb..f7248ef6dfffb5988e85f880c399a4574101ff68 100644 (file)
@@ -11,14 +11,11 @@ using namespace Msp;
 using namespace R2C2;
 
 SvgExporter::SvgExporter(const Layout &l):
-       layout(l),
-       gauge(0)
+       layout(l)
 { }
 
 void SvgExporter::save(const string &fn)
 {
-       gauge = layout.get_catalogue().get_gauge();
-
        xmlpp::Document *doc = new xmlpp::Document;
        root = doc->create_root_node("svg", "http://www.w3.org/2000/svg");
 
@@ -26,7 +23,7 @@ void SvgExporter::save(const string &fn)
        style->set_attribute("type", "text/css");
        styles.push_back(".rail { fill: none; stroke: #000000; }");
        styles.push_back(".border { fill: none; stroke: #808080; }");
-       styles.push_back(format(".artnr { text-anchor: middle; font-family: sans; font-size: %.3f; }", gauge*750));
+       styles.push_back(".artnr { text-anchor: middle; font-family: sans; }");
 
        defs = root->add_child("defs");
 
@@ -37,6 +34,7 @@ void SvgExporter::save(const string &fn)
        {
                save_track(**i);
 
+               float gauge = (*i)->get_type().get_appearance().get_gauge();
                unsigned n_endpoints = (*i)->get_type().get_endpoints().size();
                for(unsigned j=0; j<n_endpoints; ++j)
                {
@@ -45,10 +43,10 @@ void SvgExporter::save(const string &fn)
                                minp = maxp = pos;
                        else
                        {
-                               minp.x = min(minp.x, pos.x);
-                               minp.y = min(minp.y, pos.y);
-                               maxp.x = max(maxp.x, pos.x);
-                               maxp.y = max(maxp.y, pos.y);
+                               minp.x = min(minp.x, pos.x-gauge*3);
+                               minp.y = min(minp.y, pos.y-gauge*3);
+                               maxp.x = max(maxp.x, pos.x+gauge*3);
+                               maxp.y = max(maxp.y, pos.y+gauge*3);
                        }
                }
        }
@@ -56,14 +54,15 @@ void SvgExporter::save(const string &fn)
        style->set_child_text(join(styles.begin(), styles.end(), "\n"));
 
        root->set_attribute("viewBox", format("%.3f %.3f %.3f %.3f",
-               minp.x*1000-gauge*3, -maxp.y*1000-gauge*3, (maxp.x-minp.x)*1000+gauge*6, (maxp.y-minp.y)*1000+gauge*6));
+               minp.x*1000, -maxp.y*1000, (maxp.x-minp.x)*1000, (maxp.y-minp.y)*1000));
 
        doc->write_to_file_formatted(fn);
 }
 
 string SvgExporter::create_appearance(const TrackAppearance &appearance)
 {
-       string key = format("a%p", &appearance);
+       float gauge = appearance.get_gauge();
+       string key = format("a%.0f", gauge*1000);
 
        if(!appearances_created.count(&appearance))
        {
@@ -71,6 +70,7 @@ string SvgExporter::create_appearance(const TrackAppearance &appearance)
 
                styles.push_back(format(".%s .rail { stroke-width: %.3f }", key, rail_width*1000));
                styles.push_back(format(".%s .border { stroke-width: %.3f }", key, rail_width*500));
+               styles.push_back(format(".%s .artnr { font-size: %.3f }", key, gauge*750));
 
                appearances_created.insert(&appearance);
        }
@@ -108,6 +108,7 @@ string SvgExporter::create_track_type(const TrackType &type)
                group->set_attribute("id", key);
                group->set_attribute("class", appearance_key);
 
+               float gauge = appearance.get_gauge();
                float rail_width = appearance.get_rail_profile().get_width();
 
                const vector<TrackType::Endpoint> &endpoints = type.get_endpoints();
index 20af4d3eda370c0fb7f287efa7951dc6929ab583..4a53aeac3a9b3e2d07545f0b3bcb26cd384f837e 100644 (file)
@@ -8,7 +8,6 @@ class SvgExporter
 {
 private:
        const R2C2::Layout &layout;
-       float gauge;
        xmlpp::Element *root;
        xmlpp::Element *defs;
        std::set<const R2C2::TrackType *> tracks_created;
index 463a3a967e717c78d64efa81189a05926cc88c9c..20a218b22e22a7926b52f20bf4b067d0aa5f51a5 100644 (file)
@@ -50,7 +50,7 @@ void BeamGate::set_rotation(const Angle &r)
 
 void BeamGate::update_attachment()
 {
-       attach_to_closest(100*TrackAttachment::layout.get_catalogue().get_gauge());
+       attach_to_closest(100);
 
        if(track)
        {
index 2fdc21c08cb482667b08162d81535d8d1bb7c1d6..572423a7f4048279d67b3b2027dc6979e384cc73 100644 (file)
@@ -14,7 +14,6 @@ namespace R2C2 {
 
 Catalogue::Catalogue():
        scale(1),
-       gauge(1.524),
        layout(*this)
 { }
 
@@ -39,7 +38,6 @@ const ObjectType &Catalogue::get(const ArticleNumber &art_nr) const
 Catalogue::Loader::Loader(Catalogue &c):
        DataFile::ObjectLoader<Catalogue>(c)
 {
-       add("gauge", &Loader::gauge);
        add("layout", &Loader::layout);
        add("scale", &Loader::scale);
        add("signal", &Loader::signal);
@@ -49,11 +47,6 @@ Catalogue::Loader::Loader(Catalogue &c):
        add("vehicle", &Loader::vehicle);
 }
 
-void Catalogue::Loader::gauge(float g)
-{
-       obj.gauge = g/1000;
-}
-
 void Catalogue::Loader::layout()
 {
        load_sub(obj.layout);
index 21ebd38a90a6382c931f08809ac46e25051b7036..92d1149f1f4162a0030857782af9b95f472cc310 100644 (file)
@@ -19,7 +19,6 @@ public:
        public:
                Loader(Catalogue &);
        private:
-               void gauge(float);
                void layout();
                void scale(float, float);
                void signal(ArticleNumber);
@@ -35,7 +34,6 @@ public:
 
 private:
        float scale;
-       float gauge;
        TrackAppearance appearance;
        ObjectMap objects;
        Layout layout;
@@ -45,7 +43,6 @@ public:
        ~Catalogue();
 
        float get_scale() const { return scale; }
-       float get_gauge() const { return gauge; }
 
        void add(ObjectType &);
        const ObjectType &get(const ArticleNumber &) const;
index 72b35a737015f0d74349380cde8ac3a81c92b9bf..3ec1623bf4249f5f652ed39a890568c57bbfa36d 100644 (file)
@@ -70,7 +70,7 @@ void Signal::set_rotation(const Angle &r)
 
 void Signal::update_attachment()
 {
-       attach_to_closest(layout.get_catalogue().get_gauge()*2);
+       attach_to_closest(2);
 
        if(track)
                block = track.block_iter();
index 0df1f40b03141c60febd73c237148a2d97656709..680e6ea8746cbe63ba7a2c797c8a952da6a625a4 100644 (file)
@@ -320,7 +320,7 @@ bool Track::link_to(Object &other)
        if(!otrack)
                return false;
 
-       float limit = layout.get_catalogue().get_gauge();
+       float limit = type.get_appearance().get_gauge();
        if(!flex && !otrack->get_flex())
                limit /= 10;
        limit *= limit;
index b5d8b354082c7d5b022bdd99dbb16428fa91d327..11e1ca3e58227dff56184fddcc01ed94b1830a2e 100644 (file)
@@ -6,6 +6,7 @@ using namespace Msp;
 namespace R2C2 {
 
 TrackAppearance::TrackAppearance():
+       gauge(1.524),
        tie_length(0),
        tie_spacing(1)
 { }
@@ -20,6 +21,7 @@ TrackAppearance::Loader::Loader(TrackAppearance &a):
        ObjectLoader<TrackAppearance>(a)
 {
        add("ballast_profile", &Loader::ballast_profile);
+       add("gauge", &Loader::gauge);
        add("rail_profile", &Loader::rail_profile);
        add("technique", &TrackAppearance::technique);
        add("tie_length", &Loader::tie_length);
@@ -32,6 +34,11 @@ void TrackAppearance::Loader::ballast_profile()
        load_sub(obj.ballast_profile);
 }
 
+void TrackAppearance::Loader::gauge(float g)
+{
+       obj.gauge = g/1000;
+}
+
 void TrackAppearance::Loader::rail_profile()
 {
        load_sub(obj.rail_profile);
index a108ec0e011de0f449331c84c55d9d461e566a46..739aa968d7f61d1ecc286baf530599a673967221 100644 (file)
@@ -17,6 +17,7 @@ public:
 
        private:
                void ballast_profile();
+               void gauge(float);
                void rail_profile();
                void tie_length(float);
                void tie_profile();
@@ -24,6 +25,7 @@ public:
        };
 
 private:
+       float gauge;
        Profile rail_profile;
        Profile ballast_profile;
        Profile tie_profile;
@@ -34,6 +36,7 @@ private:
 public:
        TrackAppearance();
 
+       float get_gauge() const { return gauge; }
        float get_rail_elevation() const;
        const Profile &get_rail_profile() const { return rail_profile; }
        const Profile &get_ballast_profile() const { return ballast_profile; }
index 5895100706977faa44fda8492d2c4181313f2b8e..b67ba5fbbb6274ac7c69f6e9d7710ad01930ce56 100644 (file)
@@ -50,7 +50,8 @@ void TrackAttachment::attach_to_closest(float limit)
                        Snap sn;
                        sn.position = position;
                        sn.rotation = rotation;
-                       if((*i)->snap(sn, limit, SNAP_SEGMENT))
+                       float gauge = (*i)->get_type().get_appearance().get_gauge();
+                       if((*i)->snap(sn, gauge*limit, SNAP_SEGMENT))
                        {
                                float d = distance(position, sn.position);
                                if(d<dist || dist<0)
index a7b09e5d1f204a2e2f8d137fefcd0df7979e0d08..91224575a938fe9f20fc3aded18a8ca6dd70ab61 100644 (file)
@@ -1,8 +1,8 @@
 scale 1 87;
-gauge 16.5;
 
 track_appearance
 {
+       gauge 16.5;
        rail_profile
        {
                point 1.5 0.0;
index fab49a49c6d547a9a421880fbcf8cdeaf7d7af02..4bae289d302208d6e0e4f81d520d098d202d635c 100644 (file)
@@ -1,5 +1,4 @@
 scale 1 87;
-gauge 16.5;
 
 vehicle \46274
 {