public LayerTemplate SaveTemplate()
 {
     return(new LayerTemplate(Width, Height,
                              Pins.Select(x => new Pin(x.Width, x.Height, x.Y, x.X, x.Name, x.ValuesFunction.Build(), x.IsOutputPin, x.IsSignificant)).ToArray(),
                              DeadZones.Select(x => new Zone(new Position(x.X, x.Y), x.Width, x.Height)).ToArray(),
                              Functions.ToDictionary(x => x.Name, x => x.Function.Build())));
 }
        public void RemoveSelectedObject()
        {
            switch (SelectedObject)
            {
            case PinTemplate pt:
                Pins.Remove(pt);
                break;

            case DeadZoneTemplate dzt:
                DeadZones.Remove(dzt);
                break;

            case NamedFunctionTemplate nft:
                Functions.Remove(nft);
                break;
            }
        }
        public void OpenTemplate(LayerTemplate template)
        {
            Width  = template.Width;
            Height = template.Height;

            Pins.Clear();
            DeadZones.Clear();

            foreach (var pin in template.Pins)
            {
                Pins.Add(new PinTemplate
                {
                    X              = pin.Col,
                    Y              = pin.Row,
                    Width          = pin.Width,
                    Height         = pin.Height,
                    Name           = pin.Name,
                    IsSignificant  = pin.IsSignificant,
                    IsOutputPin    = pin.IsOutputPin,
                    ValuesFunction = new ValuesFunctionTemplate(pin.ValuesFunction)
                });
            }

            foreach (var zone in template.DeadZones)
            {
                DeadZones.Add(new DeadZoneTemplate
                {
                    X      = zone.Origin.X,
                    Y      = zone.Origin.Y,
                    Width  = zone.Width,
                    Height = zone.Height
                });
            }

            foreach (var fun in template.Functions)
            {
                Functions.Add(new NamedFunctionTemplate {
                    Name = fun.Key, Function = new ValuesFunctionTemplate(fun.Value)
                });
            }
        }
 public void AddDeadZone()
 {
     DeadZones.Add(new DeadZoneTemplate {
         Width = 3, Height = 3
     });
 }