3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
15 TrackType::TrackType(unsigned a):
19 float TrackType::get_total_length() const
21 return get_path_length(-1);
24 float TrackType::get_path_length(int p) const
27 for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
28 if(p<0 || i->path==static_cast<unsigned>(p))
38 unsigned TrackType::get_paths() const
41 for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
46 unsigned TrackType::get_n_paths() const
49 for(unsigned mask = get_paths(); mask; ++n)
54 bool TrackType::is_turnout() const
56 return endpoints.size()>2;
59 bool TrackType::is_double_address() const
61 return get_n_paths()>2;
64 void TrackType::collect_endpoints()
68 for(vector<TrackPart>::iterator i=parts.begin(); i!=parts.end(); ++i)
69 i->collect_endpoints(endpoints);
71 for(vector<Endpoint>::iterator i=endpoints.begin(); i!=endpoints.end();)
74 for(vector<Endpoint>::iterator j=i+1; j!=endpoints.end();)
76 float dx = i->pos.x-j->pos.x;
77 float dy = i->pos.y-j->pos.y;
78 if(dx*dx+dy*dy<0.0001)
80 float da = i->dir-j->dir;
88 j = endpoints.erase(j);
95 i = endpoints.erase(i);
102 TrackType::Loader::Loader(TrackType &t):
103 Msp::DataFile::BasicLoader<TrackType>(t)
105 add("description", &TrackType::description);
106 add("part", &Loader::part);
109 void TrackType::Loader::finish()
111 obj.collect_endpoints();
114 void TrackType::Loader::part()
118 obj.parts.push_back(p);
121 } // namespace Marklin