1967 lines
78 KiB
C#
1967 lines
78 KiB
C#
|
|
namespace Big.Lito.Desktop
|
|
{
|
|
using System;
|
|
using System.IO;
|
|
using System.Data;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Windows.Forms;
|
|
using System.Drawing;
|
|
using Big.Lito.Data.BusinessService;
|
|
using Big.Lito.Data.DataModel;
|
|
using Big.Lito.Data.Enum;
|
|
using Big.Lito.Desktop.Properties;
|
|
using System.Globalization;
|
|
|
|
public partial class Projects : Form
|
|
{
|
|
|
|
#region FIELDS
|
|
|
|
/// <summary>
|
|
/// Interface of ProjectService
|
|
/// </summary>
|
|
private IProjectService projectService;
|
|
private IProgressService progressService;
|
|
private IProcessLevelsService processLevelsService;
|
|
private IFToBIniGenService fToBIniGenService;
|
|
private IHeightmapService heightmapService;
|
|
private ISystemSettingsService systemSettingsService;
|
|
|
|
/// <summary>
|
|
/// Variable to store error message
|
|
/// </summary>
|
|
private string errorMessage;
|
|
|
|
private int projectId;
|
|
|
|
private ProgressModel progressModel;
|
|
private ProcessLevelsModel processLevelsModel;
|
|
private FToBIniGenModel fToBIniGenModel;
|
|
private HeightmapModel heightmapModel;
|
|
private SystemSettingsModel systemSettingsModel;
|
|
public bool license;
|
|
|
|
public string MessageIniGen
|
|
{
|
|
set
|
|
{
|
|
labelMessageIniGen.Text = value;
|
|
}
|
|
}
|
|
|
|
public int ProgressValueIniGen
|
|
{
|
|
set
|
|
{
|
|
progressBarIniGen.Value = value;
|
|
}
|
|
}
|
|
|
|
public int ProgressMaxIniGen
|
|
{
|
|
set
|
|
{
|
|
progressBarIniGen.Maximum = value;
|
|
}
|
|
}
|
|
|
|
public int ProgressMinIniGen
|
|
{
|
|
set
|
|
{
|
|
progressBarIniGen.Minimum = value;
|
|
}
|
|
}
|
|
|
|
public string MessageGifGen
|
|
{
|
|
set
|
|
{
|
|
labelMessageGifGen.Text = value;
|
|
}
|
|
}
|
|
|
|
public int ProgressValueGifGen
|
|
{
|
|
set
|
|
{
|
|
progressBarGifGen.Value = value;
|
|
}
|
|
}
|
|
|
|
public int ProgressMaxGifGen
|
|
{
|
|
set
|
|
{
|
|
progressBarGifGen.Maximum = value;
|
|
}
|
|
}
|
|
|
|
public int ProgressMinGifGen
|
|
{
|
|
set
|
|
{
|
|
progressBarGifGen.Minimum = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public Projects()
|
|
{
|
|
this.InitializeComponent();
|
|
//this.InitializeResourceString();
|
|
//this.InitializeDropDownList();
|
|
this.InitilizeDataGridViewStyle();
|
|
this.projectService = new ProjectService();
|
|
|
|
this.ResetRegistration();
|
|
this.progressService = new ProgressService();
|
|
this.processLevelsService = new ProcessLevelsService();
|
|
this.progressModel = new ProgressModel();
|
|
this.processLevelsModel = new ProcessLevelsModel();
|
|
this.fToBIniGenModel = new FToBIniGenModel();
|
|
this.fToBIniGenService = new FToBIniGenService();
|
|
this.heightmapService = new HeightmapService();
|
|
this.systemSettingsService = new SystemSettingsService();
|
|
this.heightmapModel = new HeightmapModel();
|
|
this.systemSettingsModel = new SystemSettingsModel();
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// To generate the error message
|
|
/// </summary>
|
|
/// <param name="error">error message</param>
|
|
private void AddErrorMessage(string error)
|
|
{
|
|
if (this.errorMessage == string.Empty)
|
|
{
|
|
this.errorMessage = Resources.Error_Message_Header + "\n\n";
|
|
}
|
|
|
|
this.errorMessage += error + "\n";
|
|
}
|
|
|
|
/// <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>
|
|
/// Initializes data grid view style
|
|
/// </summary>
|
|
private void InitilizeDataGridViewStyle()
|
|
{
|
|
// Setting the style of the DataGridView control
|
|
dataGridViewProjects.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 9, FontStyle.Bold, GraphicsUnit.Point);
|
|
dataGridViewProjects.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.ControlDark;
|
|
dataGridViewProjects.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
|
|
dataGridViewProjects.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
|
dataGridViewProjects.DefaultCellStyle.Font = new Font("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Point);
|
|
dataGridViewProjects.DefaultCellStyle.BackColor = Color.Empty;
|
|
dataGridViewProjects.AlternatingRowsDefaultCellStyle.BackColor = SystemColors.Info;
|
|
dataGridViewProjects.CellBorderStyle = DataGridViewCellBorderStyle.Single;
|
|
dataGridViewProjects.GridColor = SystemColors.ControlDarkDark;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method to load data grid view
|
|
/// </summary>
|
|
/// <param name="data">data table</param>
|
|
private void LoadDataGridView(DataTable data)
|
|
{
|
|
// Data grid view column setting
|
|
dataGridViewProjects.DataSource = data;
|
|
dataGridViewProjects.DataMember = data.TableName;
|
|
dataGridViewProjects.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
|
|
dataGridViewProjects.Columns[0].Visible = false;
|
|
dataGridViewProjects.Columns[5].Visible = false;
|
|
dataGridViewProjects.Columns[6].Visible = false;
|
|
dataGridViewProjects.Columns[7].Visible = false;
|
|
dataGridViewProjects.Columns[8].Visible = false;
|
|
dataGridViewProjects.Columns[9].Visible = false;
|
|
dataGridViewProjects.Columns[10].Visible = false;
|
|
dataGridViewProjects.Columns[11].Visible = false;
|
|
dataGridViewProjects.Columns[12].Visible = false;
|
|
dataGridViewProjects.Columns[13].Visible = false;
|
|
dataGridViewProjects.Columns[14].Visible = false;
|
|
dataGridViewProjects.Columns[15].Visible = false;
|
|
dataGridViewProjects.Columns[16].Visible = false;
|
|
dataGridViewProjects.Columns[17].Visible = false;
|
|
dataGridViewProjects.Columns[18].Visible = false;
|
|
dataGridViewProjects.Columns[19].Visible = false;
|
|
dataGridViewProjects.Columns[20].Visible = false;
|
|
dataGridViewProjects.Columns[21].Visible = false;
|
|
dataGridViewProjects.Columns[22].Visible = false;
|
|
//dataGridViewProjects.Columns[23].Visible = false;
|
|
//dataGridViewProjects.Columns[24].Visible = false;
|
|
//dataGridViewProjects.Columns[25].Visible = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method to load data grid view
|
|
/// </summary>
|
|
/// <param name="data">data table</param>
|
|
private void LoadComboBoxView(DataTable data)
|
|
{
|
|
int selectedIndex = cmbProjects.SelectedIndex;
|
|
cmbProjects.DisplayMember = "Project name";
|
|
cmbProjects.DataSource = data;
|
|
cmbProjects.SelectedIndex = selectedIndex;
|
|
//cmbProjects.DataMember = data.TableName;
|
|
//cmbProjects.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
|
|
}
|
|
|
|
private void LoadTextBoxes(DataTable data)
|
|
{
|
|
// Data grid view column setting
|
|
textBoxAuthor.DataBindings.Clear();
|
|
textBoxAuthor.DataBindings.Add("Text", data, "Author");
|
|
textBoxFrameWidth.DataBindings.Clear();
|
|
textBoxFrameWidth.DataBindings.Add("Text", data, "FrameWidth");
|
|
textBoxFrameHeight.DataBindings.Clear();
|
|
textBoxFrameHeight.DataBindings.Add("Text", data, "FrameHeight");
|
|
textBoxResW.DataBindings.Clear();
|
|
textBoxResW.DataBindings.Add("Text", data, "ResW");
|
|
textBoxResH.DataBindings.Clear();
|
|
textBoxResH.DataBindings.Add("Text", data, "ResH");
|
|
textBoxObjName.DataBindings.Clear();
|
|
textBoxObjName.DataBindings.Add("Text", data, "ObjName");
|
|
textBoxCoX.DataBindings.Clear();
|
|
textBoxCoX.DataBindings.Add("Text", data, "CoX");
|
|
textBoxCoY.DataBindings.Clear();
|
|
textBoxCoY.DataBindings.Add("Text", data, "CoY");
|
|
textBoxObjH.DataBindings.Clear();
|
|
textBoxObjH.DataBindings.Add("Text", data, "ObjH");
|
|
textBoxObjW.DataBindings.Clear();
|
|
textBoxObjW.DataBindings.Add("Text", data, "ObjW");
|
|
textBoxNRows.DataBindings.Clear();
|
|
textBoxNRows.DataBindings.Add("Text", data, "NRows");
|
|
textBoxNumberOfLevels.DataBindings.Clear();
|
|
textBoxNumberOfLevels.DataBindings.Add("Text", data, "NRows");
|
|
textBoxNCols.DataBindings.Clear();
|
|
textBoxNCols.DataBindings.Add("Text", data, "NCols");
|
|
textBoxBlenderDir.DataBindings.Clear();
|
|
textBoxBlenderDir.DataBindings.Add("Text", data, "BlenderDir");
|
|
textBoxHomeProjectsDir.DataBindings.Clear();
|
|
textBoxHomeProjectsDir.DataBindings.Add("Text", data, "HomeDir");
|
|
textBoxRepeats.DataBindings.Clear();
|
|
textBoxRepeats.DataBindings.Add("Text", data, "Repeats");
|
|
//trackBarMinLevel.DataBindings.Clear();
|
|
//trackBarMinLevel.DataBindings.Add("Value", data, "HighLevelBrightness");
|
|
textBoxMinLevel.DataBindings.Clear();
|
|
textBoxMinLevel.DataBindings.Add("Text", data, "LowLevelBrightness");
|
|
textBoxMaxLevel.DataBindings.Clear();
|
|
textBoxMaxLevel.DataBindings.Add("Text", data, "HighLevelBrightness");
|
|
textBoxRepTexture.DataBindings.Clear();
|
|
textBoxRepTexture.DataBindings.Add("Text", data, "NSlicesTexture");
|
|
textBoxNLevels.DataBindings.Clear();
|
|
textBoxNLevels.DataBindings.Add("Text", data, "NSlices");
|
|
|
|
//cmbProjects.DataSource = data;
|
|
//cmbProjects.SelectedIndex = 0;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes all dropdown controls in update section
|
|
/// </summary>
|
|
private void InitializeUpdate()
|
|
{
|
|
//cmb2Occupation.DataSource = Enum.GetValues(typeof(Occupation));
|
|
//cmb2MaritalStatus.DataSource = Enum.GetValues(typeof(MaritalStatus));
|
|
//cmb2HealthStatus.DataSource = Enum.GetValues(typeof(HealthStatus));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes resource strings
|
|
/// </summary>
|
|
private void InitializeResourceString()
|
|
{
|
|
// Registeration
|
|
//lblName.Text = Resources.Registration_Name_Label_Text;
|
|
//lblDateOfBirth.Text = Resources.Registration_DateOfBirth_Label_Text;
|
|
//lblOccupation.Text = Resources.Registration_Occupation_Label_Text;
|
|
//lblMaritalStatus.Text = Resources.Registration_MaritalStatus_Label_Text;
|
|
//lblHealthStatus.Text = Resources.Registration_HealthStatus_Label_Text;
|
|
//lblSalary.Text = Resources.Registration_Salary_Label_Text;
|
|
//lblNoOfChildren.Text = Resources.Registration_Children_Label_Text;
|
|
//btnRegister.Text = Resources.Registration_Register_Button_Text;
|
|
|
|
//// Search, Print, Export, Update, Delete
|
|
//btnSearch.Text = Resources.Search_Search_Button_Text;
|
|
//btnRefresh.Text = Resources.Search_Refresh_Button_Text;
|
|
//btnPrintPreview.Text = Resources.Print_PrintPreview_Button_Text;
|
|
//btnPrint.Text = Resources.Print_Print_Button_Text;
|
|
//btnExport.Text = Resources.Export_Button_Text;
|
|
//btnUpdate.Text = Resources.Update_Button_Text;
|
|
//btnDelete.Text = Resources.Delete_Button_Text;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes all dropdown controls
|
|
/// </summary>
|
|
private void InitializeDropDownList()
|
|
{
|
|
//cmbOccupation.DataSource = Enum.GetValues(typeof(Occupation));
|
|
//cmbMaritalStatus.DataSource = Enum.GetValues(typeof(MaritalStatus));
|
|
//cmbHealthStatus.DataSource = Enum.GetValues(typeof(HealthStatus));
|
|
|
|
//cmbSearchOccupation.DataSource = Enum.GetValues(typeof(Occupation));
|
|
//cmbSearchMaritalStatus.DataSource = Enum.GetValues(typeof(MaritalStatus));
|
|
//cmbOperand.SelectedIndex = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets the registration screen
|
|
/// </summary>
|
|
private void ResetRegistration()
|
|
{
|
|
cmbProjects.SelectedIndex = -1;
|
|
textBoxAuthor.Text = string.Empty;
|
|
|
|
try
|
|
{
|
|
if (tab.SelectedIndex == 0)
|
|
{
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
this.InitializeUpdate();
|
|
this.LoadDataGridView(data);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
//var srv = new Server();
|
|
//var db = new Database(srv, "mydb");
|
|
//db.Create();
|
|
}
|
|
|
|
//txtName.Text = string.Empty;
|
|
//txtSalary.Text = string.Empty;
|
|
//txtNoOfChildren.Text = string.Empty;
|
|
//cmbOccupation.SelectedIndex = -1;
|
|
//cmbHealthStatus.SelectedIndex = -1;
|
|
//cmbMaritalStatus.SelectedIndex = -1;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validates registration input
|
|
/// </summary>
|
|
/// <returns>true or false</returns>
|
|
private bool ValidateRegistration()
|
|
{
|
|
this.errorMessage = string.Empty;
|
|
|
|
if (cmbProjects.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 this.errorMessage != string.Empty ? false : true;
|
|
}
|
|
|
|
private void tab_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (tab.SelectedIndex == 0)
|
|
{
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
this.InitializeUpdate();
|
|
//this.LoadDataGridView(data);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
}
|
|
|
|
private void Refresh()
|
|
{
|
|
try
|
|
{
|
|
//this.ResetSearch();
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
//DataTable dataGridView = this.projectService.GetAllProjectsForGridView();
|
|
this.LoadDataGridView(data);
|
|
this.LoadComboBoxView(data);
|
|
this.LoadTextBoxes(data);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
}
|
|
|
|
private void btnRefresh_Click(object sender, EventArgs e)
|
|
{
|
|
Refresh();
|
|
}
|
|
|
|
private bool updateProject()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
if (this.ValidateUpdate())
|
|
{
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = this.projectId,
|
|
ProjectName = cmbProjects.Text.Trim(),
|
|
Author = this.textBoxAuthor.Text.Trim(),
|
|
UpdatedDate = DateTime.Now,
|
|
HomeDir = textBoxHomeProjectsDir.Text,
|
|
//FrameWidth = 0,
|
|
//FrameHeight = 0,
|
|
//ResW = 0,
|
|
//ResH = 0,
|
|
//ObjName = "",
|
|
//NRows = 0,
|
|
//NCols = 0,
|
|
//CoX = 0,
|
|
//CoY = 0,
|
|
//NSlices = 0,
|
|
//NLowEdgeBrightness = 0,
|
|
//NHighEdgeBrightness = 0,
|
|
//ImageMappingRepeat = 0
|
|
};
|
|
|
|
var flag = this.projectService.UpdateProject(projectModel);//, textBoxHomeProjectsDir.Text);
|
|
|
|
if (flag)
|
|
{
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
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 bool updateProjectIniGen()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
if (this.ValidateUpdate())
|
|
{
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = this.projectId,
|
|
ProjectName = cmbProjects.Text.Trim(),
|
|
Author = this.textBoxAuthor.Text.Trim(),
|
|
UpdatedDate = DateTime.Now,
|
|
FrameWidth = float.Parse(textBoxFrameWidth.Text.Trim()),
|
|
FrameHeight = float.Parse(textBoxFrameHeight.Text.Trim()),
|
|
ResW = int.Parse(textBoxResW.Text.Trim()),
|
|
ResH = int.Parse(textBoxResH.Text.Trim()),
|
|
ObjName = textBoxObjName.Text.Trim(),
|
|
ObjHeight = float.Parse(textBoxObjH.Text.Trim()),
|
|
ObjWidth = float.Parse(textBoxObjW.Text.Trim()),
|
|
NRows = int.Parse(textBoxNRows.Text.Trim()),
|
|
NCols = int.Parse(textBoxNCols.Text.Trim()),
|
|
CoX = float.Parse(textBoxCoX.Text.Trim()),
|
|
CoY = float.Parse(textBoxCoY.Text.Trim()),
|
|
//NSlices = int.Parse(textBoxNCols.Text.Trim()),
|
|
//LowLevelBrightness = 0,
|
|
//HighLevelBrightness = 0,
|
|
//Repeats = 0
|
|
};
|
|
|
|
var flag = this.projectService.UpdateProjectIniGen(projectModel);
|
|
|
|
if (flag)
|
|
{
|
|
//DataTable data = this.projectService.GetAllProjects();
|
|
//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 bool UpdateProjectImageGen()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
if (this.ValidateUpdate())
|
|
{
|
|
HeightmapModel heightmapModel = new HeightmapModel()
|
|
{
|
|
Id = this.projectId,
|
|
ProjectName = cmbProjects.Text.Trim(),
|
|
NSlices = Int32.Parse(textBoxNLevels.Text.Trim()),
|
|
LowLevelBrightness = trackBarMinLevel.Value,
|
|
HighLevelBrightness = trackBarMaxLevel.Value,
|
|
Repeats = Int32.Parse(textBoxRepeats.Text),
|
|
NSlicesTexture = Int32.Parse(textBoxRepTexture.Text.Trim()),
|
|
//BorderSize = Int32.Parse(textBoxRepTexture.Text.Trim()),
|
|
PictureWidth = trackBarPictureWidth.Value,
|
|
};
|
|
|
|
var flag = this.heightmapService.UpdateProject(heightmapModel);
|
|
|
|
if (flag)
|
|
{
|
|
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 bool UpdateProjectSystemSettings()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
if (this.ValidateUpdate())
|
|
{
|
|
SystemSettingsModel systemSettingsModel = new SystemSettingsModel()
|
|
{
|
|
Id = this.projectId,
|
|
ProjectName = cmbProjects.Text.Trim(),
|
|
HomeDir = textBoxHomeProjectsDir.Text,
|
|
BlenderDir = textBoxBlenderDir.Text
|
|
};
|
|
|
|
var flag = this.systemSettingsService.UpdateProject(systemSettingsModel);
|
|
|
|
if (flag)
|
|
{
|
|
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 bool renameSubdirectories(string oldProjectName, string newProjectName)
|
|
{
|
|
var success = false;
|
|
|
|
string homeProjectsDir = textBoxHomeProjectsDir.Text;
|
|
string oldDirectory = homeProjectsDir + oldProjectName;
|
|
string newDirectory = homeProjectsDir + newProjectName;
|
|
|
|
try
|
|
{
|
|
Directory.Move(oldDirectory, newDirectory);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
|
|
try
|
|
{
|
|
File.Move(newDirectory + "\\" + oldProjectName + @".blend", newDirectory + "\\" + newProjectName + @".blend");
|
|
success = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
|
|
//this.Text = comboBoxProjects.Text;
|
|
|
|
return success;
|
|
}
|
|
|
|
private void buttonUpdateProject_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dataRow = this.projectService.GetProjectById(this.projectId);
|
|
string oldProjectName = dataRow["Project Name"].ToString();
|
|
string newProjectName = cmbProjects.Text.Trim();
|
|
updateProject();
|
|
renameSubdirectories(oldProjectName, newProjectName);
|
|
Refresh();
|
|
}
|
|
|
|
private void deleteProject()
|
|
{
|
|
try
|
|
{
|
|
var flag = this.projectService.DeleteProject(this.projectId);
|
|
|
|
if (flag)
|
|
{
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
this.LoadDataGridView(data);
|
|
|
|
MessageBox.Show(
|
|
Resources.Delete_Successful_Message,
|
|
Resources.Delete_Successful_Message_Title,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
}
|
|
|
|
private bool deleteSubdirectories(string projectName)
|
|
{
|
|
string homeProjectsDir = textBoxHomeProjectsDir.Text;
|
|
string targetDirectory = homeProjectsDir + projectName;
|
|
|
|
var successDeleteDir = false;
|
|
//var successCopyFile = false;
|
|
|
|
try
|
|
{
|
|
CopyDir.Delete(targetDirectory);
|
|
successDeleteDir = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return successDeleteDir;
|
|
}
|
|
|
|
private void buttonDeleteProject_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dataRow = this.projectService.GetProjectById(this.projectId);
|
|
string projectName = dataRow["Project Name"].ToString();
|
|
deleteProject();
|
|
deleteSubdirectories(projectName);
|
|
Refresh();
|
|
Refresh();
|
|
//this.ResetRegistration();
|
|
}
|
|
|
|
private void Projects_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//this.ResetSearch();
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
//DataTable dataGridView = this.projectService.GetAllProjectsForGridView();
|
|
this.LoadDataGridView(data);
|
|
this.LoadComboBoxView(data);
|
|
this.LoadTextBoxes(data);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
}
|
|
|
|
private bool registerNewProject()
|
|
{
|
|
var success = false;
|
|
try
|
|
{
|
|
// Check if the validation passes
|
|
if (this.ValidateRegistration())
|
|
{
|
|
// Assign the values to the model
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = 0,
|
|
ProjectName = this.cmbProjects.Text.Trim(),
|
|
Author = this.textBoxAuthor.Text.Trim(),
|
|
CreatedDate = DateTime.Now,
|
|
UpdatedDate = DateTime.Now,
|
|
HomeDir = textBoxHomeProjectsDir.Text
|
|
|
|
// Name = txtName.Text.Trim(),
|
|
// DateOfBirth = dtDateOfBirth.Value,
|
|
// Occupation = (Occupation)cmbOccupation.SelectedValue,
|
|
// HealthStatus = (HealthStatus)cmbHealthStatus.SelectedValue,
|
|
// MaritalStatus = (MaritalStatus)cmbMaritalStatus.SelectedValue,
|
|
// Salary = txtSalary.Text.Trim() == string.Empty ? 0 : Convert.ToDecimal(txtSalary.Text),
|
|
// NumberOfChildren = txtNoOfChildren.Text.Trim() == string.Empty ? 0 : Convert.ToInt16(txtNoOfChildren.Text)
|
|
};
|
|
|
|
// Call the service method and assign the return status to variable
|
|
success = this.projectService.RegisterProject(projectModel);
|
|
|
|
// 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_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 bool createSubdirectories()
|
|
{
|
|
//string homeProjectsDir = textBoxHomeProjectsDir.Text;
|
|
//string homeProjectsDir = textBoxBlenderDir.Text;
|
|
//string sourceDirectory = homeProjectsDir + @"template";
|
|
//string targetDirectory = homeProjectsDir + cmbProjects.Text;
|
|
string sourceDirectory = textBoxBlenderDir.Text + @"template";
|
|
string targetDirectory = textBoxHomeProjectsDir.Text + cmbProjects.Text;
|
|
|
|
var successCopyDir = false;
|
|
var successCopyFile = false;
|
|
|
|
|
|
try
|
|
{
|
|
CopyDir.Copy(sourceDirectory, targetDirectory);
|
|
successCopyDir = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
string projectTemplateName = @"Template";
|
|
try
|
|
{
|
|
File.Move(targetDirectory + "\\" + projectTemplateName + @".blend", targetDirectory + "\\" + cmbProjects.Text + @".blend");
|
|
successCopyFile = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
this.Text = cmbProjects.Text;
|
|
return successCopyDir & successCopyFile;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Click event to handle registration
|
|
/// </summary>
|
|
/// <param name="sender">sender object</param>
|
|
/// <param name="e">event data</param>
|
|
private void btnNewProject_Click(object sender, EventArgs e)
|
|
{
|
|
registerNewProject();
|
|
createSubdirectories();
|
|
this.ResetRegistration();
|
|
Refresh();
|
|
}
|
|
|
|
private void dataGridViewProjects_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
if (e.ColumnIndex == 3)
|
|
{
|
|
e.Value = string.Format("{0:dd/MM/yyyy}", (DateTime)e.Value);
|
|
}
|
|
|
|
if (e.ColumnIndex == 4)
|
|
{
|
|
e.Value = string.Format("{0:dd/MM/yyyy}", (DateTime)e.Value);
|
|
}
|
|
|
|
//if (e.ColumnIndex == 3)
|
|
//{
|
|
// e.Value = Enum.GetName(typeof(Occupation), e.Value).ToString();
|
|
//}
|
|
|
|
//if (e.ColumnIndex == 4)
|
|
//{
|
|
// e.Value = Enum.GetName(typeof(MaritalStatus), e.Value).ToString();
|
|
//}
|
|
|
|
//if (e.ColumnIndex == 5)
|
|
//{
|
|
// e.Value = Enum.GetName(typeof(HealthStatus), e.Value).ToString();
|
|
//}
|
|
|
|
if (e.ColumnIndex == 6)
|
|
{
|
|
e.Value = Convert.ToDecimal(e.Value) == 0 ? string.Empty : e.Value;
|
|
}
|
|
|
|
if (e.ColumnIndex == 7)
|
|
{
|
|
e.Value = Convert.ToInt16(e.Value) == 0 ? string.Empty : e.Value;
|
|
}
|
|
|
|
}
|
|
|
|
private void cmbProjects_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
ComboBox cbProjects = (ComboBox)sender;
|
|
|
|
try
|
|
{
|
|
if (cbProjects.SelectedIndex > -1)
|
|
{
|
|
DataRowView selectedProject = (DataRowView)cbProjects.SelectedValue;
|
|
DataRow dataRow = selectedProject.Row; // this.projectService.GetProjectByName(projectName);
|
|
|
|
if (dataRow != null)
|
|
{
|
|
string Id = dataRow["Id"].ToString();
|
|
projectId = int.Parse(Id);
|
|
|
|
// Load Project management screen
|
|
cmbProjects.Text = dataRow["Project Name"].ToString();
|
|
textBoxAuthor.Text = dataRow["Author"].ToString();
|
|
// Load Generate Exp.ini screen
|
|
// Load Levels screen
|
|
trackBarMinLevel.Value = (int)dataRow["LowLevelBrightness"];
|
|
trackBarMaxLevel.Value = (int)dataRow["HighLevelBrightness"];
|
|
textBoxNLevels.Text = dataRow["NSlices"].ToString();
|
|
// Load Generate Gif's screen
|
|
// Load System Settings screen
|
|
}
|
|
//datetimePickerCreated.Value = Convert.ToDateTime(dataRow["Created"]);
|
|
//datetimePickerUpdated.Value = Convert.ToDateTime(dataRow["Last updated"]);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
}
|
|
|
|
private void dataGridViewProjects_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
DataGridView dgv = (DataGridView)sender;
|
|
|
|
try
|
|
{
|
|
if (dgv.SelectedRows.Count > 0)
|
|
{
|
|
string Id = dgv.SelectedRows[0].Cells[0].Value.ToString();
|
|
projectId = int.Parse(Id);
|
|
|
|
DataRow dataRow = this.projectService.GetProjectById(projectId);
|
|
|
|
//cmbProjects.Text = dataRow["Project Name"].ToString();
|
|
//textBoxAuthor.Text = dataRow["Author"].ToString();
|
|
//textBoxFrameWidth.Text = dataRow["FrameWidth"].ToString();
|
|
//textBoxFrameHeight.Text = dataRow["FrameHeight"].ToString();
|
|
//textBoxResW.Text = dataRow["ResW"].ToString();
|
|
//textBoxResH.Text = dataRow["ResH"].ToString();
|
|
//textBoxObjName.Text =
|
|
|
|
//datetimePickerCreated.Value = Convert.ToDateTime(dataRow["Created"]);
|
|
//datetimePickerUpdated.Value = Convert.ToDateTime(dataRow["Last updated"]);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
}
|
|
|
|
private void runBlenderInstanceWithProcessIniGen(string processDir)
|
|
{
|
|
ProcessStartInfo processInfo;
|
|
Process process;
|
|
|
|
//string processDir = textBoxHomeProjectsDir.Text;
|
|
//processDir += objName + @"\CheckFiles\blender_ini_gen.bat";
|
|
processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + processDir + "\"");
|
|
// processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + @"C:\Nikita\DotMatrix\Buddha_180_2400\CheckFiles\blender_ini_gen.bat" + "\"");
|
|
//processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + @"C:\Nikita\DotMatrix\Buddha_180_2400\CheckFiles\blender.bat" + "\"");
|
|
//processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + @"C:\Program Files\Blender Foundation\Blender\blender.exe" + "\"");
|
|
processInfo.CreateNoWindow = false;
|
|
processInfo.UseShellExecute = false;
|
|
|
|
processInfo.RedirectStandardError = false;
|
|
processInfo.RedirectStandardOutput = false;
|
|
|
|
process = Process.Start(processInfo);
|
|
//process.WaitForExit();
|
|
}
|
|
|
|
private void runBlenderInstanceWithProcessGifGen(string processDir)
|
|
{
|
|
ProcessStartInfo processInfo;
|
|
Process process;
|
|
|
|
//string processDir = textBoxHomeProjectsDir.Text;
|
|
//processDir += objName + @"\CheckFiles\blender_ini_gen.bat";
|
|
processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + processDir + "\"");
|
|
// processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + @"C:\Nikita\DotMatrix\Buddha_180_2400\CheckFiles\blender_ini_gen.bat" + "\"");
|
|
//processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + @"C:\Nikita\DotMatrix\Buddha_180_2400\CheckFiles\blender.bat" + "\"");
|
|
//processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + @"C:\Program Files\Blender Foundation\Blender\blender.exe" + "\"");
|
|
processInfo.CreateNoWindow = false;
|
|
processInfo.UseShellExecute = false;
|
|
|
|
processInfo.RedirectStandardError = false;
|
|
processInfo.RedirectStandardOutput = false;
|
|
|
|
process = Process.Start(processInfo);
|
|
//process.WaitForExit();
|
|
}
|
|
|
|
private string getProcessIniGenPath(string objName)
|
|
{
|
|
string processDir = textBoxHomeProjectsDir.Text;
|
|
processDir += objName + @"\CheckFiles\blender_ini_gen.bat";
|
|
return processDir;
|
|
}
|
|
|
|
private string getProcessGifGenPath(string objName)
|
|
{
|
|
string processDir = textBoxHomeProjectsDir.Text;
|
|
processDir += objName + @"\CheckFiles\blender_gifs_gen.bat";
|
|
return processDir;
|
|
}
|
|
|
|
private string getProcessRunBlenderTemplatePath(string objName)
|
|
{
|
|
string processDir = textBoxHomeProjectsDir.Text;
|
|
processDir += objName + @"\CheckFiles\run_blender_template.bat";
|
|
return processDir;
|
|
}
|
|
|
|
private string getIniGenScriptPath(string objName)
|
|
{
|
|
string scriptDir = textBoxHomeProjectsDir.Text;
|
|
scriptDir += objName + @"\CheckFiles\ini_gen.py";
|
|
return scriptDir;
|
|
}
|
|
|
|
private string getGifGenScriptPath(string objName)
|
|
{
|
|
string scriptDir = textBoxHomeProjectsDir.Text;
|
|
scriptDir += objName + @"\CheckFiles\gif_gen.py";
|
|
return scriptDir;
|
|
}
|
|
|
|
private string getBlenderPath()
|
|
{
|
|
string blenderDir = textBoxBlenderDir.Text;
|
|
return blenderDir;
|
|
}
|
|
|
|
private string getBlenderTemplatePath(string objName)
|
|
{
|
|
string blenderTemplateDir = textBoxHomeProjectsDir.Text;
|
|
blenderTemplateDir += objName + @"\" + objName + @".blend";
|
|
return blenderTemplateDir;
|
|
}
|
|
|
|
private void generateIniGenBatchFile(string processPath, string objName)
|
|
{
|
|
StreamWriter sw = null;
|
|
//FileInfo fi = new FileInfo(processPath);
|
|
FileStream fs = new FileStream(processPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
|
|
sw = new StreamWriter(fs);
|
|
string batchLineRunBlender = "";
|
|
string blenderPath = getBlenderPath() + @"blender.exe";
|
|
batchLineRunBlender += "\"" + blenderPath + "\"";
|
|
|
|
string blenderTemplatePath = getBlenderTemplatePath(objName);
|
|
|
|
batchLineRunBlender += " \"" + blenderTemplatePath + "\"";
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//string mode = @" --background";
|
|
|
|
//batchLineRunBlender += mode;
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
string python = @" --python";
|
|
|
|
batchLineRunBlender += python;
|
|
|
|
string script = getIniGenScriptPath(objName);
|
|
|
|
batchLineRunBlender += " \"" + script + "\"";
|
|
|
|
sw.WriteLine(batchLineRunBlender);
|
|
sw.Close();
|
|
}
|
|
|
|
private void generateGifGenBatchFile(string processPath, string objName)
|
|
{
|
|
StreamWriter sw = null;
|
|
//FileInfo fi = new FileInfo(processPath);
|
|
FileStream fs = new FileStream(processPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
|
|
sw = new StreamWriter(fs);
|
|
string batchLineRunBlender = "";
|
|
string blenderPath = getBlenderPath() + @"blender.exe";
|
|
batchLineRunBlender += "\"" + blenderPath + "\"";
|
|
|
|
string blenderTemplatePath = getBlenderTemplatePath(objName);
|
|
|
|
batchLineRunBlender += " \"" + blenderTemplatePath + "\"";
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//string mode = @" --background";
|
|
|
|
//batchLineRunBlender += mode;
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
string python = @" --python";
|
|
|
|
batchLineRunBlender += python;
|
|
|
|
string script = getGifGenScriptPath(objName);
|
|
|
|
batchLineRunBlender += " \"" + script + "\"";
|
|
|
|
sw.WriteLine(batchLineRunBlender);
|
|
sw.Close();
|
|
}
|
|
|
|
private void generateRunBlenderTemplateBatchFile(string processPath, string objName)
|
|
{
|
|
StreamWriter sw = null;
|
|
//FileInfo fi = new FileInfo(processPath);
|
|
FileStream fs = new FileStream(processPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
|
|
sw = new StreamWriter(fs);
|
|
string batchLineRunBlender = "";
|
|
string blenderPath = getBlenderPath() + @"blender.exe";
|
|
batchLineRunBlender += "\"" + blenderPath + "\"";
|
|
|
|
string blenderTemplatePath = getBlenderTemplatePath(objName);
|
|
|
|
batchLineRunBlender += " \"" + blenderTemplatePath + "\"";
|
|
|
|
sw.WriteLine(batchLineRunBlender);
|
|
sw.Close();
|
|
}
|
|
|
|
private void updateIniGenParametersTableForBlender(string projectName)
|
|
{
|
|
//fToBIniGenModel.Name = "iniGen";
|
|
fToBIniGenModel.ObjName = textBoxObjName.Text.Trim();
|
|
fToBIniGenModel.CoX = float.Parse(textBoxCoX.Text.Trim());
|
|
fToBIniGenModel.CoY = float.Parse(textBoxCoY.Text.Trim());
|
|
fToBIniGenModel.WRes = int.Parse(textBoxResW.Text.Trim());
|
|
fToBIniGenModel.HRes = int.Parse(textBoxResH.Text.Trim());
|
|
fToBIniGenModel.FrmW = float.Parse(textBoxFrameWidth.Text.Trim());
|
|
fToBIniGenModel.FrmH = float.Parse(textBoxFrameHeight.Text.Trim());
|
|
fToBIniGenModel.NRows = int.Parse(textBoxNRows.Text.Trim());
|
|
fToBIniGenModel.NCols = int.Parse(textBoxNCols.Text.Trim());
|
|
string processDir = textBoxHomeProjectsDir.Text.Trim();
|
|
fToBIniGenModel.FilePath = processDir + projectName + "\\";
|
|
fToBIniGenModel.Repeats = heightmapModel.Repeats;
|
|
fToBIniGenModel.CancelIniGen = 0;
|
|
fToBIniGenService.UpdateFToBIniGen(fToBIniGenModel);
|
|
|
|
}
|
|
|
|
private void buttonRunIniGen_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dataRow = this.projectService.GetProjectById(this.projectId);
|
|
string projectName = dataRow["Project Name"].ToString();
|
|
string processDir = getProcessIniGenPath(projectName);
|
|
updateIniGenParametersTableForBlender(projectName);
|
|
// Reset Cancel IniGen
|
|
fToBIniGenModel.Name = "IniGen";
|
|
fToBIniGenModel.CancelIniGen = 0;
|
|
fToBIniGenService.UpdateCancelFToBIniGen(fToBIniGenModel);
|
|
|
|
generateIniGenBatchFile(processDir, projectName);
|
|
progressModel.ProgressName = "IniGen";
|
|
this.progressService.ResetProgress(progressModel);
|
|
runBlenderInstanceWithProcessIniGen(processDir);
|
|
if (backWorkerIniGen.IsBusy != true)
|
|
{
|
|
// ini values in file
|
|
ReadProgressIniGen();
|
|
this.progressBarIniGen.Visible = true;
|
|
this.labelMessageIniGen.Visible = true;
|
|
|
|
// Start the asynchronous operation.
|
|
backWorkerIniGen.RunWorkerAsync();
|
|
}
|
|
|
|
}
|
|
|
|
private void buttonCancelProcess_Click(object sender, EventArgs e)
|
|
{
|
|
fToBIniGenModel.Name = "IniGen";
|
|
fToBIniGenModel.CancelIniGen = 1;
|
|
fToBIniGenService.UpdateCancelFToBIniGen(fToBIniGenModel);
|
|
backWorkerIniGen.CancelAsync();
|
|
}
|
|
|
|
public int ProgressPercentage(int value, int minval, int maxval)
|
|
{
|
|
if (maxval <= minval)
|
|
return 0;
|
|
return (value - minval) * 100 / (maxval - minval);
|
|
}
|
|
|
|
private bool ReadProgressIniGen()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
DataRow dataRow = this.progressService.GetProgressByName("IniGen");
|
|
//int percVal = ProgressPercentage(val, min, max);
|
|
progressModel.MinValue = (int)dataRow["start"];
|
|
progressModel.MaxValue = (int)dataRow["end"];
|
|
progressModel.CurValue = (int)dataRow["val"];
|
|
success = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
private void backWorkerIniGen_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
|
|
{
|
|
BackgroundWorker worker = sender as BackgroundWorker;
|
|
|
|
while (progressModel.CurValue < progressModel.MaxValue)
|
|
{
|
|
if (worker.CancellationPending == true)
|
|
{
|
|
e.Cancel = true;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
ReadProgressIniGen();
|
|
// Perform a time consuming operation and report progress.
|
|
worker.ReportProgress(ProgressPercentage(progressModel.CurValue, progressModel.MinValue, progressModel.MaxValue));
|
|
System.Threading.Thread.Sleep(500);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void backWorkerIniGen_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
|
{
|
|
// Show the progress in main form (GUI)
|
|
textBoxNumEdges.Text = progressModel.MaxValue.ToString();
|
|
textBoxNumEdgesProcessed.Text = progressModel.CurValue.ToString();
|
|
labelMessageIniGen.Text = "In progress, please wait... " + e.ProgressPercentage.ToString() + "%";
|
|
//textBoxStatus.Text = e.ProgressPercentage.ToString();
|
|
ProgressValueIniGen = e.ProgressPercentage;
|
|
ProgressMaxIniGen = 100;
|
|
ProgressMinIniGen = 0;
|
|
}
|
|
|
|
private void backWorkerIniGen_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
|
{
|
|
if (e.Cancelled == true)
|
|
{
|
|
labelMessageIniGen.Text = "Canceled!";
|
|
}
|
|
else if (e.Error != null)
|
|
{
|
|
labelMessageIniGen.Text = "Error: " + e.Error.Message;
|
|
}
|
|
else
|
|
{
|
|
labelMessageIniGen.Text = "Done!";
|
|
}
|
|
// Close the AlertForm
|
|
this.progressBarIniGen.Visible = false;
|
|
//this.labelMessageIniGen.Visible = false;
|
|
}
|
|
|
|
private bool ReadProgressGifGen()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
DataRow dataRow = this.progressService.GetProgressByName("GifGen");
|
|
//int percVal = ProgressPercentage(val, min, max);
|
|
progressModel.MinValue = (int)dataRow["start"];
|
|
progressModel.MaxValue = (int)dataRow["end"];
|
|
progressModel.CurValue = (int)dataRow["val"];
|
|
progressModel.CurValueExt = (int)dataRow["val_ext"];
|
|
success = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
private void backWorkerGifGen_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
|
|
{
|
|
BackgroundWorker worker = sender as BackgroundWorker;
|
|
|
|
while (progressModel.CurValue < progressModel.MaxValue)
|
|
{
|
|
if (worker.CancellationPending == true)
|
|
{
|
|
e.Cancel = true;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
ReadProgressGifGen();
|
|
// Perform a time consuming operation and report progress.
|
|
worker.ReportProgress(ProgressPercentage(progressModel.CurValue, progressModel.MinValue, progressModel.MaxValue));
|
|
System.Threading.Thread.Sleep(500);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void backWorkerGifGen_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
|
{
|
|
// Show the progress in main form (GUI)
|
|
int numLevelsToProcess = processLevelsModel.End - processLevelsModel.Start + 1;
|
|
textBoxNumLevels.Text = numLevelsToProcess.ToString();
|
|
textBoxNumLevelsProcessed.Text = progressModel.CurValue.ToString();
|
|
textBoxNumFramesProcessed.Text = progressModel.CurValueExt.ToString();
|
|
labelMessageGifGen.Text = "In progress, please wait... " + e.ProgressPercentage.ToString() + "%";
|
|
//textBoxStatus.Text = e.ProgressPercentage.ToString();
|
|
ProgressValueGifGen = e.ProgressPercentage;
|
|
ProgressMaxGifGen = 100;
|
|
ProgressMinGifGen = 0;
|
|
}
|
|
|
|
private void backWorkerGifGen_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
|
{
|
|
if (e.Cancelled == true)
|
|
{
|
|
labelMessageGifGen.Text = "Canceled!";
|
|
}
|
|
else if (e.Error != null)
|
|
{
|
|
labelMessageGifGen.Text = "Error: " + e.Error.Message;
|
|
}
|
|
else
|
|
{
|
|
labelMessageGifGen.Text = "Done!";
|
|
}
|
|
// Close the AlertForm
|
|
this.progressBarGifGen.Visible = false;
|
|
//this.labelMessageGifGen.Visible = false;
|
|
}
|
|
|
|
private void buttonRunBlender_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dataRow = this.projectService.GetProjectById(this.projectId);
|
|
//string projectName = dataRow["Project Name"].ToString();
|
|
string projectName = "nnnn";
|
|
string processDir = getProcessRunBlenderTemplatePath(projectName);
|
|
generateRunBlenderTemplateBatchFile(processDir, projectName);
|
|
runBlenderInstanceWithProcessIniGen(processDir);
|
|
}
|
|
|
|
private void buttonUpdateProjectIniGen_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dataRow = this.projectService.GetProjectById(this.projectId);
|
|
updateProjectIniGen();
|
|
}
|
|
|
|
private void buttonUpdateProjectImageGen_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dataRow = this.heightmapService.GetHeightmapByProjectId(this.projectId);
|
|
UpdateProjectImageGen();
|
|
}
|
|
|
|
private void buttonUpdateProjectSystemSettings_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dataRow = this.systemSettingsService.GetSystemSettingsByProjectId(this.projectId);
|
|
UpdateProjectSystemSettings();
|
|
}
|
|
|
|
private bool updateStartEndLevels()
|
|
{
|
|
var success = false;
|
|
|
|
processLevelsModel.Name = "GifGen";
|
|
processLevelsModel.Start = int.Parse(textBoxStartLevel.Text);
|
|
processLevelsModel.End = int.Parse(textBoxEndLevel.Text);
|
|
|
|
//DataRow dataRow = this.processLevelsService.GetProcessLevelsByName(processLevelsModel.Name);
|
|
try
|
|
{
|
|
var flag = this.processLevelsService.UpdateProcessLevels(processLevelsModel);
|
|
|
|
success = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
private void updateGifGenParametersTableForBlender(string projectName)
|
|
{
|
|
fToBIniGenModel.Name = "GifGen";
|
|
fToBIniGenModel.ObjName = textBoxObjName.Text.Trim();
|
|
fToBIniGenModel.CoX = float.Parse(textBoxCoX.Text.Trim());
|
|
fToBIniGenModel.CoY = float.Parse(textBoxCoY.Text.Trim());
|
|
fToBIniGenModel.WRes = int.Parse(textBoxResW.Text.Trim());
|
|
fToBIniGenModel.HRes = int.Parse(textBoxResH.Text.Trim());
|
|
fToBIniGenModel.FrmW = float.Parse(textBoxFrameWidth.Text.Trim());
|
|
fToBIniGenModel.FrmH = float.Parse(textBoxFrameHeight.Text.Trim());
|
|
fToBIniGenModel.NRows = int.Parse(textBoxNRows.Text.Trim());
|
|
fToBIniGenModel.NCols = int.Parse(textBoxNCols.Text.Trim());
|
|
string processDir = textBoxHomeProjectsDir.Text.Trim();
|
|
fToBIniGenModel.FilePath = processDir + projectName + "\\";
|
|
fToBIniGenModel.Repeats = heightmapModel.Repeats;
|
|
fToBIniGenModel.CancelIniGen = 0;
|
|
fToBIniGenService.UpdateFToBIniGen(fToBIniGenModel);
|
|
|
|
}
|
|
|
|
private void buttonRunGifsGen_Click(object sender, EventArgs e)
|
|
{
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
DataRow dataRow = this.projectService.GetProjectById(this.projectId);
|
|
//string objName = dataRow["ObjName"].ToString();
|
|
string projectName = dataRow["Project Name"].ToString();
|
|
//updateGifGenParametersTableForBlender(projectName);
|
|
bool success = updateStartEndLevels();
|
|
if (success == false)
|
|
return;
|
|
// Reset Cancel IniGen
|
|
fToBIniGenModel.Name = "GifGen";
|
|
fToBIniGenModel.CancelIniGen = 0;
|
|
updateIniGenParametersTableForBlender(projectName);
|
|
fToBIniGenService.UpdateCancelFToBIniGen(fToBIniGenModel);
|
|
// Set Repeats to interface with Blender
|
|
fToBIniGenModel.Repeats = (int)dataRow["Repeats"]; // heightmapModel.Repeats;
|
|
fToBIniGenService.UpdateRepeatsFToBIniGen(fToBIniGenModel);
|
|
|
|
string processDir = getProcessGifGenPath(projectName);
|
|
generateGifGenBatchFile(processDir, projectName);
|
|
progressModel.ProgressName = "GifGen";
|
|
this.progressService.ResetProgress(progressModel);
|
|
runBlenderInstanceWithProcessGifGen(processDir);
|
|
if (backWorkerGifGen.IsBusy != true)
|
|
{
|
|
// ini values in file
|
|
ReadProgressGifGen();
|
|
this.progressBarGifGen.Visible = true;
|
|
this.labelMessageGifGen.Visible = true;
|
|
|
|
// Start the asynchronous operation.
|
|
backWorkerGifGen.RunWorkerAsync();
|
|
}
|
|
}
|
|
|
|
private void buttonCancelGifGen_Click(object sender, EventArgs e)
|
|
{
|
|
fToBIniGenModel.Name = "GifGen";
|
|
fToBIniGenModel.CancelIniGen = 1;
|
|
fToBIniGenService.UpdateCancelFToBIniGen(fToBIniGenModel);
|
|
backWorkerGifGen.CancelAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Heightmap screen (Kolja)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
///
|
|
private void IniFolder()
|
|
{
|
|
trackBarNumberSlices.Maximum = heightmapModel.MaxSlices;
|
|
label17.Text = "Witdh of picture = << " + Convert.ToString(heightmapModel.PictureWidth) + " >>";
|
|
Bordlabel.Text = "Border - << " + Convert.ToString(heightmapModel.BorderSize) + " >>";
|
|
//fPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
heightmapModel.FPath = Application.StartupPath.ToString();
|
|
CalNSlices();
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
|
|
private void CalNSlices()
|
|
{
|
|
heightmapModel.NSlicesTexture = (heightmapModel.NSlices / 255) + 1;
|
|
trackBarNumberSlices.Value = Convert.ToInt32(Math.Sqrt(heightmapModel.NSlices * heightmapModel.MaxSlices));
|
|
heightmapModel.Repeats = heightmapModel.NSlices / heightmapModel.NSlicesTexture;
|
|
textBoxRepeats.Text = heightmapModel.Repeats.ToString();
|
|
textBoxRepTexture.Text = heightmapModel.NSlicesTexture.ToString();
|
|
//RepTlabel.Text = "Number patterns = << " + Convert.ToString(heightmapModel.NSlicesTexture) + " >>";
|
|
}
|
|
|
|
private void textBoxNLevels_TextChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
heightmapModel.NSlices = Convert.ToInt32(textBoxNLevels.Text);
|
|
}
|
|
catch
|
|
{
|
|
textBoxNLevels.Text = "1";
|
|
}
|
|
|
|
if (heightmapModel.NSlices > heightmapModel.MaxSlices)
|
|
{
|
|
heightmapModel.NSlices = heightmapModel.MaxSlices;
|
|
textBoxNLevels.Text = Convert.ToString(heightmapModel.NSlices);
|
|
textBoxNLevels.Cursor.ToString();
|
|
}
|
|
if (heightmapModel.NSlices < 1)
|
|
{
|
|
heightmapModel.NSlices = 1;
|
|
textBoxNLevels.Text = Convert.ToString(heightmapModel.NSlices);
|
|
textBoxNLevels.Cursor.ToString();
|
|
}
|
|
CalNSlices();
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
|
|
private void trackBarMinLevel_Scroll(object sender, EventArgs e)
|
|
{
|
|
heightmapModel.LowLevelBrightness = trackBarMinLevel.Value;
|
|
//MinLevelLabel.Text = "MinLevel - << " + Convert.ToString(heightmapModel.LowLevelBrightness) + " >>";
|
|
textBoxMinLevel.Text = heightmapModel.LowLevelBrightness.ToString();
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
|
|
private void trackBarMaxLevel_Scroll(object sender, EventArgs e)
|
|
{
|
|
heightmapModel.HighLevelBrightness = trackBarMaxLevel.Value;
|
|
//MaxLevelLabel.Text = "MaxLevel - << " + Convert.ToString(heightmapModel.HighLevelBrightness) + " >>";
|
|
textBoxMaxLevel.Text = heightmapModel.HighLevelBrightness.ToString();
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
|
|
private void buttonSetHomeProjectDir_Click(object sender, EventArgs e)
|
|
{
|
|
//folderBrowserDialog1.RootFolder = textBoxHomeProjectsDir.Text.Trim();
|
|
folderBrowserDialog1.ShowNewFolderButton = true;
|
|
folderBrowserDialog1.ShowDialog();
|
|
string selectedPath = folderBrowserDialog1.SelectedPath;
|
|
textBoxHomeProjectsDir.Text = selectedPath + "\\";
|
|
}
|
|
|
|
private void buttonSetBlenderDir_Click(object sender, EventArgs e)
|
|
{
|
|
folderBrowserDialog1.ShowNewFolderButton = true;
|
|
folderBrowserDialog1.ShowDialog();
|
|
string selectedPath = folderBrowserDialog1.SelectedPath;
|
|
textBoxBlenderDir.Text = selectedPath + "\\";
|
|
}
|
|
|
|
private void trackBarPictureWidth_Scroll(object sender, EventArgs e)
|
|
{
|
|
heightmapModel.PictureWidth = trackBarPictureWidth.Value;
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
label17.Text = "Witdh of picture = << " + Convert.ToString(heightmapModel.PictureWidth) + " >>";
|
|
}
|
|
|
|
//private void Border_Scroll(object sender, EventArgs e)
|
|
//{
|
|
// bord = Border.Value;
|
|
// Bordlabel.Text = "Border - << " + Convert.ToString(bord) + " >>";
|
|
// GenHeight(nslices, MinLev, MaxLev);
|
|
//}
|
|
|
|
private void trackBarNumberSlices_Scroll(object sender, EventArgs e)
|
|
{
|
|
int nRep = 1;
|
|
int nSlicesTexture = 1;
|
|
|
|
heightmapModel.NSlices = (trackBarNumberSlices.Value * trackBarNumberSlices.Value / heightmapModel.MaxSlices);
|
|
textBoxNLevels.Text = Convert.ToString(heightmapModel.NSlices);
|
|
nSlicesTexture = (heightmapModel.NSlices / 255) + 1;
|
|
nRep = heightmapModel.NSlices / nSlicesTexture;
|
|
textBoxRepeats.Text = Convert.ToString(nRep);
|
|
//RepTlabel.Text = "Number patterns = << " + Convert.ToString(nSlicesTexture) + " >>";
|
|
textBoxRepTexture.Text = nSlicesTexture.ToString();
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
|
|
private void btSave_Click(object sender, EventArgs e)
|
|
{
|
|
string fName;
|
|
|
|
|
|
//Bitmap MyImage;
|
|
if (MenuEn.Checked == true)
|
|
{
|
|
if (TextureHeight.Image != null)
|
|
{
|
|
//string format = full_name_of_image.Substring(full_name_of_image.Length - 4, 4);
|
|
|
|
// SaveFileDialog savedialog = new SaveFileDialog();
|
|
saveFileDialog1.Title = "Save texture";
|
|
saveFileDialog1.OverwritePrompt = true;
|
|
saveFileDialog1.CheckPathExists = true;
|
|
saveFileDialog1.Filter = "Image Files(*.BMP)|*.BMP|Image Files(*.JPG)|*.JPG|ImageFiles(*.GIF)|*.GIF|Image Files(*.PNG)|*.PNG|All files (*.*)|*.*";
|
|
saveFileDialog1.FilterIndex = 5;
|
|
saveFileDialog1.ShowHelp = true;
|
|
// If selected, save
|
|
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
try
|
|
{
|
|
if (saveFileDialog1.FileName.IndexOf(".") > 0) fName = saveFileDialog1.FileName;
|
|
else fName = saveFileDialog1.FileName + ".BMP";
|
|
TextureHeight.Image.Save(fName, System.Drawing.Imaging.ImageFormat.Bmp);
|
|
/*pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
|
|
MyImage = new Bitmap(fName);
|
|
pictureBox1.ClientSize = new Size(100, 420);
|
|
pictureBox1.Image = (Image)MyImage;*/
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("Impossible to save image", "FATAL ERROR",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DataRow dataRowProject = this.projectService.GetProjectById(this.projectId);
|
|
string fPath = dataRowProject["HomeDir"] + (string)dataRowProject["Project name"] + "\\Textures\\Height.BMP";
|
|
TextureHeight.Image.Save(fPath, System.Drawing.Imaging.ImageFormat.Bmp);
|
|
/*pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
|
|
MyImage = new Bitmap("Height.BMP");
|
|
pictureBox1.ClientSize = new Size(100, 420);
|
|
pictureBox1.Image = (Image)MyImage;*/
|
|
}
|
|
|
|
DataRow dataRow = this.heightmapService.GetHeightmapByProjectId(this.projectId);
|
|
UpdateProjectImageGen();
|
|
|
|
}
|
|
|
|
private void tabGenImage_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void buttonGeneratePicture_Click(object sender, EventArgs e)
|
|
{
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
|
|
}
|
|
|
|
private int GenHeight(int nslices, int minLev, int maxLev, int percent, int frequency)
|
|
{
|
|
int nSlicesTexture = 1;
|
|
int i = 0, j = 0;
|
|
int c = 0;
|
|
int imageH;
|
|
int y = 0;
|
|
int colInterval = 255;
|
|
int colIntervalMod = 255;
|
|
int mod = 0;
|
|
int heightlevel = 255;
|
|
int lowlevel = 0;
|
|
int deltaCol = 0;
|
|
double Mod = 0;
|
|
|
|
nSlicesTexture = (nslices / 255) + 1;
|
|
heightmapModel.Repeats = nslices / nSlicesTexture;
|
|
TextureHeight.Width = heightmapModel.PictureWidth;
|
|
if (heightmapModel.HighLevelBrightness <= heightmapModel.LowLevelBrightness) heightmapModel.HighLevelBrightness = heightmapModel.LowLevelBrightness + 1;
|
|
imageH = ((heightmapModel.HighLevelBrightness - heightmapModel.LowLevelBrightness) * nSlicesTexture);
|
|
TextureHeight.Height = (imageH + (heightmapModel.BorderSize * 1));
|
|
|
|
TextureHeight.Refresh();
|
|
TextureHeight.Image = new Bitmap(heightmapModel.PictureWidth, imageH);
|
|
Image btmBack = TextureHeight.Image;
|
|
Graphics grBack = Graphics.FromImage(btmBack);
|
|
TextureHeight.BackgroundImage = btmBack;
|
|
colInterval = heightmapModel.HighLevelBrightness - heightmapModel.LowLevelBrightness;
|
|
deltaCol = Convert.ToInt32((double)colInterval * (double)percent / 200);
|
|
if (deltaCol > colInterval / 2) deltaCol = colInterval / 2;
|
|
lowlevel = heightmapModel.LowLevelBrightness + deltaCol;
|
|
heightlevel = heightmapModel.HighLevelBrightness - deltaCol;
|
|
colIntervalMod = heightlevel - lowlevel;
|
|
|
|
|
|
for (j = 0; j < nSlicesTexture; ++j)
|
|
{
|
|
for (i = 0; i <= colInterval; ++i)
|
|
{
|
|
Color col = new Color();
|
|
//c = (heightmapModel.HighLevelBrightness - deltaCol) - (colInterval - 2 * deltaCol) * i;
|
|
c = Convert.ToInt32(((double) heightlevel - (((double) colInterval - 2.0 * (double) deltaCol) / (double) colInterval) * (double) i));
|
|
if (c < 0) c = 0;
|
|
if (c > 255) c = 255;
|
|
col = Color.FromArgb(c, c, c);
|
|
Mod = 2 * Math.PI / Convert.ToDouble(colInterval) * i * frequency;
|
|
//mod = Convert.ToInt32(Math.Cos(Mod) * colIntervalMod * percent / 100);
|
|
mod = Convert.ToInt32(Math.Cos(Mod) * deltaCol * percent / 100);
|
|
c = c - mod;
|
|
if (c > 255) c = 255;
|
|
if (c < heightmapModel.LowLevelBrightness) c = heightmapModel.LowLevelBrightness;
|
|
col = Color.FromArgb(c, c, c);
|
|
Pen Pn = new Pen(col, 1);
|
|
y = i + (j * (heightmapModel.HighLevelBrightness - heightmapModel.LowLevelBrightness));
|
|
grBack.DrawLine(Pn, heightmapModel.BorderSize, y + heightmapModel.BorderSize, heightmapModel.PictureWidth - heightmapModel.BorderSize, y + heightmapModel.BorderSize);
|
|
}
|
|
}
|
|
|
|
return heightmapModel.Repeats;
|
|
}
|
|
|
|
private void textBoxMaxLevel_TextChanged(object sender, EventArgs e)
|
|
{
|
|
int result = 0;
|
|
if (Int32.TryParse(textBoxMaxLevel.Text, out result))
|
|
{
|
|
if (result >= trackBarMaxLevel.Minimum && result <= trackBarMaxLevel.Maximum)
|
|
{
|
|
trackBarMaxLevel.Value = result;
|
|
heightmapModel.HighLevelBrightness = result;
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void textBoxMinLevel_TextChanged(object sender, EventArgs e)
|
|
{
|
|
int result = 0;
|
|
if (Int32.TryParse(textBoxMinLevel.Text, out result))
|
|
{
|
|
if (result >= trackBarMinLevel.Minimum && result <= trackBarMinLevel.Maximum)
|
|
{
|
|
trackBarMinLevel.Value = result;
|
|
heightmapModel.LowLevelBrightness = result;
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void buttonCalcRowsCols_Click(object sender, EventArgs e)
|
|
{
|
|
textBoxNRows.Text = Convert.ToString(Math.Ceiling(float.Parse(textBoxObjH.Text.Trim()) / float.Parse(textBoxFrameHeight.Text.Trim())));
|
|
textBoxNCols.Text = Convert.ToString(Math.Ceiling(float.Parse(textBoxObjW.Text.Trim()) / float.Parse(textBoxFrameWidth.Text.Trim())));
|
|
}
|
|
|
|
private void textBoxFrameWidth_Leave(object sender, EventArgs e)
|
|
{
|
|
if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",") {
|
|
textBoxFrameWidth.Text = textBoxFrameWidth.Text.Replace('.', ',');
|
|
} else {
|
|
textBoxFrameWidth.Text = textBoxFrameWidth.Text.Replace(',', '.');
|
|
}
|
|
//textBoxFrameWidth.Text = textBoxFrameWidth.Text.Replace(textBoxFrameWidth.Text, "[^0-9" + CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator + "]", "");
|
|
}
|
|
|
|
private void textBoxFrameHeight_Leave(object sender, EventArgs e)
|
|
{
|
|
if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",")
|
|
{
|
|
textBoxFrameHeight.Text = textBoxFrameHeight.Text.Replace('.', ',');
|
|
}
|
|
else
|
|
{
|
|
textBoxFrameHeight.Text = textBoxFrameHeight.Text.Replace(',', '.');
|
|
}
|
|
}
|
|
|
|
private void textBoxCoX_Leave(object sender, EventArgs e)
|
|
{
|
|
if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",")
|
|
{
|
|
textBoxCoX.Text = textBoxCoX.Text.Replace('.', ',');
|
|
}
|
|
else
|
|
{
|
|
textBoxCoX.Text = textBoxCoX.Text.Replace(',', '.');
|
|
}
|
|
}
|
|
|
|
private void textBoxCoY_Leave(object sender, EventArgs e)
|
|
{
|
|
//GetVolumeInformation("C:\\", NameBuffer, sizeof(NameBuffer), &VSNumber, &MCLength, &FileSF, SysNameBuffer, sizeof(SysNameBuffer));
|
|
if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",")
|
|
{
|
|
textBoxCoY.Text = textBoxCoY.Text.Replace('.', ',');
|
|
}
|
|
else
|
|
{
|
|
textBoxCoY.Text = textBoxCoY.Text.Replace(',', '.');
|
|
}
|
|
}
|
|
|
|
private void textBoxObjW_Leave(object sender, EventArgs e)
|
|
{
|
|
if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",")
|
|
{
|
|
textBoxObjW.Text = textBoxObjW.Text.Replace('.', ',');
|
|
textBoxFrameWidth.Text = textBoxFrameWidth.Text.Replace('.', ',');
|
|
}
|
|
else
|
|
{
|
|
textBoxObjW.Text = textBoxObjW.Text.Replace(',', '.');
|
|
textBoxFrameWidth.Text = textBoxFrameWidth.Text.Replace(',', '.');
|
|
}
|
|
if (textBoxObjW.Text != "")
|
|
{
|
|
textBoxNCols.Text = Convert.ToString(Math.Ceiling(float.Parse(textBoxObjW.Text.Trim()) / float.Parse(textBoxFrameWidth.Text.Trim())));
|
|
}
|
|
}
|
|
|
|
private void textBoxObjH_Leave(object sender, EventArgs e)
|
|
{
|
|
if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",")
|
|
{
|
|
textBoxObjH.Text = textBoxObjH.Text.Replace('.', ',');
|
|
textBoxFrameHeight.Text = textBoxFrameHeight.Text.Replace('.', ',');
|
|
}
|
|
else
|
|
{
|
|
textBoxObjH.Text = textBoxObjH.Text.Replace(',', '.');
|
|
textBoxFrameHeight.Text = textBoxFrameHeight.Text.Replace(',', '.');
|
|
}
|
|
if (textBoxObjH.Text != "")
|
|
{
|
|
textBoxNRows.Text = Convert.ToString(Math.Ceiling(float.Parse(textBoxObjH.Text.Trim()) / float.Parse(textBoxFrameHeight.Text.Trim())));
|
|
}
|
|
}
|
|
|
|
private void trackBarPercent_Scroll(object sender, EventArgs e)
|
|
{
|
|
heightmapModel.Percent = trackBarPercent.Value;
|
|
//MinLevelLabel.Text = "MinLevel - << " + Convert.ToString(heightmapModel.LowLevelBrightness) + " >>";
|
|
textBoxPercent.Text = heightmapModel.Percent.ToString();
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
|
|
private void textBoxPercent_TextChanged(object sender, EventArgs e)
|
|
{
|
|
int result = 0;
|
|
if (Int32.TryParse(textBoxPercent.Text, out result))
|
|
{
|
|
if (result >= trackBarPercent.Minimum && result <= trackBarPercent.Maximum)
|
|
{
|
|
trackBarPercent.Value = result;
|
|
heightmapModel.Percent = result;
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void trackBarFrequency_Scroll(object sender, EventArgs e)
|
|
{
|
|
heightmapModel.Frequency = trackBarFrequency.Value;
|
|
textBoxFrequency.Text = heightmapModel.Frequency.ToString();
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
private void textBoxFrequency_TextChanged(object sender, EventArgs e)
|
|
{
|
|
int result = 0;
|
|
if (Int32.TryParse(textBoxFrequency.Text, out result))
|
|
{
|
|
if (result >= trackBarFrequency.Minimum && result <= trackBarFrequency.Maximum)
|
|
{
|
|
trackBarFrequency.Value = result;
|
|
heightmapModel.Frequency = result;
|
|
GenHeight(heightmapModel.NSlices, heightmapModel.LowLevelBrightness, heightmapModel.HighLevelBrightness, heightmapModel.Percent, heightmapModel.Frequency);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ReigsterTSMIVisible()
|
|
{
|
|
//this.registerToolStripMenuItem.Visible = !license;
|
|
//// Выбор лицензированных проектов
|
|
|
|
tab.Enabled = license; //LicenseAuthorization.Treko;
|
|
buttonRunBlender.Enabled = license; //reko3D.Enabled = LicenseAuthorization.Treko3D;
|
|
btnRefresh.Enabled = license;
|
|
//// меню file
|
|
//fileToolStripMenuItem.Enabled = license;
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
//string st = "";
|
|
|
|
//st = Big.Lito.Data.LicenseAuthorization.TestTestLicense();
|
|
|
|
//if ((st == "") || (st == " "))
|
|
//{
|
|
// timer1.Interval = 1800000;
|
|
// license = true;
|
|
//}
|
|
//else
|
|
//{
|
|
// timer1.Enabled = false;
|
|
// if(MessageBox.Show(st, "License error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
|
|
// {
|
|
// Form ifrm = new NewRegisterForm();
|
|
// ifrm.Show();
|
|
// }
|
|
// license = false;
|
|
//}
|
|
//ReigsterTSMIVisible();
|
|
}
|
|
}
|
|
}
|
|
|