Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@ The first target is **AutoCAD 2020**, using **C# / .NET Framework / WPF**.
- Review and edit recognized values before import
- Create AutoCAD `DBPoint` objects
- Add point-number `DBText` labels next to points
- Export recognized coordinates to CSV
- Export coordinates to CSV

No latitude/longitude or coordinate-system transformation is planned for the first MVP.

## Current development build
## Current development build — v0.2

The bootstrap build already contains:
The current development branch contains:

- AutoCAD plugin entry point
- `OCR2GEOMETRY` command
- WPF plugin window
- test coordinate model
- editable X/Y coordinate table
- add and delete table rows
- X/Y swap
- configurable start point number
- configurable text height
- creation of `DBPoint` objects in Model Space
- creation of point-number `DBText` labels
- CSV export with `Point,X,Y` columns

Test coordinates currently used by the bootstrap build:
Three sample coordinates are preloaded for quick testing:

```text
1 512345.23 6876543.11
Expand All @@ -39,7 +42,7 @@ Test coordinates currently used by the bootstrap build:

- Windows
- AutoCAD 2020 installed
- Visual Studio 2022 with .NET desktop development tools
- Visual Studio with .NET desktop development tools
- .NET Framework 4.7.2 targeting pack

The project expects the AutoCAD managed API assemblies in the default installation directory:
Expand All @@ -59,29 +62,21 @@ AutoCAD references use `Copy Local = False` so Autodesk DLLs are not copied into
1. Open `OCR2Geometry.sln` in Visual Studio.
2. Build the solution in `Debug` or `Release` mode.
3. Start AutoCAD 2020.
4. Run:

```text
NETLOAD
```

4. Run `NETLOAD`.
5. Select the built `OCR2Geometry.dll`, normally from:

```text
src\OCR2Geometry\bin\Debug\OCR2Geometry.dll
```

6. Run:

```text
OCR2GEOMETRY
```
6. Run `OCR2GEOMETRY`.
7. Edit/add/delete coordinate rows as required.
8. Test `Swap X/Y`.
9. Set a start number and text height.
10. Click **Create points** and verify points/labels in Model Space.
11. Click **Export CSV** and verify the saved coordinate table.

7. Click **Create test points**.

The bootstrap build should create three points and their point numbers in Model Space.

## Planned development stages
## Development stages

### v0.1 — AutoCAD bootstrap

Expand All @@ -90,26 +85,32 @@ The bootstrap build should create three points and their point numbers in Model
- [x] WPF window
- [x] Test point creation
- [x] Point numbering labels
- [x] Validated in AutoCAD 2020

### v0.2 — Coordinate table

- [ ] Editable coordinate grid
- [ ] Add/delete rows
- [ ] Start-number setting
- [ ] Text height and text offset settings
- [ ] X/Y swap
### v0.2 — Coordinate workflow

### v0.3 — CSV
- [x] Editable coordinate grid
- [x] Add/delete rows
- [x] Start-number setting
- [x] Text-height setting
- [x] X/Y swap
- [x] Create points from the edited table
- [x] CSV export
- [ ] Validate v0.2 build in AutoCAD 2020

- [ ] Export recognized/edited table to CSV

### v0.4 — OCR
### v0.3 — OCR foundation

- [ ] Image selection
- [ ] OCR engine integration
- [ ] Coordinate table parser
- [ ] Recognition confidence / validation workflow

### Later improvements

- [ ] User-defined text offset
- [ ] Improved AutoCAD layer/settings workflow
- [ ] Support additional AutoCAD versions

## Project structure

```text
Expand All @@ -119,6 +120,7 @@ OCR2Geometry-for-AutoCAD/
│ └── OCR2Geometry/
│ ├── AutoCAD/
│ ├── Commands/
│ ├── Export/
│ ├── Models/
│ ├── Properties/
│ ├── UI/
Expand All @@ -128,4 +130,4 @@ OCR2Geometry-for-AutoCAD/

## Status

Early development. The current branch is intended to prove the AutoCAD 2020 plugin loading and geometry-writing workflow before OCR is added.
Active development. v0.1 has been validated in AutoCAD 2020; v0.2 is ready for local build/testing before merge to `main`.
29 changes: 29 additions & 0 deletions src/OCR2Geometry/Export/CsvExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using OCR2Geometry.Models;

