From: Mikko Rasa Date: Mon, 8 Jul 2013 16:59:34 +0000 (+0300) Subject: Add a function to retrieve track attachments in order X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cb4dfc37dd2cd9e02de7f022fd7f8a1fc8e5ee3c;p=r2c2.git Add a function to retrieve track attachments in order --- diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 26fb59e..455cc88 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -5,11 +5,26 @@ #include "driver.h" #include "layout.h" #include "track.h" +#include "trackattachment.h" #include "tracktype.h" using namespace std; using namespace Msp; +namespace { + +struct AttachmentCompare +{ + unsigned entry; + + AttachmentCompare(unsigned e): entry(e) { } + + bool operator()(const R2C2::TrackAttachment *a1, const R2C2::TrackAttachment *a2) const + { return a1->get_offset_from_endpoint(entry)get_offset_from_endpoint(entry); } +}; + +} + namespace R2C2 { Track::Track(Layout &l, const TrackType &t): @@ -347,6 +362,13 @@ void Track::remove_attachment(TrackAttachment &a) attachments.erase(i); } +Track::AttachmentList Track::get_attachments_ordered(unsigned epi) const +{ + AttachmentList result = attachments; + result.sort(AttachmentCompare(epi)); + return result; +} + void Track::save(list &st) const { st.push_back((DataFile::Statement("position"), position.x, position.y, position.z)); diff --git a/source/libr2c2/track.h b/source/libr2c2/track.h index 994712d..0f92271 100644 --- a/source/libr2c2/track.h +++ b/source/libr2c2/track.h @@ -99,6 +99,7 @@ public: void add_attachment(TrackAttachment &); void remove_attachment(TrackAttachment &); const AttachmentList &get_attachments() const { return attachments; } + AttachmentList get_attachments_ordered(unsigned) const; void save(std::list &) const; private: diff --git a/source/libr2c2/trackattachment.cpp b/source/libr2c2/trackattachment.cpp index 29521fd..eb2d563 100644 --- a/source/libr2c2/trackattachment.cpp +++ b/source/libr2c2/trackattachment.cpp @@ -20,6 +20,14 @@ TrackAttachment::~TrackAttachment() track->remove_attachment(*this); } +float TrackAttachment::get_offset_from_endpoint(unsigned epi) const +{ + if(epi==track.entry()) + return offset; + else + return track->get_type().get_path_length(0)-offset; +} + void TrackAttachment::attach_to(const TrackIter &t, float o) { if(track) diff --git a/source/libr2c2/trackattachment.h b/source/libr2c2/trackattachment.h index d02a443..1572f61 100644 --- a/source/libr2c2/trackattachment.h +++ b/source/libr2c2/trackattachment.h @@ -2,6 +2,7 @@ #define LIBR2C2_TRACKATTACHMENT_H_ #include "object.h" +#include "track.h" #include "trackiter.h" namespace R2C2 { @@ -20,6 +21,7 @@ public: Track *get_track() const { return track.track(); } unsigned get_entry() const { return track.entry(); } float get_offset() const { return offset; } + float get_offset_from_endpoint(unsigned) const; protected: void attach_to(const TrackIter &, float); void attach_to_closest(float);