← Back to team overview

kicad-developers team mailing list archive

[PATCH] Replace .wrl files with .step on export (fixes lp:1710796)

 

The attached patch implements the feature suggested here :
https://bugs.launchpad.net/kicad/+bug/1710796

Problem:

.wrl files are specified as default but these don't export to MCAD.

Solution:

On STEP export, wrl files are replaced with their step counterparts (if
such models exist).

This is essentially what Maurice's famous StepUP tool does.

Turns out it was a pretty simple fix :)

Regards,
Oliver
From 6d48b4725159309c34e084788e70d8f5d311fe91 Mon Sep 17 00:00:00 2001
From: Oliver <oliver.henry.walters@xxxxxxxxx>
Date: Sat, 4 Nov 2017 23:44:13 +1100
Subject: [PATCH] Replace WRL files with STEP equivalent

- Use simple filename matching
- If a STEP file is found, use that instead
- Similar behaviour to the infamous StepUp tool
---
 utils/kicad2step/pcb/oce_utils.cpp | 57 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/utils/kicad2step/pcb/oce_utils.cpp b/utils/kicad2step/pcb/oce_utils.cpp
index cce6d1f..5ed7ac1 100644
--- a/utils/kicad2step/pcb/oce_utils.cpp
+++ b/utils/kicad2step/pcb/oce_utils.cpp
@@ -148,7 +148,8 @@ enum FormatType
     FMT_STEP = 1,
     FMT_IGES = 2,
     FMT_EMN  = 3,
-    FMT_IDF  = 4
+    FMT_IDF  = 4,
+    FMT_WRL  = 5,  // .wrl files are replaced with MCAD equivalent
 };
 
 
@@ -168,6 +169,9 @@ FormatType fileType( const char* aFileName )
 
     wxString ext = lfile.GetExt();
 
+    if( ext == "wrl" || ext == "WRL" || ext == "Wrl" )
+        return FMT_WRL;
+
     if( ext == "idf" || ext == "IDF" )
         return FMT_IDF;     // component outline
     else if( ext == "emn" || ext == "EMN" )
@@ -888,6 +892,57 @@ bool PCBMODEL::getModelLabel( const std::string aFileName, TDF_Label& aLabel )
             }
             break;
 
+        case FMT_WRL:
+            /* WRL files are preferred for internal rendering,
+             * due to superior material properties, etc.
+             * However they are not suitable for MCAD export.
+             *
+             * If a .wrl file is specified, attempt to locate
+             * a replacement file for it.
+             *
+             * If a valid replacement file is found, the label
+             * for THAT file will be associated with the .wrl file
+             *
+             */
+            {
+                wxFileName wrlName( aFileName );
+
+                wxString basePath = wrlName.GetPath();
+                wxString baseName = wrlName.GetName();
+
+                // List of alternate files to look for
+                // Given in order of preference
+                // (Break if match is found)
+                wxArrayString alts;
+
+                // Step files
+                alts.Add( "stp" );
+                alts.Add( "step" );
+                alts.Add( "STP" );
+                alts.Add( "STEP" );
+                alts.Add( "Stp" );
+                alts.Add( "Step" );
+
+                //TODO - Other alternative formats?
+
+                for( auto alt : alts )
+                {
+                    wxFileName altFile( basePath, baseName + "." + alt );
+
+                    if( altFile.IsOk() && altFile.FileExists() )
+                    {
+                        std::string altFileName = altFile.GetFullPath().ToStdString();
+
+                        if( getModelLabel( altFileName, aLabel ) )
+                        {
+                            return true;
+                        }
+                    }
+                }
+            }
+
+            break;
+
         // TODO: implement IDF and EMN converters
 
         default:
-- 
2.7.4


Follow ups