添加项目文件。
This commit is contained in:
29
Sai.RvKits/Converters/IdToNameConverter.cs
Normal file
29
Sai.RvKits/Converters/IdToNameConverter.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
|
||||
using Sai.Toolkit.Mvvm;
|
||||
|
||||
namespace Sai.RvKits.Converters
|
||||
{
|
||||
public class IdToNameConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (parameter is BindingProxy proxy && proxy.Data is Document document && value is ElementId id && (id != ElementId.InvalidElementId))
|
||||
{
|
||||
return document.GetElement(id).Name;
|
||||
}
|
||||
return System.Windows.Data.Binding.DoNothing;
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Sai.RvKits/Converters/Rv2WinColorConverter.cs
Normal file
32
Sai.RvKits/Converters/Rv2WinColorConverter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using Color = System.Windows.Media.Color;
|
||||
|
||||
namespace Sai.RvKits.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Autodesk颜色转Windows系统颜色
|
||||
/// </summary>
|
||||
public class Rv2WinColorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var color = (Autodesk.Revit.DB.Color)value;
|
||||
//if (Autodesk.Revit.DB.SelectedColor.InvalidColorValue)
|
||||
//{
|
||||
//}
|
||||
if (color is { IsValid: true })
|
||||
{
|
||||
var rgb = Color.FromRgb(color.Red, color.Green, color.Blue);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
return new Color();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is Color rgb ? new Autodesk.Revit.DB.Color(rgb.R, rgb.G, rgb.B) : (object)Autodesk.Revit.DB.Color.InvalidColorValue;
|
||||
}
|
||||
}
|
||||
31
Sai.RvKits/Converters/RvConverters.cs
Normal file
31
Sai.RvKits/Converters/RvConverters.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
namespace Sai.RvKits.Converters;
|
||||
|
||||
public static class RvConverters
|
||||
{
|
||||
public static Element ToElement(this ElementId elementId, Document doc)
|
||||
{
|
||||
return doc.GetElement(elementId);
|
||||
}
|
||||
|
||||
public static Category ToCategory(this BuiltInCategory builtInCategory, Document doc)
|
||||
{
|
||||
return Category.GetCategory(doc, builtInCategory);
|
||||
}
|
||||
|
||||
public static BuiltInCategory ToBuiltInCategory(this Category category)
|
||||
{
|
||||
#if REVIT2018 || REVIT2020
|
||||
var builtInCategory = (BuiltInCategory)category.Id.IntegerValue;
|
||||
#elif REVIT2025
|
||||
var builtInCategory = (BuiltInCategory)category.Id.Value;
|
||||
#endif
|
||||
|
||||
return Enum.IsDefined(typeof(BuiltInCategory), builtInCategory)
|
||||
? builtInCategory
|
||||
: throw new ArgumentNullException(nameof(category), "不存在该内建类别");
|
||||
}
|
||||
}
|
||||
95
Sai.RvKits/Converters/RvEnumConverter.cs
Normal file
95
Sai.RvKits/Converters/RvEnumConverter.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
namespace Sai.RvKits.Converters
|
||||
{
|
||||
public class RvEnumConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{ return RvEnumConverter.GetChineseName(value); }
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{ throw new NotImplementedException(); }
|
||||
|
||||
private static string GetChineseName(object obj)
|
||||
{
|
||||
#if REVIT2018
|
||||
if (obj is BuiltInParameter parameter)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(parameter);
|
||||
}
|
||||
else if (obj is BuiltInParameterGroup group)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(group);
|
||||
}
|
||||
else if (obj is UnitType uType)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(uType);
|
||||
}
|
||||
else if (obj is ParameterType pType)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(pType);
|
||||
}
|
||||
#elif REVIT2020
|
||||
if (obj is BuiltInParameter parameter)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(parameter, Autodesk.Revit.ApplicationServices.LanguageType.Chinese_Simplified);
|
||||
}
|
||||
else if (obj is BuiltInCategory category)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(category);
|
||||
}
|
||||
else if (obj is BuiltInParameterGroup group)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(group);
|
||||
}
|
||||
else if (obj is UnitType uType)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(uType);
|
||||
}
|
||||
else if (obj is ParameterType pType)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(pType);
|
||||
}
|
||||
#elif REVIT2025
|
||||
if (obj is BuiltInParameter parameter)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(
|
||||
parameter,
|
||||
Autodesk.Revit.ApplicationServices.LanguageType.Chinese_Simplified);
|
||||
}
|
||||
else if (obj is BuiltInCategory category)
|
||||
{
|
||||
return LabelUtils.GetLabelFor(category);
|
||||
}
|
||||
else if (obj is ForgeTypeId forgeTypeId)
|
||||
{
|
||||
|
||||
if (UnitUtils.IsSymbol(forgeTypeId))
|
||||
{
|
||||
return LabelUtils.GetLabelForSymbol(forgeTypeId);
|
||||
}
|
||||
else if (SpecUtils.IsSpec(forgeTypeId))
|
||||
{
|
||||
return LabelUtils.GetLabelForSpec(forgeTypeId);
|
||||
}
|
||||
else if (UnitUtils.IsUnit(forgeTypeId))
|
||||
{
|
||||
return LabelUtils.GetLabelForUnit(forgeTypeId);
|
||||
}
|
||||
else if (ParameterUtils.IsBuiltInGroup(forgeTypeId))
|
||||
{
|
||||
return LabelUtils.GetLabelForGroup(forgeTypeId);
|
||||
}
|
||||
else if (UnitUtils.GetDiscipline(forgeTypeId).IsValidObject)
|
||||
{
|
||||
return LabelUtils.GetLabelForDiscipline(forgeTypeId);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Sai.RvKits/Converters/SearchTypeValueConverter.cs
Normal file
42
Sai.RvKits/Converters/SearchTypeValueConverter.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Sai.RvKits.Converters
|
||||
{
|
||||
public class SearchTypeValueConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var cellText = values[0] == null ? string.Empty : values[0].ToString();
|
||||
var searchText = values[1] as string;
|
||||
var cell = values[2] as DataGridCell;
|
||||
|
||||
var head = cell?.Column?.Header?.ToString();
|
||||
|
||||
return head is "族类型" && !string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(cellText) ? cellText.Contains(searchText) : (object)false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public class SearchFamilyValueConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var cellText = values[0] == null ? string.Empty : values[0].ToString();
|
||||
var searchText = values[1] as string;
|
||||
var cell = values[2] as DataGridCell;
|
||||
|
||||
var head = cell?.Column?.Header?.ToString();
|
||||
|
||||
return head is "族名称" && !string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(cellText) ? cellText.Contains(searchText) : (object)false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user