]> git.tdb.fi Git - r2c2.git/commitdiff
Code reformatting: add spaces around assignment operators
authorMikko Rasa <tdb@tdb.fi>
Sat, 23 May 2009 07:46:58 +0000 (07:46 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 23 May 2009 07:46:58 +0000 (07:46 +0000)
23 files changed:
source/3d/layout.cpp
source/3d/track.cpp
source/designer/designer.cpp
source/designer/manipulator.cpp
source/designer/measure.cpp
source/designer/selection.cpp
source/engineer/engineer.cpp
source/engineer/trainpanel.cpp
source/engineer/trainproperties.cpp
source/libmarklin/block.cpp
source/libmarklin/catalogue.cpp
source/libmarklin/control.cpp
source/libmarklin/layout.cpp
source/libmarklin/locomotive.cpp
source/libmarklin/locotype.cpp
source/libmarklin/reply.cpp
source/libmarklin/sensor.cpp
source/libmarklin/track.cpp
source/libmarklin/trackpart.cpp
source/libmarklin/tracktype.cpp
source/libmarklin/trafficmanager.cpp
source/libmarklin/train.cpp
source/libmarklin/turnout.cpp

index 8093081d82c2a1630f99812f04e702a15eed8e91..f3fe3795fa909a1e3cc4d5d259cbe9c31df61ca0 100644 (file)
@@ -35,7 +35,7 @@ Layout3D::~Layout3D()
 
 void Layout3D::set_quality(unsigned q)
 {
-       quality=q;
+       quality = q;
        for(list<Track3D *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                (*i)->set_quality(quality);
 }
@@ -76,26 +76,26 @@ Track3D *Layout3D::pick_track(float x, float y, float size) const
        glLoadIdentity();
 
        double clip[4];
-       clip[0]=1;
-       clip[1]=0;
-       clip[2]=x-size;
-       clip[3]=0;
+       clip[0] = 1;
+       clip[1] = 0;
+       clip[2] = x-size;
+       clip[3] = 0;
        glClipPlane(GL_CLIP_PLANE0, clip);
        glEnable(GL_CLIP_PLANE0);
 
-       clip[0]=-1;
-       clip[2]=-(x+size);
+       clip[0] = -1;
+       clip[2] = -(x+size);
        glClipPlane(GL_CLIP_PLANE1, clip);
        glEnable(GL_CLIP_PLANE1);
 
-       clip[0]=0;
-       clip[1]=1;
-       clip[2]=y-size;
+       clip[0] = 0;
+       clip[1] = 1;
+       clip[2] = y-size;
        glClipPlane(GL_CLIP_PLANE2, clip);
        glEnable(GL_CLIP_PLANE2);
 
-       clip[1]=-1;
-       clip[2]=-(y+size);
+       clip[1] = -1;
+       clip[2] = -(y+size);
        glClipPlane(GL_CLIP_PLANE3, clip);
        glEnable(GL_CLIP_PLANE3);
 
@@ -109,13 +109,13 @@ Track3D *Layout3D::pick_track(float x, float y, float size) const
        glDisable(GL_CLIP_PLANE3);
 
        GL::render_mode(GL::RENDER);
-       Track3D *track=0;
-       unsigned track_depth=numeric_limits<unsigned>::max();
+       Track3D *track = 0;
+       unsigned track_depth = numeric_limits<unsigned>::max();
        for(vector<GL::SelectRecord>::iterator i=select_buf.begin(); i!=select_buf.end(); ++i)
                if(i->min_depth<track_depth)
                {
-                       track=reinterpret_cast<Track3D *>(i->names.back());
-                       track_depth=i->min_depth;
+                       track = reinterpret_cast<Track3D *>(i->names.back());
+                       track_depth = i->min_depth;
                }
 
        return track;
index f9b03ed00220fc78659ee591730cc6f2125e0414..85050c97f597a50d0b9b56d185d574bf8735ea62 100644 (file)
@@ -27,38 +27,38 @@ Track3D::Track3D(Track &t, unsigned q):
 
 void Track3D::set_color(const Msp::GL::Color &c)
 {
-       color=c;
+       color = c;
 }
 
 void Track3D::set_quality(unsigned q)
 {
-       quality=q;
+       quality = q;
        build_object();
 }
 
 void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const
 {
-       const Point &pos=track.get_position();
-       float rot=track.get_rotation();
+       const Point &pos = track.get_position();
+       float rot = track.get_rotation();
 
-       float c=cos(-angle);
-       float s=sin(-angle);
+       float c = cos(-angle);
+       float s = sin(-angle);
 
-       minp.x=maxp.x=c*pos.x-s*pos.y;
-       minp.y=maxp.y=s*pos.x+c*pos.y;
+       minp.x = maxp.x = c*pos.x-s*pos.y;
+       minp.y = maxp.y = s*pos.x+c*pos.y;
 
-       float c2=cos(rot-angle);
-       float s2=sin(rot-angle);
+       float c2 = cos(rot-angle);
+       float s2 = sin(rot-angle);
 
        for(vector<Point>::const_iterator i=border.begin(); i!=border.end(); ++i)
        {
-               float x=c*pos.x-s*pos.y + c2*i->x-s2*i->y;
-               float y=s*pos.x+c*pos.y + s2*i->x+c2*i->y;
+               float x = c*pos.x-s*pos.y + c2*i->x-s2*i->y;
+               float y = s*pos.x+c*pos.y + s2*i->x+c2*i->y;
 
-               minp.x=min(minp.x, x);
-               minp.y=min(minp.y, y);
-               maxp.x=max(maxp.x, x);
-               maxp.y=max(maxp.y, y);
+               minp.x = min(minp.x, x);
+               minp.y = min(minp.y, y);
+               maxp.x = max(maxp.x, x);
+               maxp.y = max(maxp.y, y);
        }
 }
 
@@ -85,18 +85,18 @@ void Track3D::render_endpoints() const
 {
        prepare_render();
 
-       const vector<Endpoint> &endpoints=track.get_type().get_endpoints();
+       const vector<Endpoint> &endpoints = track.get_type().get_endpoints();
        for(unsigned i=0; i<endpoints.size(); ++i)
        {
-               const Endpoint &ep=endpoints[i];
+               const Endpoint &ep = endpoints[i];
                GL::set(GL_CULL_FACE, track.get_link(i));
                if(track.get_link(i))
                        glColor4f(0.5, 0, 1, 0.5);
                else
                        glColor4f(1, 0, 0.5, 0.5);
 
-               float c=cos(ep.dir);
-               float s=sin(ep.dir);
+               float c = cos(ep.dir);
+               float s = sin(ep.dir);
 
                glBegin(GL_QUADS);
                glVertex3f(ep.pos.x-s*0.025, ep.pos.y+c*0.025, 0);
@@ -127,8 +127,8 @@ void Track3D::render_route(int route) const
 
 void Track3D::prepare_render() const
 {
-       const Point &pos=track.get_position();
-       float rot=track.get_rotation();
+       const Point &pos = track.get_position();
+       float rot = track.get_rotation();
 
        glPushMatrix();
        glTranslatef(pos.x, pos.y, pos.z);
@@ -145,8 +145,8 @@ void Track3D::build_object()
        route_seq.clear();
        route_seq.resize(track.get_type().get_n_routes());
 
-       const vector<TrackPart> &parts=track.get_type().get_parts();
-       unsigned index=0;
+       const vector<TrackPart> &parts = track.get_type().get_parts();
+       unsigned index = 0;
        for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
                build_part(*i, builder, index);
 }
@@ -174,26 +174,26 @@ void Track3D::build_part(const TrackPart &part, GL::VertexArrayBuilder &va_build
                profile.push_back(Point(0, -0.002, 0.012));
                profile.push_back(Point(0, 0.002, 0.012));
        }
-       static unsigned psize=profile.size();
+       static unsigned psize = profile.size();
 
-       unsigned nsegs=(part.radius ? static_cast<unsigned>(part.length*(1<<quality))+1 : 1);
-       float plen=part.length;
+       unsigned nsegs = (part.radius ? static_cast<unsigned>(part.length*(1<<quality))+1 : 1);
+       float plen = part.length;
        if(part.radius)
-               plen*=abs(part.radius);
+               plen *= abs(part.radius);
 
        for(unsigned i=0; i<=nsegs; ++i)
        {
-               float a=part.dir+(part.radius ? i*plen/nsegs/part.radius : 0);
-               float c=cos(a);
-               float s=sin(a);
-               Point p=part.get_point(i*plen/nsegs);
+               float a = part.dir+(part.radius ? i*plen/nsegs/part.radius : 0);
+               float c = cos(a);
+               float s = sin(a);
+               Point p = part.get_point(i*plen/nsegs);
 
-               for(unsigned j=0; j<profile.size(); ++j)
+               for(unsigned j=0; j<psize; ++j)
                {
-                       unsigned k=j&~1;
-                       float dy=profile[k+1].y-profile[k].y;
-                       float dz=profile[k+1].z-profile[k].z;
-                       float d=sqrt(dy*dy+dz*dz);
+                       unsigned k = j&~1;
+                       float dy = profile[k+1].y-profile[k].y;
+                       float dz = profile[k+1].z-profile[k].z;
+                       float d = sqrt(dy*dy+dz*dz);
                        va_builder.normal(s*dz/d, -c*dz/d, dy/d);
 
                        Point v(p.x+c*profile[j].x-s*profile[j].y, p.y+c*profile[j].y+s*profile[j].x, profile[j].z+i*track.get_slope()/nsegs);
@@ -225,7 +225,7 @@ void Track3D::build_part(const TrackPart &part, GL::VertexArrayBuilder &va_build
                route_seq[part.route].push_back(base_index+i*psize+19);
        }
 
-       base_index+=(nsegs+1)*psize;
+       base_index += (nsegs+1)*psize;
 }
 
 } // namespace Marklin
index c1bbc3ff17dfb4f56b7bd1fa15200ab9be6d4fb4..71391ff349c007a3ff8013b8c5bed08b52f28476 100644 (file)
@@ -50,30 +50,30 @@ Designer::Designer(int argc, char **argv):
 {
        DataFile::load(catalogue, "tracks.dat");
 
-       cat_layout=new Layout(catalogue);
-       cat_layout_3d=new Layout3D(*cat_layout);
+       cat_layout = new Layout(catalogue);
+       cat_layout_3d = new Layout3D(*cat_layout);
 
-       const map<unsigned, TrackType *> &ctracks=catalogue.get_tracks();
-       unsigned n=0;
+       const map<unsigned, TrackType *> &ctracks = catalogue.get_tracks();
+       unsigned n = 0;
        for(map<unsigned, TrackType *>::const_iterator i=ctracks.begin(); i!=ctracks.end(); ++i, ++n)
        {
-               Track *track=new Track(*i->second);
+               Track *track = new Track(*i->second);
                track->set_position(Point((n%11)*0.1-0.5, 0.2-n/11*0.3, 0));
                track->set_rotation(M_PI/2);
                cat_layout->add_track(*track);
        }
 
-       manipulator=new Manipulator(*this);
+       manipulator = new Manipulator(*this);
        manipulator->signal_status.connect(sigc::mem_fun(this, &Designer::manipulation_status));
        manipulator->signal_done.connect(sigc::mem_fun(this, &Designer::manipulation_done));
 
-       layout=new Layout(catalogue);
-       layout_3d=new Layout3D(*layout);
+       layout = new Layout(catalogue);
+       layout_3d = new Layout3D(*layout);
 
        if(argc>1)
        {
                DataFile::load(*layout, argv[1]);
-               const list<Track3D *> &ltracks=layout_3d->get_tracks();
+               const list<Track3D *> &ltracks = layout_3d->get_tracks();
                for(list<Track3D *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
                {
                        if((*i)->get_track().get_sensor_id())
@@ -86,15 +86,15 @@ Designer::Designer(int argc, char **argv):
 
                if(!layout->get_base().empty())
                {
-                       base_mesh=new GL::Mesh;
+                       base_mesh = new GL::Mesh;
                        DataFile::load(*base_mesh, layout->get_base());
                }
        }
 
-       selection=new Selection;
+       selection = new Selection;
        manipulator->set_selection(selection);
 
-       measure=new Measure(*this);
+       measure = new Measure(*this);
        measure->signal_changed.connect(sigc::mem_fun(this, &Designer::measure_changed));
        measure->signal_done.connect(sigc::mem_fun(this, &Designer::measure_done));
 }
@@ -112,9 +112,9 @@ Designer::~Designer()
 
 int Designer::main()
 {
-       dpy=new Graphics::Display;
-       wnd=new Graphics::Window(*dpy, screen_w, screen_h);
-       glc=new Graphics::GLContext(*wnd);
+       dpy = new Graphics::Display;
+       wnd = new Graphics::Window(*dpy, screen_w, screen_h);
+       glc = new Graphics::GLContext(*wnd);
 
        wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &Designer::exit), 0));
        wnd->signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press));
@@ -130,14 +130,14 @@ int Designer::main()
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_CULL_FACE);
 
-       GL::Texture2D *font_tex=new GL::Texture2D;
+       GL::Texture2D *font_tex = new GL::Texture2D;
        font_tex->set_min_filter(GL::LINEAR);
        font_tex->load_image("dejavu-20.png");
-       font=new GL::Font();
+       font = new GL::Font();
        font->set_texture(*font_tex);
        DataFile::load(*font, "dejavu-20.font");
 
-       mode=SELECT;
+       mode = SELECT;
 
        Application::main();
 
@@ -154,94 +154,94 @@ int Designer::main()
 
 void Designer::map_pointer_coords(int x, int y, float &gx, float &gy)
 {
-       float cos_pitch=cos(cam_pitch);
-       float sin_pitch=sin(cam_pitch);
-       float cos_yaw=cos(cam_yaw);
-       float sin_yaw=sin(cam_yaw);
+       float cos_pitch = cos(cam_pitch);
+       float sin_pitch = sin(cam_pitch);
+       float cos_yaw = cos(cam_yaw);
+       float sin_yaw = sin(cam_yaw);
 
-       float rx=sin_yaw*0.55228;
-       float ry=-cos_yaw*0.55228;
+       float rx = sin_yaw*0.55228;
+       float ry = -cos_yaw*0.55228;
 
-       float ux=cos_yaw*-sin_pitch*0.41421;
-       float uy=sin_yaw*-sin_pitch*0.41421;
-       float uz=cos_pitch*0.41421;
+       float ux = cos_yaw*-sin_pitch*0.41421;
+       float uy = sin_yaw*-sin_pitch*0.41421;
+       float uz = cos_pitch*0.41421;
 
-       float xf=static_cast<float>(x)*2/screen_w-1;
-       float yf=static_cast<float>(y)*2/screen_h-1;
+       float xf = static_cast<float>(x)*2/screen_w-1;
+       float yf = static_cast<float>(y)*2/screen_h-1;
 
-       float vx=cos_yaw*cos_pitch + xf*rx + yf*ux;
-       float vy=sin_yaw*cos_pitch + xf*ry + yf*uy;
-       float vz=sin_pitch + yf*uz;
+       float vx = cos_yaw*cos_pitch + xf*rx + yf*ux;
+       float vy = sin_yaw*cos_pitch + xf*ry + yf*uy;
+       float vz = sin_pitch + yf*uz;
 
-       gx=cam_pos.x-vx*cam_pos.z/vz;
-       gy=cam_pos.y-vy*cam_pos.z/vz;
+       gx = cam_pos.x-vx*cam_pos.z/vz;
+       gy = cam_pos.y-vy*cam_pos.z/vz;
 }
 
 void Designer::tick()
 {
-       const Msp::Time::TimeStamp t=Msp::Time::now();
-       float dt=(t-last_tick)/Msp::Time::sec;
-       last_tick=t;
+       const Msp::Time::TimeStamp t = Msp::Time::now();
+       float dt = (t-last_tick)/Msp::Time::sec;
+       last_tick = t;
 
        dpy->tick();
 
        if(move_y)
        {
-               cam_pos.x+=cos(cam_yaw)*dt*move_y;
-               cam_pos.y+=sin(cam_yaw)*dt*move_y;
+               cam_pos.x += cos(cam_yaw)*dt*move_y;
+               cam_pos.y += sin(cam_yaw)*dt*move_y;
        }
        if(move_x)
        {
-               cam_pos.x+=sin(cam_yaw)*dt*move_x;
-               cam_pos.y+=-cos(cam_yaw)*dt*move_x;
+               cam_pos.x += sin(cam_yaw)*dt*move_x;
+               cam_pos.y += -cos(cam_yaw)*dt*move_x;
        }
        if(zoom)
        {
-               cam_pos.x+=cos(cam_yaw)*cos(cam_pitch)*dt*zoom;
-               cam_pos.y+=sin(cam_yaw)*cos(cam_pitch)*dt*zoom;
-               cam_pos.z+=sin(cam_pitch)*dt*zoom;
+               cam_pos.x += cos(cam_yaw)*cos(cam_pitch)*dt*zoom;
+               cam_pos.y += sin(cam_yaw)*cos(cam_pitch)*dt*zoom;
+               cam_pos.z += sin(cam_pitch)*dt*zoom;
        }
        if(rotate)
        {
-               float vx=cos(cam_yaw)*cos(cam_pitch);
-               float vy=sin(cam_yaw)*cos(cam_pitch);
-               float vz=sin(cam_pitch);
+               float vx = cos(cam_yaw)*cos(cam_pitch);
+               float vy = sin(cam_yaw)*cos(cam_pitch);
+               float vz = sin(cam_pitch);
 
-               float gx=cam_pos.x-vx*cam_pos.z/vz;
-               float gy=cam_pos.y-vy*cam_pos.z/vz;
-               float d=sqrt(vx*vx+vy*vy)*cam_pos.z/vz;
+               float gx = cam_pos.x-vx*cam_pos.z/vz;
+               float gy = cam_pos.y-vy*cam_pos.z/vz;
+               float d = sqrt(vx*vx+vy*vy)*cam_pos.z/vz;
 
-               cam_yaw+=M_PI*dt*rotate;
+               cam_yaw += M_PI*dt*rotate;
                if(cam_yaw>M_PI*2)
-                       cam_yaw-=M_PI*2;
+                       cam_yaw -= M_PI*2;
                else if(cam_yaw<0)
-                       cam_yaw+=M_PI*2;
+                       cam_yaw += M_PI*2;
 
-               cam_pos.x=gx+cos(cam_yaw)*d;
-               cam_pos.y=gy+sin(cam_yaw)*d;
+               cam_pos.x = gx+cos(cam_yaw)*d;
+               cam_pos.y = gy+sin(cam_yaw)*d;
        }
        if(pitch)
        {
-               cam_pitch+=M_PI/2*dt*pitch;
+               cam_pitch += M_PI/2*dt*pitch;
                if(cam_pitch>M_PI/12)
-                       cam_pitch=M_PI/12;
+                       cam_pitch = M_PI/12;
                else if(cam_pitch<-M_PI/2)
-                       cam_pitch=-M_PI/2;
+                       cam_pitch = -M_PI/2;
        }
 
        if(tooltip_timeout && t>tooltip_timeout)
        {
-               Track3D *t3d=0;
+               Track3D *t3d = 0;
 
                if(mode==CATALOGUE)
-                       t3d=pick_track(pointer_x, pointer_y);
+                       t3d = pick_track(pointer_x, pointer_y);
                else
-                       t3d=pick_track(pointer_x, pointer_y);
+                       t3d = pick_track(pointer_x, pointer_y);
 
                if(t3d)
                {
-                       const Track &track=t3d->get_track();
-                       const TrackType &ttype=track.get_type();
+                       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();
@@ -251,14 +251,14 @@ void Designer::tick()
                                ss<<" (turnout "<<track.get_turnout_id()<<')';
                        else if(track.get_sensor_id())
                                ss<<" (sensor "<<track.get_sensor_id()<<')';
-                       tooltip=ss.str();
+                       tooltip = ss.str();
 
                        move_tooltip(pointer_x, pointer_y);
                }
                else
-                       tooltip="";
+                       tooltip.clear();
 
-               tooltip_timeout=Msp::Time::TimeStamp();
+               tooltip_timeout = Msp::Time::TimeStamp();
        }
 
        render();
@@ -270,7 +270,7 @@ void Designer::tick()
 
 void Designer::key_press(unsigned code, unsigned mod, wchar_t ch)
 {
-       unsigned key=Msp::Input::key_from_sys(code);
+       unsigned key = Msp::Input::key_from_sys(code);
 
        if(mode==INPUT)
        {
@@ -279,41 +279,41 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t ch)
        }
 
        if(key==Msp::Input::KEY_SHIFT_L || key==Msp::Input::KEY_SHIFT_R)
-               shift=true;
+               shift = true;
 
        if(key==Msp::Input::KEY_N)
-               mode=CATALOGUE;
+               mode = CATALOGUE;
        else if(key==Msp::Input::KEY_G)
        {
                manipulator->start_move();
-               mode=MANIPULATE;
+               mode = MANIPULATE;
        }
        else if(key==Msp::Input::KEY_R)
        {
                manipulator->start_rotate();
-               mode=MANIPULATE;
+               mode = MANIPULATE;
        }
        else if(key==Msp::Input::KEY_D)
        {
                manipulator->duplicate();
                manipulator->start_move();
-               mode=MANIPULATE;
+               mode = MANIPULATE;
        }
        else if(key==Msp::Input::KEY_W)
        {
-               input=new ::Input(*this, "Filename");
+               input = new ::Input(*this, "Filename");
                input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
                input->signal_accept.connect(sigc::mem_fun(this, &Designer::save_accept));
-               mode=INPUT;
+               mode = INPUT;
        }
        else if(key==Msp::Input::KEY_PLUS)
                selection->select_more();
        else if(key==Msp::Input::KEY_L && (mod&1))
        {
-               const set<Track *> &tracks=layout->get_tracks();
-               float len=0;
+               const set<Track *> &tracks = layout->get_tracks();
+               float len = 0;
                for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
-                       len+=(*i)->get_type().get_total_length();
+                       len += (*i)->get_type().get_total_length();
                cout<<"Total length: "<<len<<"m\n";
        }
        else if(key==Msp::Input::KEY_L)
@@ -321,25 +321,25 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t ch)
        else if(key==Msp::Input::KEY_M)
        {
                measure->start();
-               mode=MEASURE;
+               mode = MEASURE;
        }
        else if(key==Msp::Input::KEY_Z)
        {
                manipulator->start_elevate();
-               mode=MANIPULATE;
+               mode = MANIPULATE;
        }
        else if(key==Msp::Input::KEY_ESC)
        {
                if(mode==MANIPULATE)
                        manipulator->cancel();
                else if(mode==CATALOGUE)
-                       mode=SELECT;
+                       mode = SELECT;
                else
                        selection->clear();
        }
        else if(key==Msp::Input::KEY_X)
        {
-               set<Track *> tracks=selection->get_tracks();
+               set<Track *> tracks = selection->get_tracks();
                selection->clear();
                for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                {
@@ -349,8 +349,8 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t ch)
        }
        else if(key==Msp::Input::KEY_F && (mod&1))
        {
-               const set<Track *> &tracks=selection->get_tracks();
-               const set<Track *> &ltracks=layout->get_tracks();
+               const set<Track *> &tracks = selection->get_tracks();
+               const set<Track *> &ltracks = layout->get_tracks();
                for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                {
                        (*i)->set_flex(!(*i)->get_flex());
@@ -359,7 +359,7 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t ch)
                                if(*j!=*i)
                                        (*i)->snap_to(**j, true);
 
-                       Track3D &t3d=layout_3d->get_track(**i);
+                       Track3D &t3d = layout_3d->get_track(**i);
                        if((*i)->get_flex())
                                t3d.set_color(GL::Color(1, 0.5, 1));
                        else
@@ -374,32 +374,32 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t ch)
                manipulator->even_slope();
        else if(key==Msp::Input::KEY_T)
        {
-               Track *track=selection->get_track();
+               Track *track = selection->get_track();
                if(selection->size()==1 && track->get_type().get_n_routes()>1)
                {
                        ostringstream ss;
                        ss<<track->get_turnout_id();
-                       input=new ::Input(*this, "Turnout ID", ss.str());
+                       input = new ::Input(*this, "Turnout ID", ss.str());
                        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;
+                       mode = INPUT;
                }
        }
        else if(key==Msp::Input::KEY_S)
        {
-               const set<Track *> &tracks=selection->get_tracks();
-               bool ok=false;
-               int id=-1;
+               const set<Track *> &tracks = selection->get_tracks();
+               bool ok = false;
+               int id = -1;
                for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                {
                        if((*i)->get_type().get_n_routes()==1)
-                               ok=true;
+                               ok = true;
                        if(static_cast<int>((*i)->get_sensor_id())!=id)
                        {
                                if(id==-1)
-                                       id=(*i)->get_sensor_id();
+                                       id = (*i)->get_sensor_id();
                                else
-                                       id=-2;
+                                       id = -2;
                        }
                }
                if(ok)
@@ -407,58 +407,58 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t ch)
                        ostringstream ss;
                        if(id>=0)
                                ss<<id;
-                       input=new ::Input(*this, "Sensor ID", ss.str());
+                       input = new ::Input(*this, "Sensor ID", ss.str());
                        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;
+                       mode = INPUT;
                }
        }
        else if(key==Msp::Input::KEY_RIGHT)
