From: Mikko Rasa Date: Sat, 23 May 2009 07:11:51 +0000 (+0000) Subject: Code reformatting: X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=449fb5de95ddb2ac9da4bd72a1c12150505d5549;p=r2c2.git Code reformatting: - Remove alignment from variable and function declarations - Reorder and group class members --- diff --git a/source/3d/layout.h b/source/3d/layout.h index c2faa46..208ddac 100644 --- a/source/3d/layout.h +++ b/source/3d/layout.h @@ -16,9 +16,9 @@ namespace Marklin { class Layout3D { private: - Layout &layout; + Layout &layout; std::list tracks; - unsigned quality; + unsigned quality; public: Layout3D(Layout &); @@ -26,7 +26,7 @@ public: void set_quality(unsigned); const std::list &get_tracks() const { return tracks; } - void render(bool =false) const; + void render(bool =false) const; Track3D &get_track(const Track &) const; Track3D *pick_track(float, float, float) const; private: diff --git a/source/3d/track.cpp b/source/3d/track.cpp index 5857e52..f9b03ed 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -25,6 +25,11 @@ Track3D::Track3D(Track &t, unsigned q): build_object(); } +void Track3D::set_color(const Msp::GL::Color &c) +{ + color=c; +} + void Track3D::set_quality(unsigned q) { quality=q; diff --git a/source/3d/track.h b/source/3d/track.h index 7131877..660d1cf 100644 --- a/source/3d/track.h +++ b/source/3d/track.h @@ -20,7 +20,7 @@ namespace Marklin { class Track3D { private: - Track &track; + Track &track; Msp::GL::Color color; std::vector border; Msp::GL::VertexArray varray; @@ -32,10 +32,10 @@ private: public: Track3D(Track &, unsigned); - void set_color(const Msp::GL::Color &c) { color=c; } + Track &get_track() const { return track; } + void set_color(const Msp::GL::Color &); 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; diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index f2c6fb8..c1bbc3f 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -30,12 +30,14 @@ using namespace std; using namespace Marklin; using namespace Msp; +Application::RegApp Designer::reg; + Designer::Designer(int argc, char **argv): screen_w(1280), screen_h(960), base_mesh(0), - input(0), mode(SELECT), + input(0), cam_yaw(M_PI/2), cam_pitch(-M_PI/4), cam_pos(0, -0.5, 0.5), @@ -691,5 +693,3 @@ void Designer::input_dismiss() input=0; mode=SELECT; } - -Application::RegApp Designer::reg; diff --git a/source/designer/designer.h b/source/designer/designer.h index 598c1ae..8dbc9d4 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -41,46 +41,54 @@ private: Msp::Graphics::Display *dpy; Msp::Graphics::Window *wnd; Msp::Graphics::GLContext *glc; - unsigned screen_w; - unsigned screen_h; - Msp::GL::Font *font; + unsigned screen_w; + unsigned screen_h; + Msp::GL::Font *font; + Marklin::Catalogue catalogue; - Marklin::Layout *layout; - Marklin::Layout3D *layout_3d; - Marklin::Layout *cat_layout; - Marklin::Layout3D *cat_layout_3d; - Msp::GL::Mesh *base_mesh; - Selection *selection; - Manipulator *manipulator; - Measure *measure; - Input *input; - Mode mode; - float cam_yaw; - float cam_pitch; + Marklin::Layout *layout; + Marklin::Layout3D *layout_3d; + Marklin::Layout *cat_layout; + Marklin::Layout3D *cat_layout_3d; + Msp::GL::Mesh *base_mesh; + + Mode mode; + Selection *selection; + Manipulator *manipulator; + Measure *measure; + Input *input; + + float cam_yaw; + float cam_pitch; Marklin::Point cam_pos; - bool shift; - int move_x; - int move_y; - int zoom; - int rotate; - int pitch; - int pointer_x; - int pointer_y; - int tooltip_x; - int tooltip_y; - std::string tooltip; + + bool shift; + int move_x; + int move_y; + int zoom; + int rotate; + int pitch; + int pointer_x; + int pointer_y; + + int tooltip_x; + int tooltip_y; + std::string tooltip; Msp::Time::TimeStamp tooltip_timeout; + Msp::Time::TimeStamp last_tick; + static Msp::Application::RegApp reg; + 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 &); + 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); @@ -100,8 +108,6 @@ private: void turnout_id_accept(); void sensor_id_accept(); void input_dismiss(); - - static Msp::Application::RegApp reg; }; #endif diff --git a/source/designer/input.h b/source/designer/input.h index 3449e2b..9a4dbcc 100644 --- a/source/designer/input.h +++ b/source/designer/input.h @@ -19,15 +19,17 @@ public: sigc::signal signal_accept; sigc::signal signal_cancel; - Input(Designer &, const std::string &, const std::string & =""); - const std::string &get_text() { return text; } - void key_press(unsigned, unsigned, wchar_t); - void render(); private: - Designer &designer; + Designer &designer; std::string title; std::string text; - unsigned pos; + unsigned pos; + +public: + Input(Designer &, const std::string &, const std::string & =std::string()); + const std::string &get_text() { return text; } + void key_press(unsigned, unsigned, wchar_t); + void render(); }; #endif diff --git a/source/designer/manipulator.h b/source/designer/manipulator.h index b482251..9177f97 100644 --- a/source/designer/manipulator.h +++ b/source/designer/manipulator.h @@ -50,8 +50,13 @@ private: float height; }; - Designer &designer; - Selection *selection; +public: + sigc::signal signal_status; + sigc::signal signal_done; + +private: + Designer &designer; + Selection *selection; std::vector tracks; Marklin::Point center; @@ -60,19 +65,16 @@ private: float wrap_rot; Marklin::Point gpointer; - int pointer_y; - Mode mode; + int pointer_y; + Mode mode; Marklin::Point move_origin; - float angle; - float rot_origin; - int elev_origin; + float angle; + float rot_origin; + int elev_origin; std::set neighbors; sigc::connection selection_changed_conn; public: - sigc::signal signal_status; - sigc::signal signal_done; - Manipulator(Designer &); void set_selection(Selection *); diff --git a/source/designer/measure.h b/source/designer/measure.h index e4f230f..f68178d 100644 --- a/source/designer/measure.h +++ b/source/designer/measure.h @@ -22,6 +22,11 @@ private: ACTIVE }; +public: + sigc::signal signal_done; + sigc::signal signal_changed; + +private: Designer &designer; Marklin::Point pointer; Marklin::Point spoint; @@ -32,13 +37,10 @@ private: State state; public: - sigc::signal signal_done; - sigc::signal signal_changed; - Measure(Designer &); - float get_parallel_distance() const { return par_dist; } + float get_parallel_distance() const { return par_dist; } float get_perpendicular_distance() const { return perp_dist; } - float get_angle_difference() const { return adiff; } + float get_angle_difference() const { return adiff; } void start(); void button_press(int, int, float, float, unsigned); void pointer_motion(int, int, float, float); diff --git a/source/designer/selection.h b/source/designer/selection.h index 802c6f2..abae683 100644 --- a/source/designer/selection.h +++ b/source/designer/selection.h @@ -14,12 +14,13 @@ Distributed under the GPL class Selection { +public: + sigc::signal signal_changed; + private: std::set tracks; public: - sigc::signal signal_changed; - const std::set &get_tracks() const { return tracks; } Marklin::Track *get_track() const; unsigned size() const { return tracks.size(); } diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 4b8ba70..83827c1 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -37,16 +37,16 @@ Engineer::Engineer(int argc, char **argv): fullscreen(false), layout(catalogue), layout_3d(layout), - no_lighting(false), + train_prop(0), + train_prop_stale(false), placing_train(0), placing_block(0), placing_entry(0), - simulate(false), - train_prop(0), - train_prop_stale(false) + no_lighting(false), + simulate(false) { string res; - bool debug=false; + bool debug=false; string device="/dev/ttyS0"; unsigned quality=4; @@ -267,13 +267,13 @@ void Engineer::tick() GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2)); imm.color(1.0f, 1.0f, 1.0f); imm.begin(GL::TRIANGLE_FAN); - imm.vertex(0.08, 0); - imm.vertex(0.05, 0.03); - imm.vertex(0.05, 0.01); - imm.vertex(0, 0.01); - imm.vertex(0, -0.01); - imm.vertex(0.05, -0.01); - imm.vertex(0.05, -0.03); + imm.vertex(0.08, 0); + imm.vertex(0.05, 0.03); + imm.vertex(0.05, 0.01); + imm.vertex(0, 0.01); + imm.vertex(0, -0.01); + imm.vertex(0.05, -0.01); + imm.vertex(0.05, -0.03); imm.end(); GL::pop_matrix(); diff --git a/source/engineer/engineer.h b/source/engineer/engineer.h index 0c295bf..ad4bbcc 100644 --- a/source/engineer/engineer.h +++ b/source/engineer/engineer.h @@ -27,42 +27,46 @@ class TrainProperties; class Engineer: public Msp::Application { private: - Msp::Graphics::Display *dpy; - Msp::Graphics::Window *wnd; + Msp::Graphics::Display *dpy; + Msp::Graphics::Window *wnd; Msp::Graphics::GLContext *glc; - Msp::GLtk::Root *root; - unsigned screen_w; - unsigned screen_h; - bool fullscreen; - Marklin::Catalogue catalogue; - Marklin::Layout layout; - Marklin::Layout3D layout_3d; - Marklin::Control control; - Marklin::Point cam_pos; - float cam_rot; + unsigned screen_w; + unsigned screen_h; + bool fullscreen; Msp::GLtk::Resources ui_res; - MainPanel *main_panel; - std::list train_panels; - bool no_lighting; + Msp::GLtk::Root *root; + + Marklin::Catalogue catalogue; + Marklin::Layout layout; + Marklin::Layout3D layout_3d; + Marklin::Control control; Marklin::TrafficManager *trfc_mgr; - Marklin::Train *placing_train; - Marklin::Block *placing_block; - unsigned placing_entry; - bool simulate; - TrainProperties *train_prop; - bool train_prop_stale; + + Marklin::Point cam_pos; + float cam_rot; + + MainPanel *main_panel; + std::list train_panels; + TrainProperties *train_prop; + bool train_prop_stale; + Marklin::Train *placing_train; + Marklin::Block *placing_block; + unsigned placing_entry; + + bool no_lighting; + bool simulate; public: Engineer(int argc, char **argv); ~Engineer(); const Marklin::Catalogue &get_catalogue() const { return catalogue; } - Marklin::Control &get_control() { return control; } - void add_train(); - Marklin::Train *add_train(const Marklin::LocoType &, unsigned); - void place_train(Marklin::Train &); - int main(); - void quit() { exit(0); } + Marklin::Control &get_control() { return control; } + void add_train(); + Marklin::Train *add_train(const Marklin::LocoType &, unsigned); + void place_train(Marklin::Train &); + int main(); + void quit() { exit(0); } private: void tick(); void key_press(unsigned, unsigned, wchar_t); diff --git a/source/engineer/trainproperties.h b/source/engineer/trainproperties.h index 62dc85a..0171cf5 100644 --- a/source/engineer/trainproperties.h +++ b/source/engineer/trainproperties.h @@ -17,6 +17,9 @@ class Engineer; class TrainProperties: public Msp::GLtk::Panel { +public: + sigc::signal signal_ok; + private: Engineer &engineer; Marklin::Train *train; @@ -25,8 +28,6 @@ private: 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 68c57b8..770a352 100644 --- a/source/libmarklin/block.h +++ b/source/libmarklin/block.h @@ -22,9 +22,9 @@ class Block public: struct Endpoint { - Track *track; + Track *track; unsigned track_ep; - Block *link; + Block *link; unsigned routes; Endpoint(Track *, unsigned); @@ -32,12 +32,12 @@ public: private: TrafficManager &trfc_mgr; - unsigned id; - unsigned sensor_id; - unsigned turnout_id; - std::set tracks; + unsigned id; + unsigned sensor_id; + unsigned turnout_id; + std::set tracks; std::vector endpoints; - const Train *train; + const Train *train; public: Block(TrafficManager &, Track &); diff --git a/source/libmarklin/command.h b/source/libmarklin/command.h index a270be0..e6123c3 100644 --- a/source/libmarklin/command.h +++ b/source/libmarklin/command.h @@ -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 */ @@ -19,6 +19,9 @@ class Reply; class Command { +public: + sigc::signal signal_done; + private: Cmd cmd; unsigned char data[128]; @@ -26,12 +29,10 @@ private: bool sent; public: - sigc::signal signal_done; - Command(Cmd, const unsigned char *, unsigned); void send(int); - bool get_sent() const { return sent; } + bool is_sent() const { return sent; } Cmd get_command() const { return cmd; } friend std::ostream &operator<<(std::ostream &, const Command &); diff --git a/source/libmarklin/control.cpp b/source/libmarklin/control.cpp index 6c6ceb3..3eab42c 100644 --- a/source/libmarklin/control.cpp +++ b/source/libmarklin/control.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 */ @@ -39,22 +39,6 @@ Control::~Control() close(serial_fd); } -void Control::set_power(bool p) -{ - power=p; - if(power) - command(CMD_POWER_ON); - else - command(CMD_POWER_OFF); - - signal_power_event.emit(power); -} - -void Control::set_debug(bool d) -{ - debug=d; -} - void Control::open(const string &dev) { serial_fd=::open(dev.c_str(), O_RDWR); @@ -104,6 +88,22 @@ void Control::open(const string &dev) command(CMD_STATUS).signal_done.connect(sigc::mem_fun(this, &Control::status_done)); } +void Control::set_debug(bool d) +{ + debug=d; +} + +void Control::set_power(bool p) +{ + power=p; + if(power) + command(CMD_POWER_ON); + else + command(CMD_POWER_OFF); + + signal_power_event.emit(power); +} + Command &Control::command(Cmd cmd) { queue.push_back(Command(cmd, 0, 0)); @@ -191,7 +191,7 @@ void Control::tick() poll_sensors=false; } - if(!queue.empty() && queue.front().get_sent()) + if(!queue.empty() && queue.front().is_sent()) { pollfd pfd={serial_fd, POLLIN, 0}; if(poll(&pfd, 1, 0)>0) @@ -221,16 +221,6 @@ Time::Timer::Slot &Control::set_timer(const Time::TimeDelta &dt) return timer.add(dt); } -void Control::read_all(int fd, char *buf, int size) -{ - int pos=0; - while(pos signal_power_event; + sigc::signal signal_turnout_event; + sigc::signal signal_sensor_event; + private: - int serial_fd; + int serial_fd; bool power; std::list queue; std::map turnouts; @@ -37,36 +42,30 @@ private: Msp::Time::Timer timer; public: - sigc::signal signal_power_event; - sigc::signal signal_turnout_event; - sigc::signal signal_sensor_event; - Control(); ~Control(); - void set_power(bool); - bool get_power() const { return power; } - void set_debug(bool); - const std::map &get_turnouts() const { return turnouts; } - const std::map &get_sensors() const { return sensors; } - unsigned get_queue_length() const { return queue.size(); } - void open(const std::string &); - Command &command(Cmd); - Command &command(Cmd, unsigned char); - Command &command(Cmd, const unsigned char *, unsigned); + void open(const std::string &); + void set_debug(bool); + void set_power(bool); + bool get_power() const { return power; } + Command &command(Cmd); + Command &command(Cmd, unsigned char); + Command &command(Cmd, const unsigned char *, unsigned); + unsigned get_queue_length() const { return queue.size(); } - void add_turnout(Turnout &); - Turnout &get_turnout(unsigned) const; - void add_locomotive(Locomotive &); + void add_turnout(Turnout &); + Turnout &get_turnout(unsigned) const; + const std::map &get_turnouts() const { return turnouts; } + void add_locomotive(Locomotive &); Locomotive &get_locomotive(unsigned) const; - void add_sensor(Sensor &); - Sensor &get_sensor(unsigned) const; + void add_sensor(Sensor &); + Sensor &get_sensor(unsigned) const; + const std::map &get_sensors() const { return sensors; } - void tick(); + void tick(); Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &); private: - void read_all(int, char *, int); - std::string read_reply(Cmd); void status_done(const Reply &); void event_query_done(const Reply &); void turnout_event_done(const Reply &); diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index 50eba62..8cfb95f 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -79,36 +79,6 @@ void Layout::save(const string &fn) (*i)->save(st.sub); writer.write(st); } - /*ofstream out(fn.c_str()); - if(!out) return -1; - - filename=fn; - - if(!base.empty()) - out<<"base \""<::iterator i=tracks.begin(); i!=tracks.end(); ++i) - { - out<<"track "<<(*i)->get_type().get_article_number()<<"\n{\n"; - const Point &p=(*i)->get_position(); - out<<"\tposition "<get_rotation()<<";\n"; - out<<"\tslope "<<(*i)->get_slope()<<";\n"; - - unsigned id=(*i)->get_turnout_id(); - if(id) - out<<"\tturnout_id "<get_sensor_id(); - if(id) - out<<"\tsensor_id "<get_flex()) - out<<"\tflex true;\n"; - - out<<"};\n"; - } - - return 0;*/ } diff --git a/source/libmarklin/layout.h b/source/libmarklin/layout.h index f603d39..dd13925 100644 --- a/source/libmarklin/layout.h +++ b/source/libmarklin/layout.h @@ -29,26 +29,27 @@ public: void track(unsigned); }; +public: + sigc::signal signal_track_added; + sigc::signal signal_track_removed; + private: const Catalogue &catalogue; std::string base; std::set tracks; - //RouteSeq routes; + //std::set routes; public: - sigc::signal signal_track_added; - sigc::signal signal_track_removed; - Layout(const Catalogue &); ~Layout(); const Catalogue &get_catalogue() const { return catalogue; } const std::string &get_base() const { return base; } const std::set &get_tracks() const { return tracks; } - void add_track(Track &); - void remove_track(Track &); - void check_links(); - void save(const std::string &); + void add_track(Track &); + void remove_track(Track &); + void check_links(); + void save(const std::string &); }; } // namespace Marklin diff --git a/source/libmarklin/locomotive.h b/source/libmarklin/locomotive.h index 89b275e..9ebccda 100644 --- a/source/libmarklin/locomotive.h +++ b/source/libmarklin/locomotive.h @@ -21,34 +21,35 @@ class Reply; class Locomotive { +public: + sigc::signal signal_speed_changing; + sigc::signal signal_speed_changed; + sigc::signal signal_function_changed; + private: const LocoType &type; - Control &control; + Control &control; unsigned addr; unsigned speed; - bool reverse; + bool reverse; unsigned funcs; public: - sigc::signal signal_speed_changing; - sigc::signal signal_speed_changed; - sigc::signal signal_function_changed; - Locomotive(const LocoType &, Control &, unsigned); const LocoType &get_type() const { return type; } - void set_speed(unsigned); - void set_reverse(bool); - void set_function(unsigned, bool); - unsigned get_address() const { return addr; } - unsigned get_speed() const { return speed; } - bool get_reverse() const { return reverse; } - bool get_function(unsigned f) const { return (funcs>>f)&1; } - void refresh_status(); + unsigned get_address() const { return addr; } + void set_speed(unsigned); + void set_reverse(bool); + void set_function(unsigned, bool); + unsigned get_speed() const { return speed; } + bool get_reverse() const { return reverse; } + bool get_function(unsigned f) const { return (funcs>>f)&1; } + void refresh_status(); private: - void send_command(bool); - void status_reply(const Reply &); - bool reverse_timeout(); + void send_command(bool); + void status_reply(const Reply &); + bool reverse_timeout(); }; } // namespace Marklin diff --git a/source/libmarklin/route.h b/source/libmarklin/route.h index f1f3664..a8e220d 100644 --- a/source/libmarklin/route.h +++ b/source/libmarklin/route.h @@ -1,14 +1,13 @@ /* $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 */ #ifndef LIBMARKLIN_ROUTE_H_ #define LIBMARKLIN_ROUTE_H_ -#include #include #include #include @@ -20,15 +19,17 @@ class Turnout; class Route { -public: - Route(); - const std::map &get_turnouts() const { return turnouts; } - void add_track(Track *); - ~Route(); private: std::string name; std::set tracks; std::map turnouts; + +public: + Route(); + ~Route(); + + const std::map &get_turnouts() const { return turnouts; } + void add_track(Track *); }; } // namespace Marklin diff --git a/source/libmarklin/sensor.h b/source/libmarklin/sensor.h index 930b15f..45749ea 100644 --- a/source/libmarklin/sensor.h +++ b/source/libmarklin/sensor.h @@ -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 */ @@ -19,20 +19,21 @@ class Control; class Sensor { +public: + sigc::signal signal_state_changed; + private: - Control &control; + Control &control; unsigned addr; - bool state; + 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(); + bool get_state() const { return state; } + void tick(); private: void sensor_event(unsigned, bool); }; diff --git a/source/libmarklin/track.cpp b/source/libmarklin/track.cpp index b6674ae..73674ee 100644 --- a/source/libmarklin/track.cpp +++ b/source/libmarklin/track.cpp @@ -55,6 +55,34 @@ void Track::set_flex(bool f) flex=f; } +void Track::check_slope() +{ + if(links.size()!=2) + return; + + 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; + } + else + { + slope=0; + if(links[0]) + { + 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; + } + } +} + void Track::set_turnout_id(unsigned i) { turnout_id=i; @@ -190,34 +218,6 @@ Track *Track::get_link(unsigned i) const return links[i]; } -void Track::check_slope() -{ - if(links.size()!=2) - return; - - 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; - } - else - { - slope=0; - if(links[0]) - { - 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; - } - } -} - int Track::traverse(unsigned i, unsigned route) const { const vector &eps=type.get_endpoints(); @@ -334,12 +334,12 @@ void Track::save(list &st) const Track::Loader::Loader(Track &t): DataFile::BasicLoader(t) { - add("position", &Loader::position); - add("rotation", &Track::rot); - add("slope", &Track::slope); - add("turnout_id", &Track::turnout_id); - add("sensor_id", &Track::sensor_id); - add("flex", &Track::flex); + add("position", &Loader::position); + add("rotation", &Track::rot); + add("slope", &Track::slope); + add("turnout_id", &Track::turnout_id); + add("sensor_id", &Track::sensor_id); + add("flex", &Track::flex); } void Track::Loader::position(float x, float y, float z) diff --git a/source/libmarklin/track.h b/source/libmarklin/track.h index 3c96a82..b000e34 100644 --- a/source/libmarklin/track.h +++ b/source/libmarklin/track.h @@ -30,43 +30,49 @@ public: private: const TrackType &type; - Point pos; - float rot; - float slope; - bool flex; - unsigned turnout_id; - unsigned sensor_id; + Point pos; + float rot; + float slope; + bool flex; + unsigned turnout_id; + unsigned sensor_id; std::vector links; + // Direct copying not allowed due to links. See the copy() function. + Track(const Track &); + Track &operator=(const Track &); public: Track(const TrackType &); ~Track(); const TrackType &get_type() const { return type; } - void set_position(const Point &); - const Point &get_position() const { return pos; } - void set_rotation(float); - float get_rotation() const { return rot; } - void set_slope(float); - float get_slope() const { return slope; } - void set_flex(bool); - bool get_flex() const { return flex; } - void set_turnout_id(unsigned); - unsigned get_turnout_id() const { return turnout_id; } - void set_sensor_id(unsigned); - unsigned get_sensor_id() const { return sensor_id; } - int get_endpoint_by_link(const Track &) const; - Point get_endpoint_position(unsigned) const; - float get_endpoint_direction(unsigned) const; - bool snap_to(Track &, bool); - bool snap(Point &, float &) const; - void break_link(Track &); - void break_links(); + + void set_position(const Point &); + void set_rotation(float); + void set_slope(float); + void set_flex(bool); + const Point &get_position() const { return pos; } + float get_rotation() const { return rot; } + float get_slope() const { return slope; } + bool get_flex() const { return flex; } + void check_slope(); + + void set_turnout_id(unsigned); + void set_sensor_id(unsigned); + unsigned get_turnout_id() const { return turnout_id; } + unsigned get_sensor_id() const { return sensor_id; } + + int get_endpoint_by_link(const Track &) const; + Point get_endpoint_position(unsigned) const; + float get_endpoint_direction(unsigned) const; + bool snap_to(Track &, bool); + bool snap(Point &, float &) const; + void break_link(Track &); + void break_links(); const std::vector &get_links() const { return links; } - Track *get_link(unsigned) const; - void check_slope(); - int traverse(unsigned, unsigned) const; - Point get_point(unsigned, unsigned, float) const; + Track *get_link(unsigned) const; + int traverse(unsigned, unsigned) const; + Point get_point(unsigned, unsigned, float) const; /** Creates a copy of the track. The new track will be almost identical, but @@ -75,11 +81,6 @@ public: Track *copy() const; void save(std::list &) const; -private: - - // Direct copying not allowed due to links. See the copy() function. - Track(const Track &); - Track &operator=(const Track &); }; } // namespace Marklin diff --git a/source/libmarklin/trackpart.h b/source/libmarklin/trackpart.h index de449b3..34605ca 100644 --- a/source/libmarklin/trackpart.h +++ b/source/libmarklin/trackpart.h @@ -25,12 +25,12 @@ struct TrackPart void start(float, float, float); }; - Point pos; - float dir; - float length; - float radius; + Point pos; + float dir; + float length; + float radius; unsigned route; - bool dead_end; + bool dead_end; TrackPart(); diff --git a/source/libmarklin/tracktype.h b/source/libmarklin/tracktype.h index ba1b95f..65aa1f2 100644 --- a/source/libmarklin/tracktype.h +++ b/source/libmarklin/tracktype.h @@ -28,8 +28,8 @@ public: }; private: - unsigned art_nr; - std::string description; + unsigned art_nr; + std::string description; std::vector parts; std::vector endpoints; @@ -42,10 +42,10 @@ public: float get_route_length(int) const; unsigned get_n_routes() const; const std::vector &get_parts() const { return parts; } - const std::vector &get_endpoints() const { return endpoints; } + const std::vector &get_endpoints() const { return endpoints; } private: - void collect_endpoints(); + void collect_endpoints(); }; } // namespace Marklin diff --git a/source/libmarklin/trafficmanager.h b/source/libmarklin/trafficmanager.h index b09c500..d75bf3a 100644 --- a/source/libmarklin/trafficmanager.h +++ b/source/libmarklin/trafficmanager.h @@ -28,6 +28,8 @@ public: void train(unsigned, unsigned); }; + sigc::signal signal_block_reserved; + private: Control &control; Layout &layout; @@ -36,8 +38,6 @@ private: Msp::Time::TimeStamp last_tick; public: - sigc::signal signal_block_reserved; - TrafficManager(Control &, Layout &); ~TrafficManager(); diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index d95d4c4..a4e2b15 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -28,6 +28,9 @@ public: Loader(Train &); }; + sigc::signal signal_name_changed; + sigc::signal signal_status_changed; + private: struct BlockRef { @@ -59,9 +62,6 @@ private: Point pos; public: - sigc::signal signal_name_changed; - sigc::signal signal_status_changed; - Train(TrafficManager &, Locomotive &); void set_name(const std::string &); diff --git a/source/libmarklin/turnout.h b/source/libmarklin/turnout.h index 616a7fe..2795714 100644 --- a/source/libmarklin/turnout.h +++ b/source/libmarklin/turnout.h @@ -21,21 +21,22 @@ class Reply; class Turnout { +public: + sigc::signal signal_route_changing; + sigc::signal signal_route_changed; + private: - Control &control; + Control &control; unsigned addr; unsigned route; - bool dual; + bool dual; public: - sigc::signal signal_route_changing; - sigc::signal signal_route_changed; - Turnout(Control &, unsigned, bool =false); - void set_route(unsigned); + void set_route(unsigned); unsigned get_address() const { return addr; } - unsigned get_route() const { return route; } + unsigned get_route() const { return route; } private: void command(bool); void status_reply(const Reply &, bool);