Пример #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);
        }
Пример #2
0
        public AdvParamForm(NestParamEx nestParam, int iNestingTime)
        {
            m_nestParam    = nestParam;
            m_iNestingTime = iNestingTime;

            InitializeComponent();
        }
Пример #3
0
        public NestResultForm(NestTaskEx nestTask, NestParamEx nestParam, NestProcessorEx nestProcessor, int iNestingTime, ImpDataListEx impDataList, Dictionary <long, int> partColorConfig)
        {
            m_nestTask        = nestTask;
            m_nestParam       = nestParam;
            m_nestProcessor   = nestProcessor;
            m_iNestingTime    = iNestingTime;
            m_impDataList     = impDataList;
            m_partColorConfig = partColorConfig;

            InitializeComponent();
        }
Пример #4
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();
            }
        }
Пример #5
0
 public QrCodeForm(ListView shtListView, SheetListEx m_sheetList, NestParamEx nestParam)
 {
     this.shtListView = shtListView;
     m_nestParam      = nestParam;
     this.m_sheetList = m_sheetList;
     InitializeComponent();
     cbShadowBmp.Visible = isDebug;
     Paneltext.Visible   = isDebug;
     panelQr.Visible     = isDebug;
     panelQrCode.Visible = isDebug;
     this.Size           = new Size(450, 670);
 }
Пример #6
0
        static private NestParamEx LoadNestParam_V1(XmlNode paramNode, ref int iNestingTime)
        {
            NestParamEx nestParam = new NestParamEx();

            // MatLeftMargin.
            nestParam.SetMatLeftMargin(Convert.ToDouble(paramNode.SelectSingleNode("MatLeftMargin").InnerText));

            // MatRightMargin.
            nestParam.SetMatRightMargin(Convert.ToDouble(paramNode.SelectSingleNode("MatRightMargin").InnerText));

            // MatTopMargin.
            nestParam.SetMatTopMargin(Convert.ToDouble(paramNode.SelectSingleNode("MatTopMargin").InnerText));

            // MatBottomMargin.
            nestParam.SetMatBottomMargin(Convert.ToDouble(paramNode.SelectSingleNode("MatBottomMargin").InnerText));

            // MatBottomMargin.
            nestParam.SetMatMargin(Convert.ToDouble(paramNode.SelectSingleNode("MatMargin").InnerText));

            // PartDis.
            nestParam.SetPartDis(Convert.ToDouble(paramNode.SelectSingleNode("PartDis").InnerText));

            // ConTol.
            nestParam.SetConTol(Convert.ToDouble(paramNode.SelectSingleNode("ConTol").InnerText));

            // PartRotStep.
            nestParam.SetPartRotStep(Convert.ToDouble(paramNode.SelectSingleNode("PartRotStep").InnerText));

            // StartCorner.
            nestParam.SetStartCorner((RECT_CORNER_EX)Convert.ToInt32(paramNode.SelectSingleNode("StartCorner").InnerText));

            // NestDir.
            nestParam.SetNestDir((NEST_DIRECTION_EX)Convert.ToInt32(paramNode.SelectSingleNode("NestDir").InnerText));

            // PartInPart.
            if (Convert.ToInt32(paramNode.SelectSingleNode("PartInPart").InnerText) == 1)
            {
                nestParam.IsPartInPart(true);
            }
            else if (Convert.ToInt32(paramNode.SelectSingleNode("PartInPart").InnerText) == 0)
            {
                nestParam.IsPartInPart(false);
            }

            // EvalFactor.
            nestParam.SetEvalFactor(Convert.ToInt32(paramNode.SelectSingleNode("EvalFactor").InnerText));

            // nesting time.
            iNestingTime = Convert.ToInt32(paramNode.SelectSingleNode("NestingTime").InnerText);

            return(nestParam);
        }
Пример #7
0
        // calc the utilization of the material.
        static public double CalcMatUtil(SheetListEx sheetList, NestParamEx nestParam)
        {
            double dUtilization = .0;

            // calculate the utilization of material.
            double dMatArea = .0, dNestedArea = .0;

            for (int i = 0; i < sheetList.Size(); i++)
            {
                SheetEx sheet       = sheetList.GetSheetByIndex(i);
                int     iSheetCount = sheet.GetCount();
                dMatArea += sheet.GetMat().GetArea() * iSheetCount;

                // go through each part placement object in the sheet.
                PartPmtListEx partPmtList = sheet.GetPartPmtList();
                for (int j = 0; j < partPmtList.Size(); j++)
                {
                    PartPmtEx partPmt = partPmtList.GetPartPmtByIndex(j);
                    PartEx    part    = partPmt.GetPart();

                    // the area of the part.
                    double dPartArea = NestFacadeEx.GetPartArea(part, nestParam.GetConTol());

                    // part count in the part placement object.
                    int iPartCount = 1;
                    if (partPmt.IsGrid())
                    {
                        iPartCount = partPmt.GetRowCount() * partPmt.GetColCount();
                    }
                    dNestedArea += iSheetCount * iPartCount * dPartArea;
                }
            }

            // figure out the utilization.
            if (dMatArea == 0 || dNestedArea == 0)
            {
                dUtilization = .0;
            }
            else
            {
                dUtilization = (dNestedArea / dMatArea) * 100;
            }

            return(dUtilization);
        }
