-
Notifications
You must be signed in to change notification settings - Fork 327
Add visualization dialogs for CurveLoop #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bffa89b
Add visualization dialogs for CurveLoop
JieGou e4e7501
Merge remote-tracking branch 'upstream/dev' into dev
JieGou 09a6b40
optimize visualization dialogs for CurveLoop
JieGou 3680f2b
optimize
JieGou 5879b92
fix:Reverse package change for RevitLookup.csproj
JieGou 22dbcf4
Cleanup
Nice3point 4c2804b
Update title
Nice3point File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
source/RevitLookup.Abstractions/ViewModels/Visualization/ICurveLoopVisualizationViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RevitLookup.Abstractions/ViewModels/Visualization/ICurveLoopVisualizationViewModel.cs | ||
using System.Windows.Media; | ||
|
||
namespace RevitLookup.Abstractions.ViewModels.Visualization | ||
{ | ||
public interface ICurveLoopVisualizationViewModel | ||
{ | ||
double MinThickness { get; } | ||
double Diameter { get; set; } | ||
double Transparency { get; set; } | ||
Color SurfaceColor { get; set; } | ||
Color CurveColor { get; set; } | ||
Color DirectionColor { get; set; } | ||
bool ShowSurface { get; set; } | ||
bool ShowCurve { get; set; } | ||
bool ShowDirection { get; set; } | ||
|
||
void RegisterServer(object curveLoop); | ||
void UnregisterServer(); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
source/RevitLookup.UI.Framework/Views/Visualization/CurveLoopVisualizationDialog.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<ui:ContentDialog | ||
x:Class="RevitLookup.UI.Framework.Views.Visualization.CurveLoopVisualizationDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:ui="http://lookupengine.com/xaml" | ||
xmlns:colorPicker="clr-namespace:RevitLookup.UI.Framework.Controls.ColorPicker" | ||
xmlns:local="clr-namespace:RevitLookup.UI.Framework.Views.Visualization" | ||
xmlns:visualization="clr-namespace:RevitLookup.Abstractions.ViewModels.Visualization;assembly=RevitLookup.Abstractions" | ||
Title="Curve Loop Visualization settings" | ||
DialogMaxWidth="470" | ||
VerticalContentAlignment="Center" | ||
mc:Ignorable="d" | ||
d:DesignHeight="540" | ||
d:DesignWidth="600" | ||
d:DataContext="{d:DesignInstance visualization:ICurveLoopVisualizationViewModel}"> | ||
|
||
<ui:ContentDialog.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ui:ControlsDictionary /> | ||
</ResourceDictionary.MergedDictionaries> | ||
<Style | ||
BasedOn="{StaticResource DefaultContentDialogStyle}" | ||
TargetType="{x:Type local:CurveLoopVisualizationDialog}" /> | ||
</ResourceDictionary> | ||
</ui:ContentDialog.Resources> | ||
|
||
<StackPanel> | ||
<DockPanel> | ||
<ui:SymbolIcon | ||
DockPanel.Dock="Right" | ||
Margin="8 0 0 0" | ||
FontSize="20" | ||
Symbol="Eyedropper20" /> | ||
<colorPicker:ColorPickerControl | ||
DockPanel.Dock="Right" | ||
SelectedColor="{Binding SurfaceColor}" /> | ||
<CheckBox | ||
TabIndex="0" | ||
IsChecked="{Binding ShowSurface}" | ||
Content="Surface" /> | ||
</DockPanel> | ||
<StackPanel | ||
Margin="0 8 0 0"> | ||
<DockPanel> | ||
<TextBlock | ||
Text="Diameter" /> | ||
<TextBlock | ||
HorizontalAlignment="Right" | ||
Text="{Binding Diameter, | ||
StringFormat={}{0:F1} inch, | ||
Mode=OneWay, | ||
FallbackValue='12 inch'}" /> | ||
</DockPanel> | ||
<Slider | ||
Margin="0 4 0 0" | ||
Minimum="{Binding MinThickness, Mode=OneTime}" | ||
Maximum="6" | ||
TickFrequency="0.2" | ||
IsSnapToTickEnabled="True" | ||
TickPlacement="BottomRight" | ||
Value="{Binding Diameter}" /> | ||
</StackPanel> | ||
<StackPanel | ||
Margin="0 8 0 0"> | ||
<DockPanel> | ||
<TextBlock | ||
Text="Transparency" /> | ||
<TextBlock | ||
HorizontalAlignment="Right" | ||
Text="{Binding Transparency, | ||
StringFormat={}{0} %, | ||
Mode=OneWay, | ||
FallbackValue='12 %'}" /> | ||
</DockPanel> | ||
<Slider | ||
Margin="0 4 0 0" | ||
Minimum="0" | ||
Maximum="100" | ||
TickFrequency="10" | ||
IsSnapToTickEnabled="True" | ||
TickPlacement="BottomRight" | ||
Value="{Binding Transparency}" /> | ||
</StackPanel> | ||
<DockPanel | ||
Margin="0 8 0 0"> | ||
<ui:SymbolIcon | ||
DockPanel.Dock="Right" | ||
Margin="8 0 0 0" | ||
FontSize="20" | ||
Symbol="Eyedropper20" /> | ||
<colorPicker:ColorPickerControl | ||
DockPanel.Dock="Right" | ||
SelectedColor="{Binding CurveColor}" /> | ||
<CheckBox | ||
TabIndex="1" | ||
IsChecked="{Binding ShowCurve}" | ||
Content="Curve Loop" /> | ||
</DockPanel> | ||
<DockPanel | ||
Margin="0 8 0 0"> | ||
<ui:SymbolIcon | ||
DockPanel.Dock="Right" | ||
Margin="8 0 0 0" | ||
FontSize="20" | ||
Symbol="Eyedropper20" /> | ||
<colorPicker:ColorPickerControl | ||
DockPanel.Dock="Right" | ||
SelectedColor="{Binding DirectionColor}" /> | ||
<CheckBox | ||
TabIndex="2" | ||
IsChecked="{Binding ShowDirection}" | ||
Content="Direction" /> | ||
</DockPanel> | ||
</StackPanel> | ||
</ui:ContentDialog> |
39 changes: 39 additions & 0 deletions
39
source/RevitLookup.UI.Framework/Views/Visualization/CurveLoopVisualizationDialog.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RevitLookup.UI.Framework/Views/Visualization/CurveLoopVisualizationDialog.xaml.cs | ||
using RevitLookup.Abstractions.Services.Appearance; | ||
using RevitLookup.Abstractions.ViewModels.Visualization; | ||
using Wpf.Ui; | ||
|
||
namespace RevitLookup.UI.Framework.Views.Visualization | ||
{ | ||
public sealed partial class CurveLoopVisualizationDialog: Wpf.Ui.Controls.ContentDialog | ||
{ | ||
private readonly ICurveLoopVisualizationViewModel _viewModel; | ||
|
||
public CurveLoopVisualizationDialog( | ||
IContentDialogService dialogService, | ||
ICurveLoopVisualizationViewModel viewModel, | ||
IThemeWatcherService themeWatcherService) | ||
: base(dialogService.GetDialogHost()) | ||
{ | ||
_viewModel = viewModel; | ||
|
||
DataContext = _viewModel; | ||
InitializeComponent(); | ||
|
||
themeWatcherService.Watch(this); | ||
} | ||
|
||
public async Task ShowDialogAsync(object curveLoop) | ||
{ | ||
_viewModel.RegisterServer(curveLoop); | ||
MonitorServerConnection(); | ||
|
||
await ShowAsync(); | ||
} | ||
|
||
private void MonitorServerConnection() | ||
{ | ||
Unloaded += (_, _) => _viewModel.UnregisterServer(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
source/RevitLookup/Core/Decomposition/Descriptors/CurveLoopDescriptor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright 2003-2024 by Autodesk, Inc. | ||
// | ||
// Permission to use, copy, modify, and distribute this software in | ||
// object code form for any purpose and without fee is hereby granted, | ||
// provided that the above copyright notice appears in all copies and | ||
// that both that copyright notice and the limited warranty and | ||
// restricted rights notice below appear in all supporting | ||
// documentation. | ||
// | ||
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. | ||
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF | ||
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. | ||
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE | ||
// UNINTERRUPTED OR ERROR FREE. | ||
// | ||
// Use, duplication, or disclosure by the U.S. Government is subject to | ||
// restrictions set forth in FAR 52.227-19 (Commercial Computer | ||
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) | ||
// (Rights in Technical Data and Computer Software), as applicable. | ||
|
||
using System.Globalization; | ||
using System.Reflection; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
using Autodesk.Revit.DB; | ||
using LookupEngine.Abstractions.Configuration; | ||
using LookupEngine.Abstractions.Decomposition; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using RevitLookup.Abstractions.Configuration; | ||
using RevitLookup.Abstractions.Services.Presentation; | ||
using RevitLookup.UI.Framework.Extensions; | ||
using RevitLookup.UI.Framework.Views.Visualization; | ||
|
||
namespace RevitLookup.Core.Decomposition.Descriptors; | ||
|
||
public sealed class CurveLoopDescriptor : Descriptor, IDescriptorResolver, IContextMenuConnector | ||
{ | ||
private readonly CurveLoop _curveloop; | ||
|
||
public CurveLoopDescriptor(CurveLoop curveloop) | ||
{ | ||
_curveloop = curveloop; | ||
Name = $"{curveloop.GetExactLength().ToString(CultureInfo.InvariantCulture)} ft"; | ||
} | ||
|
||
public Func<IVariant>? Resolve(string target, ParameterInfo[] parameters) | ||
{ | ||
return target switch | ||
{ | ||
nameof(CurveLoop.IsOpen) => ResolveIsOpen, | ||
nameof(CurveLoop.GetPlane) => ResolveGetPlane, | ||
nameof(CurveLoop.NumberOfCurves) => ResolveNumberOfCurves, | ||
_ => null | ||
}; | ||
|
||
IVariant ResolveNumberOfCurves() | ||
{ | ||
var variants = Variants.Values<int>(1); | ||
|
||
variants.Add(_curveloop.NumberOfCurves(), "number of curves in the curve loop"); | ||
|
||
return variants.Consume(); | ||
} | ||
|
||
IVariant ResolveIsOpen() | ||
{ | ||
return Variants.Values<bool>(1) | ||
.Add(_curveloop.IsOpen(), "whether the curve loop is open or closed") | ||
.Consume(); | ||
} | ||
|
||
IVariant ResolveGetPlane() | ||
{ | ||
return Variants.Values<Plane>(1) | ||
.Add(_curveloop.GetPlane(), "Plane") | ||
.Consume(); | ||
} | ||
} | ||
|
||
public void RegisterMenu(ContextMenu contextMenu, IServiceProvider serviceProvider) | ||
{ | ||
#if REVIT2023_OR_GREATER | ||
contextMenu.AddMenuItem("SelectMenuItem") | ||
.SetCommand(_curveloop, SelectCurve) | ||
.SetShortcut(Key.F6); | ||
|
||
contextMenu.AddMenuItem("ShowMenuItem") | ||
.SetCommand(_curveloop, ShowCurve) | ||
.SetShortcut(Key.F7); | ||
#endif | ||
contextMenu.AddMenuItem("VisualizeMenuItem") | ||
.SetAvailability(true && _curveloop.GetExactLength() > 1e-6) | ||
JieGou marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
.SetCommand(_curveloop, VisualizeCurve) | ||
.SetShortcut(Key.F8); | ||
|
||
async Task VisualizeCurve(CurveLoop curveloop) | ||
{ | ||
if (Context.ActiveUiDocument is null) return; | ||
|
||
try | ||
{ | ||
var dialog = serviceProvider.GetRequiredService<CurveLoopVisualizationDialog>(); | ||
await dialog.ShowDialogAsync(curveloop); | ||
} | ||
catch (Exception exception) | ||
{ | ||
var logger = serviceProvider.GetRequiredService<ILogger<CurveLoopDescriptor>>(); | ||
var notificationService = serviceProvider.GetRequiredService<INotificationService>(); | ||
|
||
logger.LogError(exception, "Visualize curveloop error"); | ||
notificationService.ShowError("Visualization error", exception); | ||
} | ||
} | ||
|
||
#if REVIT2023_OR_GREATER | ||
void SelectCurve(CurveLoop curveloop) | ||
{ | ||
if (Context.ActiveUiDocument is null) return; | ||
if (curveloop.Any(curve => curve.Reference is null)) return; | ||
|
||
foreach (var curve in curveloop) | ||
{ | ||
RevitShell.ActionEventHandler.Raise(_ => Context.ActiveUiDocument.Selection.SetReferences([curve.Reference])); | ||
} | ||
} | ||
|
||
void ShowCurve(CurveLoop curveloop) | ||
{ | ||
if (Context.ActiveUiDocument is null) return; | ||
if (curveloop.Any(curve => curve.Reference is null)) return; | ||
|
||
RevitShell.ActionEventHandler.Raise(application => | ||
{ | ||
var uiDocument = application.ActiveUIDocument; | ||
if (uiDocument is null) return; | ||
|
||
foreach (var curve in curveloop) | ||
{ | ||
var element = curve.Reference.ElementId.ToElement(uiDocument.Document); | ||
if (element is not null) uiDocument.ShowElements(element); | ||
|
||
uiDocument.Selection.SetReferences([curve.Reference]); | ||
} | ||
}); | ||
} | ||
#endif | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.