X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrack.h;h=13a98bf51b268d4772dff9d1c7111df54fbea967;hb=52cbe8d99669f843f8f75c51128e2748584dd03a;hp=6bddd4dad01518676062db707caab0b173d19ff9;hpb=36beacc579d3132642ed4d98ce5a6d99842b5812;p=r2c2.git diff --git a/source/libmarklin/track.h b/source/libmarklin/track.h index 6bddd4d..13a98bf 100644 --- a/source/libmarklin/track.h +++ b/source/libmarklin/track.h @@ -3,93 +3,66 @@ #include #include -#include +#include #include "geometry.h" namespace Marklin { +class TrackType; + class Track { public: - class Loader: public Msp::Parser::Loader + class Loader: public Msp::DataFile::Loader { + private: + Track &track; + public: Loader(Track &); Track &get_object() { return track; } - ~Loader(); private: - Track &track; - - void part(); void position(float, float, float); }; - struct Endpoint - { - Point pos; - float rot; - Track *link; - unsigned routes; - - Endpoint(const Point &p, float r, unsigned o): pos(p), rot(r), link(0), routes(o) { } - }; - typedef std::list EndpointSeq; - - struct Part - { - class Loader: public Msp::Parser::Loader - { - public: - Loader(Part &); - Part &get_object() { return part; } - ~Loader(); - private: - Part ∂ - - void start(float, float, float); - }; - - float x,y; - float dir; - float length; - float radius; - unsigned route; - bool dead_end; - - Part(); - void collect_endpoints(EndpointSeq &); - }; - typedef std::list PartSeq; +private: + const TrackType &type; + Point pos; + float rot; + float slope; + bool flex; + unsigned turnout_id; + unsigned sensor_id; + std::vector links; - Track(unsigned); +public: + Track(const TrackType &); ~Track(); - void set_position(const Point &); - void set_rotation(float); - void set_slope(float); - void set_flex(bool f) { flex=f; } - void set_turnout_id(unsigned i) { turnout_id=i; } - void set_sensor_id(unsigned i) { sensor_id=i; } - const Point &get_position() const { return pos; } - float get_rotation() const { return rot; } - unsigned get_article_number() const { return art_nr; } - const PartSeq &get_parts() const { return parts; } - const EndpointSeq &get_endpoints() const { return endpoints; } - const Endpoint *get_endpoint_by_link(Track *) const; - Point get_endpoint_position(const Endpoint &) const; - const std::string &get_description() const { return description; } - float get_slope() const { return slope; } - bool get_flex() const { return flex; } - float get_length() const; - float get_total_length() const; - unsigned get_turnout_id() const { return turnout_id; } - unsigned get_sensor_id() const { return sensor_id; } - unsigned get_n_routes() const; - bool snap_to(Track &, bool); - bool snap(Point &, float &) const; - void break_link(Track &); - void break_links(); - void check_slope(); - const Endpoint *traverse(const Endpoint *, unsigned) const; + + 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(); + const std::vector &get_links() const { return links; } + Track *get_link(unsigned) const; + void check_slope(); + int traverse(unsigned, unsigned) const; /** Creates a copy of the track. The new track will be almost identical, but @@ -97,25 +70,11 @@ public: */ Track *copy() const; private: - unsigned art_nr; - std::string description; - PartSeq parts; - EndpointSeq endpoints; - Point pos; - float rot; - float slope; - bool flex; - unsigned turnout_id; - unsigned sensor_id; // Direct copying not allowed due to links. See the copy() function. - //Track(const Track &); + Track(const Track &); Track &operator=(const Track &); - - void collect_endpoints(); }; -typedef std::list TrackSeq; -typedef std::set TrackSet; } // namespace Marklin