|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Autodesk.Revit.DB; |
| 4 | +using Autodesk.Revit.UI; |
| 5 | +using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; |
| 6 | +using RevitExplorer.Visualizations.DrawingVisuals; |
| 7 | + |
| 8 | +// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md |
| 9 | + |
| 10 | +namespace RevitDBExplorer.Domain.DataModel.ValueContainers |
| 11 | +{ |
| 12 | + internal class UIViewHandler : TypeHandler<UIView> |
| 13 | + { |
| 14 | + protected override bool CanBeSnoooped(SnoopableContext context, UIView value) => true; |
| 15 | + |
| 16 | + protected override string ToLabel(SnoopableContext context, UIView value) => Labeler.GetLabelForObjectWithId("GeometryElement", value.ViewId.Value()); |
| 17 | + |
| 18 | + |
| 19 | + protected override bool CanBeVisualized(SnoopableContext context, UIView value) => true; |
| 20 | + |
| 21 | + |
| 22 | + private readonly static Color CrossColor = new Color(255, 0, 225); |
| 23 | + |
| 24 | + protected override IEnumerable<VisualizationItem> GetVisualization(SnoopableContext context, UIView uiView) |
| 25 | + { |
| 26 | + var view = context.Document.GetElement(uiView.ViewId) as View; |
| 27 | + IList<XYZ> corners = null; |
| 28 | + try |
| 29 | + { |
| 30 | + corners = uiView.GetZoomCorners(); |
| 31 | + } |
| 32 | + catch |
| 33 | + { |
| 34 | + yield break; |
| 35 | + |
| 36 | + } |
| 37 | + |
| 38 | + yield return new VisualizationItem("UIView", "GetZoomCorners()[0]", new CrossDrawingVisual(corners[0], VisualizationItem.StartColor) { LineLength = 0.1 }); |
| 39 | + yield return new VisualizationItem("UIView", "GetZoomCorners()[1]", new CrossDrawingVisual(corners[1], VisualizationItem.EndColor) { LineLength = 0.1 }); |
| 40 | + |
| 41 | + var diagVector = corners[0] - corners[1]; |
| 42 | + |
| 43 | + double height = Math.Abs(diagVector.DotProduct(view.UpDirection)); |
| 44 | + double width = Math.Abs(diagVector.DotProduct(view.RightDirection)); |
| 45 | + |
| 46 | + var p0 = corners[0]; |
| 47 | + var p1 = corners[0] + width * view.RightDirection; |
| 48 | + var p2 = corners[1]; |
| 49 | + var p3 = corners[0] + height * view.UpDirection; |
| 50 | + |
| 51 | + var l1 = Line.CreateBound(p0, p1); |
| 52 | + var l2 = Line.CreateBound(p1, p2); |
| 53 | + var l3 = Line.CreateBound(p2, p3); |
| 54 | + var l4 = Line.CreateBound(p3, p0); |
| 55 | + |
| 56 | + yield return new VisualizationItem("UIView", "GetZoomCorners()", new CurvesDrawingVisual([l1, l2, l3 , l4], CrossColor)); |
| 57 | + |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments