From b5d9f673ae0887a54417776d5d1ba45b644903f1 Mon Sep 17 00:00:00 2001 From: NeVeSpl Date: Thu, 9 May 2024 19:21:20 +0200 Subject: [PATCH] make use of IHaveVisualization.CanBeVisualized in type handlers --- .../Domain/DataModel/SnoopableMember.cs | 2 ++ .../ValueContainers/BoundingBoxXYZHandler.cs | 18 ++++++++++-------- .../ValueContainers/CategoryHandler.cs | 5 ++++- .../ValueContainers/CategoryNameMapHandler.cs | 5 ++++- .../DataModel/ValueContainers/CurveHandler.cs | 11 +++++++---- .../DataModel/ValueContainers/EdgeHandler.cs | 9 +++++++-- .../ValueContainers/ElementHandler.cs | 7 +++++-- .../ValueContainers/ElementIdHandler.cs | 3 +++ .../DataModel/ValueContainers/FaceHandler.cs | 8 ++++++-- .../FailureDefinitionIdHandler.cs | 2 +- .../DataModel/ValueContainers/PointHandler.cs | 1 + .../DataModel/ValueContainers/RebarHandler.cs | 1 + .../DataModel/ValueContainers/SolidHandler.cs | 1 + .../DataModel/ValueContainers/XYZHandler.cs | 1 + sources/RevitDBExplorer/MainWindow.xaml | 2 +- sources/RevitDBExplorer/RevitDBExplorer.csproj | 2 +- .../UIComponents/List/ListView.xaml | 13 +++++++++---- 17 files changed, 64 insertions(+), 27 deletions(-) diff --git a/sources/RevitDBExplorer/Domain/DataModel/SnoopableMember.cs b/sources/RevitDBExplorer/Domain/DataModel/SnoopableMember.cs index faa17b9..1ebd8e6 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/SnoopableMember.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/SnoopableMember.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Windows.Documents; using RevitDBExplorer.Domain.DataModel.Streams.Base; +using RevitDBExplorer.Domain.DataModel.ValueViewModels; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -16,6 +17,7 @@ internal sealed class SnoopableMember : SnoopableItem public override string Name => memberDescriptor.Name; public DocXml Documentation => memberDescriptor.Documentation; public override bool CanGenerateCode => memberDescriptor.Kind != MemberKind.None; + public bool CanBeVisualized => (ValueViewModel as DefaultPresenter)?.ValueContainer?.CanBeVisualized == true; public SnoopableMember(SnoopableObject parent, MemberDescriptor memberDescriptor) : base(parent, memberDescriptor.MemberAccessor) diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundingBoxXYZHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundingBoxXYZHandler.cs index e1ff10e..bb74c38 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundingBoxXYZHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundingBoxXYZHandler.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using Autodesk.Revit.DB; -using RevitExplorer.Visualizations.DrawingVisuals; +using NSourceGenerators; using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; +using RevitExplorer.Visualizations.DrawingVisuals; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -10,11 +11,13 @@ namespace RevitDBExplorer.Domain.DataModel.ValueContainers { internal sealed class BoundingBoxXYZHandler : TypeHandler, IHaveToolTip { - protected override bool CanBeSnoooped(SnoopableContext context, BoundingBoxXYZ box) => box is not null; + protected override bool CanBeSnoooped(SnoopableContext context, BoundingBoxXYZ box) => true; protected override string ToLabel(SnoopableContext context, BoundingBoxXYZ box) { return $"Min({box.Min.X:0.##}, {box.Min.Y:0.##}, {box.Min.Z:0.##}), Max({box.Max.X:0.##}, {box.Max.Y:0.##}, {box.Max.Z:0.##})"; } + + [CodeToString] protected override IEnumerable Snooop(SnoopableContext context, BoundingBoxXYZ box) { yield return new SnoopableObject(context.Document, box); @@ -31,15 +34,14 @@ public string GetToolTip(SnoopableContext context, BoundingBoxXYZ value) WDH({(value.Max.X - value.Min.X).ToLengthDisplayString(units)}, {(value.Max.Y - value.Min.Y).ToLengthDisplayString(units)}, {(value.Max.Z - value.Min.Z).ToLengthDisplayString(units)})"; } - + protected override bool CanBeVisualized(SnoopableContext context, BoundingBoxXYZ value) => true; + [CodeToString] protected override IEnumerable GetVisualization(SnoopableContext context, BoundingBoxXYZ box) { - var bb = box; - - if (bb != null && (bb.Max != null) && (bb.Min != null)) + if ((box.Max != null) && (box.Min != null)) { - var min = box.Transform.OfPoint(bb.Min); - var max = box.Transform.OfPoint(bb.Max); + var min = box.Transform.OfPoint(box.Min); + var max = box.Transform.OfPoint(box.Max); yield return new BoundingBoxDrawingVisual(min, max); } diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryHandler.cs index 99257ce..61d7986 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryHandler.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Autodesk.Revit.DB; +using NSourceGenerators; using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -11,8 +12,10 @@ internal sealed class CategoryHandler : TypeHandler protected override bool CanBeSnoooped(SnoopableContext context, Category category) => category is not null; protected override string ToLabel(SnoopableContext context, Category category) { - return $"{category.Name} ({category.Id})"; + return Labeler.GetLabelForObjectWithId(category.Name, category.Id.Value()); } + + [CodeToString] protected override IEnumerable Snooop(SnoopableContext context, Category category) { yield return new SnoopableObject(context.Document, category); diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryNameMapHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryNameMapHandler.cs index 8300ac5..6151a0c 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryNameMapHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryNameMapHandler.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Autodesk.Revit.DB; +using NSourceGenerators; using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -11,8 +12,10 @@ internal class CategoryNameMapHandler : TypeHandler protected override bool CanBeSnoooped(SnoopableContext context, CategoryNameMap categoryNameMap) => categoryNameMap?.IsEmpty == false; protected override string ToLabel(SnoopableContext context, CategoryNameMap categoryNameMap) { - return $"Categories : {categoryNameMap.Size}"; + return Labeler.GetLabelForCollection("Category", categoryNameMap.Size); } + + [CodeToString] protected override IEnumerable Snooop(SnoopableContext context, CategoryNameMap categoryNameMap) { foreach (Category cat in categoryNameMap) diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CurveHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CurveHandler.cs index a1a333d..0847d02 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CurveHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CurveHandler.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using Autodesk.Revit.DB; -using RevitExplorer.Visualizations.DrawingVisuals; +using NSourceGenerators; using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; +using RevitExplorer.Visualizations.DrawingVisuals; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -10,18 +11,20 @@ namespace RevitDBExplorer.Domain.DataModel.ValueContainers { internal sealed class CurveHandler : TypeHandler { - protected override bool CanBeSnoooped(SnoopableContext context, Curve curve) => curve is not null; + protected override bool CanBeSnoooped(SnoopableContext context, Curve curve) => true; protected override string ToLabel(SnoopableContext context, Curve curve) => curve.GetType()?.GetCSharpName(); + + [CodeToString] protected override IEnumerable Snooop(SnoopableContext context, Curve curve) { yield return new SnoopableObject(context.Document, curve); } - private readonly static Color StartColor = new Color(0, 255, 0); private readonly static Color EndColor = new Color(255, 0, 0); private readonly static Color CurveColor = new Color(80, 175, 228); - + protected override bool CanBeVisualized(SnoopableContext context, Curve curve) => true; + [CodeToString] protected override IEnumerable GetVisualization(SnoopableContext context, Curve curve) { if (curve.IsBound) diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/EdgeHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/EdgeHandler.cs index 92fb505..da62182 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/EdgeHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/EdgeHandler.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using Autodesk.Revit.DB; -using RevitExplorer.Visualizations.DrawingVisuals; +using NSourceGenerators; using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; +using RevitExplorer.Visualizations.DrawingVisuals; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -10,8 +11,10 @@ namespace RevitDBExplorer.Domain.DataModel.ValueContainers { internal sealed class EdgeHandler : TypeHandler { - protected override bool CanBeSnoooped(SnoopableContext context, Edge edge) => edge is not null; + protected override bool CanBeSnoooped(SnoopableContext context, Edge edge) => true; protected override string ToLabel(SnoopableContext context, Edge edge) => edge.GetType()?.GetCSharpName(); + + [CodeToString] protected override IEnumerable Snooop(SnoopableContext context, Edge edge) { yield return new SnoopableObject(context.Document, edge); @@ -22,6 +25,8 @@ protected override IEnumerable Snooop(SnoopableContext context, private readonly static Color EndColor = new Color(255, 0, 0); private readonly static Color CurveColor = new Color(80, 175, 228); + protected override bool CanBeVisualized(SnoopableContext context, Edge edge) => true; + [CodeToString] protected override IEnumerable GetVisualization(SnoopableContext context, Edge edge) { var curve = edge.AsCurve(); diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementHandler.cs index 50a7bd3..cc0e280 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementHandler.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using Autodesk.Revit.DB; -using RevitExplorer.Visualizations.DrawingVisuals; +using NSourceGenerators; using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; +using RevitExplorer.Visualizations.DrawingVisuals; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -29,13 +30,15 @@ protected override string ToLabel(SnoopableContext context, Element element) return $"{elementName} ({element.Id})"; } + [CodeToString] protected override IEnumerable Snooop(SnoopableContext context, Element element) { var freshElement = context.Document?.GetElement(element.Id) ?? element; yield return new SnoopableObject(context.Document, freshElement); } - + protected override bool CanBeVisualized(SnoopableContext context, Element element) => element is not ElementType; + [CodeToString] protected override IEnumerable GetVisualization(SnoopableContext context, Element element) { var bb = element.get_BoundingBox(null); diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementIdHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementIdHandler.cs index aaff495..1ff4f77 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementIdHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementIdHandler.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Autodesk.Revit.DB; +using NSourceGenerators; using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -37,6 +38,8 @@ protected override string ToLabel(SnoopableContext context, ElementId id) } return $"{id}"; } + + [CodeToString] protected override IEnumerable Snooop(SnoopableContext context, ElementId id) { yield return new SnoopableObject(context.Document, id); diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FaceHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FaceHandler.cs index 8d5bc5c..1d2073e 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FaceHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FaceHandler.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using Autodesk.Revit.DB; -using RevitExplorer.Visualizations.DrawingVisuals; +using NSourceGenerators; using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; +using RevitExplorer.Visualizations.DrawingVisuals; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -10,8 +11,9 @@ namespace RevitDBExplorer.Domain.DataModel.ValueContainers { internal sealed class FaceHandler : TypeHandler { - protected override bool CanBeSnoooped(SnoopableContext context, Face face) => face is not null; + protected override bool CanBeSnoooped(SnoopableContext context, Face face) => true; protected override string ToLabel(SnoopableContext context, Face face) => face.GetType()?.GetCSharpName(); + protected override IEnumerable Snooop(SnoopableContext context, Face face) { yield return new SnoopableObject(context.Document, face); @@ -20,6 +22,8 @@ protected override IEnumerable Snooop(SnoopableContext context, private readonly static Color FaceColor = new Color(80, 175, 228); + protected override bool CanBeVisualized(SnoopableContext context, Face face) => true; + [CodeToString] protected override IEnumerable GetVisualization(SnoopableContext context, Face face) { yield return new FaceDrawingVisual(face, FaceColor); diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FailureDefinitionIdHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FailureDefinitionIdHandler.cs index 01239dc..fd3c0eb 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FailureDefinitionIdHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FailureDefinitionIdHandler.cs @@ -13,11 +13,11 @@ protected override bool CanBeSnoooped(SnoopableContext context, FailureDefinitio { return true; } - protected override string ToLabel(SnoopableContext context, FailureDefinitionId value) { return $"FailureDefinitionId ({value.Guid})"; } + protected override IEnumerable Snooop(SnoopableContext context, FailureDefinitionId value) { var failure = ControlledApplication.GetFailureDefinitionRegistry().FindFailureDefinition(value); diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/PointHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/PointHandler.cs index c248976..1a37572 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/PointHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/PointHandler.cs @@ -21,6 +21,7 @@ protected override IEnumerable Snooop(SnoopableContext context, private readonly static Color PointColor = new Color(80, 175, 228); + protected override bool CanBeVisualized(SnoopableContext context, Point point) => true; protected override IEnumerable GetVisualization(SnoopableContext context, Point point) { XYZ coord = point.Coord; diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/RebarHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/RebarHandler.cs index bc94dc0..d2f4eee 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/RebarHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/RebarHandler.cs @@ -29,6 +29,7 @@ protected override IEnumerable Snooop(SnoopableContext context, private readonly static Color StartColor = new Color(0, 255, 0); private readonly static Color EndColor = new Color(255, 0, 0); + protected override bool CanBeVisualized(SnoopableContext context, Rebar rebar) => true; protected override IEnumerable GetVisualization(SnoopableContext context, Rebar rebar) { if (rebar.IsRebarShapeDriven()) diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/SolidHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/SolidHandler.cs index 1da398d..2e7d38b 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/SolidHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/SolidHandler.cs @@ -21,6 +21,7 @@ protected override IEnumerable Snooop(SnoopableContext context, private readonly static Color SolidColor = new Color(80, 175, 228); + protected override bool CanBeVisualized(SnoopableContext context, Solid solid) => true; protected override IEnumerable GetVisualization(SnoopableContext context, Solid solid) { yield return new SolidDrawingVisual(solid, SolidColor); diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/XYZHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/XYZHandler.cs index 50a3905..ae20fb4 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/XYZHandler.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/XYZHandler.cs @@ -24,6 +24,7 @@ public string GetToolTip(SnoopableContext context, XYZ xyz) return $"{ToLabel(context, xyz)}\n({xyz.X.ToLengthDisplayString(units)}, {xyz.Y.ToLengthDisplayString(units)},{xyz.Z.ToLengthDisplayString(units)})"; ; } + protected override bool CanBeVisualized(SnoopableContext context, XYZ xyz) => true; protected override IEnumerable GetVisualization(SnoopableContext context, XYZ xyz) { yield return new CoordinateSystemDrawingVisual(xyz); diff --git a/sources/RevitDBExplorer/MainWindow.xaml b/sources/RevitDBExplorer/MainWindow.xaml index 9616745..4eb29d2 100644 --- a/sources/RevitDBExplorer/MainWindow.xaml +++ b/sources/RevitDBExplorer/MainWindow.xaml @@ -280,7 +280,7 @@ - + diff --git a/sources/RevitDBExplorer/RevitDBExplorer.csproj b/sources/RevitDBExplorer/RevitDBExplorer.csproj index 3873c5f..108e889 100644 --- a/sources/RevitDBExplorer/RevitDBExplorer.csproj +++ b/sources/RevitDBExplorer/RevitDBExplorer.csproj @@ -71,7 +71,7 @@ - + diff --git a/sources/RevitDBExplorer/UIComponents/List/ListView.xaml b/sources/RevitDBExplorer/UIComponents/List/ListView.xaml index 264ea13..2c55c32 100644 --- a/sources/RevitDBExplorer/UIComponents/List/ListView.xaml +++ b/sources/RevitDBExplorer/UIComponents/List/ListView.xaml @@ -95,7 +95,7 @@ -