using CoreUnit.Common; using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace CoreUnit.Control.UserControl.Canvas.Dialog { public partial class ArrayCopyDialog : FormBase { public ArrayCopyDialog() { InitializeComponent(); } #region 사용자 정의 함수 CanvasCtrl m_canvas; public void Run(CanvasCtrl canvas) { m_canvas = canvas; ShowDialog(); } #endregion private void btnCopyLineArray_Click(object sender, EventArgs e) { if (m_canvas.Model.SelectedObjects.Count == UInt16.MinValue) { throw new Exception("ERR_SCANNER_CANVAS_USER_CONTROL_NOT_SELECT_OBJECTS_IN_ARRAY_COPY"); } List ptList = new List(); List copies = new List(); foreach (IDrawObject obj in m_canvas.Model.SelectedObjects) { copies.Add(obj.Clone()); if (obj is Line) { ptList.Add(((Line)obj).P1); ptList.Add(((Line)obj).P2); } else if (obj is Dot) { ptList.Add(((Dot)obj).P1); } else if (obj is Spline) { ptList.Add(((Spline)obj).Center); } else if (obj is SnowMan) { ptList.Add(((SnowMan)obj).P1); ptList.Add(((SnowMan)obj).P2); } else if (obj is Arc) { ptList.Add(((Arc)obj).Center); } else if (obj is Group) { ptList.Add(((Group)obj).P1); ptList.Add(((Group)obj).P2); ptList.Add(((Group)obj).P3); ptList.Add(((Group)obj).P3); } } RectangleF rect = ScreenUtils.GetRect(ptList, 0); List arrayCopyPositions = new List(); uint columnCount = (uint)Int32.Parse(tbLineArrayColumnCount.Text); uint rowCount = (uint)Int32.Parse(tbLineArrayRowCount.Text); float width = (float)Double.Parse(tbWidthPerArray.Text); float height = (float)Double.Parse(tbHeightPerArray.Text); float initXPos = 0, initYPos = 0; float XPos = initXPos, YPos = initYPos; for (int row = 0; row < rowCount; row++) { //수정-안오산-161020-배열복사시 경계 기준이 아닌 중심 기준으로 변경 //YPos = height * row + rect.Height * row; YPos = height * row; for (int col = 0; col < columnCount; col++) { //XPos = width * col + rect.Width * col; XPos = width * col; arrayCopyPositions.Add(new PointF(XPos, YPos)); } } arrayCopyPositions.RemoveAt(0); m_canvas.Model.IsArrayCopying = true; m_canvas.Model.SelectedCopyObject = new List(); foreach (IDrawObject obj in copies) { m_canvas.Model.SelectedCopyObject.Add(obj); } foreach (PointF p in arrayCopyPositions) { m_canvas.Model.CopyObjects(new UnitPoint(p.X, p.Y), copies); } m_canvas.Model.IsArrayCopying = false; //m_canvas.Model.SelectedCopyObject = new List(); m_canvas.DoInvalidate(true); } private void tbLineArrayColumnCount_KeyPress(object sender, KeyPressEventArgs e) { if (!(Char.IsDigit(e.KeyChar)) && (e.KeyChar != 8)) //8:백스페이스,45:마이너스,46:소수점 { e.Handled = true; } } private void tbLineArrayRowCount_KeyPress(object sender, KeyPressEventArgs e) { if (!(Char.IsDigit(e.KeyChar)) && (e.KeyChar != 8)) //8:백스페이스 { e.Handled = true; } } private void tbWidthPerArray_KeyPress(object sender, KeyPressEventArgs e) { if (!(Char.IsDigit(e.KeyChar)) && (e.KeyChar != 8) && (e.KeyChar != 46)) //8:백스페이스,45:마이너스,46:소수점 { e.Handled = true; } } private void tbHeightPerArray_KeyPress(object sender, KeyPressEventArgs e) { if (!(Char.IsDigit(e.KeyChar)) && (e.KeyChar != 8) && (e.KeyChar != 46)) //8:백스페이스,45:마이너스,46:소수점 { e.Handled = true; } } } }