添加项目文件。
This commit is contained in:
343
Szmedi.RvKits/InfoManager/Delivery/MetroParamManagerViewModel.cs
Normal file
343
Szmedi.RvKits/InfoManager/Delivery/MetroParamManagerViewModel.cs
Normal file
@@ -0,0 +1,343 @@
|
||||
|
||||
using Autodesk.Revit.UI;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
using System.Windows;
|
||||
|
||||
using Szmedi.RvKits.Assists;
|
||||
using Szmedi.RvKits.InfoManager.Delivery;
|
||||
using Szmedi.RvKits.Models;
|
||||
|
||||
namespace Szmedi.RvKits.InfoManager
|
||||
{
|
||||
public partial class MetroParamManagerViewModel : ObservableObject
|
||||
{
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(AddParametersCommand))]
|
||||
private bool canAdd;
|
||||
private readonly List<MetroCommonParamData> commonParams;
|
||||
|
||||
private readonly DapperUtil dapperUtil;
|
||||
private readonly ActionEventHandler handler;
|
||||
/// <summary>
|
||||
/// 添加通用属性
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool isAddCommonParam = true;
|
||||
/// <summary>
|
||||
/// 是否族参数
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool isFamilyParam;
|
||||
/// <summary>
|
||||
/// 是否共享族参数
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool isSharedFamilyParam;
|
||||
/// <summary>
|
||||
/// 共享项目参数
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool isSharedProjectParam = true;
|
||||
private readonly List<ParamData> paramsToAdd;
|
||||
private readonly UIApplication uiapp;
|
||||
//public ParamManagerWin ParentWindow { get; set; }
|
||||
|
||||
//public MetroParamManagerViewModel(ParamManagerWin parentWindow)
|
||||
//{
|
||||
// ParentWindow = parentWindow;
|
||||
// dapperUtil = parentWindow.DapperUtil;
|
||||
// List<ParamData> dedicatedParams = GetMetroDedicatedProperties();
|
||||
// commonParams = GetMetroCommonProperties();
|
||||
// MetroSharedParams = GetMetroSharedParams();
|
||||
// GenerateMetroDedicatedPropTree(dedicatedParams);
|
||||
// CanAdd = paramsToAdd.Count > 0;
|
||||
//}
|
||||
public MetroParamManagerViewModel(UIApplication uiapp, DapperUtil dapperUtil, ActionEventHandler handler)
|
||||
{
|
||||
this.dapperUtil = dapperUtil;
|
||||
this.handler = handler;
|
||||
this.uiapp = uiapp;
|
||||
List<MetroDedicatedParamData> dedicatedParams = GetMetroDedicatedProperties();
|
||||
commonParams = GetMetroCommonProperties();
|
||||
MetroSharedParams = GetMetroSharedParams();
|
||||
GenerateMetroDedicatedPropTree(dedicatedParams);
|
||||
paramsToAdd = new List<ParamData>();
|
||||
CanAdd = paramsToAdd.Count > 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AddParameters()
|
||||
{
|
||||
if (paramsToAdd.Any())
|
||||
{
|
||||
handler.Raise(
|
||||
uiapp =>
|
||||
{
|
||||
|
||||
if (paramsToAdd.Any())
|
||||
{
|
||||
if (IsAddCommonParam)
|
||||
{
|
||||
paramsToAdd.AddRange(commonParams);
|
||||
}
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
var filePath = Path.Combine(GlobalVariables.DirAssembly, $"TempSharedParameters.txt");
|
||||
if (IsSharedProjectParam)
|
||||
{
|
||||
ParameterHelpers.AddParameterElementsBinding(uidoc, paramsToAdd, MetroSharedParams, filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParameterHelpers.AddFamilyParameters(uidoc, paramsToAdd, MetroSharedParams, IsFamilyParam, filePath);
|
||||
}
|
||||
}
|
||||
});
|
||||
//ParentWindow.AddParameterEventHandler.IsSharedProjectParam = IsSharedProjectParam;
|
||||
//ParentWindow.AddParameterEventHandler.IsFamilyParam = IsFamilyParam;
|
||||
//ParentWindow.AddParameterEventHandler.IsSharedFamilyParam = IsSharedFamilyParam;
|
||||
//ParentWindow.AddParameterEventHandler.ParametersToAdded = paramsToAdd;
|
||||
//ParentWindow.AddParameterEventHandler.SharedParameters = MetroSharedParams;
|
||||
//ParentWindow.AddParameterEvent.Raise();
|
||||
}
|
||||
|
||||
//CanAdd = x != ExternalEventRequest.Accepted;
|
||||
}
|
||||
|
||||
//private void PerformCheckedAll(object obj)
|
||||
//{
|
||||
// if (obj is List<ParamData>)
|
||||
// {
|
||||
// List<ParamData> paramters = obj as List<ParamData>;
|
||||
// foreach (ParamData param in paramters)
|
||||
// {
|
||||
// param.IsChecked = true;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteParameters()
|
||||
{
|
||||
MessageBoxResult result = MessageBox.Show("是否清理所有轨道交通标准参数?", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
|
||||
|
||||
if (result == MessageBoxResult.OK)
|
||||
{
|
||||
//ParentWindow.DeleteElementsParamEvent.Raise();
|
||||
handler.Raise(
|
||||
uiapp =>
|
||||
{
|
||||
ParameterHelpers.RemoveMetroParameters(uiapp.ActiveUIDocument.Document);
|
||||
});
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 专项属性
|
||||
/// </summary>
|
||||
/// <param name="paramsData"></param>
|
||||
private void GenerateMetroDedicatedPropTree(IList<MetroDedicatedParamData> paramsData)
|
||||
{
|
||||
var projects = paramsData.GroupBy(param => param.Project);
|
||||
foreach (var project in projects)
|
||||
{
|
||||
//项目
|
||||
List<TreeModel> projectChildren = new();
|
||||
TreeModel projectTreeModel =
|
||||
new()
|
||||
{
|
||||
Name = project.Key,
|
||||
Icon = null,
|
||||
IsChecked = false,
|
||||
IsExpanded = true,
|
||||
Parent = null,
|
||||
Children = projectChildren,
|
||||
Tag = null
|
||||
};
|
||||
Models.Add(projectTreeModel);
|
||||
//专业
|
||||
IEnumerable<IGrouping<string, MetroDedicatedParamData>> majors = project.GroupBy(p => p.Major);
|
||||
foreach (var major in majors)
|
||||
{
|
||||
List<TreeModel> majorChildren = new();
|
||||
TreeModel majorTreeModel =
|
||||
new()
|
||||
{
|
||||
Name = major.Key,
|
||||
Icon = null,
|
||||
IsChecked = false,
|
||||
IsExpanded = false,
|
||||
Children = majorChildren,
|
||||
Tag = null
|
||||
};
|
||||
projectChildren.Add(majorTreeModel);
|
||||
//构件
|
||||
var components = major.GroupBy(p => p.Component);
|
||||
foreach (var component in components)
|
||||
{
|
||||
TreeModel componentTreeModel =
|
||||
new()
|
||||
{
|
||||
Id = null,
|
||||
Name = component.Key,
|
||||
Icon = null,
|
||||
IsExpanded = false,
|
||||
Parent = null,
|
||||
Children = null,
|
||||
Tag = component.ToList()
|
||||
};
|
||||
majorChildren.Add(componentTreeModel);
|
||||
|
||||
//属性分类
|
||||
//var propertyCategories = component.GroupBy(p => p.PropertyCategory);
|
||||
//foreach (var category in propertyCategories)
|
||||
//{
|
||||
// List<TreeModel> categoryChildren = new List<TreeModel>();
|
||||
// TreeModel categoryTreeModel = new TreeModel
|
||||
// {
|
||||
// Id = null,
|
||||
// Name = category.Key,
|
||||
// Icon = null,
|
||||
// IsChecked = false,
|
||||
// IsExpanded = false,
|
||||
// Parent = null,
|
||||
// Children = categoryChildren,
|
||||
// Tag = category
|
||||
// };
|
||||
|
||||
// componentChildren.Add(categoryTreeModel);
|
||||
// //属性分组
|
||||
// var groups = category.GroupBy(p => p.PropertyGroup);
|
||||
// foreach (var ZoomRBGroup in groups)
|
||||
// {
|
||||
// List<TreeModel> groupChildren = new List<TreeModel>();
|
||||
// TreeModel groupTreeModel = new TreeModel
|
||||
// {
|
||||
// Id = null,
|
||||
// Name = ZoomRBGroup.Key,
|
||||
// Icon = null,
|
||||
// IsChecked = false,
|
||||
// IsExpanded = false,
|
||||
// Parent = null,
|
||||
// Children = groupChildren,
|
||||
// Tag = ZoomRBGroup
|
||||
// };
|
||||
// categoryChildren.Add(groupTreeModel);
|
||||
// //属性
|
||||
// var properties = ZoomRBGroup.GroupBy(p => p.FullProperty);
|
||||
// foreach (var property in properties)
|
||||
// {
|
||||
// TreeModel propertyTreeModel = new TreeModel
|
||||
// {
|
||||
// Id = null,
|
||||
// Name = property.Key,
|
||||
// Icon = null,
|
||||
// IsChecked = false,
|
||||
// IsExpanded = false,
|
||||
// Parent = null,
|
||||
// Tag = property
|
||||
// };
|
||||
// groupChildren.Add(propertyTreeModel);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 轨交通用属性
|
||||
/// </summary>
|
||||
private List<MetroCommonParamData> GetMetroCommonProperties()
|
||||
{
|
||||
return dapperUtil.LoadModel<MetroCommonParamData>("metro_common_properties");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轨交专项属性
|
||||
/// </summary>
|
||||
private List<MetroDedicatedParamData> GetMetroDedicatedProperties()
|
||||
{
|
||||
return dapperUtil.LoadModel<MetroDedicatedParamData>("metro_dedicated_properties");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轨交共享参数
|
||||
/// </summary>
|
||||
private List<SharedParameterData> GetMetroSharedParams()
|
||||
{
|
||||
return dapperUtil.LoadModel<SharedParameterData>("metro_shared_params");
|
||||
}
|
||||
//partial void OnIsAddCommonParamChanged(bool oldValue, bool newValue)
|
||||
//{
|
||||
// if (newValue)
|
||||
// {
|
||||
// paramsToAdd.AddRange(commonParams);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// foreach (var item in commonParams)
|
||||
// {
|
||||
// var data = paramsToAdd.Find(d => item.FullProperty == d.FullProperty);
|
||||
// paramsToAdd.Remove(data);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
[RelayCommand]
|
||||
private void TreeItemChanged(object obj)
|
||||
{
|
||||
if (obj is List<MetroDedicatedParamData> parameters)
|
||||
{
|
||||
paramsToAdd.Clear();
|
||||
if (parameters.Any())
|
||||
{
|
||||
paramsToAdd.AddRange(parameters.Where(param => param.IsChecked == true));
|
||||
}
|
||||
}
|
||||
|
||||
CanAdd = paramsToAdd.Any() && !uiapp.ActiveUIDocument.Document.IsFamilyDocument;
|
||||
}
|
||||
//private RelayCommand deleteParameters;
|
||||
//private RelayCommand<object> addParameters;
|
||||
//private RelayCommand<object> checkAll;
|
||||
|
||||
//private RelayCommand<object> treeItemChanged;
|
||||
//private RelayCommand<object> unCheckAll;
|
||||
|
||||
//public ICommand CheckAll
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// checkAll ??= new RelayCommand<object>(PerformCheckedAll);
|
||||
|
||||
// return checkAll;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public ICommand UnCheckAll => unCheckAll ??= new RelayCommand<object>(PerformUnCheckedAll);
|
||||
|
||||
public List<SharedParameterData> MetroSharedParams { get; set; }
|
||||
|
||||
public List<TreeModel> Models { get; } = new List<TreeModel>();
|
||||
|
||||
//private void PerformUnCheckedAll(object obj)
|
||||
//{
|
||||
// if (obj is List<ParamData>)
|
||||
// {
|
||||
// List<ParamData> paramters = obj as List<ParamData>;
|
||||
// foreach (ParamData param in paramters)
|
||||
// {
|
||||
// param.IsChecked = false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user