00001 00005 /* Copyright © 2009 James Legg. 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 */ 00011 00012 #include "ChangeVertexSegmentDelta.h" 00013 #include "../Track.h" 00014 #include "ClearVertexDelta.h" 00015 00016 namespace Document 00017 { 00018 00019 VertexSegmentFinder::VertexSegmentFinder(std::size_t node_id) 00020 : node_id(node_id) 00021 { 00022 } 00023 00024 void VertexSegmentFinder::read(const Track::Track & track, std::size_t & new_segment_index) 00025 { 00026 new_segment_index = track.get_path().get_node(node_id).get_segment_index(); 00027 } 00028 00029 void VertexSegmentFinder::write(Track::Track & track, const std::size_t & new_segment_index) 00030 { 00031 Track::Path & path = track.get_path(); 00032 Track::PathVertex & vertex = path.get_node(node_id); 00033 // set the new segment. 00034 vertex.set_segment(new_segment_index, 00035 &track.get_theme().get_segment(new_segment_index)); 00036 } 00037 00038 std::size_t VertexSegmentFinder::get_vertex_name() const 00039 { 00040 return node_id; 00041 } 00042 00043 ChangeVertexSegmentDelta::ChangeVertexSegmentDelta(VertexSegmentFinder vertex_segment_finder, std::size_t new_segment_index) 00044 : vertex_segment_finder(vertex_segment_finder) 00045 , new_segment_index(new_segment_index) 00046 { 00047 } 00048 00049 void ChangeVertexSegmentDelta::apply(Track::Track & track) 00050 { 00051 // remove attached edges. 00052 std::size_t vertex_name = vertex_segment_finder.get_vertex_name(); 00053 boost::shared_ptr<DocumentDelta> clear_delta( 00054 new ClearVertexDelta(vertex_name) 00055 ); 00056 add_to_stack(clear_delta, track); 00057 00058 // change the vertex's segment 00059 boost::shared_ptr<DocumentDelta> change_segment_delta( 00060 new ChangeVertexSegmentOnlyDelta(vertex_segment_finder, 00061 new_segment_index) 00062 ); 00063 add_to_stack(change_segment_delta, track); 00064 } 00065 00066 }
Generated at Mon Sep 6 00:41:11 2010 by Doxygen version 1.4.7 for Racer version svn335.