X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrack.h;h=21c505fb9ae12c180ed955e632aab989d0684b03;hb=02c9a9779954d993cb73fe5f7a72b0847e87f633;hp=6bddd4dad01518676062db707caab0b173d19ff9;hpb=06c100aacb559fbbe7380e15981c4772092c269b;p=r2c2.git diff --git a/source/libmarklin/track.h b/source/libmarklin/track.h index 6bddd4d..21c505f 100644 --- a/source/libmarklin/track.h +++ b/source/libmarklin/track.h @@ -1,121 +1,87 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + #ifndef LIBMARKLIN_TRACK_H_ #define LIBMARKLIN_TRACK_H_ #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::BasicLoader { 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); + // Direct copying not allowed due to links. See the copy() function. + Track(const Track &); + Track &operator=(const Track &); +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 &); + 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; + unsigned 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 won't have any links to other tracks, nor a turnout or sensor id. */ 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 &operator=(const Track &); - void collect_endpoints(); + void save(std::list &) const; }; -typedef std::list TrackSeq; -typedef std::set TrackSet; } // namespace Marklin