Example #1
0
        private void toolStripButtonDES3_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 = _treeViewCtrl.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; }
            List<string> filePathes = new List<string>();
            foreach (Document d in des3Docs)
                filePathes.Add(d.File.Path(db));

            SaveFileDialog fd = new SaveFileDialog();
            fd.Filter = "Picador 3D files (*.des3)|*.des3|All files (*.*)|*.*";
            fd.FilterIndex = 0;
            fd.DefaultExt = "des3";
            fd.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 = Path.Combine(currentDir, "Pic3DExporter.exe");
                    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 (!Properties.Settings.Default.DebugMode)
                            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));
                }
            }
        }
Example #2
0
        private void OnGenerate(object sender, EventArgs e)
        {
            try
            {
                richTextBoxOutput.Clear();

                if (null == formTreeView)
                {
                    return;
                }
                string pdfFile            = fileSelectOutput.FileName;
                string desFile            = Path.ChangeExtension(pdfFile, "des");
                string des3File           = Path.ChangeExtension(pdfFile, "des3");
                string xmlFile            = Path.ChangeExtension(pdfFile, "xml");
                string xmlResultFile      = Path.ChangeExtension(pdfFile, "result.xml");
                string u3dFile            = Path.ChangeExtension(pdfFile, "u3d");
                string defaultPdfTemplate = fileSelectPdfTemplate.FileName;

                // generate des file
                formTreeView.Export(desFile);
                // #### job file
                Pic3DExporter.Job job = new Pic3DExporter.Job();
                // **** FILES BEGIN ****
                job.Pathes.Add(new Pic3DExporter.PathItem()
                {
                    pathID = "FID-1", path = defaultPdfTemplate, type = Pic3DExporter.pathType.FILE
                });
                job.Pathes.Add(new Pic3DExporter.PathItem()
                {
                    pathID = "FID-2", path = desFile, type = Pic3DExporter.pathType.FILE
                });
                job.Pathes.Add(new Pic3DExporter.PathItem()
                {
                    pathID = "FID-3", path = des3File, type = Pic3DExporter.pathType.FILE
                });
                job.Pathes.Add(new Pic3DExporter.PathItem()
                {
                    pathID = "FID-4", path = u3dFile, type = Pic3DExporter.pathType.FILE
                });
                job.Pathes.Add(new Pic3DExporter.PathItem()
                {
                    pathID = "FID-5", path = pdfFile, type = Pic3DExporter.pathType.FILE
                });

                int fid = 5;
                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-2", role = "input des", deleteAfterUsing = true
                });
                task_2D_to_DES3.Outputs.Add(new Pic3DExporter.PathRef()
                {
                    pathID = "FID-3", 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 = 5;
                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);
                // DES3 -> U3D
                Pic3DExporter.task_DES3_TO_U3D task_DES3_to_U3D = new Pic3DExporter.task_DES3_TO_U3D()
                {
                    id = "TID-2"
                };
                task_DES3_to_U3D.Dependencies = "TID-1";
                task_DES3_to_U3D.Inputs.Add(new Pic3DExporter.PathRef()
                {
                    pathID = "FID-3", role = "input des3", deleteAfterUsing = true
                });
                task_DES3_to_U3D.Outputs.Add(new Pic3DExporter.PathRef()
                {
                    pathID = "FID-4", role = "output u3d", deleteAfterUsing = false
                });
                task_DES3_to_U3D.Parameters.Material.opacitySpecified        = true;
                task_DES3_to_U3D.Parameters.Material.opacity                 = 1.0F;
                task_DES3_to_U3D.Parameters.Material.reflectivitySpecified   = true;
                task_DES3_to_U3D.Parameters.Material.reflectivity            = 0.0F;
                task_DES3_to_U3D.Parameters.Qualities.meshDefaultSpecified   = true;
                task_DES3_to_U3D.Parameters.Qualities.meshDefault            = 1000;
                task_DES3_to_U3D.Parameters.Qualities.meshPositionSpecified  = true;
                task_DES3_to_U3D.Parameters.Qualities.meshPosition           = 1000;
                task_DES3_to_U3D.Parameters.Qualities.shaderQualitySpecified = true;
                task_DES3_to_U3D.Parameters.Qualities.shaderQuality          = 1000;
                job.Tasks.Add(task_DES3_to_U3D);
                // U3D -> PDF
                float[]      mat        = { -0.768655F, -0.632503F, 0.0954455F, -0.220844F, 0.402444F, 0.888407F, -0.600332F, 0.661799F, -0.449025F, 1805.8F, -1990.7F, 1350.67F };
                List <float> viewMatrix = new List <float>(mat);
                float[]      bColor     = { 1.0f, 1.0f, 1.0f };
                List <float> backColor  = new List <float>(bColor);

                Pic3DExporter.task_U3D_TO_PDF task_U3D_to_PDF = new Pic3DExporter.task_U3D_TO_PDF()
                {
                    id = "TID-3"
                };
                task_U3D_to_PDF.Dependencies = "TID-2";
                task_U3D_to_PDF.Inputs.Add(new Pic3DExporter.PathRef()
                {
                    pathID = "FID-4", role = "input u3d", deleteAfterUsing = true
                });
                task_U3D_to_PDF.Inputs.Add(new Pic3DExporter.PathRef()
                {
                    pathID = "FID-1", role = "pdf template", deleteAfterUsing = false
                });
                task_U3D_to_PDF.Outputs.Add(new Pic3DExporter.PathRef()
                {
                    pathID = "FID-5", role = "output pdf", deleteAfterUsing = false
                });
                task_U3D_to_PDF.pdfAnnotation.PageLayout.buttonPositionsSpecified = true;
                task_U3D_to_PDF.pdfAnnotation.PageLayout.buttonPositions          = Pic3DExporter.RelativePosition.LEFT;
                task_U3D_to_PDF.pdfAnnotation.PageLayout.pageNumberSpecified      = true;
                task_U3D_to_PDF.pdfAnnotation.PageLayout.pageNumber = 1;
                task_U3D_to_PDF.pdfAnnotation.PageLayout.position.Add(40);
                task_U3D_to_PDF.pdfAnnotation.PageLayout.position.Add(40);
                task_U3D_to_PDF.pdfAnnotation.PageLayout.dimensions.Add(760);
                task_U3D_to_PDF.pdfAnnotation.PageLayout.dimensions.Add(500);
                task_U3D_to_PDF.pdfAnnotation.ViewNodes.Add(new Pic3DExporter.viewNode()
                {
                    name = "View_Step0", matrix = viewMatrix, backgroundColor = backColor, COSpecified = true, CO = 3000.0f, lightingScheme = "CAD"
                });
                job.Tasks.Add(task_U3D_to_PDF);
                //
                // open PDF
                Pic3DExporter.task_OPEN_PDF_ADOBEREADER task_OpenPDF = new Pic3DExporter.task_OPEN_PDF_ADOBEREADER()
                {
                    id = "TID-4"
                };
                task_OpenPDF.Dependencies = "TID-3";
                task_OpenPDF.Inputs.Add(new Pic3DExporter.PathRef()
                {
                    pathID = "FID-5", role = "input pdf", deleteAfterUsing = false
                });
                job.Tasks.Add(task_OpenPDF);
                // **** TASKS END ****
                job.SaveToFile(xmlFile);

                // #### execute Pic3DExporter
                string exePath = formTreeView.Pic3DExporterPath;
                if (!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 = true,
                        RedirectStandardError  = false
                    }
                };
                procExporter.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
                procExporter.Start();
                procExporter.BeginOutputReadLine();
                while (!procExporter.HasExited)
                {
                    Application.DoEvents();
                }
                Thread.Sleep(1000);
                // delete xml task file
                try
                {
                    if (!Properties.Settings.Default.ShowLogConsole)
                    {
                        File.Delete(xmlFile);
                        File.Delete(xmlResultFile);
                    }
                }
                catch (Exception) { }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #3
