示例#1
0
 public void Init()
 {
     _mocks      = new MockRepository();
     _topObject  = _mocks.StrictMock <ITopObject>();
     _dimensions = new RectangleF(0, 0, 1000, 1000);
     _data       = new XElement("TODO");
 }
示例#2
0
        internal EditOffsetViewModel(XElement data, ITopObject topObject)
        {
            _data      = data;
            _topObject = topObject;
            _wallHole  = new WallHole(data, topObject);

            Init();

            this.SubmitCommand = new RelayCommand(Submit);
        }
示例#3
0
        internal WallHole(XElement data, ITopObject topObject)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (topObject == null)
            {
                throw new ArgumentNullException(nameof(topObject));
            }

            _xmlData   = new XmlAdapter(data);
            _topObject = topObject;

            WallHoleData wallHoleData = (_xmlData.IsWinOffsetSpecified()) ? _xmlData.GetCurrentData() : GetTopObjectWallHoleData();

            Init(wallHoleData);
        }
示例#4
0
        internal bool ApplyTo(ITopObject topObject)
        {
            // round dimensions
            var mainDim = GetRounded(this.Size);
            var tl      = GetRounded(this.TopLeft);
            var tr      = GetRounded(this.TopRight);
            var br      = GetRounded(this.BottomRight);
            var bl      = GetRounded(this.BottomLeft);

            bool shouldHorScale  = false;
            bool shouldVertScale = false;

            // test scale for left
            if (ShouldScale(mainDim.Height, tl.Height, bl.Height))
            {
                shouldVertScale = true;
            }

            // test scale for top
            if (ShouldScale(mainDim.Width, tl.Width, tr.Width))
            {
                shouldHorScale = true;
            }

            // test scale for right
            if (ShouldScale(mainDim.Height, tr.Height, br.Height))
            {
                shouldVertScale = true;
            }

            // test scale for bottom
            if (ShouldScale(mainDim.Width, br.Width, bl.Width))
            {
                shouldHorScale = true;
            }

            bool doScale = false;

            if (shouldHorScale || shouldVertScale)
            {
                if (shouldHorScale && shouldVertScale)
                {
                    if (Abs(mainDim.Height - mainDim.Width) < DELTA)
                    {
                        doScale = true;
                    }
                }
                else
                {
                    doScale = true;
                }
            }
            if (doScale && !_wasScaled)
            {
                float scaleFactor = GetScaleFactor((shouldHorScale) ? this.Size.Width : this.Size.Height);
                var   newOutline  = this.Scale(scaleFactor);
                return(newOutline.ApplyTo(topObject));
            }

            // validate left
            float sumL = tl.Height + bl.Height;

            if (sumL > mainDim.Height)
            {
                bl.Height = mainDim.Height - tl.Height;
            }

            // validate top
            float sumT = tl.Width + tr.Width;

            if (sumT > mainDim.Width)
            {
                tr.Width = mainDim.Width - tl.Width;
            }

            // validate right
            float sumR = tr.Height + br.Height;

            if (sumR > mainDim.Height)
            {
                br.Height = mainDim.Height - tr.Height;
            }

            // validate bottom
            float sumB = br.Width + bl.Width;

            if (sumB > mainDim.Width)
            {
                br.Width = mainDim.Width - bl.Width;
            }

            // vynulování šikmin
            for (int i = 0; i < 4; i++)
            {
                topObject.set_Slants(i, SizeF.Empty);
            }

            // nastavení nových rozměrů
            topObject.Dimensions = new RectangleF(PointF.Empty, mainDim);
            topObject.set_Slants(0, tl);
            topObject.set_Slants(1, tr);
            topObject.set_Slants(2, br);
            topObject.set_Slants(3, bl);

            if (topObject.Update(true))
            {
                topObject.CheckPoint();
                topObject.Invalidate();

                return(true);
            }
            else
            {
                topObject.Undo(null);

                return(false);
            }
        }