]> git.tdb.fi Git - r2c2.git/commitdiff
Add a function to retrieve track attachments in order
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Jul 2013 16:59:34 +0000 (19:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Jul 2013 20:17:38 +0000 (23:17 +0300)
source/libr2c2/track.cpp
source/libr2c2/track.h
source/libr2c2/trackattachment.cpp
source/libr2c2/trackattachment.h

index 26fb59e0fa7e756b619ad718d090dec6b6f05314..455cc88055c6301a8b7d53d29998a5d98cea8eb1 100644 (file)
@@ -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)<a2->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<DataFile::Statement> &st) const
 {
        st.push_back((DataFile::Statement("position"), position.x, position.y, position.z));
index 994712da8c43cc2171cf340cb624cf55aa53bbd4..0f9227111cb41a1a98b4b8020c555725b0d13e20 100644 (file)
@@ -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<Msp::DataFile::Statement> &) const;
 private:
index 29521fdc064659457d3dfaa97da30d3fc0b79563..eb2d563561c6fcf7864d00c1a8a170f943c7e624 100644 (file)
@@ -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)
index d02a443d823a6e77a123f7a56246c453669985fa..1572f619db1ede100ea9cfa8e22d4298ba9a2edc 100644 (file)
@@ -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);