-               rotate=-1;
+               rotate = -1;
        else if(key==Msp::Input::KEY_LEFT)
-               rotate=1;
+               rotate = 1;
        else if(key==Msp::Input::KEY_UP)
-               move_y=1;
+               move_y = 1;
        else if(key==Msp::Input::KEY_DOWN)
-               move_y=-1;
+               move_y = -1;
        else if(key==Msp::Input::KEY_INSERT)
-               zoom=-1;
+               zoom = -1;
        else if(key==Msp::Input::KEY_PGUP)
-               zoom=1;
+               zoom = 1;
        else if(key==Msp::Input::KEY_HOME)
-               pitch=1;
+               pitch = 1;
        else if(key==Msp::Input::KEY_END)
-               pitch=-1;
+               pitch = -1;
        else if(key==Msp::Input::KEY_DELETE)
-               move_x=-1;
+               move_x = -1;
        else if(key==Msp::Input::KEY_PGDN)
-               move_x=1;
+               move_x = 1;
 }
 
 void Designer::key_release(unsigned code, unsigned)
 {
-       unsigned key=Msp::Input::key_from_sys(code);
+       unsigned key = Msp::Input::key_from_sys(code);
 
        if(mode==INPUT)
                return;
 
        if(key==Msp::Input::KEY_SHIFT_L || key==Msp::Input::KEY_SHIFT_R)
-               shift=false;
+               shift = false;
        else if(key==Msp::Input::KEY_RIGHT || key==Msp::Input::KEY_LEFT)
-               rotate=0;
+               rotate = 0;
        else if(key==Msp::Input::KEY_UP || key==Msp::Input::KEY_DOWN)
-               move_y=0;
+               move_y = 0;
        else if(key==Msp::Input::KEY_INSERT || key==Msp::Input::KEY_PGUP)
-               zoom=0;
+               zoom = 0;
        else if(key==Msp::Input::KEY_HOME || key==Msp::Input::KEY_END)
-               pitch=0;
+               pitch = 0;
        else if(key==Msp::Input::KEY_DELETE || key==Msp::Input::KEY_PGDN)
-               move_x=0;
+               move_x = 0;
 }
 
 void Designer::button_press(int x, int y, unsigned btn, unsigned)
 {
-       y=screen_h-y-1;
+       y = screen_h-y-1;
 
        float gx, gy;
        map_pointer_coords(x, y, gx, gy);
@@ -467,27 +467,27 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned)
        {
                if(btn==1)
                {
-                       Track3D *ctrack=pick_track(x, y);
+                       Track3D *ctrack = pick_track(x, y);
                        if(ctrack)
                        {
-                               Track *track=ctrack->get_track().copy();
+                               Track *track = ctrack->get_track().copy();
                                track->set_position(Point(gx, gy, 0));
                                layout->add_track(*track);
 
                                selection->clear();
                                selection->add_track(track);
 
-                               mode=SELECT;
+                               mode = SELECT;
                        }
                }
                else
-                       mode=SELECT;
+                       mode = SELECT;
        }
        else if(mode==SELECT)
        {
                if(btn==1)
                {
-                       Track3D *track=pick_track(x, y);
+                       Track3D *track = pick_track(x, y);
                        if(track)
                        {
                                if(!shift)
@@ -504,16 +504,16 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned)
 
 void Designer::pointer_motion(int x, int y)
 {
-       y=screen_h-y-1;
+       y = screen_h-y-1;
 
        float gx, gy;
        map_pointer_coords(x, y, gx, gy);
 
        if(mode==SELECT || mode==CATALOGUE)
        {
-               pointer_x=x;
-               pointer_y=y;
-               tooltip_timeout=Msp::Time::now()+100*Msp::Time::msec;
+               pointer_x = x;
+               pointer_y = y;
+               tooltip_timeout = Msp::Time::now()+100*Msp::Time::msec;
        }
 
        if(mode!=INPUT)
@@ -581,7 +581,7 @@ void Designer::render()
        {
                glTranslatef(tooltip_x, tooltip_y, 0);
                glScalef(20, 20, 20);
-               float width=font->get_string_width(tooltip);
+               float width = font->get_string_width(tooltip);
                glColor4f(0, 0, 0, 0.5);
                glBegin(GL_QUADS);
                glVertex2f(0, 0);
@@ -599,13 +599,13 @@ void Designer::render()
 
 Track3D *Designer::pick_track(int x, int y)
 {
-       Layout3D *l=layout_3d;
+       Layout3D *l = layout_3d;
        if(mode==CATALOGUE)
-               l=cat_layout_3d;
+               l = cat_layout_3d;
 
-       float xx=(static_cast<float>(x-static_cast<int>(screen_w)/2)/screen_h)*0.82843;
-       float yy=(static_cast<float>(y)/screen_h-0.5)*0.82843;
-       float size=4.0/screen_h*0.82843;
+       float xx = (static_cast<float>(x-static_cast<int>(screen_w)/2)/screen_h)*0.82843;
+       float yy = (static_cast<float>(y)/screen_h-0.5)*0.82843;
+       float size = 4.0/screen_h*0.82843;
 
        project_3d();
        apply_camera();
@@ -615,36 +615,36 @@ Track3D *Designer::pick_track(int x, int y)
 
 void Designer::manipulation_status(const string &status)
 {
-       tooltip=status;
+       tooltip = status;
 }
 
 void Designer::manipulation_done(bool)
 {
-       mode=SELECT;
+       mode = SELECT;
 }
 
 void Designer::measure_changed()
 {
-       float pard=measure->get_parallel_distance()*1000;
-       float perpd=measure->get_perpendicular_distance()*1000;
-       float d=sqrt(pard*pard+perpd*perpd);
-       float adiff=measure->get_angle_difference()*180/M_PI;
+       float pard = measure->get_parallel_distance()*1000;
+       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<<"°";
-       tooltip=ss.str();
+       tooltip = ss.str();
 }
 
 void Designer::measure_done()
 {
-       mode=SELECT;
+       mode = SELECT;
 }
 
 void Designer::move_tooltip(int x, int y)
 {
-       int w=static_cast<int>(font->get_string_width(tooltip)*20);
-       tooltip_x=max(min(static_cast<int>(screen_w)-w, x), 0);
-       tooltip_y=max(min(static_cast<int>(screen_h)-20, y), 0);
+       int w = static_cast<int>(font->get_string_width(tooltip)*20);
+       tooltip_x = max(min(static_cast<int>(screen_w)-w, x), 0);
+       tooltip_y = max(min(static_cast<int>(screen_h)-20, y), 0);
 }
 
 void Designer::save_accept()
@@ -656,11 +656,11 @@ void Designer::save_accept()
 
 void Designer::turnout_id_accept()
 {
-       Track *track=selection->get_track();
-       unsigned id=lexical_cast<unsigned>(input->get_text());
+       Track *track = selection->get_track();
+       unsigned id = lexical_cast<unsigned>(input->get_text());
        track->set_turnout_id(id);
 
-       Track3D &t3d=layout_3d->get_track(*track);
+       Track3D &t3d = layout_3d->get_track(*track);
        if(id)
                t3d.set_color(GL::Color(0.5, 1, 1));
        else
@@ -671,13 +671,13 @@ void Designer::turnout_id_accept()
 
 void Designer::sensor_id_accept()
 {
-       const set<Track *> &tracks=selection->get_tracks();
-       unsigned id=lexical_cast<unsigned>(input->get_text());
+       const set<Track *> &tracks = selection->get_tracks();
+       unsigned id = lexical_cast<unsigned>(input->get_text());
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
                (*i)->set_sensor_id(id);
 
-               Track3D &t3d=layout_3d->get_track(**i);
+               Track3D &t3d = layout_3d->get_track(**i);
                if(id)
                        t3d.set_color(GL::Color(1, 1, 0.5));
                else
@@ -690,6 +690,6 @@ void Designer::sensor_id_accept()
 void Designer::input_dismiss()
 {
        delete input;
-       input=0;
-       mode=SELECT;
+       input = 0;
+       mode = SELECT;
 }
index 798e99f7ebef1c95a47ede24de2daf043480aa6d..1f21430737c6c2f7d9dcda85869c02cddd1847da 100644 (file)
@@ -32,9 +32,9 @@ void Manipulator::set_selection(Selection *s)
 {
        selection_changed_conn.disconnect();
 
-       selection=s;
+       selection = s;
        if(selection)
-               selection_changed_conn=selection->signal_changed.connect(sigc::mem_fun(this, &Manipulator::selection_changed));
+               selection_changed_conn = selection->signal_changed.connect(sigc::mem_fun(this, &Manipulator::selection_changed));
 
        selection_changed();
 }
@@ -44,9 +44,9 @@ void Manipulator::start_move()
        if(mode)
                cancel();
 
-       move_origin=gpointer;
+       move_origin = gpointer;
 
-       mode=MOVE;
+       mode = MOVE;
 }
 
 void Manipulator::start_rotate()
@@ -54,9 +54,9 @@ void Manipulator::start_rotate()
        if(mode)
                cancel();
 
-       rot_origin=atan2(gpointer.y-center.y, gpointer.x-center.x);
+       rot_origin = atan2(gpointer.y-center.y, gpointer.x-center.x);
 
-       mode=ROTATE;
+       mode = ROTATE;
 }
 
 void Manipulator::start_elevate()
@@ -64,9 +64,9 @@ void Manipulator::start_elevate()
        if(mode)
                cancel();
 
-       elev_origin=pointer_y;
+       elev_origin = pointer_y;
 
-       mode=ELEVATE;
+       mode = ELEVATE;
 }
 
 void Manipulator::duplicate()
@@ -77,7 +77,7 @@ void Manipulator::duplicate()
        list<Track *> new_tracks;
        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
-               Track *track=i->track->copy();
+               Track *track = i->track->copy();
                designer.get_layout()->add_track(*track);
                new_tracks.push_back(track);
        }
@@ -99,14 +99,14 @@ void Manipulator::flatten()
 
        if(tracks.empty()) return;
 
-       float z=0;
+       float z = 0;
        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
-               z+=i->track->get_position().z+i->track->get_slope()/2;
-       z/=tracks.size();
+               z += i->track->get_position().z+i->track->get_slope()/2;
+       z /= tracks.size();
 
        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
-               Point p=i->track->get_position();
+               Point p = i->track->get_position();
                i->track->set_position(Point(p.x, p.y, z));
                i->track->set_slope(0);
        }
@@ -133,69 +133,69 @@ void Manipulator::even_slope(bool smooth)
        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                tracks2.push_back(i->track);
 
-       float total_len=0;
+       float total_len = 0;
 
        list<TrackOrder> order;
-       Track *cur=*neighbors.begin();
+       Track *cur = *neighbors.begin();
        while(tracks2.size())
        {
-               bool rev=false;
+               bool rev = false;
                for(list<Track *>::iterator i=tracks2.begin(); i!=tracks2.end(); ++i)
                {
-                       const vector<Track *> &links=(*i)->get_links();
+                       const vector<Track *> &links = (*i)->get_links();
                        if(links[0]==cur)
                        {
-                               cur=*i;
+                               cur = *i;
                                tracks2.erase(i);
                                break;
                        }
                        else if(links[1]==cur)
                        {
-                               cur=*i;
-                               rev=true;
+                               cur = *i;
+                               rev = true;
                                tracks2.erase(i);
                                break;
                        }
                }
                order.push_back(TrackOrder(cur, rev));
-               total_len+=cur->get_type().get_total_length();
+               total_len += cur->get_type().get_total_length();
        }
 
-       set<Track *>::iterator nb=neighbors.begin();
-       int epi=(*nb)->get_endpoint_by_link(*order.front().track);
-       float start_z=(*nb)->get_endpoint_position(epi).z;
+       set<Track *>::iterator nb = neighbors.begin();
+       int epi = (*nb)->get_endpoint_by_link(*order.front().track);
+       float start_z = (*nb)->get_endpoint_position(epi).z;
        ++nb;
-       epi=(*nb)->get_endpoint_by_link(*order.back().track);
-       float end_z=(*nb)->get_endpoint_position(epi).z;
+       epi = (*nb)->get_endpoint_by_link(*order.back().track);
+       float end_z = (*nb)->get_endpoint_position(epi).z;
 
        if(smooth)
        {
-               float dir=(end_z>start_z)?1:-1;
-               float cur_slope=0;
+               float dir = (end_z>start_z)?1:-1;
+               float cur_slope = 0;
                while((end_z-start_z)*dir/total_len>cur_slope+0.025 && order.size()>2)
                {
-                       cur_slope+=0.025;
+                       cur_slope += 0.025;
 
-                       float dz=order.front().track->get_type().get_total_length()*dir*cur_slope;
+                       float dz = order.front().track->get_type().get_total_length()*dir*cur_slope;
                        set_slope(order.front(), start_z, dz);
-                       start_z+=dz;
-                       total_len-=order.front().track->get_type().get_total_length();
+                       start_z += dz;
+                       total_len -= order.front().track->get_type().get_total_length();
                        order.erase(order.begin());
 
-                       dz=order.back().track->get_type().get_total_length()*dir*cur_slope;
+                       dz = order.back().track->get_type().get_total_length()*dir*cur_slope;
                        set_slope(order.back(), end_z-dz, dz);
-                       end_z-=dz;
-                       total_len-=order.back().track->get_type().get_total_length();
+                       end_z -= dz;
+                       total_len -= order.back().track->get_type().get_total_length();
                        order.erase(--order.end());
                }
        }
 
-       float cur_z=start_z;
+       float cur_z = start_z;
        for(list<TrackOrder>::iterator i=order.begin(); i!=order.end(); ++i)
        {
-               float dz=i->track->get_type().get_total_length()*(end_z-start_z)/total_len;
+               float dz = i->track->get_type().get_total_length()*(end_z-start_z)/total_len;
                set_slope(*i, cur_z, dz);
-               cur_z+=dz;
+               cur_z += dz;
        }
 
        for(set<Track *>::iterator i=neighbors.begin(); i!=neighbors.end(); ++i)
@@ -208,9 +208,9 @@ void Manipulator::cancel()
 {
        if(!mode)
                return;
-       mode=NONE;
+       mode = NONE;
 
-       wrap_pos=center;
+       wrap_pos = center;
        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
                i->track->set_position(Point(center.x+i->pos.x, center.y+i->pos.y, center.z+i->pos.z));
@@ -220,8 +220,8 @@ void Manipulator::cancel()
        for(set<Track *>::iterator i=neighbors.begin(); i!=neighbors.end(); ++i)
                (*i)->check_slope();
 
-       angle=0;
-       wrap_rot=0;
+       angle = 0;
+       wrap_rot = 0;
 
        signal_done.emit(false);
 }
@@ -232,20 +232,20 @@ void Manipulator::button_press(int, int, float, float, unsigned btn)
                cancel();
        else if(mode)
        {
-               mode=NONE;
+               mode = NONE;
                update_wrap();
-               angle=0;
+               angle = 0;
 
                for(set<Track *>::iterator i=neighbors.begin(); i!=neighbors.end(); ++i)
                        for(vector<MTrack>::iterator j=tracks.begin(); j!=tracks.end(); ++j)
                                j->track->break_link(**i);
 
-               const set<Track *> &ltracks=designer.get_layout()->get_tracks();
+               const set<Track *> &ltracks = designer.get_layout()->get_tracks();
                for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
                {
-                       bool ok=true;
+                       bool ok = true;
                        for(vector<MTrack>::iterator j=tracks.begin(); (j!=tracks.end() && ok); ++j)
-                               ok=(j->track!=*i);
+                               ok = (j->track!=*i);
                        if(!ok) continue;
 
                        for(vector<MTrack>::iterator j=tracks.begin(); j!=tracks.end(); ++j)
@@ -253,7 +253,7 @@ void Manipulator::button_press(int, int, float, float, unsigned btn)
                }
 
                for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
-                       i->rot=i->track->get_rotation();
+                       i->rot = i->track->get_rotation();
 
                update_neighbors();
 
@@ -263,40 +263,40 @@ void Manipulator::button_press(int, int, float, float, unsigned btn)
 
 void Manipulator::pointer_motion(int, int y, float gx, float gy)
 {
-       pointer_y=y;
-       gpointer=Point(gx, gy, 0);
+       pointer_y = y;
+       gpointer = Point(gx, gy, 0);
 
        if(mode==MOVE)
        {
                Point delta(gpointer.x-move_origin.x, gpointer.y-move_origin.y, 0);
 
-               wrap_pos=Point(center.x+delta.x, center.y+delta.y, center.z);
+               wrap_pos = Point(center.x+delta.x, center.y+delta.y, center.z);
                for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                {
                        i->track->set_position(Point(wrap_pos.x+i->pos.x, wrap_pos.y+i->pos.y, wrap_pos.z+i->pos.z));
                        i->track->set_rotation(i->rot);
                }
 
-               const set<Track *> &ltracks=designer.get_layout()->get_tracks();
-               MTrack *snapped=0;
+               const set<Track *> &ltracks = designer.get_layout()->get_tracks();
+               MTrack *snapped = 0;
                for(set<Track *>::const_iterator i=ltracks.begin(); (i!=ltracks.end() && !snapped); ++i)
                {
-                       bool ok=true;
+                       bool ok = true;
                        for(vector<MTrack>::iterator j=tracks.begin(); (j!=tracks.end() && ok); ++j)
-                               ok=(j->track!=*i);
+                               ok = (j->track!=*i);
                        if(!ok) continue;
 
                        for(vector<MTrack>::iterator j=tracks.begin(); (j!=tracks.end() && !snapped); ++j)
                                if(j->track->snap_to(**i, false))
-                                       snapped=&*j;
+                                       snapped = &*j;
                }
 
                if(snapped)
                {
-                       float da=snapped->track->get_rotation()-snapped->rot;
-                       float c=cos(da);
-                       float s=sin(da);
-                       const Point &sp=snapped->track->get_position();
+                       float da = snapped->track->get_rotation()-snapped->rot;
+                       float c = cos(da);
+                       float s = sin(da);
+                       const Point &sp = snapped->track->get_position();
                        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                        {
                                if(&*i==snapped)
@@ -310,29 +310,29 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy)
        }
        else if(mode==ROTATE)
        {
-               float a=atan2(gpointer.y-center.y, gpointer.x-center.x);
-               angle+=a-rot_origin;
-               rot_origin=a;
+               float a = atan2(gpointer.y-center.y, gpointer.x-center.x);
+               angle += a-rot_origin;
+               rot_origin = a;
 
-               wrap_rot=angle;
+               wrap_rot = angle;
                for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                {
-                       float c=cos(angle);
-                       float s=sin(angle);
+                       float c = cos(angle);
+                       float s = sin(angle);
                        i->track->set_position(Point(center.x+c*i->pos.x-s*i->pos.y, center.y+s*i->pos.x+c*i->pos.y, center.z*i->pos.z));
                        i->track->set_rotation(angle+i->rot);
                }
        }
        else if(mode==ELEVATE)
        {
-               float dz=(y-elev_origin)/1000.;
+               float dz = (y-elev_origin)/1000.;
 
                ostringstream ss;
                ss.precision(3);
                ss<<"Elevation: "<<dz*1000<<"mm ("<<(center.z+dz)*1000<<"mm)";
                signal_status.emit(ss.str());
 
-               wrap_pos.z=center.z+dz;
+               wrap_pos.z = center.z+dz;
                for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                        i->track->set_position(Point(center.x+i->pos.x, center.y+i->pos.y, center.z+i->pos.z+dz));
 
@@ -378,7 +378,7 @@ void Manipulator::selection_changed()
        tracks.clear();
        if(selection)
        {
-               const set<Track *> &stracks=selection->get_tracks();
+               const set<Track *> &stracks = selection->get_tracks();
                tracks.insert(tracks.end(), stracks.begin(), stracks.end());
        }
 
@@ -389,61 +389,61 @@ void Manipulator::selection_changed()
 void Manipulator::update_wrap()
 {
        wrap.clear();
-       float min_x=0, max_x=0;
-       float min_y=0, max_y=0;
+       float min_x = 0, max_x = 0;
+       float min_y = 0, max_y = 0;
        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
-               Track3D &t3d=designer.get_layout_3d()->get_track(*i->track);
+               Track3D &t3d = designer.get_layout_3d()->get_track(*i->track);
 
                TrackWrap tw;
-               float min_area=100;
+               float min_area = 100;
                for(float a=0; a<M_PI; a+=0.01)
                {
                        Point minp, maxp;
                        t3d.get_bounds(a, minp, maxp);
-                       float area=(maxp.x-minp.x)*(maxp.y-minp.y);
+                       float area = (maxp.x-minp.x)*(maxp.y-minp.y);
                        if(area<min_area)
                        {
-                               float c=cos(a);
-                               float s=sin(a);
-                               float x=(minp.x+maxp.x)/2;
-                               float y=(minp.y+maxp.y)/2;
-                               tw.pos=Point(c*x-s*y, s*x+c*y, (minp.z+maxp.z)/2);
-                               tw.rot=a;
-                               tw.width=maxp.x-minp.x+0.01;
-                               tw.height=maxp.y-minp.y+0.01;
-
-                               min_area=area;
+                               float c = cos(a);
+                               float s = sin(a);
+                               float x = (minp.x+maxp.x)/2;
+                               float y = (minp.y+maxp.y)/2;
+                               tw.pos = Point(c*x-s*y, s*x+c*y, (minp.z+maxp.z)/2);
+                               tw.rot = a;
+                               tw.width = maxp.x-minp.x+0.01;
+                               tw.height = maxp.y-minp.y+0.01;
+
+                               min_area = area;
                        }
                }
 
                if(i==tracks.begin())
                {
-                       min_x=max_x=tw.pos.x;
-                       min_y=max_y=tw.pos.y;
+                       min_x = max_x = tw.pos.x;
+                       min_y = max_y = tw.pos.y;
                }
                else
                {
-                       min_x=min(min_x, tw.pos.x);
-                       max_x=max(max_x, tw.pos.x);
-                       min_y=min(min_y, tw.pos.y);
-                       max_y=max(max_y, tw.pos.y);
+                       min_x = min(min_x, tw.pos.x);
+                       max_x = max(max_x, tw.pos.x);
+                       min_y = min(min_y, tw.pos.y);
+                       max_y = max(max_y, tw.pos.y);
                }
                wrap.push_back(tw);
        }
 
-       center=Point((min_x+max_x)/2, (min_y+max_y)/2, 0);
-       wrap_pos=center;
-       wrap_rot=0;
+       center = Point((min_x+max_x)/2, (min_y+max_y)/2, 0);
+       wrap_pos = center;
+       wrap_rot = 0;
        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
-               const Point &tp=i->track->get_position();
-               i->pos=Point(tp.x-center.x, tp.y-center.y, tp.z);
+               const Point &tp = i->track->get_position();
+               i->pos = Point(tp.x-center.x, tp.y-center.y, tp.z);
        }
        for(list<TrackWrap>::iterator i=wrap.begin(); i!=wrap.end(); ++i)
        {
-               i->pos.x-=center.x;
-               i->pos.y-=center.y;
+               i->pos.x -= center.x;
+               i->pos.y -= center.y;
        }
 }
 
@@ -452,7 +452,7 @@ void Manipulator::update_neighbors()
        neighbors.clear();
        for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
-               const vector<Track *> &links=i->track->get_links();
+               const vector<Track *> &links = i->track->get_links();
                for(vector<Track *>::const_iterator j=links.begin(); j!=links.end(); ++j)
                {
                        if(!*j)
@@ -460,9 +460,9 @@ void Manipulator::update_neighbors()
                        if(neighbors.count(*j))
                                continue;
 
-                       bool ok=true;
+                       bool ok = true;
                        for(vector<MTrack>::iterator k=tracks.begin(); (k!=tracks.end() && ok); ++k)
-                               ok=(k->track!=*j);
+                               ok = (k->track!=*j);
 
                        if(ok)
                                neighbors.insert(*j);
@@ -472,7 +472,7 @@ void Manipulator::update_neighbors()
 
 void Manipulator::set_slope(TrackOrder &track, float z, float dz)
 {
-       const Point &p=track.track->get_position();
+       const Point &p = track.track->get_position();
        if(track.rev)
        {
                track.track->set_position(Point(p.x, p.y, z+dz));
index ee08ba7943276793961ed5cfeba072c025a72752..cbe17938dd3debe1fa28f367c86175329b956130 100644 (file)
@@ -22,12 +22,12 @@ Measure::Measure(Designer &d):
 
 void Measure::start()
 {
-       state=STARTING;
+       state = STARTING;
 }
 
 void Measure::snap_to_tracks(Point &pt, float &dir)
 {
-       const set<Track *> &ltracks=designer.get_layout()->get_tracks();
+       const set<Track *> &ltracks = designer.get_layout()->get_tracks();
        for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
                if((*i)->snap(pt, dir))
                        return;
@@ -40,19 +40,19 @@ void Measure::button_press(int, int, float gx, float gy, unsigned btn)
 
        if(btn==1)
        {
-               spoint=Point(gx, gy, 0);
-               sdir=0;
+               spoint = Point(gx, gy, 0);
+               sdir = 0;
                snap_to_tracks(spoint, sdir);
 
-               state=ACTIVE;
+               state = ACTIVE;
        }
        else if(btn==3)
        {
                if(state==ACTIVE)
-                       state=STARTING;
+                       state = STARTING;
                else
                {
-                       state=NONE;
+                       state = NONE;
                        signal_done.emit();
                }
        }
@@ -63,24 +63,24 @@ void Measure::pointer_motion(int, int, float gx, float gy)
        if(!state)
                return;
 
-       pointer=Point(gx, gy, 0);
-       float dir=sdir;
+       pointer = Point(gx, gy, 0);
+       float dir = sdir;
        snap_to_tracks(pointer, dir);
 
        if(state!=STARTING)
        {
                Point delta(pointer.x-spoint.x, pointer.y-spoint.y, 0);
-               float c=cos(sdir);
-               float s=sin(sdir);
+               float c = cos(sdir);
+               float s = sin(sdir);
 
-               par_dist=delta.x*c+delta.y*s;
-               perp_dist=delta.x*s-delta.y*c;
+               par_dist = delta.x*c+delta.y*s;
+               perp_dist = delta.x*s-delta.y*c;
 
-               adiff=dir-sdir+M_PI;
+               adiff = dir-sdir+M_PI;
                while(adiff<-M_PI)
-                       adiff+=M_PI*2;
+                       adiff += M_PI*2;
                while(adiff>M_PI)
-                       adiff-=M_PI*2;
+                       adiff -= M_PI*2;
 
                signal_changed.emit();
        }
@@ -99,8 +99,8 @@ void Measure::render()
        glBegin(GL_QUAD_STRIP);
        for(unsigned i=0; i<=16; ++i)
        {
-               float x=cos(i*M_PI/8)*0.005;
-               float y=sin(i*M_PI/8)*0.005;
+               float x = cos(i*M_PI/8)*0.005;
+               float y = sin(i*M_PI/8)*0.005;
                glVertex3f(x, y, 0);
                glVertex3f(x, y, 0.01);
        }
@@ -108,8 +108,8 @@ void Measure::render()
 
        if(state==ACTIVE)
        {
-               float c=cos(sdir);
-               float s=sin(sdir);
+               float c = cos(sdir);
+               float s = sin(sdir);
                glBegin(GL_QUAD_STRIP);
                glVertex3f(0, 0, 0);
                glVertex3f(0, 0, 0.01);
index 48f5b497d1410ddcd96a9d4d8cdf178e30f959e6..5f71e8b68a5b6be56d72cb2d73f878689807e7d2 100644 (file)
@@ -51,16 +51,16 @@ void Selection::select_more()
        set<Track *> new_tracks;
        for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
-               const vector<Track *> &links=(*i)->get_links();
+               const vector<Track *> &links = (*i)->get_links();
                for(vector<Track *>::const_iterator j=links.begin(); j!=links.end(); ++j)
                        if(*j)
                                new_tracks.insert(*j);
        }
 
-       bool changed=false;
+       bool changed = false;
        for(set<Track *>::iterator i=new_tracks.begin(); i!=new_tracks.end(); ++i)
                if(tracks.insert(*i).second)
-                       changed=true;
+                       changed = true;
 
        if(changed)
                signal_changed.emit();
@@ -68,27 +68,27 @@ void Selection::select_more()
 
 void Selection::select_linked()
 {
-       bool changed=false;
+       bool changed = false;
        list<Track *> queue(tracks.begin(), tracks.end());
        while(!queue.empty())
        {
-               Track *track=queue.front();
+               Track *track = queue.front();
                queue.erase(queue.begin());
 
-               const vector<Track *> &links=track->get_links();
+               const vector<Track *> &links = track->get_links();
                for(vector<Track *>::const_iterator j=links.begin(); j!=links.end(); ++j)
                        if(*j && tracks.insert(*j).second)
                        {
                                queue.push_back(*j);
-                               changed=true;
+                               changed = true;
                        }
        }
        for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
-               const vector<Track *> &links=(*i)->get_links();
+               const vector<Track *> &links = (*i)->get_links();
                for(vector<Track *>::const_iterator j=links.begin(); j!=links.end(); ++j)
                        if(*j && tracks.insert(*j).second)
-                               changed=true;
+                               changed = true;
        }
 
        if(changed)
index 83827c142f61f023a04fb7a005a3012d0c37ad40..08e1466893f209a445c6d69e49c2fe03136209ee 100644 (file)
@@ -46,9 +46,9 @@ Engineer::Engineer(int argc, char **argv):
        simulate(false)
 {
        string res;
-       bool debug=false;
-       string device="/dev/ttyS0";
-       unsigned quality=4;
+       bool debug = false;
+       string device = "/dev/ttyS0";
+       unsigned quality = 4;
 
        GetOpt getopt;
        getopt.add_option('r', "resolution",  res,         GetOpt::REQUIRED_ARG);
@@ -64,8 +64,8 @@ Engineer::Engineer(int argc, char **argv):
        {
                if(RegMatch m=Regex("([1-9][0-9]*)x([1-9][0-9]*)").match(res))
                {
-                       screen_w=lexical_cast<unsigned>(m[1].str);
-                       screen_h=lexical_cast<unsigned>(m[2].str);
+                       screen_w = lexical_cast<unsigned>(m[1].str);
+                       screen_h = lexical_cast<unsigned>(m[2].str);
                }
                else
                        throw UsageError("Invalid resolution");
@@ -81,17 +81,17 @@ Engineer::Engineer(int argc, char **argv):
        DataFile::load(catalogue, "tracks.dat");
        DataFile::load(catalogue, "locos.dat");
 
-       const vector<string> &args=getopt.get_args();
+       const vector<string> &args = getopt.get_args();
        if(args.empty())
                throw UsageError("No layout given");
        DataFile::load(layout, args.front());
 
-       trfc_mgr=new TrafficManager(control, layout);
+       trfc_mgr = new TrafficManager(control, layout);
        trfc_mgr->signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved));
        if(FS::exists("engineer.state"))
                DataFile::load(*trfc_mgr, "engineer.state");
 
-       const map<unsigned, Sensor *> &sensors=control.get_sensors();
+       const map<unsigned, Sensor *> &sensors = control.get_sensors();
        for(map<unsigned, Sensor *>::const_iterator i=sensors.begin(); i!=sensors.end(); ++i)
                i->second->signal_state_changed.connect(sigc::bind(sigc::mem_fun(this, &Engineer::sensor_event), i->second));
 
@@ -107,24 +107,24 @@ Engineer::~Engineer()
 
 void Engineer::add_train()
 {
-       train_prop=new TrainProperties(*this, ui_res, 0);
+       train_prop = new TrainProperties(*this, ui_res, 0);
        root->add(*train_prop);
        train_prop->signal_ok.connect(sigc::mem_fun(this, &Engineer::dismiss_train_prop));
-       train_prop_stale=false;
+       train_prop_stale = false;
        train_prop->set_visible(true);
 }
 
 Train *Engineer::add_train(const LocoType &type, unsigned addr)
 {
-       Locomotive *loco=new Locomotive(type, control, addr);
-       Train *train=new Train(*trfc_mgr, *loco);
+       Locomotive *loco = new Locomotive(type, control, addr);
+       Train *train = new Train(*trfc_mgr, *loco);
        train->set_name(format("Train %d", trfc_mgr->get_trains().size()));
 
-       TrainPanel *tpanel=new TrainPanel(*this, ui_res, *train);
+       TrainPanel *tpanel = new TrainPanel(*this, ui_res, *train);
        root->add(*tpanel);
-       int y=main_panel->get_geometry().y;
+       int y = main_panel->get_geometry().y;
        for(list<TrainPanel *>::iterator i=train_panels.begin(); i!=train_panels.end(); ++i)
-               y-=(*i)->get_geometry().h;
+               y -= (*i)->get_geometry().h;
        tpanel->set_position(0, y-tpanel->get_geometry().h);
        train_panels.push_back(tpanel);
        tpanel->set_visible(true);
@@ -136,24 +136,24 @@ Train *Engineer::add_train(const LocoType &type, unsigned addr)
 
 void Engineer::place_train(Train &train)
 {
-       placing_train=&train;
-       placing_block=0;
+       placing_train = &train;
+       placing_block = 0;
        main_panel->set_status_text("Select location");
 }
 
 int Engineer::main()
 {
-       dpy=new Graphics::Display;
+       dpy = new Graphics::Display;
 
        Graphics::WindowOptions wopt;
-       wopt.width=screen_w;
-       wopt.height=screen_h;
-       wopt.fullscreen=fullscreen;
-       wnd=new Graphics::Window(*dpy, wopt);
+       wopt.width = screen_w;
+       wopt.height = screen_h;
+       wopt.fullscreen = fullscreen;
+       wnd = new Graphics::Window(*dpy, wopt);
 
        Graphics::GLOptions glopt;
-       //glopt.multisample=4;
-       glc=new Graphics::GLContext(*wnd, glopt);
+       //glopt.multisample = 4;
+       glc = new Graphics::GLContext(*wnd, glopt);
 
        wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &Engineer::exit), 0));
        wnd->signal_button_press.connect(sigc::mem_fun(this, &Engineer::button_press));
@@ -168,31 +168,31 @@ int Engineer::main()
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
        DataFile::load(ui_res, "marklin.res");
-       root=new GLtk::Root(ui_res, *wnd);
+       root = new GLtk::Root(ui_res, *wnd);
        root->set_visible(true);
 
-       list<GL::Texture *> texs=ui_res.get_list<GL::Texture>();
+       list<GL::Texture *> texs = ui_res.get_list<GL::Texture>();
        for(list<GL::Texture *>::iterator i=texs.begin(); i!=texs.end(); ++i)
        {
                (*i)->set_min_filter(GL::NEAREST);
                (*i)->set_mag_filter(GL::NEAREST);
        }
 
-       main_panel=new MainPanel(*this, ui_res);
+       main_panel = new MainPanel(*this, ui_res);
        root->add(*main_panel);
        main_panel->set_position(0, screen_h-main_panel->get_geometry().h);
        main_panel->set_visible(true);
 
-       const list<Train *> &trains=trfc_mgr->get_trains();
-       int y=main_panel->get_geometry().y;
+       const list<Train *> &trains = trfc_mgr->get_trains();
+       int y = main_panel->get_geometry().y;
        for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
-               TrainPanel *tpanel=new TrainPanel(*this, ui_res, **i);
+               TrainPanel *tpanel = new TrainPanel(*this, ui_res, **i);
                root->add(*tpanel);
                tpanel->set_position(0, y-tpanel->get_geometry().h);
                train_panels.push_back(tpanel);
                tpanel->set_visible(true);
-               y-=tpanel->get_geometry().h;
+               y -= tpanel->get_geometry().h;
        }
 
        wnd->show();
@@ -225,10 +225,10 @@ void Engineer::tick()
                glEnable(GL_LIGHTING);
                glEnable(GL_LIGHT0);
                float params[4];
-               params[0]=0;
-               params[1]=-0.2;
-               params[2]=1;
-               params[3]=0;
+               params[0] = 0;
+               params[1] = -0.2;
+               params[2] = 1;
+               params[3] = 0;
                glLightfv(GL_LIGHT0, GL_POSITION, params);
        }
 
@@ -239,13 +239,13 @@ void Engineer::tick()
 
        glDisable(GL_LIGHTING);
        glColor4f(1, 1, 1, 1);
-       const list<Track3D *> &ltracks=layout_3d.get_tracks();
+       const list<Track3D *> &ltracks = layout_3d.get_tracks();
        for(list<Track3D *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
        {
-               Track &track=(*i)->get_track();
+               Track &track = (*i)->get_track();
                if(track.get_turnout_id())
                {
-                       Turnout &trnt=control.get_turnout(track.get_turnout_id());
+                       Turnout &trnt = control.get_turnout(track.get_turnout_id());
                        (*i)->render_route(trnt.get_route());
                }
                else
@@ -256,9 +256,9 @@ void Engineer::tick()
        {
                GL::push_matrix();
 
-               const Marklin::Block::Endpoint &bep=placing_block->get_endpoints()[placing_entry];
-               float rot=bep.track->get_endpoint_direction(bep.track_ep);
-               Point pos=bep.track->get_endpoint_position(bep.track_ep);
+               const Marklin::Block::Endpoint &bep = placing_block->get_endpoints()[placing_entry];
+               float rot = bep.track->get_endpoint_direction(bep.track_ep);
+               Point pos = bep.track->get_endpoint_position(bep.track_ep);
 
                GL::translate(pos.x, pos.y, pos.z+0.03);
                GL::rotate(rot*180/M_PI+180, 0, 0, 1);
@@ -279,12 +279,12 @@ void Engineer::tick()
                GL::pop_matrix();
        }
 
-       const list<Train *> &trains=trfc_mgr->get_trains();
+       const list<Train *> &trains = trfc_mgr->get_trains();
        for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
                GL::PushMatrix _push;
 
-               const Point &tp=(*i)->get_position();
+               const Point &tp = (*i)->get_position();
                GL::translate(tp.x, tp.y, 0.02);
                GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2));
                imm.color(0.8f, 0.8f, 1.0f);
@@ -316,7 +316,7 @@ void Engineer::tick()
        if(train_prop_stale)
        {
                delete train_prop;
-               train_prop=0;
+               train_prop = 0;
        }
 
        glc->swap_buffers();
@@ -337,23 +337,23 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned)
                        set_block_color(*placing_block, GL::Color(1, 1, 1));
 
                        placing_train->place(placing_block, placing_entry);
-                       placing_train=0;
+                       placing_train = 0;
                        main_panel->set_status_text(string());
                }
                else if(btn==3)
                {
-                       const vector<Block::Endpoint> &endpoints=placing_block->get_endpoints();
-                       placing_entry=(placing_entry+1)%endpoints.size();
+                       const vector<Block::Endpoint> &endpoints = placing_block->get_endpoints();
+                       placing_entry = (placing_entry+1)%endpoints.size();
                }
        }
        else
        {
-               Track3D *track=pick_track(x, screen_h-y-1);
+               Track3D *track = pick_track(x, screen_h-y-1);
                if(track)
                {
                        if(unsigned tid=track->get_track().get_turnout_id())
                        {
-                               Turnout &turnout=control.get_turnout(tid);
+                               Turnout &turnout = control.get_turnout(tid);
                                try
                                {
                                        turnout.set_route((turnout.get_route()+1)%track->get_track().get_type().get_n_routes());
@@ -368,7 +368,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned)
                        {
                                if(unsigned sid=track->get_track().get_sensor_id())
                                {
-                                       Sensor &sensor=control.get_sensor(sid);
+                                       Sensor &sensor = control.get_sensor(sid);
                                        control.signal_sensor_event.emit(sid, !sensor.get_state());
                                }
                        }
@@ -384,16 +384,16 @@ void Engineer::pointer_motion(int x, int y)
 {
        if(placing_train)
        {
-               Track3D *track=pick_track(x, screen_h-y-1);
+               Track3D *track = pick_track(x, screen_h-y-1);
                if(track && placing_train)
                {
-                       Block &block=trfc_mgr->get_block_by_track(track->get_track());
+                       Block &block = trfc_mgr->get_block_by_track(track->get_track());
                        if(&block!=placing_block)
                        {
                                if(placing_block)
                                        reset_block_color(*placing_block);
-                               placing_block=&block;
-                               placing_entry=0;
+                               placing_block = &block;
+                               placing_entry = 0;
                                set_block_color(*placing_block, GL::Color(0.5, 1, 0.7));
                        }
                }
@@ -406,51 +406,51 @@ void Engineer::pointer_motion(int x, int y)
 
 void Engineer::view_all()
 {
-       const list<Track3D *> &tracks=layout_3d.get_tracks();
+       const list<Track3D *> &tracks = layout_3d.get_tracks();
 
-       cam_rot=0;
-       float best_height=-1;
-       float mid_x=0;
-       float mid_y=0;
+       cam_rot = 0;
+       float best_height = -1;
+       float mid_x = 0;
+       float mid_y = 0;
        for(float angle=0; angle<M_PI; angle+=0.01)
        {
-               float min_x=0;
-               float max_x=0;
-               float min_y=0;
-               float max_y=0;
+               float min_x = 0;
+               float max_x = 0;
+               float min_y = 0;
+               float max_y = 0;
                for(list<Track3D *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                {
                        Point minp, maxp;
                        (*i)->get_bounds(angle, minp, maxp);
-                       min_x=min(min_x, minp.x);
-                       max_x=max(max_x, maxp.x);
-                       min_y=min(min_y, minp.y);
-                       max_y=max(max_y, maxp.y);
+                       min_x = min(min_x, minp.x);
+                       max_x = max(max_x, maxp.x);
+                       min_y = min(min_y, minp.y);
+                       max_y = max(max_y, maxp.y);
                }
 
-               float width=max_x-min_x;
-               float height=max_y-min_y;
-               height=max(height, width);
+               float width = max_x-min_x;
+               float height = max_y-min_y;
+               height = max(height, width);
 
                if(height<best_height || best_height<0)
                {
-                       cam_rot=angle;
-                       best_height=height;
-                       mid_x=(min_x+max_x)/2;
-                       mid_y=(min_y+max_y)/2;
+                       cam_rot = angle;
+                       best_height = height;
+                       mid_x = (min_x+max_x)/2;
+                       mid_y = (min_y+max_y)/2;
                }
        }
 
-       float c=cos(cam_rot);
-       float s=sin(cam_rot);
-       cam_pos.x=c*mid_x-s*mid_y;
-       cam_pos.y=s*mid_x+c*mid_y;
-       cam_pos.z=max(best_height*1.05/0.82843, 0.15);
+       float c = cos(cam_rot);
+       float s = sin(cam_rot);
+       cam_pos.x = c*mid_x-s*mid_y;
+       cam_pos.y = s*mid_x+c*mid_y;
+       cam_pos.z = max(best_height*1.05/0.82843, 0.15);
 }
 
 void Engineer::set_block_color(const Block &block, const GL::Color &color)
 {
-       const set<Track *> &tracks=block.get_tracks();
+       const set<Track *> &tracks = block.get_tracks();
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                layout_3d.get_track(**i).set_color(color);
 }
@@ -459,7 +459,7 @@ void Engineer::reset_block_color(const Block &block)
 {
        if(unsigned sid=block.get_sensor_id())
        {
-               Sensor &sensor=control.get_sensor(sid);
+               Sensor &sensor = control.get_sensor(sid);
                if(sensor.get_state())
                {
                        set_block_color(block, GL::Color(1, 0.5, 0.3));
@@ -475,7 +475,7 @@ void Engineer::reset_block_color(const Block &block)
 
 void Engineer::sensor_event(bool, Sensor *sensor)
 {
-       const list<Block *> &blocks=trfc_mgr->get_blocks();
+       const list<Block *> &blocks = trfc_mgr->get_blocks();
        for(list<Block *>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
                if((*i)->get_sensor_id()==sensor->get_address())
                        reset_block_color(**i);
@@ -490,16 +490,16 @@ void Engineer::project_3d()
 {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
-       float offset=200.0/screen_w*0.055228;
+       float offset = 200.0/screen_w*0.055228;
        glFrustum(-0.055228-offset, 0.055228-offset, -0.041421, 0.041421, 0.1, 10);
        glMatrixMode(GL_MODELVIEW);
 }
 
 Track3D *Engineer::pick_track(int x, int y)
 {
-       float xx=(static_cast<float>(x-static_cast<int>(screen_w)/2-100)/screen_h)*0.82843;
-       float yy=(static_cast<float>(y)/screen_h-0.5)*0.82843;
-       float size=4.0/screen_h*0.82843;
+       float xx = (static_cast<float>(x-static_cast<int>(screen_w)/2-100)/screen_h)*0.82843;
+       float yy = (static_cast<float>(y)/screen_h-0.5)*0.82843;
+       float size = 4.0/screen_h*0.82843;
 
        project_3d();
        glLoadIdentity();
@@ -511,7 +511,7 @@ Track3D *Engineer::pick_track(int x, int y)
 
 void Engineer::dismiss_train_prop()
 {
-       train_prop_stale=true;
+       train_prop_stale = true;
 }
 
 Application::RegApp<Engineer> Engineer::reg;
index 9f3bf1a95f1c8303b8b6b432c6803f19326d3e4f..b47093468cac16197a4bd890fe588f4010efb902 100644 (file)
@@ -44,21 +44,21 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t):
 
        GLtk::Button *btn;
 
-       const map<unsigned, string> &funcs=train.get_locomotive().get_type().get_functions();
-       unsigned x=10;
+       const map<unsigned, string> &funcs = train.get_locomotive().get_type().get_functions();
+       unsigned x = 10;
        for(map<unsigned, string>::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=40)
        {
-               string fname=i->second;
-               fname[0]=toupper(fname[0]);
+               string fname = i->second;
+               fname[0] = toupper(fname[0]);
                add(*(btn=new GLtk::Button(res, fname)));
                btn->set_geometry(GLtk::Geometry(x, 68, 40, 24));
                btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::func_clicked), i->first));
 
-               GLtk::Indicator *ind=new GLtk::Indicator(res);
+               GLtk::Indicator *ind = new GLtk::Indicator(res);
                add(*ind);
                ind->set_geometry(GLtk::Geometry(x, 92, 40, 12));
                ind->set_active(train.get_locomotive().get_function(i->first));
-               ind_funcs[i->first]=ind;
+               ind_funcs[i->first] = ind;
        }
        train.get_locomotive().signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_function_changed));
 
@@ -87,7 +87,7 @@ void TrainPanel::loco_speed_changed(unsigned speed)
 
 void TrainPanel::loco_function_changed(unsigned func, bool value)
 {
-       map<unsigned, GLtk::Indicator *>::iterator i=ind_funcs.find(func);
+       map<unsigned, GLtk::Indicator *>::iterator i = ind_funcs.find(func);
        if(i!=ind_funcs.end())
                i->second->set_active(value);
 }
index 9eaf8d37255c55c3cd81fa0532cf14850136ed54..be3ba8daa410091746b9efb3cde1f7407b30aa1b 100644 (file)
@@ -28,7 +28,7 @@ TrainProperties::TrainProperties(Engineer &e, GLtk::Resources &r, Train *t):
        add(*(drp_type=new GLtk::Dropdown(res)));
        drp_type->set_geometry(GLtk::Geometry(60, geom.h-30, geom.w-70, 20));
 
-       const map<unsigned, LocoType *> &locos=engineer.get_catalogue().get_locomotives();
+       const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
        for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i)
                drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
 
@@ -52,10 +52,10 @@ void TrainProperties::ok_clicked()
 {
        if(!train)
        {
-               const map<unsigned, LocoType *> &locos=engineer.get_catalogue().get_locomotives();
-               map<unsigned, LocoType *>::const_iterator i=locos.begin();
+               const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
+               map<unsigned, LocoType *>::const_iterator i = locos.begin();
                advance(i, drp_type->get_selected_index());
-               train=engineer.add_train(*i->second, lexical_cast<unsigned>(ent_addr->get_text()));
+               train = engineer.add_train(*i->second, lexical_cast<unsigned>(ent_addr->get_text()));
        }
 
        train->set_name(ent_name->get_text());
index ee0a48cb950498474e0fe7d2b8bc602a5ac77987..c562788811a05ec07bc4997a8df6d6b49cf14a16 100644 (file)
@@ -17,6 +17,8 @@ using namespace Msp;
 
 namespace Marklin {
 
+unsigned Block::next_id = 1;
+
 Block::Block(TrafficManager &tm, Track &start):
        trfc_mgr(tm),
        id(next_id++),
@@ -31,10 +33,10 @@ Block::Block(TrafficManager &tm, Track &start):
 
        while(!queue.empty())
        {
-               Track *track=queue.front();
+               Track *track = queue.front();
                queue.erase(queue.begin());
 
-               const vector<Track *> &links=track->get_links();
+               const vector<Track *> &links = track->get_links();
                for(unsigned i=0; i<links.size(); ++i)
                        if(links[i] && !tracks.count(links[i]))
                        {
@@ -50,8 +52,8 @@ Block::Block(TrafficManager &tm, Track &start):
 
        for(unsigned i=0; i<endpoints.size(); ++i)
        {
-               unsigned route=1<<i;
-               endpoints[i].routes|=route;
+               unsigned route = 1<<i;
+               endpoints[i].routes |= route;
                set<Track *> visited;
                find_routes(*endpoints[i].track, endpoints[i].track_ep, route, visited);
        }
@@ -71,27 +73,27 @@ int Block::traverse(unsigned epi, float *len) const
        if(epi>=endpoints.size())
                throw InvalidParameterValue("Endpoint index out of range");
 
-       const Endpoint &ep=endpoints[epi];
-       Track *track=ep.track;
-       unsigned track_ep=ep.track_ep;
+       const Endpoint &ep = endpoints[epi];
+       Track *track = ep.track;
+       unsigned track_ep = ep.track_ep;
 
        if(len)
-               *len=0;
+               *len = 0;
 
        while(1)
        {
-               unsigned cur_route=0;
-               unsigned tid=track->get_turnout_id();
+               unsigned cur_route = 0;
+               unsigned tid = track->get_turnout_id();
                if(tid)
                {
-                       Turnout &turnout=trfc_mgr.get_control().get_turnout(tid);
-                       cur_route=turnout.get_route();
+                       Turnout &turnout = trfc_mgr.get_control().get_turnout(tid);
+                       cur_route = turnout.get_route();
                }
 
                if(len)
-                       *len+=track->get_type().get_route_length(cur_route);
+                       *len += track->get_type().get_route_length(cur_route);
 
-               int other_ep=track->traverse(track_ep, cur_route);
+               int other_ep = track->traverse(track_ep, cur_route);
                if(other_ep<0)
                        return -1;
 
@@ -99,11 +101,11 @@ int Block::traverse(unsigned epi, float *len) const
                        if(endpoints[i].track==track && endpoints[i].track_ep==static_cast<unsigned>(other_ep))
                                return i;
 
-               Track *next=track->get_link(other_ep);
+               Track *next = track->get_link(other_ep);
                if(tracks.count(next)==0)
                        return -1;
-               track_ep=next->get_endpoint_by_link(*track);
-               track=next;
+               track_ep = next->get_endpoint_by_link(*track);
+               track = next;
        }
 }
 
@@ -117,8 +119,8 @@ void Block::check_link(Block &other)
                for(vector<Endpoint>::iterator j=other.endpoints.begin(); j!=other.endpoints.end(); ++j)
                        if(j->track==i->track->get_link(i->track_ep) && j->track->get_link(j->track_ep)==i->track && !j->link)
                        {
-                               i->link=&other;
-                               j->link=this;
+                               i->link = &other;
+                               j->link = this;
                        }
        }
 }
@@ -134,7 +136,7 @@ bool Block::reserve(const Train *t)
 {
        if(!t || !train)
        {
-               train=t;
+               train = t;
                trfc_mgr.signal_block_reserved.emit(*this, train);
                return true;
        }
@@ -163,11 +165,11 @@ void Block::find_routes(Track &track, unsigned track_ep, unsigned route, set<Tra
 {
        visited.insert(&track);
 
-       const vector<Marklin::Endpoint> &eps=track.get_type().get_endpoints();
+       const vector<Marklin::Endpoint> &eps = track.get_type().get_endpoints();
        for(unsigned i=0; i<eps.size(); ++i)
        {
                if(i==track_ep) continue;
-               Track *link=track.get_link(i);
+               Track *link = track.get_link(i);
                if(!link) continue;
                if(visited.count(link)) continue;
                if(!(eps[i].routes&eps[track_ep].routes)) continue;
@@ -178,13 +180,11 @@ void Block::find_routes(Track &track, unsigned track_ep, unsigned route, set<Tra
                {
                        for(vector<Endpoint>::iterator j=endpoints.begin(); j!=endpoints.end(); ++j)
                                if(j->track==&track && j->track_ep==i)
-                                       j->routes|=route;
+                                       j->routes |= route;
                }
        }
 }
 
-unsigned Block::next_id=1;
-
 
 Block::Endpoint::Endpoint(Track *t, unsigned e):
        track(t),
index 1b181dffc0ec856ba76f87a6af54f8697971c968..689ad3b09c79e47e4db70e3ea5af8a2fa40a3f96 100644 (file)
@@ -53,9 +53,9 @@ void Catalogue::Loader::locomotive(unsigned art_nr)
        if(obj.locos.count(art_nr))
                throw Exception("Duplicate locomotive number");
 
-       RefPtr<LocoType> loco=new LocoType(art_nr);
+       RefPtr<LocoType> loco = new LocoType(art_nr);
        load_sub(*loco);
-       obj.locos[art_nr]=loco.release();
+       obj.locos[art_nr] = loco.release();
 }
 
 void Catalogue::Loader::track(unsigned art_nr)
@@ -63,9 +63,9 @@ void Catalogue::Loader::track(unsigned art_nr)
        if(obj.tracks.count(art_nr))
                throw Exception("Duplicate track number");
 
-       RefPtr<TrackType> trk=new TrackType(art_nr);
+       RefPtr<TrackType> trk = new TrackType(art_nr);
        load_sub(*trk);
-       obj.tracks[art_nr]=trk.release();
+       obj.tracks[art_nr] = trk.release();
 }
 
 } // namespace Marklin
index 3eab42ce57b4e90aa0ac6840aeec242fcb1ec1e7..6f7ef74dbf30bc18cd83bd111e994ef7e606c619 100644 (file)
@@ -41,7 +41,7 @@ Control::~Control()
 
 void Control::open(const string &dev)
 {
-       serial_fd=::open(dev.c_str(), O_RDWR);
+       serial_fd = ::open(dev.c_str(), O_RDWR);
        if(serial_fd<0)
                throw Exception("Couldn't open serial port\n");
 
@@ -57,10 +57,10 @@ void Control::open(const string &dev)
        termios attr;
        tcgetattr(serial_fd, &attr);
        cfmakeraw(&attr);
-       attr.c_cflag|=CSTOPB;
+       attr.c_cflag |= CSTOPB;
 
-       bool ok=false;
-       bool p50=false;
+       bool ok = false;
+       bool p50 = false;
        for(unsigned i=0; baud[i]; i+=2)
        {
                cfsetospeed(&attr, baud[i+1]);
@@ -68,13 +68,13 @@ void Control::open(const string &dev)
 
                write(serial_fd, "\xC4", 1);
 
-               pollfd pfd={serial_fd, POLLIN, 0};
+               pollfd pfd = { serial_fd, POLLIN, 0 };
                if(poll(&pfd, 1, 500)>0)
                {
                        cout<<"IB detected at "<<baud[i]<<" bits/s\n";
                        char buf[2];
-                       p50=(read(serial_fd, buf, 2)==2);
-                       ok=true;
+                       p50 = (read(serial_fd, buf, 2)==2);
+                       ok = true;
                        break;
                }
        }
@@ -90,12 +90,12 @@ void Control::open(const string &dev)
 
 void Control::set_debug(bool d)
 {
-       debug=d;
+       debug = d;
 }
 
 void Control::set_power(bool p)
 {
-       power=p;
+       power = p;
        if(power)
                command(CMD_POWER_ON);
        else
@@ -124,12 +124,12 @@ Command &Control::command(Cmd cmd, const unsigned char *data, unsigned len)
 
 void Control::add_turnout(Turnout &t)
 {
-       turnouts[t.get_address()]=&t;
+       turnouts[t.get_address()] = &t;
 }
 
 Turnout &Control::get_turnout(unsigned id) const
 {
-       map<unsigned, Turnout *>::const_iterator i=turnouts.find(id);
+       map<unsigned, Turnout *>::const_iterator i = turnouts.find(id);
        if(i==turnouts.end())
                throw KeyError("Unknown turnout");
 
@@ -138,12 +138,12 @@ Turnout &Control::get_turnout(unsigned id) const
 
 void Control::add_locomotive(Locomotive &l)
 {
-       locomotives[l.get_address()]=&l;
+       locomotives[l.get_address()] = &l;
 }
 
 Locomotive &Control::get_locomotive(unsigned id) const
 {
-       map<unsigned, Locomotive *>::const_iterator i=locomotives.find(id);
+       map<unsigned, Locomotive *>::const_iterator i = locomotives.find(id);
        if(i==locomotives.end())
                throw KeyError("Unknown locomotive");
 
@@ -152,13 +152,13 @@ Locomotive &Control::get_locomotive(unsigned id) const
 
 void Control::add_sensor(Sensor &s)
 {
-       sensors[s.get_address()]=&s;
-       poll_sensors=true;
+       sensors[s.get_address()] = &s;
+       poll_sensors = true;
 }
 
 Sensor &Control::get_sensor(unsigned id) const
 {
-       map<unsigned, Sensor *>::const_iterator i=sensors.find(id);
+       map<unsigned, Sensor *>::const_iterator i = sensors.find(id);
        if(i==sensors.end())
                throw KeyError("Unknown sensor");
 
@@ -167,7 +167,7 @@ Sensor &Control::get_sensor(unsigned id) const
 
 void Control::tick()
 {
-       const Time::TimeStamp t=Time::now();
+       const Time::TimeStamp t = Time::now();
 
        for(map<unsigned, Sensor *>::const_iterator i=sensors.begin(); i!=sensors.end(); ++i)
                i->second->tick();
@@ -176,27 +176,27 @@ void Control::tick()
 
        if(t>next_event_query)
        {
-               next_event_query=t+200*Time::msec;
+               next_event_query = t+200*Time::msec;
                command(CMD_EVENT).signal_done.connect(sigc::mem_fun(this, &Control::event_query_done));
        }
 
        if(poll_sensors)
        {
-               unsigned max_addr=(--sensors.end())->first;
+               unsigned max_addr = (--sensors.end())->first;
                unsigned char data[2];
-               data[0]=0;
-               data[1]=(max_addr+7)/8;
+               data[0] = 0;
+               data[1] = (max_addr+7)/8;
                command(CMD_SENSOR_PARAM_SET, data, 2);
                command(CMD_SENSOR_REPORT);
-               poll_sensors=false;
+               poll_sensors = false;
        }
 
        if(!queue.empty() && queue.front().is_sent())
        {
-               pollfd pfd={serial_fd, POLLIN, 0};
+               pollfd pfd = { serial_fd, POLLIN, 0 };
                if(poll(&pfd, 1, 0)>0)
                {
-                       Reply reply=Reply::read(serial_fd, queue.front().get_command());
+                       Reply reply = Reply::read(serial_fd, queue.front().get_command());
                        if(debug)
                                cout<<"R: "<<reply<<'\n';
 
@@ -223,13 +223,13 @@ Time::Timer::Slot &Control::set_timer(const Time::TimeDelta &dt)
 
 void Control::status_done(const Reply &reply)
 {
-       power=((reply.get_data()[0]&0x08)!=0);
+       power = ((reply.get_data()[0]&0x08)!=0);
        signal_power_event.emit(power);
 }
 
 void Control::event_query_done(const Reply &reply)
 {
-       const unsigned char *data=reply.get_data();
+       const unsigned char *data = reply.get_data();
        if(data[0]&0x01)
                command(CMD_EVENT_LOK);
        if(data[0]&0x20)
@@ -242,12 +242,12 @@ void Control::event_query_done(const Reply &reply)
 
 void Control::turnout_event_done(const Reply &reply)
 {
-       const unsigned char *data=reply.get_data();
-       unsigned count=data[0];
+       const unsigned char *data = reply.get_data();
+       unsigned count = data[0];
        for(unsigned i=0; i<count; ++i)
        {
-               unsigned addr=(data[i*2+1])+((data[i*2+2]&7)<<8);
-               bool status=!(data[i*2+2]&0x80);
+               unsigned addr = (data[i*2+1])+((data[i*2+2]&7)<<8);
+               bool status = !(data[i*2+2]&0x80);
                cout<<"Turnout "<<addr<<", status "<<status<<'\n';
                signal_turnout_event.emit(addr, status);
        }
@@ -255,10 +255,10 @@ void Control::turnout_event_done(const Reply &reply)
 
 void Control::sensor_event_done(const Reply &reply)
 {
-       const unsigned char *data=reply.get_data();
+       const unsigned char *data = reply.get_data();
        for(unsigned i=0; data[i]; i+=3)
        {
-               unsigned module=data[i];
+               unsigned module = data[i];
 
                cout<<"S88 module "<<module<<", status ";
                for(unsigned j=0; j<16; ++j)
index 8cfb95fa5e1c4f2d11ae471704516b8537bc2085..bd9ee712d5370ae5b7aac5afc180102fefdc6614 100644 (file)
@@ -99,9 +99,9 @@ void Layout::Loader::finish()
 
 void Layout::Loader::track(unsigned art_nr)
 {
-       TrackType &type=obj.catalogue.get_track(art_nr);
+       TrackType &type = obj.catalogue.get_track(art_nr);
 
-       RefPtr<Track> trk=new Track(type);
+       RefPtr<Track> trk = new Track(type);
        load_sub(*trk);
        obj.add_track(*trk.release());
 }
index 32f2ecc1a185f2fa1ac387cb4659ad61e1926f01..c7d6227cddb938e5d3acfbbb6cc2c8f564ca771f 100644 (file)
@@ -33,10 +33,10 @@ Locomotive::Locomotive(const LocoType &t, Control &c, unsigned a):
 
 void Locomotive::set_speed(unsigned spd)
 {
-       spd=min(spd, 14U);
+       spd = min(spd, 14U);
        signal_speed_changing.emit(spd);
 
-       speed=spd;
+       speed = spd;
        send_command(false);
 
        signal_speed_changed.emit(speed);
@@ -54,7 +54,7 @@ void Locomotive::set_reverse(bool rev)
        }
        else
        {
-               reverse=rev;
+               reverse = rev;
                send_command(false);
        }
 }
@@ -62,9 +62,9 @@ void Locomotive::set_reverse(bool rev)
 void Locomotive::set_function(unsigned func, bool state)
 {
        if(state)
-               funcs|=1<<func;
+               funcs |= 1<<func;
        else
-               funcs&=~(1<<func);
+               funcs &= ~(1<<func);
 
        send_command(true);
 
@@ -74,32 +74,32 @@ void Locomotive::set_function(unsigned func, bool state)
 void Locomotive::refresh_status()
 {
        unsigned char data[2];
-       data[0]=addr&0xFF;
-       data[1]=(addr>>8)&0xFF;
+       data[0] = addr&0xFF;
+       data[1] = (addr>>8)&0xFF;
        control.command(CMD_LOK_STATUS, data, 2).signal_done.connect(sigc::mem_fun(this, &Locomotive::status_reply));
 }
 
 void Locomotive::send_command(bool setf)
 {
        unsigned char data[4];
-       data[0]=addr&0xFF;
-       data[1]=(addr>>8)&0xFF;
+       data[0] = addr&0xFF;
+       data[1] = (addr>>8)&0xFF;
 
        if(speed==0)
-               data[2]=0;
+               data[2] = 0;
        else if(speed==1)
-               data[2]=2;
+               data[2] = 2;
        else
-               data[2]=(speed*19-18)/2;
+               data[2] = (speed*19-18)/2;
        
-       data[3]=(reverse ? 0 : 0x20) | ((funcs&1) ? 0x10 : 0);
+       data[3] = (reverse ? 0 : 0x20) | ((funcs&1) ? 0x10 : 0);
 
        if(setf)
        {
-               data[3]|=0x80;
+               data[3] |= 0x80;
                for(unsigned i=0; i<4; ++i)
                        if((funcs>>i)&2)
-                               data[3]|=(1<<i);
+                               data[3] |= (1<<i);
        }
        control.command(CMD_LOK, data, 4);
 }
@@ -108,17 +108,17 @@ void Locomotive::status_reply(const Reply &reply)
 {
        if(reply.get_error()==ERR_NO_ERROR)
        {
-               const unsigned char *data=reply.get_data();
+               const unsigned char *data = reply.get_data();
 
                if(data[0]<=1)
-                       speed=0;
+                       speed = 0;
                else
-                       speed=data[0]*2/19+1;
+                       speed = data[0]*2/19+1;
 
-               reverse=(data[1]&0x20) ? false : true;
-               funcs=(data[1]&0xF)<<1;
+               reverse = (data[1]&0x20) ? false : true;
+               funcs = (data[1]&0xF)<<1;
                if(data[1]&0x10)
-                       funcs|=1;
+                       funcs |= 1;
 
                for(unsigned i=0; i<5; ++i)
                        signal_function_changed.emit(i, (funcs>>i)&1);
@@ -127,7 +127,7 @@ void Locomotive::status_reply(const Reply &reply)
 
 bool Locomotive::reverse_timeout()
 {
-       reverse=!reverse;
+       reverse = !reverse;
        send_command(true);
        return false;
 }
index 9eed205289a74c61566349f9f239a179e53796c1..6dcd6ae302920757072eee25c0fb5d00eb168ed6 100644 (file)
@@ -25,7 +25,7 @@ LocoType::Loader::Loader(LocoType &lt):
 
 void LocoType::Loader::function(unsigned i, const string &f)
 {
-       obj.funcs[i]=f;
+       obj.funcs[i] = f;
 }
 
 } // namespace Marklin
index ede23ccb3aa939dd28665e8f0000786d7a85e5d9..5a02df212897c4efd36a2261d4747d94da41617b 100644 (file)
@@ -18,9 +18,9 @@ namespace {
 
 unsigned read_all(int fd, char *buf, unsigned size)
 {
-       unsigned pos=0;
+       unsigned pos = 0;
        while(pos<size)
-               pos+=read(fd, buf+pos, size-pos);
+               pos += read(fd, buf+pos, size-pos);
 
        return pos;
 }
@@ -40,13 +40,13 @@ Reply Reply::read(int fd, Cmd cmd)
 {
        Reply result;
 
-       char *data=reinterpret_cast<char *>(result.data);
+       char *data = reinterpret_cast<char *>(result.data);
 
        if(cmd==CMD_EVENT)
        {
                for(unsigned i=0; i<3; ++i)
                {
-                       result.len+=read_all(fd, data+i, 1);
+                       result.len += read_all(fd, data+i, 1);
                        if(!(result.data[i]&0x80))
                                break;
                }
@@ -55,54 +55,54 @@ Reply Reply::read(int fd, Cmd cmd)
        {
                for(unsigned i=0;; i+=5)
                {
-                       result.len+=read_all(fd, data+i, 1);
+                       result.len += read_all(fd, data+i, 1);
 
                        if(result.data[i]&0x80)
                                break;
 
-                       result.len+=read_all(fd, data+i+1, 4);
+                       result.len += read_all(fd, data+i+1, 4);
                }
        }
        else if(cmd==CMD_EVENT_TURNOUT)
        {
-               result.len+=read_all(fd, data, 1);
-               result.len+=read_all(fd, data+1, result.data[0]*2);
+               result.len += read_all(fd, data, 1);
+               result.len += read_all(fd, data+1, result.data[0]*2);
        }
        else if(cmd==CMD_EVENT_SENSOR)
        {
                for(unsigned i=0;; i+=3)
                {
-                       result.len+=read_all(fd, data+i, 1);
+                       result.len += read_all(fd, data+i, 1);
 
                        if(result.data[i]==0)
                                break;
 
-                       result.len+=read_all(fd, data+i+1, 2);
+                       result.len += read_all(fd, data+i+1, 2);
                }
        }
        else
        {
-               bool expect_errcode=(cmd!=CMD_STATUS);
+               bool expect_errcode = (cmd!=CMD_STATUS);
 
-               unsigned expected_bytes=0;
+               unsigned expected_bytes = 0;
                if(cmd==CMD_STATUS || cmd==CMD_FUNC_STATUS || cmd==CMD_TURNOUT_STATUS)
-                       expected_bytes=1;
+                       expected_bytes = 1;
                if(cmd==CMD_SENSOR_STATUS || cmd==CMD_TURNOUT_GROUP_STATUS)
-                       expected_bytes=2;
+                       expected_bytes = 2;
                if(cmd==CMD_LOK_STATUS)
-                       expected_bytes=3;
+                       expected_bytes = 3;
                if(cmd==CMD_LOK_CONFIG)
-                       expected_bytes=4;
+                       expected_bytes = 4;
 
                if(expect_errcode)
                {
                        char c;
                        read_all(fd, &c, 1);
-                       result.err=static_cast<Error>(c);
+                       result.err = static_cast<Error>(c);
                }
 
                if(result.err==ERR_NO_ERROR)
-                       result.len+=read_all(fd, data, expected_bytes);
+                       result.len += read_all(fd, data, expected_bytes);
        }
 
        return result;
index 9b9b5f3656f46868d452a00f52b7d22f415bd8e8..28f95482ab0b746652ed37bc0b44b31020cde22e 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright Â© 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright Â© 2007-2008  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
@@ -29,15 +29,15 @@ void Sensor::sensor_event(unsigned a, bool s)
        {
                if(s)
                {
-                       off_timeout=Time::TimeStamp();
+                       off_timeout = Time::TimeStamp();
                        if(s!=state)
                        {
-                               state=s;
+                               state = s;
                                signal_state_changed.emit(state);
                        }
                }
                else
-                       off_timeout=Time::now()+0.5*Time::sec;
+                       off_timeout = Time::now()+0.5*Time::sec;
        }
 }
 
@@ -45,13 +45,13 @@ void Sensor::tick()
 {
        if(off_timeout)
        {
-               const Time::TimeStamp t=Time::now();
+               const Time::TimeStamp t = Time::now();
                if(t>off_timeout)
                {
-                       off_timeout=Time::TimeStamp();
+                       off_timeout = Time::TimeStamp();
                        if(state)
                        {
-                               state=false;
+                               state = false;
                                signal_state_changed.emit(state);
                        }
                }
index 73674ee8c39f340cf7665e153ff3908544a33b29..01b789373c6fb655b712a6558533ec588adc08f9 100644 (file)
@@ -31,28 +31,28 @@ Track::~Track()
 
 void Track::set_position(const Point &p)
 {
-       pos=p;
+       pos = p;
 }
 
 void Track::set_rotation(float r)
 {
-       rot=r;
+       rot = r;
        while(rot<0)
-               rot+=M_PI*2;
+               rot += M_PI*2;
        while(rot>M_PI*2)
-               rot-=M_PI*2;
+               rot -= M_PI*2;
 }
 
 void Track::set_slope(float s)
 {
        if(links.size()!=2) return;
 
-       slope=s;
+       slope = s;
 }
 
 void Track::set_flex(bool f)
 {
-       flex=f;
+       flex = f;
 }
 
 void Track::check_slope()
@@ -62,35 +62,35 @@ void Track::check_slope()
 
        if(links[0] && links[1])
        {
-               Point epp0=links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this));
-               Point epp1=links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this));
-               pos.z=epp0.z;
-               slope=epp1.z-pos.z;
+               Point epp0 = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this));
+               Point epp1 = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this));
+               pos.z = epp0.z;
+               slope = epp1.z-pos.z;
        }
        else
        {
-               slope=0;
+               slope = 0;
                if(links[0])
                {
-                       Point epp=links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this));
-                       pos.z=epp.z;
+                       Point epp = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this));
+                       pos.z = epp.z;
                }
                else if(links[1])
                {
-                       Point epp=links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this));
-                       pos.z=epp.z;
+                       Point epp = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this));
+                       pos.z = epp.z;
                }
        }
 }
 
 void Track::set_turnout_id(unsigned i)
 {
-       turnout_id=i;
+       turnout_id = i;
 }
 
 void Track::set_sensor_id(unsigned i)
 {
-       sensor_id=i;
+       sensor_id = i;
 }
 
 int Track::get_endpoint_by_link(const Track &other) const
@@ -104,50 +104,50 @@ int Track::get_endpoint_by_link(const Track &other) const
 
 Point Track::get_endpoint_position(unsigned epi) const
 {
-       const vector<Endpoint> &eps=type.get_endpoints();
+       const vector<Endpoint> &eps = type.get_endpoints();
        if(epi>=eps.size())
                throw InvalidParameterValue("Endpoint index out of range");
 
-       const Endpoint &ep=eps[epi];
+       const Endpoint &ep = eps[epi];
 
-       float c=cos(rot);
-       float s=sin(rot);
+       float c = cos(rot);
+       float s = sin(rot);
 
        Point p(pos.x+c*ep.pos.x-s*ep.pos.y, pos.y+s*ep.pos.x+c*ep.pos.y, pos.z);
        if(eps.size()==2 && epi==1)
-               p.z+=slope;
+               p.z += slope;
        return p;
 }
 
 float Track::get_endpoint_direction(unsigned epi) const
 {
-       const vector<Endpoint> &eps=type.get_endpoints();
+       const vector<Endpoint> &eps = type.get_endpoints();
        if(epi>=eps.size())
                throw InvalidParameterValue("Endpoint index out of range");
 
-       const Endpoint &ep=eps[epi];
+       const Endpoint &ep = eps[epi];
 
        return rot+ep.dir;
 }
 
 bool Track::snap_to(Track &other, bool link)
 {
-       float limit=(link && !flex) ? 1e-6 : 1e-4;
-       const vector<Endpoint> &eps=type.get_endpoints();
-       const vector<Endpoint> &other_eps=other.get_type().get_endpoints();
+       float limit = (link && !flex) ? 1e-6 : 1e-4;
+       const vector<Endpoint> &eps = type.get_endpoints();
+       const vector<Endpoint> &other_eps = other.get_type().get_endpoints();
 
        for(unsigned i=0; i<eps.size(); ++i)
        {
-               Point epp=get_endpoint_position(i);
+               Point epp = get_endpoint_position(i);
 
                for(unsigned j=0; j<other_eps.size(); ++j)
                {
                        if(other.get_link(j))
                                continue;
 
-                       Point epp2=other.get_endpoint_position(j);
-                       float dx=epp2.x-epp.x;
-                       float dy=epp2.y-epp.y;
+                       Point epp2 = other.get_endpoint_position(j);
+                       float dx = epp2.x-epp.x;
+                       float dy = epp2.y-epp.y;
                        if(dx*dx+dy*dy<limit)
                        {
                                set_rotation(other.rot+other_eps[j].dir-eps[i].dir+M_PI);
@@ -157,8 +157,8 @@ bool Track::snap_to(Track &other, bool link)
                                {
                                        if(links[i])
                                                break_link(*links[i]);
-                                       links[i]=&other;
-                                       other.links[j]=this;
+                                       links[i] = &other;
+                                       other.links[j] = this;
                                }
 
                                return true;
@@ -171,17 +171,17 @@ bool Track::snap_to(Track &other, bool link)
 
 bool Track::snap(Point &pt, float &d) const
 {
-       const vector<Endpoint> &eps=type.get_endpoints();
+       const vector<Endpoint> &eps = type.get_endpoints();
 
        for(unsigned i=0; i<eps.size(); ++i)
        {
-               Point epp=get_endpoint_position(i);
-               float dx=pt.x-epp.x;
-               float dy=pt.y-epp.y;
+               Point epp = get_endpoint_position(i);
+               float dx = pt.x-epp.x;
+               float dy = pt.y-epp.y;
                if(dx*dx+dy*dy<1e-4)
                {
-                       pt=epp;
-                       d=rot+eps[i].dir;
+                       pt = epp;
+                       d = rot+eps[i].dir;
                        return true;
                }
        }
@@ -194,7 +194,7 @@ void Track::break_link(Track &trk)
        for(vector<Track *>::iterator i=links.begin(); i!=links.end(); ++i)
                if(*i==&trk)
                {
-                       *i=0;
+                       *i = 0;
                        trk.break_link(*this);
                        return;
                }
@@ -205,7 +205,7 @@ void Track::break_links()
        for(vector<Track *>::iterator i=links.begin(); i!=links.end(); ++i)
                if(Track *trk=*i)
                {
-                       *i=0;
+                       *i = 0;
                        trk->break_link(*this);
                }
 }
@@ -220,11 +220,11 @@ Track *Track::get_link(unsigned i) const
 
 int Track::traverse(unsigned i, unsigned route) const
 {
-       const vector<Endpoint> &eps=type.get_endpoints();
+       const vector<Endpoint> &eps = type.get_endpoints();
        if(i>=eps.size())
                throw InvalidParameterValue("Endpoint index out of range");
 
-       const Endpoint &ep=eps[i];
+       const Endpoint &ep = eps[i];
        
        if(ep.routes&(1<<route))
        {
@@ -246,15 +246,15 @@ int Track::traverse(unsigned i, unsigned route) const
 
 Point Track::get_point(unsigned epi, unsigned route, float d) const
 {
-       const vector<Endpoint> &eps=type.get_endpoints();
+       const vector<Endpoint> &eps = type.get_endpoints();
        if(epi>=eps.size())
                throw InvalidParameterValue("Endpoint index out of range");
 
-       float x=eps[epi].pos.x;
-       float y=eps[epi].pos.y;
+       float x = eps[epi].pos.x;
+       float y = eps[epi].pos.y;
 
-       const vector<TrackPart> &parts=type.get_parts();
-       const TrackPart *last_part=0;
+       const vector<TrackPart> &parts = type.get_parts();
+       const TrackPart *last_part = 0;
        while(1)
        {
                for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
@@ -268,29 +268,29 @@ Point Track::get_point(unsigned epi, unsigned route, float d) const
                        i->collect_endpoints(part_eps);
                        for(unsigned j=0; j<part_eps.size(); ++j)
                        {
-                               float dx=part_eps[j].pos.x-x;
-                               float dy=part_eps[j].pos.y-y;
+                               float dx = part_eps[j].pos.x-x;
+                               float dy = part_eps[j].pos.y-y;
                                if(dx*dx+dy*dy<1e-6)
                                {
-                                       float plen=i->length;
+                                       float plen = i->length;
                                        if(i->radius)
-                                               plen*=abs(i->radius);
+                                               plen *= abs(i->radius);
                                        if(d<plen)
                                        {
                                                if(j==1)
-                                                       d=plen-d;
-                                               Point p=i->get_point(d);
-                                               float c=cos(rot);
-                                               float s=sin(rot);
+                                                       d = plen-d;
+                                               Point p = i->get_point(d);
+                                               float c = cos(rot);
+                                               float s = sin(rot);
                                                return Point(pos.x+c*p.x-s*p.y, pos.y+c*p.y+s*p.x);
                                        }
                                        else if(part_eps.size()>1)
                                        {
-                                               d-=plen;
-                                               x=part_eps[1-j].pos.x;
-                                               y=part_eps[1-j].pos.y;
-                                               last_part=&*i;
-                                               i=parts.begin();
+                                               d -= plen;
+                                               x = part_eps[1-j].pos.x;
+                                               y = part_eps[1-j].pos.y;
+                                               last_part = &*i;
+                                               i = parts.begin();
                                                break;
                                        }
                                        else
@@ -308,7 +308,7 @@ Point Track::get_point(unsigned epi, unsigned route, float d) const
 
 Track *Track::copy() const
 {
-       Track *trk=new Track(type);
+       Track *trk = new Track(type);
        trk->set_position(pos);
        trk->set_rotation(rot);
        trk->set_slope(slope);
@@ -344,7 +344,7 @@ Track::Loader::Loader(Track &t):
 
 void Track::Loader::position(float x, float y, float z)
 {
-       obj.pos=Point(x, y, z);
+       obj.pos = Point(x, y, z);
 }
 
 } // namespace Marklin
index da177f8a73387cf21308d70efbe9a4da21989a79..943832fff413577dc77eabdef5d7d16840d61dbc 100644 (file)
@@ -28,8 +28,8 @@ void TrackPart::collect_endpoints(vector<Endpoint> &eps) const
                ;
        else if(radius)
        {
-               float a=((radius<0) ? -length : length);
-               Point p=get_point(length*abs(radius));
+               float a = ((radius<0) ? -length : length);
+               Point p = get_point(length*abs(radius));
                eps.push_back(Endpoint(p.x, p.y, dir+a, 1<<route));
        }
        else
@@ -40,11 +40,11 @@ Point TrackPart::get_point(float d) const
 {
        if(radius)
        {
-               float a=d/radius;
-               float c=cos(a);
-               float s=sin(a);
-               float rx=radius*sin(dir);
-               float ry=-radius*cos(dir);
+               float a = d/radius;
+               float c = cos(a);
+               float s = sin(a);
+               float rx = radius*sin(dir);
+               float ry = -radius*cos(dir);
                return Point(pos.x+c*rx-s*ry-rx, pos.y+c*ry+s*rx-ry);
        }
        else
@@ -66,21 +66,21 @@ void TrackPart::Loader::finish()
 {
        if(obj.radius)
        {
-               obj.length*=M_PI/180;
-               obj.radius/=1000;
+               obj.length *= M_PI/180;
+               obj.radius /= 1000;
        }
        else
-               obj.length/=1000;
+               obj.length /= 1000;
 
-       obj.pos.x/=1000;
-       obj.pos.y/=1000;
-       obj.dir*=M_PI/180;
+       obj.pos.x /= 1000;
+       obj.pos.y /= 1000;
+       obj.dir *= M_PI/180;
 }
 
 void TrackPart::Loader::start(float x, float y, float d)
 {
-       obj.pos=Point(x, y);
-       obj.dir=d;
+       obj.pos = Point(x, y);
+       obj.dir = d;
 }
 
 } // namespace Marklin
index 7fc796245ef126dba67253e1ae1ab4ce447e6131..692b5625f1335c59fbc594ae11b1816520916b0d 100644 (file)
@@ -23,24 +23,24 @@ float TrackType::get_total_length() const
 
 float TrackType::get_route_length(int r) const
 {
-       float len=0;
+       float len = 0;
        for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
                if(r<0 || i->route==static_cast<unsigned>(r))
                {
-                       float l=i->length;
+                       float l = i->length;
                        if(i->radius)
-                               l*=abs(i->radius);
-                       len+=l;
+                               l *= abs(i->radius);
+                       len += l;
                }
        return len;
 }
 
 unsigned TrackType::get_n_routes() const
 {
-       unsigned n=1;
+       unsigned n = 1;
        for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
                if(i->route>=n)
-                       n=i->route+1;
+                       n = i->route+1;
        return n;
 }
 
@@ -53,29 +53,29 @@ void TrackType::collect_endpoints()
 
        for(vector<Endpoint>::iterator i=endpoints.begin(); i!=endpoints.end();)
        {
-               bool rm=false;
+               bool rm = false;
                for(vector<Endpoint>::iterator j=i+1; j!=endpoints.end();)
                {
-                       float dx=i->pos.x-j->pos.x;
-                       float dy=i->pos.y-j->pos.y;
+                       float dx = i->pos.x-j->pos.x;
+                       float dy = i->pos.y-j->pos.y;
                        if(dx*dx+dy*dy<0.0001)
                        {
-                               float da=i->dir-j->dir;
+                               float da = i->dir-j->dir;
                                if(da<-M_PI)
-                                       da+=M_PI*2;
+                                       da += M_PI*2;
                                if(da>M_PI)
-                                       da-=M_PI*2;
+                                       da -= M_PI*2;
                                if(da<-3.1 || da>3.1)
-                                       rm=true;
-                               i->routes|=j->routes;
-                               j=endpoints.erase(j);
+                                       rm = true;
+                               i->routes |= j->routes;
+                               j = endpoints.erase(j);
                        }
                        else
                                ++j;
                }
 
                if(rm)
-                       i=endpoints.erase(i);
+                       i = endpoints.erase(i);
                else
                        ++i;
        }
index 4075415ac95fdbe703a3287ad0e1f8d6e586d2d0..069731e060ae3a80e741a754fa83519af0b6da59 100644 (file)
@@ -25,7 +25,7 @@ TrafficManager::TrafficManager(Control &c, Layout &l):
        control(c),
        layout(l)
 {
-       const set<Track *> &tracks=layout.get_tracks();
+       const set<Track *> &tracks = layout.get_tracks();
 
        set<Track *> used_tracks;
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
@@ -37,7 +37,7 @@ TrafficManager::TrafficManager(Control &c, Layout &l):
 
                if(used_tracks.count(*i)==0)
                {
-                       Block *block=new Block(*this, **i);
+                       Block *block = new Block(*this, **i);
                        blocks.push_back(block);
                        used_tracks.insert(block->get_tracks().begin(), block->get_tracks().end());
                }
@@ -61,7 +61,7 @@ Block &TrafficManager::get_block_by_track(const Track &t) const
 {
        for(list<Block *>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
        {
-               const set<Track *> &tracks=(*i)->get_tracks();
+               const set<Track *> &tracks = (*i)->get_tracks();
                if(tracks.count(const_cast<Track *>(&t)))
                        return **i;
        }
@@ -77,11 +77,11 @@ void TrafficManager::add_train(Train *t)
 
 void TrafficManager::tick()
 {
-       Time::TimeStamp t=Time::now();
+       Time::TimeStamp t = Time::now();
        Time::TimeDelta dt;
        if(last_tick)
-               dt=t-last_tick;
-       last_tick=t;
+               dt = t-last_tick;
+       last_tick = t;
 
        for(list<Train *>::iterator i=trains.begin(); i!=trains.end(); ++i)
                (*i)->tick(t, dt);
@@ -93,7 +93,7 @@ void TrafficManager::save(const string &fn) const
        DataFile::Writer writer(out);
        for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
-               const Locomotive &loco=(*i)->get_locomotive();
+               const Locomotive &loco = (*i)->get_locomotive();
                DataFile::Statement st("train");
                st.append(loco.get_type().get_article_number());
                st.append(loco.get_address());
@@ -115,8 +115,8 @@ TrafficManager::Loader::Loader(TrafficManager &tm):
 
 void TrafficManager::Loader::train(unsigned art_nr, unsigned addr)
 {
-       Locomotive *loco=new Locomotive(obj.layout.get_catalogue().get_locomotive(art_nr), obj.control, addr);
-       Train *trn=new Train(obj, *loco);
+       Locomotive *loco = new Locomotive(obj.layout.get_catalogue().get_locomotive(art_nr), obj.control, addr);
+       Train *trn = new Train(obj, *loco);
        load_sub(*trn);
 }
 
index 7d6afbae1f1c074ad281712ae43cde0be3888460..341921aaf511000a406869cd78f0b566641ec420 100644 (file)
@@ -36,11 +36,11 @@ Train::Train(TrafficManager &tm, Locomotive &l):
 {
        trfc_mgr.add_train(this);
 
-       const map<unsigned, Sensor *> &sensors=trfc_mgr.get_control().get_sensors();
+       const map<unsigned, Sensor *> &sensors = trfc_mgr.get_control().get_sensors();
        for(map<unsigned, Sensor *>::const_iterator i=sensors.begin(); i!=sensors.end(); ++i)
                i->second->signal_state_changed.connect(sigc::bind(sigc::mem_fun(this, &Train::sensor_event), i->second));
 
-       const map<unsigned, Turnout *> &turnouts=trfc_mgr.get_control().get_turnouts();
+       const map<unsigned, Turnout *> &turnouts = trfc_mgr.get_control().get_turnouts();
        for(map<unsigned, Turnout *>::const_iterator i=turnouts.begin(); i!=turnouts.end(); ++i)
        {
                i->second->signal_route_changing.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_route_changing), i->second));
@@ -50,7 +50,7 @@ Train::Train(TrafficManager &tm, Locomotive &l):
 
 void Train::set_name(const string &n)
 {
-       name=n;
+       name = n;
 
        signal_name_changed.emit(name);
 }
@@ -58,9 +58,9 @@ void Train::set_name(const string &n)
 void Train::set_speed(unsigned speed)
 {
        if(!target_speed && speed)
-               travel_speed=static_cast<int>(round(speed*speed_scale*87*3.6/5))*5;
+               travel_speed = static_cast<int>(round(speed*speed_scale*87*3.6/5))*5;
 
-       target_speed=speed;
+       target_speed = speed;
        if(!target_speed)
        {
                // XXX We might roll onto a new sensor and get confused - should delay freeing blocks a bit
@@ -72,7 +72,7 @@ void Train::set_speed(unsigned speed)
                reserve_more();
 
        update_speed();
-       pure_speed=false;
+       pure_speed = false;
 }
 
 void Train::place(Block *block, unsigned entry)
@@ -80,13 +80,13 @@ void Train::place(Block *block, unsigned entry)
        for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end();)
        {
                i->block->reserve(0);
-               i=rsv_blocks.erase(i);
+               i = rsv_blocks.erase(i);
        }
 
        for(list<BlockRef>::iterator i=cur_blocks.begin(); i!=cur_blocks.end();)
        {
                i->block->reserve(0);
-               i=cur_blocks.erase(i);
+               i = cur_blocks.erase(i);
        }
 
        if(!block->reserve(this))
@@ -103,7 +103,7 @@ void Train::place(Block *block, unsigned entry)
 
 bool Train::free_block(Block *block)
 {
-       unsigned nsens=0;
+       unsigned nsens = 0;
        for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
        {
                if(i->block==block)
@@ -113,7 +113,7 @@ bool Train::free_block(Block *block)
                        while(i!=rsv_blocks.end())
                        {
                                i->block->reserve(0);
-                               i=rsv_blocks.erase(i);
+                               i = rsv_blocks.erase(i);
                        }
                        update_speed();
                        return true;
@@ -135,28 +135,28 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
 
        if(cur_track)
        {
-               unsigned route=0;
+               unsigned route = 0;
                if(cur_track->get_turnout_id())
-                       route=trfc_mgr.get_control().get_turnout(cur_track->get_turnout_id()).get_route();
+                       route = trfc_mgr.get_control().get_turnout(cur_track->get_turnout_id()).get_route();
 
-               offset+=speed_scale*loco.get_speed()*(dt/Time::sec);
+               offset += speed_scale*loco.get_speed()*(dt/Time::sec);
                if(offset>cur_track->get_type().get_route_length(route))
                {
-                       int out=cur_track->traverse(cur_track_ep, route);
+                       int out = cur_track->traverse(cur_track_ep, route);
                        if(out>=0)
                        {
-                               Track *next=cur_track->get_link(out);
+                               Track *next = cur_track->get_link(out);
                                if(next)
-                                       cur_track_ep=next->get_endpoint_by_link(*cur_track);
-                               cur_track=next;
-                               offset=0;
+                                       cur_track_ep = next->get_endpoint_by_link(*cur_track);
+                               cur_track = next;
+                               offset = 0;
                        }
                        else
-                               cur_track=0;
+                               cur_track = 0;
                }
 
                if(cur_track)
-                       pos=cur_track->get_point(cur_track_ep, route, offset);
+                       pos = cur_track->get_point(cur_track_ep, route, offset);
        }
 }
 
@@ -168,7 +168,7 @@ void Train::save(list<DataFile::Statement> &st) const
 
 void Train::sensor_event(bool state, Sensor *sensor)
 {
-       unsigned addr=sensor->get_address();
+       unsigned addr = sensor->get_address();
 
        if(state)
        {
@@ -179,32 +179,32 @@ void Train::sensor_event(bool state, Sensor *sensor)
 
                if(i!=rsv_blocks.begin())
                {
-                       float travel_time_secs=(Time::now()-last_entry_time)/Time::sec;
-                       travel_speed=static_cast<int>(round(travel_dist/travel_time_secs*87*3.6/5))*5;
+                       float travel_time_secs = (Time::now()-last_entry_time)/Time::sec;
+                       travel_speed = static_cast<int>(round(travel_dist/travel_time_secs*87*3.6/5))*5;
 
                        if(pure_speed)
                        {
-                               float weight=loco.get_speed()*travel_dist;
+                               float weight = loco.get_speed()*travel_dist;
                                if(weight)
                                {
-                                       weight*=weight;
-                                       float scale=travel_dist/travel_time_secs/loco.get_speed();
+                                       weight *= weight;
+                                       float scale = travel_dist/travel_time_secs/loco.get_speed();
                                        cout<<"Updating speed_scale: "<<speed_scale<<'x'<<speed_scale_weight<<" + "<<scale<<'x'<<weight<<'\n';
-                                       speed_scale=(speed_scale*speed_scale_weight+scale*weight)/(speed_scale_weight+weight);
-                                       speed_scale_weight+=weight;
+                                       speed_scale = (speed_scale*speed_scale_weight+scale*weight)/(speed_scale_weight+weight);
+                                       speed_scale_weight += weight;
                                        cout<<"  Result: "<<speed_scale<<'x'<<speed_scale_weight<<'\n';
                                }
                        }
 
-                       travel_dist=0;
+                       travel_dist = 0;
                        float block_len;
                        for(list<BlockRef>::iterator j=rsv_blocks.begin(); j!=i; ++j)
                        {
                                j->block->traverse(j->entry, &block_len);
-                               travel_dist+=block_len;
+                               travel_dist += block_len;
                        }
-                       last_entry_time=Time::now();
-                       pure_speed=true;
+                       last_entry_time = Time::now();
+                       pure_speed = true;
 
                        cur_blocks.splice(cur_blocks.end(), rsv_blocks, rsv_blocks.begin(), i);
                }
@@ -238,12 +238,12 @@ void Train::sensor_event(bool state, Sensor *sensor)
 
 void Train::turnout_route_changing(unsigned, Turnout *turnout)
 {
-       unsigned tid=turnout->get_address();
+       unsigned tid = turnout->get_address();
        for(list<BlockRef>::const_iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
                if(i->block->get_turnout_id()==tid)
                        throw TurnoutBusy(this);
        
-       unsigned nsens=0;
+       unsigned nsens = 0;
        for(list<BlockRef>::const_iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
        {
                if(i->block->get_turnout_id()==tid)
@@ -259,14 +259,14 @@ void Train::turnout_route_changing(unsigned, Turnout *turnout)
 
 void Train::turnout_route_changed(unsigned, Turnout *turnout)
 {
-       unsigned tid=turnout->get_address();
+       unsigned tid = turnout->get_address();
        for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
                if(i->block->get_turnout_id()==tid)
                {
                        while(i!=rsv_blocks.end())
                        {
                                i->block->reserve(0);
-                               i=rsv_blocks.erase(i);
+                               i = rsv_blocks.erase(i);
                        }
                        reserve_more();
                        update_speed();
@@ -276,34 +276,34 @@ void Train::turnout_route_changed(unsigned, Turnout *turnout)
 
 unsigned Train::reserve_more()
 {
-       BlockRef *last=0;
+       BlockRef *last = 0;
        if(!rsv_blocks.empty())
-               last=&rsv_blocks.back();
+               last = &rsv_blocks.back();
        else if(!cur_blocks.empty())
-               last=&cur_blocks.back();
+               last = &cur_blocks.back();
        if(!last)
                return 0;
 
-       unsigned nsens=0;
+       unsigned nsens = 0;
        for(list<BlockRef>::const_iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
                if(i->block->get_sensor_id())
                        ++nsens;
 
-       bool result=false;
+       bool result = false;
        while(nsens<2)
        {
-               int exit=last->block->traverse(last->entry);
+               int exit = last->block->traverse(last->entry);
                if(exit>=0) 
                {
-                       Block *link=last->block->get_link(exit);
+                       Block *link = last->block->get_link(exit);
                        if(link && link->reserve(this))
                        {
                                rsv_blocks.push_back(BlockRef(link, link->get_endpoint_by_link(*last->block)));
-                               last=&rsv_blocks.back();
+                               last = &rsv_blocks.back();
                                if(last->block->get_sensor_id())
                                {
                                        ++nsens;
-                                       result=true;
+                                       result = true;
                                }
                        }
                        else
@@ -318,9 +318,9 @@ unsigned Train::reserve_more()
                last->block->reserve(0);
                rsv_blocks.erase(--rsv_blocks.end());
                if(!rsv_blocks.empty())
-                       last=&rsv_blocks.back();
+                       last = &rsv_blocks.back();
                else
-                       last=0;
+                       last = 0;
        }
 
        return nsens;
@@ -331,12 +331,12 @@ void Train::update_speed()
        if(!target_speed)
        {
                loco.set_speed(0);
-               try_reserve=Time::TimeStamp();
+               try_reserve = Time::TimeStamp();
                set_status("Stopped");
        }
        else
        {
-               unsigned nsens=0;
+               unsigned nsens = 0;
                for(list<BlockRef>::const_iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
                        if(i->block->get_sensor_id())
                                ++nsens;
@@ -344,21 +344,21 @@ void Train::update_speed()
                if(nsens==0)
                {
                        loco.set_speed(0);
-                       pure_speed=false;
-                       try_reserve=Time::now()+2*Time::sec;
+                       pure_speed = false;
+                       try_reserve = Time::now()+2*Time::sec;
                        set_status("Blocked");
                }
                else if(nsens==1 && target_speed>3)
                {
                        loco.set_speed(3);
-                       pure_speed=false;
-                       try_reserve=Time::now()+2*Time::sec;
+                       pure_speed = false;
+                       try_reserve = Time::now()+2*Time::sec;
                        set_status("Slow");
                }
                else
                {
                        loco.set_speed(target_speed);
-                       try_reserve=Time::TimeStamp();
+                       try_reserve = Time::TimeStamp();
                        set_status(format("Traveling %d kmh", travel_speed));
                }
        }
@@ -366,16 +366,16 @@ void Train::update_speed()
 
 void Train::set_status(const string &s)
 {
-       status=s;
+       status = s;
        signal_status_changed.emit(s);
 }
 
 void Train::set_position(const Block::Endpoint &bep)
 {
-       cur_track=bep.track;
-       cur_track_ep=bep.track_ep;
-       offset=0;
-       pos=cur_track->get_endpoint_position(cur_track_ep);
+       cur_track = bep.track;
+       cur_track_ep = bep.track_ep;
+       offset = 0;
+       pos = cur_track->get_endpoint_position(cur_track_ep);
 }
 
 
index 3e6e10dcc69f0d37c3148b3abf7506c3fadb6f35..efa98bb5a7b5c49dd62800de0c878091fcda6747 100644 (file)
@@ -28,13 +28,13 @@ Turnout::Turnout(Control &c, unsigned a, bool d):
        control.signal_turnout_event.connect(sigc::mem_fun(this, &Turnout::turnout_event));
 
        unsigned char data[2];
-       data[0]=addr&0xFF;
-       data[1]=(addr>>8)&0xFF;
+       data[0] = addr&0xFF;
+       data[1] = (addr>>8)&0xFF;
        control.command(CMD_TURNOUT_STATUS, data, 2).signal_done.connect(sigc::bind(sigc::mem_fun(this, &Turnout::status_reply), false));
        if(dual)
        {
-               data[0]=(addr+1)&0xFF;
-               data[1]=((addr+1)>>8)&0xFF;
+               data[0] = (addr+1)&0xFF;
+               data[1] = ((addr+1)>>8)&0xFF;
                control.command(CMD_TURNOUT_STATUS, data, 2).signal_done.connect(sigc::bind(sigc::mem_fun(this, &Turnout::status_reply), true));
        }
 }
@@ -43,7 +43,7 @@ void Turnout::set_route(unsigned r)
 {
        signal_route_changing.emit(r);
 
-       route=r;
+       route = r;
        command(true);
        control.set_timer(200*Time::msec).signal_timeout.connect(sigc::mem_fun(this, &Turnout::switch_timeout));
 
@@ -53,13 +53,13 @@ void Turnout::set_route(unsigned r)
 void Turnout::command(bool on)
 {
        unsigned char data[2];
-       data[0]=addr&0xFF;
-       data[1]=((addr>>8)&0x7) | (on ? 0x40 : 0) | (route&1 ? 0 : 0x80);
+       data[0] = addr&0xFF;
+       data[1] = ((addr>>8)&0x7) | (on ? 0x40 : 0) | (route&1 ? 0 : 0x80);
        control.command(CMD_TURNOUT, data, 2);
        if(dual)
        {
-               data[0]=(addr+1)&0xFF;
-               data[1]=(((addr+1)>>8)&0x7) | (on ? 0x40 : 0) | (route&2 ? 0 : 0x80);
+               data[0] = (addr+1)&0xFF;
+               data[1] = (((addr+1)>>8)&0x7) | (on ? 0x40 : 0) | (route&2 ? 0 : 0x80);
                control.command(CMD_TURNOUT, data, 2);
        }
 }
@@ -68,9 +68,9 @@ void Turnout::status_reply(const Reply &reply, bool high)
 {
        if(reply.get_error()==ERR_NO_ERROR)
        {
-               bool v=!(reply.get_data()[0]&0x04);
-               unsigned b=(high?2:1);
-               route=(route&~b)|(v?b:0);
+               bool v = !(reply.get_data()[0]&0x04);
+               unsigned b = (high?2:1);
+               route = (route&~b)|(v?b:0);
                signal_route_changed.emit(route);
        }
 }
@@ -86,12 +86,12 @@ void Turnout::turnout_event(unsigned a, bool r)
 {
        if(a==addr && r!=(route&1))
        {
-               route=(route&2)|(r?1:0);
+               route = (route&2)|(r?1:0);
                signal_route_changed.emit(route);
        }
        else if(dual && a==addr+1 && r!=((route>>1)&1))
        {
-               route=(route&1)|(r?2:0);
+               route = (route&1)|(r?2:0);
                signal_route_changed.emit(route);
        }
 }