Skip to content

Conversation

Copy link

Copilot AI commented Jan 20, 2026

Implements ACadSharp adapter to enable runtime switching between netDxf and ACadSharp for DXF/DWG operations. Refactors ImportDxf to use abstraction interfaces, removing direct netDxf dependencies.

Implementation

ACadSharpLibraryAdapter (~900 lines)

  • Entity adapters for 20+ types: Line, Arc, Circle, Ellipse, Spline, Polyline2D/3D, Text, MText, Hatch, Insert, Face3D, PolyfaceMesh, Mesh, Solid, Point, Ray, MLine, Dimension, Leader
  • DXF and DWG file I/O using ACadSharp's DxfReader/DxfWriter and DwgReader/DwgWriter
  • Color conversion from ACadSharp ACI to ARGB
  • Block, layer, and linetype collection adapters

ImportDxf refactoring

  • Converted 20 entity creation methods from netDxf.Entities.* to IDxf* interfaces
  • Replaced Vector3 with tuple types (double X, double Y, double Z) for library neutrality
  • Updated helper methods: GeoPoint, GeoVector, Plane, SetAttributes to use abstraction
  • Layer/color mapping through abstraction layer lookups

Export extension

  • Added IDxfEntityFactory interface with entity creation methods
  • Implemented NetDxfEntityFactory and ACadSharpEntityFactory
  • ExportDxf.cs continues using netDxf directly (export logic remains stable)

Usage

// Runtime library selection
var library = DxfLibraryFactory.GetLibrary(DxfLibraryType.ACadSharp);
var doc = library.LoadFromFile("drawing.dwg");

// Entity access through abstraction
foreach (var entity in doc.Entities)
{
    if (entity is IDxfLine line)
    {
        var (x1, y1, z1) = line.StartPoint;
        var (x2, y2, z2) = line.EndPoint;
    }
}

Architecture

Import/Export
    ↓
DxfLibraryFactory
    ↓
IDxfLibrary
   ├─ NetDxfLibraryAdapter (existing)
   └─ ACadSharpLibraryAdapter (new)

Enables DWG support via ACadSharp while maintaining netDxf compatibility for DXF workflows.

Original prompt

To fully migrate ImportDxf and ExportDxf to use the abstraction layer would require:
• Rewriting approximately 50 entity conversion methods in ImportDxf
• Rewriting approximately 30 entity export methods in ExportDxf
• Creating entity-level adapters or converters for each entity type

Please make sure that ACadSharp is fully implemented to support all types like lines, splines, etc...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 7 commits January 20, 2026 20:02
Co-authored-by: dsn27 <45662116+dsn27@users.noreply.github.com>
Co-authored-by: dsn27 <45662116+dsn27@users.noreply.github.com>
Co-authored-by: dsn27 <45662116+dsn27@users.noreply.github.com>
Co-authored-by: dsn27 <45662116+dsn27@users.noreply.github.com>
Co-authored-by: dsn27 <45662116+dsn27@users.noreply.github.com>
Co-authored-by: dsn27 <45662116+dsn27@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate ImportDxf and ExportDxf to follow abstraction layer Complete ACadSharp abstraction layer with full entity type coverage Jan 20, 2026
Copilot AI requested a review from dsn27 January 20, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants