Small changes to match conventions.

This commit is contained in:
Leonardo Zide 2023-06-18 19:06:44 -07:00
parent eade4bcb5f
commit 7271679f9d
3 changed files with 40 additions and 38 deletions

View file

@ -1620,7 +1620,7 @@ void lcBlenderPreferences::ShowResult()
QString const& Title = tr ("%1 Blender Addon Install").arg(LC_PRODUCTNAME_STR); QString const& Title = tr ("%1 Blender Addon Install").arg(LC_PRODUCTNAME_STR);
QString const& Header = "<b>" + tr ("Addon install failed.") + "</b>"; QString const& Header = "<b>" + tr ("Addon install failed.") + "</b>";
QString const& Body = tr ("LDraw addon install encountered one or more errors. See Show Details..."); QString const& Body = tr ("LDraw addon install encountered one or more errors. See Show Details...");
ShowMessage(Header, Title, Body, StdErrLog, MBB_OK, QMessageBox::Critical); ShowMessage(Header, Title, Body, StdErrLog, MBB_OK, QMessageBox::Warning);
} }
else else
{ {
@ -1883,7 +1883,7 @@ void lcBlenderPreferences::ReadStdOut()
QString const StdOutLog = QDir::toNativeSeparators(QString("<br>- See %1/Blender/stdout-blender-addon-install") QString const StdOutLog = QDir::toNativeSeparators(QString("<br>- See %1/Blender/stdout-blender-addon-install")
.arg(mDataDir)); .arg(mDataDir));
QMessageBox::Icon Icon = Error ? QMessageBox::Critical : QMessageBox::Warning; QMessageBox::Icon Icon = QMessageBox::Warning;
QString const& Items = Error ? tr("errors%1").arg(Warning ? tr(" and warnings") : "") : Warning ? tr("warnings") : ""; QString const& Items = Error ? tr("errors%1").arg(Warning ? tr(" and warnings") : "") : Warning ? tr("warnings") : "";
QString const& Title = tr ("%1 Blender Addon Install").arg(LC_PRODUCTNAME_STR); QString const& Title = tr ("%1 Blender Addon Install").arg(LC_PRODUCTNAME_STR);

View file

@ -18,7 +18,7 @@
#define LC_POVRAY_MEMORY_MAPPED_FILE 1 #define LC_POVRAY_MEMORY_MAPPED_FILE 1
#endif #endif
static inline QString ElapsedTime(const qint64 &Duration) static inline QString ElapsedTime(const qint64& Duration)
{ {
qint64 Elapsed = Duration; qint64 Elapsed = Duration;
int Milliseconds = int(Elapsed % 1000); int Milliseconds = int(Elapsed % 1000);
@ -179,11 +179,17 @@ lcRenderDialog::~lcRenderDialog()
delete ui; delete ui;
} }
QString lcRenderDialog::GetOutputFileName(int StdErr) const QString lcRenderDialog::GetStdOutFileName() const
{ {
QString LogFile = mCommand == POVRAY_RENDER QString LogFile = mCommand == POVRAY_RENDER ? QLatin1String("leocad-povray-render.out") : QLatin1String("leocad-blender-render.out");
? StdErr ? QLatin1String("leocad-povray-render.err") : QLatin1String("leocad-povray-render.out")
: StdErr ? QLatin1String("leocad-blender-render.err") : QLatin1String("leocad-blender-render.out"); return QDir(QDir::tempPath()).absoluteFilePath(LogFile);
}
QString lcRenderDialog::GetStdErrFileName() const
{
QString LogFile = mCommand == POVRAY_RENDER ? QLatin1String("leocad-povray-render.err") : QLatin1String("leocad-blender-render.err");
return QDir(QDir::tempPath()).absoluteFilePath(LogFile); return QDir(QDir::tempPath()).absoluteFilePath(LogFile);
} }
@ -221,7 +227,7 @@ void lcRenderDialog::CloseProcess()
mOutputBuffer = nullptr; mOutputBuffer = nullptr;
mOutputFile.close(); mOutputFile.close();
QFile::remove(GetOutputFileName()); QFile::remove(GetStdOutFileName());
#endif #endif
QFile::remove(GetPOVFileName()); QFile::remove(GetPOVFileName());
@ -322,7 +328,7 @@ void lcRenderDialog::on_RenderButton_clicked()
Arguments.append("-O-"); Arguments.append("-O-");
#if LC_POVRAY_MEMORY_MAPPED_FILE #if LC_POVRAY_MEMORY_MAPPED_FILE
Arguments.append(QString::fromLatin1("+SM\"%1\"").arg(GetOutputFileName())); Arguments.append(QString::fromLatin1("+SM\"%1\"").arg(GetStdOutFileName()));
#endif #endif
int Quality = ui->QualityComboBox->currentIndex(); int Quality = ui->QualityComboBox->currentIndex();
@ -369,15 +375,14 @@ void lcRenderDialog::on_RenderButton_clicked()
POVRayPath = QDir::cleanPath(QCoreApplication::applicationDirPath() + QLatin1String("/povray")); POVRayPath = QDir::cleanPath(QCoreApplication::applicationDirPath() + QLatin1String("/povray"));
#endif #endif
mProcess = new RenderProcess(this); mProcess = new lcRenderProcess(this);
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
connect(mProcess, SIGNAL(readyReadStandardError()), this, SLOT(ReadStdErr())); connect(mProcess, SIGNAL(readyReadStandardError()), this, SLOT(ReadStdErr()));
#endif #endif
int const StdErr = 1;
QStringList POVEnv = QProcess::systemEnvironment(); QStringList POVEnv = QProcess::systemEnvironment();
POVEnv.prepend("POV_IGNORE_SYSCONF_MSG=1"); POVEnv.prepend("POV_IGNORE_SYSCONF_MSG=1");
mProcess->setEnvironment(POVEnv); mProcess->setEnvironment(POVEnv);
mProcess->setStandardErrorFile(GetOutputFileName(StdErr)); mProcess->setStandardErrorFile(GetStdErrFileName());
mProcess->start(POVRayPath, Arguments); mProcess->start(POVRayPath, Arguments);
mImage = QImage(ui->WidthEdit->text().toInt(), ui->HeightEdit->text().toInt(), QImage::Format_ARGB32); mImage = QImage(ui->WidthEdit->text().toInt(), ui->HeightEdit->text().toInt(), QImage::Format_ARGB32);
@ -413,7 +418,7 @@ void lcRenderDialog::on_RenderButton_clicked()
mBlendProgValue = 0; mBlendProgValue = 0;
mBlendProgMax = 0; mBlendProgMax = 0;
QStringList const &DataPathList = QStandardPaths::standardLocations(QStandardPaths::DataLocation); const QStringList DataPathList = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
mDataPath = DataPathList.first(); mDataPath = DataPathList.first();
QString const DefaultBlendFile = QString("%1/blender/config/%2").arg(mDataPath).arg(LC_BLENDER_ADDON_BLEND_FILE); QString const DefaultBlendFile = QString("%1/blender/config/%2").arg(mDataPath).arg(LC_BLENDER_ADDON_BLEND_FILE);
@ -473,7 +478,7 @@ void lcRenderDialog::on_RenderButton_clicked()
ScriptCommand = QString("%1 %2").arg(lcGetProfileString(LC_PROFILE_BLENDER_PATH)).arg(Arguments.join(" ")); ScriptCommand = QString("%1 %2").arg(lcGetProfileString(LC_PROFILE_BLENDER_PATH)).arg(Arguments.join(" "));
if (mCommand == OPEN_IN_BLENDER) if (mCommand == OPEN_IN_BLENDER)
ScriptCommand.append(QString(" > %1").arg(QDir::toNativeSeparators(GetOutputFileName()))); ScriptCommand.append(QString(" > %1").arg(QDir::toNativeSeparators(GetStdOutFileName())));
const QLatin1String LineEnding("\r\n"); const QLatin1String LineEnding("\r\n");
@ -507,24 +512,23 @@ void lcRenderDialog::on_RenderButton_clicked()
ShellProgram = QLatin1String(LC_UNIX_SHELL); ShellProgram = QLatin1String(LC_UNIX_SHELL);
#endif #endif
mProcess = new RenderProcess(this); mProcess = new lcRenderProcess(this);
connect(mProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadStdOut())); connect(mProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadStdOut()));
QString const LDrawLibPath = QFileInfo(lcGetProfileString(LC_PROFILE_PARTS_LIBRARY)).absolutePath(); QString const LDrawLibPath = QFileInfo(lcGetProfileString(LC_PROFILE_PARTS_LIBRARY)).absolutePath();
QStringList SystemEnvironment = QProcess::systemEnvironment(); QStringList SystemEnvironment = QProcess::systemEnvironment();
SystemEnvironment.prepend("LDRAW_DIRECTORY=" + LDrawLibPath); SystemEnvironment.prepend("LDRAW_DIRECTORY=" + LDrawLibPath);
int const StdErr = 1;
mProcess->setEnvironment(SystemEnvironment); mProcess->setEnvironment(SystemEnvironment);
mProcess->setWorkingDirectory(QDir::toNativeSeparators(QString("%1/blender").arg(mDataPath))); mProcess->setWorkingDirectory(QDir::toNativeSeparators(QString("%1/blender").arg(mDataPath)));
mProcess->setStandardErrorFile(GetOutputFileName(StdErr)); mProcess->setStandardErrorFile(GetStdErrFileName());
if (mCommand == OPEN_IN_BLENDER) if (mCommand == OPEN_IN_BLENDER)
{ {
QFileInfo Info(GetOutputFileName()); QFileInfo Info(GetStdOutFileName());
if (Info.exists()) if (Info.exists())
QFile::remove(Info.absoluteFilePath()); QFile::remove(Info.absoluteFilePath());
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -552,10 +556,10 @@ void lcRenderDialog::on_RenderButton_clicked()
bool const Warning = QString(Ba).contains(QRegExp("(?:\\w)*WARNING: ", Qt::CaseInsensitive)); bool const Warning = QString(Ba).contains(QRegExp("(?:\\w)*WARNING: ", Qt::CaseInsensitive));
if (Error || Warning) if (Error || Warning)
{ {
QMessageBox::Icon Icon = Error ? QMessageBox::Critical : QMessageBox::Warning; QMessageBox::Icon Icon = QMessageBox::Warning;
QString const &Items = Error ? tr("errors%1").arg(Warning ? tr(" and warnings") : "") : Warning ? tr("warnings") : ""; const QString Items = Error ? tr("errors%1").arg(Warning ? tr(" and warnings") : "") : Warning ? tr("warnings") : "";
QString const &Title = tr("Open in Blender output"); const QString Title = tr("Open in Blender output");
QString const &Body = tr("Open in Blender encountered %1. See Show Details...").arg(Items); const QString Body = tr("Open in Blender encountered %1. See Show Details...").arg(Items);
lcBlenderPreferences::ShowMessage(Body, Title, QString(), QString(Ba), 0, Icon); lcBlenderPreferences::ShowMessage(Body, Title, QString(), QString(Ba), 0, Icon);
} }
} }
@ -663,15 +667,14 @@ void lcRenderDialog::ReadStdOut()
} }
} }
QString lcRenderDialog::ReadStdErr(bool &HasError) const QString lcRenderDialog::ReadStdErr(bool& HasError) const
{ {
HasError = mCommand == BLENDER_RENDER ? false : true; HasError = mCommand == BLENDER_RENDER ? false : true;
QFile File; QFile File;
QStringList returnLines; QStringList returnLines;
int const StdErr = 1; File.setFileName(GetStdErrFileName());
File.setFileName(GetOutputFileName(StdErr));
if (! File.open(QFile::ReadOnly | QFile::Text)) if (! File.open(QFile::ReadOnly | QFile::Text))
{ {
@ -703,7 +706,7 @@ QString lcRenderDialog::ReadStdErr(bool &HasError) const
void lcRenderDialog::WriteStdOut() void lcRenderDialog::WriteStdOut()
{ {
QFile File(GetOutputFileName()); QFile File(GetStdOutFileName());
if (File.open(QFile::WriteOnly | QIODevice::Truncate | QFile::Text)) if (File.open(QFile::WriteOnly | QIODevice::Truncate | QFile::Text))
{ {
@ -741,7 +744,7 @@ void lcRenderDialog::Update()
#if LC_POVRAY_MEMORY_MAPPED_FILE #if LC_POVRAY_MEMORY_MAPPED_FILE
if (!mOutputBuffer) if (!mOutputBuffer)
{ {
mOutputFile.setFileName(GetOutputFileName()); mOutputFile.setFileName(GetStdOutFileName());
if (!mOutputFile.open(QFile::ReadWrite)) if (!mOutputFile.open(QFile::ReadWrite))
return; return;
@ -817,8 +820,8 @@ void lcRenderDialog::ShowResult()
ui->RenderProgress->setRange(0,1); ui->RenderProgress->setRange(0,1);
ui->RenderProgress->setValue(0); ui->RenderProgress->setValue(0);
QString const &Title = mCommand == BLENDER_RENDER ? tr("Blender Render") : tr("POV-Ray Render"); QString const Title = mCommand == BLENDER_RENDER ? tr("Blender Render") : tr("POV-Ray Render");
QString const &Body = tr ("An error occurred while rendering. See Show Details..."); QString const Body = tr ("An error occurred while rendering. See Show Details...");
lcBlenderPreferences::ShowMessage(Body, Title, QString(), StdErrLog, 0, QMessageBox::Warning); lcBlenderPreferences::ShowMessage(Body, Title, QString(), StdErrLog, 0, QMessageBox::Warning);
return; return;
} }
@ -891,7 +894,7 @@ void lcRenderDialog::on_OutputBrowseButton_clicked()
void lcRenderDialog::on_RenderOutputButton_clicked() void lcRenderDialog::on_RenderOutputButton_clicked()
{ {
QString RenderType = mCommand == POVRAY_RENDER ? QLatin1String("POV-Ray") : QLatin1String("Blender"); QString RenderType = mCommand == POVRAY_RENDER ? QLatin1String("POV-Ray") : QLatin1String("Blender");
QFileInfo FileInfo(GetOutputFileName()); QFileInfo FileInfo(GetStdOutFileName());
if (!FileInfo.exists()) if (!FileInfo.exists())
{ {
QMessageBox::warning(this, tr("Error"), tr("%1 Standard output file not found: %2.") QMessageBox::warning(this, tr("Error"), tr("%1 Standard output file not found: %2.")
@ -902,8 +905,7 @@ void lcRenderDialog::on_RenderOutputButton_clicked()
QDesktopServices::openUrl(QUrl("file:///"+FileInfo.absoluteFilePath(), QUrl::TolerantMode)); QDesktopServices::openUrl(QUrl("file:///"+FileInfo.absoluteFilePath(), QUrl::TolerantMode));
} }
lcRenderProcess::~lcRenderProcess()
RenderProcess::~RenderProcess()
{ {
if(state() == QProcess::Running || state() == QProcess::Starting) if(state() == QProcess::Running || state() == QProcess::Starting)
{ {

View file

@ -6,17 +6,16 @@ namespace Ui {
class lcRenderDialog; class lcRenderDialog;
} }
class QProcess; class lcRenderProcess : public QProcess
class RenderProcess : public QProcess
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit RenderProcess(QObject* parent = nullptr) explicit lcRenderProcess(QObject* parent = nullptr)
: QProcess(parent) : QProcess(parent)
{ {
} }
~RenderProcess(); ~lcRenderProcess();
}; };
class lcRenderPreviewWidget : public QWidget class lcRenderPreviewWidget : public QWidget
@ -66,7 +65,8 @@ protected slots:
void UpdateElapsedTime() const; void UpdateElapsedTime() const;
protected: protected:
QString GetOutputFileName(int StdErr = 0) const; QString GetStdOutFileName() const;
QString GetStdErrFileName() const;
QString GetPOVFileName() const; QString GetPOVFileName() const;
QString ReadStdErr(bool& Error) const; QString ReadStdErr(bool& Error) const;
void CloseProcess(); void CloseProcess();
@ -76,7 +76,7 @@ protected:
int TerminateChildProcess(const qint64 Pid, const qint64 Ppid); int TerminateChildProcess(const qint64 Pid, const qint64 Ppid);
#endif #endif
#ifndef QT_NO_PROCESS #ifndef QT_NO_PROCESS
RenderProcess* mProcess; lcRenderProcess* mProcess;
#endif #endif
enum CommandType enum CommandType
{ {