← Back to team overview

kicad-developers team mailing list archive

Re: New Footprint libs and wizard issues

 

Attached is a patch that adds support for custom environment paths. Previously the wizard would only accept KISYSMOD, KIPRJMOD and the github one.

left some legacy handling in the GetAutoPath, as to not break anything, I can remove it if wanted.


- Kristoffer


On 2018-04-04 11:02, jp charras wrote:
Le 04/04/2018 à 10:01, kristoffer Ödmark a écrit :
Hello!

So it was a while since I made some noise, so its time again.

Is there a way to create new footprint libs from KiCad? I cannot find it,
right now I create them by mkdir name.pretty, thento be able to add them
with the wizard, I have to create a temp.kicad_mod file in that folder.

Should this be considered a bug, and if so, would it go into v5? I would
like to be able to add/create empty libs, and then populate them all from within
kicad.
In footprint library, the third tool.
(Tooltip: Create new lib and save current footprint)

I also noticed that the wizard does not autoreplace the paths with the configured
paths in kicad the same way that the symbol library editor does. Should this also
be considered a bug and would a fix be accepted in v5?

- Kristoffer
It works for me.



>From 419f409524fe2ab95fcee5eefc7404cbefda1ab7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= <kristoffer.odmark90@xxxxxxxxx>
Date: Fri, 6 Apr 2018 12:06:05 +0200
Subject: [PATCH] Footprint Wizard now also handles custom Env paths

---
 common/env_paths.cpp                | 16 ++++++++++++----
 include/env_paths.h                 | 16 ++++++++++++++--
 pcbnew/dialogs/wizard_add_fplib.cpp | 10 ++++++++--
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/common/env_paths.cpp b/common/env_paths.cpp
index 3569c436d..ae3d08b1e 100644
--- a/common/env_paths.cpp
+++ b/common/env_paths.cpp
@@ -64,9 +64,8 @@ static bool normalizeAbsolutePaths( const wxFileName& aPathA,
     return true;
 }
 
-
 wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars,
-        const PROJECT* aProject )
+        const wxString& aProjectPath )
 {
     wxFileName envPath;
     wxString tmp, varName, normalizedFullPath;
@@ -90,9 +89,9 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
         }
     }
 
-    if( varName.IsEmpty() && aProject )
+    if( varName.IsEmpty() && !aProjectPath.IsEmpty() )
     {
-        envPath.SetPath( aProject->GetProjectPath() );
+        envPath.SetPath( aProjectPath );
 
         if( normalizeAbsolutePaths( envPath, aFilePath, &tmp ) )
             varName = PROJECT_VAR_NAME;
@@ -111,6 +110,15 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
     return normalizedFullPath;
 }
 
+wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars,
+        const PROJECT* aProject )
+{
+  if( aProject )
+    return NormalizePath( aFilePath, aEnvVars, aProject->GetProjectPath() );
+  else
+    return NormalizePath( aFilePath, aEnvVars, "" );
+}
+
 
 // Create file path by appending path and file name. This approach allows the filename
 // to contain a relative path, whereas wxFileName::SetPath() would replace the
diff --git a/include/env_paths.h b/include/env_paths.h
index bac92ffca..a27fbcc7c 100644
--- a/include/env_paths.h
+++ b/include/env_paths.h
@@ -39,6 +39,18 @@
 wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars,
         const PROJECT* aProject );
 
+/**
+ * Normalizes a file path to an environmental variable, if possible.
+ *
+ * @param aFilePath is the full file path (path and file name) to be normalized.
+ * @param aEnvVars is an optional map of environmental variables to try substition with.
+ * @param aProjectPath is an optional string to normalize the file path to the project path.
+ * @return Normalized full file path (path and file name) if succeeded or empty string if the
+ *          path could not be normalized.
+ */
+wxString NormalizePath(
+        const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars, const wxString& aProjectPath );
+
 /**
  * Searches the default paths trying to find one with the requested file.
  *
@@ -48,7 +60,7 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
  * @return Full path (apth and file name) if the file was found in one of the paths, otherwise
  *      an empty string.
 */
-wxString ResolveFile( const wxString& aFileName, const ENV_VAR_MAP* aEnvVars,
-        const PROJECT* aProject );
+wxString ResolveFile(
+        const wxString& aFileName, const ENV_VAR_MAP* aEnvVars, const PROJECT* aProject );
 
 #endif /* ENV_PATHS_H */
diff --git a/pcbnew/dialogs/wizard_add_fplib.cpp b/pcbnew/dialogs/wizard_add_fplib.cpp
index 193253cb3..838222402 100644
--- a/pcbnew/dialogs/wizard_add_fplib.cpp
+++ b/pcbnew/dialogs/wizard_add_fplib.cpp
@@ -46,6 +46,7 @@
 #include <bitmaps.h>
 
 #include <class_module.h>
+#include <env_paths.h>
 
 #ifdef BUILD_GITHUB_PLUGIN
 #include <../github/github_getliblist.h>
@@ -249,8 +250,13 @@ wxString WIZARD_FPLIB_TABLE::LIBRARY::GetAutoPath( LIB_SCOPE aScope ) const
             return rel_path;
     }
 
-    // Return the full path
-    return m_path;
+    rel_path = NormalizePath( wxFileName( m_path ), &Pgm().GetLocalEnvVariables(), project_env );
+
+    // If normalizePath failed, then rel_path will be empty, m_path is the full path.
+    if( rel_path.IsEmpty() )
+      return m_path;
+
+    return rel_path;
 }
 
 
-- 
2.16.2


Follow ups

References