diff --git a/src/Mod/Raytracing/Gui/Command.cpp b/src/Mod/Raytracing/Gui/Command.cpp index aeebf3d24..f3817cfc7 100644 --- a/src/Mod/Raytracing/Gui/Command.cpp +++ b/src/Mod/Raytracing/Gui/Command.cpp @@ -464,6 +464,83 @@ bool CmdRaytracingExportProject::isActive(void) } +//=========================================================================== +// Raytracing_Render +//=========================================================================== + +DEF_STD_CMD_A(CmdRaytracingRender); + +CmdRaytracingRender::CmdRaytracingRender() + : Command("Raytracing_Render") +{ + // seting the + sGroup = QT_TR_NOOP("File"); + sMenuText = QT_TR_NOOP("&Render"); + sToolTipText = QT_TR_NOOP("Renders the current raytracing project with povray"); + sWhatsThis = "Raytracing_Render"; + sStatusTip = sToolTipText; + sPixmap = "Raytrace_Render"; +} + +void CmdRaytracingRender::activated(int iMsg) +{ + unsigned int n = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId()); + if (n != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select one Povray project object.")); + return; + } + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Raytracing"); + std::string povray = hGrp->GetASCII("PovrayExecutable", ""); + if (povray == "") { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Povray not found"), + QObject::tr("Please set the path to the povray executable in the preferences.")); + return; + } else { + QFileInfo fi(QString::fromUtf8(povray.c_str())); + if (!fi.exists() || !fi.isFile()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Povray not found"), + QObject::tr("Please correct the path to the povray executable in the preferences.")); + return; + } + } + + QStringList filter; + filter << QObject::tr("Rendered image(*.png)"); + filter << QObject::tr("All Files (*.*)"); + + QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Rendered image"), QString(), filter.join(QLatin1String(";;"))); + if (!fn.isEmpty()) { + std::vector Sel = getSelection().getSelection(); + int width = hGrp->GetInt("OutputWidth", 800); + std::stringstream w; + w << width; + int height = hGrp->GetInt("OutputHeight", 600); + std::stringstream h; + h << height; + std::string par = hGrp->GetASCII("OutputParameters", "+UA +P +A"); + std::string fname = (const char*)fn.toUtf8(); + openCommand("Render project"); + doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName); + doCommand(Doc,"import subprocess,tempfile"); + doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.pov')[1]"); + doCommand(Doc,"f = open(TempFile,'wb')"); + doCommand(Doc,"f.write(PageFile.read())"); + doCommand(Doc,"f.close()"); + doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" '+TempFile,shell=True)",povray.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),fname.c_str()); + doCommand(Gui,"import ImageGui"); + doCommand(Gui,"ImageGui.open('%s')",fname.c_str()); + doCommand(Doc,"del TempFile,PageFile"); + commitCommand(); + } +} + +bool CmdRaytracingRender::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + + void CreateRaytracingCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -473,4 +550,5 @@ void CreateRaytracingCommands(void) rcCmdMgr.addCommand(new CmdRaytracingNewPovrayProject()); rcCmdMgr.addCommand(new CmdRaytracingExportProject()); rcCmdMgr.addCommand(new CmdRaytracingNewPartSegment()); + rcCmdMgr.addCommand(new CmdRaytracingRender()); } diff --git a/src/Mod/Raytracing/Gui/DlgSettingsRay.ui b/src/Mod/Raytracing/Gui/DlgSettingsRay.ui index 9308aa529..95143b88c 100644 --- a/src/Mod/Raytracing/Gui/DlgSettingsRay.ui +++ b/src/Mod/Raytracing/Gui/DlgSettingsRay.ui @@ -1,79 +1,73 @@ - - - - + + RaytracingGui::DlgSettingsRay - - + + 0 0 555 - 311 + 412 - + Raytracing - - + + 9 - + 6 - - - + + + Mesh export settings - - - 10 - - + + 6 + + 10 + - - - 0 - - + + 6 + + 0 + - - - - 1 - 5 + + + 0 0 - + max mesh deviation: - - - - 3 - 0 + + + 0 0 - - 0.1 + + 0.100000000000000 - + MeshDeviation - + Mod/Raytracing @@ -81,27 +75,27 @@ - - + + Do not calculate vertex normals - + NotWriteVertexNormals - + Mod/Raytracing - - + + Write u,v coordinates - + WriteUVCoordinates - + Mod/Raytracing @@ -109,85 +103,206 @@ - - - + + + + Render + + + + + + + + The path to the povray executable, if you want to render from FreeCAD + + + PovrayExecutable + + + Mod/Raytracing + + + + + + + Povray executable: + + + + + + + Output parameters: + + + + + + + + + The povray parameters to be passed to the render. + + + +UA +P +A + + + OutputParameters + + + Mod/Raytracing + + + + + + + +W: + + + + + + + The width of the rendered image + + + 9999 + + + 800 + + + OutputWidth + + + Mod/Raytracing + + + + + + + +H : + + + + + + + The height of the rendered image + + + 9999 + + + 600 + + + OutputHeight + + + Mod/Raytracing + + + + + + + + + + + + + Directories - - + + 9 - + 6 - - - + + + 0 - + 6 - - - + + + Part file name: - - - + + + Camera file name: - - - + + + Qt::StrongFocus - + + Used by utility tools + + Gui::FileChooser::Directory - + ProjectPath - + Mod/Raytracing - - - + + + Default Project dir: - - - + + + + Used by utility tools + + TempCamera.inc - + CameraName - + Mod/Raytracing - - - + + + + Used by utility tools + + TempPart.inc - + PartName - + Mod/Raytracing @@ -197,12 +312,12 @@ - + - + Qt::Vertical - + 20 40 @@ -212,35 +327,37 @@ - + - Gui::PrefCheckBox - QCheckBox -
Gui/PrefWidgets.h
- 0 - -
- - Gui::PrefLineEdit - QLineEdit -
Gui/PrefWidgets.h
- 0 - -
- - Gui::PrefDoubleSpinBox - QDoubleSpinBox -
Gui/PrefWidgets.h
- 0 - + Gui::FileChooser + QWidget +
Gui/FileDialog.h
Gui::PrefFileChooser Gui::FileChooser
Gui/PrefWidgets.h
- 0 - +
+ + Gui::PrefSpinBox + QSpinBox +
Gui/PrefWidgets.h
+
+ + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+ + Gui::PrefLineEdit + QLineEdit +
Gui/PrefWidgets.h
+
+ + Gui::PrefDoubleSpinBox + QDoubleSpinBox +
Gui/PrefWidgets.h
diff --git a/src/Mod/Raytracing/Gui/DlgSettingsRayImp.cpp b/src/Mod/Raytracing/Gui/DlgSettingsRayImp.cpp index 14ed55416..af22079c5 100644 --- a/src/Mod/Raytracing/Gui/DlgSettingsRayImp.cpp +++ b/src/Mod/Raytracing/Gui/DlgSettingsRayImp.cpp @@ -50,21 +50,29 @@ DlgSettingsRayImp::~DlgSettingsRayImp() void DlgSettingsRayImp::saveSettings() { prefFileChooser1->onSave(); + prefFileChooser2->onSave(); prefLineEdit2->onSave(); prefLineEdit3->onSave(); prefFloatSpinBox1->onSave(); prefCheckBox8->onSave(); prefCheckBox9->onSave(); + prefIntSpinBox1->onSave(); + prefIntSpinBox2->onSave(); + prefLineEdit1->onSave(); } void DlgSettingsRayImp::loadSettings() { prefFileChooser1->onRestore(); + prefFileChooser2->onRestore(); prefLineEdit2->onRestore(); prefLineEdit3->onRestore(); prefFloatSpinBox1->onRestore(); prefCheckBox8->onRestore(); prefCheckBox9->onRestore(); + prefIntSpinBox1->onRestore(); + prefIntSpinBox2->onRestore(); + prefLineEdit1->onSave(); } /** diff --git a/src/Mod/Raytracing/Gui/Resources/Raytracing.qrc b/src/Mod/Raytracing/Gui/Resources/Raytracing.qrc index a79b6dd0c..2dff16016 100644 --- a/src/Mod/Raytracing/Gui/Resources/Raytracing.qrc +++ b/src/Mod/Raytracing/Gui/Resources/Raytracing.qrc @@ -7,6 +7,7 @@ icons/Raytrace_Part.svg icons/Raytrace_ExportProject.svg icons/Raytrace_NewPartSegment.svg + icons/Raytrace_Render.svg translations/Raytracing_af.qm translations/Raytracing_de.qm translations/Raytracing_fi.qm diff --git a/src/Mod/Raytracing/Gui/Resources/icons/Raytrace_Render.svg b/src/Mod/Raytracing/Gui/Resources/icons/Raytrace_Render.svg new file mode 100644 index 000000000..0226ca54e --- /dev/null +++ b/src/Mod/Raytracing/Gui/Resources/icons/Raytrace_Render.svg @@ -0,0 +1,320 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/Mod/Raytracing/Gui/Workbench.cpp b/src/Mod/Raytracing/Gui/Workbench.cpp index c5636b7d8..a3d32a79d 100644 --- a/src/Mod/Raytracing/Gui/Workbench.cpp +++ b/src/Mod/Raytracing/Gui/Workbench.cpp @@ -55,15 +55,22 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem* ray = new Gui::MenuItem; root->insertItem(item, ray); - ray->setCommand("&Raytracing"); - *ray + + // utilities + Gui::MenuItem* utilities = new Gui::MenuItem; + utilities->setCommand("Utilities"); + *utilities << "Raytracing_WriteView" << "Raytracing_WriteCamera" - << "Raytracing_WritePart" - << "Separator" + << "Raytracing_WritePart"; + + ray->setCommand("&Raytracing"); + *ray + << utilities << "Raytracing_NewPovrayProject" << "Raytracing_NewPartSegment" - << "Raytracing_ExportProject"; + << "Raytracing_ExportProject" + << "Raytracing_Render"; return root; } @@ -74,12 +81,9 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem* ray = new Gui::ToolBarItem(root); ray->setCommand("Raytracing tools"); *ray - << "Raytracing_WriteView" - << "Raytracing_WriteCamera" - << "Raytracing_WritePart" - << "Separator" << "Raytracing_NewPovrayProject" << "Raytracing_NewPartSegment" - << "Raytracing_ExportProject"; + << "Raytracing_ExportProject" + << "Raytracing_Render"; return root; }