添加项目文件。
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Electrical;
|
||||
using Autodesk.Revit.DB.Mechanical;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using Szmedi.RevitToolkit.Approval.Models;
|
||||
|
||||
namespace Szmedi.RevitToolkit.Approval.ViewModels
|
||||
{
|
||||
public partial class ReviewArchiSignViewModel : ObservableObject
|
||||
{
|
||||
|
||||
public ReviewArchiSignViewModel(Document doc)
|
||||
{
|
||||
var allElements = doc.OfParentModelCollector();
|
||||
if (allElements == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SelectedMajor = doc.GetMajor(out string major);
|
||||
|
||||
var reviewItems = allElements.Select(e => new ReviewItem(e)).OrderBy(item => item.Element.Category.Name);
|
||||
|
||||
var spaces = new FilteredElementCollector(doc).OfClass(typeof(SpatialElement)).WhereElementIsNotElementType();
|
||||
var reviewSpaceItems = spaces.Select(e => new ReviewItem(e, "深圳空间标识")).OrderBy(item => item.Element.Category.Name);
|
||||
|
||||
var systems = new FilteredElementCollector(doc).OfClass(typeof(MEPSystem)).WhereElementIsNotElementType();
|
||||
var reviewSystemItems = systems.Select(e => new ReviewItem(e, "深圳系统标识")).OrderBy(item => item.Element.Category.Name);
|
||||
Items = [.. reviewSpaceItems, .. reviewSystemItems, .. reviewItems];
|
||||
CollectionViewSource.GetDefaultView(Items).GroupDescriptions.Add(new PropertyGroupDescription("Sign"));
|
||||
|
||||
var contents = IOAssists.GetMvdLiteContent(SelectedMajor);
|
||||
var data = MvdLiteAssist.Parse(contents);
|
||||
Signs = MvdLiteAssist.GetElementSigns(data);
|
||||
//SignCollectionView = CollectionViewSource.GetDefaultView(Signs);
|
||||
SignCollectionView = new CollectionViewSource() { Source = Signs }.View;
|
||||
//var contents = IOAssists.GetMvdLiteContent(SelectedMajor);
|
||||
//var data = MvdLiteAssist.Parse(major);
|
||||
//Signs = MvdLiteAssist.GetElementSigns(data);
|
||||
|
||||
}
|
||||
[ObservableProperty]
|
||||
public partial Major SelectedMajor { get; set; }
|
||||
|
||||
public HashSet<string> OriginalSigns => Signs;
|
||||
|
||||
partial void OnSelectedMajorChanged(Major value)
|
||||
{
|
||||
var contents = IOAssists.GetMvdLiteContent(value);
|
||||
var data = MvdLiteAssist.Parse(contents);
|
||||
Signs = MvdLiteAssist.GetElementSigns(data);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string signText;
|
||||
partial void OnSignTextChanged(string? oldValue, string? newValue)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(newValue))
|
||||
{
|
||||
SignCollectionView.Filter = x => (x.ToString()).IndexOf(newValue, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SignCollectionView.Filter = null;
|
||||
}
|
||||
OnPropertyChanged(nameof(SignCollectionView));
|
||||
}
|
||||
[ObservableProperty]
|
||||
public partial HashSet<string> Signs { get; set; }
|
||||
//[ObservableProperty]
|
||||
//private Dictionary<string, List<Element>> keyValues;
|
||||
//[ObservableProperty]
|
||||
public ObservableCollection<ReviewItem> Items { get; set; }
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(BatchModifySignsCommand))]
|
||||
private string selectedSign;
|
||||
|
||||
public ICollectionView SignCollectionView { get; }
|
||||
|
||||
private bool CanModifySigns => !string.IsNullOrEmpty(SelectedSign);
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanModifySigns))]
|
||||
private void BatchModifySigns(object obj)
|
||||
{
|
||||
if (obj is IList items)
|
||||
{
|
||||
foreach (ReviewItem item in items)
|
||||
{
|
||||
item.Sign = SelectedSign;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
private void PreviewTextInput(TextCompositionEventArgs args)
|
||||
{
|
||||
//signCollectionView.Filter = o =>
|
||||
//{
|
||||
// if (o is string str)
|
||||
// {
|
||||
// return FuzzySharp.Fuzz.PartialRatio(str, args.Text) > 0;
|
||||
// }
|
||||
// return false;
|
||||
//};
|
||||
if (args != null && args.Source is System.Windows.Controls.ComboBox cb)
|
||||
{
|
||||
if (cb.Text == cb.SelectedItem?.ToString())
|
||||
{
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
[RelayCommand]
|
||||
private void ShowElement(object obj)
|
||||
{
|
||||
if (obj is not ReviewItem model)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Element.IsValidObject)
|
||||
{
|
||||
|
||||
RvApp.Handler.Raise(uiapp =>
|
||||
{
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
var doc = uidoc.Document;
|
||||
List<ElementId> ids = [model.Element.Id];
|
||||
//if (model.Element.IsHidden(uidoc.ActiveView))
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
if (uidoc.ActiveView is not View3D view3d)
|
||||
{
|
||||
view3d =
|
||||
doc.QueryElementsByType<View3D>()
|
||||
.FirstOrDefault(e => FilteredElementCollector.IsViewValidForElementIteration(doc, e.Id)) as View3D;
|
||||
}
|
||||
|
||||
uidoc.ActiveView = view3d;
|
||||
|
||||
doc.Invoke(_ =>
|
||||
{
|
||||
var box = model.Element.get_BoundingBox(uidoc.ActiveGraphicalView);
|
||||
var uiView = uidoc.GetOpenUIViews().FirstOrDefault(v => v.ViewId == uidoc.ActiveGraphicalView.Id);
|
||||
XYZ extendXyz = new(1, 1, 1);
|
||||
uiView?.ZoomAndCenterRectangle(box.Min - extendXyz, box.Max + extendXyz);
|
||||
uidoc.Selection.SetElementIds(ids);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Items.Remove(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user