]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/svgexporter.cpp
Move gauge to TrackAppearance
[r2c2.git] / source / designer / svgexporter.cpp
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();