surfaces ConvertPlansBack(PlansConfiguration plansConfiguration, DeviceConfiguration deviceConfiguration) { surfaces result = new surfaces(); var innerPlans = new List<surfacesSurface>(); foreach (var plan in plansConfiguration.AllPlans) { var innerPlan = new surfacesSurface(); innerPlans.Add(innerPlan); innerPlan.caption = plan.Caption; innerPlan.height = (plan.Height / 10).ToString(); innerPlan.width = (plan.Width / 10).ToString(); var layers = new List<surfacesSurfaceLayer>(); var layer = new surfacesSurfaceLayer(); layer.name = "Зоны"; layers.Add(layer); innerPlan.layer = layers.ToArray(); var elements = new List<surfacesSurfaceLayerElementsElement>(); foreach (var elementRectangle in plan.ElementRectangles) { var element = new surfacesSurfaceLayerElementsElement(); elements.Add(element); element.@class = "TSCDeRectangle"; element.rect = new surfacesSurfaceLayerElementsElementRect[1]{new surfacesSurfaceLayerElementsElementRect()}; element.rect[0].left = elementRectangle.Left.ToString(); element.rect[0].top = elementRectangle.Top.ToString(); element.rect[0].bottom = (elementRectangle.Top + elementRectangle.Height).ToString(); element.rect[0].right = (elementRectangle.Left + elementRectangle.Width).ToString(); element.rect[0].left = elementRectangle.Top.ToString(); } layer.elements = elements.ToArray(); } result.surface = innerPlans.ToArray(); return result; }
surfaces ConvertPlansBack(PlansConfiguration plansConfiguration, DeviceConfiguration deviceConfiguration) { var innerPlansConfiguration = new surfaces(); var innerPlans = new List<surfacesSurface>(); foreach (var plan in plansConfiguration.Plans.OfType<Plan>()) { surfacesSurface innerPlan = new surfacesSurface() { caption = plan.Caption, height = (plan.Height / 10).ToString(), width = (plan.Width / 10).ToString() }; innerPlans.Add(innerPlan); var mainLayer = new surfacesSurfaceLayer() { name = "План" }; var mainLayerElements = new List<surfacesSurfaceLayerElementsElement>(); foreach (var elementRectangle in plan.ElementRectangles) { var innerRectangle = new surfacesSurfaceLayerElementsElement() { @class = "TSCDeRectangle", rect = new surfacesSurfaceLayerElementsElementRect[] { GetRect(elementRectangle) } }; mainLayerElements.Add(innerRectangle); } foreach (var elementEllipse in plan.ElementEllipses) { var innerEllipse = new surfacesSurfaceLayerElementsElement() { @class = "TSCDeEllipse", rect = new surfacesSurfaceLayerElementsElementRect[] { GetRect(elementEllipse) } }; mainLayerElements.Add(innerEllipse); } foreach (var elementTextBlock in plan.ElementTextBlocks) { var innerLable = new surfacesSurfaceLayerElementsElement() { @class = "TSCDeLabel", rect = new surfacesSurfaceLayerElementsElementRect[] { GetRect(elementTextBlock) }, caption = elementTextBlock.Text }; innerLable.pen = new surfacesSurfaceLayerElementsElementPen[1]; innerLable.pen[0] = new surfacesSurfaceLayerElementsElementPen() { color = "cl" + elementTextBlock.ForegroundColor.ToString() }; innerLable.brush = new surfacesSurfaceLayerElementsElementBrush[1]; innerLable.brush[0] = new surfacesSurfaceLayerElementsElementBrush() { color = "cl" + elementTextBlock.BackgroundColor.ToString() }; mainLayerElements.Add(innerLable); } foreach (var elementPolyline in plan.ElementPolylines) { var innerPolyline = new surfacesSurfaceLayerElementsElement() { @class = "TSCDePolyLine", }; var innerPointsCollection = new List<surfacesSurfaceLayerElementsElementPointsPoint>(); foreach (var point in elementPolyline.Points) { innerPointsCollection.Add(new surfacesSurfaceLayerElementsElementPointsPoint() { x = point.X.ToString(), y = point.Y.ToString() }); } innerPolyline.points = innerPointsCollection.ToArray(); mainLayerElements.Add(innerPolyline); } foreach (var elementPolygon in plan.ElementPolygons) { var innerPolyline = new surfacesSurfaceLayerElementsElement() { @class = "TSCDePolygon", }; var innerPointsCollection = new List<surfacesSurfaceLayerElementsElementPointsPoint>(); foreach (var point in elementPolygon.Points) { innerPointsCollection.Add(new surfacesSurfaceLayerElementsElementPointsPoint() { x = point.X.ToString(), y = point.Y.ToString() }); } innerPolyline.points = innerPointsCollection.ToArray(); mainLayerElements.Add(innerPolyline); } mainLayer.elements = mainLayerElements.ToArray(); var devicesLayer = new surfacesSurfaceLayer() { name = "Устройства" }; var innerDeviceElements = new List<surfacesSurfaceLayerElementsElement>(); foreach (var elementDevice in plan.ElementDevices) { var innerDeviceElement = new surfacesSurfaceLayerElementsElement(); var innerRect = new surfacesSurfaceLayerElementsElementRect() { left = elementDevice.Left.ToString(), top = elementDevice.Top.ToString(), bottom = (elementDevice.Top + 10).ToString(), right = (elementDevice.Left + 10).ToString() }; innerDeviceElement.rect = new surfacesSurfaceLayerElementsElementRect[] { innerRect }; var device = deviceConfiguration.Devices.FirstOrDefault(x => x.UID == elementDevice.UID); if (device != null) { innerDeviceElement.id = device.ShapeIds.FirstOrDefault(); } innerDeviceElements.Add(innerDeviceElement); } devicesLayer.elements = innerDeviceElements.ToArray(); var zonesLayer = new surfacesSurfaceLayer() { name = "Зоны" }; var zoneLayerElements = new List<surfacesSurfaceLayerElementsElement>(); foreach (var elementRectangleZone in plan.ElementRectangleZones) { var innerRectangleZone = new surfacesSurfaceLayerElementsElement() { @class = "TFS_ZoneShape", rect = new surfacesSurfaceLayerElementsElementRect[] { GetRect(elementRectangleZone) } }; var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.UID == elementRectangleZone.UID); if (zone != null) { innerRectangleZone.id = zone.ShapeIds.FirstOrDefault(); } zoneLayerElements.Add(innerRectangleZone); } foreach (var elementPolygonZone in plan.ElementPolygonZones) { var innerPolygonZone = new surfacesSurfaceLayerElementsElement() { @class = "TFS_PolyZoneShape", }; var innerPointsCollection = new List<surfacesSurfaceLayerElementsElementPointsPoint>(); foreach (var point in elementPolygonZone.Points) { innerPointsCollection.Add(new surfacesSurfaceLayerElementsElementPointsPoint() { x = point.X.ToString(), y = point.Y.ToString() }); } innerPolygonZone.points = innerPointsCollection.ToArray(); var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.UID == elementPolygonZone.UID); if (zone != null) { innerPolygonZone.id = zone.ShapeIds.FirstOrDefault(); } zoneLayerElements.Add(innerPolygonZone); } zonesLayer.elements = innerDeviceElements.ToArray(); var innerLayers = new List<surfacesSurfaceLayer>(); innerLayers.Add(mainLayer); innerLayers.Add(devicesLayer); innerLayers.Add(zonesLayer); innerPlan.layer = innerLayers.ToArray(); } innerPlansConfiguration.surface = innerPlans.ToArray(); return innerPlansConfiguration; }
PlansConfiguration ConvertPlans(surfaces innerPlans, DeviceConfiguration deviceConfiguration) { var plansConfiguration = new PlansConfiguration(); if ((innerPlans != null) && (innerPlans.surface != null)) { foreach (var innerPlan in innerPlans.surface) { var plan = new Plan() { Caption = innerPlan.caption, Height = Double.Parse(innerPlan.height) * 10, Width = Double.Parse(innerPlan.width) * 10 }; foreach (var innerLayer in innerPlan.layer) { if (innerLayer.elements == null) continue; switch (innerLayer.name) { case "План": foreach (var innerElement in innerLayer.elements) { switch (innerElement.@class) { case "TSCDePicture": int pictureIndex = 0; AddPictire(plan, innerElement, ref pictureIndex); break; case "TSCDeRectangle": AddRectangle(plan, innerElement); break; case "TSCDeEllipse": AddEllipse(plan, innerElement); break; case "TSCDeLabel": AddLabel(plan, innerElement); break; case "TSCDeText": AddLabel(plan, innerElement, true); break; case "TSCDePolyLine": AddPolyLine(plan, innerElement); break; case "TSCDePolygon": AddPolygon(plan, innerElement); break; default: Logger.Error("ConfigurationConverter.ConvertPlans: Неизвестный элемент " + innerElement.@class); break; } } break; case "Несвязанные зоны": case "Пожарные зоны": case "Охранные зоны": case "Зоны": foreach (var innerElement in innerLayer.elements) { Zone activeZone = null; long longId = long.Parse(innerElement.id); int intId = (int)longId; foreach (var zone in deviceConfiguration.Zones) foreach (var zoneShapeId in zone.ShapeIds) if ((zoneShapeId == longId.ToString()) || (zoneShapeId == intId.ToString())) activeZone = zone; switch (innerElement.@class) { case "TFS_PolyZoneShape": AddPolygonZone(plan, innerElement, activeZone); break; case "TFS_ZoneShape": AddRectangleZone(plan, innerElement, activeZone); break; case "TSCDeRectangle": AddRectangle(plan, innerElement); break; case "TSCDeEllipse": AddEllipse(plan, innerElement); break; case "TSCDeLabel": AddLabel(plan, innerElement); break; case "TSCDeText": AddLabel(plan, innerElement, true); break; case "TSCDePolyLine": AddPolyLine(plan, innerElement); break; case "TSCDePolygon": AddPolygon(plan, innerElement); break; default: Logger.Error("ConfigurationConverter.ConvertPlans: Неизвестный элемент " + innerElement.@class); break; } } break; case "Устройства": foreach (var innerElement in innerLayer.elements) { AddDevice(plan, innerElement, deviceConfiguration); } break; } } plansConfiguration.Plans.Add(plan); } } var picturesDirectory = GetPicturesDirectory(); if (picturesDirectory != null) { DeleteDirectory(Environment.CurrentDirectory + "\\Pictures"); } return plansConfiguration; }