Skip to content

Commit

Permalink
make use of IHaveVisualization.CanBeVisualized in type handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed May 9, 2024
1 parent 41f7b01 commit b5d9f67
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 27 deletions.
2 changes: 2 additions & 0 deletions sources/RevitDBExplorer/Domain/DataModel/SnoopableMember.cs
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
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

namespace RevitDBExplorer.Domain.DataModel.ValueContainers
{
internal sealed class BoundingBoxXYZHandler : TypeHandler<BoundingBoxXYZ>, IHaveToolTip<BoundingBoxXYZ>
{
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<SnoopableObject> Snooop(SnoopableContext context, BoundingBoxXYZ box)
{
yield return new SnoopableObject(context.Document, box);
Expand All @@ -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<DrawingVisual> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,8 +12,10 @@ internal sealed class CategoryHandler : TypeHandler<Category>
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<SnoopableObject> Snooop(SnoopableContext context, Category category)
{
yield return new SnoopableObject(context.Document, category);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,8 +12,10 @@ internal class CategoryNameMapHandler : TypeHandler<CategoryNameMap>
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<SnoopableObject> Snooop(SnoopableContext context, CategoryNameMap categoryNameMap)
{
foreach (Category cat in categoryNameMap)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
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

namespace RevitDBExplorer.Domain.DataModel.ValueContainers
{
internal sealed class CurveHandler : TypeHandler<Curve>
{
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<SnoopableObject> 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<DrawingVisual> GetVisualization(SnoopableContext context, Curve curve)
{
if (curve.IsBound)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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

namespace RevitDBExplorer.Domain.DataModel.ValueContainers
{
internal sealed class EdgeHandler : TypeHandler<Edge>
{
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<SnoopableObject> Snooop(SnoopableContext context, Edge edge)
{
yield return new SnoopableObject(context.Document, edge);
Expand All @@ -22,6 +25,8 @@ protected override IEnumerable<SnoopableObject> 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<DrawingVisual> GetVisualization(SnoopableContext context, Edge edge)
{
var curve = edge.AsCurve();
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -29,13 +30,15 @@ protected override string ToLabel(SnoopableContext context, Element element)
return $"{elementName} ({element.Id})";
}

[CodeToString]
protected override IEnumerable<SnoopableObject> 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<DrawingVisual> GetVisualization(SnoopableContext context, Element element)
{
var bb = element.get_BoundingBox(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,6 +38,8 @@ protected override string ToLabel(SnoopableContext context, ElementId id)
}
return $"{id}";
}

[CodeToString]
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, ElementId id)
{
yield return new SnoopableObject(context.Document, id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
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

namespace RevitDBExplorer.Domain.DataModel.ValueContainers
{
internal sealed class FaceHandler : TypeHandler<Face>
{
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<SnoopableObject> Snooop(SnoopableContext context, Face face)
{
yield return new SnoopableObject(context.Document, face);
Expand All @@ -20,6 +22,8 @@ protected override IEnumerable<SnoopableObject> 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<DrawingVisual> GetVisualization(SnoopableContext context, Face face)
{
yield return new FaceDrawingVisual(face, FaceColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SnoopableObject> Snooop(SnoopableContext context, FailureDefinitionId value)
{
var failure = ControlledApplication.GetFailureDefinitionRegistry().FindFailureDefinition(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected override IEnumerable<SnoopableObject> 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<DrawingVisual> GetVisualization(SnoopableContext context, Point point)
{
XYZ coord = point.Coord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected override IEnumerable<SnoopableObject> 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<DrawingVisual> GetVisualization(SnoopableContext context, Rebar rebar)
{
if (rebar.IsRebarShapeDriven())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected override IEnumerable<SnoopableObject> 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<DrawingVisual> GetVisualization(SnoopableContext context, Solid solid)
{
yield return new SolidDrawingVisual(solid, SolidColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DrawingVisual> GetVisualization(SnoopableContext context, XYZ xyz)
{
yield return new CoordinateSystemDrawingVisual(xyz);
Expand Down
2 changes: 1 addition & 1 deletion sources/RevitDBExplorer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
<ToggleButton Style="{StaticResource ToolTooggle}" IsChecked="{Binding IsRDVEnabled}" Padding="0" Background="red" ToolTip="Show visualization for the selected object in the Tree">
<Grid Background="#FEFCF7" Height="19" Width="38" >
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="V" Foreground="#1434CB" FontWeight="Heavy" FontFamily="Arial" FontSize="15"/>
<TextBlock Text="V" Foreground="#1434CB" FontWeight="Heavy" FontFamily="Arial" FontSize="15" ToolTip="This item has visualization"/>
<Grid>
<TextBlock Text=":on " Visibility="{Binding IsRDVEnabled, Converter={StaticResource BoolToVisibilityConverterHidden}}" Foreground="Black" VerticalAlignment="Bottom"/>
<TextBlock Text=":off " Visibility="{Binding IsRDVEnabled, Converter={StaticResource BoolToVisibilityConverterHiddenInverted}}" Foreground="Black" VerticalAlignment="Bottom"/>
Expand Down
2 changes: 1 addition & 1 deletion sources/RevitDBExplorer/RevitDBExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="CircularBuffer" Version="1.3.0" />
<PackageReference Include="LoxSmoke.DocXml" Version="3.5.0" />
<PackageReference Include="NSourceGenerators.CodeToString" Version="0.3.0" />
<PackageReference Include="NSourceGenerators.CodeToString" Version="0.4.0" />
<PackageReference Include="RevitDBScripting" Version="1.1.0.$(RevitYear)" />
<PackageReference Include="RevitExplorer.Augmentations" Version="1.0.2.$(RevitYear)" />
<PackageReference Include="RevitExplorer.Visualizations" Version="1.0.2.$(RevitYear)" />
Expand Down
13 changes: 9 additions & 4 deletions sources/RevitDBExplorer/UIComponents/List/ListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</Style>


<Style TargetType="{x:Type Button}" x:Key="MiniButton">
<Style x:Key="MiniButton" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Width" Value="15"/>
<Setter Property="Height" Value="15"/>
<Setter Property="Padding" Value="1"/>
Expand Down Expand Up @@ -142,14 +142,19 @@
ContentTemplateSelector="{StaticResource DataTemplateSelectorForPropertyType}"
HorizontalAlignment="Stretch"
/>
<Grid Grid.Column="1" Visibility="{Binding Data.IsComparisonActive, Source={StaticResource Proxy}, Converter={StaticResource InverseBoolToVisibilityConverter}}">
<Button Style="{StaticResource MiniButton}" Padding="0 0 0 0" Visibility="{Binding CanGenerateCode, Converter={StaticResource BoolToVisibilityConverter}}"
<UniformGrid Grid.Column="1" Rows="1" Visibility="{Binding Data.IsComparisonActive, Source={StaticResource Proxy}, Converter={StaticResource InverseBoolToVisibilityConverter}}">

<TextBlock Text="V" Foreground="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" FontWeight="Heavy" FontFamily="Arial" FontSize="10" Width="8"
Visibility="{Binding CanBeVisualized, Converter={StaticResource BoolToVisibilityConverter}}"
ToolTip="item has a visualization"
/>
<Button Style="{StaticResource MiniButton}" Background="Transparent" Padding="0 0 0 0" Visibility="{Binding CanGenerateCode, Converter={StaticResource BoolToVisibilityConverter}}"
ap:ButtonAP.OpenSubMenuOnClick="True"
ContextMenu="{StaticResource ContextMenuForGenerateCSharpCode}"
ToolTip="RDS: Generate C# code for a given member">
<Path Style="{StaticResource IconQuery}" Width="10" />
</Button>
</Grid>
</UniformGrid>
</Grid>
</Border>
</DataTemplate>
Expand Down

0 comments on commit b5d9f67

Please sign in to comment.