Ejemplo n.º 1
0
        public SheetInfoForm(ImpDataListEx impDataList, Dictionary <long, int> partColorConfig, SheetEx sheet)
        {
            m_impDataList     = impDataList;
            m_partColorConfig = partColorConfig;
            m_sheet           = sheet;

            InitializeComponent();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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);
        }
Ejemplo 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);
        }
Ejemplo n.º 5
0
        // load part object from dxf/dwg file.
        static public PartEx LoadPartFromDxfdwg(String strFilePath, ImpDataListEx impDataList)
        {
            PartEx part = null;

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

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

            // build part object.
            GeomItemListEx  geomItemList  = impData.GetAllGeomItem();
            AncillaryDataEx ancillaryData = new AncillaryDataEx();

            part = new PartEx(strFileName, geomItemList, ancillaryData);
            impData.SetPartID(part.GetID());
            impDataList.AddImpData(impData);

            return(part);
        }
Ejemplo n.º 6
0
        // draw the part placements.
        static public void DrawPartPmts(PartPmtListEx partPmts, PartPmtListEx selected_partPmts, GlViewPortEx viewPort, Dictionary <long, int> partColorConfig, ImpDataListEx impDataList)
        {
            for (int k = 0; k < partPmts.Size(); k++)
            {
                PartPmtEx partPmt = partPmts.GetPartPmtByIndex(k);
                PartEx    part    = partPmt.GetPart();

                // set the color and line width.
                if (selected_partPmts != null && selected_partPmts.GetPartPmtByID(partPmt.GetID()) != null)
                {
                    viewPort.SetLineWidth(6);
                    viewPort.SetDrawColor(Color.Red);
                }
                else
                {
                    viewPort.SetLineWidth(2);
                    int iColor = partColorConfig[part.GetID()];
                    viewPort.SetDrawColor(ColorTranslator.FromOle(iColor));
                }

                // get the ImpData object.
                ImpDataEx impData = null;
                for (int m = 0; m < impDataList.Size(); m++)
                {
                    ImpDataEx tmpImpData = impDataList.GetImpDataByIndex(m);
                    if (tmpImpData.GetPartID() == part.GetID())
                    {
                        impData = tmpImpData;
                        break;
                    }
                }

                // draw the first instance in the grid.
                {
                    // draw base geom.
                    GeomItemListEx geomItems_not_poly = impData.GetBaseGeomList();
                    if (geomItems_not_poly != null)
                    {
                        viewPort.DrawGeomItemList_With_Mat(geomItems_not_poly, partPmt.GetMatrix());
                    }

                    // draw poly data.
                    PolyDataListEx polyDataList = impData.GetPolyDataList();
                    if (polyDataList != null)
                    {
                        for (int m = 0; m < polyDataList.Size(); m++)
                        {
                            PolyDataEx polyData = polyDataList.GetPolyDataByIndex(m);
                            viewPort.DrawLoop_With_Mat(polyData, partPmt.GetMatrix());
                        }
                    }
                }


                // draw other parts in the grid.
                if (partPmt.IsGrid())
                {
                    int    iColCount = partPmt.GetColCount();
                    int    iRowCount = partPmt.GetRowCount();
                    double dSpacingX = partPmt.GetSpacingX();
                    double dSpacingY = partPmt.GetSpacingY();
                    for (int i = 0; i < iColCount; i++)
                    {
                        for (int j = 0; j < iRowCount; j++)
                        {
                            if (i == 0 && j == 0)
                            {
                                continue;
                            }

                            // prepare the transform matrix.
                            double     dOffsetX   = dSpacingX * i;
                            double     dOffsetY   = dSpacingY * j;
                            Vector2DEx offsetVect = new Vector2DEx(dOffsetX, dOffsetY);
                            Matrix2DEx mat        = partPmt.GetMatrix();
                            mat.Transfer(offsetVect.X(), offsetVect.Y());

                            // draw base geom.
                            GeomItemListEx geomItems_not_poly = impData.GetBaseGeomList();
                            if (geomItems_not_poly != null)
                            {
                                viewPort.DrawGeomItemList_With_Mat(geomItems_not_poly, mat);
                            }

                            // draw poly data.
                            PolyDataListEx polyDataList = impData.GetPolyDataList();
                            if (polyDataList != null)
                            {
                                for (int m = 0; m < polyDataList.Size(); m++)
                                {
                                    PolyDataEx polyData = polyDataList.GetPolyDataByIndex(m);
                                    viewPort.DrawLoop_With_Mat(polyData, mat);
                                }
                            }
                        }
                    }
                }
            }
        }