private void ToolStripButtonPDF3D_Click(object sender, EventArgs e) { Pic.Plugin.Component comp = pluginViewCtrl.Component; if (!pluginViewCtrl.Visible || null == comp || !comp.IsSupportingAutomaticFolding) { return; } // get documents at the same lavel NodeTag nodeTag = treeView.SelectedNode.Tag as NodeTag; if (null == nodeTag) { return; } PPDataContext db = new PPDataContext(); Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode); List <Document> des3Docs = treeNode.GetBrothersWithExtension(db, "des3"); if (0 == des3Docs.Count) { MessageBox.Show("Missing des3 for sample pattern files"); return; } // get default thickness Sharp3D.Math.Core.Vector2D refPoint = Sharp3D.Math.Core.Vector2D.Zero; double thickness = 0.0; if (!pluginViewCtrl.GetReferencePointAndThickness(ref refPoint, ref thickness)) { MessageBox.Show("Failed to retrieve reference point and thickness"); return; } // allow if (!System.IO.File.Exists(Pic3DExporterPath)) { MessageBox.Show(string.Format("File {0} could not be found!", Pic3DExporterPath)); return; } // show form and generate PDF 3D FormGeneratePDF3D form = new FormGeneratePDF3D(this) { OutputFilePath = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), treeNode.Name), "pdf"), thickness = thickness, v = refPoint }; foreach (Document d in des3Docs) { form.filePathes.Add(d.File.Path(db)); } form.ShowDialog(); }
private void OnGeneratePic3D(object sender, EventArgs e) { Pic.Plugin.Component comp = pluginViewCtrl.Component; if (!pluginViewCtrl.Visible || null == comp || !comp.IsSupportingAutomaticFolding) { return; } // get documents at the same lavel if (!(treeView.SelectedNode.Tag is NodeTag nodeTag)) { return; } PPDataContext db = new PPDataContext(); Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode); List <Document> des3Docs = treeNode.GetBrothersWithExtension(db, "des3"); if (0 == des3Docs.Count) { MessageBox.Show("Missing des3 for sample pattern files"); return; } List <string> filePathes = new List <string>(); foreach (Document d in des3Docs) { filePathes.Add(d.File.Path(db)); } SaveFileDialog fd = new SaveFileDialog { Filter = "Picador 3D files (*.des3)|*.des3|All files (*.*)|*.*", FilterIndex = 0, DefaultExt = "des3", FileName = treeNode.Name + ".des3" }; if (DialogResult.OK == fd.ShowDialog()) { string des3File = fd.FileName; string desFile = Path.ChangeExtension(des3File, "des"); string xmlFile = Path.ChangeExtension(des3File, "xml"); string currentDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // generate des file Export(desFile); // reference point double thickness = 0.0; Sharp3D.Math.Core.Vector2D v = Sharp3D.Math.Core.Vector2D.Zero; if (pluginViewCtrl.GetReferencePointAndThickness(ref v, ref thickness)) { // #### job file Pic3DExporter.Job job = new Pic3DExporter.Job(); // **** FILES BEGIN **** job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-1", path = desFile, type = Pic3DExporter.pathType.FILE }); job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-2", path = des3File, type = Pic3DExporter.pathType.FILE }); int fid = 2; foreach (string filePath in filePathes) { job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = string.Format("FID-{0}", ++fid), path = filePath, type = Pic3DExporter.pathType.FILE }); } // **** FILES END **** // **** TASKS BEGIN **** // DES -> DES3 Pic3DExporter.task_2D_TO_DES3 task_2D_to_DES3 = new Pic3DExporter.task_2D_TO_DES3() { id = "TID-1" }; task_2D_to_DES3.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-1", role = "input des", deleteAfterUsing = false }); task_2D_to_DES3.Outputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-2", role = "output des3", deleteAfterUsing = false }); task_2D_to_DES3.autoparameters.thicknessSpecified = true; task_2D_to_DES3.autoparameters.thickness = (float)thickness; task_2D_to_DES3.autoparameters.foldPositionSpecified = true; task_2D_to_DES3.autoparameters.foldPosition = (float)0.5; task_2D_to_DES3.autoparameters.pointRef.Add((float)v.X); task_2D_to_DES3.autoparameters.pointRef.Add((float)v.Y); fid = 2; foreach (string filePath in filePathes) { task_2D_to_DES3.autoparameters.modelFiles.Add( new Pic3DExporter.PathRef() { pathID = string.Format("FID-{0}", ++fid), role = "model files", deleteAfterUsing = false }); } job.Tasks.Add(task_2D_to_DES3); // **** TASKS END **** job.SaveToFile(xmlFile); // #### execute Pic3DExporter string exePath = Pic3DExporterPath; if (!System.IO.File.Exists(exePath)) { MessageBox.Show(string.Format("File {0} could not be found!", exePath)); return; } var procExporter = new Process { StartInfo = new ProcessStartInfo { FileName = exePath, Arguments = string.Format(" -t \"{0}\"", xmlFile), UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = false, RedirectStandardError = false } }; procExporter.Start(); procExporter.WaitForExit(); Thread.Sleep(1000); // delete xml task file try { if (!Settings.Default.ShowLogConsole) { System.IO.File.Delete(xmlFile); } } catch (Exception) { } } if (System.IO.File.Exists(des3File)) { if (ApplicationAvailabilityChecker.IsAvailable("Picador3D")) { var procPic3D = new Process { StartInfo = new ProcessStartInfo { FileName = des3File, UseShellExecute = true, CreateNoWindow = false, Verb = "open", WindowStyle = ProcessWindowStyle.Normal } }; procPic3D.Start(); } } else { MessageBox.Show(string.Format("Failed to generate {0}", des3File)); } } }