81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
|
|
using System.ComponentModel.DataAnnotations;
|
|||
|
|
using System.Windows;
|
|||
|
|
using System.Windows.Input;
|
|||
|
|
|
|||
|
|
using Autodesk.Revit.DB;
|
|||
|
|
using Autodesk.Revit.DB.Electrical;
|
|||
|
|
|
|||
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
|
using CommunityToolkit.Mvvm.Input;
|
|||
|
|
|
|||
|
|
namespace Sai.RvKits.RvMEP;
|
|||
|
|
|
|||
|
|
public partial class CableLayoutViewModel : ObservableValidator
|
|||
|
|
{
|
|||
|
|
private readonly Document doc;
|
|||
|
|
public CableLayoutViewModel(Document doc)
|
|||
|
|
{
|
|||
|
|
this.doc = doc;
|
|||
|
|
specifications = new FilteredElementCollector(doc).OfClass(typeof(ConduitType)).Cast<ConduitType>().ToList();
|
|||
|
|
}
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private ConduitType selectedConduitType;
|
|||
|
|
|
|||
|
|
[Range(1, 20, ErrorMessage = "输入值有误!")]
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyDataErrorInfo]
|
|||
|
|
private int count;
|
|||
|
|
|
|||
|
|
//public int Count
|
|||
|
|
//{
|
|||
|
|
// get => count;
|
|||
|
|
// set => SetProperty(ref count, value, true);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private List<ConduitType> specifications;
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private ConduitSize size;
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private Dictionary<string, ConduitSize> sizes;
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void CloseWin(object obj)
|
|||
|
|
{
|
|||
|
|
if (obj is System.Windows.Window window && Count > 0 && Size != null && SelectedConduitType != null)
|
|||
|
|
{
|
|||
|
|
window.DialogResult = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void SelectionType()
|
|||
|
|
{
|
|||
|
|
var enumerator = ConduitSizeSettings.GetConduitSizeSettings(doc).GetEnumerator();
|
|||
|
|
var standardName = SelectedConduitType.get_Parameter(BuiltInParameter.CONDUIT_STANDARD_TYPE_PARAM).AsValueString();
|
|||
|
|
ConduitSizes sizes = null;
|
|||
|
|
Dictionary<string, ConduitSize> dictionary = new();
|
|||
|
|
while (enumerator.MoveNext())
|
|||
|
|
{
|
|||
|
|
var current = enumerator.Current;
|
|||
|
|
if (current.Key == standardName)
|
|||
|
|
{
|
|||
|
|
sizes = current.Value;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (sizes != null)
|
|||
|
|
{
|
|||
|
|
foreach (var size in sizes)
|
|||
|
|
{
|
|||
|
|
var key = (size.NominalDiameter * 304.8).ToString();
|
|||
|
|
dictionary.Add(key, size);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Sizes = dictionary;
|
|||
|
|
}
|
|||
|
|
}
|