3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009 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_n_paths() const
41 for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
47 void TrackType::collect_endpoints()
51 for(vector<TrackPart>::iterator i=parts.begin(); i!=parts.end(); ++i)
52 i->collect_endpoints(endpoints);
54 for(vector<Endpoint>::iterator i=endpoints.begin(); i!=endpoints.end();)
57 for(vector<Endpoint>::iterator j=i+1; j!=endpoints.end();)
59 float dx = i->pos.x-j->pos.x;
60 float dy = i->pos.y-j->pos.y;
61 if(dx*dx+dy*dy<0.0001)
63 float da = i->dir-j->dir;
71 j = endpoints.erase(j);
78 i = endpoints.erase(i);
85 TrackType::Loader::Loader(TrackType &t):
86 Msp::DataFile::BasicLoader<TrackType>(t)
88 add("description", &TrackType::description);
89 add("part", &Loader::part);
92 void TrackType::Loader::finish()
94 obj.collect_endpoints();
97 void TrackType::Loader::part()
101 obj.parts.push_back(p);
104 } // namespace Marklin