Esempio n. 1
0
        private void Edit_Load(object sender, EventArgs e)
        {
            _history = new HistoryDrawing(InitialBmp);
            var rf = new RoomFigure
            {
                FirstLocationPoint  = new PointF(5, 5),
                SecondLocationPoint = new PointF(InitialBmp.Width - 5, InitialBmp.Height - 5)
            };

            rf.Draw(ref InitialBmp, rf.FirstLocationPoint, rf.SecondLocationPoint, _factor);
            _history.AddFigure(rf);
            _historyIterator.HistoryUpdate(_history.CountFigures(), _history.CountFigures());
            pictureBox1.Image = InitialBmp;
            pictureBox1.Top   = 5;
            pictureBox1.Left  = 5;
        }
Esempio n. 2
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            //if (selectedItem != null)
            //{
            //    Factor.UnCountFactor(ref pos, _factor);
            //    History.RemoveOfficeFigureAfterByIndex(_historyIterator.Current);

            //    selectedItem.FirstLocationPoint = pos;

            //    if (!IsOptionalDrawing)
            //    {
            //        var tmpItem = selectedItem;
            //        var resCoor = CoordinateCorrector.CorrectOfficeCoordinate(ref tmpItem, bmp, _factor, History);
            //        selectedItem = tmpItem;
            //        if (resCoor)
            //        {
            //            selectedItem.Draw(ref bmp, selectedItem.FirstLocationPoint, _factor);
            //            History.AddOfficeFigure(selectedItem.Clone() as OfficeFigure);
            //            _historyIterator.HistoryUpdate(History.CountOfficeFigures(), History.CountOfficeFigures());
            //        }
            //        else
            //        {
            //            FormsHelper.FormWarningMeassage("Нельзя так разместить объект типа \"" + selectedItem.ToString() + "\"!" +
            //                Environment.NewLine + "Возможно объект пересекается с другими объектами.");
            //        }
            //    }
            //    else
            //    {
            //        if (++_buttonClicks == 1)
            //        {
            //            _start = pos;
            //        }
            //        else
            //        {
            //            _end = pos;
            //            _buttonClicks = 0;
            //            var tmp = selectedItem as TwistedPair;
            //            selectedItem.Draw(ref bmp, selectedItem.FirstLocationPoint, _factor);
            //            History.AddOfficeFigure(selectedItem.Clone() as OfficeFigure);
            //            _historyIterator.HistoryUpdate(History.CountOfficeFigures(), History.CountOfficeFigures());
            //        }
            //    }
            //}
            var currentPosition       = (PointF)pictureBox1.PointToClient(MousePosition);
            var selectedItem          = listBox1.SelectedItem as OfficeFigure;
            var isOptionalDrawing     = selectedItem is TwistedPair;
            var isNeedMoreDrawingArea = selectedItem is Switchboard;
            var bmp = (Bitmap)pictureBox1.Image;

            _buttonClicker.Click();

            if (!_buttonClicker.IsSecondClick())
            {
                BlockInstruments();
                _start = currentPosition;
                Factor.UnCountFactor(ref _start, _factor);
                SaveBmp(bmp);
                _stp.DrawPoint(ref bmp, _start, _factor);
                selectedItem.FirstLocationPoint = currentPosition;
                if (!isOptionalDrawing)
                {
                    _buttonClicker.RemoveStatistics();
                    History.RemoveOfficeFigureAfterByIndex(_historyIterator.Current);

                    var tmpItem = selectedItem;
                    var resCoor = true;
                    if (!isNeedMoreDrawingArea)
                    {
                        resCoor = CoordinateCorrector.CorrectOfficeCoordinate(ref tmpItem, bmp, _factor, History);  // Временный хак, сейчас можно поставить switch на стол
                    }
                    selectedItem = tmpItem;
                    if (resCoor)
                    {
                        RestoreBmp(ref bmp);
                        selectedItem.Draw(ref bmp, selectedItem.FirstLocationPoint, _factor);
                        History.AddOfficeFigure(selectedItem.Clone() as OfficeFigure);
                        _historyIterator.HistoryUpdate(History.CountOfficeFigures(), History.CountOfficeFigures());
                    }
                    else
                    {
                        FormsHelper.FormWarningMeassage("Нельзя так разместить объект типа \"" + selectedItem.ToString() + "\"!" +
                                                        Environment.NewLine + "Возможно объект пересекается с другими объектами.");
                        RestoreBmp(ref bmp);
                    }
                    UnBlockInstruments();
                }
            }
            else
            {
                RestoreBmp(ref bmp);
                _end = currentPosition;
                var twisted = selectedItem as TwistedPair;
                twisted.Points.Add(_end);
                History.RemoveOfficeFigureAfterByIndex(_historyIterator.Current);
                twisted.DrawLine(ref bmp, _start, _end, _factor, History);
                History.AddOfficeFigure(twisted);
                _historyIterator.HistoryUpdate(History.CountOfficeFigures(), History.CountOfficeFigures());
                twisted.Points.Clear();
                UnBlockInstruments();
            }



            pictureBox1.Image = bmp;
        }