394 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			394 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Collections;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Drawing;
 | 
						|
using System.ComponentModel;
 | 
						|
using System.Text;
 | 
						|
 | 
						|
namespace Volian.Svg.Library
 | 
						|
{
 | 
						|
	/// <summary>
 | 
						|
	///	 <para>
 | 
						|
	///	   A collection that stores <see cref='SVGPart'/> objects.
 | 
						|
	///	</para>
 | 
						|
	/// </summary>
 | 
						|
	/// <seealso cref='SVGPart'/>
 | 
						|
	[Serializable()]
 | 
						|
	[TypeConverter(typeof(SVGPartsConverter))]
 | 
						|
	public partial class SvgParts : CollectionBase, ICustomTypeDescriptor
 | 
						|
	{
 | 
						|
		/// <summary>Notifies when the collection has been modified.</summary>
 | 
						|
		public event EventHandler OnItemsChanged;
 | 
						|
 | 
						|
		/// <summary>Notifies that an item has been added.</summary>
 | 
						|
		public event SVGPartHandler OnItemAdd;
 | 
						|
 | 
						|
		/// <summary>Notifies that items have been added.</summary>
 | 
						|
		public event SVGPartHandler OnItemsAdd;
 | 
						|
 | 
						|
		/// <summary>Notifies that an item has been removed.</summary>
 | 
						|
		public event SVGPartHandler OnItemRemove;
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		///	 <para>
 | 
						|
		///	   Initializes a new instance of <see cref='SVGPart'/>.
 | 
						|
		///	</para>
 | 
						|
		/// </summary>
 | 
						|
		public SvgParts()
 | 
						|
		{
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		///	 <para>
 | 
						|
		///	   Initializes a new instance of <see cref='SVGPart'/> based on another <see cref='SVGPart'/>.
 | 
						|
		///	</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='value'>
 | 
						|
		///	   A <see cref='SVGPart'/> from which the contents are copied
 | 
						|
		/// </param>
 | 
						|
		public SvgParts(SvgParts value)
 | 
						|
		{
 | 
						|
			this.AddRange(value);
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		///	 <para>
 | 
						|
		///	   Initializes a new instance of <see cref='SVGPart'/> containing any array of <see cref='SVGPart'/> objects.
 | 
						|
		///	</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='value'>
 | 
						|
		///	   A array of <see cref='SVGPart'/> objects with which to intialize the collection
 | 
						|
		/// </param>
 | 
						|
		public SvgParts(SvgPart[] value)
 | 
						|
		{
 | 
						|
			this.AddRange(value);
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		/// <para>Represents the entry at the specified index of the <see cref='SVGPart'/>.</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
 | 
						|
		/// <value>
 | 
						|
		///	<para> The entry at the specified index of the collection.</para>
 | 
						|
		/// </value>
 | 
						|
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
 | 
						|
		public SvgPart this[int index]
 | 
						|
		{
 | 
						|
			get { return ((SvgPart)(List[index])); }
 | 
						|
			set { List[index] = value; }
 | 
						|
		}
 | 
						|
		//#region SetupInheritance
 | 
						|
		//internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
 | 
						|
		//{
 | 
						|
		//  foreach (SvgPart svgPart in List)
 | 
						|
		//    svgPart.SetupInheritance(myParentsSettings);
 | 
						|
		//}
 | 
						|
		//#endregion
 | 
						|
		#region Dictionary of Parts
 | 
						|
		internal void AddLookup(Dictionary<string, SvgPart> lookUp)
 | 
						|
		{
 | 
						|
			foreach (SvgPart svgPart in List)
 | 
						|
				svgPart.AddLookup(lookUp);
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		internal static void ShowException(Exception ex)
 | 
						|
		{
 | 
						|
			StringBuilder sb = new StringBuilder();
 | 
						|
			string sep = "";
 | 
						|
			for (Exception ex1 = ex; ex1 != null; ex1 = ex1.InnerException)
 | 
						|
			{
 | 
						|
				sb.Append(sep + string.Format("ShowException {0} - {1}", ex1.GetType().Name, ex1.Message));
 | 
						|
				sep = "\r\n";
 | 
						|
			}
 | 
						|
			Console.WriteLine(sb);
 | 
						|
		}
 | 
						|
		/// <summary>
 | 
						|
		///	<para>Adds a <see cref='SVGPart'/> with the specified value to the 
 | 
						|
		///	<see cref='SVGPart'/> .</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='value'>The <see cref='SVGPart'/> to add.</param>
 | 
						|
		/// <returns>
 | 
						|
		///	<para>The index at which the new element was inserted.</para>
 | 
						|
		/// </returns>
 | 
						|
		/// <seealso cref='SVGParts.AddRange'/>
 | 
						|
		public int Add(SvgPart value)
 | 
						|
		{
 | 
						|
			int ndx = List.Add(value);
 | 
						|
			if (OnItemAdd != null) { OnItemAdd(this, new SVGPartArgs(value)); }
 | 
						|
			if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
 | 
						|
			return ndx;
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		/// <para>Copies the elements of an array to the end of the <see cref='SVGPart'/>.</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='value'>
 | 
						|
		///	An array of type <see cref='SVGPart'/> containing the objects to add to the collection.
 | 
						|
		/// </param>
 | 
						|
		/// <returns>
 | 
						|
		///   <para>None.</para>
 | 
						|
		/// </returns>
 | 
						|
		/// <seealso cref='SVGParts.Add'/>
 | 
						|
		public void AddRange(SvgPart[] value)
 | 
						|
		{
 | 
						|
			for (int i = 0; i < value.Length; i++)
 | 
						|
			{
 | 
						|
				this.Add(value[i]);
 | 
						|
			}
 | 
						|
			if (OnItemsAdd != null) { OnItemsAdd(this, new SVGPartArgs(value)); }
 | 
						|
			if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		///	 <para>
 | 
						|
		///	   Adds the contents of another <see cref='SVGPart'/> to the end of the collection.
 | 
						|
		///	</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='value'>
 | 
						|
		///	A <see cref='SVGPart'/> containing the objects to add to the collection.
 | 
						|
		/// </param>
 | 
						|
		/// <returns>
 | 
						|
		///   <para>None.</para>
 | 
						|
		/// </returns>
 | 
						|
		/// <seealso cref='SVGParts.Add'/>
 | 
						|
		public void AddRange(SvgParts value)
 | 
						|
		{
 | 
						|
			for (int i = 0; i < value.Count; i++)
 | 
						|
			{
 | 
						|
				this.Add(value[i]);
 | 
						|
			}
 | 
						|
			if (OnItemsAdd != null) { OnItemsAdd(this, new SVGPartArgs(value)); }
 | 
						|
			if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		/// <para>Gets a value indicating whether the 
 | 
						|
		///	<see cref='SVGPart'/> contains the specified <see cref='SVGPart'/>.</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='value'>The <see cref='SVGPart'/> to locate.</param>
 | 
						|
		/// <returns>
 | 
						|
		/// <para><see langword='true'/> if the <see cref='SVGPart'/> is contained in the collection; 
 | 
						|
		///   otherwise, <see langword='false'/>.</para>
 | 
						|
		/// </returns>
 | 
						|
		/// <seealso cref='SVGParts.IndexOf'/>
 | 
						|
		public bool Contains(SvgPart value)
 | 
						|
		{
 | 
						|
			return List.Contains(value);
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		/// <para>Copies the <see cref='SVGPart'/> values to a one-dimensional <see cref='System.Array'/> instance at the 
 | 
						|
		///	specified index.</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='SVGPart'/> .</para></param>
 | 
						|
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
 | 
						|
		/// <returns>
 | 
						|
		///   <para>None.</para>
 | 
						|
		/// </returns>
 | 
						|
		/// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='SVGPart'/> is greater than the available space between <paramref name='arrayIndex'/> and the end of <paramref name='array'/>.</para></exception>
 | 
						|
		/// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
 | 
						|
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
 | 
						|
		/// <seealso cref='System.Array'/>
 | 
						|
		public void CopyTo(SvgPart[] array, int index)
 | 
						|
		{
 | 
						|
			List.CopyTo(array, index);
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		///	<para>Returns the index of a <see cref='SVGPart'/> in 
 | 
						|
		///	   the <see cref='SVGPart'/> .</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='value'>The <see cref='SVGPart'/> to locate.</param>
 | 
						|
		/// <returns>
 | 
						|
		/// <para>The index of the <see cref='SVGPart'/> of <paramref name='value'/> in the 
 | 
						|
		/// <see cref='SVGPart'/>, if found; otherwise, -1.</para>
 | 
						|
		/// </returns>
 | 
						|
		/// <seealso cref='SVGParts.Contains'/>
 | 
						|
		public int IndexOf(SvgPart value)
 | 
						|
		{
 | 
						|
			return List.IndexOf(value);
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		/// <para>Inserts a <see cref='SVGPart'/> into the <see cref='SVGParts'/> at the specified index.</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='index'>The zero-based index where <paramref name='value'/> should be inserted.</param>
 | 
						|
		/// <param name=' value'>The <see cref='SVGPart'/> to insert.</param>
 | 
						|
		/// <returns><para>None.</para></returns>
 | 
						|
		/// <seealso cref='SVGParts.Add'/>
 | 
						|
		public void Insert(int index, SvgPart value)
 | 
						|
		{
 | 
						|
			List.Insert(index, value);
 | 
						|
			if (OnItemAdd != null) { OnItemAdd(this, new SVGPartArgs(value)); }
 | 
						|
			if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
 | 
						|
		}
 | 
						|
 | 
						|
		/// <summary>
 | 
						|
		///	<para> Removes a specific <see cref='SVGPart'/> from the 
 | 
						|
		///	<see cref='SVGParts'/> .</para>
 | 
						|
		/// </summary>
 | 
						|
		/// <param name='value'>The <see cref='SVGPart'/> to remove from the <see cref='SVGParts'/> .</param>
 | 
						|
		/// <returns><para>None.</para></returns>
 | 
						|
		/// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
 | 
						|
		public void Remove(SvgPart value)
 | 
						|
		{
 | 
						|
			List.Remove(value);
 | 
						|
			if (OnItemRemove != null) { OnItemRemove(this, new SVGPartArgs(value)); }
 | 
						|
			if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
 | 
						|
		}
 | 
						|
		#region ICustomTypeDescriptor impl
 | 
						|
		public String GetClassName()
 | 
						|
		{ return TypeDescriptor.GetClassName(this, true); }
 | 
						|
		public AttributeCollection GetAttributes()
 | 
						|
		{ return TypeDescriptor.GetAttributes(this, true); }
 | 
						|
		public String GetComponentName()
 | 
						|
		{ return TypeDescriptor.GetComponentName(this, true); }
 | 
						|
		public TypeConverter GetConverter()
 | 
						|
		{ return TypeDescriptor.GetConverter(this, true); }
 | 
						|
		public EventDescriptor GetDefaultEvent()
 | 
						|
		{ return TypeDescriptor.GetDefaultEvent(this, true); }
 | 
						|
		public PropertyDescriptor GetDefaultProperty()
 | 
						|
		{ return TypeDescriptor.GetDefaultProperty(this, true); }
 | 
						|
		public object GetEditor(Type editorBaseType)
 | 
						|
		{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
 | 
						|
		public EventDescriptorCollection GetEvents(Attribute[] attributes)
 | 
						|
		{ return TypeDescriptor.GetEvents(this, attributes, true); }
 | 
						|
		public EventDescriptorCollection GetEvents()
 | 
						|
		{ return TypeDescriptor.GetEvents(this, true); }
 | 
						|
		public object GetPropertyOwner(PropertyDescriptor pd)
 | 
						|
		{ return this; }
 | 
						|
		/// <summary>
 | 
						|
		/// Called to get the properties of this type. Returns properties with certain
 | 
						|
		/// attributes. this restriction is not implemented here.
 | 
						|
		/// </summary>
 | 
						|
		/// <param name="attributes"></param>
 | 
						|
		/// <returns></returns>
 | 
						|
		public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
 | 
						|
		{ return GetProperties(); }
 | 
						|
		/// <summary>
 | 
						|
		/// Called to get the properties of this type.
 | 
						|
		/// </summary>
 | 
						|
		/// <returns></returns>
 | 
						|
		public PropertyDescriptorCollection GetProperties()
 | 
						|
		{
 | 
						|
			// Create a collection object to hold property descriptors
 | 
						|
			PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
 | 
						|
			// Iterate the list 
 | 
						|
			for (int i = 0; i < this.Count; i++)
 | 
						|
			{
 | 
						|
				// Create a property descriptor for the item and add to the property descriptor collection
 | 
						|
				SvgPartsPropertyDescriptor pd = new SvgPartsPropertyDescriptor(this, i);
 | 
						|
				pds.Add(pd);
 | 
						|
			}
 | 
						|
			// return the property descriptor collection
 | 
						|
			return pds;
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
 | 
						|
		/// Event arguments for the SVGParts collection class.
 | 
						|
		public class SVGPartArgs : EventArgs
 | 
						|
		{
 | 
						|
			private SvgParts t;
 | 
						|
 | 
						|
			/// Default constructor.
 | 
						|
			public SVGPartArgs()
 | 
						|
			{
 | 
						|
				t = new SvgParts();
 | 
						|
			}
 | 
						|
 | 
						|
			/// Initializes with a SVGPart.
 | 
						|
			/// Data object.
 | 
						|
			public SVGPartArgs(SvgPart t)
 | 
						|
				: this()
 | 
						|
			{
 | 
						|
				this.t.Add(t);
 | 
						|
			}
 | 
						|
 | 
						|
			/// Initializes with a collection of SVGPart objects.
 | 
						|
			/// Collection of data.
 | 
						|
			public SVGPartArgs(SvgParts ts)
 | 
						|
				: this()
 | 
						|
			{
 | 
						|
				this.t.AddRange(ts);
 | 
						|
			}
 | 
						|
 | 
						|
			/// Initializes with an array of SVGPart objects.
 | 
						|
			/// Array of data.
 | 
						|
			public SVGPartArgs(SvgPart[] ts)
 | 
						|
				: this()
 | 
						|
			{
 | 
						|
				this.t.AddRange(ts);
 | 
						|
			}
 | 
						|
 | 
						|
			/// Gets or sets the data of this argument.
 | 
						|
			public SvgParts SVGParts
 | 
						|
			{
 | 
						|
				get { return t; }
 | 
						|
				set { t = value; }
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		/// SVGParts event handler.
 | 
						|
		public delegate void SVGPartHandler(object sender, SVGPartArgs e);
 | 
						|
		#region Property Descriptor
 | 
						|
		/// <summary>
 | 
						|
		/// Summary description for CollectionPropertyDescriptor.
 | 
						|
		/// </summary>
 | 
						|
		public partial class SvgPartsPropertyDescriptor : vlnListPropertyDescriptor
 | 
						|
		{
 | 
						|
			private SvgPart Item { get { return (SvgPart)_Item; } }
 | 
						|
			public SvgPartsPropertyDescriptor(SvgParts collection, int index) : base(collection, index) { ;}
 | 
						|
			public override string DisplayName
 | 
						|
			{ get { return Item.GetType().Name; } }
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		[Serializable()]
 | 
						|
		public partial class vlnListPropertyDescriptor : PropertyDescriptor
 | 
						|
		{
 | 
						|
			protected object _Item = null;
 | 
						|
			public vlnListPropertyDescriptor(System.Collections.IList collection, int index)
 | 
						|
				: base("#" + index.ToString(), null)
 | 
						|
			{ _Item = collection[index]; }
 | 
						|
			public override bool CanResetValue(object component)
 | 
						|
			{ return true; }
 | 
						|
			public override Type ComponentType
 | 
						|
			{ get { return _Item.GetType(); } }
 | 
						|
			public override object GetValue(object component)
 | 
						|
			{ return _Item; }
 | 
						|
			public override bool IsReadOnly
 | 
						|
			{ get { return false; } }
 | 
						|
			public override Type PropertyType
 | 
						|
			{ get { return _Item.GetType(); } }
 | 
						|
			public override void ResetValue(object component)
 | 
						|
			{ ;}
 | 
						|
			public override bool ShouldSerializeValue(object component)
 | 
						|
			{ return true; }
 | 
						|
			public override void SetValue(object component, object value)
 | 
						|
			{ /*_Item = value*/;}
 | 
						|
			//public override AttributeCollection Attributes
 | 
						|
			//{ get { return new AttributeCollection(null); } }
 | 
						|
			public override string DisplayName
 | 
						|
			{ get { return _Item.ToString(); } }
 | 
						|
			public override string Description
 | 
						|
			{ get { return _Item.ToString(); } }
 | 
						|
			public override string Name
 | 
						|
			{ get { return _Item.ToString(); } }
 | 
						|
 | 
						|
		} // Class
 | 
						|
		#region Converter
 | 
						|
		internal class SVGPartsConverter : ExpandableObjectConverter
 | 
						|
		{
 | 
						|
			public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
 | 
						|
			{
 | 
						|
				if (destType == typeof(string) && value is SvgParts)
 | 
						|
				{
 | 
						|
					// Return department and department role separated by comma.
 | 
						|
					return ((SvgParts)value).List.Count.ToString() + " SVG Drawing Parts";
 | 
						|
				}
 | 
						|
				return base.ConvertTo(context, culture, value, destType);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
 | 
						|
	}
 | 
						|
} |