← Back to team overview

kicad-developers team mailing list archive

PATCH: export IDF without empty PLACEMENT section

 

The attached patch prevents the IDF exporter from creating
a file with an empty PLACEMENT section. Although not really
a bug (the IDFv3 specification does not prohibit empty
sections), SolidWorks/CircuitWorks segfaults on an empty PLACEMENT
section.

The patch was prepared against rev. 5044 but since it only
touches idf_parser.cpp the revision should not be an issue.

- Cirilo
=== modified file 'utils/idftools/idf_parser.cpp'
--- utils/idftools/idf_parser.cpp	2014-06-08 10:35:42 +0000
+++ utils/idftools/idf_parser.cpp	2014-08-03 00:46:20 +0000
@@ -3053,15 +3053,38 @@
             std::map< std::string, IDF3_COMPONENT*>::iterator itcs = components.begin();
             std::map< std::string, IDF3_COMPONENT*>::iterator itce = components.end();
 
-            brd << ".PLACEMENT\n";
+            // determine if there are any component outlines at all and avoid
+            // writing an empty PLACEMENT section if there are no outlines.
+            // this will cost a little time but prevents software such as
+            // CircuitWorks from segfaulting on an empty section.
+
+            bool hasOutlines = false;
 
             while( itcs != itce )
             {
-                itcs->second->writePlaceData( brd );
+                if( itcs->second->GetOutlinesSize() > 0 )
+                {
+                    itcs = components.begin();
+                    hasOutlines = true;
+                    break;
+                }
+
                 ++itcs;
             }
 
-            brd << ".END_PLACEMENT\n";
+            if( hasOutlines )
+            {
+                brd << ".PLACEMENT\n";
+
+                while( itcs != itce )
+                {
+                    itcs->second->writePlaceData( brd );
+                    ++itcs;
+                }
+
+                brd << ".END_PLACEMENT\n";
+            }
+
         }
 
     }


Follow ups