Example #1
0
    public List <MyCutRebar> OutputLinearResults_by_Layout(CutEngine aCalculator, string name, double shortestLength)
    {
        List <MyCutRebar> tempCutRebar = new List <MyCutRebar>();

        string[] strTemp = new string[4];
        int      totalAmount = 0;//每组需要的数量
        int      StockIndex, StockCount, iPart, iLayout, partCount, partIndex, tmp, iStock;
        double   partLength, X, StockLength, angleStart, angleEnd;
        bool     rotated, StockActive;
        bool     isAngle = aCalculator.CrossSection > 0;
        string   ID      = "";

        //aCalculator.GetStockInfo();



        // Iterate by each layout and output information about each layout,
        // such as number and length of used stocks and part indices cut from the stocks
        for (iLayout = 0; iLayout < aCalculator.LayoutCount; iLayout++)//6
        {
            aCalculator.GetLayoutInfo(iLayout, out StockIndex, out StockCount);
            // StockIndex is global index of the first stock used in the layout iLayout
            // StockCount is quantity of stocks of the same length as StockIndex used for this layout
            if (StockCount > 0)
            {
                // sw.WriteLine("Layout={0}:  Start Stock={1};  Count of Stock={2}", iLayout, StockIndex, StockCount);
                bool       istrue = true;
                MyCutRebar cm     = new MyCutRebar();
                cm.totalNumber = aCalculator.UsedLinearStockCount;                    //获取总数
                                                                                      // Output information about each stock, such as stock Length
                for (iStock = StockIndex; iStock < StockIndex + StockCount; iStock++) //86
                {
                    if (aCalculator.GetLinearStockInfo(iStock, out StockLength, out StockActive, out ID))
                    {
                        //sw.WriteLine("Stock={0}:  Length={1}", iStock, StockLength);
                        // Output the information about parts cut from this stock
                        // First we get quantity of parts cut from the stock
                        partCount = aCalculator.GetPartCountOnStock(iStock);
                        // Iterate by parts and get indices of cut parts
                        for (iPart = 0; iPart < partCount; iPart++)//3
                        {
                            // Get global part index of iPart cut from the current stock
                            partIndex = aCalculator.GetPartIndexOnStock(iStock, iPart);
                            // Get length and location of the part
                            // X - coordinate on the stock where the part beggins.
                            if (isAngle)
                            {
                                aCalculator.GetResultLinearPart(partIndex, out tmp, out partLength, out angleStart, out angleEnd, out X, out rotated);
                                // Output the part information
                                Console.Write("Part= {0}:  X={1};  Length={2}; AngleStart={3}; AngleEnd={4}{5}\n",
                                              partIndex, X, partLength, angleStart, angleEnd, LinearTurn(rotated));
                            }
                            else
                            {
                                aCalculator.GetResultLinearPart(partIndex, out tmp, out partLength, out X, out ID);
                                // Output the part information
                                if (istrue)
                                {
                                    //List<RebarsCharacter> rebarsCharacter = new List<RebarsCharacter>();
                                    //Console.Write("Part= {0}:  截取的位置X={1};  截取的长度Length={2}\n", partIndex, X, partLength);
                                    cm.NeedNumber = StockCount;
                                    cm.lenghtList.Add(partLength);
                                    cm.locationLength.Add(X);
                                    cm.cardNumList.Add(ID);
                                    cm.name           = name;
                                    cm.FixedLength    = StockLength;
                                    cm.ShortestLength = shortestLength;
                                    if (iPart == partCount - 1)
                                    {
                                        /**************添加钢筋断料组合中的特征(长度*数量*料牌号)*******************/
                                        foreach (var v in cm.lenghtList.GroupBy(x => x).Select(x => new { length = x.Key, count = x.Count() }))
                                        {
                                            RebarCharacter rebarcharacter = new RebarCharacter();

                                            rebarcharacter.Length  = v.length;
                                            rebarcharacter.Count   = v.count;
                                            rebarcharacter.CardNum = null;
                                            cm.rebarCharacter.Add(rebarcharacter);
                                        }
                                        /*********************************/
                                        tempCutRebar.Add(cm);

                                        istrue = false;
                                    }
                                }

                                if (iLayout == aCalculator.LayoutCount - 1 && iStock == StockIndex + StockCount - 1)
                                {
                                    totalAmount = iStock;
                                }
                            }
                        }
                    }
                }
            }
        }
        return(tempCutRebar);
    }
Example #2
0
        /// <summary>
        /// Gera os resultados da otimização
        /// </summary>
        /// <param name="cEngine"></param>
        /// <param name="dados"></param>
        /// <param name="otimizacao"></param>
        /// <param name="dicPecas"></param>
        private void ObterResultadoOtimizacaoLinear(CutEngine cEngine, int idProd, List <PecaOtimizada> pecas, Entidades.Otimizacao otimizacao)
        {
            var result = cEngine.GuillotineSheet();

            if (!string.IsNullOrWhiteSpace(result))
            {
                throw new Exception(TrataErroOtimizacao(result));
            }

            int    stockNo, stockCount, iPart, partIndex, tmp;
            double stockLen, partCount, length, x;
            bool   active;

            //Percorre os layout gerados
            for (int iLayout = 0; iLayout < cEngine.LayoutCount; iLayout++)
            {
                // Obtem as informações do layout
                cEngine.GetLayoutInfo(iLayout, out stockNo, out stockCount);
                cEngine.GetLinearStockInfo(stockNo, out stockLen, out active);

                var layout = SourceContext.Instance.Create <LayoutPecaOtimizada>();

                layout.IdProd = idProd;
                layout.Qtde   = stockCount;

                otimizacao.LayoutsOtimizacao.Add(layout);

                // Obtem a quantidade de peças desse layout
                partCount = cEngine.GetPartCountOnStock(stockNo);

                // Percorre as peças dentro do layout
                for (iPart = 0; iPart < partCount; iPart++)
                {
                    partIndex = cEngine.GetPartIndexOnStock(stockNo, iPart);
                    cEngine.GetResultLinearPart(partIndex, out tmp, out length, out x);

                    var peca = pecas[partIndex];

                    peca.PosicaoX = (decimal)x;
                    peca.Sobra    = false;

                    layout.PecasOtimizadas.Add(peca);
                }

                // Percorre as sobras
                partCount = cEngine.GetWastePartCountOnStock(stockNo);
                for (iPart = 0; iPart < partCount; iPart++)
                {
                    partIndex = cEngine.GetWastePartIndexOnStock(stockNo, iPart);
                    cEngine.GetRemainingLinearPart(partIndex, out tmp, out length, out x);

                    var pecaSobra = SourceContext.Instance.Create <PecaOtimizada>();

                    pecaSobra.Sobra       = true;
                    pecaSobra.PosicaoX    = (decimal)x;
                    pecaSobra.Comprimento = (decimal)length;

                    layout.PecasOtimizadas.Add(pecaSobra);
                }
            }
        }