Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
add support snoop clash result
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Sep 3, 2023
1 parent c7751c8 commit 6c9d42e
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 12 deletions.
4 changes: 4 additions & 0 deletions NavisAppInfo/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace AppInfo
[Command("ID_ButtonAppInfoActiveView", DisplayName = "Snoop \n Active View", Icon = "Resources\\view-16.png", LargeIcon = "Resources\\view-32.png",ToolTip = "Snoop Active View")]
[Command("ID_ButtonAppInfoActiveSheet", DisplayName = "Snoop \n Active Sheet", Icon = "Resources\\sheet-16.png", LargeIcon = "Resources\\sheet-32.png",ToolTip = "Snoop Active Sheet")]
[Command("ID_ButtonAppInfoClashTest", DisplayName = "Snoop \n Clash Test", Icon = "Resources\\conflict-16.png", LargeIcon = "Resources\\conflict-32.png",ToolTip = "Snoop Clash Test")]
[Command("ID_ButtonAppInfoClashResultSearch", DisplayName = "Snoop \n ClashResult Search", Icon = "Resources\\conflict-16.png", LargeIcon = "Resources\\conflict-32.png",ToolTip = "Snoop Clash Result Inside Test")]
[Command("ID_ButtonAppInfoCurrentSelection", DisplayName = "Snoop \n Current Selection", Icon = "Resources\\cursor-16.png", LargeIcon = "Resources\\cursor-32.png",ToolTip = "Snoop Current Selection")]
[Command("ID_ButtonAppInfoTest", DisplayName = "Test", Icon = "Resources\\test-16.png", LargeIcon = "Resources\\test-32.png",ToolTip = "Test")]
public class App : CommandHandlerPlugin
Expand All @@ -37,6 +38,9 @@ public override int ExecuteCommand(string name, params string[] parameters)
case "ID_ButtonAppInfoClashTest":
new SnoopClashTest().Execute();
break;
case "ID_ButtonAppInfoClashResultSearch":
new SnoopSearch().Execute();
break;
case "ID_ButtonAppInfoCurrentSelection":
new SnoopCurrentSelection().Execute();
break;
Expand Down
3 changes: 2 additions & 1 deletion NavisAppInfo/Command/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public abstract class BaseCommand : AddInPlugin

