Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
CAD layouts: view target, model-space-only drawings, viewports that are off
cre8ive-marketing6f8580878599
diff --git a/docs/ENGINES.md b/docs/ENGINES.mdindex 2a942458..055dab3d 100644--- a/docs/ENGINES.md+++ b/docs/ENGINES.md@@ -857,9 +857,11 @@ and writes the files; Filee's own renderer draws them with SkiaSharp (one drawin- PDF of a drawing with paper-space layouts (#172): **one page per layout** with something on it, in tab order,each fitted like the one-page PDF to the layout's drawing and viewport frames. Inside each viewport model spaceis drawn at the viewport's scale (height ÷ view height) around its view centre, clipped to the frame, under the- layout's own drawing (title block, notes). Not followed: twisted views (drawn untwisted), layers frozen per- viewport, non-rectangular viewports and the layout's plot settings (paper size, plot scale). Images and SVG stay- one picture of model space.+ layout's own drawing (title block, notes). Viewports that are off are skipped. When no layout has anything of its+ own besides viewports (a drawing made in model space, whose Layout1 only holds the viewport AutoCAD added), the+ PDF stays one page of model space. Not followed: twisted views (drawn untwisted), views from another direction+ than the top (drawn from the top), layers frozen per viewport, non-rectangular viewports and the layout's plot+ settings (paper size, plot scale). Images and SVG stay one picture of model space.- SVG: the drawing's aspect ratio with a 420 mm (A3) long edge at 96 px/inch, white background, text as `<text>`.- Images: the same page rendered at the preset's render resolution (150 dpi → 2480 px on the long edge, at most12 000 px / 80 MP), then the preset's image options (resize, grayscale, quality, DPI) as for other images.diff --git a/src/Filee.Engines/Cad/CadSceneBuilder.cs b/src/Filee.Engines/Cad/CadSceneBuilder.csindex 80e310c0..b5ad1df9 100644--- a/src/Filee.Engines/Cad/CadSceneBuilder.cs+++ b/src/Filee.Engines/Cad/CadSceneBuilder.cs@@ -61,7 +61,8 @@ internal sealed partial class CadSceneBuilder/// <summary>/// The paper-space layouts that have something on them, in tab order (#172): each one's own entities (title block,- /// notes) and the viewports that show model space. Empty when the drawing has none, so it is drawn as before.+ /// notes) and the viewports that show model space. Empty when the drawing has none, or when no layout has anything+ /// of its own besides viewports, so it is drawn as before./// </summary>public static List<LayoutSheet> BuildLayouts(CadDocument document, CancellationToken cancellationToken){@@ -73,23 +74,29 @@ internal sealed partial class CadSceneBuildervar builder = new CadSceneBuilder(document, cancellationToken);builder._scene.Space = layout.Name;builder.DrawEntities(layout.AssociatedBlock!.Entities, DrawContext.Root);- // The viewport that is the sheet itself (RepresentsPaper) shows no model space. Twisted views are drawn- // untwisted.+ // The viewport that is the sheet itself (RepresentsPaper) shows no model space, and one that is off shows+ // nothing. Twisted views are drawn untwisted, and every view is drawn from the top.var views = layout.AssociatedBlock.Entities.OfType<Viewport>()- .Where(v => !v.RepresentsPaper && v.Width > 0 && v.Height > 0 && v.ViewHeight > 0)+ .Where(v => !v.RepresentsPaper && !v.Status.HasFlag(ViewportStatusFlags.ViewportOff)+ && v.Width > 0 && v.Height > 0 && v.ViewHeight > 0).Select(v =>{var frame = Box2.Empty;frame.Add(new Vec2(v.Center.X - v.Width / 2, v.Center.Y - v.Height / 2));frame.Add(new Vec2(v.Center.X + v.Width / 2, v.Center.Y + v.Height / 2));- return new ViewportView(frame, new Vec2(v.ViewCenter.X, v.ViewCenter.Y), v.Height / v.ViewHeight);+ // The view centre is in display coordinates, whose origin is the view target (WCS).+ return new ViewportView(frame, new Vec2(v.ViewTarget.X + v.ViewCenter.X, v.ViewTarget.Y + v.ViewCenter.Y),+ v.Height / v.ViewHeight);}).Where(v => !v.Frame.IsEmpty).ToList();if (builder._scene.Items.Count > 0 || views.Count > 0)sheets.Add(new LayoutSheet(layout.Name, builder._scene, views));}- return sheets;+ // AutoCAD gives a layout a viewport the first time its tab is opened: a drawing made in model space then has a+ // Layout1 with only that viewport and an old view. Without a border, title block or notes on any layout, the+ // whole of model space is the better page.+ return sheets.Any(s => s.Paper.Items.Count > 0) ? sheets : [];}private static BlockRecord? TryGetPaperSpace(CadDocument document) =>diff --git a/tests/Filee.Engines.Tests/CadLayoutTests.cs b/tests/Filee.Engines.Tests/CadLayoutTests.csindex ebc7228a..65c1ec60 100644--- a/tests/Filee.Engines.Tests/CadLayoutTests.cs+++ b/tests/Filee.Engines.Tests/CadLayoutTests.cs@@ -21,7 +21,8 @@ public class CadLayoutTests(EngineFixture fx) : IClassFixture<EngineFixture>{/// <summary>/// Model space: a blue 100 × 100 square at the origin and a blue circle far right at (1000, 0). Two layouts on- /// 420 × 297 paper, each with a border and one viewport: "Plan" shows the square at 1:1, "Detail" the circle at 2:1.+ /// 420 × 297 paper, each with a border and one viewport: "Plan" shows the square at 1:1, "Detail" the circle at 2:1,+ /// through a view target at (900, 0) with the view centre 100 to its right./// </summary>private static CadDocument TwoSheets(){@@ -33,27 +34,32 @@ public class CadLayoutTests(EngineFixture fx) : IClassFixture<EngineFixture>CadBuilder.Add(doc, drawing, new Circle(new XYZ(1000, 0, 0), 20));AddSheet(doc, "Plan", 1, new XY(50, 50), viewHeight: 150);- AddSheet(doc, "Detail", 2, new XY(1000, 0), viewHeight: 75);+ AddSheet(doc, "Detail", 2, new XY(100, 0), viewHeight: 75, target: new XYZ(900, 0, 0));return doc;}- private static void AddSheet(CadDocument doc, string name, int tab, XY viewCenter, double viewHeight)+ private static Viewport AddSheet(CadDocument doc, string name, int tab, XY viewCenter, double viewHeight, XYZ target = default,+ bool border = true){var layout = new Layout(name) { TabOrder = tab };doc.Layouts.Add(layout);var block = layout.AssociatedBlock;// The sheet border (title block) in paper space, and one 200 × 150 viewport in the middle of the sheet.- block.Entities.Add(new LwPolyline(new LwPolyline.Vertex(0, 0), new LwPolyline.Vertex(420, 0), new LwPolyline.Vertex(420, 297),- new LwPolyline.Vertex(0, 297))- { IsClosed = true });- block.Entities.Add(new Viewport+ if (border)+ block.Entities.Add(new LwPolyline(new LwPolyline.Vertex(0, 0), new LwPolyline.Vertex(420, 0), new LwPolyline.Vertex(420, 297),+ new LwPolyline.Vertex(0, 297))+ { IsClosed = true });+ var viewport = new Viewport{Center = new XYZ(210, 148.5, 0),Width = 200,Height = 150,ViewCenter = viewCenter,ViewHeight = viewHeight,- });+ ViewTarget = target,+ };+ block.Entities.Add(viewport);+ return viewport;}[Fact]@@ -64,6 +70,7 @@ public class CadLayoutTests(EngineFixture fx) : IClassFixture<EngineFixture>Assert.Equal(["Plan", "Detail"], sheets.Select(s => s.Name));var detail = Assert.Single(sheets[1].Viewports);Assert.Equal(2, detail.Scale, 9); // 150 paper units show 75 model units+ Assert.Equal((1000.0, 0.0), (detail.ViewCenter.X, detail.ViewCenter.Y)); // target + centreAssert.Equal((110.0, 73.5, 310.0, 223.5), (detail.Frame.MinX, detail.Frame.MinY, detail.Frame.MaxX, detail.Frame.MaxY));Assert.Equal(420, sheets[0].Extents.Width, 9);@@ -92,6 +99,34 @@ public class CadLayoutTests(EngineFixture fx) : IClassFixture<EngineFixture>}}+ [Fact]+ public void A_viewport_that_is_off_is_skipped()+ {+ var doc = TwoSheets();+ AddSheet(doc, "Off", 3, new XY(50, 50), viewHeight: 150).Status |= ViewportStatusFlags.ViewportOff;++ var sheets = CadSceneBuilder.BuildLayouts(doc, TestContext.Current.CancellationToken);++ Assert.Equal(["Plan", "Detail", "Off"], sheets.Select(s => s.Name));+ Assert.Empty(sheets[2].Viewports); // the border is still a page+ }++ [Fact]+ public async Task A_drawing_made_in_model_space_keeps_one_page_of_all_of_it()+ {+ // Layout1 holds only the viewport AutoCAD added when its tab was first opened, with a view of the square alone.+ var doc = CadBuilder.Sample();+ AddSheet(doc, "Sheet", 1, new XY(50, 50), viewHeight: 150, border: false);+ Assert.Empty(CadSceneBuilder.BuildLayouts(doc, TestContext.Current.CancellationToken));++ var dxf = CadBuilder.SaveDxf(doc, fx.NewFolder(), "model.dxf");+ var job = await fx.ConvertAsync([dxf], new Preset { TargetFormat = "pdf" });++ Assert.Equal(JobState.Completed, job.State);+ using var document = PdfReader.Open(job.Outputs.Single(), PdfDocumentOpenMode.Import);+ Assert.Equal(1, document.PageCount);+ }+[Fact]public async Task Images_and_svg_stay_one_picture_of_model_space(){