Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="angleSpace"></param>
        /// <param name="count"></param>
        private void AddArrayDrawObject(double angleSpace, int count)
        {
            List <IDrawObject> ldrawobjects = new List <IDrawObject>();

            foreach (var item in drawObjects)
            {
                for (int i = 1; i < count; i++)
                {
                    IDrawObject      drawObject      = item.Clone();
                    IDrawTranslation drawTranslation = drawObject as IDrawTranslation;
                    if (drawTranslation != null)
                    {
                        drawTranslation.DoRotate(RotateCenterUnitPoint, i * angleSpace, false);//默认逆时针
                        //drawTranslation.DoRotate(RotateCenterUnitPoint, ((i-1) * angleSpace+addAngle)-90, true);//默认逆时针
                    }
                    drawObject.GroupParam.FigureSN = ++GlobalModel.TotalDrawObjectCount;
                    ldrawobjects.Add(drawObject);
                }
            }
            if (ldrawobjects.Count > 0)
            {
                uCCanvas.Model.AddObjectOnDrawing(ldrawobjects);
            }
            uCCanvas.Model.DrawingLayer.UpdateSN();
        }
Пример #2
0
        public void ArrayRectangle()
        {
            //确认板材位置,所有图形最大尺寸
            GetAllDrawingsMaxMinPoint(allDrawObjects, out UnitPoint maxPoint, out UnitPoint minPoint);
            //获取布满坐标
            //左下角坐标
            UnitPoint p1 = new UnitPoint(maxPoint.X + 10, maxPoint.Y - arrayFullModel.PlateHeight);
            UnitPoint p2 = new UnitPoint(maxPoint.X + 10 + arrayFullModel.PlateWidth, maxPoint.Y);

            //计算数量
            CalRowAndColCount(drawObjects, out int rowCount, out int colCount);
            if (rowCount <= 0 || colCount <= 0)
            {
                return;
            }
            marginDrawObjects = new List <IDrawObject>();
            int rowCoeff = 1;
            int colCoeff = 1;
            //偏移间距
            UnitPoint offset = new UnitPoint(arrayFullModel.PartsSpacing, arrayFullModel.PartsSpacing);

            //零件左下角坐标
            GetAllDrawingsMaxMinPoint(drawObjects, out UnitPoint maxDrawObjectPoint, out UnitPoint minDrawObjectPoint);
            // UnitPoint drawObjectPoint = minDrawObjectPoint;
            //计算偏移距离

            float  thWidth  = UCCanvas.GetThresholdWidth();
            double ofx      = maxDrawObjectPoint.X - minDrawObjectPoint.X - thWidth;
            double ofy      = maxDrawObjectPoint.Y - minDrawObjectPoint.Y - thWidth;
            int    objcount = GlobalModel.TotalDrawObjectCount;

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < colCount; j++)
                {
                    for (int k = 0; k < drawObjects.Count; k++)
                    {
                        IDrawObject drawObject = drawObjects[k].Clone();

                        drawObject.GroupParam.FigureSN = ++objcount;
                        if (i == 0 && j == 0)
                        {
                            drawObject.Move(new UnitPoint((p1.X - minDrawObjectPoint.X - thWidth / 2 + arrayFullModel.PlateRetainEdge), (p1.Y - minDrawObjectPoint.Y - thWidth / 2 + arrayFullModel.PlateRetainEdge)));
                        }
                        else
                        {
                            double movex = (p1.X - minDrawObjectPoint.X - thWidth / 2 + arrayFullModel.PlateRetainEdge);
                            movex = (movex + (j * (offset.X + ofx * colCoeff)));
                            double movey = (p1.Y - minDrawObjectPoint.Y - thWidth / 2 + arrayFullModel.PlateRetainEdge);
                            movey = movey + (i * (offset.Y + ofy * rowCoeff));
                            drawObject.Move(new UnitPoint(movex, movey));
                        }
                        marginDrawObjects.Add(drawObject);
                    }
                }
            }

            double offsetWidth  = (colCount - 1) * offset.X + colCount * ofx * colCoeff + arrayFullModel.PlateRetainEdge;
            double offsetHeight = (rowCount - 1) * offset.Y + rowCount * ofy * rowCoeff + arrayFullModel.PlateRetainEdge;

            double totalwidth  = arrayFullModel.PlateWidth - arrayFullModel.PlateRetainEdge;
            double totalheight = arrayFullModel.PlateHeight - arrayFullModel.PlateRetainEdge;

            double lastWidth  = totalwidth - offsetWidth;
            double lastHeight = totalheight - offsetHeight;
            //旋转
            List <IDrawObject> ldrawobjectsnew = new List <IDrawObject>();

            for (int k = 0; k < drawObjects.Count; k++)
            {
                IDrawObject      drawObject      = drawObjects[k].Clone();
                IDrawTranslation drawTranslation = drawObject as IDrawTranslation;
                {
                    UnitPoint centerAxis = new UnitPoint((maxDrawObjectPoint.X + minDrawObjectPoint.X) / 2, (maxDrawObjectPoint.Y + minDrawObjectPoint.Y) / 2);
                    drawTranslation.DoRotate(centerAxis, 90, false);
                }
                ldrawobjectsnew.Add(drawObject);
            }
            //确认旋转后最大尺寸
            GetAllDrawingsMaxMinPoint(ldrawobjectsnew, out UnitPoint maxPointc, out UnitPoint minPointc);

            ///偏移距离
            double ofcx = maxPointc.X - minPointc.X - thWidth;
            double ofcy = maxPointc.Y - minPointc.Y - thWidth;

            if (lastWidth > (offset.X + ofcx))
            {
                CalRowAndColCount2(drawObjects, lastWidth, ofcx + offset.X, totalheight, ofcy + offset.Y, out int rowCount1, out int colCount1);

                //左下角坐标
                UnitPoint pc1 = new UnitPoint(maxPoint.X + 10 + offsetWidth, maxPoint.Y - arrayFullModel.PlateHeight);

                for (int i = 0; i < rowCount1; i++)
                {
                    for (int j = 0; j < colCount1; j++)
                    {
                        for (int k = 0; k < drawObjects.Count; k++)
                        {
                            IDrawObject drawObject = ldrawobjectsnew[k].Clone();
                            drawObject.GroupParam.FigureSN = ++objcount;
                            if (i == 0 && j == 0)
                            {
                                drawObject.Move(new UnitPoint((pc1.X - minPointc.X - thWidth / 2) + arrayFullModel.PartsSpacing, (pc1.Y - minPointc.Y - thWidth / 2) + arrayFullModel.PlateRetainEdge));
                            }
                            else
                            {
                                drawObject.Move(
                                    new UnitPoint(
                                        ((pc1.X - minPointc.X - thWidth / 2) + arrayFullModel.PartsSpacing + (j * (offset.X + ofcx * colCoeff))),
                                        ((pc1.Y - minPointc.Y - thWidth / 2) + arrayFullModel.PlateRetainEdge + (i * (offset.Y + ofcy * rowCoeff)))
                                        )
                                    );
                            }
                            marginDrawObjects.Add(drawObject);
                        }
                    }
                }
            }

            if (lastHeight > (offset.Y + ofcy))
            {
                //CalRowAndColCount1(drawObjects, totalwidth ,lastHeight, out int rowCount1, out int colCount1);
                CalRowAndColCount2(drawObjects, totalwidth, ofcx + offset.X, lastHeight, ofcy + offset.Y, out int rowCount1, out int colCount1);

                //左下角坐标
                UnitPoint pc1 = new UnitPoint(maxPoint.X + 10, maxPoint.Y - arrayFullModel.PlateHeight + offsetHeight);


                for (int i = 0; i < rowCount1; i++)
                {
                    for (int j = 0; j < colCount1; j++)
                    {
                        for (int k = 0; k < ldrawobjectsnew.Count; k++)
                        {
                            IDrawObject drawObject = ldrawobjectsnew[k].Clone();
                            drawObject.GroupParam.FigureSN = ++objcount;
                            if (i == 0 && j == 0)
                            {
                                drawObject.Move(new UnitPoint((pc1.X - minPointc.X - thWidth / 2 + arrayFullModel.PlateRetainEdge), (pc1.Y - minPointc.Y - thWidth / 2) + arrayFullModel.PartsSpacing));
                            }
                            else
                            {
                                drawObject.Move(
                                    new UnitPoint(
                                        ((pc1.X - minPointc.X - thWidth / 2 + arrayFullModel.PlateRetainEdge) + (j * (offset.X + ofcx * colCoeff))),
                                        ((p1.Y - minPointc.Y - thWidth / 2 + offsetHeight + arrayFullModel.PartsSpacing) + (i * (offset.Y + ofcy * rowCoeff)))
                                        )
                                    );
                            }
                            marginDrawObjects.Add(drawObject);
                        }
                    }
                }
            }

            IDrawObject NewDrawObject = uCCanvas.Model.CreateObject("SingleRectangle", p1, null);

            NewDrawObject.OnMouseDown(uCCanvas.canvasWrapper, p2, null, null);
            DrawObjectBase drawData = NewDrawObject as DrawObjectBase;

            GlobalModel.TotalDrawObjectCount--;
            NewDrawObject.GroupParam.FigureSN = objcount + 1;
            drawData.IsBoard = true;
            marginDrawObjects.Add(NewDrawObject);

            if (drawData != null)
            {
                drawData.LayerId = (int)WSX.GlobalData.Model.LayerId.White;
            }

            if (GlobalModel.Params.ArrayFull.IsClearOriginalCompleted)
            {
                marginDrawObjects.ForEach(s => s.GroupParam.FigureSN = s.GroupParam.FigureSN - drawObjects.Count);
                uCCanvas.Model.ArrayObjects(drawObjects, marginDrawObjects);
            }
            else
            {
                uCCanvas.Model.ArrayObjects(null, marginDrawObjects);
            }
            uCCanvas.Model.DrawingLayer.UpdateSN();
        }