From: Mikko Rasa Date: Sun, 1 Jun 2008 08:49:18 +0000 (+0000) Subject: Style fixes, including: X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1d735b80482317fd930eb47ca255ab9f1f120a7d;p=r2c2.git Style fixes, including: - Reorder members in class declarations - Get rid of rest of the container typedefs - Convert typecasts to C++ style --- diff --git a/source/3d/layout.cpp b/source/3d/layout.cpp index 18457f0..9c260b9 100644 --- a/source/3d/layout.cpp +++ b/source/3d/layout.cpp @@ -21,44 +21,44 @@ Layout3D::Layout3D(Layout &l): Layout3D::~Layout3D() { - for(Track3DSeq::iterator i=tracks.begin(); i!=tracks.end(); ++i) + for(list::iterator i=tracks.begin(); i!=tracks.end(); ++i) delete *i; } void Layout3D::set_quality(unsigned q) { quality=q; - for(Track3DSeq::iterator i=tracks.begin(); i!=tracks.end(); ++i) + for(list::iterator i=tracks.begin(); i!=tracks.end(); ++i) (*i)->set_quality(quality); } -void Layout3D::render(bool endpoints) +void Layout3D::render(bool endpoints) const { GL::Texture::unbind(); glEnable(GL_DEPTH_TEST); - for(Track3DSeq::iterator i=tracks.begin(); i!=tracks.end(); ++i) + for(list::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) (*i)->render(); if(endpoints) { glDepthMask(false); - for(Track3DSeq::iterator i=tracks.begin(); i!=tracks.end(); ++i) + for(list::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) (*i)->render_endpoints(); glDepthMask(true); } } -Track3D *Layout3D::get_track(const Track *t) +Track3D &Layout3D::get_track(const Track &t) const { - for(Track3DSeq::iterator i=tracks.begin(); i!=tracks.end(); ++i) - if(&(*i)->get_track()==t) - return *i; - - return 0; + for(list::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + if(&(*i)->get_track()==&t) + return **i; + + throw KeyError("Unknown track"); } -Track3D *Layout3D::pick_track(float x, float y, float size) +Track3D *Layout3D::pick_track(float x, float y, float size) const { vector select_buf; GL::select_buffer(select_buf); @@ -120,7 +120,7 @@ void Layout3D::track_added(Track &t) void Layout3D::track_removed(Track &t) { - for(Track3DSeq::iterator i=tracks.begin(); i!=tracks.end(); ++i) + for(list::iterator i=tracks.begin(); i!=tracks.end(); ++i) if(&(*i)->get_track()==&t) { delete *i; diff --git a/source/3d/layout.h b/source/3d/layout.h index 9970604..d469dc9 100644 --- a/source/3d/layout.h +++ b/source/3d/layout.h @@ -8,20 +8,21 @@ namespace Marklin { class Layout3D { +private: + Layout &layout; + std::list tracks; + unsigned quality; + public: Layout3D(Layout &); ~Layout3D(); void set_quality(unsigned); - const Track3DSeq &get_tracks() const { return tracks; } - void render(bool =false); - Track3D *get_track(const Track *); - Track3D *pick_track(float, float, float); + const std::list &get_tracks() const { return tracks; } + void render(bool =false) const; + Track3D &get_track(const Track &) const; + Track3D *pick_track(float, float, float) const; private: - Layout &layout; - Track3DSeq tracks; - unsigned quality; - void track_added(Track &); void track_removed(Track &); }; diff --git a/source/3d/misc.h b/source/3d/misc.h deleted file mode 100644 index 8d77ee2..0000000 --- a/source/3d/misc.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MARKLIN3D_MISC_H_ -#define MARKLIN3D_MISC_H_ - -namespace Marklin { - -struct Color -{ - float r, g, b; - - Color(float r_, float g_, float b_): r(r_), g(g_), b(b_) { } -}; - -} // namespace Marklin - -#endif diff --git a/source/3d/track.cpp b/source/3d/track.cpp index d937084..9d5c5df 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -52,11 +52,11 @@ void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const } } -void Track3D::render() +void Track3D::render() const { prepare_render(); - glPushName((unsigned)this); + glPushName(reinterpret_cast(this)); varray.apply(); glColor4f(0.25*color.r, 0.25*color.g, 0.25*color.b, 1); @@ -71,7 +71,7 @@ void Track3D::render() glPopMatrix(); } -void Track3D::render_endpoints() +void Track3D::render_endpoints() const { prepare_render(); @@ -99,7 +99,7 @@ void Track3D::render_endpoints() glPopMatrix(); } -void Track3D::render_route(int route) +void Track3D::render_route(int route) const { prepare_render(); @@ -115,7 +115,7 @@ void Track3D::render_route(int route) glPopMatrix(); } -void Track3D::prepare_render() +void Track3D::prepare_render() const { const Point &pos=track.get_position(); float rot=track.get_rotation(); @@ -175,7 +175,7 @@ void Track3D::build_part(const TrackPart &part, GL::VertexArrayBuilder &va_build unsigned nsegs; if(radius) { - nsegs=(unsigned)(part.length*(1<(part.length*(1< +#include #include #include #include "libmarklin/track.h" #include "libmarklin/trackpart.h" -#include "misc.h" namespace Marklin { class Track3D { -public: - Track3D(Track &, unsigned); - void set_color(const Color &c) { color=c; } - void set_quality(unsigned); - void get_bounds(float, Point &, Point &) const; - Track &get_track() const { return track; } - void render(); - void render_endpoints(); - void render_route(int); private: Track &track; - Color color; + Msp::GL::Color color; std::vector border; Msp::GL::VertexArray varray; std::vector base_seq; @@ -31,11 +22,21 @@ private: std::vector > route_seq; unsigned quality; - void prepare_render(); +public: + Track3D(Track &, unsigned); + + void set_color(const Msp::GL::Color &c) { color=c; } + void set_quality(unsigned); + void get_bounds(float, Point &, Point &) const; + Track &get_track() const { return track; } + void render() const; + void render_endpoints() const; + void render_route(int) const; +private: + void prepare_render() const; void build_object(); void build_part(const TrackPart &, Msp::GL::VertexArrayBuilder &, unsigned &); }; -typedef std::list Track3DSeq; } // namespace Marklin diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 9edf816..3ca630f 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -63,15 +63,15 @@ Designer::Designer(int argc, char **argv): if(argc>1) { layout->load(argv[1]); - const Track3DSeq <racks=layout_3d->get_tracks(); - for(Track3DSeq::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i) + 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()) - (*i)->set_color(Color(1, 1, 0.5)); + (*i)->set_color(GL::Color(1, 1, 0.5)); else if((*i)->get_track().get_turnout_id()) - (*i)->set_color(Color(0.5, 1, 1)); + (*i)->set_color(GL::Color(0.5, 1, 1)); else if((*i)->get_track().get_flex()) - (*i)->set_color(Color(1, 0.5, 1)); + (*i)->set_color(GL::Color(1, 0.5, 1)); } } @@ -83,6 +83,17 @@ Designer::Designer(int argc, char **argv): measure->signal_done.connect(sigc::mem_fun(this, &Designer::measure_done)); } +Designer::~Designer() +{ + delete manipulator; + delete selection; + delete layout; + delete layout_3d; + delete cat_layout; + delete cat_layout_3d; + delete measure; +} + int Designer::main() { setenv("__GL_SYNC_TO_VBLANK", "1", 0); @@ -132,8 +143,8 @@ void Designer::map_pointer_coords(int x, int y, float &gx, float &gy) float uy=sin_yaw*-sin_pitch*0.41421; float uz=cos_pitch*0.41421; - float xf=(float)x*2/screen_w-1; - float yf=1-(float)y*2/screen_h; + float xf=static_cast(x)*2/screen_w-1; + float yf=1-static_cast(y)*2/screen_h; float vx=cos_yaw*cos_pitch + xf*rx + yf*ux; float vy=sin_yaw*cos_pitch + xf*ry + yf*uy; @@ -148,7 +159,7 @@ void Designer::tick() SDL_Event event; while(SDL_PollEvent(&event)) { - float gx,gy; + float gx, gy; switch(event.type) { case SDL_MOUSEBUTTONDOWN: @@ -256,17 +267,6 @@ void Designer::tick() SDL_GL_SwapBuffers(); } -Designer::~Designer() -{ - delete manipulator; - delete selection; - delete layout; - delete layout_3d; - delete cat_layout; - delete cat_layout_3d; - delete measure; -} - /*** private ***/ void Designer::key_press(unsigned key, unsigned mod, wchar_t ch) @@ -358,11 +358,11 @@ void Designer::key_press(unsigned key, 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(Color(1, 0.5, 1)); + t3d.set_color(GL::Color(1, 0.5, 1)); else - t3d->set_color(Color(1, 1, 1)); + t3d.set_color(GL::Color(1, 1, 1)); } } else if(key==SDLK_f) @@ -536,18 +536,6 @@ void Designer::render() measure->render(); } - /*glBegin(GL_LINES); - glColor4f(1, 0, 0, 1); - glVertex3f(0, 0, 0); - glVertex3f(0.5, 0, 0); - glColor4f(0, 1, 0, 1); - glVertex3f(0, 0, 0); - glVertex3f(0, 0.5, 0); - glColor4f(0, 0, 1, 1); - glVertex3f(0, 0, 0); - glVertex3f(0, 0, 0.5); - glEnd();*/ - glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, screen_w, 0, screen_h, 0, 1); @@ -582,9 +570,9 @@ Track3D *Designer::pick_track(int x, int y) if(mode==CATALOGUE) l=cat_layout_3d; - float xx=((float)(x-(int)screen_w/2)/screen_h)*0.82843; - float yy=((float)y/screen_h-0.5)*0.82843; - float size=(float)4/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(); @@ -621,9 +609,9 @@ void Designer::measure_done() void Designer::move_tooltip(int x, int y) { - int w=(int)(font->get_string_width(tooltip)*20); - tooltip_x=max(min((int)screen_w-w, x), 0); - tooltip_y=max(min((int)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() @@ -639,11 +627,11 @@ void Designer::turnout_id_accept() 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(Color(0.5, 1, 1)); + t3d.set_color(GL::Color(0.5, 1, 1)); else - t3d->set_color(Color(1, 1, 1)); + t3d.set_color(GL::Color(1, 1, 1)); input_dismiss(); } @@ -654,11 +642,11 @@ void Designer::sensor_id_accept() unsigned id=lexical_cast(input->get_text()); track->set_sensor_id(id); - Track3D *t3d=layout_3d->get_track(track); + Track3D &t3d=layout_3d->get_track(*track); if(id) - t3d->set_color(Color(1, 1, 0.5)); + t3d.set_color(GL::Color(1, 1, 0.5)); else - t3d->set_color(Color(1, 1, 1)); + t3d.set_color(GL::Color(1, 1, 1)); input_dismiss(); } diff --git a/source/designer/designer.h b/source/designer/designer.h index 553b25c..c72dd5c 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -17,14 +17,6 @@ class Selection; class Designer: public Msp::Application { -public: - Designer(int, char **); - Marklin::Layout *get_layout() { return layout; } - Marklin::Layout3D *get_layout_3d() { return layout_3d; } - Msp::GL::Font &get_font() { return *font; } - int main(); - void map_pointer_coords(int, int, float &, float &); - ~Designer(); private: enum Mode { @@ -65,6 +57,16 @@ private: Msp::Time::TimeStamp tooltip_timeout; Msp::Time::TimeStamp last_tick; +public: + Designer(int, char **); + ~Designer(); + + Marklin::Layout *get_layout() { return layout; } + Marklin::Layout3D *get_layout_3d() { return layout_3d; } + Msp::GL::Font &get_font() { return *font; } + int main(); + void map_pointer_coords(int, int, float &, float &); +private: void tick(); void key_press(unsigned, unsigned, wchar_t); void key_release(unsigned, unsigned); diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index e7ccead..c07003e 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -379,18 +379,18 @@ 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; for(float a=0; aget_bounds(a, minp, maxp); + Point minp, maxp; + t3d.get_bounds(a, minp, maxp); float area=(maxp.x-minp.x)*(maxp.y-minp.y); if(area signal_status; - sigc::signal signal_done; - - Manipulator(Designer &); - void set_selection(Selection *); - void start_move(); - void start_rotate(); - void start_elevate(); - void duplicate(); - void flatten(); - void even_slope(bool =false); - void cancel(); - void button_press(int, int, float, float, unsigned); - void pointer_motion(int, int, float, float); - void render(); private: enum Mode { @@ -78,6 +62,24 @@ private: std::set neighbors; sigc::connection selection_changed_conn; +public: + sigc::signal signal_status; + sigc::signal signal_done; + + Manipulator(Designer &); + + void set_selection(Selection *); + void start_move(); + void start_rotate(); + void start_elevate(); + void duplicate(); + void flatten(); + void even_slope(bool =false); + void cancel(); + void button_press(int, int, float, float, unsigned); + void pointer_motion(int, int, float, float); + void render(); +private: void selection_changed(); void update_wrap(); void update_neighbors(); diff --git a/source/designer/measure.h b/source/designer/measure.h index d7c7b77..61a5a75 100644 --- a/source/designer/measure.h +++ b/source/designer/measure.h @@ -7,18 +7,6 @@ class Designer; class Measure { -public: - sigc::signal signal_done; - sigc::signal signal_changed; - - Measure(Designer &); - float get_parallel_distance() const { return par_dist; } - float get_perpendicular_distance() const { return perp_dist; } - float get_angle_difference() const { return adiff; } - void start(); - void button_press(int, int, float, float, unsigned); - void pointer_motion(int, int, float, float); - void render(); private: enum State { @@ -36,6 +24,19 @@ private: float adiff; State state; +public: + sigc::signal signal_done; + sigc::signal signal_changed; + + Measure(Designer &); + float get_parallel_distance() const { return par_dist; } + float get_perpendicular_distance() const { return perp_dist; } + float get_angle_difference() const { return adiff; } + void start(); + void button_press(int, int, float, float, unsigned); + void pointer_motion(int, int, float, float); + void render(); +private: void snap_to_tracks(Marklin::Point &, float &); }; diff --git a/source/designer/selection.h b/source/designer/selection.h index 21c5de1..1c0d267 100644 --- a/source/designer/selection.h +++ b/source/designer/selection.h @@ -7,6 +7,9 @@ class Selection { +private: + std::set tracks; + public: sigc::signal signal_changed; @@ -19,8 +22,6 @@ public: void toggle_track(Marklin::Track *); void select_more(); void select_linked(); -private: - std::set tracks; }; #endif diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index d5f8495..3ac7c76 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -113,7 +113,7 @@ Train *Engineer::add_train(unsigned addr) TrainPanel *tpanel=new TrainPanel(*this, ui_res, *train); root->add(*tpanel); int y=main_panel->get_geometry().y; - for(TrainPanelSeq::iterator i=train_panels.begin(); i!=train_panels.end(); ++i) + for(list::iterator i=train_panels.begin(); i!=train_panels.end(); ++i) y-=(*i)->get_geometry().h; tpanel->set_position(0, y-tpanel->get_geometry().h); train_panels.push_back(tpanel); @@ -213,8 +213,8 @@ void Engineer::tick() glDisable(GL_LIGHTING); glColor4f(1, 1, 1, 1); - const Track3DSeq <racks=layout_3d.get_tracks(); - for(Track3DSeq::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i) + const list <racks=layout_3d.get_tracks(); + for(list::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i) { Track &track=(*i)->get_track(); if(track.get_turnout_id()) @@ -286,7 +286,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) { if(btn==1 && placing_block) { - set_block_color(*placing_block, Color(1, 1, 1)); + set_block_color(*placing_block, GL::Color(1, 1, 1)); placing_train->place(placing_block, placing_entry); placing_train=0; @@ -335,10 +335,10 @@ void Engineer::pointer_motion(int x, int y) if(&block!=placing_block) { if(placing_block) - set_block_color(*placing_block, Color(1, 1, 1)); + set_block_color(*placing_block, GL::Color(1, 1, 1)); placing_block=█ placing_entry=0; - set_block_color(*placing_block, Color(0.5, 1, 0.7)); + set_block_color(*placing_block, GL::Color(0.5, 1, 0.7)); } } else if(track && track->get_track().get_turnout_id()) @@ -350,7 +350,7 @@ void Engineer::pointer_motion(int x, int y) void Engineer::view_all() { - const Track3DSeq &tracks=layout_3d.get_tracks(); + const list &tracks=layout_3d.get_tracks(); cam_rot=0; float best_height=-1; @@ -362,9 +362,9 @@ void Engineer::view_all() float max_x=0; float min_y=0; float max_y=0; - for(Track3DSeq::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + for(list::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { - Point minp,maxp; + Point minp, maxp; (*i)->get_bounds(angle, minp, maxp); min_x=min(min_x, minp.x); max_x=max(max_x, maxp.x); @@ -392,11 +392,11 @@ void Engineer::view_all() cam_pos.z=max(best_height*1.05/0.82843, 0.15); } -void Engineer::set_block_color(const Block &block, const Color &color) +void Engineer::set_block_color(const Block &block, const GL::Color &color) { 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); + layout_3d.get_track(**i).set_color(color); } void Engineer::sensor_event(bool state, Sensor *sensor) @@ -407,11 +407,11 @@ void Engineer::sensor_event(bool state, Sensor *sensor) { Block &block=trfc_mgr->get_block_by_track((*i)->get_track()); if(state) - (*i)->set_color(Color(1, 0.5, 0.3)); + (*i)->set_color(GL::Color(1, 0.5, 0.3)); else if(block.get_train()) - set_block_color(block, Color(1, 1, 0.3)); + set_block_color(block, GL::Color(1, 1, 0.3)); else - (*i)->set_color(Color(1, 1, 1)); + (*i)->set_color(GL::Color(1, 1, 1)); } } @@ -425,26 +425,25 @@ void Engineer::block_reserved(const Block &block, const Train *train) } if(train) - set_block_color(block, Color(1, 1, 0.3)); + set_block_color(block, GL::Color(1, 1, 0.3)); else - set_block_color(block, Color(1, 1, 1)); + set_block_color(block, GL::Color(1, 1, 1)); } void Engineer::project_3d() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - //glFrustum(-0.055228, 0.055228, -0.041421, 0.041421, 0.1, 10); - glFrustum(-0.069036, 0.041421, -0.041421, 0.041421, 0.1, 10); + 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=((float)(x-(int)screen_w*5/8)/screen_h)*0.82843; - //float xx=((float)(x-(int)screen_w/2)/screen_h)*0.82843; - float yy=((float)y/screen_h-0.5)*0.82843; - float size=(float)4/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(); diff --git a/source/engineer/engineer.h b/source/engineer/engineer.h index 1575c0c..6131c6f 100644 --- a/source/engineer/engineer.h +++ b/source/engineer/engineer.h @@ -18,17 +18,7 @@ class TrainProperties; class Engineer: public Msp::Application { -public: - Engineer(int argc, char **argv); - ~Engineer(); - - Marklin::Control &get_control() { return control; } - Marklin::Train *add_train(unsigned); - int main(); - void quit() { exit(0); } private: - typedef std::list TrainPanelSeq; - Msp::Graphics::Display *dpy; Msp::Graphics::Window *wnd; Msp::Graphics::GLContext *glc; @@ -44,7 +34,7 @@ private: float cam_rot; Msp::GLtk::Resources ui_res; MainPanel *main_panel; - TrainPanelSeq train_panels; + std::list train_panels; bool no_lighting; Marklin::TrafficManager *trfc_mgr; Marklin::Train *placing_train; @@ -54,13 +44,22 @@ private: TrainProperties *train_prop; bool train_prop_stale; +public: + Engineer(int argc, char **argv); + ~Engineer(); + + Marklin::Control &get_control() { return control; } + Marklin::Train *add_train(unsigned); + int main(); + void quit() { exit(0); } +private: void tick(); void key_press(unsigned, unsigned, wchar_t); void button_press(int, int, unsigned, unsigned); void button_release(int, int, unsigned, unsigned); void pointer_motion(int, int); void view_all(); - void set_block_color(const Marklin::Block &, const Marklin::Color &); + void set_block_color(const Marklin::Block &, const Msp::GL::Color &); void sensor_event(bool, Marklin::Sensor *); void block_reserved(const Marklin::Block &, const Marklin::Train *); void project_3d(); diff --git a/source/engineer/mainpanel.h b/source/engineer/mainpanel.h index 091d970..3e58d12 100644 --- a/source/engineer/mainpanel.h +++ b/source/engineer/mainpanel.h @@ -9,15 +9,17 @@ class Engineer; class MainPanel: public Msp::GLtk::Panel { -public: - MainPanel(Engineer &, Msp::GLtk::Resources &); - void set_status_text(const std::string &); private: Engineer &engineer; Msp::GLtk::Indicator *ind_on; Msp::GLtk::Indicator *ind_off; Msp::GLtk::Label *lbl_status; +public: + MainPanel(Engineer &, Msp::GLtk::Resources &); + + void set_status_text(const std::string &); +private: void power_on(); void power_off(); void new_loc(); diff --git a/source/engineer/trainpanel.h b/source/engineer/trainpanel.h index d21e561..3e44241 100644 --- a/source/engineer/trainpanel.h +++ b/source/engineer/trainpanel.h @@ -10,8 +10,6 @@ class Engineer; class TrainPanel: public Msp::GLtk::Panel { -public: - TrainPanel(Engineer &, const Msp::GLtk::Resources &, Marklin::Train &); private: Engineer &engineer; Marklin::Train &train; @@ -21,6 +19,9 @@ private: Marklin::Locomotive *loco; Msp::GLtk::Label *lbl_speed; +public: + TrainPanel(Engineer &, const Msp::GLtk::Resources &, Marklin::Train &); +private: void speed_slider_changed(double); void loco_speed_changed(unsigned); }; diff --git a/source/engineer/trainproperties.h b/source/engineer/trainproperties.h index b63bc3d..5d24613 100644 --- a/source/engineer/trainproperties.h +++ b/source/engineer/trainproperties.h @@ -9,16 +9,17 @@ class Engineer; class TrainProperties: public Msp::GLtk::Panel { -public: - sigc::signal signal_ok; - - TrainProperties(Engineer &, Msp::GLtk::Resources &, Marklin::Train *); private: Engineer &engineer; Marklin::Train *train; Msp::GLtk::Entry *ent_addr; Msp::GLtk::Entry *ent_name; +public: + sigc::signal signal_ok; + + TrainProperties(Engineer &, Msp::GLtk::Resources &, Marklin::Train *); +private: void ok_clicked(); }; diff --git a/source/libmarklin/block.h b/source/libmarklin/block.h index 186f0f1..0766372 100644 --- a/source/libmarklin/block.h +++ b/source/libmarklin/block.h @@ -33,6 +33,7 @@ private: public: Block(TrafficManager &, Track &); + unsigned get_sensor_id() const { return sensor_id; } const std::set &get_tracks() const { return tracks; } const std::vector &get_endpoints() const { return endpoints; } @@ -48,7 +49,6 @@ private: static unsigned next_id; }; -typedef std::list BlockSeq; } // namespace Marklin diff --git a/source/libmarklin/catalogue.h b/source/libmarklin/catalogue.h index 6277158..66e3466 100644 --- a/source/libmarklin/catalogue.h +++ b/source/libmarklin/catalogue.h @@ -20,6 +20,7 @@ public: void track(unsigned); }; + private: std::map tracks; diff --git a/source/libmarklin/command.cpp b/source/libmarklin/command.cpp new file mode 100644 index 0000000..f953cbd --- /dev/null +++ b/source/libmarklin/command.cpp @@ -0,0 +1,17 @@ +#include "command.h" + +using namespace std; + +namespace Marklin { + +Command::Command(const string &c): + cmd(c), + sent(false) +{ } + +void Command::set_sent(bool s) +{ + sent=s; +} + +} // namespace Marklin diff --git a/source/libmarklin/command.h b/source/libmarklin/command.h index 2106d23..4e4c986 100644 --- a/source/libmarklin/command.h +++ b/source/libmarklin/command.h @@ -9,16 +9,18 @@ namespace Marklin { class Command { +private: + std::string cmd; + bool sent; + public: sigc::signal signal_done; - Command(const std::string &c): cmd(c), sent(false) { } - void set_sent(bool s) { sent=s; } + Command(const std::string &); + + void set_sent(bool); const std::string &get_command() const { return cmd; } bool get_sent() const { return sent; } -private: - std::string cmd; - bool sent; }; } // namespace Marklin diff --git a/source/libmarklin/control.cpp b/source/libmarklin/control.cpp index 6e82614..bd63f9f 100644 --- a/source/libmarklin/control.cpp +++ b/source/libmarklin/control.cpp @@ -21,6 +21,17 @@ Control::Control(): debug(false) { } +Control::~Control() +{ + for(map::iterator i=sensors.begin(); i!=sensors.end(); ++i) + delete i->second; + for(map::iterator i=turnouts.begin(); i!=turnouts.end(); ++i) + delete i->second; + for(map::iterator i=locomotives.begin(); i!=locomotives.end(); ++i) + delete i->second; + close(serial_fd); +} + void Control::set_power(bool p) { power=p; @@ -30,6 +41,11 @@ void Control::set_power(bool p) command(string(1, CMD_POWER_OFF)); } +void Control::set_debug(bool d) +{ + debug=d; +} + void Control::open(const string &dev) { serial_fd=::open(dev.c_str(), O_RDWR); @@ -158,28 +174,28 @@ void Control::tick() poll_sensors=false; } - if(queue.size() && queue.front().get_sent()) + if(!queue.empty() && queue.front().get_sent()) { pollfd pfd={serial_fd, POLLIN, 0}; if(poll(&pfd, 1, 0)>0) { - string resp=read_reply((Cmd)(unsigned char)queue.front().get_command()[0]); + string resp=read_reply(static_cast(static_cast(queue.front().get_command()[0]))); if(debug) { printf("read: "); for(unsigned i=0; i(resp[i])); printf("(%d bytes)\n", resp.size()); } - queue.front().signal_done.emit((Error)resp[0], resp.substr(1)); + queue.front().signal_done.emit(static_cast(resp[0]), resp.substr(1)); queue.erase(queue.begin()); } else return; } - if(queue.size()) + if(!queue.empty()) { string cmd=queue.front().get_command(); @@ -195,8 +211,8 @@ void Control::tick() { printf("write: "); for(unsigned i=0; i(cmd[i])); + printf("(%d bytes)\n", cmd.size()); } write(serial_fd, cmd.data(), cmd.size()); @@ -209,19 +225,6 @@ Time::Timer::Slot &Control::set_timer(const Time::TimeDelta &dt) return timer.add(dt); } -Control::~Control() -{ - for(map::iterator i=sensors.begin(); i!=sensors.end(); ++i) - delete i->second; - for(map::iterator i=turnouts.begin(); i!=turnouts.end(); ++i) - delete i->second; - for(map::iterator i=locomotives.begin(); i!=locomotives.end(); ++i) - delete i->second; - close(serial_fd); -} - -/*** private ***/ - void Control::read_all(int fd, char *buf, int size) { int pos=0; @@ -315,7 +318,7 @@ void Control::turnout_event_done(Error, const string &resp) unsigned count=resp[0]; for(unsigned i=0; i(resp[i*2+1])+((resp[i*2+2]&7)<<8); bool status=!(resp[i*2+2]&0x80); cout<<"Turnout "<(resp[i]); cout<<"S88 module "< signal_sensor_event; Control(); + ~Control(); + void set_power(bool); bool get_power() const { return power; } - void set_debug(bool d) { debug=d; } - //const TurnoutMap &get_turnouts() const { return turnouts; } + void set_debug(bool); const std::map &get_sensors() const { return sensors; } unsigned get_queue_length() const { return queue.size(); } void open(const std::string &); Command &command(const std::string &); + void add_turnout(Turnout &); Turnout &get_turnout(unsigned) const; void add_locomotive(Locomotive &); Locomotive &get_locomotive(unsigned) const; void add_sensor(Sensor &); Sensor &get_sensor(unsigned) const; + void tick(); Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &); - ~Control(); private: void read_all(int, char *, int); std::string read_reply(Cmd); diff --git a/source/libmarklin/geometry.h b/source/libmarklin/geometry.h index 9dee86e..4b0afc2 100644 --- a/source/libmarklin/geometry.h +++ b/source/libmarklin/geometry.h @@ -7,7 +7,7 @@ namespace Marklin { struct Point { - float x,y,z; + float x, y, z; Point(): x(0), y(0), z(0) { } Point(float x_, float y_, float z_): x(x_), y(y_), z(z_) { } diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index 28d2eeb..a197b35 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -14,6 +14,12 @@ Layout::Layout(Catalogue &c): catalogue(c) { } +Layout::~Layout() +{ + for(set::iterator i=tracks.begin(); i!=tracks.end(); ++i) + delete *i; +} + void Layout::add_track(Track &t) { if(tracks.insert(&t).second) @@ -63,7 +69,7 @@ int Layout::save(const string &fn) filename=fn; - if(base.size()) + if(!base.empty()) out<<"base \""<::iterator i=tracks.begin(); i!=tracks.end(); ++i) { @@ -90,15 +96,6 @@ int Layout::save(const string &fn) return 0; } -Layout::~Layout() -{ - for(set::iterator i=tracks.begin(); i!=tracks.end(); ++i) - delete *i; -} - -/******************* -** Layout::Loader -*/ Layout::Loader::Loader(Layout &l): layout(l) diff --git a/source/libmarklin/layout.h b/source/libmarklin/layout.h index d1844de..d984e10 100644 --- a/source/libmarklin/layout.h +++ b/source/libmarklin/layout.h @@ -24,23 +24,26 @@ public: void track(unsigned); }; +private: + Catalogue &catalogue; + std::string filename; + std::string base; + std::set tracks; + //RouteSeq routes; + +public: sigc::signal signal_track_added; sigc::signal signal_track_removed; Layout(Catalogue &); + ~Layout(); + const std::set &get_tracks() const { return tracks; } void add_track(Track &); void remove_track(Track &); void check_links(); void load(const std::string &); int save(const std::string &); - ~Layout(); -private: - Catalogue &catalogue; - std::string filename; - std::string base; - std::set tracks; - //RouteSeq routes; }; } // namespace Marklin diff --git a/source/libmarklin/locomotive.cpp b/source/libmarklin/locomotive.cpp index fe236a5..0de0110 100644 --- a/source/libmarklin/locomotive.cpp +++ b/source/libmarklin/locomotive.cpp @@ -90,17 +90,17 @@ void Locomotive::send_command(bool setf) if((funcs>>i)&2) cmd[4]|=(1<(reply[0])<=1) speed=0; else - speed=(unsigned char)reply[0]*2/19+1; + speed=static_cast(reply[0])*2/19+1; reverse=(reply[1]&0x20)?false:true; funcs=(reply[1]&0xF)<<1; if(reply[1]&0x10) diff --git a/source/libmarklin/locomotive.h b/source/libmarklin/locomotive.h index 4188df5..eae99f5 100644 --- a/source/libmarklin/locomotive.h +++ b/source/libmarklin/locomotive.h @@ -12,10 +12,18 @@ class Control; class Locomotive { +private: + Control &control; + unsigned addr; + unsigned speed; + bool reverse; + unsigned funcs; + public: sigc::signal signal_speed_changed; Locomotive(Control &, unsigned); + void set_speed(unsigned); void set_reverse(bool); void set_function(unsigned, bool); @@ -25,12 +33,6 @@ public: bool get_function(unsigned f) const { return (funcs>>f)&1; } void refresh_status(); private: - Control &control; - unsigned addr; - unsigned speed; - bool reverse; - unsigned funcs; - void send_command(bool); void status_reply(Error, const std::string &); bool reverse_timeout(); diff --git a/source/libmarklin/route.h b/source/libmarklin/route.h index 3fa8202..6d2d710 100644 --- a/source/libmarklin/route.h +++ b/source/libmarklin/route.h @@ -14,8 +14,6 @@ class Turnout; class Route { public: - typedef std::map TurnoutMap; - Route(); const std::map &get_turnouts() const { return turnouts; } void add_track(Track *); diff --git a/source/libmarklin/sensor.h b/source/libmarklin/sensor.h index d3db636..9dbb23c 100644 --- a/source/libmarklin/sensor.h +++ b/source/libmarklin/sensor.h @@ -12,19 +12,21 @@ class Control; class Sensor { +private: + Control &control; + unsigned addr; + bool state; + Msp::Time::TimeStamp off_timeout; + public: sigc::signal signal_state_changed; Sensor(Control &, unsigned); + unsigned get_address() const { return addr; } bool get_state() const { return state; } void tick(); private: - Control &control; - unsigned addr; - bool state; - Msp::Time::TimeStamp off_timeout; - void sensor_event(unsigned, bool); }; diff --git a/source/libmarklin/trackpart.h b/source/libmarklin/trackpart.h index 092e586..043dd0d 100644 --- a/source/libmarklin/trackpart.h +++ b/source/libmarklin/trackpart.h @@ -30,6 +30,7 @@ struct TrackPart bool dead_end; TrackPart(); + void collect_endpoints(std::vector &); }; diff --git a/source/libmarklin/trafficmanager.cpp b/source/libmarklin/trafficmanager.cpp index 096d675..543c34a 100644 --- a/source/libmarklin/trafficmanager.cpp +++ b/source/libmarklin/trafficmanager.cpp @@ -31,9 +31,9 @@ TrafficManager::TrafficManager(Control &c, Layout &l): } } - for(BlockSeq::iterator i=blocks.begin(); i!=blocks.end(); ++i) + for(list::iterator i=blocks.begin(); i!=blocks.end(); ++i) { - for(BlockSeq::iterator j=i; j!=blocks.end(); ++j) + for(list::iterator j=i; j!=blocks.end(); ++j) if(j!=i) (*i)->check_link(**j); (*i)->print_debug(); @@ -42,15 +42,15 @@ TrafficManager::TrafficManager(Control &c, Layout &l): TrafficManager::~TrafficManager() { - for(BlockSeq::iterator i=blocks.begin(); i!=blocks.end(); ++i) + for(list::iterator i=blocks.begin(); i!=blocks.end(); ++i) delete *i; - for(TrainSeq::iterator i=trains.begin(); i!=trains.end(); ++i) + for(list::iterator i=trains.begin(); i!=trains.end(); ++i) delete *i; } Block &TrafficManager::get_block_by_track(const Track &t) const { - for(BlockSeq::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) + for(list::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) { const set &tracks=(*i)->get_tracks(); if(tracks.count(const_cast(&t))) diff --git a/source/libmarklin/trafficmanager.h b/source/libmarklin/trafficmanager.h index 2707e09..2ef4bc9 100644 --- a/source/libmarklin/trafficmanager.h +++ b/source/libmarklin/trafficmanager.h @@ -12,6 +12,12 @@ class Turnout; class TrafficManager { +private: + Control &control; + Layout &layout; + std::list blocks; + std::list trains; + public: sigc::signal signal_block_reserved; @@ -20,15 +26,10 @@ public: Control &get_control() const { return control; } Block &get_block_by_track(const Track &) const; - const TrainSeq &get_trains() const { return trains; } + const std::list &get_trains() const { return trains; } void add_train(Train *); void tick(); private: - Control &control; - Layout &layout; - std::list blocks; - std::list trains; - void turnout_route_changed(unsigned, Turnout *); }; diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index c424481..1644802 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -128,7 +128,7 @@ void Train::sensor_event(bool state, Sensor *sensor) ++i; for(list::iterator j=cur_blocks.begin(); j!=i; ++j) j->block->reserve(0); - cout<<" "<block->traverse(last->entry); if(exit>=0) diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 1172112..815a9e9 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -35,6 +35,7 @@ public: sigc::signal signal_name_changed; Train(TrafficManager &, Locomotive &); + void set_name(const std::string &); void set_speed(unsigned); const std::string &get_name() const { return name; } @@ -46,7 +47,6 @@ private: void sensor_event(bool, Sensor *); bool reserve_more(); }; -typedef std::list TrainSeq; } // namespace Marklin diff --git a/source/libmarklin/turnout.cpp b/source/libmarklin/turnout.cpp index a6e3f2d..6f90d47 100644 --- a/source/libmarklin/turnout.cpp +++ b/source/libmarklin/turnout.cpp @@ -23,7 +23,7 @@ Turnout::Turnout(Control &c, unsigned a): cmd[0]=CMD_TURNOUT_STATUS; cmd[1]=addr&0xFF; cmd[2]=(addr>>8)&0xFF; - control.command(string(cmd,3)).signal_done.connect(sigc::mem_fun(this, &Turnout::status_reply)); + control.command(string(cmd, 3)).signal_done.connect(sigc::mem_fun(this, &Turnout::status_reply)); } void Turnout::set_route(unsigned r) @@ -46,7 +46,7 @@ void Turnout::command(bool on) cmd[2]|=0x40; if(route==0) cmd[2]|=0x80; - control.command(string(cmd,3)); + control.command(string(cmd, 3)); } void Turnout::status_reply(Error err, const string &reply) diff --git a/source/libmarklin/turnout.h b/source/libmarklin/turnout.h index 801772b..dbb689e 100644 --- a/source/libmarklin/turnout.h +++ b/source/libmarklin/turnout.h @@ -13,18 +13,20 @@ class Control; class Turnout { +private: + Control &control; + unsigned addr; + unsigned route; + public: sigc::signal signal_route_changed; Turnout(Control &, unsigned); + void set_route(unsigned); unsigned get_address() const { return addr; } unsigned get_route() const { return route; } private: - Control &control; - unsigned addr; - unsigned route; - void command(bool); void status_reply(Error, const std::string &); bool switch_timeout(); diff --git a/source/shoppinglist/main.cpp b/source/shoppinglist/main.cpp index 5f88780..7a4f3ba 100644 --- a/source/shoppinglist/main.cpp +++ b/source/shoppinglist/main.cpp @@ -33,10 +33,8 @@ private: void track(unsigned); }; - typedef map TrackMap; - - TrackMap inventory; - TrackMap layout; + map inventory; + map layout; void load_inventory(const string &); void load_layout(const string &); @@ -79,9 +77,9 @@ void ShoppingList::load_layout(const string &fn) void ShoppingList::print(ostream &out) { out<<"// Need to get:\n"; - for(TrackMap::iterator i=layout.begin(); i!=layout.end(); ++i) + for(map::iterator i=layout.begin(); i!=layout.end(); ++i) { - TrackMap::iterator j=inventory.find(i->first); + map::iterator j=inventory.find(i->first); if(j!=inventory.end()) { if(j->secondsecond) @@ -92,17 +90,17 @@ void ShoppingList::print(ostream &out) } out<<"// Pre-existing:\n"; - for(TrackMap::iterator i=layout.begin(); i!=layout.end(); ++i) + for(map::iterator i=layout.begin(); i!=layout.end(); ++i) { - TrackMap::iterator j=inventory.find(i->first); + map::iterator j=inventory.find(i->first); if(j!=inventory.end()) out<<"track "<first<<' '<second,j->second)<<";\n"; } out<<"// Unused:\n"; - for(TrackMap::iterator i=inventory.begin(); i!=inventory.end(); ++i) + for(map::iterator i=inventory.begin(); i!=inventory.end(); ++i) { - TrackMap::iterator j=layout.find(i->first); + map::iterator j=layout.find(i->first); if(j!=layout.end()) { if(j->secondsecond)