/*-------------------------------------------------------------------------
 * 功能描述：ParseWindow
 * 作者：xulisong
 * 创建时间： 2019/6/25 17:52:58
 * 版本号：v1.0
 *  -------------------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using JBIM;
using JBIM.Component;
using JBIM.Definition;
using RevitExport.Export;
using RevitToJBim.Common;
using RevitToJBim.Extension;
using JFamilyType = RevitToJBim.Common.FamilyType;
namespace RevitToJBim.ComponentParse
{
    [UsableParse]
    public class ParseWindow : ParseBase
    {
        public override List<string> FastIndex()
        {
            return new List<string>() { CategoryGenerator.BuildingCategory(JFamilyType.Window) };
        }
        public override bool Match(ElementWrapper wrapper)
        {
            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Window);
        }


        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
        {
            if (!(wrapper.RefElement is FamilyInstance fi))
            {
                return null;
            }
            Window jObject = new Window();
            ParseCore.AttachObject(jObject, wrapper);
            context.AddBimObject(jObject);
            jObject.Location = ParseCore.GetLocation(fi.Location);
            //FamilyName
            jObject.FamilyName = fi.GetFamilyName();
            jObject.FamilySymbol = fi.GetFamilySymbolName();
            if (fi.Host != null)
            {
                jObject.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(fi.Host))?.FirstOrDefault();
                jObject.Thick= (fi.Host as Autodesk.Revit.DB.Wall).Width.FtToUse();
            }
            var polygonPath = RevitUtil.GetWindowDoorLocation(fi);
            if (polygonPath != null && polygonPath.Any())
            {
                Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath,true));
                jObject.OutLine.Add(outLine);
            }
           
            return new List<BimId>() { jObject.Id };
        }

    }
}
