]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/designer.cpp
Use Msp::IO::print instead of std::cout
[r2c2.git] / source / designer / designer.cpp
index a5bbc68e2b76fa8234cb367103652bb69f10d3a1..4763b8fda6294f3d12ff420c1245bb1e6b975dc5 100644 (file)
@@ -7,7 +7,6 @@ Distributed under the GPL
 
 #include <signal.h>
 #include <cmath>
-#include <iostream>
 #include <GL/gl.h>
 #include <msp/gl/matrix.h>
 #include <msp/gl/misc.h>
@@ -284,17 +283,15 @@ void Designer::tick()
                {
                        const Track &track = t3d->get_track();
                        const TrackType &ttype = track.get_type();
-                       ostringstream ss;
-                       ss.precision(2);
-                       ss<<ttype.get_article_number()<<' '<<ttype.get_description();
+                       string info = format("%d %s", ttype.get_article_number(), ttype.get_description());
                        if(mode!=CATALOGUE && abs(track.get_slope())>1e-4)
-                               ss<<" (slope "<<abs(track.get_slope()/ttype.get_total_length()*100)<<"%)";
+                               info += format(" (slope %.1f%%)", abs(track.get_slope()/ttype.get_total_length()*100));
                        if(track.get_turnout_id())
-                               ss<<" (turnout "<<track.get_turnout_id()<<')';
+                               info += format(" (turnout %d)", track.get_turnout_id());
                        else if(track.get_sensor_id())
-                               ss<<" (sensor "<<track.get_sensor_id()<<')';
+                               info += format(" (sensor %d)", track.get_sensor_id());
 
-                       set_tooltip(pointer_x, pointer_y, ss.str());
+                       set_tooltip(pointer_x, pointer_y, info);
                }
                else
                        clear_tooltip();
@@ -345,7 +342,7 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t)
                float len = 0;
                for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                        len += (*i)->get_type().get_total_length();
-               cout<<"Total length: "<<len<<"m\n";
+               IO::print("Total length: %.1fm\n", len);
        }
        else if(key==Msp::Input::KEY_L)
                selection->select_linked();
@@ -404,9 +401,7 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t)
                Track *track = selection->get_track();
                if(selection->size()==1 && track->get_type().get_n_paths()>1)
                {
-                       ostringstream ss;
-                       ss<<track->get_turnout_id();
-                       input = new ::Input(*this, "Turnout ID", ss.str());
+                       input = new ::Input(*this, "Turnout ID", lexical_cast(track->get_turnout_id()));
                        input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
                        input->signal_accept.connect(sigc::mem_fun(this, &Designer::turnout_id_accept));
                        mode = INPUT;
@@ -431,10 +426,7 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t)
                }
                if(ok)
                {
-                       ostringstream ss;
-                       if(id>=0)
-                               ss<<id;
-                       input = new ::Input(*this, "Sensor ID", ss.str());
+                       input = new ::Input(*this, "Sensor ID", (id>=0 ? lexical_cast(id) : string()));
                        input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
                        input->signal_accept.connect(sigc::mem_fun(this, &Designer::sensor_id_accept));
                        mode = INPUT;
@@ -672,10 +664,8 @@ void Designer::measure_changed()
        float perpd = measure->get_perpendicular_distance()*1000;
        float d = sqrt(pard*pard+perpd*perpd);
        float adiff = measure->get_angle_difference()*180/M_PI;
-       ostringstream ss;
-       ss.precision(3);
-       ss<<"Par "<<pard<<"mm - Perp "<<perpd<<"mm - Total "<<d<<"mm - Angle "<<adiff<<"°";
-       set_tooltip(pointer_x, pointer_y, ss.str());
+       string info = format("Par %.1fmm - Perp %.1fmm - Total %.1fmm - Angle %.1f°", pard, perpd, d, adiff);
+       set_tooltip(pointer_x, pointer_y, info);
 }
 
 void Designer::measure_done()