0
        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 = _treeViewCtrl.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; }
            List<string> filePathes = new List<string>();
            foreach (Document d in des3Docs)
                filePathes.Add(d.File.Path(db));

            SaveFileDialog fd = new SaveFileDialog();
            fd.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*";
            fd.FilterIndex = 0;
            fd.DefaultExt = "pdf";
            fd.FileName = treeNode.Name + ".pdf";

            if (DialogResult.OK == fd.ShowDialog())
            {
                string pdfFile = fd.FileName;
                string desFile = Path.ChangeExtension(pdfFile, "des");
                string des3File = Path.ChangeExtension(pdfFile, "des3");
                string xmlFile = Path.ChangeExtension(pdfFile, "xml");
                string u3dFile = Path.ChangeExtension(pdfFile, "u3d");
                string currentDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string defaultPdfTemplate = Path.Combine(currentDir, "DefaultTemplate.pdf");

                // 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 = defaultPdfTemplate, type = Pic3DExporter.pathType.FILE });
                    job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-2", path = desFile, type = Pic3DExporter.pathType.FILE });
                    job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-3", path = des3File, type = Pic3DExporter.pathType.FILE });
                    job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-4", path = u3dFile, type = Pic3DExporter.pathType.FILE });
                    job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-5", path = pdfFile, type = Pic3DExporter.pathType.FILE });

                    int fid = 5;
                    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-2", role = "input des", deleteAfterUsing = false });
                    task_2D_to_DES3.Outputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-3", 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 = 5;
                    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);
                    // DES3 -> U3D
                    Pic3DExporter.task_DES3_TO_U3D task_DES3_to_U3D = new Pic3DExporter.task_DES3_TO_U3D() { id = "TID-2" };
                    task_DES3_to_U3D.Dependencies = "TID-1";
                    task_DES3_to_U3D.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-3", role = "input des3", deleteAfterUsing = false });
                    task_DES3_to_U3D.Outputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-4", role = "output u3d", deleteAfterUsing = false });
                    task_DES3_to_U3D.Parameters.Material.opacitySpecified = true;
                    task_DES3_to_U3D.Parameters.Material.opacity = 1.0F;
                    task_DES3_to_U3D.Parameters.Material.reflectivitySpecified = true;
                    task_DES3_to_U3D.Parameters.Material.reflectivity = 0.0F;
                    task_DES3_to_U3D.Parameters.Qualities.meshDefaultSpecified = true;
                    task_DES3_to_U3D.Parameters.Qualities.meshDefault = 1000;
                    task_DES3_to_U3D.Parameters.Qualities.meshPositionSpecified = true;
                    task_DES3_to_U3D.Parameters.Qualities.meshPosition = 1000;
                    task_DES3_to_U3D.Parameters.Qualities.shaderQualitySpecified = true;
                    task_DES3_to_U3D.Parameters.Qualities.shaderQuality = 1000;
                    job.Tasks.Add(task_DES3_to_U3D);
                    // U3D -> PDF
                    float[] mat = { -0.768655F, -0.632503F, 0.0954455F, -0.220844F, 0.402444F, 0.888407F, -0.600332F, 0.661799F, -0.449025F, 1805.8F, -1990.7F, 1350.67F };
                    List<float> viewMatrix = new List<float>(mat);
                    float[] bColor = { 1.0f, 1.0f, 1.0f };
                    List<float> backColor = new List<float>(bColor);

                    Pic3DExporter.task_U3D_TO_PDF task_U3D_to_PDF = new Pic3DExporter.task_U3D_TO_PDF() { id = "TID-3" };
                    task_U3D_to_PDF.Dependencies = "TID-2";
                    task_U3D_to_PDF.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-4", role = "input u3d", deleteAfterUsing = false });
                    task_U3D_to_PDF.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-1", role = "pdf template", deleteAfterUsing = false });
                    task_U3D_to_PDF.Outputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-5", role = "output pdf", deleteAfterUsing = false });
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.buttonPositionsSpecified = true;
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.buttonPositions = Pic3DExporter.RelativePosition.LEFT;
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.pageNumberSpecified = true;
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.pageNumber = 1;
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.position.Add(40);
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.position.Add(40);
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.dimensions.Add(760);
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.dimensions.Add(500);
                    task_U3D_to_PDF.pdfAnnotation.ViewNodes.Add(new Pic3DExporter.viewNode() { name = "View_Step0", matrix = viewMatrix, backgroundColor = backColor, COSpecified = true, CO = 3000.0f, lightingScheme = "CAD" });
                    job.Tasks.Add(task_U3D_to_PDF);
                    // 
                    // open PDF
                    Pic3DExporter.task_OPEN_PDF_ADOBEREADER task_OpenPDF = new Pic3DExporter.task_OPEN_PDF_ADOBEREADER() { id = "TID-4" };
                    task_OpenPDF.Dependencies = "TID-3";
                    task_OpenPDF.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-5", role = "input pdf", deleteAfterUsing = false });
                    job.Tasks.Add(task_OpenPDF);
                    // **** TASKS END ****
                    job.SaveToFile(xmlFile);

                    // #### execute Pic3DExporter
                    string exePath = Path.Combine(currentDir, "Pic3DExporter.exe");
                    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 (!Properties.Settings.Default.DebugMode)
                            System.IO.File.Delete(xmlFile); 
                    }
                    catch (Exception) { }
                }
            }
        }
Example #4
0
        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));
                }
            }
        }