using System; using System.IO; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.ComponentModel; using System.Windows.Forms; using System.Threading; using ClassLibrary; using Projects; using Data.BusinessService; using Data.DataModel; using Frames; namespace ControlLibrary { public partial class TrekoControl : UserControl { #region Local Variables Project _projectObj; Layer _layerObj; ColorProfile _colorProfileObj; ColorProfileControl _colorProfileControl; private ILayerService layerService; private LayerModel layerModel; private ColorProfileModel colorProfileModel; private ColorProfileService colorProfileService; private ProgressModel progressModel1; private ProgressModel progressModel2; Treko.Treko _treko; Frames.FrameGroup[,] _frameGroups; //private string[] _rakurseFiles; private bool _editMode; /// /// Variable to store error message /// private string _errorMessage; private int _arcWidth; private Bitmap _thumbnail; #endregion // Delegate declaration public delegate void OkClicked(TrekoControl sender, EventArgs e); public delegate void PreviewClicked(TrekoControl sender, EventArgs e); public delegate void ColorProfileClicked(TrekoControl sender, EventArgs e); public delegate void AnglesClicked(TrekoControl sender, EventArgs e); public event OkClicked OnOkClicked; public event PreviewClicked OnPreviewClicked; public event ColorProfileClicked OnColorProfileClicked; public event AnglesClicked OnAnglesClicked; #region Get/Set // Control opened for Edit Treko or Create Treko public bool EditMode { get { return _editMode; } set { _editMode = value; } } public string LayerName { get { return txtLayerName.Text; } set { txtLayerName.Text = value; } } public string OpticalSchema { get { return "Sp0"; } } public Project ProjectObj { get { return _projectObj; } set { _projectObj = value; } } public Layer LayerObj { get { return _layerObj; } set { _layerObj = value; } } public int ProjectId { get; set; } public string TechnologyName { get; set; } public string SourceFilePath { get { return txtImage.Text; } set { txtImage.Text = value; } } public string AnglesFilePath { get { return txtAngles.Text; } set { txtAngles.Text = value; } } public double LayerLeft { get { return (double)numUpDownLayerLeft.Value; } set { numUpDownLayerLeft.Value = (decimal)value; } } public double LayerTop { get { return (double)numUpDownLayerTop.Value; } set { numUpDownLayerTop.Value = (decimal)value; } } public double LayerWidth { get { return (double)numUpDownLayerW.Value; } set { numUpDownLayerW.Value = (decimal)value; } } public double LayerHeight { get { return (double)numUpDownLayerH.Value; } set { numUpDownLayerH.Value = (decimal)value; } } public double Step { get { return (double)numUpDownStep.Value; } set { numUpDownStep.Value = (decimal)value; } } public double RadiusMax { get { return (double)numUpDownRadius.Value; } set { numUpDownRadius.Value = (decimal)value; } } public int ArcWidth { get { return _arcWidth; } set { _arcWidth = value; } } public string Resolution { set { this.lblResolution.Text = value; } } public ColorProfile ColorProfileObj { get { return _colorProfileObj; } set { _colorProfileObj = value; } } public ColorProfileControl ColorProfileControl { get { return _colorProfileControl; } set { _colorProfileControl = value; } } public int FrameGroupWidth { get { return (int)numFrameGroupWidth.Value; } set { numFrameGroupWidth.Value = value; } } public int FrameGroupHeight { get { return (int)numFrameGroupHeight.Value; } set { numFrameGroupHeight.Value = value; } } public int RowStart { get { return (int)numRowStart.Value; } set { numRowStart.Value = value; } } public int RowEnd { get { return (int)numRowEnd.Value; } set { numRowEnd.Value = value; } } public PictureBox pbxSourceImage { get { Control[] cnt = ParentForm.Controls.Find("picBoxSourceImage", true); return (PictureBox)cnt[0]; } } public Treko.Treko trekoObj { get { return _treko; } } public ProjectControl newProjectControl { get { Control[] cnt = this.ParentForm.Controls.Find("newProjectControl1", true); return (ProjectControl)cnt[0]; } } public Bitmap Thumbnail { get { return _thumbnail; } set { _thumbnail = value; } } #endregion public TrekoControl() { InitializeComponent(); UpdateBtnOk(); UpdateBtnCancel(); UpdateBtnReset(); UpdateBtnSaveAsDefault(); _treko = new Treko.Treko(); this.colorProfileService = new ColorProfileService(); this.colorProfileModel = new ColorProfileModel(); this.layerService = new LayerService(); this.progressModel1 = new ProgressModel(); this.progressModel2 = new ProgressModel(); numUpDownRadius.Value = (decimal)_treko.RadiusMax; //numUpDownTrekWidth.Value = _treko.ArcWidth; numUpDownStep.Value = (decimal)_treko.Step; this.LoadTrekoByNameDefault(); this._layerObj = new Layer(layerModel); this.LoadColorProfile(_layerObj.Id); } public void RefreshControl(Layer layerObj) { _layerObj = layerObj; LayerName = _layerObj.LayerName = layerObj.LayerName; //OpticalSchema = layerObj.OpticalSchema; ProjectId = layerObj.ProjectId; TechnologyName = layerObj.TechnologyName; LayerLeft = layerObj.LayerLeft; LayerTop = layerObj.LayerTop; LayerWidth = layerObj.LayerWidth; LayerHeight = layerObj.LayerHeight; ArcWidth = layerObj.ArcWidth; RadiusMax = layerObj.RadiusMax; Step = layerObj.Step; SourceFilePath = layerObj.SourceFilePath; AnglesFilePath = layerObj.AnglesFilePath; FrameGroupHeight = 1; FrameGroupWidth = 1; RowStart = 0; RowEnd = Convert.ToInt16(ProjectObj.HologramHeight / ProjectObj.FrameHeight); int imgWidth = 50; int imgHeight = 50; if (SourceFilePath != null) { _thumbnail = ImageProcessing.CreateThumbnail(SourceFilePath, imgWidth, imgHeight); } else { _thumbnail = null; } picBoxThumbnail.BackgroundImage = _thumbnail; picBoxThumbnail.Invalidate(); Visible = true; } private void UpdateBtnOk() { Point[] pts = { new Point(-1, -1), new Point(88, -1), new Point(59, 40), new Point(-1, 40), new Point(-1, -1) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); btnOk.Region = polygon_region; // Make the button big enough to hold the whole region. btnOk.SetBounds( btnOk.Location.X, btnOk.Location.Y, 89, 41); } private void UpdateBtnCancel() { Point[] pts = { new Point(0, -1), new Point(89, -1), new Point(89, 41), new Point(29, 41), new Point(0, -1) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); //fineprint //stereograd btnCancel.Region = polygon_region; // Make the button big enough to hold the whole region. btnCancel.SetBounds( btnCancel.Location.X, btnCancel.Location.Y, 89, 41); } private void UpdateBtnReset() { Point[] pts = { new Point(29, -1), new Point(79, -1), new Point(79, 41), new Point(0, 41), new Point(29, -1) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); //fineprint //stereograd btnRun.Region = polygon_region; // Make the button big enough to hold the whole region. btnRun.SetBounds( btnRun.Location.X, btnRun.Location.Y, 89, 41); } private void UpdateBtnSaveAsDefault() { Point[] pts = { new Point(0, -1), new Point(49, -1), new Point(79, 41), new Point(0, 41), new Point(0, -1) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); //fineprint //stereograd btnSaveAsDefault.Region = polygon_region; // Make the button big enough to hold the whole region. btnSaveAsDefault.SetBounds( btnSaveAsDefault.Location.X, btnSaveAsDefault.Location.Y, 79, 41); } /// /// Method to show general error message on any system level exception /// private void ShowErrorMessage(Exception ex) { MessageBox.Show( ex.Message, //Resources.System_Error_Message, Resources.System_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } /// /// Validates registration input /// /// true or false private bool ValidateRegistration() { if (_projectObj == null) { MessageBox.Show( Resources.Registration_Missing_Project_Error_Message, Resources.Registration_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } //this.errorMessage = string.Empty; //if (txtProjectName.Text.Trim() == string.Empty) //{ // //this.AddErrorMessage(Resources.Project_Name_Required_Text); //} //if (cmbOccupation.SelectedIndex == -1) //{ // this.AddErrorMessage(Resources.Registration_Occupation_Select_Text); //} //if (cmbMaritalStatus.SelectedIndex == -1) //{ // this.AddErrorMessage(Resources.Registration_MaritalStatus_Select_Text); //} //if (cmbHealthStatus.SelectedIndex == -1) //{ // this.AddErrorMessage(Resources.Registration_HealthStatus_Select_Text); //} return true; // this.errorMessage != string.Empty ? false : true; } public bool RegisterNewTrekoLayer() { var success = false; try { // Check if the validation passes if (this.ValidateRegistration()) { // Create Layer and add to Project layerModel.LayerName = LayerName; layerModel.OpticalSchema = OpticalSchema; layerModel.TechnologyName = "Treko"; layerModel.ProjectId = _projectObj.ProjectId; layerModel.Order = layerService.GetCountOfLayers(_projectObj.ProjectId); // Set as last layer layerModel.LayerLeft = LayerLeft; layerModel.LayerTop = LayerTop; layerModel.LayerWidth = LayerWidth; layerModel.LayerHeight = LayerHeight; layerModel.ArcWidth = ArcWidth; layerModel.RadiusMax = RadiusMax; layerModel.Step = Step; layerModel.SourceFilePath = SourceFilePath; layerModel.AnglesFilePath = AnglesFilePath; success = layerService.RegisterLayer(layerModel); // if status of success variable is true then display a information else display the error message if (success) { _layerObj = new Layer(layerModel); //this.ProjectId = projectModel.Id; // display the message box //MessageBox.Show( // Resources.Registration_Successful_Message, // Resources.Registration_Successful_Message_Title, // MessageBoxButtons.OK, // MessageBoxIcon.Information); // Reset the screen //this.ResetRegistration(); } else { // display the error messge MessageBox.Show( Resources.Registration_Error_Message, Resources.Registration_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { // Display the validation failed message // MessageBox.Show( // this.errorMessage, // Resources.Registration_Error_Message_Title, // MessageBoxButtons.OK, // MessageBoxIcon.Error); } } catch (Exception ex) { this.ShowErrorMessage(ex); } return success; } /// /// Validates update data /// /// true or false private bool ValidateUpdate() { //this._errorMessage = string.Empty; //if (txt2Name.Text.Trim() == string.Empty) //{ // this.AddErrorMessage(Resources.Registration_Name_Required_Text); //} //if (cmb2Occupation.SelectedIndex == -1) //{ // this.AddErrorMessage(Resources.Registration_Occupation_Select_Text); //} //if (cmb2MaritalStatus.SelectedIndex == -1) //{ // this.AddErrorMessage(Resources.Registration_MaritalStatus_Select_Text); //} //if (cmb2HealthStatus.SelectedIndex == -1) //{ // this.AddErrorMessage(Resources.Registration_HealthStatus_Select_Text); //} //return this._errorMessage != string.Empty ? false : true; return true; } public bool UpdateTrekoLayer() { var success = false; try { if (this.ValidateUpdate()) { LayerModel layerModel = new LayerModel() { Id = _layerObj.Id, LayerName = LayerName, OpticalSchema = OpticalSchema, TechnologyName = "Treko", ProjectId = ProjectId, Order = _layerObj.Order, // layerService.GetCountOfLayers(ProjectId), // Set as last layer LayerLeft = this.LayerLeft, LayerTop = this.LayerTop, LayerWidth = this.LayerWidth, LayerHeight = this.LayerHeight, ArcWidth = this.ArcWidth, RadiusMax = this.RadiusMax, Step = this.Step, SourceFilePath = this.SourceFilePath, AnglesFilePath = this.AnglesFilePath, }; var flag = this.layerService.UpdateLayer(layerModel); } else { MessageBox.Show( this._errorMessage, Resources.Registration_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { this.ShowErrorMessage(ex); } return success; } public bool RegisterNewColorProfileDefault() { var success = false; try { // Check if the validation passes if (this.ValidateRegistration()) { // Assign the values to the model this.colorProfileModel = new ColorProfileModel() { Id = 0, ProfileName = "Gauss", KeyPointsString = @"{X=0, Y=27},{X=32, Y=36},{X=64, Y=45},{X=96, Y=128},{X=128, Y=182},{X=160, Y=128},{X=192, Y=45},{X=224, Y=36},{X=255, Y=27}", TraceProfileString = @"58,59,60,60,61,61,62,63,63,64,65,66,66,67,68,69,70,71,72,73,74,75,76,77,78,80,81,82,84,85,86,88,89,91,93,94,96,98,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,130,132,134,136,139,141,143,146,148,150,153,155,157,160,162,165,167,169,172,174,176,179,181,183,186,188,190,193,195,197,199,201,204,206,208,210,212,214,216,218,220,222,223,225,227,229,230,232,233,235,236,238,239,240,242,243,244,245,246,247,248,249,250,251,251,252,253,253,253,254,254,255,255,255,255,255,255,255,255,255,254,254,253,253,253,252,251,251,250,249,248,247,246,245,244,243,242,240,239,238,236,235,233,232,230,229,227,225,223,222,220,218,216,214,212,210,208,206,204,201,199,197,195,193,190,188,186,183,181,179,176,174,172,169,167,165,162,160,157,155,153,150,148,146,143,141,139,136,134,132,130,127,125,123,121,119,117,115,113,111,109,107,105,103,101,99,98,96,94,93,91,89,88,86,85,84,82,81,80,78,77,76,75,74,73,72,71,70,69,68,67,66,66,65,64,63,63,62,61,61,60,60,0", ArcWidth = layerModel.ArcWidth, LayerId = layerModel.Id, }; // Call the service method and assign the return status to variable success = this.colorProfileService.RegisterColorProfile(colorProfileModel); // if status of success variable is true then display a information else display the error message if (success) { // display the message box //MessageBox.Show( // Resources.Registration_Color_Profile_Successful_Message, // Resources.Registration_Successful_Message_Title, // MessageBoxButtons.OK, // MessageBoxIcon.Information); // Reset the screen //this.ResetRegistration(); } else { // display the error messge MessageBox.Show( Resources.Registration_Error_Message, Resources.Registration_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { // Display the validation failed message // MessageBox.Show( // this.errorMessage, // Resources.Registration_Error_Message_Title, // MessageBoxButtons.OK, // MessageBoxIcon.Error); } } catch (Exception ex) { this.ShowErrorMessage(ex); } return success; } public void LoadColorProfile(int layerId) { DataRow dataRow = this.colorProfileService.GetLayerColorProfile(layerId); if (dataRow != null) { // Assign the values to the model this.colorProfileModel = new ColorProfileModel() { Id = Convert.ToInt16(dataRow["Id"]), ProfileName = dataRow["ProfileName"].ToString(), //Author = this.textBoxAuthor.Text.Trim(), ArcWidth = Convert.ToInt16(dataRow["ArcWidth"]), TraceProfileString = dataRow["TraceProfile"].ToString(), KeyPointsString = dataRow["KeyPoints"].ToString(), LayerId = Convert.ToInt16(dataRow["LayerId"]), }; colorProfileModel.KeyPoints = colorProfileModel.KeyPointsString.Replace("},{X=", ";").Replace("{X=", string.Empty).Replace("}", string.Empty).Replace(" Y=", string.Empty).Split(';').Select(x => x.Split(',')).Select(y => new PointF(int.Parse(y[0]), int.Parse(y[1]))).ToArray(); colorProfileModel.TraceProfile = colorProfileModel.TraceProfileString.Split(',').Select(int.Parse).ToArray(); this._colorProfileObj = new ColorProfile(colorProfileModel); } } public void LoadColorProfileDefault() { string default_layer_name = Resources.Default_Layer_Name; string technologyName = "Treko3D"; DataRow dataRow = this.colorProfileService.GetColorProfileByLayerNameTechnology(default_layer_name, technologyName); if (dataRow != null) { // Assign the values to the model this.colorProfileModel = new ColorProfileModel() { Id = Convert.ToInt16(dataRow["Id"]), ProfileName = dataRow["ProfileName"].ToString(), //Author = this.textBoxAuthor.Text.Trim(), ArcWidth = Convert.ToInt16(dataRow["ArcWidth"]), TraceProfileString = dataRow["TraceProfile"].ToString(), KeyPointsString = dataRow["KeyPoints"].ToString(), LayerId = Convert.ToInt16(dataRow["LayerId"]), }; colorProfileModel.KeyPoints = colorProfileModel.KeyPointsString.Replace("},{X=", ";").Replace("{X=", string.Empty).Replace("}", string.Empty).Replace(" Y=", string.Empty).Split(';').Select(x => x.Split(',')).Select(y => new PointF(int.Parse(y[0]), int.Parse(y[1]))).ToArray(); colorProfileModel.TraceProfile = colorProfileModel.TraceProfileString.Split(',').Select(int.Parse).ToArray(); this._colorProfileObj = new ColorProfile(colorProfileModel); } } public void LoadTrekoByNameDefault() { string layerName = Resources.Default_Layer_Name; string technologyName = "Treko"; DataRow dataRow = this.layerService.GetLayerByNameTechnology(layerName, technologyName); // Assign the values to the model // Assign the values to the model layerModel = new LayerModel() { Id = Convert.ToInt16(dataRow["Id"]), Order = Convert.ToInt16(dataRow["Order"]), LayerName = dataRow["LayerName"].ToString(), OpticalSchema = dataRow["OpticalSchema"].ToString(), ProjectId = Convert.ToInt16(dataRow["ProjectId"]), TechnologyName = dataRow["TechnologyName"].ToString(), SourceFilePath = dataRow["SourceFilePath"].ToString(), AnglesFilePath = dataRow["AnglesFilePath"].ToString(), LayerLeft = Convert.ToSingle(dataRow["LayerLeft"]), LayerTop = Convert.ToSingle(dataRow["LayerTop"]), LayerWidth = Convert.ToSingle(dataRow["LayerWidth"]), LayerHeight = Convert.ToSingle(dataRow["LayerHeight"]), RadiusMax = Convert.ToSingle(dataRow["RadiusMax"]), ArcWidth = Convert.ToInt16(dataRow["ArcWidth"]), Step = Convert.ToSingle(dataRow["Step"]), }; txtLayerName.Text = ""; numUpDownStep.Value = Convert.ToDecimal(layerModel.Step); numUpDownRadius.Value = Convert.ToDecimal(layerModel.RadiusMax); ArcWidth = Convert.ToInt16(layerModel.ArcWidth); txtImage.Text = layerModel.SourceFilePath.ToString(); txtAngles.Text = layerModel.AnglesFilePath.ToString(); } private bool UpdateTrekoDefault(LayerModel layerModel) { var success = false; string layerName = Resources.Default_Layer_Name; try { if (this.ValidateUpdate()) { //cmbResolution_SelectedIndexChanged(this, EventArgs.Empty); //DataRow dataRow = this.layerService.GetLayerByName(layerName); //LayerModel layerModel = new LayerModel() //{ // Id = Convert.ToInt16(dataRow["Id"]), // Order = Convert.ToInt16(dataRow["Order"]), // LayerName = dataRow["LayerName"].ToString(), // OpticalSchema = dataRow["OpticalSchema"].ToString(), // ProjectId = Convert.ToInt16(dataRow["ProjectId"]), // TechnologyName = dataRow["TechnologyName"].ToString(), //}; var flag = this.layerService.UpdateLayer(layerModel); //if (flag) //{ // DataTable data = this.layerService..GetAllLayers(); // //this.LoadDataGridView(data); // //MessageBox.Show( // // Resources.Update_Successful_Message, // // Resources.Update_Successful_Message_Title, // // MessageBoxButtons.OK, // // MessageBoxIcon.Information); // success = true; //} } else { MessageBox.Show( this._errorMessage, Resources.Registration_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { this.ShowErrorMessage(ex); } return success; } private void clearErrors() { errorProvider1.SetError(txtLayerName, ""); errorProvider1.SetError(txtImage, ""); errorProvider1.SetError(txtAngles, ""); errorProvider1.SetError(numUpDownStep, ""); errorProvider1.SetError(numUpDownRadius, ""); errorProvider1.SetError(txtFullMask, ""); // errorProvider1.SetError(txtTileMask, ""); } private bool btnOkValidating() { bool success = true; clearErrors(); System.ComponentModel.CancelEventArgs ea = null; txtLayerName_Validating(txtLayerName, ea); if (errorProvider1.GetError(txtLayerName) != "") success = false; txtImage_Validating(txtImage, ea); if (errorProvider1.GetError(txtImage) != "") success = false; txtAngles_Validating(txtAngles, ea); if (errorProvider1.GetError(txtAngles) != "") success = false; return success; } private void BtnOk_Click(object sender, EventArgs e) { clearProgressInfo(); if (btnOkValidating() == false) return; this.Visible = false; OnOkClicked?.Invoke(this, EventArgs.Empty); //if (EditMode == true) //control for update project //{ // success = UpdateTrekoLayer(); //} //else //control for create project //{ // success = RegisterNewTrekoLayer(); //} //if (success == true) //{ // _treko.Step = Convert.ToDouble(numUpDownStep.Value); // _treko.RadiusMax = Convert.ToDouble(numUpDownRadius.Value); // _treko.ArcWidth = Convert.ToInt32(numUpDownTrekWidth.Value); // OnOkClicked?.Invoke(this, EventArgs.Empty); //} } private void BtnCancel_Click(object sender, EventArgs e) { //FlowLayoutPanel flp = (FlowLayoutPanel)this.Parent.Parent; //SplitterPanel splitterPanel = (SplitterPanel)this.Parent.Parent; //SplitContainer splitContainer = (SplitContainer)splitterPanel.Parent; Control[] cnt = this.ParentForm.Controls.Find("splitContainer1", true); SplitContainer splitContainer = (SplitContainer)cnt[0]; if (splitContainer.Panel1Collapsed == true) splitContainer.Panel1Collapsed = false; else splitContainer.Panel1Collapsed = true; // MessageBox.Show("Cancel"); backgroundWorker1.CancelAsync(); //backgroundWorker2.CancelAsync(); this.Visible = false; } private bool btnRunValidating() { bool success = true; clearErrors(); System.ComponentModel.CancelEventArgs ee = null; txtLayerName_Validating(this, ee); if (errorProvider1.GetError(txtLayerName) != "") success = false; txtImage_Validating(txtImage, ee); if (errorProvider1.GetError(txtImage) != "") success = false; txtAngles_Validating(txtAngles, ee); if (errorProvider1.GetError(txtAngles) != "") success = false; numUpDownRadius_Validating(this, ee); if (errorProvider1.GetError(numUpDownRadius) != "") success = false; txtFullMask_Validating(this, ee); if (errorProvider1.GetError(txtFullMask) != "") success = false; txtTileMask_Validating(this, ee); // if (errorProvider1.GetError(txtTileMask) != "") // success = false; return success; } private void launchBackgroundWorker() { if (backgroundWorker1.IsBusy != true) { int nFramesHor = Convert.ToInt32(_projectObj.HologramWidth / _projectObj.FrameWidth); int nFramesVert = Convert.ToInt32(_projectObj.HologramHeight / _projectObj.FrameHeight); // Number of frames in group int nFramesInGroupHor = FrameGroupWidth; int nFramesInGroupVert = FrameGroupHeight; // ini values in file this.progressModel1.MaxValue = nFramesHor / nFramesInGroupHor + 1; // horizontal length is bigger because of briks this.progressModel1.MinValue = 0; this.progressModel1.CurValue = 0; this.progressModel2.MaxValue = RowEnd + 1; // nFramesVert / nFramesInGroupVert; this.progressModel2.MinValue = RowStart; this.progressModel2.CurValue = RowStart; // Start the asynchronous operation. backgroundWorker1.RunWorkerAsync(); } } public void SaveData() { bool success = false; if (EditMode == true) //control for update project { success = UpdateTrekoLayer(); } else { // We try to create new layer without project // So we need to create default project first if (_projectObj == null || _projectObj.ProjectName == "" || _projectObj.ProjectName == Resources.Default_Project_Name) { success = newProjectControl.RegisterDefaultProject(); _projectObj = newProjectControl.Project; ProjectObj = _projectObj; } success = RegisterNewTrekoLayer(); } string dirName = this.SourceFilePath; string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\"; if (outDirName == "" || !Directory.Exists(outDirName)) outDirName = Helper.CreateOutDir(dirName); if (outDirName == "") return; //_treko.VoxelWidthPix = 32; // Voxel size is variable. Depends on size of arcs. //_treko.VoxelHeightPix = 32; //_treko.RakurseFiles = RakurseFiles; // Array of names of rakurse files //if (RakurseFiles == null) // _treko.NRakurses = 0; //else // _treko.NRakurses = RakurseFiles.Length; DataRow row = layerService.GetColorProfileByLayerId(_layerObj.Id); if (this.ColorProfileControl != null) { ColorProfileControl.LayerId = _layerObj.Id; if (row == null) { success = ColorProfileControl.RegisterNewColorProfile(); this.ColorProfileObj = ColorProfileControl.ColorProfileObj; } else { success = ColorProfileControl.UpdateColorProfile(); this.ColorProfileObj = ColorProfileControl.ColorProfileObj; } } else { if (row == null) { LoadColorProfileDefault(); // Color Profile record is mandatory for layer success = RegisterNewColorProfileDefault(); } else { LoadColorProfile(_layerObj.Id); } } _treko.RadiusMax = (float)numUpDownRadius.Value; // Given from Control's text box _treko.Step = (float)numUpDownStep.Value; // Width of Hologram in mm / Width of Hologram in pixels (30mm/200pxs=0.15mm) _treko.ArcWidth = _colorProfileObj.ArcWidth; _projectObj = newProjectControl.Project; //trekoObj.LoadRakurseFiles(); } private void BtnRun_Click(object sender, EventArgs e) { clearProgressInfo(); if (btnRunValidating() == false) return; SaveData(); _treko.RadiusMax = (float)numUpDownRadius.Value; _treko.Step = (float)numUpDownStep.Value; _treko.ArcWidth = _colorProfileObj.ArcWidth; _projectObj = newProjectControl.Project; trekoObj.GenVectorData(_projectObj.HologramWidth, _projectObj.HologramHeight); launchBackgroundWorker(); //bool success = false; //if (EditMode == true) //control for update project //{ // success = UpdateTrekoLayer(); //} //else //{ // // We try to create new layer without project // // So we need to create default project first // if (_projectObj == null || _projectObj.ProjectName == "" // || _projectObj.ProjectName == Resources.Default_Project_Name) // { // success = newProjectControl.RegisterDefaultProject(); // _projectObj = newProjectControl.Project; // ProjectObj = _projectObj; // } // success = RegisterNewTrekoLayer(); //} //string dirName = this.SourceFilePath; //string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\"; //if (outDirName == "" || !Directory.Exists(outDirName)) // outDirName = Helper.CreateOutDir(dirName); //if (outDirName == "") // return; //DataRow row = layerService.GetColorProfileByLayerId(_layerObj.Id); //if (this.ColorProfileControl != null) //{ // ColorProfileControl.LayerId = _layerObj.Id; // if (row == null) // { // success = ColorProfileControl.RegisterNewColorProfile(); // this.ColorProfileObj = ColorProfileControl.ColorProfileObj; // } // else // { // success = ColorProfileControl.UpdateColorProfile(); // this.ColorProfileObj = ColorProfileControl.ColorProfileObj; // } //} //else //{ // if (row == null) // { // LoadColorProfileDefault(); // // Color Profile record is mandatory for layer // success = RegisterNewColorProfileDefault(); // } else // { // LoadColorProfile(_layerObj.Id); // } //} //_treko.RadiusMax = (float)numUpDownRadius.Value; //_treko.Step = (float)numUpDownStep.Value; //_treko.ArcWidth = _colorProfileObj.ArcWidth; //_projectObj = newProjectControl.Project; //trekoObj.GenVectorData(_projectObj.HologramWidth, _projectObj.HologramHeight); //if (backgroundWorker1.IsBusy != true) //{ // int nFramesHor = Convert.ToInt32(_projectObj.HologramWidth / _projectObj.FrameWidth); // int nFramesVert = Convert.ToInt32(_projectObj.HologramHeight / _projectObj.FrameHeight); // // Number of frames in group // int nFramesInGroupHor = FrameGroupWidth; // int nFramesInGroupVert = FrameGroupHeight; // // ini values in file // this.progressModel1.MaxValue = nFramesHor / nFramesInGroupHor + 1; // horizontal length is bigger because of briks // this.progressModel1.MinValue = 0; // this.progressModel1.CurValue = 0; // this.progressModel2.MaxValue = RowEnd + 1; // nFramesVert / nFramesInGroupVert; // this.progressModel2.MinValue = RowStart; // this.progressModel2.CurValue = RowStart; // // Start the asynchronous operation. // backgroundWorker1.RunWorkerAsync(); //} //_treko.RenderTreko(); //MessageBox.Show("Reset"); } private void BtnSaveAsDefault_Click(object sender, EventArgs e) { string layerName = Resources.Default_Layer_Name; try { DataRow dataRow = this.layerService.GetLayerByNameTechnology(layerName, "Treko"); LayerModel layerModel = new LayerModel() { Id = Convert.ToInt16(dataRow["Id"]), Order = 0, LayerName = layerName, OpticalSchema = this.OpticalSchema, ProjectId = Convert.ToInt16(dataRow["ProjectId"]), TechnologyName = "Treko", LayerLeft = this.LayerLeft, LayerTop = this.LayerTop, LayerWidth = this.LayerWidth, LayerHeight = this.LayerHeight, RadiusMax = this.RadiusMax, ArcWidth = this.ArcWidth, Step = this.Step, SourceFilePath = this.SourceFilePath, AnglesFilePath = this.AnglesFilePath, }; UpdateTrekoDefault(layerModel); } catch (Exception ex) { this.ShowErrorMessage(ex); } } private void BtnOpenImage_Click(object sender, EventArgs e) { OpenFileDialog open_dialog = new OpenFileDialog(); //создание диалогового окна для выбора файла open_dialog.Title = "Open (Treco - layer)"; //!!!!Nick open_dialog.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*"; //форматы загружаемых файлов //Control[] cnt = this.ParentForm.Controls.Find("picBoxSourceImage", true); //PictureBox pbx = (PictureBox)cnt[0]; if (open_dialog.ShowDialog() == DialogResult.OK) //Кнопка "ОК" { try { var image = new Bitmap(open_dialog.FileName); _treko.Pixels = new int[image.Height, image.Width]; for (int y = 0; y < image.Height; y++) for (int x = 0; x < image.Width; x++) { _treko.Pixels[y, x] = (int)(image.GetPixel(x, y).ToArgb()); //pixel[y, x] = (UInt32)(image.GetPixel(x, y).ToArgb()); } _treko.SourceImage = image; string dirName = Path.GetDirectoryName(open_dialog.FileName); _treko.ImagePath = dirName; txtImage.Text = open_dialog.FileName; int imgWidth = 50; int imgHeight = 50; _thumbnail = ImageProcessing.CreateThumbnail(SourceFilePath, imgWidth, imgHeight); picBoxThumbnail.BackgroundImage = _thumbnail; picBoxThumbnail.Invalidate(); } catch (Exception d) { DialogResult rezult = MessageBox.Show(d.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void btnOpenAnglesNik_Click(object sender, EventArgs e) { string filePath = ""; //string sr = ""; //int n = 1, m = 1; OpenFileDialog open_dialog = new OpenFileDialog(); //создание диалогового окна для выбора файла open_dialog.Title = "Open (Angles.ini)"; //!!!!Nick open_dialog.Filter = "Image Files(*.ini)|*.ini|All files (*.*)|*.*"; //форматы загружаемых файлов if (open_dialog.ShowDialog() == DialogResult.OK) //Кнопка "ОК" try { filePath = open_dialog.FileName; txtAngles.Text = filePath; _treko.GenerateAngles(filePath); } catch { DialogResult rezult = MessageBox.Show("Unable to open the selected file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void btnOpenAngles_Click(object sender, EventArgs e) { } private void btnDetalizationPreview_Click(object sender, EventArgs e) { _treko.RadiusMax = (float)numUpDownRadius.Value; // Given from Control's text box _treko.Step = (float)numUpDownStep.Value; // Width of Hologram in mm / Width of Hologram in pixels (30mm/200pxs=0.15mm) _treko.ArcWidth = (int)colorProfileModel.ArcWidth; //_treko.RakurseFiles = RakurseFiles; // Array of names of rakurse files //_treko.NRakurses = RakurseFiles.Length; System.ComponentModel.CancelEventArgs ea = null; txtImage_Validating(this, ea); if (errorProvider1.GetError(txtImage) != "") return; txtAngles_Validating(this, ea); if (errorProvider1.GetError(txtAngles) != "") return; OnPreviewClicked?.Invoke(this, EventArgs.Empty); } private void BtnColorProfile_Click(object sender, EventArgs e) { OnColorProfileClicked?.Invoke(this, EventArgs.Empty); } private void numUpDownStep_ValueChanged(object sender, EventArgs e) { _treko.Step = (float)numUpDownStep.Value; } private void btnAngles_Click(object sender, EventArgs e) { OnAnglesClicked?.Invoke(this, EventArgs.Empty); } private void btnClearImage_Click(object sender, EventArgs e) { txtImage.Text = ""; } private void btnClearAngles_Click(object sender, EventArgs e) { txtAngles.Text = ""; } private void LoadImageFile(string path) { try { var image = new Bitmap(path); _treko.Pixels = new int[image.Height, image.Width]; for (int y = 0; y < image.Height; y++) for (int x = 0; x < image.Width; x++) { _treko.Pixels[y, x] = (int)(image.GetPixel(x, y).ToArgb()); //pixel[y, x] = (UInt32)(image.GetPixel(x, y).ToArgb()); } _treko.SourceImage = image; string dirName = Path.GetDirectoryName(path); _treko.ImagePath = dirName; txtImage.Text = path; } catch (Exception d) { DialogResult rezult = MessageBox.Show(d.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void txtImage_Validating(object sender, System.ComponentModel.CancelEventArgs e) { errorProvider1.SetError(txtImage, ""); string path = txtImage.Text; if (path == "") { errorProvider1.SetError(txtImage, "Image File Path must not be empty."); return; } this.LoadImageFile(path); if (_treko.SourceImage == null) errorProvider1.SetError(txtImage, "Error Loading Image File."); } private void txtAngles_Validating(object sender, System.ComponentModel.CancelEventArgs e) { errorProvider1.SetError(txtAngles, ""); if (txtAngles.Text == "") { errorProvider1.SetError(txtAngles, "Angles File Path must not be empty."); return; } _treko.GenerateAngles(txtAngles.Text); if (_treko.Angles == null) errorProvider1.SetError(txtAngles, "Error Loading Angles File."); } private void txtLayerName_Validating(object sender, System.ComponentModel.CancelEventArgs e) { errorProvider1.SetError(txtLayerName, ""); if (txtLayerName.Text == "") errorProvider1.SetError(txtLayerName, "Layer Name must not be empty."); } public void WriteIniFile(StreamWriter sw, string sLine) { try { sw.WriteLine(sLine); } catch (Exception e) { } finally { } } private Frame GetFrame(int nCol, int nRow) { int nFramesHor = _frameGroups[0, 0].NFramesHor; int nFramesVert = _frameGroups[0, 0].NFramesVert; int iGroup = nCol / nFramesHor; int jGroup = nRow / nFramesVert; int i = nCol % nFramesHor; int j = nRow % nFramesVert; FrameGroup fg = _frameGroups[iGroup, jGroup]; Frame fr = fg.FrameMap[i, j]; if (fg.IsBlack) fr.IsBlack = true; return fr; } public void GenerateIniFile() { string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\"; string sLine = ""; int eCount = 0; int zCount = 0; StreamWriter sw = new StreamWriter(outDirName + "\\exp.ini"); int nGroupCols = _frameGroups.GetLength(0); int nGroupRows = _frameGroups.GetLength(1); int nCols = nGroupCols * _frameGroups[0, 0].NFramesHor; int nRows = nGroupRows * _frameGroups[0, 0].NFramesVert; sLine = nCols.ToString(); WriteIniFile(sw, sLine); sLine = nCols.ToString(); WriteIniFile(sw, sLine); sLine = nRows.ToString(); WriteIniFile(sw, sLine); sLine = ""; int n = 0; // for debug number of frame files for (int j = 0; j < nRows; j++) { for (int i = 0; i < nCols; i++) { Frame fr = GetFrame(i, j); //FrameGroup fg = _frameGroups[i, j]; if (fr.IsBlack == false) { checkZcount(ref zCount, ref sLine); eCount++; } else { checkEcount(ref eCount, ref n, ref sLine); zCount++; } //// in group only one frame for now //if (fg.IntersectRakurseArcs != null && fg.IntersectRakurseArcs.Count > 0) //{ // checkZcount(ref zCount, ref sLine); // eCount++; //} //else //{ // checkEcount(ref eCount, ref n, ref sLine); // zCount++; //} } checkEcount(ref eCount, ref n, ref sLine); checkZcount(ref zCount, ref sLine); WriteIniFile(sw, sLine); sLine = ""; } WriteIniFile(sw, "Number of files:" + n); sw.Close(); } void checkEcount(ref int eCount, ref int n, ref string sLine) { if (eCount > 0) { n += eCount; sLine = sLine + eCount + "e"; eCount = 0; } } void checkZcount(ref int zCount, ref string sLine) { if (zCount > 0) { sLine = sLine + zCount + "z"; zCount = 0; } } private void clearProgressInfo() { lblGenFrames.Text = ""; //lblSaveFrames.Text = ""; progressBar1.Value = 0; progressBar2.Value = 0; //progressBar3.Value = 0; //progressBar4.Value = 0; } public int ProgressPercentage(int value, int minval, int maxval) { return value * 100 / maxval; } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; while (progressModel2.CurValue < progressModel2.MaxValue) { if (worker.CancellationPending == true) { e.Cancel = true; break; } else { int nFramesHor = Convert.ToInt32(_projectObj.HologramWidth / _projectObj.FrameWidth); int nFramesVert = Convert.ToInt32(_projectObj.HologramHeight / _projectObj.FrameHeight); //string labelInd = "Gen. Frames " + Convert.ToString(nFramesHor) + "x" + Convert.ToString(nFramesVert); // Number of frames in group int nFramesInGroupHor = FrameGroupWidth; int nFramesInGroupVert = FrameGroupHeight; // add one more frame group for bricks construction _frameGroups = new FrameGroup[nFramesHor / nFramesInGroupHor + 1, nFramesVert / nFramesInGroupVert + 1]; //_frameGroups = new FrameGroup[nFramesHor, nFramesVert]; string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\"; for (int j = 0; j < _frameGroups.GetLength(1); j++) { for (int i = 0; i < _frameGroups.GetLength(0); i++) { // in group only one frame for now //_frameGroups[i, j] = new FrameGroup(_projectObj.ResolutionX, _projectObj.ResolutionY, _projectObj.FrameWidth, _projectObj.FrameHeight, 1, 1, i, j); _frameGroups[i, j] = new FrameGroup(_projectObj.ResolutionX, _projectObj.ResolutionY, _projectObj.FrameWidth, _projectObj.FrameHeight, nFramesInGroupHor, nFramesInGroupVert, i, j); FrameGroup fg = _frameGroups[i, j]; fg.FillByIntersectColorArcs(trekoObj.ColorPixels); //_frameGroups[i, j].FillByIntersectColorArcs(_treko); if (fg.IntersectColorArcs != null && fg.IntersectColorArcs.Count > 0) { fg.DrawBitmapByColorArcs(_layerObj.TraceProfile); fg.CropIntoImageArray(j); //fg.SaveGroupToFiles(_outDirName, n, i, j); fg.SaveGroupToFiles(outDirName, i, j, _frameGroups.GetLength(0), _frameGroups.GetLength(1)); fg.FrameGroupBmp.Dispose(); } else fg.MarkFrameGroupAsBlack(); this.progressModel1.CurValue = i + 1; int progress1 = ProgressPercentage(progressModel1.CurValue, progressModel1.MinValue, progressModel1.MaxValue); worker.ReportProgress(progress1); if (worker.CancellationPending == true) { e.Cancel = true; break; } // Perform a time consuming operation and report progress. Thread.Sleep(20); } this.progressModel2.CurValue = j + 1; int progress2 = ProgressPercentage(progressModel2.CurValue, progressModel2.MinValue, progressModel2.MaxValue); worker.ReportProgress(progress2); if (worker.CancellationPending == true) { e.Cancel = true; break; } Thread.Sleep(20); } } } } private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { int nFramesHor = Convert.ToInt32(_projectObj.HologramWidth / _projectObj.FrameWidth); int nFramesVert = Convert.ToInt32(_projectObj.HologramHeight / _projectObj.FrameHeight); int progress1 = ProgressPercentage(progressModel1.CurValue, progressModel1.MinValue, progressModel1.MaxValue); int progress2 = ProgressPercentage(progressModel2.CurValue, progressModel2.MinValue, progressModel2.MaxValue); // Change the value of the ProgressBar to the BackgroundWorker progress. progressBar1.Value = progress1; // e.ProgressPercentage; progressBar1.Maximum = 100; progressBar1.Minimum = 0; progressBar2.Value = progress2; progressBar2.Maximum = 100; progressBar2.Minimum = 0; // Number of frames in group int nFramesInGroupHor = FrameGroupWidth; int nFramesInGroupVert = FrameGroupHeight; string labelInd = "Gen. Frames " + Convert.ToString(nFramesHor / nFramesInGroupHor + 1) + "x" + Convert.ToString(nFramesVert / nFramesInGroupVert); lblGenFrames.Text = labelInd + " - " + Convert.ToString(this.progressModel1.CurValue) + "x" + Convert.ToString(this.progressModel2.CurValue); lblGenFrames.Refresh(); // Set the text. //this.Text = e.ProgressPercentage.ToString(); } private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { if (e.Cancelled == true) { lblGenFrames.Text = "Canceled!"; } else if (e.Error != null) { lblGenFrames.Text = "Error: " + e.Error.Message; } else { lblGenFrames.Text = "Done!"; GenerateIniFile(); //if (backgroundWorker2.IsBusy != true) //{ // // Number of frames in group // int nFramesInGroupHor = 10; // int nFramesInGroupVert = 10; // int nFramesHor = Convert.ToInt32(_projectObj.HologramWidth / _projectObj.FrameWidth) / nFramesInGroupHor; // int nFramesVert = Convert.ToInt32(_projectObj.HologramHeight / _projectObj.FrameHeight) / nFramesInGroupVert; // // ini values in file // this.progressModel1.MaxValue = nFramesHor + 1; // horizontal length is bigger because of briks // this.progressModel1.MinValue = 0; // this.progressModel1.CurValue = 0; // this.progressModel2.MaxValue = nFramesVert; // this.progressModel2.MinValue = 0; // this.progressModel2.CurValue = 0; // // Start the asynchronous operation. // backgroundWorker2.RunWorkerAsync(); //} } } //private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) //{ // BackgroundWorker worker = sender as BackgroundWorker; // while (progressModel2.CurValue < progressModel2.MaxValue) // { // if (worker.CancellationPending == true) // { // e.Cancel = true; // break; // } // string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\"; // for (int j = 0; j < _frameGroups.GetLength(1); j++) // { // for (int i = 0; i < _frameGroups.GetLength(0); i++) // { // FrameGroup fg = _frameGroups[i, j]; // // in group only one frame for now // if (fg.IntersectColorArcs != null && fg.IntersectColorArcs.Count > 0) // { // fg.DrawBitmapByColorArcs(_layerObj.TraceProfile); // fg.CropIntoImageArray(j); // //fg.SaveGroupToFiles(outDirName, n, i, j); // fg.SaveGroupToFiles(outDirName, i, j, _frameGroups.GetLength(0), _frameGroups.GetLength(1)); // fg.FrameGroupBmp.Dispose(); // } // else // fg.MarkFrameGroupAsBlack(); // this.progressModel1.CurValue = i + 1; // int progress1 = ProgressPercentage(progressModel1.CurValue, progressModel1.MinValue, progressModel1.MaxValue); // worker.ReportProgress(progress1); // if (worker.CancellationPending == true) // { // e.Cancel = true; // break; // } // // Perform a time consuming operation and report progress. // Thread.Sleep(20); // //n++; // } // this.progressModel2.CurValue = j + 1; // int progress2 = ProgressPercentage(progressModel2.CurValue, progressModel2.MinValue, progressModel2.MaxValue); // worker.ReportProgress(progress2); // if (worker.CancellationPending == true) // { // e.Cancel = true; // break; // } // Thread.Sleep(20); // } // } //} //private void backgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e) //{ // int nFramesHor = Convert.ToInt32(_projectObj.HologramWidth / _projectObj.FrameWidth); // int nFramesVert = Convert.ToInt32(_projectObj.HologramHeight / _projectObj.FrameHeight); // string labelInd = "Save Frames " + Convert.ToString(_frameGroups.GetLength(0)) + "x" + Convert.ToString(_frameGroups.GetLength(1)); // int progress1 = ProgressPercentage(progressModel1.CurValue, progressModel1.MinValue, progressModel1.MaxValue); // int progress2 = ProgressPercentage(progressModel2.CurValue, progressModel2.MinValue, progressModel2.MaxValue); // // Change the value of the ProgressBar to the BackgroundWorker progress. // progressBar3.Value = progress1; // e.ProgressPercentage; // progressBar3.Maximum = 100; // progressBar3.Minimum = 0; // progressBar4.Value = progress2; // progressBar4.Maximum = 100; // progressBar4.Minimum = 0; // lblSaveFrames.Text = labelInd + " - " + Convert.ToString(this.progressModel1.CurValue) + "x" + Convert.ToString(this.progressModel2.CurValue); // lblSaveFrames.Refresh(); //} //private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) //{ // if (e.Cancelled == true) // { // lblSaveFrames.Text = "Canceled!"; // } // else if (e.Error != null) // { // lblSaveFrames.Text = "Error: " + e.Error.Message; // } // else // { // lblSaveFrames.Text = "Done!"; // GenerateIniFile(); // } //} private void numUpDownStep_Validating(object sender, CancelEventArgs e) { errorProvider1.SetError(numUpDownStep, ""); if (numUpDownStep.Text == "") errorProvider1.SetError(numUpDownStep, "Step must not be empty."); } private void numUpDownRadius_Validating(object sender, CancelEventArgs e) { errorProvider1.SetError(txtLayerName, ""); if (numUpDownRadius.Text == "") errorProvider1.SetError(numUpDownRadius, "Radius must not be empty."); } private void txtFullMask_Validating(object sender, CancelEventArgs e) { errorProvider1.SetError(txtFullMask, ""); } private void txtTileMask_Validating(object sender, CancelEventArgs e) { // errorProvider1.SetError(txtTileMask, ""); } private void numFrameGroupWidth_Validating(object sender, CancelEventArgs e) { if (numFrameGroupWidth.Value < 1) numFrameGroupWidth.Value = 1; if (numFrameGroupWidth.Value > 20) numFrameGroupWidth.Value = 20; } private void numFrameGroupHeight_Validating(object sender, CancelEventArgs e) { if (numFrameGroupHeight.Value < 1) numFrameGroupHeight.Value = 1; if (numFrameGroupHeight.Value > 20) numFrameGroupHeight.Value = 20; } private void numRowStart_Validating(object sender, CancelEventArgs e) { if (numRowStart.Value < 0) numRowStart.Value = 0; } private void numRowEnd_Validating(object sender, CancelEventArgs e) { if (numRowEnd.Value < 0) numRowEnd.Value = 0; int nRows = Convert.ToInt16(ProjectObj.HologramHeight / (ProjectObj.FrameHeight * FrameGroupHeight)); numRowEnd.Value = nRows; } private void numFrameGroupHeight_ValueChanged(object sender, EventArgs e) { CancelEventArgs ee = new CancelEventArgs(); numRowEnd_Validating(sender, ee); } private void numUpDownLayerW_Validating(object sender, CancelEventArgs e) { } private void numUpDownLayerH_Validating(object sender, CancelEventArgs e) { } private void numUpDownLayerLeft_Validating(object sender, CancelEventArgs e) { } private void numUpDownLayerTop_Validating(object sender, CancelEventArgs e) { } } }