SetStartEdgeDelta.cpp

Go to the documentation of this file.
00001 
00006 /* Copyright © 2009, 2010 James Legg.
00007     This program is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 */
00012 
00013 #include "SetStartEdgeDelta.h"
00014 
00015 #include "InsertTrackAttachmentDelta.h"
00016 #include "../Track.h"
00017 #include "../StartingPosition.h"
00018 
00019 namespace Document
00020 {
00021 
00022 StartEdgeFinder::StartEdgeFinder()
00023 {
00024 }
00025 
00026 void StartEdgeFinder::read(const Track::Track & track, unsigned long int & edge_name)
00027 {
00028     edge_name = track.get_path().get_starting_edge();
00029 }
00030 
00031 void StartEdgeFinder::write(Track::Track & track, const unsigned long int & new_edge_name)
00032 {
00033     track.get_path().set_starting_edge(new_edge_name);
00034 }
00035 
00036 SetStartPositionsDelta::SetStartPositionsDelta(const unsigned int edge_name)
00037     :   m_edge_name(edge_name)
00038 {
00039 }
00040 
00041 void SetStartPositionsDelta::apply(Track::Track & track)
00042 {
00043     // deltas to delete the Track::StartMarkers on the current edge.
00044     unsigned int old_edge_name = track.get_path().get_starting_edge();
00045     if (old_edge_name != 0)
00046     {
00047         const Track::PathEdge &old_edge = track.get_path().get_edge(old_edge_name);
00048         std::vector<boost::shared_ptr<Track::TrackAttachment>
00049                    >::const_iterator it = old_edge.get_attachments().begin();
00050         while (it != old_edge.get_attachments().end())
00051         {
00052             if (dynamic_cast<const Track::StartingPosition *>(&(**it)))
00053             {
00054                 boost::shared_ptr<Document::DocumentDelta> delta
00055                 (
00056                     new Document::RemoveTrackAttachmentDelta
00057                     (
00058                         InsertRemoveTrackAttachmentIdentifier(*it)
00059                     )
00060                 );
00061                 add_to_stack(delta, track);
00062                 // Invalidates iterator, start again.
00063                 it = old_edge.get_attachments().begin();
00064             } else {
00065                 it++;
00066             }
00067         }
00068     }
00069     // delta to replace the starting edge
00070     add_to_stack(boost::shared_ptr<DocumentDelta>(
00071                     new SetStartEdgeDelta(Document::StartEdgeFinder(),
00072                                           m_edge_name)
00073                ), track);
00074     
00075     // Deltas to add new start markers.
00076     for (int i = 0; i < 30; i++)
00077     {
00078         boost::shared_ptr<Track::TrackAttachment> pos(new Track::StartingPosition(29-i));
00079         pos->set_lateral_position((i % 2 - 0.5) * 1.25);
00080         pos->set_t_position(0.03125 * i + 0.0625);
00081         pos->edge_name = m_edge_name;
00082         
00083         boost::shared_ptr<Document::DocumentDelta> delta
00084         (
00085             new Document::InsertTrackAttachmentDelta(pos)
00086         );
00087         add_to_stack(delta, track);
00088     }
00089 }
00090 
00091 } // namespace Document

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:11 2010 by Doxygen version 1.4.7 for Racer version svn335.