From 822409225ae56bfe61fbf62dadd11366e7e6b10b Mon Sep 17 00:00:00 2001
From: dsa-t <dudesuchamazing@gmail.com>
Date: Tue, 16 Apr 2024 22:36:34 +0000
Subject: [PATCH] STEP export: don't fail when can't construct a wire.

This can happen with very small shapes.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17774


(cherry picked from commit 481c1592aed1e4c9dc8f3db626a46105ae986a3e)

Co-authored-by: Alex Shvartzkop <dudesuchamazing@gmail.com>
---
 pcbnew/exporters/step/step_pcb_model.cpp | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/pcbnew/exporters/step/step_pcb_model.cpp b/pcbnew/exporters/step/step_pcb_model.cpp
index 086a6a05f3..0285cd8e41 100644
--- a/pcbnew/exporters/step/step_pcb_model.cpp
+++ b/pcbnew/exporters/step/step_pcb_model.cpp
@@ -851,18 +851,32 @@ bool STEP_PCB_MODEL::MakeShapes( std::vector<TopoDS_Shape>& aShapes, const SHAPE
                 if( !makeWireFromChain( mkWire, contour ) )
                     continue;
 
-                wxASSERT( mkWire.IsDone() );
+                if( !mkWire.IsDone() )
+                {
+                    ReportMessage( wxString::Format(
+                            _( "Wire not done (contour %d, points %d): OCC error %d\n" ),
+                            static_cast<int>( contId ), static_cast<int>( contour.PointCount() ),
+                            static_cast<int>( mkWire.Error() ) ) );
+                }
 
                 if( contId == 0 ) // Outline
-                    mkFace = BRepBuilderAPI_MakeFace( mkWire.Wire() );
+                {
+                    if( mkWire.IsDone() )
+                        mkFace = BRepBuilderAPI_MakeFace( mkWire.Wire() );
+                    else
+                        continue;
+                }
                 else // Hole
-                    mkFace.Add( mkWire );
+                {
+                    if( mkWire.IsDone() )
+                        mkFace.Add( mkWire );
+                }
             }
             catch( const Standard_Failure& e )
             {
                 ReportMessage(
                         wxString::Format( wxT( "MakeShapes (contour %d): OCC exception: %s\n" ),
-                                          contId, e.GetMessageString() ) );
+                                          static_cast<int>( contId ), e.GetMessageString() ) );
                 return false;
             }
         }