// ------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool Xbim.CodeGeneration 
//  
//     Changes to this file may cause incorrect behaviour and will be lost if
//     the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------

using Xbim.Ifc4x3.MeasureResource;
using System;
using System.Collections.Generic;
using System.Linq;
using Xbim.Common;
using Xbim.Common.Exceptions;
using Xbim.Ifc4x3.GeometryResource;
//## Custom using statements
//##


namespace Xbim.Ifc4x3.GeometryResource
{
	[ExpressType("IfcBSplineSurfaceWithKnots", 1103)]
	// ReSharper disable once PartialTypeWithSinglePart
	public  partial class @IfcBSplineSurfaceWithKnots : IfcBSplineSurface, IInstantiableEntity, IContainsEntityReferences, IEquatable<@IfcBSplineSurfaceWithKnots>
	{

		//internal constructor makes sure that objects are not created outside of the model/ assembly controlled area
		internal IfcBSplineSurfaceWithKnots(IModel model, int label, bool activated) : base(model, label, activated)  
		{
			_uMultiplicities = new ItemSet<IfcInteger>( this, 0,  8);
			_vMultiplicities = new ItemSet<IfcInteger>( this, 0,  9);
			_uKnots = new ItemSet<IfcParameterValue>( this, 0,  10);
			_vKnots = new ItemSet<IfcParameterValue>( this, 0,  11);
		}

		#region Explicit attribute fields
		private readonly ItemSet<IfcInteger> _uMultiplicities;
		private readonly ItemSet<IfcInteger> _vMultiplicities;
		private readonly ItemSet<IfcParameterValue> _uKnots;
		private readonly ItemSet<IfcParameterValue> _vKnots;
		private IfcKnotType _knotSpec;
		#endregion
	
		#region Explicit attribute properties
		[EntityAttribute(8, EntityAttributeState.Mandatory, EntityAttributeType.List, EntityAttributeType.None, new int [] { 2 }, new int [] { -1 }, 10)]
		public IItemSet<IfcInteger> @UMultiplicities 
		{ 
			get 
			{
				if(_activated) return _uMultiplicities;
				Activate();
				return _uMultiplicities;
			} 
		}	
		[EntityAttribute(9, EntityAttributeState.Mandatory, EntityAttributeType.List, EntityAttributeType.None, new int [] { 2 }, new int [] { -1 }, 11)]
		public IItemSet<IfcInteger> @VMultiplicities 
		{ 
			get 
			{
				if(_activated) return _vMultiplicities;
				Activate();
				return _vMultiplicities;
			} 
		}	
		[EntityAttribute(10, EntityAttributeState.Mandatory, EntityAttributeType.List, EntityAttributeType.None, new int [] { 2 }, new int [] { -1 }, 12)]
		public IItemSet<IfcParameterValue> @UKnots 
		{ 
			get 
			{
				if(_activated) return _uKnots;
				Activate();
				return _uKnots;
			} 
		}	
		[EntityAttribute(11, EntityAttributeState.Mandatory, EntityAttributeType.List, EntityAttributeType.None, new int [] { 2 }, new int [] { -1 }, 13)]
		public IItemSet<IfcParameterValue> @VKnots 
		{ 
			get 
			{
				if(_activated) return _vKnots;
				Activate();
				return _vKnots;
			} 
		}	
		[EntityAttribute(12, EntityAttributeState.Mandatory, EntityAttributeType.Enum, EntityAttributeType.None, null, null, 14)]
		public IfcKnotType @KnotSpec 
		{ 
			get 
			{
				if(_activated) return _knotSpec;
				Activate();
				return _knotSpec;
			} 
			set
			{
				SetValue( v =>  _knotSpec = v, _knotSpec, value,  "KnotSpec", 12);
			} 
		}	
		#endregion


		#region Derived attributes
		[EntityAttribute(0, EntityAttributeState.Derived, EntityAttributeType.None, EntityAttributeType.None, null, null, 0)]
		public IfcInteger @KnotVUpper 
		{
			get 
			{
				//## Getter for KnotVUpper
				return VKnots.Count;
				//##
			}
		}

		[EntityAttribute(0, EntityAttributeState.Derived, EntityAttributeType.None, EntityAttributeType.None, null, null, 0)]
		public IfcInteger @KnotUUpper 
		{
			get 
			{
				//## Getter for KnotUUpper
			    return UKnots.Count;
				//##
			}
		}

		#endregion


		#region IPersist implementation
		public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
		{
			switch (propIndex)
			{
				case 0: 
				case 1: 
				case 2: 
				case 3: 
				case 4: 
				case 5: 
				case 6: 
					base.Parse(propIndex, value, nestedIndex); 
					return;
				case 7: 
					_uMultiplicities.InternalAdd(value.IntegerVal);
					return;
				case 8: 
					_vMultiplicities.InternalAdd(value.IntegerVal);
					return;
				case 9: 
					_uKnots.InternalAdd(value.RealVal);
					return;
				case 10: 
					_vKnots.InternalAdd(value.RealVal);
					return;
				case 11: 
                    _knotSpec = (IfcKnotType) System.Enum.Parse(typeof (IfcKnotType), value.EnumVal, true);
					return;
				default:
					throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, GetType().Name.ToUpper()));
			}
		}
		#endregion

		#region Equality comparers and operators
        public bool Equals(@IfcBSplineSurfaceWithKnots other)
	    {
	        return this == other;
	    }
        #endregion

		#region IContainsEntityReferences
		IEnumerable<IPersistEntity> IContainsEntityReferences.References 
		{
			get 
			{
				foreach (var item in @ControlPointsList)
					foreach (var entity in item)
						yield return entity;
			}
		}
		#endregion

		#region Custom code (will survive code regeneration)
		//## Custom code
		//##
		#endregion
	}
}