/* ==============================================================================
* 功能描述:CommonTool
* 创 建 者:Garrett
* 创建日期:2018/3/13 17:26:29
* ==============================================================================*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Autodesk.Revit.DB;
using Newtonsoft.Json.Linq;
using SAGA.DotNetUtils.Extend;
namespace MBIUtility.Tool
{
///
/// CommonTool
///
public class CommonTool
{
///
/// 获取楼层顺序号
///
/// 当前顺序号
/// 上面增加(1)下面增加是(-1)
///
public static int GetNewSequence(int cur, int seed)
{
if (seed == -1)
{
cur = cur < 0 ? cur + seed : cur;
}
else
{
cur = cur < 0 ? cur : cur + seed;
}
return cur;
}
///
/// 获取楼层顺序号
///
/// 当前顺序号
/// 上面增加(1)下面增加是(-1)
///
public static int GetNextSequence(int cur)
{
cur = cur > 0 ? cur + 1 : cur - 1;
return cur;
}
///
/// 由楼层顺序号获取生成revit文件的文件名称;
/// 默认为B1,B2,F1,F2...
///
///
///
public static string GetFloorRevitFileName(int sequence)
{
if (sequence > 0)
return "F" + sequence;
else
{
return "B" + Math.Abs(sequence);
}
}
///
/// 信息点置为null
///
public readonly static string NullStr="Nlul";
public static JArray GetPropertyJArray(string value)
{
JArray jArray = new JArray();
if (value == null)
return jArray;
JObject valueJObject = new JObject();
if (value.Equals(NullStr))
{
valueJObject.Add("value", null);
}
else
{
valueJObject.Add("value", value);
}
jArray.Add(valueJObject);
return jArray;
}
///
/// 获取信息点更新是传递的数据结构
///
///
///
///
public static JObject GetPropertyJObject(string code,string value)
{
#region 构建array
JArray jArray = new JArray();
JObject valueJObject = new JObject();
valueJObject.Add("value", value);
jArray.Add(valueJObject);
#endregion
JObject jObject = new JObject();
jObject.Add(code, jArray);
return jObject;
}
public static JArray GetPropertyJArray(string time, string value)
{
JArray jArray = new JArray();
JObject valueJObject = new JObject();
valueJObject.Add("time", time);
valueJObject.Add("value", value);
jArray.Add(valueJObject);
return jArray;
}
public static JArray GetPropertyJArray(JToken value)
{
JArray jArray = new JArray();
JObject valueJObject = new JObject();
valueJObject.Add("value", value);
jArray.Add(valueJObject);
return jArray;
}
///
/// 由文件的全路径获取云端文件名
///
///
///
public static string GetCloudRevitName(string path)
{
var strs = path.Split('\\', ':');
List last3Strs = new List();
for (int i = strs.Length - 3; i < strs.Length; i++)
{
last3Strs.Add(strs[i]);
}
string fileName = string.Join("_", last3Strs.ToArray());
return fileName;
}
///
/// 将点按 “;”进行分组
///
///
///
public static string ConvertSpaceEdgesToStr(List xyzs)
{
var strs = xyzs.Select(t => t.X + "," + t.Y);
var str = string.Join(";", strs.ToArray());
return str;
}
///
/// 创建个资产id
/// id为Pe+uuid(去掉横线)
///
///
public static string CreateNewFmId()
{
string id = System.Guid.NewGuid().ToString("N");
return "Pe" + id;
}
///
/// 获取BIMId
///
///
///
///
public static string GetCloudBIMId(string docName, string id)
{
return $"{docName}:{id}";
}
///
/// 由视频预览图--获取视频的名称
///
///
///
public static string GetVideoKeyByImageKey(string name)
{
string videoSuffix = ".mp4";
return name.GetAppointSuffixPath(videoSuffix);
}
}
}