// ------------------------------------------------------------------------------
// <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.Ifc4.Interfaces;
using System.Collections.Generic;
using System.Linq;
using Xbim.Common;

// ReSharper disable once CheckNamespace
namespace Xbim.Ifc2x3.ProductExtension
{
	public partial class @IfcSpace : IIfcSpace
	{

		private  Ifc4.Interfaces.IfcSpaceTypeEnum? _predefinedType;


		[CrossSchemaAttribute(typeof(IIfcSpace), 10)]
		Ifc4.Interfaces.IfcSpaceTypeEnum? IIfcSpace.PredefinedType 
		{ 
			get
			{
				return _predefinedType;
			} 
			set
			{
				SetValue(v => _predefinedType = v, _predefinedType, value, "PredefinedType", -10);
				
			}
		}

		[CrossSchemaAttribute(typeof(IIfcSpace), 11)]
		Ifc4.MeasureResource.IfcLengthMeasure? IIfcSpace.ElevationWithFlooring 
		{ 
			get
			{
				if (!ElevationWithFlooring.HasValue) return null;
				return new Ifc4.MeasureResource.IfcLengthMeasure(ElevationWithFlooring.Value);
			} 
			set
			{
				ElevationWithFlooring = value.HasValue ? 
					new MeasureResource.IfcLengthMeasure(value.Value) :  
					 new MeasureResource.IfcLengthMeasure?() ;
				
			}
		}

		[CrossSchemaAttribute(typeof(IIfcSpace), 8)]
		Ifc4.MeasureResource.IfcLabel? IIfcSpatialElement.LongName 
		{ 
			get
			{
				if (!LongName.HasValue) return null;
				return new Ifc4.MeasureResource.IfcLabel(LongName.Value);
			} 
			set
			{
				LongName = value.HasValue ? 
					new MeasureResource.IfcLabel(value.Value) :  
					 new MeasureResource.IfcLabel?() ;
				
			}
		}
		IEnumerable<IIfcRelCoversSpaces> IIfcSpace.HasCoverings 
		{ 
			get
			{
				return Model.Instances.Where<IIfcRelCoversSpaces>(e => (e.RelatingSpace as IfcSpace) == this, "RelatingSpace", this);
			} 
		}
		IEnumerable<IIfcRelSpaceBoundary> IIfcSpace.BoundedBy 
		{ 
			get
			{
				return Model.Instances.Where<IIfcRelSpaceBoundary>(e => (e.RelatingSpace as IfcSpace) == this, "RelatingSpace", this);
			} 
		}
		IEnumerable<IIfcRelContainedInSpatialStructure> IIfcSpatialElement.ContainsElements 
		{ 
			get
			{
				return Model.Instances.Where<IIfcRelContainedInSpatialStructure>(e => (e.RelatingStructure as IfcSpace) == this, "RelatingStructure", this);
			} 
		}
		IEnumerable<IIfcRelServicesBuildings> IIfcSpatialElement.ServicedBySystems 
		{ 
			get
			{
				return Model.Instances.Where<IIfcRelServicesBuildings>(e => e.RelatedBuildings != null &&  e.RelatedBuildings.Contains(this), "RelatedBuildings", this);
			} 
		}
		IEnumerable<IIfcRelReferencedInSpatialStructure> IIfcSpatialElement.ReferencesElements 
		{ 
			get
			{
				return Model.Instances.Where<IIfcRelReferencedInSpatialStructure>(e => (e.RelatingStructure as IfcSpace) == this, "RelatingStructure", this);
			} 
		}
	//## Custom code
        /// <summary>
        /// Returns all spaces that are sub-spaces of this space
        /// </summary>
        /// <returns></returns>
        public IEnumerable<IIfcSpace> Spaces
        {
            get
            {
                return IsDecomposedBy.SelectMany(s => s.RelatedObjects).OfType<IfcSpace>();
            }
        }
	//##
	}
}