public void LoadData(GeometryBase geometry) { elementSizeCheckBox.Checked = geometry.GetUserString("Ibra.MaxElementSize") != null; elementSizeTextBox.Text = geometry.GetUserString("Ibra.MaxElementSize"); polynomialDegreeCheckBox.Checked = geometry.GetUserString("Ibra.MinPolynomialDegree") != null; polynomialDegreeTextBox.Text = geometry.GetUserString("Ibra.MinPolynomialDegree"); }
public static bool TryGetUserString <T>(this GeometryBase geometry, string key, out T value, T def) where T : IConvertible { if (geometry.GetUserString(key) is string stringValue) { value = (T)System.Convert.ChangeType(stringValue, typeof(T), System.Globalization.CultureInfo.InvariantCulture); return(true); } value = def; return(false); }
public static bool GetUserEnum <E>(this GeometryBase geometry, string key, out E value, E def = default) where E : struct { value = def; return(geometry.GetUserString(key) is string stringValue && Enum.TryParse <E>(stringValue, out value)); }
public static bool GetUserInteger(this GeometryBase geometry, string key, out int value, int def = default) { value = def; return(geometry.GetUserString(key) is string stringValue && int.TryParse(stringValue, out value)); }
private void StoreOutput() { DebugEvent("Start Store Output"); GH_DocumentServer doc_server = Instances.DocumentServer; if (doc_server == null) { throw new Exception("No Document Server exist!"); } GH_Document doc = doc_server.ToList().Find(x => x.Properties.ProjectFileName == ID.ToString()); if (doc == null) { throw new Exception("Tasker 未找到GH_Document"); } if (string.IsNullOrEmpty(workspace) || string.IsNullOrEmpty(ticket)) { throw new Exception("工作目录和Ticket为空"); } string outDir = Path.Combine(taskspace, ID.ToString(), ticket); var hooks = doc.ClusterOutputHooks(); if (hooks == null) { return; } foreach (var hook in hooks) { string info = hook.CustomDescription; if (string.IsNullOrEmpty(info)) { continue; } var paraMap = ConvertUrlParam(info); if (!paraMap.TryGetValue("Index", out string index) || !paraMap.TryGetValue("Type", out string type)) { continue; } DebugEvent($"Index: {index}; Type: {type}"); string fileName = Path.Combine(outDir, index + "@" + DateTime.Now.ToString("HH-mm-ss MM-dd")); var volatileData = hook.VolatileData; if (volatileData.IsEmpty) { continue; } dynamic content = null; switch (type) { case "CSV": { var allData = volatileData.AllData(true); List <string> sList = new List <string>(); allData.ToList().ForEach(el => { GH_Convert.ToString(el, out string tmp, GH_Conversion.Both); sList.Add(tmp); }); string csv = string.Join(Environment.NewLine, sList); fileName += ".csv"; File.WriteAllText(fileName, csv, Encoding.UTF8); content = fileName; break; } case "3DM": { fileName += ".3dm"; File3dmWriter writer = new File3dmWriter(fileName); foreach (var data in volatileData.AllData(true)) { GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } string layer = obj.GetUserString("Layer"); if (layer == null) { continue; } ObjectAttributes att = new ObjectAttributes { LayerIndex = writer.GetLayer(layer, Color.Black) }; writer.ObjectMap.Add(att, obj); } writer.Write(); content = fileName; break; } case "Data": { try { GH_Structure <IGH_Goo> tree = volatileData as GH_Structure <IGH_Goo>; content = IO.SerializeGrasshopperData(tree, hook.CustomName, volatileData.IsEmpty); } catch (Exception ex) { ErrorEvent(this, ex.Message); } break; } case "EPS": { List <GeometryBase> objs = new List <GeometryBase>(); foreach (var data in volatileData.AllData(true)) { if (data == null) { continue; } GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } objs.Add(obj); } if (!Directory.Exists(fileName)) { Directory.CreateDirectory(fileName); } content = JsonConvert.SerializeObject(SaveAdobeDocument(fileName, objs, AdobeDocType.EPS)); break; } case "PDF": { List <GeometryBase> objs = new List <GeometryBase>(); fileName += ".pdf"; foreach (var data in volatileData.AllData(true)) { if (data == null) { continue; } GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } objs.Add(obj); } var res = SaveAdobeDocument(fileName, objs, AdobeDocType.PDF); if (res == null || res.Count == 0) { break; } content = res[0]; break; } case "RhinoPDF": { var pdf = FilePdf.Create(); fileName += ".pdf"; DebugEvent("RhinoPDF Begin"); foreach (var page in volatileData.AllData(true)) { DebugEvent("RhinoPDF got 1 page"); if (!page.CastTo(out RhinoPageView view)) { DebugEvent(string.Format("{0} can not convert to RhinoPageView", page.GetType())); continue; } DebugEvent("Data is converted to RhinoPage"); ViewCaptureSettings settings = new ViewCaptureSettings(view, 300) { OutputColor = ViewCaptureSettings.ColorMode.DisplayColor, RasterMode = true }; pdf.AddPage(settings); } pdf.Write(fileName); content = fileName; break; } case "DXF": { break; } default: break; } StoreEvent(this, new JObject { ["route"] = "task-stored", ["id"] = ID.ToString(), ["index"] = index.ToString(), ["type"] = type, ["content"] = content }.ToString()); } }