Пример #8
0
        static private void SaveNestParam(XmlDocument xmlDoc, XmlNode paramNode, NestParamEx nestParam, int iNestingTime)
        {
            // MatLeftMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatLeftMargin");
                node.InnerText = nestParam.GetMatLeftMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // MatRightMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatRightMargin");
                node.InnerText = nestParam.GetMatRightMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // MatTopMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatTopMargin");
                node.InnerText = nestParam.GetMatTopMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // MatBottomMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatBottomMargin");
                node.InnerText = nestParam.GetMatBottomMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // MatMargin.
            {
                XmlElement node = xmlDoc.CreateElement("MatMargin");
                node.InnerText = nestParam.GetMatMargin().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // PartDis.
            {
                XmlElement node = xmlDoc.CreateElement("PartDis");
                node.InnerText = nestParam.GetPartDis().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // ConTol.
            {
                XmlElement node = xmlDoc.CreateElement("ConTol");
                node.InnerText = nestParam.GetConTol().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // PartRotStep.
            {
                XmlElement node = xmlDoc.CreateElement("PartRotStep");
                node.InnerText = nestParam.GetPartRotStep().ToString("0.0000000");
                paramNode.AppendChild(node);
            }

            // StartCorner.
            {
                XmlElement node = xmlDoc.CreateElement("StartCorner");
                node.InnerText = ((int)nestParam.GetStartCorner()).ToString();
                paramNode.AppendChild(node);
            }

            // NestDir.
            {
                XmlElement node = xmlDoc.CreateElement("NestDir");
                node.InnerText = ((int)nestParam.GetNestDir()).ToString();
                paramNode.AppendChild(node);
            }

            // PartInPart.
            {
                XmlElement node = xmlDoc.CreateElement("PartInPart");
                if (nestParam.IsPartInPart())
                {
                    node.InnerText = "1";
                }
                else
                {
                    node.InnerText = "0";
                }
                paramNode.AppendChild(node);
            }

            // EvalFactor.
            {
                XmlElement node = xmlDoc.CreateElement("EvalFactor");
                node.InnerText = nestParam.GetEvalFactor().ToString();
                paramNode.AppendChild(node);
            }

            // nest time.
            {
                XmlElement node = xmlDoc.CreateElement("NestingTime");
                node.InnerText = iNestingTime.ToString();
                paramNode.AppendChild(node);
            }
        }
Пример #9
0
        static private MatListEx LoadMats_V1(string strTaskFilePath, XmlNode matListNode, List <KeyValuePair <long, string> > matDxfPath, NestParamEx nestParam)
        {
            MatListEx mats = new MatListEx();

            for (int i = 0; i < matListNode.ChildNodes.Count; i++)
            {
                XmlNode matNode = matListNode.ChildNodes.Item(i);

                // whether load material from file.
                XmlNode pathNode = matNode.SelectSingleNode("MatPath");
                if (pathNode != null)
                {
                    string strMaterialFileFullPath = pathNode.InnerText;
                    if (!File.Exists(strMaterialFileFullPath))
                    {
                        // the new file path.
                        string strTaskFileFolder          = strTaskFilePath.Substring(0, strTaskFilePath.LastIndexOf("\\"));
                        string strMaterialFileName        = strMaterialFileFullPath.Substring(strMaterialFileFullPath.LastIndexOf("\\") + 1, strMaterialFileFullPath.Length - strMaterialFileFullPath.LastIndexOf("\\") - 1);
                        string strNewMaterialFileFullPath = strTaskFileFolder + "\\" + strMaterialFileName;

                        // try again.
                        if (!File.Exists(strNewMaterialFileFullPath))
                        {
                            string strMessage = "Cannot find material file: ";
                            MessageBox.Show(strMessage + strMaterialFileFullPath, "NestProfessor DEMO");
                            continue;
                        }
                        else
                        {
                            strMaterialFileFullPath = strNewMaterialFileFullPath;
                        }
                    }

                    MatEx mat = NestHelper.LoadMatFromDxfdwg(strMaterialFileFullPath, nestParam);
                    mats.AddMat(mat);
                    matDxfPath.Add(new KeyValuePair <long, string>(mat.GetID(), strMaterialFileFullPath));

                    // count.
                    mat.SetCount(Convert.ToInt32(matNode.SelectSingleNode("Count").InnerText));
                }
                else
                {
                    RectMatEx rectMat = new RectMatEx();
                    mats.AddMat(rectMat);

                    // name
                    rectMat.SetName(matNode.SelectSingleNode("Name").InnerText);

                    // width.
                    double dWidth = Convert.ToDouble(matNode.SelectSingleNode("Width").InnerText);

                    // height.
                    double dHeight = Convert.ToDouble(matNode.SelectSingleNode("Height").InnerText);

                    // the material rect.
                    Rect2DEx matRect = new Rect2DEx(0, dWidth, 0, dHeight);
                    rectMat.SetMatRect(matRect);

                    // count.
                    rectMat.SetCount(Convert.ToInt32(matNode.SelectSingleNode("Count").InnerText));
                }
            }

            return(mats);
        }
Пример #10
0
        // load boundary polygon from dxf/dwg file.
        static public MatEx LoadMatFromDxfdwg(String strFilePath, NestParamEx nestParam)
        {
            MatEx mat = null;

            /************************************************************************/
            // load all geometry items from the dxf/dwg file.

            // the file name.
            int    iDotIndex   = strFilePath.LastIndexOf('.');
            int    iSlashIndex = strFilePath.LastIndexOf('\\');
            String strFileName = strFilePath.Substring(iSlashIndex + 1, iDotIndex - iSlashIndex - 1);

            // whether the file is dxf file or dwg file.
            bool   bDwg   = true;
            String strExt = strFilePath.Substring(iDotIndex, strFilePath.Length - iDotIndex);

            strExt = strExt.ToLower();
            if (strExt == ".dxf")
            {
                bDwg = false;
            }
            else if (strExt == ".dwg")
            {
                bDwg = true;
            }
            else
            {
                return(mat);
            }

            // extract geometry items from dxf/dwg file.
            ImpDataEx impData;

            if (!bDwg)
            {
                impData = NestFacadeEx.ExtractGeomItems(strFilePath);
            }
            else
            {
                // the temp folder for dxf.
                String strDxfPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                strDxfPath += "\\";
                strDxfPath += new Random().Next(1, 100000).ToString();
                strDxfPath += ".dxf";

                // save dxf file in tmp path.
                NestFacadeEx.Dwg2Dxf(strFilePath, strDxfPath);

                // extract geometry items from dxf file.
                impData = NestFacadeEx.ExtractGeomItems(strDxfPath);

                // delete the temp file.
                File.Delete(strDxfPath);
            }
            /************************************************************************/

            /************************************************************************/
            // get the polygons from the dxf/dwg file.

            // build the polygons of all the geometry items.
            GeomItemListEx geomItemList = impData.GetAllGeomItem();
            Poly2DListEx   polyList     = NestFacadeEx.BuildPolyListFromLineArc(geomItemList, nestParam.GetConTol());

            // if no closed polygon found, return.
            if (polyList.Size() == 0)
            {
                MessageBox.Show("No closed boundary found.", "NestProfessor DEMO");
                return(mat);
            }

            // the outer boundary polygon.
            int         iMaxIndex = polyList.GetMaxAreaPoly();
            Polygon2DEx outerPoly = polyList.GetPolygonByIndex(iMaxIndex);

            // the hole polygons.
            polyList.DelPolygonByIndex(iMaxIndex);
            Poly2DListEx holePolyList = polyList;
            /************************************************************************/

            /************************************************************************/
            // build the material object.

            // whether the boundary polygon is a rectangle.
            bool bRectMat = true;

            if (outerPoly.GetPtCount() != 4)
            {
                bRectMat = false;
            }
            else if (holePolyList.Size() > 0)
            {
                bRectMat = false;
            }
            else
            {
                // line items in the polygon.
                ArrayList  lineItems = outerPoly.GetLineList();
                LineItemEx lineItem1 = (LineItemEx)lineItems[0];
                LineItemEx lineItem2 = (LineItemEx)lineItems[1];
                LineItemEx lineItem3 = (LineItemEx)lineItems[2];
                LineItemEx lineItem4 = (LineItemEx)lineItems[3];

                if (Math.Abs(lineItem1.GetLength() - lineItem3.GetLength()) > 0.0001)
                {
                    bRectMat = false;
                }
                if (Math.Abs(lineItem2.GetLength() - lineItem4.GetLength()) > 0.0001)
                {
                    bRectMat = false;
                }

                Vector2DEx vect1 = lineItem1.GetBaseVector();
                Vector2DEx vect2 = lineItem2.GetBaseVector();
                if (!vect1.OrthogonalTo(vect2))
                {
                    bRectMat = false;
                }
            }

            // build the material object.
            if (bRectMat)
            {
                mat = new RectMatEx(strFileName, outerPoly.GetBoundaryRect(), 1);
            }
            else
            {
                PolyMatEx polyMat = new PolyMatEx(strFileName, outerPoly, 1);
                polyMat.SetUselessHoleList(holePolyList);
                mat = polyMat;
            }
            /************************************************************************/

            return(mat);
        }