Example #1
0
        /// <summary>
        /// Построение изображений отдельных домов
        /// </summary>
        private ImgHouse generateOneHouse(HouseInfo hi)
        {
            ImgHouse      imgHouse    = new ImgHouse();
            List <Bitmap> bmpSections = new List <Bitmap>();

            foreach (FlatInfo fi in hi.Sections)
            {
                ImgSection imgSection = GetImgSection(fi, imgHouse);

                imgHouse.ImgSections.Add(imgSection);
                SectionIndex++;
            }
            //   GC.Collect();

            return(imgHouse);
        }
Example #2
0
        private Bitmap generateOneSection(ImgSection section)
        {
            int width       = section.Lenght * ModuleWidth + ModuleWidth / 9;
            int height      = section.Height * ModuleWidth;
            int yCorrection = section.CoordYCorrection * ModuleWidth;
            var bitmap      = new Bitmap(width, height + 50);

            using (var canvas = Graphics.FromImage(bitmap))
            {
                //canvas.Clear(Color.White);
                canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;

                foreach (ImgFlat imgFlat in section.ImgFlats)
                {
                    imgFlat.Heigth *= ModuleWidth;
                    imgFlat.Width  *= ModuleWidth;

                    // Подгонка угловой секции по высоте
                    if (section.SectionInfo.IsCorner)
                    {
                        imgFlat.Heigth = imgFlat.Heigth - imgFlat.Heigth / 35;
                        yCorrection    = imgFlat.Heigth / 40;

                        if (imgFlat.ImgPath.Contains("3NL2"))
                        {
                            imgFlat.Width  = imgFlat.Width - ModuleWidth / 6;
                            yCorrection    = yCorrection - 12;
                            imgFlat.Heigth = imgFlat.Width + ModuleWidth / 3;
                        }
                    }

                    imgFlat.CoordX = --imgFlat.CoordX * ModuleWidth + ModuleWidth / 18;

                    Image frame;
                    try
                    {
                        frame = Image.FromFile(imgFlat.ImgPath);
                    }
                    catch (Exception ex)

                    {
                        //#if DEBUG
                        //                        //throw new Exception("Не найдено изображение: \n" + imgFlat.ImgPath);


                        //                      System.Windows.Forms.MessageBox.Show("Не найдено изображение: \n" + imgFlat.ImgPath);
                        //#endif

                        string emptyImage = System.IO.Path.GetDirectoryName(imgFlat.ImgPath) + "\\PIK1_empty.png";

                        if (System.IO.File.Exists(emptyImage))
                        {
                            frame = Image.FromFile(emptyImage);
                        }
                        else
                        {
                            frame = new Bitmap(width, height);
                        }
                    }
                    canvas.DrawImage(frame,
                                     new Rectangle(imgFlat.CoordX,
                                                   yCorrection,
                                                   //imgFlat.CoordY * ModuleWidth * 2,
                                                   //-ModuleWidth - ModuleWidth/4,
                                                   imgFlat.Width,
                                                   imgFlat.Heigth + 50),
                                     new Rectangle(0,
                                                   0,
                                                   //imgFlat.CoordY * ModuleWidth,
                                                   //-ModuleWidth,
                                                   frame.Width,
                                                   frame.Height),
                                     GraphicsUnit.Pixel);
                    //canvas.Save();
                }
                // canvas.RotateTransform(7);
                canvas.Save();
            }
            try
            {
                switch (section.Angle)
                {
                case 90:
                    bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;

                case 180:
                    bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    break;

                case 270:
                    bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(bitmap);
        }
Example #3
0
        private ImgSection GetImgSection(FlatInfo fi, ImgHouse imgHouse = null)
        {
            ImgSection imgSection = new ImgSection();

            //if (hi.SectionsBySize[0].)
            //{
            //    imgSection.Angle += 90;
            //}

            //if (fi.IsInvert)
            //{
            //    imgSection.Angle += 180;
            //}

            imgSection.Angle = fi.ImageAngle;

            // Корректировка точки вставки секций
            if (fi.IsCorner)
            {
                imgSection.CoordYCorrection = 0;
                if (imgHouse != null)
                {
                    imgHouse.IsCorner = true;
                }
            }

            // Определение положения дома - вертикальный/горизонтальный
            if (!fi.IsVertical)
            {
                if (imgHouse != null)
                {
                    imgHouse.IsVertical = false;
                }
            }

            int SelectedDownPrev = 0;
            int offset           = 0;
            int minX             = 0;

            int X = 0;

            bool prev3NL2  = false;
            int  FlatIndex = 0;

            foreach (RoomInfo ri in fi.Flats)
            {
                // Корректировка неверно выданных данных
                if (ri.Type.Contains("3NL2"))
                {
                    ri.SelectedIndexTop    = 4;
                    ri.SelectedIndexBottom = 0;
                    imgSection.Height      = 5;
                }

                // Корректировка неверно выданных данных
                if (ri.Type == "PIK1U_BS_A_10-17_A_2")
                {
                    ri.SelectedIndexTop = 3;
                }

                // Корректировка положения квартиры 2KL2 и 2NM1

                if (ri.Type.Contains("2KL2") || ri.Type.Contains("2NM1"))
                {
                    if (prev3NL2 || (fi.Flats.Any(x => x.Type.Contains("3NL2")) && (fi.Flats.Count == FlatIndex + 2)))
                    {
                        ri.ImageNameSuffix = "_U";

                        if (ri.Type.Contains("2NM1"))
                        {
                            ri.SelectedIndexBottom = 1;
                        }
                        if (ri.Type.Contains("2KL2"))
                        {
                            ri.SelectedIndexBottom = 2;
                        }
                        ri.HorisontalModules = 2;
                        prev3NL2             = false;
                    }
                    else
                    {
                        ri.ImageNameSuffix     = "";
                        ri.SelectedIndexBottom = 3;
                        ri.HorisontalModules   = 3;
                    }

                    if (fi.Flats.Any(x => x.Type.Contains("3NL2")) && (fi.Flats.Count == FlatIndex + 2))
                    {
                        ri.NextOffsetX = 1;
                    }
                }

                if (ri.Type.Contains("3NL2"))
                {
                    // Флаг предыдущей секции 3NL2
                    prev3NL2 = true;

                    // Если после ЛЛУ идёт квартира типа 3NL2, то дом L-ориентирован
                    if (FlatIndex == 1)
                    {
                        if (imgHouse != null)
                        {
                            imgHouse.LOrientation = true;
                        }
                    }

                    // Если встретилась повёрнутая секция, то дом не является горизонтально ориентированным
                    // TODO: неясно, для чего было условие, разобраться

                    //if (fi.IsVertical)
                    //{

                    //}
                }
                else
                {
                    prev3NL2 = false;
                }
                FlatIndex++;

                ImgFlat imgFlat = new ImgFlat(ImagePath, ri.Type + ri.ImageNameSuffix, 0);
                imgFlat.Width  = ri.HorisontalModules + 2;
                imgFlat.Heigth = 6;

                // Определение точки вставки квартиры
                if (ri.SelectedIndexTop > 0 && ri.SelectedIndexBottom > 0 && SelectedDownPrev > 0)
                {
                    offset           = SelectedDownPrev;
                    SelectedDownPrev = 0;
                }
                else
                {
                    offset = SelectedDownPrev - ri.SelectedIndexTop;
                    if (ri.SelectedIndexBottom > 0)
                    {
                        SelectedDownPrev = ri.HorisontalModules + ri.NextOffsetX;
                    }
                    else
                    {
                        SelectedDownPrev = ri.SelectedIndexBottom;
                    }
                }

                X = X + offset + ri.CurrentOffsetX;

                if (X < minX)
                {
                    minX = X;
                }

                imgFlat.CoordX = X;

                imgSection.Lenght += ri.SelectedIndexBottom;

                imgSection.ImgFlats.Add(imgFlat);
            }

            foreach (ImgFlat imgFlat in imgSection.ImgFlats)
            {
                imgFlat.CoordX -= minX;
            }

            imgSection.SectionInfo = fi;

            //imgSection.BmpSectionPath = imgDir + imgName;

            imgSection.BmpSection = generateOneSection(imgSection);

            // Сохранение отдельных секций для отладки
#if DEBUG
            string imgName = @"Секция" + SectionIndex + ".png";
            string imgDir  = @"Section\";// @"C:\Users\fazleevaa\Links\Desktop\RRR" + "\\";
            SaveImage(imgSection.BmpSection, imgDir, imgName);
#endif
            return(imgSection);
        }