BigLitho/Large.Lito.Database/Make3_Treko3D/ChildForms/frmChildTreko3D.cs

1097 lines
38 KiB
C#

using System;
using System.IO;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Threading;
using System.Collections.Generic;
using Treko3D;
using Frames;
using Projects;
using ClassLibrary;
using ControlLibrary;
namespace ChildForms
{
public partial class FrmChildTreko3D : Form
{
#region Local Variables
Treko3DControl _treko3DControl;
ProjectControl _projectControl;
Treko3D.Treko3D _treko3DObj;
Project _projectObj;
Layer _layerObj;
Frames.FrameGroup[,] _frameGroups;
int _mmToPixelsCoeff;
int _mmToPixelsCoeffPreview = 20;
//Strip[] _strips;
string _outDirName;
private ProgressModel progressModel1;
private ProgressModel progressModel2;
int angPreview = 0;
int deltaAng = 10;
int parallaxAng = 0;
Graphics gPreview;
#endregion
#region Get/Set
public int MmToPixelsCoeff
{
get
{
if (_mmToPixelsCoeff == 0)
_mmToPixelsCoeff = Convert.ToInt32(_projectObj.ResolutionX / _projectObj.FrameWidth);
return _mmToPixelsCoeff;
}
set { _mmToPixelsCoeff = value; }
}
public string OutDirName
{
get { return _outDirName; }
set { _outDirName = value; }
}
public Layer LayerObj
{
get { return _layerObj; }
set { _layerObj = value; }
}
public FrmChildTreko3D()
{
InitializeComponent();
this.progressModel1 = new ProgressModel();
this.progressModel2 = new ProgressModel();
}
public Project ProjectObj
{
get { return _projectObj; }
set { _projectObj = 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 Treko3DControl Treko3DControl
{
get { return _treko3DControl; }
set { _treko3DControl = value; }
}
public ProjectControl ProjectControl
{
get { return _projectControl; }
set { _projectControl = value; }
}
#endregion
public void RefreshChildForm()
{
FrameGroupHeight = 1;
FrameGroupWidth = 1;
RowStart = 0;
RowEnd = Convert.ToInt16(ProjectObj.HologramHeight / ProjectObj.FrameHeight);
}
public void GenerateAndSaveStrips(Treko3D.Treko3D treko3DObj, Project projectObj) //string[] rakurseFiles)
{
_treko3DObj = treko3DObj;
_projectObj = projectObj;
//Strip strip = new Strip(rakurseFiles, Width, Height);
string dirName = Path.GetDirectoryName(treko3DObj.RakurseFiles[0]);
string outDirName = projectObj.OutPath; // dirName + "\\TEST\\";
if (!Directory.Exists(outDirName))
{
Directory.CreateDirectory(outDirName);
}
_outDirName = outDirName;
treko3DObj.GenerateAndSaveStrips(dirName, outDirName);
}
public void DrawOnPictureBox(Strip strip)
{
ddPanBoxTreko3D.Refresh();
_treko3DObj.CreateImageTreko3D();
ddPanBoxTreko3D.Image = _treko3DObj.ImgDisplayTreko3D;
//_treko3DObj.CreateImageVoxel();
//ddPanBoxVoxel.Refresh();
//ddPanBoxVoxel.Image = _treko3DObj.ImgDisplayVoxel;
strip.DrawOnPictureBox(_treko3DObj.ImgDisplayTreko3D, MmToPixelsCoeff);
}
public void Draw_HologramBorder(decimal nx, decimal ny)
{
Graphics g = Graphics.FromImage(ddPanBoxTreko3D.Image);
ddPanBoxTreko3D.ClearImage(g);
Color col = Color.FromArgb(255, 255, 0, 0);
var Pn = new Pen(col, 3);
g.DrawRectangle(Pn, 0, 0, (float)_projectObj.HologramWidth * _mmToPixelsCoeffPreview, (float)_projectObj.HologramHeight * _mmToPixelsCoeffPreview);
Color col1 = Color.FromArgb(255, 255, 255, 0);
var Pn1 = new Pen(col1, 1);
g.DrawRectangle(Pn1, 0, 0, (float)0.2 * _mmToPixelsCoeffPreview, (float)0.15 * _mmToPixelsCoeffPreview);
Color col2 = Color.FromArgb(255, 0, 255, 0);
var Pn2 = new Pen(col2, 1);
g.DrawRectangle(Pn2, 0, 0, (float)0.2 * _mmToPixelsCoeffPreview * Convert.ToInt32(nx), (float)0.15 * _mmToPixelsCoeffPreview * Convert.ToInt32(ny));
g.Dispose();
}
public void DrawImage()
{
if (ddPanBoxTreko3D.Image == null)
{
_treko3DObj.CreateImageTreko3D();
ddPanBoxTreko3D.Image = _treko3DObj.ImgDisplayTreko3D;
gPreview = Graphics.FromImage(ddPanBoxTreko3D.Image); //!!!!Nick
timer1.Interval = 100; //!!!!Nick
timer1.Enabled = true; //!!!!Nick
}
else
{
Graphics g = Graphics.FromImage(ddPanBoxTreko3D.Image);
ddPanBoxTreko3D.ClearImage(g);
g.Dispose();
}
Draw_HologramBorder(numFrameGroupWidth.Value, numFrameGroupHeight.Value);
_treko3DObj.DrawOnImage(_treko3DObj.ImgDisplayTreko3D, _mmToPixelsCoeffPreview);
ddPanBoxTreko3D.Refresh();
}
private void btnDraw_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
DrawImage();
//if (ddPanBoxTreko3D.Image == null)
//{
// _treko3DObj.CreateImageTreko3D();
// ddPanBoxTreko3D.Image = _treko3DObj.ImgDisplayTreko3D;
//} else
//{
// Graphics g = Graphics.FromImage(ddPanBoxTreko3D.Image);
// ddPanBoxTreko3D.ClearImage(g);
// g.Dispose();
//}
//_treko3DObj.DrawOnImage(_treko3DObj.ImgDisplayTreko3D, MmToPixelsCoeff);
//ddPanBoxTreko3D.Refresh();
}
public void GenerateFrames()
{
generateFrameGroups();
}
private void clearProgressInfo()
{
lblGenFrames.Text = "";
//lblSaveFrames.Text = "";
progressBar1.Value = 0;
progressBar2.Value = 0;
//progressBar3.Value = 0;
//progressBar4.Value = 0;
}
private void clearErrors()
{
errorProvider1.SetError(numUpDownStep, "");
errorProvider1.SetError(numUpDownRadius, "");
}
private bool btnRunValidating()
{
bool success = true;
clearErrors();
CancelEventArgs ee = null;
numFrameGroupWidth_Validating(this, ee);
numFrameGroupHeight_Validating(this, ee);
numRowStart_Validating(this, ee);
numRowEnd_Validating(this, ee);
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();
}
}
private void btnGenerateFrames_Click(object sender, EventArgs e)
{
clearProgressInfo();
if (btnRunValidating() == false)
return;
Treko3DControl.SaveData();
_treko3DObj = Treko3DControl.treko3DObj;
launchBackgroundWorker();
}
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;
// add one more frame group for bricks construction
_frameGroups = new FrameGroup[nFramesHor / nFramesInGroupHor + 1, nFramesVert / nFramesInGroupVert + 1];
string outDirName = _projectObj.OutPath; // dirName + "\\TEST\\";
for (int j = (int)numRowStart.Value; j <= (int)numRowEnd.Value /*_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, nFramesInGroupHor, nFramesInGroupVert, i, j);
FrameGroup fg = _frameGroups[i, j];
//_frameGroups[i, j].FillByIntersectVoxelArcs(_treko3D.Strips);
fg.FillByIntersectVoxelArcs(_treko3DObj);
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;
}
if (j >= numRowEnd.Value)
{
e.Result = "Done";
break;
}
// 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)
{
lblGenFrames.Text = "Error: " + e.Error.Message;
}
else
{
lblGenFrames.Text = "Done!";
GenerateIniFile();
}
}
//private void btnGenerateFrames_Click(object sender, EventArgs e)
//{
// clearProgressInfo();
// if (btnRunValidating() == false)
// return;
// 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 = ProjectControl.RegisterDefaultProject();
// _projectObj = ProjectControl.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();
// //treko3DObj.GenerateAndSaveStrips(dirName, outDirName);
// 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 ddPanBoxTreko3D_Click(object sender, EventArgs e)
{
MouseEventArgs me = (MouseEventArgs)e;
Point coordinates = me.Location;
Rectangle rect = ddPanBoxTreko3D.DrawRect;
int xPix = rect.X + coordinates.X;
int yPix = rect.Y + coordinates.Y;
txtBoxX.Text = xPix.ToString();
txtBoxY.Text = yPix.ToString();
}
private void ddPanBoxTreko3D_MouseMove(object sender, MouseEventArgs e)
{
//this.Cursor = new Cursor(Cursor.Current.Handle);
//int xCoordinate = Cursor.Position.X;
//int yCoordinate = Cursor.Position.Y;
int xCoordinate = e.X;
int yCoordinate = e.Y;
Rectangle rect = ddPanBoxTreko3D.DrawRect;
int xPix = rect.X + xCoordinate;
int yPix = rect.Y + yCoordinate;
txtBoxX.Text = xPix.ToString();
txtBoxY.Text = yPix.ToString();
txtBoxX.Refresh();
txtBoxY.Refresh();
Image img = ddPanBoxTreko3D.Image;
if (img != null)
{
float hRes = img.HorizontalResolution;
float vRes = img.VerticalResolution;
}
}
private void btnNextFrame_Click(object sender, EventArgs e)
{
FrameGroup fGroup = null;
if (_frameGroups == null || _frameGroups.GetLength(1) == 0)
GenerateFrames();
int sizeX = _frameGroups.GetLength(0);
int sizeY = _frameGroups.GetLength(1);
List<Voxel> voxels;
int startFrameX;
int startFrameY;
ddPanBoxVoxel.Refresh();
if (txtBoxNFrameX.Text == "")
{
startFrameX = 0;
startFrameY = 0;
}
else
{
startFrameX = Convert.ToInt16(txtBoxNFrameX.Text);
startFrameY = Convert.ToInt16(txtBoxNFrameY.Text);
}
fGroup = _frameGroups[0, 0];
Bitmap frameGroupBmp = new Bitmap(fGroup.GrpWidthPix, fGroup.GrpHeightPix);
//fGroup.DrawBorder(frameGroupBmp, _treko3DObj.MmToPixelsCoeff);
ddPanBoxVoxel.Image = frameGroupBmp;
for (int j = 0; j < sizeY; j++)
{
for (int i = 0; i < sizeX; i++)
{
fGroup = _frameGroups[i, j];
//voxels = fGroup.IntersectVoxels;
//if (voxels == null || voxels.Count == 0)
// continue;
// foreach (Voxel voxel in voxels)
// {
// voxel.DrawArcs(frameGroupBmp);
// txtBoxNFrameX.Text = i.ToString();
// txtBoxNFrameY.Text = j.ToString();
// goto End;
// }
}
}
End:
ddPanBoxVoxel.Refresh();
//if (fGroup != null && fGroup.FrameGroupBmp != null)
// fGroup.FrameGroupBmp.Dispose();
}
private void btnSaveBitmapToFile_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
ddPanBoxTreko3D.Image.Save(dialog.FileName, ImageFormat.Jpeg);
}
}
private void btnSaveFrame_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
ddPanBoxVoxel.Image.Save(dialog.FileName, ImageFormat.Tiff);
}
}
private void vResizeImage_ValueChanged(object sender, EventArgs e)
{
txtMmToPixCoeff.Text = ((VScrollBar)sender).Value.ToString();
_mmToPixelsCoeffPreview = ((VScrollBar)sender).Value;
if (timer1.Enabled == false)
DrawImage();
//_treko3DObj.MmToPixelsCoeff = ((VScrollBar)sender).Value;
}
private void btnClear_Click(object sender, EventArgs e)
{
if (ddPanBoxTreko3D.Image != null)
{
Image img = _treko3DObj.ImgDisplayTreko3D;
Graphics g = Graphics.FromImage(img);
Color c = Color.FromArgb(52, 52, 52);
g.Clear(c);
ddPanBoxTreko3D.Refresh();
//ddPanBoxTreko3D.ClearImage();
}
}
public void generateFrameGroups()
{
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);
_frameGroups = new FrameGroup[nFramesHor, nFramesVert];
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(_treko3DObj.Strips);
progressBar1.Maximum = _frameGroups.GetLength(0);
progressBar1.Value = i;
lblGenFrames.Text = labelInd + " - " + Convert.ToString(i) + "x" + Convert.ToString(j);
lblGenFrames.Refresh();
}
progressBar2.Maximum = _frameGroups.GetLength(1);
progressBar2.Value = j;
}
}
//public void SaveFramesToFiles()
//{
// int n = 1;
// string labelInd = "Gen. Frames " + Convert.ToString(_frameGroups.GetLength(0)) + "x" + Convert.ToString(_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.Maximum = _frameGroups.GetLength(0);
// progressBar3.Value = i;
// label10.Text = labelInd + " - " + Convert.ToString(i) + "x" + Convert.ToString(j);
// label10.Refresh();
// }
// progressBar4.Maximum = _frameGroups.GetLength(1);
// progressBar4.Value = j;
// }
//}
//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 GenerateIniFile()
//{
// string sLine = "";
// int eCount = 0;
// int zCount = 0;
// StreamWriter sw = new StreamWriter(_outDirName + "\\exp.ini");
// int nCols = _frameGroups.GetLength(0);
// int nRows = _frameGroups.GetLength(1);
// 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++)
// {
// FrameGroup fg = _frameGroups[i, j];
// // 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();
//}
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 WriteIniFile(StreamWriter sw, string sLine)
{
try
{
sw.WriteLine(sLine);
}
catch (Exception e)
{
}
finally
{
}
}
//private void BtnSaveFrames_Click(object sender, EventArgs e)
//{
// SaveFramesToFiles();
//}
private void btnGenExpIni_Click(object sender, EventArgs e)
{
GenerateIniFile();
}
private void btnAnimation_Click(object sender, EventArgs e)
{
if (ddPanBoxTreko3D.Image == null)
{
ddPanBoxTreko3D.Image = _treko3DObj.ImgDisplayTreko3D;
//ddPanBoxTreko3D.ClearImage();
}
//gPreview = Graphics.FromImage(ddPanBoxTreko3D.Image);
ddPanBoxTreko3D.ClearImage(gPreview);
ddPanBoxTreko3D.Refresh();
timer1.Interval = 100;
timer1.Enabled = true;
}
public void AnimateImage(int parallaxAng)
{
ddPanBoxTreko3D.ClearImage(gPreview);
Draw_HologramBorder(numFrameGroupWidth.Value, numFrameGroupHeight.Value);
_treko3DObj.DrawAnimation(_treko3DObj.ImgDisplayTreko3D, angPreview, parallaxAng, _mmToPixelsCoeffPreview);
ddPanBoxTreko3D.Refresh();
}
private void btMinus_Click(object sender, EventArgs e)
{
angPreview--; //!!!!Nick
labelPrevAng.Text = "ParallaxAng - " + Convert.ToString(angPreview);
labelPrevAng.Refresh();
AnimateImage(parallaxAng);
}
private void btPlus_Click(object sender, EventArgs e)
{
angPreview++; //!!!!Nick
labelPrevAng.Text = "ParallaxAng - " + Convert.ToString(angPreview);
labelPrevAng.Refresh();
AnimateImage(parallaxAng);
}
private void TrackBarAngPrev_Scroll(object sender, EventArgs e)
{
angPreview = TrackBarAngPrev.Value; //!!!!Nick
labelPrevAng.Text = "ParallaxAng - " + Convert.ToString(angPreview);
labelPrevAng.Refresh();
AnimateImage(parallaxAng);
//Preview(angPreview);
}
private void timer1_Tick(object sender, EventArgs e)
{
angPreview += deltaAng;
if (angPreview < 0)
{
angPreview = 0;
deltaAng = -deltaAng;
}
if (angPreview > 159)
{
angPreview = 159;
deltaAng = -deltaAng;
}
labelPrevAng.Text = "ParallaxAng - " + Convert.ToString(angPreview);
labelPrevAng.Refresh();
TrackBarAngPrev.Value = angPreview;
AnimateImage(parallaxAng);
}
private void chckTimer_CheckedChanged(object sender, EventArgs e)
{
timer1.Enabled = chckTimer.Checked;
}
private void numUpDownParallax_ValueChanged(object sender, EventArgs e)
{
parallaxAng = Convert.ToInt32(numericUpDown1.Value);
}
private void numUpDownSpeed_ValueChanged(object sender, EventArgs e)
{
if (deltaAng >= 0) deltaAng = Convert.ToInt32(numUpDownSpeed.Value);
if (deltaAng < 0) deltaAng = Convert.ToInt32(numUpDownSpeed.Value) * -1;
}
private void numUpDownStep_ValueChanged(object sender, EventArgs e)
{
DrawImage();
}
private void numUpDownRadius_ValueChanged(object sender, EventArgs e)
{
DrawImage();
}
private void numFrameGroupWidth_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (numFrameGroupWidth.Value < 1)
numFrameGroupWidth.Value = 1;
if (numFrameGroupWidth.Value > 20)
numFrameGroupWidth.Value = 20;
}
private void numFrameGroupHeight_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (numFrameGroupHeight.Value < 1)
numFrameGroupHeight.Value = 1;
if (numFrameGroupHeight.Value > 20)
numFrameGroupHeight.Value = 20;
}
private void numRowStart_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (numRowStart.Value < 0)
numRowStart.Value = 0;
}
private void numRowEnd_Validating(object sender, System.ComponentModel.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 btnCancel_Click(object sender, EventArgs e)
{
this.Visible = false;
backgroundWorker1.CancelAsync();
}
private void numFrameGroupWidth_ValueChanged(object sender, EventArgs e)
{
}
}
}