using CaeGlobals; using CaeKnowledge; using CaeKnowledge.View; using CaeMesh; using CaeResults; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Windows.Forms; namespace CPSO.Forms._92_Knowledge { public partial class FrmAnalysisResult : Form { public FrmAnalysisResult() { InitializeComponent(); dataGridView1.AllowUserToAddRows = false; dataGridView1.AllowUserToDeleteRows = false; dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; } private Controller _self; public Controller Self { get { return _self; } } public void PrepareForm(Controller self) { if (self != null) { _self = self; toolStripComboBox1.Items.Clear(); toolStripComboBox1.Items.Add("None"); // 分析结果 foreach (string name in Self.AllResults.GetResultNames()) { var result = Self.AllResults.GetResult(name); if (result != null) { toolStripComboBox1.Items.Add(result.FileName); } } toolStripComboBox1.SelectedIndex = 0; } } private void toolStripButton1_Click(object sender, System.EventArgs e) { if (dataGridView1.DataSource is BindingList list) { list.Clear(); if (toolStripComboBox1.SelectedIndex >= 0 && toolStripComboBox1.SelectedItem is string resultName && File.Exists(resultName)) { var results = LoadResult(resultName); results.ForEach(x => list.Add(x)); } else { MessageBox.Show($"没有指定已完成的分析结果,无法提取结果!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private List LoadResult(string resultName) { if (resultName.IsNullOrEmptyOrWhiteSpace()) return null; var list = new List(); // 1. 分析结果文件 if (!_self.AllResults.ContainsResult(resultName)) { FeResults results = FrdFileReader.Read(resultName); _self.AllResults.Add(resultName, results); } // 2. 读取映射文件 string filePath = Path.GetDirectoryName(resultName); string fileName = Path.GetFileNameWithoutExtension(resultName); string fullPath = Path.Combine(filePath, $"{fileName}.st2"); var lines = File.ReadAllLines(fullPath, System.Text.Encoding.UTF8).ToList(); Dictionary stepNames = new Dictionary(); Dictionary surfaceNames = new Dictionary(); // 3. 解析每一行数据 foreach (var line in lines) { if (string.IsNullOrWhiteSpace(line)) continue; // 跳过空行 var parts = line.Split(','); // 校验列数是否匹配(防止文件格式错误) if (parts.Length != 3) { continue; } int id = int.Parse(parts[0]); stepNames.Add(id, parts[1]); surfaceNames.Add(id, parts[2]); } // 3. 物理场 FeResults fr = _self.AllResults.GetResult(resultName); var allStepIds = fr.GetAllStepIds(); foreach (var stepId in allStepIds) { // 3.1 对应的曲面集 var stepName = stepNames[stepId]; var surfaceName = surfaceNames[stepId]; FeSurface surface = Self.GetSurface(surfaceName); var nodeSet = Self.GetNodeSet(surface.NodeSetName); // 该曲面集对应的内部节点集合 int[] labels = nodeSet.Labels; // 对应的节点 // 3.2 提取出的位移值 var dispAll = fr.GetField(fr.GetFieldData("DISP", "ALL", stepId, 1)).GetComponentValues("ALL"); var dispU = fr.GetField(fr.GetFieldData("DISP", "U1", stepId, 1)).GetComponentValues("U1"); var dispV = fr.GetField(fr.GetFieldData("DISP", "U2", stepId, 1)).GetComponentValues("U2"); var dispW = fr.GetField(fr.GetFieldData("DISP", "U3", stepId, 1)).GetComponentValues("U3"); foreach ( var label in labels) { int index = label - 1; var node = Self.GetNode(label); double all = dispAll[index]; double u = dispU[index]; double v = dispV[index]; double w = dispW[index]; list.Add(new ViewFeLog(stepId, stepName, node.Id, node.X, node.Y, node.Z, all, u, v, w)); } } return list; } private void FrmAnalysisResult_Load(object sender, System.EventArgs e) { dataGridView1.Columns.Clear(); dataGridView1.DataSource = new BindingList(); toolStripComboBox1.SelectedIndex = -1; } } }