Start: add f3d previews

This commit is contained in:
MaxiV
2024-10-07 10:51:01 -03:00
committed by Benjamin Nauck
parent fd390acd53
commit a2055d7b90

View File

@@ -283,9 +283,13 @@ void DisplayedFilesModel::addFile(const QString& filePath)
if (!qfi.isReadable()) {
return;
}
// Check if FreeCAD can open the file by its extension
if (!freecadCanOpen(qfi.suffix())) {
return;
}
// Add file information to cache
_fileInfoCache.emplace_back(getFileInfo(filePath.toStdString()));
if (qfi.suffix().toLower() == QLatin1String("fcstd")) {
auto thumbnail = loadFCStdThumbnail(filePath.toStdString());
@@ -293,6 +297,33 @@ void DisplayedFilesModel::addFile(const QString& filePath)
_imageCache.insert(filePath, thumbnail);
}
}
else {
// If it is not a FreeCAD file, generate thumbnail using F3D
QString thumbnailPath = QString(QLatin1String("%1/%2_thumbnail.png"))
.arg(QLatin1String("/tmp"))
.arg(qfi.baseName()); // Temporary path for the thumbnail
QString command =
QString(QLatin1String("f3d --config=thumbnail --load-plugins=occt --verbose=quiet "
"--output=%1 --resolution=%2,%3 %4"))
.arg(thumbnailPath)
.arg(128) // Thumbnail size in X
.arg(128) // Thumbnail size in Y
.arg(filePath); // Input file
// Run the f3d command to generate the thumbnail
int result = std::system(command.toStdString().c_str());
// Check if the thumbnail was generated successfully and exists
if (result == 0 && QFile::exists(thumbnailPath)) {
QFile thumbnailFile(thumbnailPath);
if (thumbnailFile.open(QIODevice::ReadOnly)) {
QByteArray thumbnailData = thumbnailFile.readAll();
thumbnailFile.close();
_imageCache.insert(filePath, thumbnailData);
}
}
}
}
void DisplayedFilesModel::clear()