private int Prioritet(Shcaf.BaseShcaf _baseShcaf, Element el) { int elW = 0; int elH = 0; int bW = 1; bool up = false; _baseShcaf.listE = _baseShcaf.listE.OrderByDescending(x => x.level).ToList();//по убыванию bW = _baseShcaf.listE.First().level + 1; switch (el.Id) { case IdElement.Stena: { if (el.Rec.X < _x + w / 2) elW = el.FonRec.Right; else { elW = el.FonRec.Left; } foreach (var b in _baseShcaf.listE) { switch (b.Id) { case IdElement.Stena: { if (b.Rec.Left < elW && b.FonRec.Right > elW && b.Rec.Left < _x + w / 2) { bW = b.level; b.level = b.level + 1; up = true; continue; } if (b.Rec.Right > elW && b.FonRec.Left < elW && b.Rec.Right > _x + w / 2) { bW = b.level; b.level = b.level + 1; up = true; continue; } break; } } if (up && b.level != 0) { b.level = b.level + 1; } } break; } case IdElement.Polka: { if (el.Rec.Y < _y + h / 2) elH = el.FonRec.Bottom; else { elH = el.FonRec.Top; } foreach (var b in _baseShcaf.listE) { switch (b.Id) { case IdElement.Polka: { if (b.Rec.Top < elH && b.FonRec.Bottom > elH && b.Rec.Top < _y + h / 2) { bW = b.level; b.level = b.level + 1; up = true; continue; } if (b.Rec.Bottom > elH && b.FonRec.Top < elH && b.Rec.Top > _y + h / 2) { bW = b.level; b.level = b.level + 1; up = true; continue; } break; } } if (up && b.level != 0) { b.level = b.level + 1; } } break; } } return bW; }
private void Okontovka(Element el) { el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Left, el.Rec.Top), new Point(el.Rec.Right, el.Rec.Top))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Left, el.Rec.Top), new Point(el.Rec.Left, el.Rec.Bottom))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Left, el.Rec.Bottom), new Point(el.Rec.Right, el.Rec.Bottom))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Right, el.Rec.Bottom), new Point(el.Rec.Right, el.Rec.Top))); }
//нарисавать новый элемент шкафа public void DrawNewElement(BaseShcaf _baseShcaf) { switch (newElement.Id) { case Shcaf.IdElement.Polka: { Image topPol = Image.FromFile("Element/RNewPolka.bmp"); _element = new Shcaf.Element(topPol, GetXY(_baseShcaf)); _element.Id = IdElement.Polka; _element.FonRec = GetFonXY(_element); _element.FonImg = Image.FromFile("BaseShkaf/NewPolka.bmp"); Okontovka(_element); break; } case Shcaf.IdElement.Stena: { Image rightStena = Image.FromFile("Element/LNewStena.bmp"); _element = new Shcaf.Element(rightStena, GetXY(_baseShcaf)); _element.Id = IdElement.Stena; _element.FonRec = GetFonXY(_element); _element.FonImg = Image.FromFile("BaseShkaf/NewStena.bmp"); Okontovka(_element); break; } case Shcaf.IdElement.Yschik: { Image ysch = Image.FromFile("Element/Yschik.png"); _element = new Element(ysch, GetXY(_baseShcaf)); _element.Id = IdElement.Yschik; break; } case Shcaf.IdElement.Vesh: { Image ves = Image.FromFile("Element/Vesh1.png"); _element = new Element(ves, GetXY(_baseShcaf)); _element.Id = IdElement.Vesh; break; } case Shcaf.IdElement.Del: { Delete(_baseShcaf); _baseShcaf.listS.Clear(); _baseShcaf.ListText.Clear(); return; } } TryDraw = TryOnDraw(GetXY(_baseShcaf), _baseShcaf); if (TryDraw) { _element.level = Prioritet(_baseShcaf, _element); if ((_element.Rec.X > _x) && (_element.Rec.Y > _y) && (_element.Rec.X < _x + _baseShcaf.Width / 4) && (_element.Rec.Y < _y + _baseShcaf.Height / 4)) { _baseShcaf.listE.Add(_element); _baseShcaf.listS.Clear(); _baseShcaf.ListText.Clear(); } } }
//получить размер углубления private Rectangle GetFonXY(Element el) { Rectangle rec = new Rectangle(); int i = 0; switch (el.Id) { case IdElement.Stena: { if (el.Rec.Left < _x + w / 2) { i = Glybina(w / 2, (_x + w / 2) - el.Rec.Left, 17); rec = new Rectangle(el.Rec.Left, el.Rec.Top, 6 + i, el.Rec.Height); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(rec.Right, Gup), new Point(rec.Right, Gdown))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Right, el.Rec.Top), new Point(rec.Right, Gup))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Right, el.Rec.Bottom), new Point(rec.Right, Gdown))); } if (el.Rec.Left > _x + w / 2) { i = Glybina(w / 2, el.Rec.Left - (_x + w / 2), 17); rec = new Rectangle(el.Rec.Left - (i), el.Rec.Top, 6 + i, el.Rec.Height); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(rec.Left, Gup), new Point(rec.Left, Gdown))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Left, el.Rec.Top), new Point(rec.Left, Gup))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Left, el.Rec.Bottom), new Point(rec.Left, Gdown))); } break; } case IdElement.Polka: { if (el.Rec.Top < _y + h / 2) { i = Glybina(h / 2, (_y + h / 2) - el.Rec.Top, 13); rec = new Rectangle(el.Rec.Left + 1, el.Rec.Top, el.Rec.Width - 1, 7 + i); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(Gup, rec.Bottom), new Point(Gdown, rec.Bottom))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Left, el.Rec.Bottom), new Point(Gup, rec.Bottom))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Right, el.Rec.Bottom), new Point(Gdown, rec.Bottom))); } if (el.Rec.Top > _y + h / 2) { i = Glybina(h / 2, el.Rec.Top - (_y + h / 2), 13); rec = new Rectangle(el.Rec.Left + 1, el.Rec.Top - i, el.Rec.Width - 1, 7 + i); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(Gup, rec.Top), new Point(Gdown, rec.Top))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Left, el.Rec.Top), new Point(Gup, rec.Top))); el.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(el.Rec.Right, el.Rec.Top), new Point(Gdown, rec.Top))); } break; } } return rec; }
//создаем рисунок для шкафа public BaseShcaf DrawMainShcaf(BaseShcaf _baseShcaf) { SizeShcah(_baseShcaf); //рисуем заднию стенку _element = new Element(); _element.Img = Image.FromFile("BaseShkaf/NewZStena.bmp"); _element.Rec = new Rectangle(_x, _y, w, h); _element.Id = IdElement.Zadn; _element.level = 0; _baseShcaf.listE.Add(_element); //рисуем левую стенку _element = new Element(); _element.Img = Image.FromFile("BaseShkaf/LNewStena.bmp"); _element.Rec = new Rectangle(_x, _y, _element.Img.Width, h); _element.FonImg = Image.FromFile("BaseShkaf/NewStena.bmp"); _element.FonRec = new Rectangle(_x, _y, _element.FonImg.Width, h); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x, _y), new Point(_x, _y + h - 1))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + _element.Img.Width - 1, _y + _element.Img.Width), new Point(_x + _element.Img.Width - 1, _y + h - _element.Img.Width))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + _element.FonImg.Width - 1, _y + 20), new Point(_x + _element.FonImg.Width - 1, _y + h - 20))); _element.Id = IdElement.Stena; _element.level = 0; _baseShcaf.listE.Add(_element); //рисуем правую стенку _element = new Shcaf.Element(); _element.Img = Image.FromFile("BaseShkaf/LNewStena.bmp"); _element.Rec = new Rectangle(_x + w - _element.Img.Width, _y, _element.Img.Width, h); _element.FonImg = Image.FromFile("BaseShkaf/NewStena.bmp"); _element.FonRec = new Rectangle(_x + w - _element.FonImg.Width, _y, _element.FonImg.Width, h); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + w - _element.Img.Width, _y + _element.Img.Width), new Point(_x + w - _element.Img.Width, _y + h - _element.Img.Width))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + w - 1, _y + _element.Img.Width), new Point(_x + w - 1, _y + h - 1))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + w - _element.FonImg.Width - 1, _y + 20), new Point(_x + w - _element.FonImg.Width - 1, _y + h - 20)));//лини по краям _element.Id = IdElement.Stena; _element.level = 0; _baseShcaf.listE.Add(_element); //рисуем верхнию полку _element = new Shcaf.Element(); _element.Img = Image.FromFile("BaseShkaf/RNewPolka.bmp"); _element.Rec = new Rectangle(_x, _y, w, _element.Img.Height); _element.FonImg = Image.FromFile("BaseShkaf/NewPolka.bmp"); _element.FonRec = new Rectangle(_x + _element.Img.Height, _y, w - _element.Img.Height * 2, _element.FonImg.Height); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x, _y), new Point(_x + w - 1, _y))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + _element.Img.Height, _y + _element.Img.Height), new Point(_x + w - _element.Img.Height, _y + _element.Img.Height))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x, _y), new Point(_x, _y + _element.Img.Height))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + w - 1, _y), new Point(_x + w - 1, _y + _element.Img.Height))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + 24, _y + _element.FonImg.Height), new Point(_x + w - 24, _y + _element.FonImg.Height))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + 24, _y + _element.FonImg.Height), new Point(_x + _element.Img.Height, _y + _element.Img.Height))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + w - 24, _y + _element.FonImg.Height), new Point(_x + w - _element.Img.Height, _y + _element.Img.Height))); _element.Id = IdElement.Polka; _element.level = 0; _baseShcaf.listE.Add(_element); //рисуем нижнию полку _element = new Shcaf.Element(); _element.Img = Image.FromFile("BaseShkaf/RNewPolka.bmp"); _element.Rec = new Rectangle(_x, _y + h - _element.Img.Height, w, _element.Img.Height); _element.FonImg = Image.FromFile("BaseShkaf/NewPolka.bmp"); _element.FonRec = new Rectangle(_x + _element.Img.Height, _y + h - _element.FonImg.Height, w - _element.Img.Height * 2, _element.FonImg.Height); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + _element.Img.Height - 1, _y + h - _element.Img.Height), new Point(_x + w - _element.Img.Height, _y + h - _element.Img.Height))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x, _y + h), new Point(_x + w - 1, _y + h))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x, _y + h - _element.Img.Height), new Point(_x, _y + h))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + w - 1, _y + h - _element.Img.Height), new Point(_x + w - 1, _y + h))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + 24, _y + h - _element.FonImg.Height), new Point(_x + w - 24, _y + h - _element.FonImg.Height))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + 24, _y + h - _element.FonImg.Height), new Point(_x + _element.Img.Height, _y + h - _element.Img.Height))); _element.ListPen.Add(new Shcaf.MyPenn(myPen, new Point(_x + w - 24, _y + h - _element.FonImg.Height), new Point(_x + w - _element.Img.Height, _y + h - _element.Img.Height))); _element.Id = IdElement.Polka; _element.level = 0; _baseShcaf.listE.Add(_element); return _baseShcaf; }