/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2014, PlanetMayo Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 */
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.AbsoluteTMASegment;
import Debrief.Wrappers.Track.TrackSegment;
import MWC.GenericData.WorldLocation;
import MWC.Utilities.ReaderWriter.XML.Util.LocationHandler;

abstract public class AbsoluteTMASegmentHandler extends CoreTMASegmentHandler
{
	private static final String TMA_SEGMENT = "AbsoluteTMASegment";
	public static final String ORIGIN="Origin";

	protected WorldLocation _origin;
	
	public AbsoluteTMASegmentHandler()
	{
		// inform our parent what type of class we are
		super(TMA_SEGMENT);

		addHandler(new LocationHandler(ORIGIN)
		{
			@Override
			public void setLocation(final WorldLocation val)
			{
				_origin = val;
			}
		});
	}
	
	

	@Override
	protected TrackSegment createTrack()
	{
		final AbsoluteTMASegment res = new AbsoluteTMASegment(_courseDegs, _speed, _origin, null, null);
		res.setBaseFrequency(_baseFrequency);
		return res;
	}


  @Override
  protected void finishInitialisation(TrackSegment segment)
  {
    AbsoluteTMASegment rel = (AbsoluteTMASegment) segment;
    rel.sortOutDate(null);
    
    super.finishInitialisation(segment);
  }	

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

		// sort out the remaining attributes
		LocationHandler.exportLocation(seg.getTrackStart(), ORIGIN, segE, doc);
	
		trk.appendChild(segE);
		
	}

}
@@ -799,24 +799,61 @@
 Element;%0D%0A%0D%0A
+import Debrief.Wrappers.FixWrapper;%0D%0A
 import Debri
@@ -1915,34 +1915,374 @@
 t;%0D%0A
+%0D%0A
     
-rel.sortOutDate(null);
+// ok, the track has it's fixes. pass through to set the time,%0D%0A    // if necessary%0D%0A    if(rel.getDTG_Start() == null)%0D%0A    %7B%0D%0A      FixWrapper firstF = (FixWrapper) rel.first();%0D%0A      FixWrapper lastF = (FixWrapper) rel.last();%0D%0A      %0D%0A      rel.setDTG_Start_Silent(firstF.getDateTimeGroup());%0D%0A      rel.setDTG_End_Silent(lastF.getDateTimeGroup());%0D%0A    %7D
 %0D%0A  

fix to ensure restored ABS TMA Segment knows its start & finish time