static PointCollection GetPointCollection(surfacesSurfaceLayerElementsElement innerElementLayer)
        {
            var pointCollection = new PointCollection();
            foreach (var innerPoint in innerElementLayer.points)
            {
                var point = new System.Windows.Point()
                {
                    X = Parse(innerPoint.x),
                    Y = Parse(innerPoint.y)
                };

                pointCollection.Add(point);
            }
            return pointCollection;
        }
        void AddDevice(Plan plan, surfacesSurfaceLayerElementsElement innerElement)
        {
            if (innerElement.rect != null)
            {
                var innerRect = innerElement.rect[0];

                long longId = long.Parse(innerElement.id);
                int intId = (int)longId;

                var height = Parse(innerRect.bottom) - Parse(innerRect.top);
                var width = Parse(innerRect.right) - Parse(innerRect.left);
                var elementDevice = new ElementDevice()
                {
                    Left = Parse(innerRect.left) + height / 2,
                    Top = Parse(innerRect.top) + width / 2
                };
                plan.ElementDevices.Add(elementDevice);

                foreach (var device in DeviceConfiguration.Devices)
                {
                    foreach (var deviceShapeId in device.ShapeIds)
                    {
                        if ((deviceShapeId == longId.ToString()) || (deviceShapeId == intId.ToString()))
                        {
                            elementDevice.DeviceUID = device.UID;
                            device.PlanElementUIDs.Add(elementDevice.UID);
                        }
                    }
                }
            }
        }
 void AddRectangle(Plan plan, surfacesSurfaceLayerElementsElement innerElement)
 {
     var elementRectangle = new ElementRectangle()
     {
         Left = Parse(innerElement.rect[0].left),
         Top = Parse(innerElement.rect[0].top),
         Height = Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top),
         Width = Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left)
     };
     plan.ElementRectangles.Add(elementRectangle);
 }
        void AddRectangleZone(Plan plan, surfacesSurfaceLayerElementsElement innerElement, int? zoneNo)
        {
            var elementRectangleZone = new ElementRectangleZone()
            {
                ZoneNo = zoneNo,
                Left = Math.Min(Parse(innerElement.rect[0].left), Parse(innerElement.rect[0].right)),
                Top = Math.Min(Parse(innerElement.rect[0].top), Parse(innerElement.rect[0].bottom)),
                Width = Math.Abs(Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left)),
                Height = Math.Abs(Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top))
            };

            plan.ElementRectangleZones.Add(elementRectangleZone);
        }
 void AddPolyLine(Plan plan, surfacesSurfaceLayerElementsElement innerElement)
 {
     var elementPolyline = new ElementPolyline();
     elementPolyline.Points = GetPointCollection(innerElement);
     //elementPolyline.Normalize();
     plan.ElementPolylines.Add(elementPolyline);
 }
 void AddPolygonZone(Plan plan, surfacesSurfaceLayerElementsElement innerElement, int? zoneNo)
 {
     if (innerElement.points != null)
     {
         var elementPolygonZone = new ElementPolygonZone()
         {
             ZoneNo = zoneNo
         };
         elementPolygonZone.Points = GetPointCollection(innerElement);
         //elementPolygonZone.Normalize();
         plan.ElementPolygonZones.Add(elementPolygonZone);
     };
 }
 void AddPolygon(Plan plan, surfacesSurfaceLayerElementsElement innerElement)
 {
     var elementPolygon = new ElementPolygon();
     elementPolygon.Points = GetPointCollection(innerElement);
     //elementPolygon.Normalize();
     plan.ElementPolygons.Add(elementPolygon);
 }
        void AddPictire(Plan plan, surfacesSurfaceLayerElementsElement innerElement, ref int pictureIndex)
        {
            foreach (var innerPicture in innerElement.picture)
            {
                if (string.IsNullOrEmpty(innerPicture.idx))
                    innerPicture.idx = pictureIndex++.ToString();

                var directoryInfo = new DirectoryInfo(Environment.CurrentDirectory + "\\Pictures\\Sample" + innerPicture.idx + "." + innerPicture.ext);
                if (File.Exists(directoryInfo.FullName) == false)
                    continue;

                if (innerPicture.ext == "emf")
                {
                    var metafile = new Metafile(directoryInfo.FullName);
                    innerPicture.ext = "bmp";
                    directoryInfo = new DirectoryInfo(Environment.CurrentDirectory + "\\Pictures\\Sample" + innerPicture.idx + "." + innerPicture.ext);
                    metafile.Save(directoryInfo.FullName, ImageFormat.Bmp);
                    metafile.Dispose();
                }

                byte[] backgroundPixels = File.ReadAllBytes(directoryInfo.FullName);

                var elementRectanglePicture = new ElementRectangle()
                {
                    Left = Parse(innerElement.rect[0].left),
                    Top = Parse(innerElement.rect[0].top),
                    Height = Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top),
                    Width = Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left),
                    BackgroundPixels = backgroundPixels
                };

                if ((elementRectanglePicture.Left == 0) && (elementRectanglePicture.Top == 0) && (elementRectanglePicture.Width == plan.Width) && (elementRectanglePicture.Height == plan.Height))
                {
                    plan.BackgroundPixels = elementRectanglePicture.BackgroundPixels;
                }
                else
                {
                    plan.ElementRectangles.Add(elementRectanglePicture);
                }
            }
        }
        void AddLabel(Plan plan, surfacesSurfaceLayerElementsElement innerElement, bool stretch = false)
        {
            var elementTextBlock = new ElementTextBlock()
            {
                Text = innerElement.caption,
                Left = Parse(innerElement.rect[0].left),
                Top = Parse(innerElement.rect[0].top),
                Height = Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top),
                Width = Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left),
                Stretch = true
            };

            FontFamily fontFamily = new FontFamily("Arial");
            double fontDpiSize = elementTextBlock.Height / 2;
            double fontHeight = Math.Ceiling(fontDpiSize * fontFamily.LineSpacing);
            elementTextBlock.FontSize = fontHeight;

            if (innerElement.brush != null)
                try
                {
                    elementTextBlock.BackgroundColor = ConvertColor(innerElement.brush[0].color);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Исключение при вызове ConfigurationConverter.ConvertPlans");
                }

            if (innerElement.pen != null)
                try
                {
                    elementTextBlock.ForegroundColor = ConvertColor(innerElement.pen[0].color);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Исключение при вызове ConfigurationConverter.ConvertPlans innerElementLayer.pen");
                }

            plan.ElementTextBlocks.Add(elementTextBlock);
        }