+ fixes #0002001: Crash inserting Raytracing Template when in Image View
This commit is contained in:
parent
bafe8d4b14
commit
0063b80937
|
@ -35,10 +35,10 @@
|
|||
#include <Base/PyObjectBase.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/EditorView.h>
|
||||
#include <Gui/TextEdit.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/View.h>
|
||||
|
||||
#include <Mod/Raytracing/App/PovTools.h>
|
||||
|
@ -96,16 +96,39 @@ povViewCamera(PyObject *self, PyObject *args)
|
|||
std::string out;
|
||||
const char* ppReturn=0;
|
||||
|
||||
Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn);
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
if (doc) {
|
||||
// try active view first
|
||||
Gui::MDIView* view = doc->getActiveView();
|
||||
if (!(view && view->onMsg("GetCamera",&ppReturn))) {
|
||||
// now try all views
|
||||
std::list<Gui::MDIView*> views = doc->getMDIViews();
|
||||
for (std::list<Gui::MDIView*>::iterator it = views.begin(); it != views.end(); ++it) {
|
||||
if ((*it)->onMsg("GetCamera",&ppReturn)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_RuntimeError, "No active document found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ppReturn) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Could not read camera information from active view");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SoNode* rootNode;
|
||||
SoInput in;
|
||||
in.setBuffer((void*)ppReturn,std::strlen(ppReturn));
|
||||
SoDB::read(&in,rootNode);
|
||||
|
||||
if (!rootNode || !rootNode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId()))
|
||||
throw Base::Exception("CmdRaytracingWriteCamera::activated(): Could not read "
|
||||
"camera information from ASCII stream....\n");
|
||||
if (!rootNode || !rootNode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId())) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Could not read camera information from ASCII stream");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// root-node returned from SoDB::readAll() has initial zero
|
||||
// ref-count, so reference it before we start using it to
|
||||
|
@ -155,16 +178,39 @@ luxViewCamera(PyObject *self, PyObject *args)
|
|||
std::string out;
|
||||
const char* ppReturn=0;
|
||||
|
||||
Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn);
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
if (doc) {
|
||||
// try active view first
|
||||
Gui::MDIView* view = doc->getActiveView();
|
||||
if (!(view && view->onMsg("GetCamera",&ppReturn))) {
|
||||
// now try all views
|
||||
std::list<Gui::MDIView*> views = doc->getMDIViews();
|
||||
for (std::list<Gui::MDIView*>::iterator it = views.begin(); it != views.end(); ++it) {
|
||||
if ((*it)->onMsg("GetCamera",&ppReturn)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_RuntimeError, "No active document found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ppReturn) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Could not read camera information from active view");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SoNode* rootNode;
|
||||
SoInput in;
|
||||
in.setBuffer((void*)ppReturn,std::strlen(ppReturn));
|
||||
SoDB::read(&in,rootNode);
|
||||
|
||||
if (!rootNode || !rootNode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId()))
|
||||
throw Base::Exception("CmdRaytracingWriteCamera::activated(): Could not read "
|
||||
"camera information from ASCII stream....\n");
|
||||
if (!rootNode || !rootNode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId())) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Could not read camera information from ASCII stream");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// root-node returned from SoDB::readAll() has initial zero
|
||||
// ref-count, so reference it before we start using it to
|
||||
|
|
|
@ -261,26 +261,32 @@ void CmdRaytracingWriteView::activated(int iMsg)
|
|||
openCommand("Write view");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"OutFile = open(unicode(\"%s\",\"utf-8\"),\"w\")",cFullName.c_str());
|
||||
doCommand(Doc,"result = open(App.getResourceDir()+'Mod/Raytracing/Templates/ProjectStd.pov').read()");
|
||||
doCommand(Doc,"content = ''");
|
||||
doCommand(Doc,"content += RaytracingGui.povViewCamera()");
|
||||
// go through all document objects
|
||||
for (std::vector<Part::Feature*>::const_iterator it=DocObjects.begin();it!=DocObjects.end();++it) {
|
||||
Gui::ViewProvider* vp = getActiveGuiDocument()->getViewProvider(*it);
|
||||
if (vp && vp->isVisible()) {
|
||||
App::PropertyColor *pcColor = dynamic_cast<App::PropertyColor *>(vp->getPropertyByName("ShapeColor"));
|
||||
App::Color col = pcColor->getValue();
|
||||
doCommand(Doc,"content += Raytracing.getPartAsPovray('%s',App.activeDocument().%s.Shape,%f,%f,%f)",
|
||||
(*it)->getNameInDocument(),(*it)->getNameInDocument(),col.r,col.g,col.b);
|
||||
try {
|
||||
doCommand(Doc,"result = open(App.getResourceDir()+'Mod/Raytracing/Templates/ProjectStd.pov').read()");
|
||||
doCommand(Doc,"content = ''");
|
||||
doCommand(Doc,"content += RaytracingGui.povViewCamera()");
|
||||
// go through all document objects
|
||||
for (std::vector<Part::Feature*>::const_iterator it=DocObjects.begin();it!=DocObjects.end();++it) {
|
||||
Gui::ViewProvider* vp = getActiveGuiDocument()->getViewProvider(*it);
|
||||
if (vp && vp->isVisible()) {
|
||||
App::PropertyColor *pcColor = dynamic_cast<App::PropertyColor *>(vp->getPropertyByName("ShapeColor"));
|
||||
App::Color col = pcColor->getValue();
|
||||
doCommand(Doc,"content += Raytracing.getPartAsPovray('%s',App.activeDocument().%s.Shape,%f,%f,%f)",
|
||||
(*it)->getNameInDocument(),(*it)->getNameInDocument(),col.r,col.g,col.b);
|
||||
}
|
||||
}
|
||||
doCommand(Doc,"result = result.replace('//RaytracingContent',content)");
|
||||
doCommand(Doc,"OutFile.write(result)");
|
||||
doCommand(Doc,"OutFile.close()");
|
||||
doCommand(Doc,"del OutFile");
|
||||
commitCommand();
|
||||
}
|
||||
catch (...) {
|
||||
doCommand(Doc,"OutFile.close()");
|
||||
doCommand(Doc,"del OutFile");
|
||||
abortCommand();
|
||||
throw;
|
||||
}
|
||||
doCommand(Doc,"result = result.replace('//RaytracingContent',content)");
|
||||
doCommand(Doc,"OutFile.write(result)");
|
||||
doCommand(Doc,"OutFile.close()");
|
||||
doCommand(Doc,"del OutFile");
|
||||
|
||||
updateActive();
|
||||
commitCommand();
|
||||
}
|
||||
|
||||
bool CmdRaytracingWriteView::isActive(void)
|
||||
|
@ -337,12 +343,18 @@ void CmdRaytracingNewPovrayProject::activated(int iMsg)
|
|||
QAction* a = pcAction->actions()[iMsg];
|
||||
QFileInfo tfi(a->property("Template").toString());
|
||||
if (tfi.isReadable()) {
|
||||
openCommand("Create POV-Ray project");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Raytracing::RayProject','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8());
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",FeatName.c_str());
|
||||
commitCommand();
|
||||
try {
|
||||
openCommand("Create POV-Ray project");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Raytracing::RayProject','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8());
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",FeatName.c_str());
|
||||
commitCommand();
|
||||
}
|
||||
catch (...) {
|
||||
abortCommand();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
else {
|
||||
QMessageBox::critical(Gui::getMainWindow(),
|
||||
|
@ -726,12 +738,18 @@ void CmdRaytracingNewLuxProject::activated(int iMsg)
|
|||
QAction* a = pcAction->actions()[iMsg];
|
||||
QFileInfo tfi(a->property("Template").toString());
|
||||
if (tfi.isReadable()) {
|
||||
openCommand("Create LuxRender project");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Raytracing::LuxProject','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8());
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",FeatName.c_str());
|
||||
commitCommand();
|
||||
try {
|
||||
openCommand("Create LuxRender project");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Raytracing::LuxProject','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8());
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",FeatName.c_str());
|
||||
commitCommand();
|
||||
}
|
||||
catch (...) {
|
||||
abortCommand();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
else {
|
||||
QMessageBox::critical(Gui::getMainWindow(),
|
||||
|
@ -803,29 +821,43 @@ CmdRaytracingResetCamera::CmdRaytracingResetCamera()
|
|||
|
||||
void CmdRaytracingResetCamera::activated(int iMsg)
|
||||
{
|
||||
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
|
||||
unsigned int n = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId());
|
||||
if (n != 1) {
|
||||
n = getSelection().countObjectsOfType(Raytracing::LuxProject::getClassTypeId());
|
||||
if (n != 1) {
|
||||
std::vector<App::DocumentObject*> sel = getSelection().getObjectsOfType(Raytracing::RayProject::getClassTypeId());
|
||||
if (sel.size() != 1) {
|
||||
sel = getSelection().getObjectsOfType(Raytracing::LuxProject::getClassTypeId());
|
||||
if (sel.size() != 1) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select one Raytracing project object."));
|
||||
return;
|
||||
} else {
|
||||
//luxrender
|
||||
}
|
||||
}
|
||||
|
||||
if (sel.front()->getTypeId().isDerivedFrom(Raytracing::RayProject::getClassTypeId())) {
|
||||
//povray
|
||||
try {
|
||||
openCommand("Reset Raytracing Camera");
|
||||
doCommand(Doc,"import RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",Sel[0].FeatName);
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",sel.front()->getNameInDocument());
|
||||
commitCommand();
|
||||
doCommand(Doc,"App.activeDocument().recompute()");
|
||||
updateActive();
|
||||
}
|
||||
catch (...) {
|
||||
abortCommand();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
else if (sel.front()->getTypeId().isDerivedFrom(Raytracing::LuxProject::getClassTypeId())) {
|
||||
//luxrender
|
||||
try {
|
||||
openCommand("Reset Raytracing Camera");
|
||||
doCommand(Doc,"import RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",sel.front()->getNameInDocument());
|
||||
commitCommand();
|
||||
updateActive();
|
||||
}
|
||||
catch (...) {
|
||||
abortCommand();
|
||||
throw;
|
||||
}
|
||||
} else {
|
||||
//povray
|
||||
openCommand("Reset Raytracing Camera");
|
||||
doCommand(Doc,"import RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",Sel[0].FeatName);
|
||||
commitCommand();
|
||||
doCommand(Doc,"App.activeDocument().recompute()");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user