123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using JBIM;
- using JBIM.Component;
- using JBIM.Definition;
- using RevitExport;
- using RevitExport.Export;
- using RevitToJBim.Common;
- using RevitToJBim.ParseData;
- using SAGA.RevitUtils.Extends;
- using JConnector = JBIM.Component.Connector;
- namespace RevitToJBim.ComponentParse
- {
-
-
-
-
- public class ParseCore
- {
-
- public static List<ParseBase> GetUseParsers()
- {
- List<ParseBase> result = new List<ParseBase>();
- Assembly assembly = Assembly.GetCallingAssembly();
- Type[] types = assembly.GetTypes();
- foreach (var type in types)
- {
- if (typeof(ParseBase).IsAssignableFrom (type))
- {
- if (type.IsAbstract || type.IsGenericTypeDefinition)
- continue;
- var attribute = type.GetCustomAttribute<UsableParseAttribute>();
- if (attribute == null)
- continue;
- var construstor = type.GetConstructor(Type.EmptyTypes);
- if (construstor == null)
- continue;
- if (construstor.Invoke(null) is ParseBase parse)
- result.Add(parse);
- }
- }
- return result;
- }
-
- public static void AttachObject(ComponentObject bimObj, ElementWrapper wrapper)
- {
- bimObj.SourceId = wrapper.SourceId;
- bimObj.Name = wrapper.RefElement?.Name;
- }
- public static JConnector CreateConnector(Autodesk.Revit.DB.Connector connector)
- {
- var result= new JConnector();
- result.SourceId = RevitIdGenerator.GetConnectorId(connector);
- switch (connector.Domain)
- {
- case Domain.DomainHvac:
- {
- result.Domain = ConnectorDomain.DomainHvac.ToString();
- break;
- }
- case Domain.DomainPiping:
- {
- result.Domain = ConnectorDomain.DomainPiping.ToString();
- break;
- }
- }
- result.IsConnected = connector.IsConnected;
- result.Description = connector.Description;
- result.Origin = BimConvert.ConvertToXYZ(connector.Origin);
- return result;
- }
-
-
-
-
-
- public static ElementWrapper GetConnectorWrapper(Autodesk.Revit.DB.Connector connector)
- {
- ElementWrapper wrapper = new ElementWrapper(connector, RevitIdGenerator.GetConnectorId(connector));
- return wrapper;
- }
-
-
-
-
-
-
- public static ElementOneToManyRel GetConnectorRels(Element element,List<Autodesk.Revit.DB.Connector> connectors)
- {
- ElementOneToManyRel relMany = new ElementOneToManyRel(element.Id.ToString()) { RelatedObjects = new List<string>() };
- relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
- foreach (var refConnector in connectors)
- {
- relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
- }
- if (relMany.RelatedObjects.Any())
- {
- return relMany;
- }
- return null;
- }
-
-
-
-
-
- public static GeometryLocation GetLocation(Location location)
- {
- if (location == null)
- return null;
- if (location is LocationPoint point)
- {
- var usePoint = point.Point;
- return GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(usePoint));
- }
- else if (location is LocationCurve curve)
- {
- var points = curve.Curve.GetPoints();
- if (curve.Curve is Line)
- return GeometryLocation.CreateLineLocation(BimConvert.ConvertToXYZs(points));
- else if (curve.Curve is Arc)
- return GeometryLocation.CreateArcLocation(BimConvert.ConvertToXYZs(points));
- }
- return null;
- }
- }
- }
|