|  | @@ -20,8 +20,11 @@ public class DxfImportSettings
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public string? LayoutName { get; set; }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public DxfImportSettings(Size? imageSize = null, string[]? supportFolders = null, string? layoutName = null)
 | 
	
		
			
				|  |  | +    public bool AutoFit { get; set; }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public DxfImportSettings(Size? imageSize = null, string[]? supportFolders = null, string? layoutName = null, bool autoFit = true)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | +        AutoFit = autoFit;
 | 
	
		
			
				|  |  |          ImageSize = imageSize ?? new(2048, 2048);
 | 
	
		
			
				|  |  |          SupportFolders = supportFolders;
 | 
	
		
			
				|  |  |          LayoutName = layoutName ?? "Model";
 | 
	
	
		
			
				|  | @@ -69,8 +72,7 @@ public class DxfData
 | 
	
		
			
				|  |  |          set
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              Layout = Document.Layouts.First(x => x.Name == value);
 | 
	
		
			
				|  |  | -            Size = new((float)(Layout.MaxLimit.X - Layout.MinLimit.X), (float)(Layout.MaxLimit.Y - Layout.MinLimit.Y));
 | 
	
		
			
				|  |  | -            Origin = new((float)Layout.MinLimit.X, (float)Layout.MinLimit.Y);
 | 
	
		
			
				|  |  | +            UpdateSizeAndOrigin();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -80,8 +82,33 @@ public class DxfData
 | 
	
		
			
				|  |  |          Settings = settings;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Layout = settings.LayoutName is not null ? document.Layouts.First(x => x.Name == settings.LayoutName) : document.Layouts.First();
 | 
	
		
			
				|  |  | -        Size = new((float)(Layout.MaxLimit.X - Layout.MinLimit.X), (float)(Layout.MaxLimit.Y - Layout.MinLimit.Y));
 | 
	
		
			
				|  |  | -        Origin = new((float)Layout.MinLimit.X, (float)Layout.MinLimit.Y);
 | 
	
		
			
				|  |  | +        UpdateSizeAndOrigin();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void UpdateSizeAndOrigin()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (Settings.AutoFit)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            var bounds = DxfUtils.CalculateDxfSize(this) ?? new();
 | 
	
		
			
				|  |  | +            var margin = 0.1f * Math.Min(bounds.Width, bounds.Height);
 | 
	
		
			
				|  |  | +            if (bounds.IsEmpty)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                bounds.Size = new(100, 100);
 | 
	
		
			
				|  |  | +                bounds.Location = new(0, 0);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            else
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                bounds.Size = new(bounds.Width + margin * 2, bounds.Height + margin * 2);
 | 
	
		
			
				|  |  | +                bounds.Location = new(bounds.X - margin, bounds.Y - margin);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Size = bounds.Size;
 | 
	
		
			
				|  |  | +            Origin = bounds.Location;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        else
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            Size = new((float)(Layout.MaxLimit.X - Layout.MinLimit.X), (float)(Layout.MaxLimit.Y - Layout.MinLimit.Y));
 | 
	
		
			
				|  |  | +            Origin = new((float)Layout.MinLimit.X, (float)Layout.MinLimit.Y);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -128,6 +155,10 @@ public static class DxfUtils
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              return null;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        else if (el is Arc a)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            return new DxfArc(a);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          else
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              return null;
 |