/******************************************************************************
 * AnyImage.cs 
 * 
 * <Copyright and License> 
 * 
 * This file is part of GODS, a package for annotating medical images. 
 * 
 * Copyright (C) 2004 
 * Xuedong Chen 
 * Heri Mariwa 
 * Kimmy (Hsiang-ling) Lin 
 * Rui Yu 
 * 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 
 * of the License, or (at your option) any later version. 
 * 
 * This program 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. See the 
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 *  
 * For further questions about this file, please send email to 
 * gods@cs.umb.edu or visit us at http://gods.sourceforge.net.  
 ******************************************************************************/

using System;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Drawing;

namespace GODS
{
	using MarkData;

	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class AnyImage : DiagnosticImage
	{
		public AnyImage(Bitmap image) : base(image) {}

		public override ArrayList buildSummary(ArrayList marks)
		{
			ArrayList summaries = new ArrayList();
			StringBuilder anotherBuilder = new StringBuilder();
			StringBuilder builder;
			foreach (Mark mark in marks)
			{
				builder = new StringBuilder();
				builder.Append(mark.Description);

				if (mark.HasPresetValues && mark.CurrentValueIndex != 0) 
				{
					builder.Append(" : ");
					builder.Append(mark.CurrentValue);
				}
			
				builder.Append("\t Estimated size: ");
				builder.Append(mark.MarkWidth);
				builder.Append("cm X ");
				builder.Append(mark.MarkHeight);
				builder.Append("cm. ");
				
				builder.Append(mark.MarkComment);
				summaries.Add(builder.ToString());
				anotherBuilder.Append(builder.ToString() + System.Environment.NewLine);
			}
			base.LatestSummary = anotherBuilder.ToString();
			return summaries;
		}

		public override void saveAnnoImage(string path, ArrayList marks)
		{
			Bitmap tempBMP = new Bitmap(this.RealImage);
			Graphics g = Graphics.FromImage(tempBMP);
			
			foreach (Mark mark in marks) 
			{
				if (mark.HasImage)
				{
					g.DrawImage(
						mark.Image,
						mark.Location.X,
						mark.Location.Y,
						mark.Width,
						mark.Height);
				}
			}
			
			try 
			{
				if (System.IO.File.Exists(path))
				{
					System.IO.File.Delete(path);
				}
				tempBMP.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);
				
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.ToString());
			}
		}

	}
}
