Esempio n. 1
0
        // load nest task from task file.
        static public NestTaskEx LoadNestTask_from_taskFile(String strFilePath, List <KeyValuePair <long, string> > partDxfPath, List <KeyValuePair <long, string> > matDxfPath,
                                                            Dictionary <long, int> partColorConfig, ImpDataListEx impDataList, ref int iNestingTime)
        {
            NestTaskEx nestTask = new NestTaskEx();

            // load the task file.
            XmlDocument  xmlDocument = new XmlDocument();
            StreamReader reader      = new StreamReader(strFilePath, Encoding.UTF8);

            xmlDocument.Load(reader);

            // the version.
            XmlNode taskNode     = xmlDocument.SelectSingleNode("NestTask");
            int     iTaskVersion = Convert.ToInt32(taskNode.Attributes["taskVersion"].Value);

            if (iTaskVersion == TASK_VERSION_1)
            {
                // load param.
                XmlNode     paramNode = taskNode.SelectSingleNode("Param");
                NestParamEx nestParam = LoadNestParam_V1(paramNode, ref iNestingTime);
                nestTask.SetNestParam(nestParam);

                // load nest part info.
                XmlNode        partListNode = taskNode.SelectSingleNode("PartList");
                NestPartListEx nestParts    = LoadNestParts_V1(strFilePath, partListNode, partDxfPath, impDataList, partColorConfig);
                nestTask.SetNestPartList(nestParts);

                // load material info.
                XmlNode   matListNode = taskNode.SelectSingleNode("MaterialList");
                MatListEx mats        = LoadMats_V1(strFilePath, matListNode, matDxfPath, nestParam);
                nestTask.SetMatList(mats);
            }

            return(nestTask);
        }
Esempio n. 2
0
        private void loadTaskBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "Task Files|*.xml";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                String     strFilePath = openFileDialog.FileName;
                NestTaskEx nestTask    = TaskStorage.LoadNestTask_from_taskFile(strFilePath, m_partDxfPath, m_matDxfPath, m_partColorConfig, m_impDataList, ref m_iNestingTime);
                m_nestParam = nestTask.GetNestParam();

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

                // clean list.
                partListView.Items.Clear();
                matListView.Items.Clear();

                // init part list.
                {
                    m_nestPartList = nestTask.GetNestPartList();
                    for (int i = 0; i < m_nestPartList.Size(); i++)
                    {
                        AddPart_to_listCtrl(m_nestPartList.GetNestPartByIndex(i), "");
                    }

                    // 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();
                    }
                }

                // init material.
                {
                    m_matList = nestTask.GetMatList();
                    for (int i = 0; i < m_matList.Size(); i++)
                    {
                        AddMat(m_matList.GetMatByIndex(i));
                    }
                }

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

                Preview_selected_part();
                Preview_selected_material();
            }
        }
