00001 00005 /* Copyright © 2010 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 "TrackAttachmentHandle.h" 00013 #include "../document/MoveTrackAttachmentDelta.h" 00014 #include "../path/PathEdge.h" 00015 #include "../document/InsertTrackAttachmentDelta.h" 00016 00017 namespace Track 00018 { 00019 00020 namespace EditAssist 00021 { 00022 00023 TrackAttachmentHandle::TrackAttachmentHandle(const PathEdge & edge, std::size_t attachment_index) 00024 : m_edge(edge) 00025 , m_attachment_index(attachment_index) 00026 { 00027 } 00028 00029 void TrackAttachmentHandle::draw() const 00030 { 00031 // Will probably be covered by the attachment in most views, 00032 // but is useful from some angles. 00033 glColor3f(0.0, 1.0, 1.0); 00034 glBegin(GL_POINTS); 00035 glVertex3f(position.x(), position.y(), position.z()); 00036 glEnd(); 00037 } 00038 00039 void TrackAttachmentHandle::snap(btVector3 & position, btVector3 normal) const 00040 { 00041 btScalar s = m_edge.get_nearest_s(position, position + normal); 00042 position = m_edge.get_transform(s).getOrigin(); 00043 } 00044 00045 boost::shared_ptr<Document::DocumentDelta> TrackAttachmentHandle::make_delta(btVector3 position) const 00046 { 00047 // position should have been snapped with snap, 00048 // so it doesn't really matter that we do not know the direction. 00049 // but the line should have non-zero length for the maths to work. 00050 btScalar s = m_edge.get_nearest_s(position, position + btVector3(0.001, 0.001, 0.001)); 00051 00052 TrackAttachment & attachment = *(m_edge.get_attachments()[m_attachment_index]); 00053 btVector3 new_pos(s, attachment.get_lateral_position(), 00054 attachment.get_vertical_position()); 00055 00056 return boost::shared_ptr<Document::DocumentDelta>(new 00057 Document::MoveTrackAttachmentDelta( 00058 Document::TrackAttachmentPositionFinder(m_edge.get_name(), 00059 attachment.get_name()), 00060 new_pos)); 00061 } 00062 00063 boost::shared_ptr<Document::DocumentDelta> TrackAttachmentHandle::make_remove_delta() const 00064 { 00065 TrackAttachment & attachment = *(m_edge.get_attachments()[m_attachment_index]); 00066 return boost::shared_ptr<Document::DocumentDelta>(new 00067 Document::RemoveTrackAttachmentDelta( 00068 Document::InsertRemoveTrackAttachmentIdentifier( 00069 attachment.get_name(), 00070 m_edge.get_name()))); 00071 } 00072 00073 } // namespace EditAssist 00074 00075 } // namespace Track
Generated at Mon Sep 6 00:41:11 2010 by Doxygen version 1.4.7 for Racer version svn335.