Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substutute relative library path when inserting component in schematic #923

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions qucs/qucs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void QucsApp::fillLibrariesTreeView ()
// newitem->setBackground
topitems.append (newitem);

populateLibTreeFromDir(QucsSettings.LibDir, topitems);
populateLibTreeFromDir(QucsSettings.LibDir, topitems, true);

// make the user libraries section header
newitem = new QTreeWidgetItem((QTreeWidget*)0, QStringList("User Libraries"));
Expand All @@ -620,14 +620,14 @@ void QucsApp::fillLibrariesTreeView ()
newitem->setFont (0, sectionFont);
topitems.append (newitem);
if (!ProjName.isEmpty()) {
populateLibTreeFromDir(QucsSettings.QucsWorkDir.absolutePath(), topitems);
populateLibTreeFromDir(QucsSettings.QucsWorkDir.absolutePath(), topitems, true);
}

libTreeWidget->insertTopLevelItems(0, topitems);
}


bool QucsApp::populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidgetItem *> &topitems)
bool QucsApp::populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidgetItem *> &topitems, bool relpath)
{
QDir LibDir(LibDirPath);
QStringList LibFiles = LibDir.entryList(QStringList("*.lib"), QDir::Files, QDir::Name);
Expand All @@ -643,7 +643,7 @@ bool QucsApp::populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidge

ComponentLibrary parsedlibrary;

int result = parseComponentLibrary (libPath , parsedlibrary);
int result = parseComponentLibrary (libPath , parsedlibrary, QUCS_COMP_LIB_FULL, relpath);
QStringList nameAndFileName;
nameAndFileName.append (parsedlibrary.name);
nameAndFileName.append (LibDirPath + *it);
Expand Down
2 changes: 1 addition & 1 deletion qucs/qucs.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private slots:
void updateRecentFilesList(QString s);
void successExportMessages(bool ok);
void fillLibrariesTreeView (void);
bool populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidgetItem *> &topitems);
bool populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidgetItem *> &topitems, bool relpath = false);
void saveSettings();
QWidget *getSchematicWidget(QucsDoc *Doc);

Expand Down
16 changes: 12 additions & 4 deletions qucs/qucslib_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,14 @@ inline int makeModelString (QString libPath, QString compname, QString compstrin
}


inline int parseQucsComponentLibrary (QString libPath, ComponentLibrary &library, LIB_PARSE_WHAT what = QUCS_COMP_LIB_FULL)
inline int parseQucsComponentLibrary (QString libPath, ComponentLibrary &library,
LIB_PARSE_WHAT what = QUCS_COMP_LIB_FULL, bool relpath = false)
{
int Start, End, NameStart, NameEnd;

QString filename = getLibAbsPath(libPath);
QFileInfo inf(filename);
QString relName = inf.baseName();

QFile file (filename);

Expand Down Expand Up @@ -309,7 +312,11 @@ inline int parseQucsComponentLibrary (QString libPath, ComponentLibrary &library
component.definition = LibraryString.mid(Start, End-Start);

// construct model string
int result = makeModelString (libPath, component.name, component.definition, component.modelString, library.defaultSymbol);
QString libName = libPath;
if (relpath) {
libName = relName;
}
int result = makeModelString (libName, component.name, component.definition, component.modelString, library.defaultSymbol);
if (result != QUCS_COMP_LIB_OK) return result;

library.components.append (component);
Expand Down Expand Up @@ -486,9 +493,10 @@ inline int parseSPICEComponentLibrary (QString libPath, ComponentLibrary &librar
return QUCS_COMP_LIB_OK;
}

inline int parseComponentLibrary (QString filename, ComponentLibrary &library, LIB_PARSE_WHAT what = QUCS_COMP_LIB_FULL)
inline int parseComponentLibrary (QString filename, ComponentLibrary &library,
LIB_PARSE_WHAT what = QUCS_COMP_LIB_FULL, bool relpath = false)
{
int r = parseQucsComponentLibrary(filename,library,what);
int r = parseQucsComponentLibrary(filename,library,what,relpath);
if (r!=QUCS_COMP_LIB_OK) {
r = parseSPICEComponentLibrary(filename,library);
}
Expand Down
Loading