| | |
| | | /// <summary> |
| | | /// 从json字符串中解析 |
| | | /// </summary> |
| | | /// <param name="revitJsonString">json字符串</param> |
| | | /// <returns>格式错误,会抛出异常</returns> |
| | | public static HStation.Model.RevitModel FromJsonString(string revitJsonString, out string msg) |
| | | public static HStation.Model.RevitModel FromJsonString |
| | | ( |
| | | string revitJsonString, |
| | | string revitOthersJsonString, |
| | | out string msg |
| | | ) |
| | | { |
| | | msg = string.Empty; |
| | | if (string.IsNullOrEmpty(revitJsonString)) |
| | |
| | | { |
| | | var model = new Model.RevitModel(); |
| | | |
| | | //解析结构json |
| | | var jarray = JArray.Parse(revitJsonString); |
| | | for (int i = 0; i < jarray.Count; i++) |
| | | { |
| | |
| | | reservoir.Head = head; |
| | | } |
| | | reservoir.HeadPattern = jobject[RevitJsonProp.HeadPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(reservoir.HeadPattern)) |
| | | { |
| | | reservoir.HeadPattern = string.Empty; |
| | | } |
| | | model.Reservoirs.Add(reservoir); |
| | | } |
| | | break; |
| | |
| | | tank.MinVol = minVol; |
| | | } |
| | | tank.VolCurve = jobject[RevitJsonProp.VolCurve].ToString(); |
| | | if (!string.IsNullOrEmpty(tank.VolCurve)) |
| | | { |
| | | tank.VolCurve = string.Empty; |
| | | } |
| | | model.Tanks.Add(tank); |
| | | } |
| | | break; |
| | |
| | | waterbox.MinVol = minVol; |
| | | } |
| | | waterbox.VolCurve = jobject[RevitJsonProp.VolCurve].ToString(); |
| | | if (!string.IsNullOrEmpty(waterbox.VolCurve)) |
| | | { |
| | | waterbox.VolCurve = string.Empty; |
| | | } |
| | | model.Waterboxs.Add(waterbox); |
| | | } |
| | | break; |
| | |
| | | junction.Demand = demand; |
| | | } |
| | | junction.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(junction.DemandPattern)) |
| | | { |
| | | junction.DemandPattern = string.Empty; |
| | | } |
| | | model.Junctions.Add(junction); |
| | | } |
| | | break; |
| | |
| | | elbow.Demand = demand; |
| | | } |
| | | elbow.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(elbow.DemandPattern)) |
| | | { |
| | | elbow.DemandPattern = string.Empty; |
| | | } |
| | | model.Elbows.Add(elbow); |
| | | } |
| | | break; |
| | |
| | | threelink.Demand = demand; |
| | | } |
| | | threelink.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(threelink.DemandPattern)) |
| | | { |
| | | threelink.DemandPattern = string.Empty; |
| | | } |
| | | model.Threelinks.Add(threelink); |
| | | } |
| | | break; |
| | |
| | | fourlink.Demand = demand; |
| | | } |
| | | fourlink.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(fourlink.DemandPattern)) |
| | | { |
| | | fourlink.DemandPattern = string.Empty; |
| | | } |
| | | model.Fourlinks.Add(fourlink); |
| | | } |
| | | break; |
| | |
| | | meter.Demand = demand; |
| | | } |
| | | meter.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(meter.DemandPattern)) |
| | | { |
| | | meter.DemandPattern = string.Empty; |
| | | } |
| | | model.Meters.Add(meter); |
| | | } |
| | | break; |
| | |
| | | flowmeter.Demand = demand; |
| | | } |
| | | flowmeter.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(flowmeter.DemandPattern)) |
| | | { |
| | | flowmeter.DemandPattern = string.Empty; |
| | | } |
| | | model.Flowmeters.Add(flowmeter); |
| | | } |
| | | break; |
| | |
| | | pressmeter.Demand = demand; |
| | | } |
| | | pressmeter.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(pressmeter.DemandPattern)) |
| | | { |
| | | pressmeter.DemandPattern = string.Empty; |
| | | } |
| | | model.Pressmeters.Add(pressmeter); |
| | | } |
| | | break; |
| | |
| | | blunthead.Demand = demand; |
| | | } |
| | | blunthead.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(blunthead.DemandPattern)) |
| | | { |
| | | blunthead.DemandPattern = string.Empty; |
| | | } |
| | | model.Bluntheads.Add(blunthead); |
| | | } |
| | | break; |
| | |
| | | nozzle.Demand = demand; |
| | | } |
| | | nozzle.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(nozzle.DemandPattern)) |
| | | { |
| | | nozzle.DemandPattern = string.Empty; |
| | | } |
| | | if (jobject[RevitJsonProp.CoefficientP].MatchNumeric(out double coeffient)) |
| | | { |
| | | nozzle.Coefficient = coeffient; |
| | |
| | | hydrant.Demand = demand; |
| | | } |
| | | hydrant.DemandPattern = jobject[RevitJsonProp.DemandPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(hydrant.DemandPattern)) |
| | | { |
| | | hydrant.DemandPattern = string.Empty; |
| | | } |
| | | if (jobject[RevitJsonProp.CoefficientF].MatchNumeric(out double coeffient)) |
| | | { |
| | | hydrant.Coefficient = coeffient; |
| | |
| | | } |
| | | if (exchanger.Diameter < 0.1) |
| | | { |
| | | exchanger.Diameter = 0.1; |
| | | exchanger.Diameter = 500; |
| | | } |
| | | if (exchanger.Roughness < 0.1) |
| | | { |
| | | exchanger.Roughness = 0.1; |
| | | exchanger.Roughness = 110; |
| | | } |
| | | model.Exchangers.Add(exchanger); |
| | | } |
| | |
| | | { |
| | | pipe.Length = length; |
| | | } |
| | | |
| | | |
| | | #region 直径 |
| | | |
| | | if (jobject[RevitJsonProp.Diameter].MatchNumeric(out double diameter)) |
| | | { |
| | | pipe.Diameter = diameter; |
| | | } |
| | | else if (jobject[RevitJsonProp.InternalDiameter].MatchNumeric(out double internalDiameter)) |
| | | |
| | | if (pipe.Diameter < 1) |
| | | { |
| | | pipe.Diameter = internalDiameter; |
| | | if (jobject[RevitJsonProp.InternalDiameter].MatchNumeric(out double internalDiameter)) |
| | | { |
| | | pipe.Diameter = internalDiameter; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | if (jobject[RevitJsonProp.MinorLoss].MatchNumeric(out double minorLoss)) |
| | | { |
| | | pipe.MinorLoss = minorLoss; |
| | |
| | | } |
| | | if (pipe.Diameter < 0.1) |
| | | { |
| | | pipe.Diameter = 0.1; |
| | | pipe.Diameter = 500; |
| | | } |
| | | if (pipe.Roughness < 0.1) |
| | | { |
| | | pipe.Roughness = 0.1; |
| | | pipe.Roughness = 110; |
| | | } |
| | | model.Pipes.Add(pipe); |
| | | } |
| | |
| | | } |
| | | if (translation.Diameter < 0.1) |
| | | { |
| | | translation.Diameter = 0.1; |
| | | translation.Diameter = 500; |
| | | } |
| | | if (translation.Roughness < 0.1) |
| | | { |
| | | translation.Roughness = 0.1; |
| | | translation.Roughness = 110; |
| | | } |
| | | model.Translations.Add(translation); |
| | | } |
| | |
| | | pump.RatedPower = ratedPower; |
| | | } |
| | | pump.CurveQH = jobject[RevitJsonProp.CurveQH].ToString(); |
| | | pump.CurveQH = "PumpDefault"; |
| | | if (jobject[RevitJsonProp.SpeedRatio].MatchNumeric(out double speedRatio)) |
| | | { |
| | | pump.SpeedRatio = speedRatio; |
| | | } |
| | | pump.SpeedRatioPattern = jobject[RevitJsonProp.SpeedRatioPattern].ToString(); |
| | | if (!string.IsNullOrEmpty(pump.SpeedRatioPattern)) |
| | | { |
| | | pump.SpeedRatioPattern = string.Empty; |
| | | } |
| | | if (jobject[RevitJsonProp.Price].MatchNumeric(out double price)) |
| | | { |
| | | pump.Price = price; |
| | | } |
| | | pump.PricePattern = jobject[RevitJsonProp.PricePattern].ToString(); |
| | | if (!string.IsNullOrEmpty(pump.PricePattern)) |
| | | { |
| | | pump.PricePattern = string.Empty; |
| | | } |
| | | pump.CurveQE = jobject[RevitJsonProp.CurveQE].ToString(); |
| | | if (!string.IsNullOrEmpty(pump.CurveQE)) |
| | | { |
| | | pump.CurveQE = string.Empty; |
| | | } |
| | | model.Pumps.Add(pump); |
| | | } |
| | | break; |
| | |
| | | valve.MinorLoss = minorLoss; |
| | | } |
| | | |
| | | if (valve.Diameter < 0.1) |
| | | { |
| | | valve.Diameter = 500; |
| | | } |
| | | |
| | | valve.ValveType = jobject[RevitJsonProp.ValveType].ToString(); |
| | | valve.ValveSetting = jobject[RevitJsonProp.ValveSetting].ToString(); |
| | | model.Valves.Add(valve); |
| | | } |
| | | break; |
| | | |
| | | case RevitJsonCatalog.Other: |
| | | { |
| | | var decorator = new Model.RevitDecorator(); |
| | | decorator.Id = jobject[RevitJsonProp.Id].ToString(); |
| | | decorator.Code = jobject[RevitJsonProp.Code].ToString(); |
| | | if (string.IsNullOrEmpty(decorator.Code)) |
| | | { |
| | | decorator.Code = decorator.Id; |
| | | } |
| | | decorator.Name = string.Empty; |
| | | decorator.Category = jobject[RevitJsonProp.ClanAndType][RevitJsonProp.ClanName].ToString(); |
| | | decorator.Decoration = string.Empty; |
| | | model.Decorators.Add(decorator); |
| | | } |
| | | break; |
| | | default: break; |
| | | } |
| | | } |
| | | |
| | | //解析其他json |
| | | var jothersArray = JArray.Parse(revitOthersJsonString); |
| | | if (jothersArray != null && jothersArray.Count > 0) |
| | | { |
| | | var allParterList = model.GetAllParters(); |
| | | for (int i = 0; i < jothersArray.Count; i++) |
| | | { |
| | | var jobject = jothersArray[i]; |
| | | var id = jobject[RevitOthersJsonProp.Id]?.ToString(); |
| | | if (string.IsNullOrEmpty(id)) |
| | | { |
| | | continue; |
| | | } |
| | | if (allParterList.Exists(x => x.Id == id)) |
| | | { |
| | | continue; |
| | | } |
| | | if (model.Decorators.Exists(x => x.Id == id)) |
| | | { |
| | | continue; |
| | | } |
| | | var decorator = new Model.RevitDecorator(); |
| | | decorator.Id = id; |
| | | decorator.Code = id; |
| | | decorator.Name = jobject[RevitOthersJsonProp.Name]?.ToString(); |
| | | decorator.Category = jobject[RevitOthersJsonProp.CategoryName]?.ToString(); |
| | | decorator.Decoration = jobject[RevitOthersJsonProp.CategoryID]?.ToString(); |
| | | model.Decorators.Add(decorator); |
| | | } |
| | | } |
| | | |
| | |
| | | /// <summary> |
| | | /// 从json文件中解析 |
| | | /// </summary> |
| | | /// <param name="revitJsonFile">json文件路径</param> |
| | | /// <returns></returns> |
| | | public static Model.RevitModel FromJsonFile(string revitJsonFile, out string msg) |
| | | public static Model.RevitModel FromJsonFile(string revitJsonFile, string revitOthersJsonFile, out string msg) |
| | | { |
| | | if (!File.Exists(revitJsonFile)) |
| | | { |
| | |
| | | return default; |
| | | } |
| | | var revitJson = File.ReadAllText(revitJsonFile); |
| | | var revitModel = FromJsonString(revitJson, out msg); |
| | | var revitOthersJson = string.Empty; |
| | | if (File.Exists(revitOthersJsonFile)) |
| | | { |
| | | revitOthersJson = File.ReadAllText(revitOthersJsonFile); |
| | | } |
| | | var revitModel = FromJsonString(revitJson, revitOthersJson, out msg); |
| | | if (revitModel == null) |
| | | { |
| | | return default; |