/******************************************************************************
 * MarkSet.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.Collections;

namespace GODS.MarkData
{
	/// <summary>
	/// Summary description for Markset.
	/// </summary>
	public class MarkSet
	{
		private int id;
		private string name;
		private MarkCategory category;
		private ArrayList groups;
		private bool removable = true;
		private bool hasChanged = false;

		public MarkSet(MarkCategory cat, int id, string name, ArrayList groups)
		{
			this.category = cat;
			this.id = id;
			this.name = name;
			this.groups = groups;
		}

		public MarkSet(MarkCategory cat, int id, string name) : this(cat, id, name, new ArrayList())
		{
		}

		public MarkSet(MarkCategory cat, string name) : this(cat, -1, name, new ArrayList())
		{
		}

		//this is to fix the bug when save mark set is clicked twice
		internal void setMarkSetID(int id)
		{
			this.id = id;
		}

		public int MarkSetID
		{
			get
			{
				return this.id;
			}
		}

		public string MarksetName
		{
			get 
			{
				return this.name;
			}
			set
			{
				this.name = value;
			}
		}
        
		//indicated wether mark has changed since last saved
		public bool HasChanged
		{
			get 
			{
				return this.hasChanged;
			}
			set
			{
				this.hasChanged = value;
			}
		}

		public MarkCategory Category
		{
			get 
			{
				return this.category;
			}
		}

		public ArrayList MarkGroups
		{
  	       get
		   {  
			   return this.groups;
           }
        }

		public bool Removable
		{
			get 
			{
				return this.removable;
			}
		}

		public ArrayList AllMarks
		{
			get 
			{
				ArrayList allMarks = new ArrayList();
				foreach (MarkGroup group in this.groups)
					allMarks.AddRange(group.Marks.ToArray());
				return allMarks;
			}
		}
		
		private MarkGroup getMarkGroup(string gName)
		{
			foreach (MarkGroup group in this.groups)
			{
				if (gName.Equals(group.GroupName)) 
				{
					return group;
				}
			}
			return null;
		}

		public void addMarkGroup(MarkGroup newGroup)
		{
			MarkGroup group = this.getMarkGroup(newGroup.GroupName);
			if (group == null)
			{
				this.groups.Add(newGroup);
			}
			else
			{
				throw new System.Exception("Dupplicate group: Group with the same name already exists.");
			}
		}

		public void removeMarkGroup(MarkGroup group)
		{
			this.groups.Remove(group);
		}

		public override string ToString()
		{
			return this.name;
		}
	}
}
