From: Mikko Rasa Date: Sat, 3 May 2014 09:15:22 +0000 (+0300) Subject: Move gauge to TrackAppearance X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5929b101ee38b5668b328e7b1eac4bf49c912412;p=r2c2.git Move gauge to TrackAppearance 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. --- diff --git a/locos.dat b/locos.dat index dd2ebfe..fb22469 100644 --- a/locos.dat +++ b/locos.dat @@ -1,5 +1,4 @@ scale 1 87; -gauge 16.5; vehicle \39230 { diff --git a/source/3d/catalogue.cpp b/source/3d/catalogue.cpp index 2f932d6..d84e2d0 100644 --- a/source/3d/catalogue.cpp +++ b/source/3d/catalogue.cpp @@ -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; diff --git a/source/3d/path.cpp b/source/3d/path.cpp index f9e51f4..8c36a30 100644 --- a/source/3d/path.cpp +++ b/source/3d/path.cpp @@ -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) diff --git a/source/3d/tracktype.cpp b/source/3d/tracktype.cpp index aad2ca8..b9ebc73 100644 --- a/source/3d/tracktype.cpp +++ b/source/3d/tracktype.cpp @@ -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 &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()) diff --git a/source/designer/cameracontroller.cpp b/source/designer/cameracontroller.cpp index d4f828c..7b7e5f1 100644 --- a/source/designer/cameracontroller.cpp +++ b/source/designer/cameracontroller.cpp @@ -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::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::const_iterator j=i; ++j!=unlinked_endpoints.end(); ) { diff --git a/source/designer/movetool.cpp b/source/designer/movetool.cpp index 72bbc19..57f6216 100644 --- a/source/designer/movetool.cpp +++ b/source/designer/movetool.cpp @@ -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::iterator i=boundaries.begin(); (!snapped && i!=boundaries.end()); ++i) { for(set::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(object->object)) + limit = track->get_type().get_appearance().get_gauge(); +} diff --git a/source/designer/movetool.h b/source/designer/movetool.h index 548315e..afd556d 100644 --- a/source/designer/movetool.h +++ b/source/designer/movetool.h @@ -10,6 +10,7 @@ private: { MObject *object; unsigned index; + float limit; Boundary(MObject *, unsigned); diff --git a/source/designer/svgexporter.cpp b/source/designer/svgexporter.cpp index 74d9ccf..f7248ef 100644 --- a/source/designer/svgexporter.cpp +++ b/source/designer/svgexporter.cpp @@ -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; jset_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 &endpoints = type.get_endpoints(); diff --git a/source/designer/svgexporter.h b/source/designer/svgexporter.h index 20af4d3..4a53aea 100644 --- a/source/designer/svgexporter.h +++ b/source/designer/svgexporter.h @@ -8,7 +8,6 @@ class SvgExporter { private: const R2C2::Layout &layout; - float gauge; xmlpp::Element *root; xmlpp::Element *defs; std::set tracks_created; diff --git a/source/libr2c2/beamgate.cpp b/source/libr2c2/beamgate.cpp index 463a3a9..20a218b 100644 --- a/source/libr2c2/beamgate.cpp +++ b/source/libr2c2/beamgate.cpp @@ -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) { diff --git a/source/libr2c2/catalogue.cpp b/source/libr2c2/catalogue.cpp index 2fdc21c..572423a 100644 --- a/source/libr2c2/catalogue.cpp +++ b/source/libr2c2/catalogue.cpp @@ -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(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); diff --git a/source/libr2c2/catalogue.h b/source/libr2c2/catalogue.h index 21ebd38..92d1149 100644 --- a/source/libr2c2/catalogue.h +++ b/source/libr2c2/catalogue.h @@ -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; diff --git a/source/libr2c2/signal.cpp b/source/libr2c2/signal.cpp index 72b35a7..3ec1623 100644 --- a/source/libr2c2/signal.cpp +++ b/source/libr2c2/signal.cpp @@ -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(); diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 0df1f40..680e6ea 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -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; diff --git a/source/libr2c2/trackappearance.cpp b/source/libr2c2/trackappearance.cpp index b5d8b35..11e1ca3 100644 --- a/source/libr2c2/trackappearance.cpp +++ b/source/libr2c2/trackappearance.cpp @@ -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(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); diff --git a/source/libr2c2/trackappearance.h b/source/libr2c2/trackappearance.h index a108ec0..739aa96 100644 --- a/source/libr2c2/trackappearance.h +++ b/source/libr2c2/trackappearance.h @@ -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; } diff --git a/source/libr2c2/trackattachment.cpp b/source/libr2c2/trackattachment.cpp index 5895100..b67ba5f 100644 --- a/source/libr2c2/trackattachment.cpp +++ b/source/libr2c2/trackattachment.cpp @@ -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