public override int Execute(params string[] parameters)
{
FrmAppInfo frmAppInfo = new FrmAppInfo(new AppInfoViewModel(SnoopType));
AppInfoViewModel viewModel = new AppInfoViewModel(SnoopType);
FrmAppInfo frmAppInfo = new FrmAppInfo(viewModel);
frmAppInfo.WindowStartupLocation = WindowStartupLocation.CenterScreen;
IntPtr handle = Application.Gui.MainWindow.Handle;
new WindowInteropHelper(frmAppInfo).Owner = handle;
Expand Down
19 changes: 17 additions & 2 deletions NavisAppInfo/Command/SnoopSearch.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
namespace AppInfo.Command
using System.Windows;
using System.Windows.Interop;
using AppInfo.View;
using AppInfo.ViewModel;
using Application = System.Windows.Forms.Application;

namespace AppInfo.Command
{
public class SnoopSearch : BaseCommand
{
public override SnoopType SnoopType { get; set; } = SnoopType.Search;

public override int Execute(params string[] parameters)
{
AppInfoViewModel viewModel = new AppInfoViewModel(SnoopType);
SearchByContains searchByContains = new SearchByContains(viewModel);
searchByContains.WindowStartupLocation = WindowStartupLocation.CenterScreen;
IntPtr handle = Autodesk.Navisworks.Api.Application.Gui.MainWindow.Handle;
new WindowInteropHelper(searchByContains).Owner = handle;
searchByContains.ShowDialog();
return 0;
}
}
}
10 changes: 10 additions & 0 deletions NavisAppInfo/Model/NodeSearch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace AppInfo.Model;

public class NodeSearch
{
public enum SearchType
{
ClashResultGuid,
ClashResultName,
}
}
85 changes: 85 additions & 0 deletions NavisAppInfo/View/AppInfoControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,91 @@ private void AppInfoControl_Load(object sender, EventArgs e)
case SnoopType.ElementId:
break;
case SnoopType.Search:
DocumentClashTests clashTests = Application.MainDocument.GetClash().TestsData;
if (clashTests == null) return;
if(clashTests.Tests.Count==0) return;
SavedItem clashResult = null;
foreach (var savedItem1 in clashTests.Tests)
{
var savedItem = (ClashTest) savedItem1;
if (savedItem == null) continue;
SavedItemCollection savedItemCollection = savedItem.Children;
switch (_ViewModel.SearchType)
{
case NodeSearch.SearchType.ClashResultGuid:

foreach (SavedItem item in savedItemCollection)
{
if (item == null) continue;
if (item is ClashResult)
{
ClashResult result = item as ClashResult;
if(result.Guid.ToString().ToLower() == _ViewModel.SearchValue)
{
clashResult = result;
break;
}
}
else if (item is ClashResultGroup clashResultGroup)
{
foreach (var clashResultItem in clashResultGroup.Children)
{
ClashResult resultItem = clashResultItem as ClashResult;
if(resultItem != null)
{
if (clashResult.Guid.ToString().ToLower() == _ViewModel.SearchValue)
{
clashResult = resultItem;
break;
}
}
}
}
};
break;
case NodeSearch.SearchType.ClashResultName:
foreach (SavedItem item in savedItemCollection)
{
if (item == null) continue;
if (item is ClashResult result)
{
if (result.DisplayName.ToLower() == _ViewModel.SearchValue)
{
clashResult = result;
break;
}
}
else if (item is ClashResultGroup clashResultGroup)
{
foreach (var clashResultItem in clashResultGroup.Children)
{
ClashResult resultItem = clashResultItem as ClashResult;
if (resultItem != null)
{
if (clashResult.DisplayName.ToLower() == _ViewModel.SearchValue)
{
clashResult = resultItem;
break;
}
}
}
}
};
break;
default:
clashResult = null;
break;
}
}
if (clashResult == null)
{
return;
}
AddRootNode(clashResult.GetType(), "ClashResult", clashResult);
TreeNode clashResultTree = appView.Nodes[0];
DisplayNodeProperties(clashResultTree);
clashResultTree.Expand();
break;
case SnoopType.ActiveView:
Autodesk.Navisworks.Api.View activeView = Document.ActiveView;
if (activeView == null) return;
Expand Down
25 changes: 18 additions & 7 deletions NavisAppInfo/View/SearchByContains.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<Window
Height="Auto"
Title="SearchBy..."
Width="350"
Height="150"
Title="SearchBy..."
mc:Ignorable="d"
ResizeMode="NoResize"
x:Class="AppInfo.View.SearchByContains"
FocusManager.FocusedElement="{Binding ElementName=txtSearchValue}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand All @@ -21,24 +23,33 @@
<Label Grid.Column="0" Grid.Row="0" >SnoopType:</Label>
<ComboBox Grid.Column="1"
Grid.Row="0"
x:Name="cbbSnoopType"
Margin="2,2,2,2"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">
<ComboBoxItem IsSelected="True" Content="Item Guid"></ComboBoxItem>
<ComboBoxItem Content="Item Guid"></ComboBoxItem>
<ComboBoxItem Content="Clash Guid"></ComboBoxItem>
<ComboBoxItem Content="Clash Name"></ComboBoxItem>
<ComboBoxItem Content="ClashResult Name"></ComboBoxItem>
<ComboBoxItem Tag="Name" IsSelected="True" Content="ClashResult Name"></ComboBoxItem>
<ComboBoxItem Tag="Guid" Content="ClashResult Guid"></ComboBoxItem>
</ComboBox>
<Label Grid.Row="1"
Content="Value:"
Grid.Column="0"/>
<TextBox Grid.Column="1"
Grid.Row="1"
CaretIndex="0"
TabIndex="0"
Focusable="True"
x:Name="txtSearchValue"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"
Margin="2,2,2,2"
/>
<Button
Grid.Row="2"
Background="GhostWhite"
Grid.Column="0"
Click="SnoopSearchClick"
Grid.ColumnSpan="2"
IsDefault="True"
Content="Snoop"/>
</Grid>
</Window>
55 changes: 53 additions & 2 deletions NavisAppInfo/View/SearchByContains.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,67 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using AppInfo.Model;
using AppInfo.ViewModel;
using Application = Autodesk.Navisworks.Api.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MessageBox = System.Windows.MessageBox;

namespace AppInfo.View
{
public partial class SearchByContains : Window
{
private AppInfoViewModel _viewModel { get; }
private AppInfoViewModel _viewModel { get; set; }
public SearchByContains(AppInfoViewModel viewModel)
{
InitializeComponent();
this._viewModel = viewModel;
WindowStartupLocation = WindowStartupLocation.CenterScreen;
_viewModel = viewModel;
this.DataContext = viewModel;
KeyDown += Window_KeyDown;
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
SnoopSearchClick(sender, e);
}
}


[STAThread]
private void SnoopSearchClick(object sender, RoutedEventArgs e)
{
try
{
switch (cbbSnoopType.Text)
{
case "ClashResult Name":
_viewModel.SearchType = NodeSearch.SearchType.ClashResultName;
break;
case "ClashResult Guid":
_viewModel.SearchType = NodeSearch.SearchType.ClashResultGuid;
break;
}

if (string.IsNullOrEmpty(txtSearchValue.Text))
{
MessageBox.Show("Please input search value");
return;
}
_viewModel.SearchValue = txtSearchValue.Text.ToLower();
Close();
FrmAppInfo frmAppInfo = new FrmAppInfo(_viewModel);
frmAppInfo.WindowStartupLocation = WindowStartupLocation.CenterScreen;
IntPtr handle = Application.Gui.MainWindow.Handle;
new WindowInteropHelper(frmAppInfo).Owner = handle;
frmAppInfo.Show();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}

}
}
}
3 changes: 3 additions & 0 deletions NavisAppInfo/ViewModel/AppInfoViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using AppInfo.Command;
using AppInfo.Model;

namespace AppInfo.ViewModel
{
public class AppInfoViewModel
{
public SnoopType SnoopType { get; set; }
public NodeSearch.SearchType SearchType { get; set; }
public string SearchValue { get; set; }
public AppInfoViewModel(SnoopType snoopType)
{
SnoopType = snoopType;
Expand Down
6 changes: 6 additions & 0 deletions NavisAppInfo/en-US/AppInfoRibbon.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
ShowText="True"
Size="Large"
x:Uid="UID_ButtonAppInfoClashTest" />
<nvw:NWRibbonButton
Id="ID_ButtonAppInfoClashResultSearch"
Orientation="Vertical"
ShowText="True"
Size="Large"
x:Uid="UID_ButtonAppInfoClashResultSearch" />
<nvw:NWRibbonButton
Id="ID_ButtonAppInfoCurrentSelection"
Orientation="Vertical"
Expand Down

0 comments on commit 6c9d42e

Please sign in to comment.