From d7f89c6576608f840d4c28326354390e092c9ad4 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 12 Jan 2025 19:54:33 -0800 Subject: [PATCH] Respect DXF origin on graphics import if possible We only need to adjust the DXF import box location if the graphics imported do not fit on our drawing area Fixes https://gitlab.com/kicad/code/kicad/-/issues/18523 --- common/import_gfx/graphics_importer_buffer.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/import_gfx/graphics_importer_buffer.cpp b/common/import_gfx/graphics_importer_buffer.cpp index 9f8629b568..c447948b16 100644 --- a/common/import_gfx/graphics_importer_buffer.cpp +++ b/common/import_gfx/graphics_importer_buffer.cpp @@ -128,16 +128,19 @@ void GRAPHICS_IMPORTER_BUFFER::ImportTo( GRAPHICS_IMPORTER& aImporter ) // in the KiCad drawing area else if( aImporter.GetImportOffsetMM() == VECTOR2D( 0, 0 ) ) { - VECTOR2D offset = boundingBox.GetOrigin(); - aImporter.SetImportOffsetMM( -offset ); + if( boundingBox.GetRight() > std::numeric_limits::max() + || boundingBox.GetBottom() > std::numeric_limits::max() + || boundingBox.GetLeft() < std::numeric_limits::min() + || boundingBox.GetTop() < std::numeric_limits::min() ) + { + VECTOR2D offset = boundingBox.GetOrigin(); + aImporter.SetImportOffsetMM( -offset ); + } } else { - VECTOR2D bbox_origin = boundingBox.GetOrigin(); - aImporter.SetImportOffsetMM( -bbox_origin + aImporter.GetImportOffsetMM() ); - - double total_scale_x = aImporter.GetScale().x * aImporter.GetMillimeterToIuFactor(); - double total_scale_y = aImporter.GetScale().y * aImporter.GetMillimeterToIuFactor(); + double total_scale_x = aImporter.GetScale().x * aImporter.GetMillimeterToIuFactor(); + double total_scale_y = aImporter.GetScale().y * aImporter.GetMillimeterToIuFactor(); double max_offset_x = ( aImporter.GetImportOffsetMM().x + boundingBox.GetRight() ) * total_scale_x;