using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ImageBlockz.Operations;
using ImageBlockz.Operations.Edit;
using ImageBlockz.Api;
using ImageBlockz.Core;

namespace ImageBlockz.Operations.Controls
{
    public partial class CircularProjectionsControl : OperationControl
    {
        private ImageBlockz.Operations.Transformations.CircularProjections circularProjections;

        public CircularProjectionsControl()
            : base(typeof(ImageBlockz.Operations.Transformations.CircularProjections).FullName)
        {
            IsPreview = false;

            InitializeComponent();
        }

        public override IOperation GetOperation()
        {
            circularProjections.AngleSamples = (int) dbAngleSamples.GetValue();
            circularProjections.RadiusSamples = (int) dbRadiusSamples.GetValue();
            circularProjections.Minimum = dbMinimum.GetValue();
            circularProjections.Maximum = dbMaximum.GetValue();

            return circularProjections;
        }

        public override void SetOperation(IOperation operation)
        {
            base.SetOperation(operation);

            if (operation is ImageBlockz.Operations.Transformations.CircularProjections == false)
            {
                throw new ArgumentException("operation", "Argument operation is not instance of "
                    + typeof(ImageBlockz.Operations.Transformations.CircularProjections).FullName);
            }

            circularProjections = (ImageBlockz.Operations.Transformations.CircularProjections)operation;
        }

        public override bool OnOK()
        {
            if (dbAngleSamples.IsOK() == false || dbMinimum.IsOK() == false || dbMaximum.IsOK() == false)
            {
                return false;
            }

            circularProjections.AngleSamples = (int)dbAngleSamples.GetValue();
            circularProjections.RadiusSamples = (int)dbRadiusSamples.GetValue();
            circularProjections.Minimum = dbMinimum.GetValue();
            circularProjections.Maximum = dbMaximum.GetValue();

            return true;
        }

        public override void ShowData()
        {
            dbAngleSamples.SetDigitBox(DigitBox.ValueType.Int, 0, 3000, 360);
            dbAngleSamples.SetDigitBox(DigitBox.ValueType.Int, 0, 3000, 500);
            dbMinimum.SetDigitBox(DigitBox.ValueType.Dec, 0, 1, 0);
            dbMaximum.SetDigitBox(DigitBox.ValueType.Dec, 0, 1, 1);        

            if (IsNew)
            {
                dbAngleSamples.Value   = 360;
                dbRadiusSamples.Value = 500;
                dbMinimum.Value = 0;
                dbMaximum.Value = 1;
            }
            else
            {
                dbAngleSamples.Value = circularProjections.AngleSamples;
                dbRadiusSamples.Value = circularProjections.RadiusSamples;
                dbMinimum.Value = (float) circularProjections.Minimum;
                dbMaximum.Value = (float) circularProjections.Maximum;
            }

        }

    }
}
