Commit a76fbe55 authored by Sylvain Thery's avatar Sylvain Thery

save cameras/splitter/windows in py recording

parent fcf9f256
......@@ -206,7 +206,7 @@ void EdgeSelector_Radiance<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
const REAL rad = computeRadianceError(d, newPos, newN, newRad);
const REAL t = 0.01 ;
const REAL t = 0.01f ;
const REAL err = t*geom + (1-t)*rad ;
// Check if errated values appear
......
......@@ -267,7 +267,7 @@ void HalfEdgeSelector_Radiance<PFP>::computeHalfEdgeInfo(Dart d, HalfEdgeInfo& h
const REAL rad = computeRadianceError(d);
const REAL t = 0.01 ;
const REAL t = 0.01f ;
const REAL err = t*geom + (1-t)*rad ;
// Check if errated values appear
......
......@@ -50,6 +50,9 @@ public slots:
void enableViewsBoundingBoxFitting() { b_fitToViewsBoundingBox = true; }
void disableViewsBoundingBoxFitting() { b_fitToViewsBoundingBox = false; }
QString toString();
void fromString(QString cam);
private:
void linkView(View* view);
void unlinkView(View* view);
......
......@@ -56,6 +56,7 @@ public slots:
public:
void redrawAllViews();
public slots:
View* addView(const QString& name);
View* addView();
......@@ -69,6 +70,10 @@ public slots:
void splitView(const QString& name, Qt::Orientation orientation);
QString saveSplitViewPositions();
void restoreSplitViewPositions(QString stringStates);
/*********************************************************
* MANAGE PLUGINS
*********************************************************/
......@@ -148,6 +153,7 @@ public slots:
QString saveFileDialog(const QString& title, const QString& dir = QString(), const QString& filter = QString());
void setWindowSize(int w, int h) { this->setFixedSize(w, h); }
private slots:
void loadPythonScriptFromFileDialog();
......@@ -163,7 +169,7 @@ protected:
QString m_pyBuffer;
private slots:
void beginPyRecording();
void pyRecording();
void appendPyRecording();
//void endPyRecording();
......
......@@ -121,6 +121,35 @@ void Camera::fitToViewsBoundingBox()
}
}
QString Camera::toString()
{
QString res;
QTextStream str(&res);
qglviewer::Vec pos = this->position();
qglviewer::Quaternion ori = this->orientation();
str << pos[0] << " " << pos[1] << " " << pos[2] << " ";
str << ori[0] << " " << ori[1] << " " << ori[2] << " " << ori[3];
return res;
}
void Camera::fromString(QString cam)
{
QTextStream str(&cam);
qglviewer::Vec pos = this->position();
qglviewer::Quaternion ori = this->orientation();
str >> pos[0];
str >> pos[1];
str >> pos[2];
str >> ori[0];
str >> ori[1];
str >> ori[2];
str >> ori[3];
this->setPosition(pos);
this->setOrientation(ori);
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -11,7 +11,7 @@
#include <QMouseEvent>
#include <QWheelEvent>
#include <QFile>
#include <QByteArray>
#include "mapHandler.h"
#include "schnapps.h"
......@@ -107,7 +107,7 @@ SCHNApps::SCHNApps(const QString& appPath, PythonQtObjectPtr& pythonContext, Pyt
connect(action_ShowHidePythonDock, SIGNAL(triggered()), this, SLOT(showHidePythonDock()));
connect(action_LoadPythonScript, SIGNAL(triggered()), this, SLOT(loadPythonScriptFromFileDialog()));
connect(action_Python_Recording, SIGNAL(triggered()), this, SLOT(beginPyRecording()));
connect(action_Python_Recording, SIGNAL(triggered()), this, SLOT(pyRecording()));
connect(action_Append_Python_Recording, SIGNAL(triggered()), this, SLOT(appendPyRecording()));
action_Python_Recording->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
......@@ -320,8 +320,18 @@ void SCHNApps::splitView(const QString& name, Qt::Orientation orientation)
m_rootSplitter->setOrientation(orientation);
b_rootSplitterInitialized = true;
}
if(parent->orientation() == orientation)
parent->insertWidget(parent->indexOf(view)+1, newView);
if (parent->orientation() == orientation)
{
parent->insertWidget(parent->indexOf(view) + 1, newView);
QList<int> sz = parent->sizes();
int tot = 0;
for (int i = 0; i < parent->count(); ++i)
tot += sz[i];
sz[0] = tot / parent->count() + tot % parent->count();
for (int i = 1; i < parent->count(); ++i)
sz[i] = tot / parent->count();
parent->setSizes(sz);
}
else
{
int idx = parent->indexOf(view);
......@@ -330,10 +340,82 @@ void SCHNApps::splitView(const QString& name, Qt::Orientation orientation)
spl->addWidget(view);
spl->addWidget(newView);
parent->insertWidget(idx, spl);
QList<int> sz = spl->sizes();
int tot = sz[0] + sz[1];
sz[0] = tot / 2;
sz[1] = tot - sz[0];
spl->setSizes(sz);
}
}
QString SCHNApps::saveSplitViewPositions()
{
QList<QSplitter*> liste;
liste.push_back(m_rootSplitter);
QString result;
QTextStream qts(&result);
while (!liste.empty())
{
QSplitter* spl = liste.first();
for (int i = 0; i < spl->count(); ++i)
{
QWidget *w = spl->widget(i);
QSplitter* qw = dynamic_cast<QSplitter*>(w);
if (qw != NULL)
liste.push_back(qw);
}
QByteArray ba = spl->saveState();
qts << ba.count() << " ";
for (int j = 0; j < ba.count(); ++j)
qts << int(ba[j]) << " ";
//qts << endl;
liste.pop_front();
}
return result;
}
void SCHNApps::restoreSplitViewPositions(QString stringStates)
{
QList<QSplitter*> liste;
liste.push_back(m_rootSplitter);
QTextStream qts(&stringStates);
while (!liste.empty())
{
QSplitter* spl = liste.first();
for (int i = 0; i < spl->count(); ++i)
{
QWidget *w = spl->widget(i);
QSplitter* qw = dynamic_cast<QSplitter*>(w);
if (qw != NULL)
liste.push_back(qw);
}
if (qts.atEnd())
{
std::cerr << "Problem restoring view split configuration" << std::endl;
return;
}
int nb;
qts >> nb;
QByteArray ba(nb + 1, 0);
for (int j = 0; j < nb; ++j)
{
int v;
qts >> v;
ba[j] = char(v);
}
spl->restoreState(ba);
liste.pop_front();
}
}
/*********************************************************
* MANAGE PLUGINS
*********************************************************/
......@@ -920,7 +1002,7 @@ void SCHNApps::loadPythonScriptFromFileDialog()
}
void SCHNApps::beginPyRecording()
void SCHNApps::pyRecording()
{
if (m_pyRecording != NULL) // WRITE & CLOSE
{
......@@ -929,7 +1011,21 @@ void SCHNApps::beginPyRecording()
{
m_pyBuffer.replace("\"" + var + "\"", var + ".getName()");
}
out << m_pyBuffer << endl;
// split view positions
out << "schnapps.restoreSplitViewPositions(\"" << saveSplitViewPositions() << "\")" << endl;
// cameras
foreach(Camera* cam, m_cameras)
{
out << "schnapps.getCamera(\"" << cam->getName() << "\").fromString(\"" << cam->toString() << "\")" << endl;
}
//windows
out << "schnapps.setWindowSize(" << this->width() << ", "<< this->height() << ")" << endl;
m_pyRecFile->close();
delete m_pyRecording;
......@@ -981,6 +1077,19 @@ void SCHNApps::appendPyRecording()
m_pyBuffer.replace("\"" + var + "\"", var + ".getName()");
}
out << m_pyBuffer << endl;
// split view positions
out << "schnapps.restoreSplitViewPositions(\"" << saveSplitViewPositions() << "\")" << endl;
// cameras
foreach(Camera* cam, m_cameras)
{
out << "schnapps.getCamera(\"" << cam->getName() << "\").fromString(\"" << cam->toString() << "\")" << endl;
}
//windows
out << "schnapps.setWindowSize(" << this->width() << ", " << this->height() << ")" << endl;
m_pyRecFile->close();
delete m_pyRecording;
......
......@@ -168,6 +168,8 @@ bool View::usesCamera(const QString& name) const
return usesCamera(c);
}
void View::linkPlugin(PluginInteraction* plugin)
{
// RECORDING
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment