Skip to content

Commit

Permalink
Add details pane, add revert selected rows button (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Obbay2 authored Mar 29, 2023
1 parent cc8ce1a commit 64e15b5
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 32 deletions.
20 changes: 10 additions & 10 deletions FindAndReplaceCAD/CADUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public static void WriteCADItems(IEnumerable<ObjectInformation> items)
TypeUtil.TypeInformation typeInfo = TypeUtil.GetTypeInformation(obj.Id);
ITypeUtil typeUtil = typeInfo.TypeUtil;

if (typeUtil.CanTextBeEdited(obj))
if (typeUtil.CanTextBeEdited(obj) && objInfo.HasTextChanged)
{
typeUtil.WriteText(obj, objInfo.NewText, myT);
}

if (typeUtil.CanMaskBeEdited(obj))
if (typeUtil.CanMaskBeEdited(obj) && objInfo.HasMaskChanged)
{
typeUtil.WriteMask(obj, objInfo.NewMask);
}
Expand Down Expand Up @@ -78,14 +78,14 @@ public static IList<ObjectInformation> ReadCADItems()
/// </summary>
/// <param name="data">Text for a single element</param>
/// <returns>String with all characters escaped for AutoCAD</returns>
public static string ReplaceWithCADEscapeCharacters(string data)
{
data = data.Replace(@"\", @"\\"); // Must come first
data = data.Replace("\r\n", @"\P");
data = data.Replace(@"{", @"\{");
data = data.Replace(@"}", @"\}");
return data;
}
//public static string ReplaceWithCADEscapeCharacters(string data)
//{
// data = data.Replace(@"\", @"\\"); // Must come first
// data = data.Replace("\r\n", @"\P");
// data = data.Replace(@"{", @"\{");
// data = data.Replace(@"}", @"\}");
// return data;
//}

/// <summary>
/// Moves and scales the viewport to center on the CAD element specified by its object ID
Expand Down
7 changes: 7 additions & 0 deletions FindAndReplaceCAD/FindAndReplaceCAD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<ItemGroup>
<Compile Include="CAD.cs" />
<Compile Include="CADUtil.cs" />
<Compile Include="UserControl\DetailsDialog.xaml.cs">
<DependentUpon>DetailsDialog.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\FindAndReplace.xaml.cs">
<DependentUpon>FindAndReplace.xaml</DependentUpon>
</Compile>
Expand All @@ -85,6 +88,10 @@
<Compile Include="Util\ITypeUtil.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="UserControl\DetailsDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\FindAndReplace.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
2 changes: 1 addition & 1 deletion FindAndReplaceCAD/FindAndReplaceCAD.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<StartProgram>C:\Program Files\Autodesk\AutoCAD 2022\acad.exe</StartProgram>
<StartArguments>"C:\Users\natha\OneDrive\Desktop\CI-001 - Standard\CI-001.dwg" /b C:\Users\natha\OneDrive\Projects\AutoCAD\FindAndReplaceCAD\config\script.scr /nologo</StartArguments>
<StartArguments>C:\Users\natha\OneDrive\Projects\AutoCAD\FindAndReplaceCAD\config\Drawing1.dwg /b C:\Users\natha\OneDrive\Projects\AutoCAD\FindAndReplaceCAD\config\script.scr /nologo</StartArguments>
<StartAction>Program</StartAction>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
Expand Down
17 changes: 14 additions & 3 deletions FindAndReplaceCAD/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mc:Ignorable="d"
Title="Find and Replace"
Height="800"
Width="918"
Width="1000"
Name="MainControlWindow">
<Window.Resources>
<CollectionViewSource x:Key="ItemCollectionViewSource" CollectionViewType="ListCollectionView"/>
Expand Down Expand Up @@ -41,6 +41,7 @@
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,10,0,10">
<Button Content="Refresh" Click="refreshButton_Click"/>
<Button Content="Revert Selected" Click="revertButton_Click"/>
</StackPanel>
<TabControl Grid.Row="2" Margin="10,10,10,10">
<TabItem Header="Masking">
Expand All @@ -61,6 +62,16 @@
<TabItem Header="Dimension Override">

</TabItem>
<TabItem Header="Help">
<StackPanel Orientation="Horizontal" Margin="10,10,10,10">
<TextBlock Margin="0,0,10,0" Text="AutoCAD Character Encoding Reference:" />
<TextBlock>
<Hyperlink NavigateUri="{Binding Path=CharacterEncodingURL, ElementName=MainControlWindow}" RequestNavigate="Hyperlink_RequestNavigate">
Click Here
</Hyperlink>
</TextBlock>
</StackPanel>
</TabItem>
</TabControl>
<DataGrid Name="DataGrid" ItemsSource="{Binding Path=Texts, ElementName=MainControlWindow}" SelectionMode="Extended" CanUserResizeRows="False" AutoGenerateColumns="False" Grid.Row="3">
<DataGrid.Resources>
Expand All @@ -72,7 +83,7 @@
<Setter Property="IsChecked" Value="{Binding NewMask, UpdateSourceTrigger=PropertyChanged}"/>
</Style>
<Style TargetType="DataGridCell" x:Key="newMaskCellStyle">
<Setter Property="Background" Value="{Binding HasMaskChanged}" />
<Setter Property="Background" Value="{Binding MaskBackgroundColor}" />
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
Expand All @@ -96,7 +107,7 @@
<DataGridTemplateColumn Width="1*" Header="New Text">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding NewText, UpdateSourceTrigger=PropertyChanged}" Background="{Binding HasTextChanged}" IsEnabled="{Binding CanEditText}"/>
<TextBox Text="{Binding NewText, UpdateSourceTrigger=PropertyChanged}" Background="{Binding TextBackgroundColor}" IsEnabled="{Binding CanEditText}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Expand Down
44 changes: 40 additions & 4 deletions FindAndReplaceCAD/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Autodesk.AutoCAD.DatabaseServices;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Navigation;

namespace CADApp
{
Expand Down Expand Up @@ -47,6 +50,15 @@ public string EditedAttributes
}
}

