BigLitho/Large.Lito.Database/Make3_Treko3D/ControlLibrary/Treko3DControl.cs

1943 lines
72 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.IO;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using Treko3D;
using Projects;
using Data.BusinessService;
using Data.DataModel;
using Frames;
using ClassLibrary;
namespace ControlLibrary
{
public partial class Treko3DControl : UserControl
{
#region Local Variables
Project _projectObj;
Layer _layerObj;
ColorProfileControl _colorProfileControl;
ColorProfile _colorProfileObj;
private ILayerService layerService;
private LayerModel layerModel;
private ColorProfileModel _colorProfileModel;
private ColorProfileService colorProfileService;
private ProgressModel progressModel1;
private ProgressModel progressModel2;
private Treko3D.Treko3D _treko3D;
Frames.FrameGroup[,] _frameGroups;
private string[] _rakurseFiles;
private bool _editMode;
private int _arcWidth;
private Bitmap _thumbnail;
#endregion
/// <summary>
/// Variable to store error message
/// </summary>
private string _errorMessage;
// Delegate declaration
public delegate void OkClicked(Treko3DControl sender, EventArgs e);
public event OkClicked OnOkClicked;
public delegate void PreviewClicked(Treko3DControl sender, EventArgs e);
public event PreviewClicked OnPreviewClicked;
public delegate void ColorProfileClicked(Treko3DControl sender, EventArgs e);
public event ColorProfileClicked OnColorProfileClicked;
#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 int ProjectId
{
get;
set;
}
public string TechnologyName
{
get;
set;
}
public string SourceFilePath
{
get { return txtSourceFilePath.Text; }
set { txtSourceFilePath.Text = value; }
}
public string SourceFileSelected
{
get { return txtNFilesSelected.Text; }
set { txtNFilesSelected.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 Project ProjectObj
{
get { return _projectObj; }
set { _projectObj = value; }
}
public Layer LayerObj
{
get { return _layerObj; }
set { _layerObj = value; }
}
public ColorProfile ColorProfileObj
{
get { return _colorProfileObj; }
set { _colorProfileObj = value; }
}
public ColorProfileModel ColorProfileModel
{
get { return _colorProfileModel; }
set { _colorProfileModel = value; }
}
public ColorProfileControl ColorProfileControl
{
get { return _colorProfileControl; }
set { _colorProfileControl = value; }
}
public string Resolution
{
set { this.lblResolution.Text = value; }
}
public Treko3D.Treko3D Treko3D
{
get { return _treko3D; }
set { _treko3D = value; }
}
public PictureBox pbxSourceImage
{
get
{
Control[] cnt = this.ParentForm.Controls.Find("picBoxSourceImage", true);
return (PictureBox)cnt[0];
}
}
public Treko3D.Treko3D treko3DObj
{
get
{
return _treko3D;
}
}
public ProjectControl newProjectControl
{
get
{
Control[] cnt = this.ParentForm.Controls.Find("newProjectControl1", true);
return (ProjectControl)cnt[0];
}
}
//public ColorProfileControl newColorProfileControl
//{
// get
// {
// return ((frmChildColorProfile)this.ParentForm).colorProfileControl;
// //return (ColorProfileControl)cnt[0];
// }
//}
public string[] RakurseFiles
{
get
{
return _rakurseFiles;
}
}
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 Bitmap Thumbnail
{
get { return _thumbnail; }
set { _thumbnail = value; }
}
#endregion
public Treko3DControl()
{
InitializeComponent();
UpdateBtnOk();
UpdateBtnCancel();
UpdateBtnReset();
UpdateBtnSaveAsDefault();
_treko3D = new Treko3D.Treko3D();
this.layerService = new LayerService();
this.colorProfileService = new ColorProfileService();
this.progressModel1 = new ProgressModel();
this.progressModel2 = new ProgressModel();
numUpDownRadius.Value = (decimal)_treko3D.RadiusMax;
//numUpDownTrekWidth.Value = (decimal)_treko3D.ArcWidth;
numUpDownStep.Value = (decimal)_treko3D.Step;
this.LoadTreko3DByNameDefault();
this._layerObj = new Layer(layerModel);
this.LoadColorProfile(_layerObj.Id);
string path = txtSourceFilePath.Text;
_rakurseFiles = Helper.LoadRakurseFiles(path);
if (_rakurseFiles != null)
txtNFilesSelected.Text = _rakurseFiles.Length.ToString();
}
public void RefreshControl(Layer layerObj)
{
clearProgressInfo();
_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;
//LoadRakurseFiles();
string path = txtSourceFilePath.Text;
_rakurseFiles = Helper.LoadRakurseFiles(path);
if (_rakurseFiles != null)
txtNFilesSelected.Text = _rakurseFiles.Length.ToString();
FrameGroupHeight = 1;
FrameGroupWidth = 1;
RowStart = 0;
RowEnd = Convert.ToInt16(ProjectObj.HologramHeight / ProjectObj.FrameHeight);
int imgWidth = 50;
int imgHeight = 50;
if (_rakurseFiles != null)
{
_thumbnail = ImageProcessing.CreateThumbnail(_rakurseFiles[0], 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);
}
/// <summary>
/// Method to show general error message on any system level exception
/// </summary>
private void ShowErrorMessage(Exception ex)
{
MessageBox.Show(
ex.Message,
//Resources.System_Error_Message,
Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
/// <summary>
/// Validates registration input
/// </summary>
/// <returns>true or false</returns>
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;
}
return true; // this.errorMessage != string.Empty ? false : true;
}
public bool RegisterNewTreko3DLayer()
{
var success = false;
try
{
// Check if the validation passes
if (this.ValidateRegistration())
{
//Treko.Treko trekoObj = trekoControl1.trekoObj;
//Project projectObj = projectControl.Project;
// Create Layer and add to Project
layerModel.LayerName = LayerName;
layerModel.OpticalSchema = OpticalSchema;
layerModel.TechnologyName = "Treko3D";
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 = "";
success = layerService.RegisterLayer(layerModel);
//projectControl.LoadProject(projectObj.ProjectId);
//_projectObj = projectControl.Project;
// 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_Layer_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;
}
/// <summary>
/// Validates update data
/// </summary>
/// <returns>true or false</returns>
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 UpdateTreko3DLayer()
{
var success = false;
try
{
if (this.ValidateUpdate())
{
LayerModel layerModel = new LayerModel()
{
Id = _layerObj.Id,
LayerName = this.LayerName,
OpticalSchema = this.OpticalSchema,
TechnologyName = "Treko3D",
ProjectId = this.ProjectId,
TraceProfile = _layerObj.TraceProfile,
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 = "",
};
success = 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,
//};
this._colorProfileModel.Id = 0;
this._colorProfileModel.LayerId = LayerObj.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;
}
private void BtnOk_Click(object sender, EventArgs e)
{
clearProgressInfo();
System.ComponentModel.CancelEventArgs ee = null;
clearErrors();
txtLayerName_Validating(this, ee);
if (errorProvider1.GetError(txtLayerName) != "")
return;
txtSourceFilePath_Validating(this, ee);
if (errorProvider1.GetError(txtSourceFilePath) != "")
return;
numUpDownStep_Validating(this, ee);
if (errorProvider1.GetError(numUpDownStep) != "")
return;
numUpDownRadius_Validating(this, ee);
if (errorProvider1.GetError(numUpDownRadius) != "")
return;
txtFullMask_Validating(this, ee);
if (errorProvider1.GetError(txtFullMask) != "")
return;
//txtTileMask_Validating(this, ee);
//if (errorProvider1.GetError(txtTileMask) != "")
// return;
_treko3D.VoxelWidthPix = 32; // Voxel size is variable. Depends on size of arcs.
_treko3D.VoxelHeightPix = 32;
_treko3D.RakurseFiles = RakurseFiles; // Array of names of rakurse files
if (RakurseFiles == null)
_treko3D.NRakurses = 0;
else
_treko3D.NRakurses = RakurseFiles.Length;
this.Visible = false;
OnOkClicked?.Invoke(this, EventArgs.Empty);
}
private void BtnCancel_Click(object sender, EventArgs e)
{
Control[] cnt = this.ParentForm.Controls.Find("splitContainer1", true);
SplitContainer splitContainer = (SplitContainer)cnt[0];
if (splitContainer.Panel1Collapsed == true)
splitContainer.Panel1Collapsed = false;
else
splitContainer.Panel1Collapsed = true;
backgroundWorker1.CancelAsync();
//backgroundWorker2.CancelAsync();
this.Visible = false;
}
public void WriteIniFile(StreamWriter sw, string sLine)
{
try
{
sw.WriteLine(sLine);
}
catch (Exception e)
{
}
finally
{
}
}
//public void generateFrameGroups()
//{
// int nFramesHor = Convert.ToInt32(_projectObj.HologramWidth / _projectObj.FrameWidth);
// int nFramesVert = Convert.ToInt32(_projectObj.HologramHeight / _projectObj.FrameHeight);
// _frameGroups = new FrameGroup[nFramesHor, nFramesVert];
// //this.progressModel1.MaxValue = _frameGroups.GetLength(0);
// //this.progressModel1.MinValue = 0;
// //this.progressModel2.MaxValue = _frameGroups.GetLength(1);
// //this.progressModel2.MinValue = 0;
// 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].FillByIntersectVoxelArcs(_treko3D.Strips);
// this.progressModel1.CurValue = i;
// }
// this.progressModel2.CurValue = j;
// }
//}
//public void SaveFramesToFiles()
//{
// string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\";
// int n = 1;
// string labelInd = "Save Frames " + Convert.ToString(_frameGroups.GetLength(0)) + "x" + Convert.ToString(_frameGroups.GetLength(1));
// progressBar3.Maximum = _frameGroups.GetLength(0);
// progressBar4.Maximum = _frameGroups.GetLength(1);
// 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.IntersectRakurseArcs != null && fg.IntersectRakurseArcs.Count > 0)
// {
// fg.DrawBitmapByRakurseArcs(_layerObj.TraceProfile);
// //fg.SaveGroupToFiles(_outDirName, n, i, j);
// fg.SaveGroupToFiles(outDirName, n);
// fg.FrameGroupBmp.Dispose();
// }
// n++;
// progressBar3.Value = i;
// lblSaveFrames.Text = labelInd + " - " + Convert.ToString(i) + "x" + Convert.ToString(j);
// lblSaveFrames.Refresh();
// }
// progressBar4.Value = j;
// }
//}
private Frame GetFrame(int nCol, int nRow, int nFramesHor, int nFramesVert)
{
//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];
if (fg == null) // is case when we generate frame groups in limited lines (for ex from 0 to 1)
{
Frame fr1 = new Frame(0, 0, 0, 0);
fr1.IsBlack = true;
return fr1;
}
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);
FrameGroup notNullFg = null;
foreach (FrameGroup fg in _frameGroups)
{
if (fg != null)
{
notNullFg = fg;
break;
}
}
int nCols = nGroupCols * notNullFg.NFramesHor;
int nRows = nGroupRows * notNullFg.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, notNullFg.NFramesHor, notNullFg.NFramesVert);
//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;
}
}
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 LoadTreko3DByNameDefault()
{
string layerName = Resources.Default_Layer_Name;
string technologyName = "Treko3D";
DataRow dataRow = this.layerService.GetLayerByNameTechnology(layerName, technologyName);
// Assign the values to the model
this.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);
//numUpDownTrekWidth.Value = Convert.ToDecimal(layerModel.ArcWidth);
txtSourceFilePath.Text = layerModel.SourceFilePath.ToString();
string path = txtSourceFilePath.Text;
_rakurseFiles = Helper.LoadRakurseFiles(path);
if (_rakurseFiles != null)
txtNFilesSelected.Text = _rakurseFiles.Length.ToString();
//LoadRakurseFiles();
}
private bool UpdateTreko3DDefault(LayerModel layerModel)
{
var success = false;
//string layerName = "dddeeefffaaauuulllttt";
try
{
if (this.ValidateUpdate())
{
//cmbResolution_SelectedIndexChanged(this, EventArgs.Empty);
//DataRow dataRow = this.layerService.GetLayerByNameTechnology(layerName, "Treko3D");
//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(),
// RadiusMax = Convert.ToSingle(dataRow["RadiusMax"]),
// ArcWidth = Convert.ToInt16(dataRow["ArcWidth"]),
// Step = Convert.ToSingle(dataRow["Step"]),
//};
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(txtSourceFilePath, "");
errorProvider1.SetError(numUpDownStep, "");
errorProvider1.SetError(numUpDownRadius, "");
errorProvider1.SetError(txtFullMask, "");
//errorProvider1.SetError(txtTileMask, "");
}
private void btnSaveAsDefault_Click(object sender, EventArgs e)
{
clearProgressInfo();
System.ComponentModel.CancelEventArgs ee = null;
clearErrors();
//txtLayerName_Validating(this, ee);
//if (errorProvider1.GetError(txtLayerName) != "")
// return;
//txtSourceFilePath_Validating(this, ee);
//if (errorProvider1.GetError(txtSourceFilePath) != "")
// return;
numUpDownStep_Validating(this, ee);
if (errorProvider1.GetError(numUpDownStep) != "")
return;
numUpDownRadius_Validating(this, ee);
if (errorProvider1.GetError(numUpDownRadius) != "")
return;
//txtFullMask_Validating(this, ee);
//if (errorProvider1.GetError(txtFullMask) != "")
// return;
//txtTileMask_Validating(this, ee);
//if (errorProvider1.GetError(txtTileMask) != "")
// return;
string layerName = Resources.Default_Layer_Name;
try
{
DataRow dataRow = this.layerService.GetLayerByNameTechnology(layerName, "Treko3D");
LayerModel layerModel = new LayerModel()
{
Id = Convert.ToInt16(dataRow["Id"]),
Order = 0,
LayerName = layerName,
OpticalSchema = this.OpticalSchema,
ProjectId = Convert.ToInt16(dataRow["ProjectId"]),
TechnologyName = "Treko3D",
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 = "",
};
UpdateTreko3DDefault(layerModel);
}
catch (Exception ex)
{
this.ShowErrorMessage(ex);
}
//this.Visible = false;
//OnOkClicked?.Invoke(this, EventArgs.Empty);
}
//private string FoundPicExt(string[] filesname)
//{
// string ext = "";
// for (int i = 0; i < filesname.Length; i++)
// {
// if (Path.GetExtension(filesname[i]) == ".bmp" || Path.GetExtension(filesname[i]) == ".png" || Path.GetExtension(filesname[i]) == ".jpg" || Path.GetExtension(filesname[i]) == ".tif")
// {
// ext = Path.GetExtension(filesname[i]);
// return ext;
// }
// }
// return ext;
//}
//private void LoadRakurseFiles()
//{
// string path = txtSourceFilePath.Text;
// _rakurseFiles = null;
// try
// {
// // get the file attributes for file or directory
// FileAttributes attr = File.GetAttributes(path);
// if (attr.HasFlag(FileAttributes.Directory))
// {
// string[] filesname = Directory.GetFiles(path); //!!!!Nick
// string ext = FoundPicExt(filesname); //!!!!Nick
// ext = "*" + ext; //Path.GetExtension(filesname[2]); //!!!!Nick
// var files = Directory.GetFiles(path, ext).ToList(); //!!!!Nick
// //var files = Directory.GetFiles(path, "*.tif").ToList(); //.OrderBy(f => f.CreationTime);
// files.Sort();
// txtNFilesSelected.Text = files.Count.ToString();
// _rakurseFiles = new string[files.Count];
// files.CopyTo(_rakurseFiles);
// }
// }
// catch (Exception ex)
// {
// //this.ShowErrorMessage(ex);
// }
//}
private string OpenDlg()
{
string selectedFolder = "";
using (var fbd = new FileFolderDialog())
{
fbd.Dialog.Title = "Open (Treko3D - layer)"; //!!!!Nick
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
string path = fbd.SelectedPath;
// get the file attributes for file or directory
FileAttributes attr = File.GetAttributes(path);
if (attr.HasFlag(FileAttributes.Directory))
selectedFolder = fbd.SelectedPath;
else
selectedFolder = Path.GetDirectoryName(path);
string[] filesname = Directory.GetFiles(selectedFolder); //!!!!Nick
string ext = Helper.FoundPicExt(filesname); //!!!!Nick
ext = "*" + ext; //!!!!Nick
var files = Directory.GetFiles(selectedFolder, ext).ToList(); //!!!!Nick
//var files = Directory.GetFiles(selectedFolder, "*.tif").ToList(); //.OrderBy(f => f.CreationTime);
//var files = Directory.GetFiles(selectedFolder, "*.*").Where(str => str.EndsWith(".tif") || str.EndsWith(".png")).ToList();
files.Sort();
fbd.Dispose();
txtNFilesSelected.Text = files.Count.ToString();
_rakurseFiles = new string[files.Count];
files.CopyTo(_rakurseFiles);
}
}
return selectedFolder;
}
private void btnOpenImage_Click(object sender, EventArgs e)
{
string folderPath = OpenDlg();
txtSourceFilePath.Text = folderPath;
System.ComponentModel.CancelEventArgs ea = null;
txtSourceFilePath_Validating(this, ea);
int imgWidth = 50;
int imgHeight = 50;
_thumbnail = ImageProcessing.CreateThumbnail(_rakurseFiles[0], imgWidth, imgHeight);
picBoxThumbnail.BackgroundImage = _thumbnail;
picBoxThumbnail.Invalidate();
//OpenFileDialog open_dialog = new OpenFileDialog(); //создание диалогового окна для выбора файла
//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);
// pbx.Size = image.Size;
// pbx.Image = image;
// //ImageConverter cnv = new ImageConverter();
// //var myArray = (byte[])new ImageConverter().ConvertTo(image, typeof(byte[]));
// //MemoryStream ms = new MemoryStream();
// treko3D.Pixels = new int[image.Height, image.Width];
// for (int y = 0; y < image.Height; y++)
// for (int x = 0; x < image.Width; x++)
// {
// treko3D.Pixels[y, x] = (int)(image.GetPixel(x, y).ToArgb());
// //pixel[y, x] = (UInt32)(image.GetPixel(x, y).ToArgb());
// }
// //LayerH = LayerW * image.Height / image.Width;
// treko3D.SourceImage = image;
// treko3D.DefPicSize();
// txtSourceFilePath.Text = open_dialog.FileName;
// pbx.Invalidate();
// }
// catch (Exception d)
// {
// DialogResult rezult = MessageBox.Show(d.Message,
// "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
// }
//}
}
private void btnDetalizationPreview_Click(object sender, EventArgs e)
{
_treko3D.VoxelWidthPix = 32; // Voxel size is variable. Depends on size of arcs.
_treko3D.VoxelHeightPix = 32;
_treko3D.RadiusMax = (float)numUpDownRadius.Value; // Given from Control's text box
_treko3D.Step = (float)numUpDownStep.Value; // Width of Hologram in mm / Width of Hologram in pixels (30mm/200pxs=0.15mm)
_treko3D.RakurseFiles = RakurseFiles; // Array of names of rakurse files
_treko3D.NRakurses = RakurseFiles.Length;
System.ComponentModel.CancelEventArgs ea = null;
txtSourceFilePath_Validating(this, ea);
if (errorProvider1.GetError(txtSourceFilePath) != "")
return;
OnPreviewClicked?.Invoke(this, EventArgs.Empty);
}
private void BtnTraceProfile_Click(object sender, EventArgs e)
{
OnColorProfileClicked?.Invoke(this, EventArgs.Empty);
}
private void btnClearSourceFilePath_Click(object sender, EventArgs e)
{
SourceFilePath = "";
SourceFileSelected = "";
}
private void clearProgressInfo()
{
lblGenFrames.Text = "";
//lblSaveFrames.Text = "";
progressBar1.Value = 0;
progressBar2.Value = 0;
//progressBar3.Value = 0;
//progressBar4.Value = 0;
}
private bool btnRunValidating()
{
bool success = true;
clearErrors();
System.ComponentModel.CancelEventArgs ee = null;
txtLayerName_Validating(this, ee);
if (errorProvider1.GetError(txtLayerName) != "")
success = false;
txtSourceFilePath_Validating(this, ee);
if (errorProvider1.GetError(txtSourceFilePath) != "")
success = false;
numUpDownStep_Validating(this, ee);
if (errorProvider1.GetError(numUpDownStep) != "")
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;
numFrameGroupWidth_Validating(this, ee);
numFrameGroupHeight_Validating(this, ee);
numRowStart_Validating(this, ee);
numRowEnd_Validating(this, ee);
return success;
}
public void SaveData()
{
bool success = false;
if (EditMode == true) //control for update project
{
success = UpdateTreko3DLayer();
}
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 = RegisterNewTreko3DLayer();
}
string dirName = this.SourceFilePath;
string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\";
if (outDirName == "" || !Directory.Exists(outDirName))
outDirName = Helper.CreateOutDir(dirName);
if (outDirName == "")
return;
_treko3D.VoxelWidthPix = 32; // Voxel size is variable. Depends on size of arcs.
_treko3D.VoxelHeightPix = 32;
_treko3D.RakurseFiles = RakurseFiles; // Array of names of rakurse files
if (RakurseFiles == null)
_treko3D.NRakurses = 0;
else
_treko3D.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);
}
}
_treko3D.RadiusMax = (float)numUpDownRadius.Value; // Given from Control's text box
_treko3D.Step = (float)numUpDownStep.Value; // Width of Hologram in mm / Width of Hologram in pixels (30mm/200pxs=0.15mm)
_treko3D.ArcWidth = _colorProfileObj.ArcWidth;
_projectObj = newProjectControl.Project;
treko3DObj.LoadRakurseFiles();
}
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();
}
}
private void btnRun_Click(object sender, EventArgs e)
{
clearProgressInfo();
if (btnRunValidating() == false)
return;
SaveData();
launchBackgroundWorker();
//treko3DObj.GenerateAndSaveStrips(dirName, outDirName);
//generateFrameGroups();
//SaveFramesToFiles();
//GenerateIniFile();
}
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);
// Number of frames in group
int nFramesInGroupHor = FrameGroupWidth;
int nFramesInGroupVert = FrameGroupHeight;
int nCols = (int)Math.Round((decimal)nFramesHor / nFramesInGroupHor, MidpointRounding.AwayFromZero) + 1;
int nRows = (int)Math.Round((decimal)nFramesVert / nFramesInGroupVert, MidpointRounding.AwayFromZero) + 1;
// add one more frame group for bricks construction
_frameGroups = new FrameGroup[nCols, nRows];
// add one more frame group for bricks construction
//_frameGroups = new FrameGroup[nFramesHor/nFramesInGroupHor + 1, nFramesVert/nFramesInGroupVert + 1];
string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\";
Directory.CreateDirectory(outDirName + "\\TEST\\"); //!!!!Nick
TraceTotalMemory.ClearTraceFile(outDirName + "\\TEST\\");
TraceTotalMemory.WriteTotalMemory(outDirName + "\\TEST\\", "Treko3DControl, before");
for (int j = (int)numRowStart.Value; j < nRows /*_frameGroups.GetLength(1)*/; j++)
{
for (int i = 0; i < nCols; i++)
{
// in group only one frame for now
_frameGroups[i, j] = new FrameGroup(_projectObj.ResolutionX, _projectObj.ResolutionY, _projectObj.FrameWidth, _projectObj.FrameHeight, nFramesInGroupHor, nFramesInGroupVert, i, j);
//TraceTotalMemory.WriteTotalMemory(outDirName, "Treko3DControl, step 1");
FrameGroup fg = _frameGroups[i, j];
//_frameGroups[i, j].FillByIntersectVoxelArcs(_treko3D.Strips);
fg.FillByIntersectVoxelArcs(_treko3D);
//TraceTotalMemory.WriteTotalMemory(outDirName, "Treko3DControl, step 2");
if (fg.IntersectRakurseArcs != null && fg.IntersectRakurseArcs.Count > 0)
{
fg.DrawBitmapByRakurseArcs(_layerObj.TraceProfile);
//TraceTotalMemory.WriteTotalMemory(outDirName, "Treko3DControl, step 3");
fg.CropIntoImageArray(j);
//TraceTotalMemory.WriteTotalMemory(outDirName, "Treko3DControl, step 4");
//fg.SaveGroupToFiles(_outDirName, n, i, j);
fg.SaveGroupToFiles(outDirName, i, j, _frameGroups.GetLength(0), _frameGroups.GetLength(1));
//TraceTotalMemory.WriteTotalMemory(outDirName, "Treko3DControl, step 5");
fg.FrameGroupBmp.Dispose();
}
else
fg.MarkFrameGroupAsBlack();
fg.Dispose();
fg = null;
this.progressModel1.CurValue = i;
//this.progressModel1.CurValue = i + 1;
//if (i == 27)
// i = 27;
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;
}
if (j >= numRowEnd.Value)
{
e.Result = "Done";
break;
}
TraceTotalMemory.WriteTotalMemory(outDirName + "\\TEST\\", "Treko3DControl, j = " + j);
// Perform a time consuming operation and report progress.
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)
{
int nFramesHor = Convert.ToInt32(_projectObj.HologramWidth / _projectObj.FrameWidth);
int nFramesVert = Convert.ToInt32(_projectObj.HologramHeight / _projectObj.FrameHeight);
int nFramesInGroupHor = FrameGroupWidth;
int nFramesInGroupVert = FrameGroupHeight;
string labelInd = "Error: " + 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();
//lblGenFrames.Text = "Error: " + e.Error.Message;
}
else
{
lblGenFrames.Text = "Done!";
GenerateIniFile();
//if (backgroundWorker2.IsBusy != true)
//{
// // Number of frames in group
// int nFramesInGroupHor = 2;
// int nFramesInGroupVert = 2;
// 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.IntersectRakurseArcs != null && fg.IntersectRakurseArcs.Count > 0)
// {
// fg.DrawBitmapByRakurseArcs(_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 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 txtSourceFilePath_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
errorProvider1.SetError(txtSourceFilePath, "");
if (txtSourceFilePath.Text == "")
{
errorProvider1.SetError(txtSourceFilePath, "Source File Path must not be empty.");
return;
}
if (Helper.IsValidPath(txtSourceFilePath.Text.Trim(), false) == false)
errorProvider1.SetError(txtSourceFilePath, "Source File Path is incorrect.");
//this.LoadRakurseFiles();
string path = txtSourceFilePath.Text;
_rakurseFiles = Helper.LoadRakurseFiles(path);
if (_rakurseFiles != null)
txtNFilesSelected.Text = _rakurseFiles.Length.ToString();
if (_rakurseFiles == null || _rakurseFiles.Length == 0)
errorProvider1.SetError(txtSourceFilePath, "Error Loading Source Files.");
}
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.");
}
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)
{
}
}
}