Example #1
0
        //新建工艺
        private void CreateNewProject()
        {
            int flag = 0;

            //选择保存路径;
            saveFileDialog.AddExtension    = true;
            saveFileDialog.Title           = "请选择要保存的工艺所在路径";
            saveFileDialog.DefaultExt      = "3dppm";
            saveFileDialog.Filter          = "三维机加工艺文件(*.3dppm)|*.3dppm";
            saveFileDialog.OverwritePrompt = true;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filename = saveFileDialog.FileName;
                if (NXFun.IsChina(filename))
                {
                    MessageBox.Show("NX不支持中文路径,请重新选择保存路径");
                    flag = 1;
                }
                else
                {
                    //得到工艺路径和文件名;
                    ProPath = Path.GetDirectoryName(filename);
                    ProName = Path.GetFileNameWithoutExtension(filename);
                    XmlFile = ToFullPath(NXFun.ProcessXML);
                    //删除并创建文件夹;
                    bool result = NXFun.DeleteDirectory(ToFullPath(""));
                    if (!result)
                    {
                        MessageBox.Show("文件夹" + ToFullPath("") + "无法删除,请手动关闭可能已打开的文件并删除该目录。");
                        return;
                    }
                    Directory.CreateDirectory(ToFullPath(""));
                    //复制工艺模板;
                    File.Copy(NXFun.TDPPMPath + NXFun.ProcessXML, XmlFile, true);
                    OpenOrCreateProjectInit();
                    SetStatusLabel("工艺新建成功!", 2);
                }
            }
            if (flag == 1)
            {
                //包含中文,重新选择文件;
                CreateNewProject();
            }
        }
Example #2
0
        //恢复工艺
        private void RecoverProject()
        {
            folderBrowserDialog.Description         = "请选择要打开的工艺临时文件夹:";
            folderBrowserDialog.ShowNewFolderButton = false;
            DialogResult result = folderBrowserDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string path = folderBrowserDialog.SelectedPath;
                //判断合法性
                string root     = Path.GetPathRoot(path);
                string pathname = Path.GetDirectoryName(path);
                string filename = Path.GetFileName(path);
                if (path.Equals(root) && string.IsNullOrEmpty(pathname) && string.IsNullOrEmpty(filename))
                {
                    MessageBox.Show("请不要选择根目录!");
                    return;
                }
                else if (NXFun.IsChina(path))
                {
                    MessageBox.Show("NX不支持中文路径,请修改路径!");
                    return;
                }
                else if (!NXFun.isFileExist(path + "\\" + NXFun.ProcessXML))
                {
                    MessageBox.Show("所选路径非工艺临时数据包");
                    return;
                }
                else
                {
                    ProPath = pathname;
                    ProName = filename;
                    XmlFile = ToFullPath(NXFun.ProcessXML);
                    XML3DPPM.Update3dppm(XmlFile, TemplateXML);
                    OpenOrCreateProjectInit();
                }
            }
        }
Example #3
0
        //打开工艺
        private void OpenProject()
        {
            openFileDialog.Title    = "请选择要打开的工艺文件:";
            openFileDialog.Filter   = "3DPPM 文件 (*.3dppm)|*.3dppm";
            openFileDialog.FileName = "";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filename = openFileDialog.FileName;
                if (NXFun.IsChina(filename))
                {
                    MessageBox.Show("NX不支持中文路径,请将工艺文件放到英文路径下再打开.");
                    return;
                }
                else
                {
                    //得到工艺路径和文件名;
                    ProPath = Path.GetDirectoryName(filename);
                    ProName = Path.GetFileNameWithoutExtension(filename);
                    XmlFile = ToFullPath(NXFun.ProcessXML);
                    //删除文件夹;
                    bool result = NXFun.DeleteDirectory(ProPath + "\\" + ProName);
                    if (!result)
                    {
                        MessageBox.Show("文件夹" + ProPath + "\\" + ProName + "无法删除,请手动关闭可能已打开的文件并删除该目录。");
                        return;
                    }
                    //判断是否是压缩文件
                    int type = GetFileRealType(filename);
                    switch (type)
                    {
                    case -1:
                        MessageBox.Show("读取文件出错,请确认文件是否有效!");
                        return;

                    case 0:
                        break;

                    case 1:
                        break;

                    default:
                        MessageBox.Show("读取文件出错,请确认文件是否有效!");
                        return;
                    }
                    //解压
                    bool isUnZip = true;
                    if (type == 0)
                    {
                        //按zip格式解压
                        isUnZip = Compress.UnZipFileDictory(filename, "");
                    }
                    else if (type == 1)
                    {
                        //按rar格式解压
                        isUnZip = Compress.UnRAR(NXFun.TDPPMPath + NXFun.RarEXE, filename, ToFullPath(""));
                    }
                    if (!isUnZip)
                    {
                        MessageBox.Show(
                            "工艺文件打开失败!请确认以下几项:\r\n" +
                            "1:文件有是否有效;\r\n" +
                            "2:工艺临时文件夹或其中文件若处于打开状态请关闭。");
                        return;
                    }
                    //检测文件有效性
                    if (!NXFun.isFileExist(XmlFile))
                    {
                        MessageBox.Show("工艺数据文件丢失!请确认文件有效!");
                    }
                    //检测版本有效性,若旧版则自动升级
                    XML3DPPM.Update3dppm(XmlFile, TemplateXML);


                    OpenOrCreateProjectInit();
                    //打开所有模型
                    List <S_Model> ModelList = XML3DPPM.GetModelList(XmlFile);
                    foreach (S_Model model in ModelList)
                    {
                        if (!String.IsNullOrEmpty(model.filename))
                        {
                            NXFun.OpenPrtQuiet(ToFullPath(model.filename));
                        }
                    }
                    SetStatusLabel("工艺打开成功!", 2);
                }
            }
        }