public SubstationBlock(MainBlockViewModel vm, SubstationData subBlock)
        {
            InitializeComponent();
            DataContext = this;

            _mainBlockViewModel = vm;
            _substationData     = subBlock;

            DrawSubstation(subBlock, true, true, true);
        }
        public void CreateSubstation(SubstationData subBlock)
        {
            if (subBlock == null)
            {
                return;
            }

            while (ControlsCollection.Any(x => x.GetType() == typeof(SubstationBlock)))
            {
                ControlsCollection.Remove(ControlsCollection.First(x => x.GetType() == typeof(SubstationBlock)));
            }

            ControlsCollection.Add(new SubstationBlock(this, subBlock));

            ReDrawSubstation();
        }
        private void DrawSubstation(SubstationData subBlock, bool transPlaceholder, bool ruvnPlaceholder, bool runnPlaceholder)
        {
            ControlWidth  = subBlock.Width / Constants.MainScale;
            ControlHeight = subBlock.Height / Constants.MainScale;

            foreach (var sandData in subBlock.SandwichDataList)
            {
                foreach (var subRoom in sandData.SubstationRoomDataList ?? new List <SubstationRoomData>())
                {
                    var grid = new Grid();
                    grid.Children.Add(new Line()
                    {
                        X1     = 16,
                        X2     = 0,
                        Y1     = 0,
                        Y2     = 16,
                        Stroke = new SolidColorBrush(Colors.Gray)
                    });
                    grid.Children.Add(new Line()
                    {
                        X1     = 16,
                        X2     = 0,
                        Y1     = 0,
                        Y2     = 16,
                        Stroke = new SolidColorBrush(Colors.Gray),
                        Margin = new Thickness(-8, -8, 0, 0)
                    });
                    grid.Children.Add(new Line()
                    {
                        X1     = 16,
                        X2     = 0,
                        Y1     = 0,
                        Y2     = 16,
                        Stroke = new SolidColorBrush(Colors.Gray),
                        Margin = new Thickness(8, 8, 0, 0)
                    });

                    if (transPlaceholder && subRoom.RoomType == RoomType.Transformer)
                    {
                        BlockItems.Items.Add(new Ellipse()
                        {
                            Tag             = "TRANSFORMER_PLACEHOLDER",
                            Stroke          = new SolidColorBrush(Colors.Blue),
                            StrokeThickness = 2,
                            Width           = 1000 / Constants.MainScale,
                            Height          = 1000 / Constants.MainScale,
                            Margin          = new Thickness(
                                (subRoom.X / Constants.MainScale),
                                (subRoom.Y / Constants.MainScale), 0, 0),
                        });

                        BlockItems.Items.Add(new Ellipse()
                        {
                            Tag             = "TRANSFORMER_PLACEHOLDER",
                            Stroke          = new SolidColorBrush(Colors.Blue),
                            StrokeThickness = 2,
                            Width           = 1000 / Constants.MainScale,
                            Height          = 1000 / Constants.MainScale,
                            Margin          = new Thickness(
                                (subRoom.X / Constants.MainScale),
                                (subRoom.Y / Constants.MainScale) + 150, 0, 0),
                        });
                    }

                    if (ruvnPlaceholder && subRoom.RoomType == RoomType.HighVoltage)
                    {
                        foreach (var cellRow in subRoom.CellPlaceDataList)
                        {
                            BlockItems.Items.Add(new Rectangle()
                            {
                                Tag  = "RUVN_PLACEHOLDER",
                                Fill = new VisualBrush()
                                {
                                    TileMode      = TileMode.Tile,
                                    Viewport      = new Rect(0, 0, 16, 16),
                                    ViewportUnits = BrushMappingMode.Absolute,
                                    Viewbox       = new Rect(0, 0, 16, 16),
                                    ViewboxUnits  = BrushMappingMode.Absolute,
                                    Visual        = grid,
                                },
                                Width  = cellRow.Width / Constants.MainScale,
                                Height = cellRow.Height / Constants.MainScale,
                                Margin = new Thickness(
                                    (subRoom.X / Constants.MainScale) + (cellRow.X / Constants.MainScale),
                                    (subRoom.Y / Constants.MainScale) + (cellRow.Y / Constants.MainScale), 0, 0),
                            });

                            BlockItems.Items.Add(new Border()
                            {
                                Tag             = "RUVN_PLACEHOLDER",
                                BorderBrush     = new SolidColorBrush(Colors.Gray),
                                BorderThickness = new Thickness(1),
                                Width           = cellRow.Width / Constants.MainScale,
                                Height          = cellRow.Height / Constants.MainScale,
                                Margin          = new Thickness(
                                    (subRoom.X / Constants.MainScale) + (cellRow.X / Constants.MainScale),
                                    (subRoom.Y / Constants.MainScale) + (cellRow.Y / Constants.MainScale), 0, 0),
                            });

                            BlockItems.Items.Add(new Label()
                            {
                                Tag      = "RUVN_PLACEHOLDER",
                                Content  = "РУ 6-10 кВ (РУВН)",
                                FontSize = 16,
                                Padding  = new Thickness(0, 0, 0, 15),
                                HorizontalContentAlignment = HorizontalAlignment.Center,
                                VerticalContentAlignment   = VerticalAlignment.Center,
                                Foreground = new SolidColorBrush(Colors.Black),
                                Width      = cellRow.Width / Constants.MainScale,
                                Height     = cellRow.Height / Constants.MainScale,
                                Margin     = new Thickness(
                                    (subRoom.X / Constants.MainScale) + (cellRow.X / Constants.MainScale),
                                    (subRoom.Y / Constants.MainScale) + (cellRow.Y / Constants.MainScale), 0, 0),
                            });
                        }
                    }

                    if (runnPlaceholder && subRoom.RoomType == RoomType.LowVoltage)
                    {
                        foreach (var cellRow in subRoom.CellPlaceDataList)
                        {
                            BlockItems.Items.Add(new Rectangle()
                            {
                                Tag  = "RUNN_PLACEHOLDER",
                                Fill = new VisualBrush()
                                {
                                    TileMode      = TileMode.Tile,
                                    Viewport      = new Rect(0, 0, 16, 16),
                                    ViewportUnits = BrushMappingMode.Absolute,
                                    Viewbox       = new Rect(0, 0, 16, 16),
                                    ViewboxUnits  = BrushMappingMode.Absolute,
                                    Visual        = grid,
                                },
                                Width  = cellRow.Width / Constants.MainScale,
                                Height = cellRow.Height / Constants.MainScale,
                                Margin = new Thickness(
                                    (subRoom.X / Constants.MainScale) + (cellRow.X / Constants.MainScale),
                                    (subRoom.Y / Constants.MainScale) + (cellRow.Y / Constants.MainScale), 0, 0),
                            });

                            BlockItems.Items.Add(new Border()
                            {
                                Tag             = "RUNN_PLACEHOLDER",
                                BorderBrush     = new SolidColorBrush(Colors.Gray),
                                BorderThickness = new Thickness(1),
                                Width           = cellRow.Width / Constants.MainScale,
                                Height          = cellRow.Height / Constants.MainScale,
                                Margin          = new Thickness(
                                    (subRoom.X / Constants.MainScale) + (cellRow.X / Constants.MainScale),
                                    (subRoom.Y / Constants.MainScale) + (cellRow.Y / Constants.MainScale), 0, 0),
                            });

                            BlockItems.Items.Add(new Label()
                            {
                                Tag      = "RUNN_PLACEHOLDER",
                                Content  = "РУ 0,4 кВ (РУНН)",
                                FontSize = 16,
                                Padding  = new Thickness(0, 0, 0, 15),
                                HorizontalContentAlignment = HorizontalAlignment.Center,
                                VerticalContentAlignment   = VerticalAlignment.Center,
                                Foreground = new SolidColorBrush(Colors.Black),
                                Width      = cellRow.Width / Constants.MainScale,
                                Height     = cellRow.Height / Constants.MainScale,
                                Margin     = new Thickness(
                                    (subRoom.X / Constants.MainScale) + (cellRow.X / Constants.MainScale),
                                    (subRoom.Y / Constants.MainScale) + (cellRow.Y / Constants.MainScale), 0, 0),
                            });
                        }
                    }
                }
            }
        }