/*-------------------------------------------------------------------------
 * 功能描述：ParseColumn
 * 作者：xulisong
 * 创建时间： 2019/6/24 9:49:28
 * 版本号：v1.0
 *  -------------------------------------------------------------------------*/

using Autodesk.Revit.DB;
using JBIM;
using RevitExport.Export;
using RevitToJBim.Common;
using System;
using System.Collections.Generic;
using JFamilyType = RevitToJBim.Common.FamilyType;
using JColumn =JBIM.Component.Column;
using SAGA.RevitUtils.Extends;
using SAGA.RevitUtils.Extends.Graphic;
using System.Linq;
using JBIM.Definition;
using RevitToJBim.Extension;

namespace RevitToJBim.ComponentParse
{
    [UsableParse]
    public class ParseColumn : ParseBase
    {
        public override List<string> FastIndex()
        {
            return new List<string>() { CategoryGenerator.BuildingCategory(JFamilyType.Column) };
        }
        public override bool Match(ElementWrapper wrapper)
        {
            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Column);
        }
        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
        {
            if (!(wrapper.RefElement is FamilyInstance familyInstance))
            {
                return null;
            }
            JColumn jObject = new JColumn();
            ParseCore.AttachObject(jObject, wrapper);
            jObject.Location = ParseCore.GetLocation(familyInstance.Location);
            //FamilyName
            jObject.FamilyName = familyInstance.GetFamilyName();
            jObject.FamilySymbol = familyInstance.GetFamilySymbolName();
            var polygonPath = RevitUtil.GetTopPolygon(familyInstance);
            if (polygonPath != null && polygonPath.Any())
            {
                Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath,true));
                StandardUtil.ArrangeLoop(outLine);
                jObject.OutLine.Add(outLine);
            }

            var parameter = familyInstance.GetParameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING);
            if (parameter != null)
            {
                jObject.RoomBoundary=parameter.AsInteger() == 1;
            }
            context.AddBimObject(jObject);          
            return new List<BimId>() { jObject.Id };
        }
    }
}