public string CharacterEncodingURL
{
get
{
string currentYear = DateTime.Now.Year.ToString();
return $"https://help.autodesk.com/view/ACD/{currentYear}/ENU/?guid=GUID-7D8BB40F-5C4E-4AE5-BD75-9ED7112E5967";
}
}

public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string propertyName)
{
Expand Down Expand Up @@ -92,7 +104,7 @@ public void btnStrip_Click(object sender, RoutedEventArgs e)
{
foreach(ObjectInformation item in Test.Where(item => item.IsSelected))
{
item.NewText = item.OriginalText.Replace("\n", " ");
item.NewText = item.OriginalText.Replace(@"\P", " ");
}
}

Expand All @@ -105,13 +117,22 @@ private void btnJumpTo_Click(object sender, RoutedEventArgs e)

public void refreshButton_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure? All edits made so far will be discarded.", "Refresh Confirmation", MessageBoxButton.YesNo);
MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure? All edits made so far will be discarded. Latest changes will retrieved from drawing file.", "Refresh Confirmation", MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
{
refreshData();
}
}

public void revertButton_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure? All edits in selected rows will be discarded.", "Revert Confirmation", MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
{
revertSelectedData();
}
}

private bool FindFilter(object item)
{
bool shouldShow = true;
Expand Down Expand Up @@ -140,6 +161,15 @@ private bool FindFilter(object item)
return shouldShow;
}

private void revertSelectedData()
{
foreach (var item in Test.Where(item => item.IsSelected))
{
item.NewText = item.OriginalText;
item.NewMask = item.OriginalMask;
}
}

