using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DataProcessing
{
    public partial class FormSurface : Form
    {
        public FormMain mainForm = null;

        public FormSurface()
        {
            InitializeComponent();
        }

        public void Enable()
        {
            groupBoxSurface.Enabled = true;
        }

        public void Disable()
        {
            groupBoxSurface.Enabled = false;
        }

        private void FormSurface_FormClosed(object sender, FormClosedEventArgs e)
        {
            mainForm.SurfaceForm = null;
        }

        private void btnSurface_Click(object sender, EventArgs e)
        {
            mainForm.SaveState();
            
            if (mainForm.SelectedMesh != null)
            {
                mainForm.StartAction();
                mainForm.SelectedMesh.SurfacesFromRawData((int)numBoxTolerance.Value);
                mainForm.StopAction();
            }
            mainForm.UpdateValues();
            mainForm.ReDraw();
        }

        private void btnDeleteSurface_Click(object sender, EventArgs e)
        {  
            mainForm.SaveState();

            if (mainForm.SelectedMesh != null)
            {
                mainForm.SelectedMesh.DeleteSurfaces();
                mainForm.UpdateValues();
                mainForm.ReDraw();
            }    
        }

        ToolTip toolTipSurface = new ToolTip();

        private void FormSurface_Load(object sender, EventArgs e)
        {
            toolTipSurface.SetToolTip(this.labelMaxDistance , "Maximální vzdálenost mezi sousedními body, které mají tvořit plochu.");
            toolTipSurface.SetToolTip(this.btnSurface, "Spustí rekonstrukci.");
            toolTipSurface.SetToolTip(this.btnDeleteSurface, "Smaže všechny plochy.");

            toolTipSurface.ShowAlways = true;
            toolTipSurface.AutomaticDelay = 6000;
            toolTipSurface.InitialDelay = 500;
        }

        //nutne kvuli bugu na winXP kdy se tooltip objevi pouze 1x
        private void labelMaxDistance_MouseEnter(object sender, EventArgs e)
        {
            toolTipSurface.Active = false;
            toolTipSurface.Active = true;
        }

        private void btnSurface_MouseEnter(object sender, EventArgs e)
        {
            toolTipSurface.Active = false;
            toolTipSurface.Active = true;
        }

        private void btnDeleteSurface_MouseEnter(object sender, EventArgs e)
        {
            toolTipSurface.Active = false;
            toolTipSurface.Active = true;
        }
    }
}