qin
2024-09-28 e358beb08f5be49703009b64f058ecfbcfeefbd9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Autodesk.Revit.DB;
using HStation.RevitDev.Model.AttributeClass;
using HStation.RevitDev.Model.ModelEnum;
using HStation.RevitDev.RevitDataExport.Common;
using HStation.RevitDev.RevitDataExport.Entity;
using HStation.RevitDev.RevitDataExport.Entity.ElementModels;
using HStation.RevitDev.RevitDataExport.Parser;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
 
namespace HStation.RevitDev.RevitDataExport.Utility
{
    internal class ModelFactory
    {
        public ModelFactory() { }
        public static ElementModel CreateModel(RevitType revitType, Element element)
        {
            BaseParser parser = revitType.CreateModelParser();
            var ret = new ElementModel();
            if (parser == null) { return ret; }
 
            ret = parser.Parse(element);
            return ret;
        }
 
        public static List<T> Convert2Sub<T>(List<string> ids) where T : ElementModel
        {
            var ret = new List<T>();
            foreach (var id in ids)
            {
                var elem = GlobalResource.CurrentDocument.GetElement(new ElementId(int.Parse(id)));
                if (elem == null) { continue; }
 
                var attr = typeof(T).GetCustomAttribute<RevitTypeAttribute>();
                if (attr == null) { continue; }
 
                var parser = attr.m_revitType.GetParser();
                if (parser == null) { continue; }
 
                T model = parser.Parse(elem) as T;
                ret.Add(model);
            }
            return ret;
        }
 
        public static List<OtherModel> Convert2Others(List<string> ids)
        {
            var ret = new List<OtherModel>();
            foreach (var id in ids)
            {
                var elem = GlobalResource.CurrentDocument.GetElement(new ElementId(int.Parse(id)));
                if (elem == null) { continue; }
 
                var parser = new QitaParser();
                OtherModel model = parser.Parse(elem) as OtherModel;
                ret.Add(model);
            }
            return ret;
        }
    }
}