private void refreshData()
{
Test.Clear();
Expand All @@ -159,8 +189,14 @@ private void DataGrid_AttributesChanged(object sender, PropertyChangedEventArgs

private void btnDetails_Click(object sender, RoutedEventArgs e)
{
//DataGridRow dgr = DataGridRow.GetRowContainingElement((Button)sender);
//DataGrid.SetDetailsVisibilityForItem(dgr, System.Windows.Visibility.Visible);
ObjectInformation objInfo = (ObjectInformation) ((Button)sender).DataContext;
new DetailsDialog(objInfo).ShowDialog();
}

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
}
}
23 changes: 19 additions & 4 deletions FindAndReplaceCAD/ObjectInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,33 @@ public bool NewMask {

public bool CanBeMasked { get; }

public SolidColorBrush HasTextChanged {
public bool HasTextChanged {
get
{
return OriginalText != NewText;
}
}

public bool HasMaskChanged
{
get
{
return OriginalMask != NewMask;
}
}

public SolidColorBrush TextBackgroundColor {
get
{
return OriginalText != NewText ? new SolidColorBrush(Colors.Yellow) : new SolidColorBrush(Colors.Transparent);
return HasTextChanged ? new SolidColorBrush(Colors.Yellow) : new SolidColorBrush(Colors.Transparent);
}
}

public SolidColorBrush HasMaskChanged
public SolidColorBrush MaskBackgroundColor
{
get
{
return OriginalMask != NewMask ? new SolidColorBrush(Colors.Yellow) : new SolidColorBrush(Colors.Transparent);
return HasMaskChanged ? new SolidColorBrush(Colors.Yellow) : new SolidColorBrush(Colors.Transparent);
}
}

Expand Down
120 changes: 120 additions & 0 deletions FindAndReplaceCAD/UserControl/DetailsDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<Window x:Class="CADApp.DetailsDialog"
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:local="clr-namespace:CADApp"
mc:Ignorable="d"
Height="Auto"
Width="600"
MinWidth="300"
Title="Details Pane">
<Window.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="10,5,10,5" />
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="10,5,10,5" />
</Style>
</Window.Resources>
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="ID" Grid.Column="0" />
<TextBlock Text="{Binding Path=Id}" Grid.Column="1" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Type" Grid.Column="0" />
<TextBlock Text="{Binding Path=Type}" Grid.Column="1" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Friendly Type" Grid.Column="0" />
<TextBlock Text="{Binding Path=FriendlyType}" Grid.Column="1" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Content Type" Grid.Column="0" />
<TextBlock Text="{Binding Path=ContentType}" Grid.Column="1" />
</Grid>
<Separator />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Original Text" Grid.Column="0" />
<TextBox Text="{Binding Path=OriginalText, Mode=OneTime}" Grid.Column="1" TextWrapping="Wrap" IsReadOnly="True" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="New Text" Grid.Column="0" />
<TextBox Text="{Binding Path=NewText, Mode=OneTime}" Grid.Column="1" TextWrapping="Wrap" IsReadOnly="True" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Can Edit Text?" Grid.Column="0" />
<TextBlock Text="{Binding Path=CanEditText}" Grid.Column="1" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Has Attribute Changed?" Grid.Column="0" />
<TextBlock Text="{Binding Path=HasTextChanged}" Grid.Column="1" />
</Grid>
<Separator />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Original Mask" Grid.Column="0" />
<TextBlock Text="{Binding Path=OriginalMask}" Grid.Column="1" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="New Mask" Grid.Column="0" />
<TextBlock Text="{Binding Path=NewMask}" Grid.Column="1" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Can Edit Mask?" Grid.Column="0" />
<TextBlock Text="{Binding Path=CanBeMasked}" Grid.Column="1" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Has Attribute Changed?" Grid.Column="0" />
<TextBlock Text="{Binding Path=HasMaskChanged}" Grid.Column="1" />
</Grid>
</StackPanel>
</Window>
16 changes: 16 additions & 0 deletions FindAndReplaceCAD/UserControl/DetailsDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Windows;

namespace CADApp
{
/// <summary>
/// Interaction logic for DetailsDialog.xaml
/// </summary>
public partial class DetailsDialog : Window
{
public DetailsDialog(ObjectInformation obj)
{
this.DataContext = obj;
InitializeComponent();
}
}
}
Loading

0 comments on commit 64e15b5

Please sign in to comment.