AppRaytracingGuiPy.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <gp_Vec.hxx>
00027 # include <QFileInfo>
00028 # include <Inventor/SoInput.h>
00029 # include <Inventor/nodes/SoNode.h>
00030 # include <Inventor/nodes/SoOrthographicCamera.h>
00031 # include <vector>
00032 # include <Inventor/nodes/SoPerspectiveCamera.h>
00033 #endif
00034
00035 #include <Base/PyObjectBase.h>
00036 #include <Base/Interpreter.h>
00037 #include <Gui/Application.h>
00038 #include <Gui/EditorView.h>
00039 #include <Gui/TextEdit.h>
00040 #include <Gui/MainWindow.h>
00041 #include <Gui/MainWindow.h>
00042 #include <Gui/View.h>
00043
00044 #include <Mod/Raytracing/App/PovTools.h>
00045
00046 #include "PovrayHighlighter.h"
00047
00048 using namespace RaytracingGui;
00049 using namespace Raytracing;
00050
00052 static PyObject *
00053 open(PyObject *self, PyObject *args)
00054 {
00055
00056 const char* Name;
00057 const char* DocName;
00058 if (!PyArg_ParseTuple(args, "s|s",&Name, &DocName))
00059 return NULL;
00060 PY_TRY {
00061 QString fileName = QString::fromUtf8(Name);
00062 QFileInfo fi;
00063 fi.setFile(fileName);
00064 QString ext = fi.completeSuffix().toLower();
00065 QList<Gui::EditorView*> views = Gui::getMainWindow()->findChildren<Gui::EditorView*>();
00066 for (QList<Gui::EditorView*>::Iterator it = views.begin(); it != views.end(); ++it) {
00067 if ((*it)->fileName() == fileName) {
00068 (*it)->setFocus();
00069 Py_Return;
00070 }
00071 }
00072
00073 if (ext == QLatin1String("pov") || ext == QLatin1String("inc")) {
00074 Gui::TextEditor* editor = new Gui::TextEditor();
00075 editor->setSyntaxHighlighter(new PovrayHighlighter(editor));
00076 Gui::EditorView* edit = new Gui::EditorView(editor, Gui::getMainWindow());
00077 edit->open(fileName);
00078 edit->resize(400, 300);
00079 Gui::getMainWindow()->addWindow(edit);
00080 }
00081 } PY_CATCH;
00082
00083 Py_Return;
00084 }
00085
00087 static PyObject *
00088 povViewCamera(PyObject *self, PyObject *args)
00089 {
00090
00091 if (!PyArg_ParseTuple(args, ""))
00092 return NULL;
00093 PY_TRY {
00094 std::string out;
00095 const char* ppReturn=0;
00096
00097 Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn);
00098
00099 SoNode* rootNode;
00100 SoInput in;
00101 in.setBuffer((void*)ppReturn,std::strlen(ppReturn));
00102 SoDB::read(&in,rootNode);
00103
00104 if (!rootNode || !rootNode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId()))
00105 throw Base::Exception("CmdRaytracingWriteCamera::activated(): Could not read "
00106 "camera information from ASCII stream....\n");
00107
00108
00109
00110
00111 SoCamera * Cam = static_cast<SoCamera*>(rootNode);
00112 Cam->ref();
00113
00114 SbRotation camrot = Cam->orientation.getValue();
00115
00116 SbVec3f upvec(0, 1, 0);
00117 camrot.multVec(upvec, upvec);
00118
00119 SbVec3f lookat(0, 0, -1);
00120 camrot.multVec(lookat, lookat);
00121
00122 SbVec3f pos = Cam->position.getValue();
00123 float Dist = Cam->focalDistance.getValue();
00124
00125
00126 gp_Vec gpPos(pos.getValue()[0],pos.getValue()[1],pos.getValue()[2]);
00127 gp_Vec gpDir(lookat.getValue()[0],lookat.getValue()[1],lookat.getValue()[2]);
00128 lookat *= Dist;
00129 lookat += pos;
00130 gp_Vec gpLookAt(lookat.getValue()[0],lookat.getValue()[1],lookat.getValue()[2]);
00131 gp_Vec gpUp(upvec.getValue()[0],upvec.getValue()[1],upvec.getValue()[2]);
00132
00133
00134 out = PovTools::getCamera(CamDef(gpPos,gpDir,gpLookAt,gpUp));
00135
00136 return Py::new_reference_to(Py::String(out));
00137 } PY_CATCH;
00138 }
00139
00140
00141 struct PyMethodDef RaytracingGui_methods[] = {
00142 {"open" ,open ,METH_VARARGS,
00143 "open(string) -- Create a new text document and load the file into the document."},
00144 {"insert" ,open ,METH_VARARGS,
00145 "insert(string,string) -- Create a new text document and load the file into the document."},
00146 {"povViewCamera" ,povViewCamera ,METH_VARARGS,
00147 "string povViewCamera() -- returns the povray camera devinition of the active 3D view."},
00148 {NULL, NULL}
00149 };