Esempio n. 3
0
        static private void SaveNestParts(XmlDocument xmlDoc, XmlNode partListNode, NestPartListEx nestParts, List <KeyValuePair <long, string> > partDxfPath, Dictionary <long, int> partColorConfig)
        {
            for (int i = 0; i < nestParts.Size(); i++)
            {
                NestPartEx nestPart = nestParts.GetNestPartByIndex(i);

                XmlElement partNode = xmlDoc.CreateElement("Part");
                partListNode.AppendChild(partNode);

                // path node.
                {
                    for (int j = 0; i < partDxfPath.Count; j++)
                    {
                        if (partDxfPath[j].Key == nestPart.GetID())
                        {
                            XmlElement pathNode = xmlDoc.CreateElement("Path");
                            pathNode.InnerText = partDxfPath[j].Value;
                            partNode.AppendChild(pathNode);
                            break;
                        }
                    }
                }

                // Count
                {
                    XmlElement countNode = xmlDoc.CreateElement("Count");
                    countNode.InnerText = nestPart.GetNestCount().ToString();
                    partNode.AppendChild(countNode);
                }

                // Rotate.
                {
                    XmlElement rotateNode = xmlDoc.CreateElement("Rotate");
                    rotateNode.InnerText = ((int)nestPart.GetRotStyle()).ToString();
                    partNode.AppendChild(rotateNode);

                    // custom angles.
                    if (nestPart.GetRotStyle() == PART_ROT_STYLE_EX.PART_ROT_CUSTOM_ANG)
                    {
                        // the angle-string.
                        string    strAngs = "";
                        ArrayList angles  = nestPart.GetCustomRotAng();
                        for (int k = 0; k < angles.Count; k++)
                        {
                            double dAngle = (double)angles[k];
                            strAngs += dAngle.ToString("0.00000000");
                            strAngs += ",";
                        }

                        // append the node.
                        XmlElement customAngleNode = xmlDoc.CreateElement("CustomAng");
                        customAngleNode.InnerText = strAngs;
                        partNode.AppendChild(customAngleNode);
                    }
                }

                // part color.
                {
                    XmlElement colorNode = xmlDoc.CreateElement("Color");
                    colorNode.InnerText = partColorConfig[nestPart.GetPart().GetID()].ToString();
                    partNode.AppendChild(colorNode);
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        // display the nesting result.
        private void DisplayNestResult()
        {
            if (m_sheetList == null)
            {
                return;
            }

            m_bDisableEvent = true;

            // display detail info of each sheet.
            shtListView.Items.Clear();
            for (int i = 0; i < m_sheetList.Size(); i++)
            {
                SheetEx sheet = m_sheetList.GetSheetByIndex(i);

                // insert a row.
                int          iCount = shtListView.Items.Count + 1;
                ListViewItem item   = shtListView.Items.Add(iCount.ToString());

                // "name" column.
                item.SubItems.Add(sheet.GetName());

                // "sheet count" column.
                item.SubItems.Add(sheet.GetCount().ToString());

                // "material name" column.
                item.SubItems.Add(sheet.GetMat().GetName());

                // hold the sheet ID.
                item.Tag = sheet.GetID();
            }

            /************************************************************************/
            // part group.

            NestPartListEx nestPartList = m_nestTask.GetNestPartList();

            // submitted part count.
            int iSubmitPartCount = 0;

            for (int i = 0; i < nestPartList.Size(); i++)
            {
                iSubmitPartCount += nestPartList.GetNestPartByIndex(i).GetNestCount();
            }
            subPartTextBox.Text = iSubmitPartCount.ToString();

            // the count of the nested parts.
            int iNestedPartCount = m_sheetList.GetPartInstTotalCount();

            nestPartTextBox.Text = iNestedPartCount.ToString();

            // display detailed info of each part.
            partListView.Items.Clear();
            for (int i = 0; i < nestPartList.Size(); i++)
            {
                NestPartEx nestPart = nestPartList.GetNestPartByIndex(i);
                PartEx     part     = nestPart.GetPart();

                // insert a row.
                int          iCount = partListView.Items.Count + 1;
                ListViewItem item   = partListView.Items.Add(iCount.ToString());

                // "name" column.
                item.SubItems.Add(part.GetName());

                // "submitted count" column.
                item.SubItems.Add(nestPart.GetNestCount().ToString());

                // "nested count" column.
                int iNestedCount = m_sheetList.GetPartInstCount(part.GetID());
                item.SubItems.Add(iNestedCount.ToString());
            }
            /************************************************************************/

            /************************************************************************/
            // material group.

            MatListEx matList = m_nestTask.GetMatList();

            // the utilization of material.
            double dUtilization = NestHelper.CalcMatUtil(m_sheetList, m_nestTask.GetNestParam());

            utilTextBox.Text = dUtilization.ToString("0.00");

            matListView.Items.Clear();
            for (int i = 0; i < matList.Size(); i++)
            {
                MatEx mat = matList.GetMatByIndex(i);

                // insert a row.
                int          iCount = matListView.Items.Count + 1;
                ListViewItem item   = matListView.Items.Add(iCount.ToString());

                // "name" column.
                item.SubItems.Add(mat.GetName());

                // "submitted count" column.
                item.SubItems.Add(mat.GetCount().ToString());

                // "consumed count" column.
                int iConsumedCount = m_sheetList.GetSheetCount(mat.GetID());
                item.SubItems.Add(iConsumedCount.ToString());
            }
            /************************************************************************/

            // preview the first sheet.
            if (shtListView.Items.Count > 0)
            {
                shtListView.Items[0].Selected = true;

                // get the select sheet.
                ListView.SelectedListViewItemCollection selItems = shtListView.SelectedItems;
                ListViewItem item          = selItems[0];
                long         iSheetID      = (long)item.Tag;
                SheetEx      selectedSheet = m_sheetList.GetSheetByID(iSheetID);

                // fit the window.
                DrawHelper.FitWindow(selectedSheet.GetMat().GetBoundaryRect(), m_shtViewPort, shtPreViewWnd);

                PreviewSheet();
            }

            m_bDisableEvent = false;
        }