224 lines
8.4 KiB
C#
224 lines
8.4 KiB
C#
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Windows;
|
|||
|
|
|
|||
|
|
using Autodesk.Revit.DB;
|
|||
|
|
|
|||
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
|
using CommunityToolkit.Mvvm.Input;
|
|||
|
|
|
|||
|
|
using Nice3point.Revit.Toolkit.External.Handlers;
|
|||
|
|
|
|||
|
|
using Szmedi.RevitToolkit.Approval.Models;
|
|||
|
|
using Szmedi.Toolkit.Revit.Approval;
|
|||
|
|
|
|||
|
|
namespace Szmedi.RevitToolkit.Approval.ViewModels
|
|||
|
|
{
|
|||
|
|
public partial class FillMetroParametersViewModel : ObservableObject
|
|||
|
|
{
|
|||
|
|
private readonly List<MetroNode> allClassifications;
|
|||
|
|
//private readonly SQLiteConnection cnn;
|
|||
|
|
|
|||
|
|
//[ObservableProperty]
|
|||
|
|
//private MetroPropTable baseTable;
|
|||
|
|
//private const string id = "深圳构件标识";
|
|||
|
|
|
|||
|
|
//private const string code = "AM-100-EAM分类编码";
|
|||
|
|
//[ObservableProperty]
|
|||
|
|
//private List<MetroPropTable> metroPropTables;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
public partial List<MetroNode> ClassHierarchicalData { get; set; }
|
|||
|
|
|
|||
|
|
//private readonly ActionEventHandler handler;
|
|||
|
|
|
|||
|
|
//[ObservableProperty]
|
|||
|
|
//public partial Dictionary<string, List<Element>> KeyValues { get; set; }
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
public partial ObservableCollection<AfcaMetroBaseParameter> PropertyCollection { get; set; }
|
|||
|
|
|
|||
|
|
//private readonly IEnumerable<MetroBaseProperty> baseProps;
|
|||
|
|
|
|||
|
|
public FillMetroParametersViewModel()
|
|||
|
|
{
|
|||
|
|
//PropertyDictionary = GlobalAssists.GetArchiMajorParameters(value);
|
|||
|
|
|
|||
|
|
allClassifications = GlobalAssists.GetMetroClassificationModels().Where(c => !string.IsNullOrEmpty(c.CategoryName)).ToList();
|
|||
|
|
ClassHierarchicalData = GlobalAssists.InitTreeViewSource(allClassifications, true);
|
|||
|
|
//handler = new ActionEventHandler();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void GetProperties(MetroNode model)
|
|||
|
|
{
|
|||
|
|
if (model != null)
|
|||
|
|
{
|
|||
|
|
PropertyCollection?.Clear();
|
|||
|
|
//通用属性
|
|||
|
|
var baseProps = GlobalAssists.GetMetroCommonParameters();
|
|||
|
|
if (model.Parent == null)
|
|||
|
|
{
|
|||
|
|
var list = new List<AfcaMetroBaseParameter>();
|
|||
|
|
//var baseProps = cnn.GetList<MetroBaseProperty>();
|
|||
|
|
list.AddRange(baseProps);
|
|||
|
|
PropertyCollection = [.. list];
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (model.Children.Count == 0)
|
|||
|
|
{
|
|||
|
|
var list = new List<AfcaMetroBaseParameter>();
|
|||
|
|
//var baseProps = cnn.GetList<MetroBaseProperty>();
|
|||
|
|
list.AddRange(baseProps);
|
|||
|
|
|
|||
|
|
var dedicatedProps = model.Properties;
|
|||
|
|
list.AddRange(dedicatedProps);
|
|||
|
|
PropertyCollection = [.. list];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string GetSign(Element e)
|
|||
|
|
{
|
|||
|
|
var list = e.GetParameters("深圳构件标识");
|
|||
|
|
string str = default;
|
|||
|
|
if (list.Any())
|
|||
|
|
{
|
|||
|
|
foreach (var param in list)
|
|||
|
|
{
|
|||
|
|
str = param.AsString();
|
|||
|
|
if (string.IsNullOrEmpty(str))
|
|||
|
|
{
|
|||
|
|
str = "未定义";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return str;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return "未定义";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void ManualProcess(MetroNode model)
|
|||
|
|
{
|
|||
|
|
RvApp.Handler.Raise(
|
|||
|
|
uiapp =>
|
|||
|
|
{
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
var uidoc = uiapp.ActiveUIDocument;
|
|||
|
|
var doc = uidoc.Document;
|
|||
|
|
var elems = uidoc.Selection.PickElementsByRectangle("请框选元素!");
|
|||
|
|
if (model == null)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("请选择分类节点");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (model.Children.Count > 0)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("请选择子节点");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
doc.Invoke(
|
|||
|
|
ts =>
|
|||
|
|
{
|
|||
|
|
foreach (var item in elems)
|
|||
|
|
{
|
|||
|
|
var paras = item.GetParameters("深圳构件标识");
|
|||
|
|
if (!paras.Any())
|
|||
|
|
{
|
|||
|
|
sb.AppendLine($"{item.Id} {item.Name}未定义参数:深圳构件标识");
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
var parameters = paras.Where(p => !p.IsReadOnly).ToList();
|
|||
|
|
foreach (var param in parameters)
|
|||
|
|
{
|
|||
|
|
param.Set(model.CategoryName);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var codesParams = item.GetParameters("AM-100-EAM分类编码");
|
|||
|
|
var classification =
|
|||
|
|
allClassifications.FirstOrDefault(d => d.CategoryName == model.CategoryName);
|
|||
|
|
if (codesParams.Count <= 0)
|
|||
|
|
{
|
|||
|
|
sb.AppendLine($"{item.Id} {item.Name}未定义参数:AM-100-EAM分类编码");
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
foreach (var param in codesParams.Where(p => !p.IsReadOnly))
|
|||
|
|
{
|
|||
|
|
param.SetValue(classification?.Code);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
"手动修改标识&编码");
|
|||
|
|
if (sb.Length > 0)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show(sb.ToString(), "部分元素处理失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("处理完成", "完成");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand(CanExecute = nameof(CanModify))]
|
|||
|
|
private void ModifyParameterValue()
|
|||
|
|
{
|
|||
|
|
RvApp.Handler
|
|||
|
|
.Raise(
|
|||
|
|
uiapp =>
|
|||
|
|
{
|
|||
|
|
CanModify = false;
|
|||
|
|
var uidoc = uiapp.ActiveUIDocument;
|
|||
|
|
var doc = uidoc.Document;
|
|||
|
|
//doc.OfParentModelCollector
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
doc.Invoke(
|
|||
|
|
ts =>
|
|||
|
|
{
|
|||
|
|
var elements = uidoc.Selection
|
|||
|
|
.PickElementsByRectangle(
|
|||
|
|
new FuncFilter(
|
|||
|
|
e => e.Category is { CategoryType: CategoryType.Model, AllowsBoundParameters: true, Parent: null }),
|
|||
|
|
"请选择要填写参数值的构件");
|
|||
|
|
foreach (var elem in elements)
|
|||
|
|
{
|
|||
|
|
foreach (var prop in Properties)
|
|||
|
|
{
|
|||
|
|
var param = elem.LookupParameter(prop.ParamName);
|
|||
|
|
param.SetValue(prop.ParamValue);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
"填写轨交工程参数");
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|||
|
|
//CanModify = true;
|
|||
|
|
}
|
|||
|
|
CanModify = true;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(ModifyParameterValueCommand))]
|
|||
|
|
public partial bool CanModify { get; set; }
|
|||
|
|
|
|||
|
|
//public FillMetroParametersViewModel()
|
|||
|
|
//{
|
|||
|
|
//}
|
|||
|
|
[ObservableProperty]
|
|||
|
|
public partial List<AfcaMetroBaseParameter> Properties { get; set; }
|
|||
|
|
}
|
|||
|
|
}
|