227 lines
8.6 KiB
C#
227 lines
8.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows;
|
|
|
|
using FuzzySharp;
|
|
using FuzzySharp.PreProcess;
|
|
using FuzzySharp.SimilarityRatio;
|
|
|
|
using Microsoft.Win32;
|
|
|
|
using MvdLiteSnoop.MvdLite;
|
|
|
|
namespace MvdLiteSnoop
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
public MainWindow()
|
|
{
|
|
DataContext = this;
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void BuildTree()
|
|
{
|
|
string fileContent = File.ReadAllText(@"E:\Users\Zhanggg\Desktop\建筑工程BIM设计交付标准-施工图设计阶段_建筑V1.2.0.mvdlite");
|
|
|
|
MvdData parsedData = MvdLiteAssists.Parse(fileContent);
|
|
|
|
// 2. 从解析出的实体定义中构建树状结构
|
|
Console.WriteLine("--- Building Entity Inheritance Tree ---");
|
|
List<EntityNode> rootNodes = EntityTreeBuilder.Build(parsedData.EntityDefinitions);
|
|
Console.WriteLine($"Found {rootNodes.Count} root node(s).");
|
|
|
|
|
|
// 3. 打印树状结构
|
|
Console.WriteLine("\n--- Entity Hierarchy ---");
|
|
PrintTree(rootNodes);
|
|
}
|
|
/// <summary>
|
|
/// 打印实体树的主函数。
|
|
/// </summary>
|
|
/// <param name="roots">要打印的根节点列表。</param>
|
|
public static void PrintTree(List<EntityNode> roots)
|
|
{
|
|
foreach (var rootNode in roots)
|
|
{
|
|
// 对每个根节点调用递归打印函数
|
|
PrintNode(rootNode, "");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 递归函数,用于打印单个节点及其所有子孙节点。
|
|
/// </summary>
|
|
/// <param name="node">当前要打印的节点。</param>
|
|
/// <param name="indent">用于表示层级深度的缩进字符串。</param>
|
|
private static void PrintNode(EntityNode node, string indent)
|
|
{
|
|
// 打印当前节点名称,前面加上缩进
|
|
Console.WriteLine($"{indent}└── {node.Data.Name}");
|
|
|
|
// 遍历所有子节点
|
|
for (int i = 0; i < node.Children.Count; i++)
|
|
{
|
|
var child = node.Children[i];
|
|
|
|
// 判断是否为最后一个子节点,以决定使用 "└──" 还是 "├──"
|
|
bool isLast = i == (node.Children.Count - 1);
|
|
string newIndent = indent + (isLast ? " " : "│ ");
|
|
|
|
// 递归调用,打印子节点
|
|
PrintNode(child, newIndent);
|
|
}
|
|
}
|
|
public EntityNode SelectedNode { get; set; }
|
|
public ObservableCollection<EntityNode> EntityNodes { get; set; } = new ObservableCollection<EntityNode>();
|
|
|
|
private MvdData data;
|
|
private void Read(object sender, RoutedEventArgs e)
|
|
{
|
|
OpenFileDialog dialog = new OpenFileDialog()
|
|
{
|
|
Filter = "MVDLite Files (*.mvdlite)|*.mvdlite",
|
|
Title = "选择 MVDLite 文件",
|
|
};
|
|
if (dialog.ShowDialog() != true)
|
|
{
|
|
return;
|
|
}
|
|
string fileContent = File.ReadAllText(dialog.FileName);
|
|
//MvdLiteAssists parser = new MvdLiteAssists(dialog.FileName);
|
|
data = MvdLiteAssists.Parse(fileContent);
|
|
var definitions = data.EntityDefinitions;
|
|
var nodes = EntityTreeBuilder.Build(definitions);
|
|
EntityNodes.Clear();
|
|
foreach (var node in nodes)
|
|
{
|
|
EntityNodes.Add(node);
|
|
}
|
|
// --- 打印解析结果 ---
|
|
return;
|
|
// 打印元数据
|
|
Console.WriteLine("--- Metadata ---");
|
|
foreach (var meta in data.Metadata)
|
|
{
|
|
Console.WriteLine($"{meta.Key}: {meta.Value}");
|
|
}
|
|
|
|
// 打印别名
|
|
Console.WriteLine("\n--- Aliases ---");
|
|
foreach (var alias in data.Aliases)
|
|
{
|
|
Console.WriteLine(alias);
|
|
}
|
|
|
|
// 打印实体和约束
|
|
Console.WriteLine("\n--- Entity Definitions ---");
|
|
foreach (var entity in data.EntityDefinitions)
|
|
{
|
|
Console.WriteLine($"\n[Entity] Name: {entity.Name}, Inherits: {entity.InheritsFrom}, Description: {entity.Description}");
|
|
if (entity.Conditions.Any())
|
|
{
|
|
Console.WriteLine(" Conditions:");
|
|
foreach (var condition in entity.Conditions)
|
|
{
|
|
Console.WriteLine($" - {condition}");
|
|
}
|
|
}
|
|
if (entity.Constraints.Any())
|
|
{
|
|
Console.WriteLine(" Constraints:");
|
|
foreach (var constraint in entity.Constraints)
|
|
{
|
|
Console.WriteLine($" - Rule: {constraint.Description}");
|
|
Console.WriteLine($" Expression: {constraint.Expression}");
|
|
if (constraint.Properties.Any())
|
|
{
|
|
foreach (var prop in constraint.Properties)
|
|
{
|
|
Console.WriteLine($" Property: {prop.Key} = '{prop.Value}'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Search(object sender, RoutedEventArgs e)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return;
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
int ratio = int.MinValue;
|
|
var replaceText = TbToSearch.Text.Replace('-', ' ').Replace('_', ' ').Replace('—', ' ');
|
|
string searchText = replaceText;
|
|
var definitions = data.EntityDefinitions.Where(def => !string.IsNullOrEmpty(def.Description));
|
|
foreach (var defin in definitions)
|
|
{
|
|
var tempRatio = Fuzz.TokenSortRatio(defin.Description, replaceText);
|
|
if (tempRatio > ratio)
|
|
{
|
|
ratio = tempRatio;
|
|
searchText = defin.Name;
|
|
}
|
|
}
|
|
sb.AppendLine($"比例:{ratio},查询文本: {searchText}");
|
|
var resultDefinitions = MvdLiteAssists.FindByTypeLabel(data, searchText)
|
|
.Where(def => !string.IsNullOrEmpty(def.Description));
|
|
if (!resultDefinitions.Any())
|
|
{
|
|
MessageBox.Show("未查询到数据", "查询结果");
|
|
return;
|
|
}
|
|
var properties = new Dictionary<string, string>();
|
|
foreach (var entity in resultDefinitions)
|
|
{
|
|
var constraints = entity.Constraints;
|
|
foreach (var cons in constraints)
|
|
{
|
|
properties.Add(cons.PropName, cons.ValueRange);
|
|
sb.AppendLine($"Entity: {entity.Name}, Property: {cons.PropName}, Value: {cons.ValueRange}");
|
|
}
|
|
}
|
|
MessageBox.Show(sb.ToString(), "查询结果");
|
|
}
|
|
private HashSet<string> distinctProperties = new HashSet<string>();
|
|
|
|
private void Export(object sender, RoutedEventArgs e)
|
|
{
|
|
var dir = @$"E:\Users\Zhanggg\Desktop\近期工作\报批报建IFC交付\20250703勘察设计、消防审查、竣工验收三系统面向行业全面更新SZ-IFC模型质检工具包\1.3.1合标质检规则\cbims\ModelCheck\mvdlite";
|
|
var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "输出属性表.csv");
|
|
|
|
foreach (var item in Directory.GetFiles(dir))
|
|
{
|
|
string fileContent = File.ReadAllText(item);
|
|
|
|
var data = MvdLiteAssists.Parse(fileContent);
|
|
var props = MvdLiteAssists.GetDistinctProperties(data);
|
|
foreach (var prop in props)
|
|
{
|
|
if (!distinctProperties.Contains(prop))
|
|
{
|
|
distinctProperties.Add(prop);
|
|
}
|
|
}
|
|
}
|
|
var contents = distinctProperties.Aggregate((a, b) => a + "\n" + b);
|
|
File.WriteAllText(fileName, contents, Encoding.UTF8);
|
|
}
|
|
|
|
private void Test(object sender, RoutedEventArgs e)
|
|
{
|
|
Window1 window1 = new Window1();
|
|
window1.Owner = this;
|
|
window1.ShowDialog();
|
|
}
|
|
}
|
|
}
|