Parcourir la source

xls:修改Location信息

xulisong il y a 5 ans
Parent
commit
82569fcadc

+ 2 - 2
JBIM/JBIM/Component/VisibleComponentObject.cs

@@ -20,13 +20,13 @@ namespace JBIM.Component
     {
         public VisibleComponentObject()
         {
-            Location = new List<XYZ>();
+            //Location = new List<XYZ>();
             OutLine = new List<Polygon>();
         }
         /// <summary>
         /// 定位信息
         /// </summary>
-        public List<XYZ> Location { get; private set; }
+        public GeometryLocation Location { get;  set; }
         /// <summary>
         /// 轮廓信息
         /// </summary>

+ 50 - 0
JBIM/JBIM/Definition/GeometryLocation.cs

@@ -0,0 +1,50 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:GeometryLocation
+ * 作者:xulisong
+ * 创建时间: 2019/6/19 16:43:58
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JBIM
+{
+    /// <summary>
+    /// 定位类型
+    /// </summary>
+    public enum LocationType
+    {
+        Point,
+        Line,
+        Arc,
+        Common
+    }
+    public class GeometryLocation
+    {
+        public GeometryLocation(LocationType type)
+        {
+            Type = type;
+            Points = new List<XYZ>();
+        }
+        public LocationType Type { get; set; }
+        public List<XYZ> Points { get;private set; }
+
+        public static GeometryLocation CreatePointLocation(XYZ xyz)
+        {
+            var result = new GeometryLocation(LocationType.Line);
+            result.Points.Add(xyz);
+            return result;
+        }
+
+        public static GeometryLocation CreateLineLocation(List<XYZ> xyzes)
+        {
+            var result = new GeometryLocation(LocationType.Line);
+            result.Points.AddRange(xyzes);
+            return result;
+        }
+    }
+}

+ 5 - 0
JBIM/JBIM/Definition/XYZ.cs

@@ -18,6 +18,11 @@ namespace JBIM
         public double X { get; set; }
         public double Y { get; set; }
         public double Z { get; set; }
+
+        public override string ToString()
+        {
+            return $"{X},{Y},{Z}";
+        }
     }
     public class XY
     {

+ 1 - 0
JBIM/JBIM/JBIM.csproj

@@ -69,6 +69,7 @@
     <Compile Include="Component\Space.cs" />
     <Compile Include="Component\VisibleComponentObject.cs" />
     <Compile Include="Definition\ConnectorShape.cs" />
+    <Compile Include="Definition\GeometryLocation.cs" />
     <Compile Include="Definition\XYZ.cs" />
     <Compile Include="Geometry\GeometryObject.cs" />
     <Compile Include="Properties\AssemblyInfo.cs">

+ 5 - 3
JBIM/RevitToJBim/ComponentParse/ParsePipe.cs

@@ -46,9 +46,11 @@ namespace RevitToJBim.ComponentParse
             JPipe jPipe = new JPipe();
             ParseCore.AttachObject(jPipe, wrapper);
             jPipe.Diameter = BimConvert.Round(pipe.Diameter.FromApi());
-            jPipe.Location.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().StartPoint()));
-            jPipe.Location.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().EndPoint()));
-            Polygon outLine = new Polygon(jPipe.Location);
+            var locations = new List<XYZ>();
+            locations.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().StartPoint()));
+            locations.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().EndPoint()));
+            jPipe.Location = GeometryLocation.CreateLineLocation(locations);
+            Polygon outLine = new Polygon(locations);
             jPipe.OutLine.Add(outLine);
             context.AddBimObject(jPipe);
             #region 关联数据处理相关

+ 3 - 2
JBIM/RevitToJBim/ComponentParse/ParseSpace.cs

@@ -44,8 +44,9 @@ namespace RevitToJBim.ComponentParse
             //}
             JSpace bimObject = new JSpace();
             ParseCore.AttachObject(bimObject, wrapper);
-            bimObject.Location.Add(BimConvert.ConvertToXYZ(space.Location.GetPoint()));
-
+            //bimObject.Location.Add(BimConvert.ConvertToXYZ(space.Location.GetPoint()));
+            bimObject.Location =
+                GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(space.Location.GetPoint()));
             var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
             if (segments != null)
             {

+ 3 - 0
JBIM/RevitToJBim/JsonConverter/BimJsonUtil.cs

@@ -12,6 +12,7 @@ using System.Text;
 using System.Threading.Tasks;
 using JBIM;
 using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
 
 namespace RevitToJBim.JsonConverter
 {
@@ -21,6 +22,8 @@ namespace RevitToJBim.JsonConverter
         {
             JsonSerializerSettings jsetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
             jsetting.Converters.Add(new BimIdConverter());
+            jsetting.Converters.Add(new XYZConverter());
+            jsetting.Converters.Add(new StringEnumConverter());
             //var serializer = JsonSerializer.Create(jsetting);
             //JObject jobject = new JObject();
             //foreach (var collection in m_DataSource)

+ 40 - 0
JBIM/RevitToJBim/JsonConverter/XYZConverter.cs

@@ -0,0 +1,40 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:XYZConverter
+ * 作者:xulisong
+ * 创建时间: 2019/6/19 16:40:15
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM;
+using Newtonsoft.Json;
+
+namespace RevitToJBim.JsonConverter
+{
+    public class XYZConverter : Newtonsoft.Json.JsonConverter
+    {
+        public override bool CanConvert(Type objectType)
+        {
+            return objectType == typeof(XYZ);
+        }
+
+        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+        {
+            if (value == null)
+            {
+                writer.WriteNull();
+                return;
+            }
+            writer.WriteValue(value.ToString());
+        }
+    }
+}

+ 1 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -71,6 +71,7 @@
     <Compile Include="ComponentParse\UsableParseAttribute.cs" />
     <Compile Include="JsonConverter\BimIdConverter.cs" />
     <Compile Include="JsonConverter\BimJsonUtil.cs" />
+    <Compile Include="JsonConverter\XYZConverter.cs" />
     <Compile Include="ParseData\ElementRelationShip.cs" />
     <Compile Include="ParseData\ElementOneToManyRel.cs" />
     <Compile Include="ParseData\ElementOneToOneRel.cs" />