namespace OCR2Geometry.Export
{
public static class CsvExporter
{
public static void Export(string path, IEnumerable<CoordinatePoint> points)
{
using (var writer = new StreamWriter(path, false, new UTF8Encoding(true)))
{
writer.WriteLine("Point,X,Y");

foreach (var point in points)
{
writer.WriteLine(string.Format(
CultureInfo.InvariantCulture,
"{0},{1:0.########},{2:0.########}",
point.Number,
point.X,
point.Y));
}
}
}
}
}
1 change: 1 addition & 0 deletions src/OCR2Geometry/OCR2Geometry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Compile Include="Plugin.cs" />
<Compile Include="Commands\OcrCommand.cs" />
<Compile Include="AutoCAD\PointCreator.cs" />
<Compile Include="Export\CsvExporter.cs" />
<Compile Include="Models\CoordinatePoint.cs" />
<Compile Include="UI\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
Expand Down
82 changes: 61 additions & 21 deletions src/OCR2Geometry/UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,82 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="OCR2Geometry for AutoCAD"
Height="360"
Width="560"
ResizeMode="CanMinimize"
Height="560"
Width="760"
MinHeight="500"
MinWidth="700"
WindowStartupLocation="CenterOwner">
<Grid Margin="18">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock Text="OCR2Geometry"
FontSize="26"
FontWeight="SemiBold" />

<TextBlock Grid.Row="1"
Margin="0,6,0,16"
Text="AutoCAD 2020 development build — geometry bootstrap"
Margin="0,6,0,14"
Text="AutoCAD 2020 — coordinate table v0.2"
Foreground="Gray" />

<Border Grid.Row="2" BorderBrush="#CCCCCC" BorderThickness="1" Padding="12">
<StackPanel>
<TextBlock Text="Test coordinates" FontWeight="SemiBold" Margin="0,0,0,8" />
<TextBlock FontFamily="Consolas" Text="1 512345.23 6876543.11" />
<TextBlock FontFamily="Consolas" Text="2 512351.86 6876551.42" />
<TextBlock FontFamily="Consolas" Text="3 512360.14 6876567.30" />
<TextBlock Margin="0,14,0,0"
TextWrapping="Wrap"
Text="This bootstrap build creates three DBPoint objects and point-number DBText labels in Model Space." />
</StackPanel>
</Border>

<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,16,0,0">
<Button Width="150" Height="34" Margin="0,0,8,0" Content="Create test points" Click="CreateTestPoints_Click" />
<Button Width="90" Height="34" Content="Close" IsCancel="True" />
</StackPanel>
<DataGrid x:Name="PointsGrid"
Grid.Row="2"
ItemsSource="{Binding Points}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
SelectionMode="Extended"
SelectionUnit="FullRow"
HeadersVisibility="Column"
GridLinesVisibility="Horizontal"
Margin="0,0,0,12">
<DataGrid.Columns>
<DataGridTextColumn Header="Point" Binding="{Binding Number}" Width="100" IsReadOnly="True" />
<DataGridTextColumn Header="X" Binding="{Binding X, UpdateSourceTrigger=LostFocus}" Width="*" />
<DataGridTextColumn Header="Y" Binding="{Binding Y, UpdateSourceTrigger=LostFocus}" Width="*" />
</DataGrid.Columns>
</DataGrid>

<Grid Grid.Row="3" Margin="0,0,0,12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="22" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="22" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Button Grid.Column="0" Width="90" Height="30" Margin="0,0,8,0" Content="Add row" Click="AddRow_Click" />
<Button Grid.Column="1" Width="110" Height="30" Margin="0,0,8,0" Content="Delete selected" Click="DeleteSelected_Click" />
<Button Grid.Column="2" Width="90" Height="30" Content="Swap X/Y" Click="SwapXY_Click" />

<TextBlock Grid.Column="4" VerticalAlignment="Center" Text="Start number:" Margin="0,0,6,0" />
<TextBox x:Name="StartNumberTextBox" Grid.Column="5" Width="60" Height="26" Text="1" VerticalContentAlignment="Center" />

<TextBlock Grid.Column="7" VerticalAlignment="Center" Text="Text height:" Margin="0,0,6,0" />
<TextBox x:Name="TextHeightTextBox" Grid.Column="8" Width="65" Height="26" Text="2.5" VerticalContentAlignment="Center" />
</Grid>

<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Button Grid.Column="0" Width="150" Height="36" Margin="0,0,8,0" Content="Create points" Click="CreatePoints_Click" />
<Button Grid.Column="1" Width="120" Height="36" Content="Export CSV" Click="ExportCsv_Click" />
<Button Grid.Column="3" Width="90" Height="36" Content="Close" IsCancel="True" />
</Grid>
</Grid>
</Window>
Loading