+ improve error handling when rendering a raytracing project

This commit is contained in:
wmayer 2014-06-27 11:58:56 +02:00
parent 2def3c03b8
commit 63aed855ab

View File

@ -559,7 +559,7 @@ CmdRaytracingRender::CmdRaytracingRender()
void CmdRaytracingRender::activated(int iMsg) void CmdRaytracingRender::activated(int iMsg)
{ {
// determining render type // determining render type
std::string renderType; Base::Type renderType;
unsigned int n1 = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId()); unsigned int n1 = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId());
if (n1 != 1) { if (n1 != 1) {
unsigned int n2 = getSelection().countObjectsOfType(Raytracing::LuxProject::getClassTypeId()); unsigned int n2 = getSelection().countObjectsOfType(Raytracing::LuxProject::getClassTypeId());
@ -568,16 +568,16 @@ void CmdRaytracingRender::activated(int iMsg)
QObject::tr("Select one Raytracing project object.")); QObject::tr("Select one Raytracing project object."));
return; return;
} else { } else {
renderType = "luxrender"; renderType = Raytracing::LuxProject::getClassTypeId();
} }
} else { } else {
renderType = "povray"; renderType = Raytracing::RayProject::getClassTypeId();
} }
// checking if renderer is present // checking if renderer is present
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Raytracing"); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Raytracing");
std::string renderer; std::string renderer;
if (renderType == "povray") { if (renderType == Raytracing::RayProject::getClassTypeId()) {
renderer = hGrp->GetASCII("PovrayExecutable", ""); renderer = hGrp->GetASCII("PovrayExecutable", "");
if (renderer == "") { if (renderer == "") {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("POV-Ray not found"), QMessageBox::warning(Gui::getMainWindow(), QObject::tr("POV-Ray not found"),
@ -607,9 +607,17 @@ void CmdRaytracingRender::activated(int iMsg)
} }
} }
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); std::vector<Gui::SelectionObject> Sel = getSelection().getSelectionEx(0, renderType);
if (renderType == Raytracing::RayProject::getClassTypeId()) {
Raytracing::RayProject* proj = static_cast<Raytracing::RayProject*>(Sel[0].getObject());
QFileInfo fi(QString::fromUtf8(proj->PageResult.getValue()));
if (!fi.exists() || !fi.isFile()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("POV-Ray file missing"),
QObject::tr("The POV-Ray project file doesn't exist."));
return;
}
if (renderType == "povray") {
QStringList filter; QStringList filter;
#ifdef FC_OS_WIN32 #ifdef FC_OS_WIN32
filter << QObject::tr("Rendered image (*.bmp)"); filter << QObject::tr("Rendered image (*.bmp)");
@ -632,7 +640,7 @@ void CmdRaytracingRender::activated(int iMsg)
std::stringstream h; std::stringstream h;
h << height; h << height;
std::string par = hGrp->GetASCII("OutputParameters", "+P +A"); std::string par = hGrp->GetASCII("OutputParameters", "+P +A");
doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName); doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].getFeatName());
doCommand(Doc,"import subprocess,tempfile"); doCommand(Doc,"import subprocess,tempfile");
doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.pov')[1]"); doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.pov')[1]");
doCommand(Doc,"f = open(TempFile,'wb')"); doCommand(Doc,"f = open(TempFile,'wb')");
@ -650,8 +658,16 @@ void CmdRaytracingRender::activated(int iMsg)
commitCommand(); commitCommand();
} }
} else { } else {
Raytracing::LuxProject* proj = static_cast<Raytracing::LuxProject*>(Sel[0].getObject());
QFileInfo fi(QString::fromUtf8(proj->PageResult.getValue()));
if (!fi.exists() || !fi.isFile()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Lux project file missing"),
QObject::tr("The Lux project file doesn't exist."));
return;
}
openCommand("Render project"); openCommand("Render project");
doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName); doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].getFeatName());
doCommand(Doc,"import subprocess,tempfile"); doCommand(Doc,"import subprocess,tempfile");
doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.lxs')[1]"); doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.lxs')[1]");
doCommand(Doc,"f = open(TempFile,'wb')"); doCommand(Doc,"f = open(TempFile,'wb')");