Exemple #1
0
        public void Locate(int x, int y, List <CADShape> shapes, CADShape initialShape)
        {
            this.X          = x;
            this.Y          = y;
            this.X2         = x + Width;
            this.Y2         = Y - Height;
            this.Calculated = true;

            if (this.RightShape != null && this.RightShape.Place == Place && !this.RightShape.Calculated)
            {
                var nextX = this.X + this.Width;
                var nextY = this.Y;
                this.RightShape.Locate(nextX, nextY, shapes, initialShape);
            }

            if (this.LeftShape != null && this.LeftShape.Place == Place && !this.LeftShape.Calculated)
            {
                var nextX = this.X - this.LeftShape.Width;
                var nextY = this.Y;
                this.LeftShape.Locate(nextX, nextY, shapes, initialShape);
            }

            if (this.BottomShape != null && this.BottomShape.Place == Place && !this.BottomShape.Calculated)
            {
                var nextX = this.X;
                var nextY = this.Y - this.Height;
                this.BottomShape.Locate(nextX, nextY, shapes, initialShape);
            }

            if (this.TopShape != null && this.TopShape.Place == Place && !this.TopShape.Calculated)
            {
                var nextX = this.X;
                var nextY = this.Y + this.Height;
                this.TopShape.Locate(nextX, nextY, shapes, initialShape);
            }

            if (initialShape == this)
            {
                this.LocateOtherPlaces(x, y, shapes, this);
            }
        }
Exemple #2
0
        public void LocateOtherPlaces(int x, int y, List <CADShape> shapes, CADShape initialShape)
        {
            this.SearchOtherPlaces = true;

            if (this.RightShape != null && this.RightShape.Place != Place && !this.RightShape.Calculated)
            {
                var nextX = this.X + this.Width + (this.Place != this.RightShape.Place ? this.RightWall : 0);
                var nextY = this.Y - (this.RightShape.TopShape != null ? this.RightShape.TopWall : 0);

                this.RightShape.Locate(nextX, nextY, shapes, this.RightShape);
            }

            if (this.LeftShape != null && this.LeftShape.Place != Place && !this.LeftShape.Calculated)
            {
                var nextX = this.X - this.LeftShape.Width - (this.Place != this.LeftShape.Place ? this.LeftWall : 0);
                var nextY = this.Y;
                this.LeftShape.Locate(nextX, nextY, shapes, this.LeftShape);
            }

            if (this.BottomShape != null && this.BottomShape.Place != Place && !this.BottomShape.Calculated)
            {
                var nextX = this.X;
                var nextY = this.Y - this.Height - (this.Place != this.BottomShape.Place ? this.BottomWall : 0);

                var leftShape = shapes.Where(s => s.Calculated && s.X2 <= nextX && s.X2 >= nextX - s.RightWall && ((s.Y >= nextY && s.Y2 <= nextY) || (s.Y > nextY - this.BottomShape.Height && s.Y2 <= nextY - this.BottomShape.Height))).FirstOrDefault();
                if (leftShape != null)
                {
                    nextX = leftShape.X2 + leftShape.RightWall;
                }

                this.BottomShape.Locate(nextX, nextY, shapes, this.BottomShape);
            }

            if (this.TopShape != null && this.TopShape.Place != Place && !this.TopShape.Calculated)
            {
                var nextX = this.X;
                var nextY = this.Y + this.TopShape.Height + this.TopWall;
                this.TopShape.Locate(nextX, nextY, shapes, this.TopShape);
            }

            //Procurando novos comodos

            if (this.RightShape != null && this.RightShape.Place == Place && !this.RightShape.SearchOtherPlaces)
            {
                var nextX = this.X + this.Width + (this.Place != this.RightShape.Place ? this.RightWall : 0);
                var nextY = this.Y - (this.RightShape.TopShape != null ? this.RightShape.TopWall : 0);
                this.RightShape.LocateOtherPlaces(nextX, nextY, shapes, initialShape);
            }

            if (this.LeftShape != null && this.LeftShape.Place == Place && !this.LeftShape.SearchOtherPlaces)
            {
                var nextX = this.X - this.LeftShape.Width - (this.Place != this.LeftShape.Place ? this.LeftWall : 0);
                var nextY = this.Y;
                this.LeftShape.LocateOtherPlaces(nextX, nextY, shapes, initialShape);
            }

            if (this.BottomShape != null && this.BottomShape.Place == Place && !this.BottomShape.SearchOtherPlaces)
            {
                var nextX = this.X;
                var nextY = this.Y - this.Height - (this.Place != this.BottomShape.Place ? this.BottomWall : 0);
                this.BottomShape.LocateOtherPlaces(nextX, nextY, shapes, initialShape);
            }

            if (this.TopShape != null && this.TopShape.Place == Place && !this.TopShape.SearchOtherPlaces)
            {
                var nextX = this.X;
                var nextY = this.Y + this.Height + (this.Place != this.TopShape.Place ? this.TopWall : 0);
                this.TopShape.LocateOtherPlaces(nextX, nextY, shapes, initialShape);
            }
        }