| | |
| | | using ExportMap.Models; |
| | | using ExportMap.db; |
| | | using ExportMap.Models; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | |
| | | |
| | | namespace ExportMap.cs |
| | | { |
| | | /// <summary> |
| | | /// 模型转换工具 |
| | | /// </summary> |
| | | public class ConvertUtils |
| | | { |
| | | /// <summary> |
| | | /// 工作配置 |
| | | /// </summary> |
| | | public static string JobConfig = "{ \"format\": \"3dtiles\", \"mode\": 0, \"outputPath\": \"{0}\", \"outputOptions\": null, \"levelOfDetail\": -1, \"levelOfDetailText\": \"Auto\", \"georeferenced\": null }"; |
| | | public static string JobConfig = "{{ \"format\": \"3dtiles\", \"mode\": 0, \"outputPath\": \"{0}\", \"outputOptions\": null, \"levelOfDetail\": -1, \"levelOfDetailText\": \"Auto\", \"georeferenced\": null }}"; |
| | | |
| | | /// <summary> |
| | | /// Roamer.exe |
| | |
| | | public static string RoamerExe = "\"C:\\Program Files\\Autodesk\\Navisworks Manage 2020\\Roamer.exe\""; |
| | | |
| | | /// <summary> |
| | | /// 获取发布地址 |
| | | /// </summary> |
| | | public static string GetReleaseUrl(SysMeta meta) |
| | | { |
| | | return "{host}/LFData/3d/3dtiles/" + meta.type + "/" + meta.id + "/tileset.json"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 模型转换 |
| | | /// </summary> |
| | | public static int Convert(List<int> ids) |
| | | public static List<int> Convert(XYZArgs args) |
| | | { |
| | | int count = 0; |
| | | string uploadFolder = Tool.GetSetting("uploadFolder"); |
| | | string tilesFolder = Path.Combine(Tool.GetSetting("lfData"), "3d\\3dtiles"); |
| | | string uploadFolder = Tools.GetSetting("uploadFolder"); |
| | | string tilesFolder = Path.Combine(Tools.GetSetting("lfData"), "3d\\3dtiles"); |
| | | |
| | | List<SysMeta> list = XYZUtils.selectMetas(ids, "type in ('ifc', 'fbx', 'rvt')"); |
| | | List<SysMeta> list = XYZUtils.SelectMetas(args.ids, "and type in ('ifc', 'fbx', 'rvt')"); |
| | | if (null == list || list.Count == 0) return null; |
| | | |
| | | Tools.SetIsModel(args, list); |
| | | |
| | | List<int> ids = new List<int>(); |
| | | foreach (SysMeta meta in list) |
| | | { |
| | | try |
| | | string modelFile = Path.Combine(uploadFolder, meta.path); |
| | | if (!File.Exists(modelFile)) continue; |
| | | |
| | | string configFile = Path.Combine(Tools.TempDir, ExportUtil.DateStr + ".json"); |
| | | string outPath = Path.Combine(tilesFolder, meta.type, meta.id.ToString()); |
| | | string jsonFile = Path.Combine(outPath, "tileset.json"); |
| | | |
| | | if (args.isNew && Directory.Exists(outPath)) Tools.DelPath(outPath); |
| | | if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath); |
| | | if (File.Exists(jsonFile)) File.Delete(jsonFile); |
| | | |
| | | WriteText(configFile, string.Format(JobConfig, outPath.Replace("\\", "\\\\"))); |
| | | SysTask task = TaskDBHelper.CreateTask(args, meta, "BIM", "三维模型(BIM)"); |
| | | ExecNavisworks(task, modelFile, configFile); |
| | | |
| | | File.Delete(configFile); |
| | | if (File.Exists(jsonFile)) |
| | | { |
| | | string modelFile = Path.Combine(uploadFolder, meta.path); |
| | | if (!File.Exists(modelFile)) |
| | | { |
| | | continue; |
| | | } |
| | | string path = jsonFile.Replace(Tools.GetSetting("lfData") + "\\", ""); |
| | | int pubid = InsertToDB(meta, args, path); |
| | | |
| | | string configFile = Path.Combine(Tool.BaseDir, ExportUtil.DateStr + ".json"); |
| | | string outPath = Path.Combine(tilesFolder, meta.type, meta.id.ToString()); |
| | | |
| | | if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath); |
| | | WriteText(configFile, string.Format(JobConfig, outPath)); |
| | | |
| | | ExecNavisworks(modelFile, configFile); |
| | | |
| | | count++; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.StackTrace); |
| | | if (pubid > 0) ids.Add(pubid); |
| | | } |
| | | } |
| | | |
| | | return count; |
| | | return ids; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 运行Navisworks |
| | | /// </summary> |
| | | public static string ExecNavisworks(string modelFile, string outPath) |
| | | public static void ExecNavisworks(SysTask task, string modelFile, string configFile) |
| | | { |
| | | string args = string.Format("-licensing AdLM -OpenFile \"{0}\" -ExecuteAddInPlugin SmartEarth \"{1}\" -NoGui -NoCache -Exit", modelFile, outPath); |
| | | Process p = null; |
| | | try |
| | | { |
| | | //string args = string.Format("-licensing AdLM -OpenFile \"{0}\" -ExecuteAddInPlugin \"EngineBatch_Sample.SmartEarth\" \"{1}\" -log \"{2}\" -NoGui -Exit", modelFile, configFile, Path.Combine(ExportUtil.SourcesPath, "ns_log.txt")); |
| | | string args = string.Format("-licensing AdLM -OpenFile \"{0}\" -ExecuteAddInPlugin \"EngineBatch_Sample.SmartEarth\" \"{1}\" -NoGui -Exit", modelFile, configFile); |
| | | LogOut.Info("Args:" + args); |
| | | |
| | | Process p = new Process(); |
| | | p.StartInfo.UseShellExecute = false; |
| | | p.StartInfo.ErrorDialog = true; |
| | | p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; |
| | | p.StartInfo.RedirectStandardError = false; |
| | | p.StartInfo.FileName = RoamerExe; |
| | | p.StartInfo.Arguments = args; |
| | | p.StartInfo.CreateNoWindow = true; |
| | | p.Start(); |
| | | // 启动进程 |
| | | p = Process.Start(RoamerExe, args); |
| | | task.pid = p.Id; |
| | | task.id = TaskDBHelper.Insert(task); |
| | | |
| | | return string.Empty; |
| | | p.WaitForInputIdle(); // 让组件等候相关的进程进入闲置状态 |
| | | p.WaitForExit(); // 让组件无限期地等待关联进程退出 |
| | | |
| | | task = TaskDBHelper.SelectById(task.id); |
| | | if (null != task && task.status < 2) |
| | | { |
| | | task.status = 2; |
| | | TaskDBHelper.Update(task); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | task = TaskDBHelper.SelectById(task.id); |
| | | if (null != task && task.status < 2) |
| | | { |
| | | task.err = ex.Message; |
| | | task.status = 4; |
| | | TaskDBHelper.Update(task); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | if (p != null) |
| | | { |
| | | p.Close(); |
| | | p = null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | private static void WriteText(string file, string str) |
| | | { |
| | | File.WriteAllText(file, str); |
| | | LogOut.Info("JobConfig:" + str); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 插入数据库 |
| | | /// </summary> |
| | | private static int InsertToDB(SysMeta meta, XYZArgs args, string path) |
| | | { |
| | | //if (PubDBHelper.IsPublish(meta.id)) return 1; |
| | | int pubid = PubDBHelper.GetPushlishId(meta.id); |
| | | if (pubid > 0) |
| | | { |
| | | PubDBHelper.UpdatePublish(pubid, meta.name, args.userId, null); |
| | | return pubid; |
| | | } |
| | | |
| | | SysPublish sys = Tools.NewPublish(meta, args, GetReleaseUrl(meta), path); |
| | | |
| | | pubid = PubDBHelper.InsertPublish(sys); |
| | | if (pubid > 0) |
| | | { |
| | | sys.id = pubid; |
| | | PubDBHelper.InsertLayer(sys, meta); |
| | | PubDBHelper.InsertMetaPub(meta.id, pubid, args.userId); |
| | | } |
| | | |
| | | return pubid; |
| | | } |
| | | } |
| | | } |