예제 #1
0
        static private NestPartListEx LoadNestParts_V1(string strTaskFilePath, XmlNode partListNode, List <KeyValuePair <long, string> > partDxfPath,
                                                       ImpDataListEx impDataList, Dictionary <long, int> partColorConfig)
        {
            NestPartListEx nestParts = new NestPartListEx();

            for (int i = 0; i < partListNode.ChildNodes.Count; i++)
            {
                XmlNode    partNode = partListNode.ChildNodes.Item(i);
                NestPartEx nestPart = new NestPartEx();

                // part Path.
                string strPartFileFullPath = partNode.SelectSingleNode("Path").InnerText;

                // load part.
                if (!File.Exists(strPartFileFullPath))
                {
                    // the new file path.
                    string strTaskFileFolder      = strTaskFilePath.Substring(0, strTaskFilePath.LastIndexOf("\\"));
                    string strPartFileName        = strPartFileFullPath.Substring(strPartFileFullPath.LastIndexOf("\\") + 1, strPartFileFullPath.Length - strPartFileFullPath.LastIndexOf("\\") - 1);
                    string strNewPartFileFullPath = strTaskFileFolder + "\\" + strPartFileName;

                    // try again.
                    if (!File.Exists(strNewPartFileFullPath))
                    {
                        string strMessage = "Cannot find part file: ";
                        MessageBox.Show(strMessage + strPartFileFullPath, "NestProfessor DEMO");
                        continue;
                    }
                    else
                    {
                        strPartFileFullPath = strNewPartFileFullPath;
                    }
                }
                PartEx part = NestHelper.LoadPartFromDxfdwg(strPartFileFullPath, impDataList);
                nestPart.SetPart(part);

                // nest count.
                nestPart.SetNestCount(Convert.ToInt32(partNode.SelectSingleNode("Count").InnerText));

                // rotate.
                nestPart.SetRotStyle((PART_ROT_STYLE_EX)Convert.ToInt32(partNode.SelectSingleNode("Rotate").InnerText));

                // custom angle.
                if (nestPart.GetRotStyle() == PART_ROT_STYLE_EX.PART_ROT_CUSTOM_ANG)
                {
                    ArrayList customRotAngs = new ArrayList();

                    string   strAngles = partNode.SelectSingleNode("CustomAng").InnerText;
                    string[] strArray  = strAngles.Split(',');
                    foreach (string strAngle in strArray)
                    {
                        double dAngle = Convert.ToDouble(strAngle);
                        customRotAngs.Add(dAngle);
                    }
                    nestPart.SetCustomRotAng(customRotAngs);
                }

                // color.
                int iColor = Convert.ToInt32(partNode.SelectSingleNode("Color").InnerText);

                nestParts.AddNestPart(nestPart);
                partDxfPath.Add(new KeyValuePair <long, string>(nestPart.GetID(), strPartFileFullPath));
                partColorConfig[nestPart.GetPart().GetID()] = iColor;
            }

            return(nestParts);
        }
예제 #2
0
        private void addPartBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "DXF Files|*.dxf|DWG Files|*.dwg";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            openFileDialog.Multiselect      = true;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                // disable select-change event.
                m_bDisableSelChgEvent = true;
                lblLoadPart.Text      = "零件加载中……";

                Task tk = new Task(new Action(() =>
                {
                    for (int i = 0; i < openFileDialog.FileNames.Length; i++)
                    {
                        String strFilePath = openFileDialog.FileNames[i];

                        //获取文件所在的文件夹名,用做订单号
                        var view = strFilePath.Split('\\');
                        var dir  = view[view.Length - 2];

                        // 从Dxf文件中加载零件对象
                        PartEx part = NestHelper.LoadPartFromDxfdwg(strFilePath, m_impDataList);

                        // 判断零件是否是闭合的
                        bool bClosedBoundary = NestFacadeEx.HasClosedBoundary(part, m_nestParam.GetConTol());
                        if (!bClosedBoundary)
                        {
                            MessageBox.Show("零件没有闭合!!!");
                            continue;
                        }

                        // build NestPartEx object.
                        NestPartEx nestPart = new NestPartEx(part, NestPriorityEx.MaxPriority(), 1, PART_ROT_STYLE_EX.PART_ROT_PID2_INCREMENT, false);
                        m_nestPartList.AddNestPart(nestPart);
                        m_partDxfPath.Add(new KeyValuePair <long, string>(nestPart.GetID(), strFilePath));
                        m_partColorConfig[nestPart.GetPart().GetID()] = ColorTranslator.ToOle(NestHelper.PickNextColor_4_part(ref m_iCurrentColorIndex));

                        // add part to list control.
                        this.Invoke(new Action(() =>
                        {
                            AddPart_to_listCtrl(nestPart, dir);
                        }));
                    }
                }));
                tk.Start();
                tk.ContinueWith(t => this.Invoke(new Action(() => { lblLoadPart.Text = string.Empty; })));

                // disable select-change event.
                m_bDisableSelChgEvent = false;

                // select the last row.
                if (partListView.Items.Count > 0)
                {
                    partListView.SelectedItems.Clear();
                    partListView.Items[partListView.Items.Count - 1].Selected = true;
                    partListView.Items[partListView.Items.Count - 1].Focused  = true;
                    partListView.Items[partListView.Items.Count - 1].EnsureVisible();
                }
            }
        }