Better path handling for importing LTspice files.
This commit is contained in:
parent
3bdc66d3ed
commit
4f52c69724
|
@ -27,8 +27,6 @@
|
|||
#include <sch_plugins/ltspice/ltspice_sch_parser.h>
|
||||
#include <sch_plugins/ltspice/ltspice_schematic.h>
|
||||
#include <sch_io_mgr.h>
|
||||
#include <base_units.h>
|
||||
#include <core/kicad_algo.h>
|
||||
#include <schematic.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <sch_sheet_pin.h>
|
||||
|
@ -38,7 +36,6 @@
|
|||
#include <sch_edit_frame.h>
|
||||
#include <sch_shape.h>
|
||||
#include <sch_bus_entry.h>
|
||||
#include <kiplatform/environment.h>
|
||||
|
||||
|
||||
void LTSPICE_SCH_PARSER::Parse( SCH_SHEET_PATH* aSheet,
|
||||
|
@ -77,8 +74,7 @@ void LTSPICE_SCH_PARSER::Parse( SCH_SHEET_PATH* aSheet,
|
|||
|
||||
void LTSPICE_SCH_PARSER::readIncludes( std::vector<LTSPICE_SCHEMATIC::LT_ASC>& outLT_ASCs )
|
||||
{
|
||||
static wxString ltSubDir = KIPLATFORM::ENV::GetDocumentsPath() + wxS( "/LTspiceXVII/lib/sub/" );
|
||||
|
||||
wxString ltSubDir = m_lt_schematic->GetLTspiceDataDir().GetFullPath() + wxS( "lib/sub/" );
|
||||
wxString path;
|
||||
|
||||
for( const LTSPICE_SCHEMATIC::LT_ASC& asc : outLT_ASCs )
|
||||
|
@ -349,22 +345,14 @@ VECTOR2I LTSPICE_SCH_PARSER::ToKicadFontSize( int aLTFontSize )
|
|||
return VECTOR2I( schIUScale.MilsToIU( mils ), schIUScale.MilsToIU( mils ) );
|
||||
};
|
||||
|
||||
if( aLTFontSize == 1 )
|
||||
return MILS_SIZE( 36 );
|
||||
else if( aLTFontSize == 2 )
|
||||
return MILS_SIZE( 42 );
|
||||
else if( aLTFontSize == 3 )
|
||||
return MILS_SIZE( 50 );
|
||||
else if( aLTFontSize == 4 )
|
||||
return MILS_SIZE( 60 );
|
||||
else if( aLTFontSize == 5 )
|
||||
return MILS_SIZE( 72 );
|
||||
else if( aLTFontSize == 6 )
|
||||
return MILS_SIZE( 88 );
|
||||
else if( aLTFontSize == 7 )
|
||||
return MILS_SIZE( 108 );
|
||||
else
|
||||
return ToKicadFontSize( 2 );
|
||||
if( aLTFontSize == 1 ) return MILS_SIZE( 36 );
|
||||
else if( aLTFontSize == 2 ) return MILS_SIZE( 42 );
|
||||
else if( aLTFontSize == 3 ) return MILS_SIZE( 50 );
|
||||
else if( aLTFontSize == 4 ) return MILS_SIZE( 60 );
|
||||
else if( aLTFontSize == 5 ) return MILS_SIZE( 72 );
|
||||
else if( aLTFontSize == 6 ) return MILS_SIZE( 88 );
|
||||
else if( aLTFontSize == 7 ) return MILS_SIZE( 108 );
|
||||
else return ToKicadFontSize( 2 );
|
||||
}
|
||||
|
||||
|
||||
|
@ -903,7 +891,7 @@ SCH_LABEL_BASE* LTSPICE_SCH_PARSER::CreateSCH_LABEL( KICAD_T aType, const VECTOR
|
|||
void LTSPICE_SCH_PARSER::CreateFields( LTSPICE_SCHEMATIC::LT_SYMBOL& aLTSymbol,
|
||||
SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheet )
|
||||
{
|
||||
wxString libPath = KIPLATFORM::ENV::GetDocumentsPath() + wxS( "/LTspiceXVII/lib/" );
|
||||
wxString libPath = m_lt_schematic->GetLTspiceDataDir().GetFullPath() + wxS( "lib/" );
|
||||
wxString symbolName = aLTSymbol.Name.Upper();
|
||||
wxString type = aLTSymbol.SymAttributes[ wxS( "TYPE" ) ].Upper();
|
||||
wxString prefix = aLTSymbol.SymAttributes[ wxS( "PREFIX" ) ].Upper();
|
||||
|
|
|
@ -66,9 +66,6 @@ class SCH_SHAPE;
|
|||
class LTSPICE_SCH_PARSER
|
||||
{
|
||||
public:
|
||||
// Size of tiny net labels which none present in original design
|
||||
const int SMALL_LABEL_SIZE = KiROUND( (double) SCH_IU_PER_MM * 0.4 );
|
||||
|
||||
explicit LTSPICE_SCH_PARSER( const wxString& aFilename, LTSPICE_SCHEMATIC* aLTSchematic ) :
|
||||
m_lt_schematic( aLTSchematic ),
|
||||
m_powerSymbolIndex( 0 )
|
||||
|
@ -279,18 +276,8 @@ public:
|
|||
void CreateCircle( LTSPICE_SCHEMATIC::LT_SYMBOL& aLTSymbol, int aIndex, SCH_SHEET_PATH* aSheet );
|
||||
|
||||
private:
|
||||
/**
|
||||
* Method for setting Text Justification.
|
||||
*
|
||||
* @param aLineWidth object representing line width from ltspice.
|
||||
*/
|
||||
int getLineWidth( const LTSPICE_SCHEMATIC::LINEWIDTH& aLineWidth );
|
||||
|
||||
/**
|
||||
* Method to get line Style For kicad.
|
||||
*
|
||||
* @param aLineStyle lineStyle from ltspice.
|
||||
*/
|
||||
PLOT_DASH_TYPE getLineStyle( const LTSPICE_SCHEMATIC::LINESTYLE& aLineStyle );
|
||||
|
||||
STROKE_PARAMS getStroke( const LTSPICE_SCHEMATIC::LINEWIDTH& aLineWidth,
|
||||
|
@ -300,7 +287,6 @@ private:
|
|||
|
||||
private:
|
||||
LTSPICE_SCHEMATIC* m_lt_schematic;
|
||||
wxFileName m_libraryFileName;
|
||||
VECTOR2I m_originOffset;
|
||||
std::map<wxString, wxString> m_includes;
|
||||
int m_powerSymbolIndex;
|
||||
|
|
|
@ -26,8 +26,7 @@
|
|||
#include <schematic.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <sch_screen.h>
|
||||
#include <sch_line.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <kiplatform/environment.h>
|
||||
|
||||
/**
|
||||
* @brief schematic PLUGIN for Ltspice (*.asc) and (.asy) format.
|
||||
|
@ -88,7 +87,17 @@ SCH_SHEET* SCH_LTSPICE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSche
|
|||
|
||||
wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
|
||||
|
||||
LTSPICE_SCHEMATIC ascFile( aFileName );
|
||||
wxFileName ltspiceDataDir( KIPLATFORM::ENV::GetUserDataPath(), wxEmptyString );
|
||||
ltspiceDataDir.RemoveLastDir(); // "kicad"
|
||||
ltspiceDataDir.AppendDir( wxS( "LTspice" ) );
|
||||
|
||||
if( !ltspiceDataDir.DirExists() )
|
||||
{
|
||||
ltspiceDataDir = wxFileName( KIPLATFORM::ENV::GetDocumentsPath(), wxEmptyString );
|
||||
ltspiceDataDir.AppendDir( wxS( "LTspiceXVII" ) );
|
||||
}
|
||||
|
||||
LTSPICE_SCHEMATIC ascFile( aFileName, ltspiceDataDir, nullptr, nullptr );
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER sch_plugin;
|
||||
|
||||
sch_plugin.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
|
||||
|
|
|
@ -25,11 +25,9 @@
|
|||
|
||||
#include <sch_plugins/ltspice/ltspice_schematic.h>
|
||||
#include <sch_plugins/ltspice/ltspice_sch_parser.h>
|
||||
#include <sch_io_mgr.h>
|
||||
#include <sch_screen.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/dir.h>
|
||||
#include <kiplatform/environment.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <schematic.h>
|
||||
|
@ -164,9 +162,6 @@ void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
|
|||
|
||||
curSheet->GetScreen()->SetFileName( m_schematic->Prj().GetProjectPath() + sheetName
|
||||
+ ".kicad_sch" );
|
||||
|
||||
// JEY TODO: do we need this?
|
||||
//curSheet->addInstance( sheetPath );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -205,10 +200,10 @@ void LTSPICE_SCHEMATIC::GetAscAndAsyFilePaths( std::map<wxString, wxString>& aMa
|
|||
std::map<wxString, wxString>& aMapOfAsyFiles,
|
||||
const wxFileName& parentFileName )
|
||||
{
|
||||
wxString ltSpiceFolder = KIPLATFORM::ENV::GetDocumentsPath() + wxS( "/LTspiceXVII" );
|
||||
wxString cmpFolder = ltSpiceFolder + wxS( "/lib/cmp/" );
|
||||
wxString subFolder = ltSpiceFolder + wxS( "/lib/sub/" );
|
||||
wxString symFolder = ltSpiceFolder + wxS( "/lib/sym/" );
|
||||
wxString ltSpiceFolder = m_ltspiceDataDir.GetFullPath();
|
||||
wxString cmpFolder = ltSpiceFolder + wxS( "lib/cmp/" );
|
||||
wxString subFolder = ltSpiceFolder + wxS( "lib/sub/" );
|
||||
wxString symFolder = ltSpiceFolder + wxS( "lib/sym/" );
|
||||
wxArrayString fileList;
|
||||
|
||||
wxDir::GetAllFiles( ltSpiceFolder, &fileList );
|
||||
|
@ -329,10 +324,7 @@ void LTSPICE_SCHEMATIC::tokensSizeRangeCheck( size_t aActualSize, int aExpectedM
|
|||
|
||||
void LTSPICE_SCHEMATIC::aggregateAttributeValue( wxArrayString& aTokens, int aIndex )
|
||||
{
|
||||
/**
|
||||
* Merges a value which is across multiple tokens into one token appended with spaces in
|
||||
* between.
|
||||
*/
|
||||
// Merges a value which is across multiple tokens into one token with spaces in between.
|
||||
for( int i = aIndex + 1; i < (int) aTokens.GetCount(); i++ )
|
||||
aTokens[ aIndex ] += " " + aTokens[i];
|
||||
}
|
||||
|
@ -1038,7 +1030,6 @@ std::vector<LTSPICE_SCHEMATIC::LT_ASC> LTSPICE_SCHEMATIC::StructureBuilder()
|
|||
else if( element == "VERSION" )
|
||||
{
|
||||
wxString versionNumber = tokens[1];
|
||||
|
||||
ascFile.Version = integerCheck( versionNumber, lineNumber, fileName );
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ struct LTSPICE_FILE
|
|||
ParentIndex( 0 ),
|
||||
Sheet( nullptr ),
|
||||
Screen( nullptr )
|
||||
|
||||
{ }
|
||||
|
||||
bool operator<( const LTSPICE_FILE& t ) const
|
||||
|
@ -276,17 +275,13 @@ public:
|
|||
BOX2I BoundingBox;
|
||||
};
|
||||
|
||||
explicit LTSPICE_SCHEMATIC( const wxString& aFilename, REPORTER* aReporter = nullptr,
|
||||
PROGRESS_REPORTER* aProgressReporter = nullptr )
|
||||
{
|
||||
m_schematic = nullptr;
|
||||
m_rootSheet = nullptr;
|
||||
m_plugin = nullptr;
|
||||
m_designCenter.x = 0;
|
||||
m_designCenter.y = 0;
|
||||
m_reporter = aReporter;
|
||||
m_progressReporter = aProgressReporter;
|
||||
}
|
||||
explicit LTSPICE_SCHEMATIC( const wxString& aFilename, const wxFileName& aLTspiceDataDir,
|
||||
REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter ) :
|
||||
m_reporter( aReporter ),
|
||||
m_schematic( nullptr ),
|
||||
m_ltspiceDataDir( aLTspiceDataDir ),
|
||||
m_progressReporter( aProgressReporter )
|
||||
{}
|
||||
|
||||
~LTSPICE_SCHEMATIC() {}
|
||||
|
||||
|
@ -352,6 +347,9 @@ public:
|
|||
|
||||
LT_SYMBOL SymbolBuilder( const wxString& aAscFileName, const wxString& aAsyFileContent,
|
||||
LT_ASC& aAscFile );
|
||||
|
||||
const wxFileName& GetLTspiceDataDir() { return m_ltspiceDataDir; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Join value present across multiple tokens into one
|
||||
|
@ -432,15 +430,10 @@ private:
|
|||
static SYMBOLTYPE getSymbolType( const wxString& aValue );
|
||||
|
||||
private:
|
||||
REPORTER* m_reporter;
|
||||
SCHEMATIC* m_schematic;
|
||||
SCH_SHEET* m_rootSheet;
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER* m_plugin;
|
||||
wxFileName m_libraryFileName;
|
||||
wxPoint m_designCenter; //< Used for calculating the required
|
||||
//< offset to apply to the LTspice design
|
||||
//< so that it fits in KiCad canvas
|
||||
PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
|
||||
REPORTER* m_reporter;
|
||||
SCHEMATIC* m_schematic;
|
||||
wxFileName m_ltspiceDataDir;
|
||||
PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
|
||||
|
||||
std::map<wxString, std::map<wxString, wxString>> m_fileCache;
|
||||
};
|
||||
|
|
|
@ -109,6 +109,12 @@ wxString KIPLATFORM::ENV::GetUserConfigPath()
|
|||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserDataPath()
|
||||
{
|
||||
return g_get_user_data_dir();
|
||||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserCachePath()
|
||||
{
|
||||
return g_get_user_cache_dir();
|
||||
|
|
|
@ -65,6 +65,13 @@ namespace KIPLATFORM
|
|||
*/
|
||||
wxString GetUserConfigPath();
|
||||
|
||||
/**
|
||||
* Retrieves the operating system specific path for a user's data store
|
||||
*
|
||||
* @return User config path
|
||||
*/
|
||||
wxString GetUserDataPath();
|
||||
|
||||
/**
|
||||
* Retrieves the operating system specific path for user's application cache
|
||||
*
|
||||
|
|
|
@ -102,6 +102,20 @@ wxString KIPLATFORM::ENV::GetUserConfigPath()
|
|||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserDataPath()
|
||||
{
|
||||
// If called by a python script in stand-alone (outside KiCad), wxStandardPaths::Get()
|
||||
// complains about not existing app. so use a dummy app
|
||||
if( wxTheApp == nullptr )
|
||||
{
|
||||
wxApp dummy;
|
||||
return wxStandardPaths::Get().GetUserDataDir();
|
||||
}
|
||||
|
||||
return wxStandardPaths::Get().GetUserDataDir();
|
||||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserCachePath()
|
||||
{
|
||||
// Unfortunately AppData/Local is the closest analog to "Cache" directories of other platforms
|
||||
|
|
|
@ -85,6 +85,12 @@ wxString KIPLATFORM::ENV::GetUserConfigPath()
|
|||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserDataPath()
|
||||
{
|
||||
return wxStandardPaths::Get().GetUserDataDir();
|
||||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserCachePath()
|
||||
{
|
||||
NSURL* url = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory
|
||||
|
|
Loading…
Reference in New Issue