package Debrief.ReaderWriter.XML.Tactical;

/**
 * Title:        Debrief 2000
 * Description:  Debrief 2000 Track Analysis Software
 * Copyright:    Copyright (c) 2000
 * Company:      MWC
 * @author Ian Mayo
 * @version 1.0
 */

import org.w3c.dom.Element;

import Debrief.Wrappers.Track.RelativeTMASegment;
import Debrief.Wrappers.Track.TrackSegment;
import MWC.GUI.Layers;
import MWC.GenericData.WorldVector;
import MWC.Utilities.ReaderWriter.XML.Util.WorldVectorHandler;

abstract public class RelativeTMASegmentHandler extends CoreTMASegmentHandler
{
	private static final String TMA_SEGMENT = "RelativeTMASegment";
	public static final String HOST="HostTrack";
	public static final String OFFSET="Offset";	

	protected String _host;
	protected WorldVector _offset;
	private final Layers _theLayers;
	
	public RelativeTMASegmentHandler(Layers theLayers)
	{
		// inform our parent what type of class we are
		super(theLayers, TMA_SEGMENT);

		_theLayers = theLayers;
		
		addAttributeHandler(new HandleAttribute(HOST)
		{
			@Override
			public void setValue(String name, String val)
			{
				_host = val;
			}
		});
		
		addHandler(new WorldVectorHandler(OFFSET){
		
			@Override
			public void setWorldVector(WorldVector res)
			{
				_offset = res;
			}
		});
		

	}
	
	

	@Override
	protected TrackSegment createTrack()
	{
		RelativeTMASegment res = new RelativeTMASegment(_courseDegs, _speed, _offset, _theLayers);
		res.setBaseFrequency(_baseFrequency);
		res.setHostName(_host);
		return res;
	}


	public static void exportThisTMASegment(org.w3c.dom.Document doc, Element trk,
			RelativeTMASegment seg)
	{
		
		final Element segE = CoreTrackSegmentHandler.exportThisSegment(doc, seg, TMA_SEGMENT);
	
		// export the start bits
		CoreTMASegmentHandler.exportThisTMASegment(doc, seg, segE);

		// sort out the remaining attributes
		segE.setAttribute(HOST, seg.getReferenceTrack().getName());		
	
		trk.appendChild(segE);
		
	}

}
@@ -1979,16 +1979,119 @@
 ());%09%09%0D%0A
+%09%09%0D%0A%09%09// and the offset vector%0D%0A%09%09WorldVectorHandler.exportVector(OFFSET, seg.getOffset(),segE, doc);%0D%0A
 %09%0D%0A%09%09trk

Fix correct saving of Relative TMA Segments (we weren't exporting the vector)