using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Windows.Forms.DataVisualization.Charting;
using System;
using System.ComponentModel;
using System.IO;
namespace WindowsFormsApp1
{
partial class Form1
{
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
/// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
private void initializeSplitContainer()
{
mainContainer1 = new SplitContainer
{
Dock = DockStyle.Fill,
Orientation = Orientation.Vertical // 수직으로 나눔
};
// 왼쪽 영역 (트리 뷰 및 파일 브라우저)
leftContainer1 = new SplitContainer
{
Dock = DockStyle.Fill,
Orientation = Orientation.Horizontal // 수평으로 나눔
};
// 왼쪽 컨테이너에 추가
leftContainer1.Panel1.Controls.Add(treeView1); // 트리 뷰
leftContainer1.Panel2.Controls.Add(propertyGrid1); // 파일 브라우저
// 오른쪽 영역 (속성 창, 그래프 및 Python Console)
rightContainer1 = new SplitContainer
{
Dock = DockStyle.Fill,
Orientation = Orientation.Horizontal
};
// 속성 창 추가
//rightContainer1.Panel1.Controls.Add(propertyGrid1);
// 그래프 및 콘솔 창 분할
SplitContainer graphConsoleContainer1 = new SplitContainer
{
Dock = DockStyle.Fill,
Orientation = Orientation.Vertical // 수직으로 나눔
};
// 그래프 창
graphConsoleContainer1.Panel1.Controls.Add(chart1); // 차트
graphConsoleContainer1.Panel2.Controls.Add(pythonConsole1); // Python Console
rightContainer1.Panel2.Controls.Add(graphConsoleContainer1);
// 메인 컨테이너 구성
mainContainer1.Panel1.Controls.Add(leftContainer1);
mainContainer1.Panel2.Controls.Add(rightContainer1);
// 폼에 추가
this.Controls.Add(mainContainer1);
this.Controls.Add(statusStrip1);
}
private void initializeTreeView()
{
treeView1 = new System.Windows.Forms.TreeView()
{
Dock = DockStyle.Fill
};
// "내 컴퓨터" 루트 노드 추가
TreeNode rootNode = new TreeNode("My Computer");
rootNode.Tag = null; // 최상위 루트는 특별한 태그가 필요 없음
rootNode.Nodes.Add("Loading..."); // Lazy Loading
treeView1.Nodes.Add(rootNode);
// TreeView 이벤트 핸들러 추가
treeView1.BeforeExpand += TreeView1_BeforeExpand;
treeView1.AfterSelect += TreeView1_AfterSelect; // AfterSelect 이벤트 등록
// TreeView를 초기화할 때 드라이브 추가
foreach (var drive in System.IO.DriveInfo.GetDrives())
{
TreeNode driveNode = new TreeNode(drive.Name)
{
Tag = drive.RootDirectory.FullName // 드라이브 경로 저장
};
driveNode.Nodes.Add("Loading..."); // Lazy Loading
rootNode.Nodes.Add(driveNode);
}
}
private ParamData LoadParamData(string filePath)
{
var paramData = new ParamData();
if (!System.IO.File.Exists(filePath))
throw new FileNotFoundException($"File not found: {filePath}");
foreach (var line in System.IO.File.ReadAllLines(filePath))
{
if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#"))
continue;
var parts = line.Split(new[] { '=' }, 2);
if (parts.Length == 2)
{
string key = parts[0].Trim();
string value = parts[1].Trim();
// Property 이름과 매핑
var property = typeof(ParamData).GetProperty(key);
if (property != null)
{
// 적절한 타입으로 변환
var convertedValue = Convert.ChangeType(value, property.PropertyType);
property.SetValue(paramData, convertedValue);
}
}
}
return paramData;
}
private void initializePropertyGrid()
{
propertyGrid1 = new PropertyGrid
{
Dock = DockStyle.Fill
};
/*string filePath = @"F:\WindowsFormsApp1_CADIOSIM\DrugSimulationWin\param.txt";
try
{
var paramData = LoadParamData(filePath);
propertyGrid1.SelectedObject = paramData;
}
catch (Exception ex)
{
MessageBox.Show($"Error loading file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}*/
}
private void initializeChart()
{
chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart
{
Dock = DockStyle.Fill
};
ChartArea chartArea = new ChartArea();
chart1.ChartAreas.Add(chartArea);
Series series = new Series
{
ChartType = SeriesChartType.Line
};
series.Points.AddXY(0, 0);
series.Points.AddXY(1, 2);
series.Points.AddXY(2, 4);
chart1.Series.Add(series);
}
private void initializePhthonConsole()
{
pythonConsole1 = new System.Windows.Forms.TextBox
{
Dock = DockStyle.Fill,
Multiline = true,
ScrollBars = ScrollBars.Vertical,
Font = new Font("Consolas", 10)
};
}
private void initializeStatusStrip()
{
statusStrip1 = new StatusStrip();
statusStrip1.Items.Add(new ToolStripStatusLabel { Text = "Ready" });
}
private void TreeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
TreeNode currentNode = e.Node;
// "Loading..." 노드가 있으면 제거 후 실제 데이터를 로드
if (currentNode.Nodes.Count == 1 && currentNode.Nodes[0].Text == "Loading...")
{
currentNode.Nodes.Clear(); // "Loading..." 노드 제거
try
{
// 현재 노드의 경로
string path = currentNode.Tag as string;
// 하위 폴더 추가
var directories = System.IO.Directory.GetDirectories(path);
foreach (var directory in directories)
{
TreeNode directoryNode = new TreeNode(System.IO.Path.GetFileName(directory))
{
Tag = directory // 폴더 경로 저장
};
directoryNode.Nodes.Add("Loading..."); // Lazy Loading
currentNode.Nodes.Add(directoryNode);
}
// 하위 파일 추가
var files = System.IO.Directory.GetFiles(path);
foreach (var file in files)
{
TreeNode fileNode = new TreeNode(System.IO.Path.GetFileName(file))
{
Tag = file // 파일 경로 저장
};
currentNode.Nodes.Add(fileNode);
}
}
catch (UnauthorizedAccessException)
{
currentNode.Nodes.Add("Access Denied");
}
catch (Exception ex)
{
currentNode.Nodes.Add($"Error: {ex.Message}");
}
}
}
private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Tag is string filePath && File.Exists(filePath))
{
// 파일이 .txt 형식인지 확인
if (Path.GetExtension(filePath).ToLower() == ".txt")
{
try
{
// 파일 로드 및 PropertyGrid 업데이트
var paramData = LoadParamData(filePath);
propertyGrid1.SelectedObject = paramData;
}
catch (Exception ex)
{
MessageBox.Show($"Failed to load file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
System.Windows.Forms.SplitContainer mainContainer1;
System.Windows.Forms.SplitContainer leftContainer1;
System.Windows.Forms.SplitContainer rightContainer1;
System.Windows.Forms.TreeView treeView1;
System.Windows.Forms.PropertyGrid propertyGrid1;
System.Windows.Forms.DataVisualization.Charting.Chart chart1;
System.Windows.Forms.TextBox pythonConsole1;
System.Windows.Forms.StatusStrip statusStrip1;
#endregion
}
public class ParamData
{
[Category("Simulation Parameters")]
public string User_Name { get; set; }
public int Celltype { get; set; }
public double Basic_Cycle_Length { get; set; }
public int Number_of_Pacing { get; set; }
public int Solver_Type { get; set; }
public double Time_Step { get; set; }
public double Time_Step_Min { get; set; }
public double Time_Step_Max { get; set; }
public double Writing_Step { get; set; }
public string Drug_Name { get; set; }
public string Concentrations { get; set; }
public string Hill_File { get; set; }
public string Herg_File { get; set; }
}
}