From: Mikko Rasa Date: Sat, 23 May 2009 07:46:58 +0000 (+0000) Subject: Code reformatting: add spaces around assignment operators X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=38fb8d56efde037a71c46a58bda314655e68ab6c;p=r2c2.git Code reformatting: add spaces around assignment operators --- diff --git a/source/3d/layout.cpp b/source/3d/layout.cpp index 8093081..f3fe379 100644 --- a/source/3d/layout.cpp +++ b/source/3d/layout.cpp @@ -35,7 +35,7 @@ Layout3D::~Layout3D() void Layout3D::set_quality(unsigned q) { - quality=q; + quality = q; for(list::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::max(); + Track3D *track = 0; + unsigned track_depth = numeric_limits::max(); for(vector::iterator i=select_buf.begin(); i!=select_buf.end(); ++i) if(i->min_depth(i->names.back()); - track_depth=i->min_depth; + track = reinterpret_cast(i->names.back()); + track_depth = i->min_depth; } return track; diff --git a/source/3d/track.cpp b/source/3d/track.cpp index f9b03ed..85050c9 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -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::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 &endpoints=track.get_type().get_endpoints(); + const vector &endpoints = track.get_type().get_endpoints(); for(unsigned i=0; i &parts=track.get_type().get_parts(); - unsigned index=0; + const vector &parts = track.get_type().get_parts(); + unsigned index = 0; for(vector::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(part.length*(1<(part.length*(1< &ctracks=catalogue.get_tracks(); - unsigned n=0; + const map &ctracks = catalogue.get_tracks(); + unsigned n = 0; for(map::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 <racks=layout_3d->get_tracks(); + const list <racks = layout_3d->get_tracks(); for(list::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(x)*2/screen_w-1; - float yf=static_cast(y)*2/screen_h-1; + float xf = static_cast(x)*2/screen_w-1; + float yf = static_cast(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<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 &tracks=layout->get_tracks(); - float len=0; + const set &tracks = layout->get_tracks(); + float len = 0; for(set::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: "<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 tracks=selection->get_tracks(); + set tracks = selection->get_tracks(); selection->clear(); for(set::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 &tracks=selection->get_tracks(); - const set <racks=layout->get_tracks(); + const set &tracks = selection->get_tracks(); + const set <racks = layout->get_tracks(); for(set::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<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 &tracks=selection->get_tracks(); - bool ok=false; - int id=-1; + const set &tracks = selection->get_tracks(); + bool ok = false; + int id = -1; for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { if((*i)->get_type().get_n_routes()==1) - ok=true; + ok = true; if(static_cast((*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<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(x-static_cast(screen_w)/2)/screen_h)*0.82843; - float yy=(static_cast(y)/screen_h-0.5)*0.82843; - float size=4.0/screen_h*0.82843; + float xx = (static_cast(x-static_cast(screen_w)/2)/screen_h)*0.82843; + float yy = (static_cast(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 "<(font->get_string_width(tooltip)*20); - tooltip_x=max(min(static_cast(screen_w)-w, x), 0); - tooltip_y=max(min(static_cast(screen_h)-20, y), 0); + int w = static_cast(font->get_string_width(tooltip)*20); + tooltip_x = max(min(static_cast(screen_w)-w, x), 0); + tooltip_y = max(min(static_cast(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(input->get_text()); + Track *track = selection->get_track(); + unsigned id = lexical_cast(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 &tracks=selection->get_tracks(); - unsigned id=lexical_cast(input->get_text()); + const set &tracks = selection->get_tracks(); + unsigned id = lexical_cast(input->get_text()); for(set::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; } diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index 798e99f..1f21430 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -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 new_tracks; for(vector::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::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::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::iterator i=tracks.begin(); i!=tracks.end(); ++i) tracks2.push_back(i->track); - float total_len=0; + float total_len = 0; list order; - Track *cur=*neighbors.begin(); + Track *cur = *neighbors.begin(); while(tracks2.size()) { - bool rev=false; + bool rev = false; for(list::iterator i=tracks2.begin(); i!=tracks2.end(); ++i) { - const vector &links=(*i)->get_links(); + const vector &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::iterator nb=neighbors.begin(); - int epi=(*nb)->get_endpoint_by_link(*order.front().track); - float start_z=(*nb)->get_endpoint_position(epi).z; + set::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::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::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::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::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::iterator i=neighbors.begin(); i!=neighbors.end(); ++i) for(vector::iterator j=tracks.begin(); j!=tracks.end(); ++j) j->track->break_link(**i); - const set <racks=designer.get_layout()->get_tracks(); + const set <racks = designer.get_layout()->get_tracks(); for(set::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i) { - bool ok=true; + bool ok = true; for(vector::iterator j=tracks.begin(); (j!=tracks.end() && ok); ++j) - ok=(j->track!=*i); + ok = (j->track!=*i); if(!ok) continue; for(vector::iterator j=tracks.begin(); j!=tracks.end(); ++j) @@ -253,7 +253,7 @@ void Manipulator::button_press(int, int, float, float, unsigned btn) } for(vector::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::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 <racks=designer.get_layout()->get_tracks(); - MTrack *snapped=0; + const set <racks = designer.get_layout()->get_tracks(); + MTrack *snapped = 0; for(set::const_iterator i=ltracks.begin(); (i!=ltracks.end() && !snapped); ++i) { - bool ok=true; + bool ok = true; for(vector::iterator j=tracks.begin(); (j!=tracks.end() && ok); ++j) - ok=(j->track!=*i); + ok = (j->track!=*i); if(!ok) continue; for(vector::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::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::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: "<::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 &stracks=selection->get_tracks(); + const set &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::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::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::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::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - const vector &links=i->track->get_links(); + const vector &links = i->track->get_links(); for(vector::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::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)); diff --git a/source/designer/measure.cpp b/source/designer/measure.cpp index ee08ba7..cbe1793 100644 --- a/source/designer/measure.cpp +++ b/source/designer/measure.cpp @@ -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 <racks=designer.get_layout()->get_tracks(); + const set <racks = designer.get_layout()->get_tracks(); for(set::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); diff --git a/source/designer/selection.cpp b/source/designer/selection.cpp index 48f5b49..5f71e8b 100644 --- a/source/designer/selection.cpp +++ b/source/designer/selection.cpp @@ -51,16 +51,16 @@ void Selection::select_more() set new_tracks; for(set::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - const vector &links=(*i)->get_links(); + const vector &links = (*i)->get_links(); for(vector::const_iterator j=links.begin(); j!=links.end(); ++j) if(*j) new_tracks.insert(*j); } - bool changed=false; + bool changed = false; for(set::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 queue(tracks.begin(), tracks.end()); while(!queue.empty()) { - Track *track=queue.front(); + Track *track = queue.front(); queue.erase(queue.begin()); - const vector &links=track->get_links(); + const vector &links = track->get_links(); for(vector::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::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - const vector &links=(*i)->get_links(); + const vector &links = (*i)->get_links(); for(vector::const_iterator j=links.begin(); j!=links.end(); ++j) if(*j && tracks.insert(*j).second) - changed=true; + changed = true; } if(changed) diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 83827c1..08e1466 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -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(m[1].str); - screen_h=lexical_cast(m[2].str); + screen_w = lexical_cast(m[1].str); + screen_h = lexical_cast(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 &args=getopt.get_args(); + const vector &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 &sensors=control.get_sensors(); + const map &sensors = control.get_sensors(); for(map::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::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 texs=ui_res.get_list(); + list texs = ui_res.get_list(); for(list::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 &trains=trfc_mgr->get_trains(); - int y=main_panel->get_geometry().y; + const list &trains = trfc_mgr->get_trains(); + int y = main_panel->get_geometry().y; for(list::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 <racks=layout_3d.get_tracks(); + const list <racks = layout_3d.get_tracks(); for(list::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 &trains=trfc_mgr->get_trains(); + const list &trains = trfc_mgr->get_trains(); for(list::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 &endpoints=placing_block->get_endpoints(); - placing_entry=(placing_entry+1)%endpoints.size(); + const vector &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=█ - placing_entry=0; + placing_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 &tracks=layout_3d.get_tracks(); + const list &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::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 &tracks=block.get_tracks(); + const set &tracks = block.get_tracks(); for(set::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 &blocks=trfc_mgr->get_blocks(); + const list &blocks = trfc_mgr->get_blocks(); for(list::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(x-static_cast(screen_w)/2-100)/screen_h)*0.82843; - float yy=(static_cast(y)/screen_h-0.5)*0.82843; - float size=4.0/screen_h*0.82843; + float xx = (static_cast(x-static_cast(screen_w)/2-100)/screen_h)*0.82843; + float yy = (static_cast(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::reg; diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index 9f3bf1a..b470934 100644 --- a/source/engineer/trainpanel.cpp +++ b/source/engineer/trainpanel.cpp @@ -44,21 +44,21 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): GLtk::Button *btn; - const map &funcs=train.get_locomotive().get_type().get_functions(); - unsigned x=10; + const map &funcs = train.get_locomotive().get_type().get_functions(); + unsigned x = 10; for(map::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::iterator i=ind_funcs.find(func); + map::iterator i = ind_funcs.find(func); if(i!=ind_funcs.end()) i->second->set_active(value); } diff --git a/source/engineer/trainproperties.cpp b/source/engineer/trainproperties.cpp index 9eaf8d3..be3ba8d 100644 --- a/source/engineer/trainproperties.cpp +++ b/source/engineer/trainproperties.cpp @@ -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 &locos=engineer.get_catalogue().get_locomotives(); + const map &locos = engineer.get_catalogue().get_locomotives(); for(map::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 &locos=engineer.get_catalogue().get_locomotives(); - map::const_iterator i=locos.begin(); + const map &locos = engineer.get_catalogue().get_locomotives(); + map::const_iterator i = locos.begin(); advance(i, drp_type->get_selected_index()); - train=engineer.add_train(*i->second, lexical_cast(ent_addr->get_text())); + train = engineer.add_train(*i->second, lexical_cast(ent_addr->get_text())); } train->set_name(ent_name->get_text()); diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index ee0a48c..c562788 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -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 &links=track->get_links(); + const vector &links = track->get_links(); for(unsigned i=0; i 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(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::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 &eps=track.get_type().get_endpoints(); + const vector &eps = track.get_type().get_endpoints(); for(unsigned i=0; i::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), diff --git a/source/libmarklin/catalogue.cpp b/source/libmarklin/catalogue.cpp index 1b181df..689ad3b 100644 --- a/source/libmarklin/catalogue.cpp +++ b/source/libmarklin/catalogue.cpp @@ -53,9 +53,9 @@ void Catalogue::Loader::locomotive(unsigned art_nr) if(obj.locos.count(art_nr)) throw Exception("Duplicate locomotive number"); - RefPtr loco=new LocoType(art_nr); + RefPtr 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 trk=new TrackType(art_nr); + RefPtr trk = new TrackType(art_nr); load_sub(*trk); - obj.tracks[art_nr]=trk.release(); + obj.tracks[art_nr] = trk.release(); } } // namespace Marklin diff --git a/source/libmarklin/control.cpp b/source/libmarklin/control.cpp index 3eab42c..6f7ef74 100644 --- a/source/libmarklin/control.cpp +++ b/source/libmarklin/control.cpp @@ -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 "<::const_iterator i=turnouts.find(id); + map::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::const_iterator i=locomotives.find(id); + map::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::const_iterator i=sensors.find(id); + map::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::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: "< trk=new Track(type); + RefPtr trk = new Track(type); load_sub(*trk); obj.add_track(*trk.release()); } diff --git a/source/libmarklin/locomotive.cpp b/source/libmarklin/locomotive.cpp index 32f2ecc..c7d6227 100644 --- a/source/libmarklin/locomotive.cpp +++ b/source/libmarklin/locomotive.cpp @@ -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<>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)&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; } diff --git a/source/libmarklin/locotype.cpp b/source/libmarklin/locotype.cpp index 9eed205..6dcd6ae 100644 --- a/source/libmarklin/locotype.cpp +++ b/source/libmarklin/locotype.cpp @@ -25,7 +25,7 @@ LocoType::Loader::Loader(LocoType <): void LocoType::Loader::function(unsigned i, const string &f) { - obj.funcs[i]=f; + obj.funcs[i] = f; } } // namespace Marklin diff --git a/source/libmarklin/reply.cpp b/source/libmarklin/reply.cpp index ede23cc..5a02df2 100644 --- a/source/libmarklin/reply.cpp +++ b/source/libmarklin/reply.cpp @@ -18,9 +18,9 @@ namespace { unsigned read_all(int fd, char *buf, unsigned size) { - unsigned pos=0; + unsigned pos = 0; while(pos(result.data); + char *data = reinterpret_cast(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(c); + result.err = static_cast(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; diff --git a/source/libmarklin/sensor.cpp b/source/libmarklin/sensor.cpp index 9b9b5f3..28f9548 100644 --- a/source/libmarklin/sensor.cpp +++ b/source/libmarklin/sensor.cpp @@ -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); } } diff --git a/source/libmarklin/track.cpp b/source/libmarklin/track.cpp index 73674ee..01b7893 100644 --- a/source/libmarklin/track.cpp +++ b/source/libmarklin/track.cpp @@ -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 &eps=type.get_endpoints(); + const vector &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 &eps=type.get_endpoints(); + const vector &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 &eps=type.get_endpoints(); - const vector &other_eps=other.get_type().get_endpoints(); + float limit = (link && !flex) ? 1e-6 : 1e-4; + const vector &eps = type.get_endpoints(); + const vector &other_eps = other.get_type().get_endpoints(); for(unsigned i=0; i &eps=type.get_endpoints(); + const vector &eps = type.get_endpoints(); for(unsigned i=0; i::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::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 &eps=type.get_endpoints(); + const vector &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< &eps=type.get_endpoints(); + const vector &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 &parts=type.get_parts(); - const TrackPart *last_part=0; + const vector &parts = type.get_parts(); + const TrackPart *last_part = 0; while(1) { for(vector::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; jlength; + float plen = i->length; if(i->radius) - plen*=abs(i->radius); + plen *= abs(i->radius); if(dget_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 diff --git a/source/libmarklin/trackpart.cpp b/source/libmarklin/trackpart.cpp index da177f8..943832f 100644 --- a/source/libmarklin/trackpart.cpp +++ b/source/libmarklin/trackpart.cpp @@ -28,8 +28,8 @@ void TrackPart::collect_endpoints(vector &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<::const_iterator i=parts.begin(); i!=parts.end(); ++i) if(r<0 || i->route==static_cast(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::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::iterator i=endpoints.begin(); i!=endpoints.end();) { - bool rm=false; + bool rm = false; for(vector::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; } diff --git a/source/libmarklin/trafficmanager.cpp b/source/libmarklin/trafficmanager.cpp index 4075415..069731e 100644 --- a/source/libmarklin/trafficmanager.cpp +++ b/source/libmarklin/trafficmanager.cpp @@ -25,7 +25,7 @@ TrafficManager::TrafficManager(Control &c, Layout &l): control(c), layout(l) { - const set &tracks=layout.get_tracks(); + const set &tracks = layout.get_tracks(); set used_tracks; for(set::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::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) { - const set &tracks=(*i)->get_tracks(); + const set &tracks = (*i)->get_tracks(); if(tracks.count(const_cast(&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::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::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); } diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 7d6afba..341921a 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -36,11 +36,11 @@ Train::Train(TrafficManager &tm, Locomotive &l): { trfc_mgr.add_train(this); - const map &sensors=trfc_mgr.get_control().get_sensors(); + const map &sensors = trfc_mgr.get_control().get_sensors(); for(map::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 &turnouts=trfc_mgr.get_control().get_turnouts(); + const map &turnouts = trfc_mgr.get_control().get_turnouts(); for(map::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(round(speed*speed_scale*87*3.6/5))*5; + travel_speed = static_cast(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::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::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::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 &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(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(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: "<::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::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::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::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::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::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); } diff --git a/source/libmarklin/turnout.cpp b/source/libmarklin/turnout.cpp index 3e6e10d..efa98bb 100644 --- a/source/libmarklin/turnout.cpp +++ b/source/libmarklin/turnout.cpp @@ -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); } }