Commit 04f9e0b7 authored by Sylvain Thery's avatar Sylvain Thery

Camera::setScaling

parent b9dd9823
...@@ -59,6 +59,9 @@ e</string> ...@@ -59,6 +59,9 @@ e</string>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum> <enum>QAbstractItemView::ExtendedSelection</enum>
</property> </property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
...@@ -163,6 +166,9 @@ d</string> ...@@ -163,6 +166,9 @@ d</string>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum> <enum>QAbstractItemView::ExtendedSelection</enum>
</property> </property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
<addaction name="action_LoadPythonScript"/> <addaction name="action_LoadPythonScript"/>
<addaction name="action_Python_Recording"/> <addaction name="action_Python_Recording"/>
<addaction name="action_Append_Python_Recording"/> <addaction name="action_Append_Python_Recording"/>
<addaction name="action_Clean_All"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_Quit"/> <addaction name="action_Quit"/>
</widget> </widget>
...@@ -97,6 +98,11 @@ ...@@ -97,6 +98,11 @@
<string>Append Python Recording</string> <string>Append Python Recording</string>
</property> </property>
</action> </action>
<action name="action_Clean_All">
<property name="text">
<string>Clean All</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
......
...@@ -29,6 +29,8 @@ public: ...@@ -29,6 +29,8 @@ public:
~Camera(); ~Camera();
const QString& getName() const { return m_name; } const QString& getName() const { return m_name; }
const glm::mat4& getTransfoMatrix() const;
public slots: public slots:
QString getName() { return m_name; } QString getName() { return m_name; }
SCHNApps* getSCHNApps() const { return m_schnapps; } SCHNApps* getSCHNApps() const { return m_schnapps; }
...@@ -53,6 +55,8 @@ public slots: ...@@ -53,6 +55,8 @@ public slots:
QString toString(); QString toString();
void fromString(QString cam); void fromString(QString cam);
void setScaling(float sx, float sy, float sz);
private: private:
void linkView(View* view); void linkView(View* view);
void unlinkView(View* view); void unlinkView(View* view);
...@@ -72,10 +76,13 @@ protected: ...@@ -72,10 +76,13 @@ protected:
QList<View*> l_views; QList<View*> l_views;
glm::mat4 m_transfoMatrix;
bool b_draw; bool b_draw;
bool b_drawPath; bool b_drawPath;
bool b_fitToViewsBoundingBox; bool b_fitToViewsBoundingBox;
}; };
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -137,6 +137,9 @@ public: ...@@ -137,6 +137,9 @@ public:
void addMenuAction(Plugin* plugin, const QString& menuPath, QAction* action); void addMenuAction(Plugin* plugin, const QString& menuPath, QAction* action);
void removeMenuAction(Plugin* plugin, QAction* action); void removeMenuAction(Plugin* plugin, QAction* action);
bool execPythonShortcut(quint64 key);
public slots: public slots:
void aboutSCHNApps(); void aboutSCHNApps();
void aboutCGoGN(); void aboutCGoGN();
...@@ -147,7 +150,12 @@ public slots: ...@@ -147,7 +150,12 @@ public slots:
void loadPythonScriptFromFile(const QString& fileName); void loadPythonScriptFromFile(const QString& fileName);
void execPythonCmd(const QString& fileName); /**
* associated a python command with a key shortcut
* @param keys example "control a", "alt shift B" "control keypad +"
* @param a python cmd
*/
void setPythonShortcut(const QString& keys, const QString& command);
void statusBarMessage(const QString& msg, int msec); void statusBarMessage(const QString& msg, int msec);
...@@ -155,7 +163,9 @@ public slots: ...@@ -155,7 +163,9 @@ public slots:
QString saveFileDialog(const QString& title, const QString& dir = QString(), const QString& filter = QString()); QString saveFileDialog(const QString& title, const QString& dir = QString(), const QString& filter = QString());
void setWindowSize(int w, int h) { this->resize(w, h); } inline void setWindowSize(int w, int h) { this->resize(w, h); }
inline void setPythonPath(const QString& path) { m_pyPathFile = path; }
private slots: private slots:
void loadPythonScriptFromFileDialog(); void loadPythonScriptFromFileDialog();
...@@ -169,17 +179,21 @@ protected: ...@@ -169,17 +179,21 @@ protected:
QFile* m_pyRecFile; QFile* m_pyRecFile;
QList<QString> m_pyVarNames; QList<QString> m_pyVarNames;
QString m_pyBuffer; QString m_pyBuffer;
QMap<quint64, QString > m_pythonShortCuts;
QString m_pyPathFile;
private slots: private slots:
void pyRecording(); void pyRecording();
void appendPyRecording(); void appendPyRecording();
// void endPyRecording(); void cleanAll();
public: public:
inline QTextStream* pythonStreamRecorder() { return m_pyRecording; } inline QTextStream* pythonStreamRecorder() { return m_pyRecording; }
inline void pythonVarDeclare(const QString& var) { m_pyVarNames.push_back(var); } inline void pythonVarDeclare(const QString& var) { m_pyVarNames.push_back(var); }
inline void pythonVarsClear() { m_pyVarNames.clear(); } inline void pythonVarsClear() { m_pyVarNames.clear(); }
signals: signals:
void cameraAdded(Camera* camera); void cameraAdded(Camera* camera);
void cameraRemoved(Camera* camera); void cameraRemoved(Camera* camera);
...@@ -204,6 +218,8 @@ protected: ...@@ -204,6 +218,8 @@ protected:
PythonQtObjectPtr& m_pythonContext; PythonQtObjectPtr& m_pythonContext;
PythonQtScriptingConsole& m_pythonConsole; PythonQtScriptingConsole& m_pythonConsole;
void execPythonCmd(const QString& fileName);
QDockWidget* m_controlDock; QDockWidget* m_controlDock;
QTabWidget* m_controlDockTabWidget; QTabWidget* m_controlDockTabWidget;
ControlDock_CameraTab* m_controlCameraTab; ControlDock_CameraTab* m_controlCameraTab;
...@@ -226,8 +242,6 @@ protected: ...@@ -226,8 +242,6 @@ protected:
QMap<Plugin*, QList<QWidget*> > m_pluginTabs; QMap<Plugin*, QList<QWidget*> > m_pluginTabs;
QMap<Plugin*, QList<QAction*> > m_pluginMenuActions; QMap<Plugin*, QList<QAction*> > m_pluginMenuActions;
QMap<int, QString > m_pythonShortCuts;
CameraSet m_cameras; CameraSet m_cameras;
ViewSet m_views; ViewSet m_views;
......
...@@ -80,8 +80,6 @@ public slots: ...@@ -80,8 +80,6 @@ public slots:
bool isLinkedToMap(MapHandlerGen* map) const { return l_maps.contains(map); } bool isLinkedToMap(MapHandlerGen* map) const { return l_maps.contains(map); }
bool isLinkedToMap(const QString& name) const; bool isLinkedToMap(const QString& name) const;
void setViewScaling(float sx, float sy, float sz);
private: private:
bool b_updatingUI; bool b_updatingUI;
...@@ -104,6 +102,7 @@ private: ...@@ -104,6 +102,7 @@ private:
glm::mat4 getCurrentModelViewMatrix() const; glm::mat4 getCurrentModelViewMatrix() const;
glm::mat4 getCurrentProjectionMatrix() const; glm::mat4 getCurrentProjectionMatrix() const;
glm::mat4 getCurrentModelViewProjectionMatrix() const; glm::mat4 getCurrentModelViewProjectionMatrix() const;
const glm::mat4& getCurrentTransfoMatrix() const;
private slots: private slots:
void closeDialogs(); void closeDialogs();
...@@ -176,10 +175,6 @@ protected: ...@@ -176,10 +175,6 @@ protected:
Utils::Texture<2, Geom::Vec3uc>* m_textureWallpaper; Utils::Texture<2, Geom::Vec3uc>* m_textureWallpaper;
Utils::ShaderWallPaper* m_shaderWallpaper; Utils::ShaderWallPaper* m_shaderWallpaper;
glm::mat4 m_scaleView;
inline float scaleRealSlideVal(int v);
inline int scaleIntSlideVal(float v);
bool b_saveSnapshots; bool b_saveSnapshots;
inline int pixelRatio() const inline int pixelRatio() const
......
...@@ -14,6 +14,7 @@ unsigned int Camera::cameraCount = 0; ...@@ -14,6 +14,7 @@ unsigned int Camera::cameraCount = 0;
Camera::Camera(const QString& name, SCHNApps* s) : Camera::Camera(const QString& name, SCHNApps* s) :
m_name(name), m_name(name),
m_schnapps(s), m_schnapps(s),
m_transfoMatrix(1.0f),
b_draw(false), b_draw(false),
b_drawPath(false), b_drawPath(false),
b_fitToViewsBoundingBox(true) b_fitToViewsBoundingBox(true)
...@@ -149,6 +150,19 @@ void Camera::fromString(QString cam) ...@@ -149,6 +150,19 @@ void Camera::fromString(QString cam)
this->setOrientation(ori); this->setOrientation(ori);
} }
void Camera::setScaling(float sx, float sy, float sz)
{
m_transfoMatrix[0][0] = sx;
m_transfoMatrix[1][1] = sy;
m_transfoMatrix[2][2] = sz;
foreach(View* view, l_views)
view->updateGL();
}
const glm::mat4& Camera::getTransfoMatrix() const
{
return m_transfoMatrix;
}
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -109,6 +109,8 @@ SCHNApps::SCHNApps(const QString& appPath, PythonQtObjectPtr& pythonContext, Pyt ...@@ -109,6 +109,8 @@ SCHNApps::SCHNApps(const QString& appPath, PythonQtObjectPtr& pythonContext, Pyt
connect(action_Python_Recording, SIGNAL(triggered()), this, SLOT(pyRecording())); connect(action_Python_Recording, SIGNAL(triggered()), this, SLOT(pyRecording()));
connect(action_Append_Python_Recording, SIGNAL(triggered()), this, SLOT(appendPyRecording())); connect(action_Append_Python_Recording, SIGNAL(triggered()), this, SLOT(appendPyRecording()));
connect(action_Clean_All, SIGNAL(triggered()), this, SLOT(cleanAll()));
action_Python_Recording->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P)); action_Python_Recording->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
action_Append_Python_Recording->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_P)); action_Append_Python_Recording->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_P));
...@@ -525,13 +527,6 @@ void SCHNApps::disablePlugin(const QString& pluginName) ...@@ -525,13 +527,6 @@ void SCHNApps::disablePlugin(const QString& pluginName)
{ {
Plugin* plugin = m_plugins[pluginName]; Plugin* plugin = m_plugins[pluginName];
// remove plugin dock tabs
foreach(QWidget* tab, m_pluginTabs[plugin])
removePluginDockTab(plugin, tab);
// remove plugin menu actions
foreach(QAction* action, m_pluginMenuActions[plugin])
removeMenuAction(plugin, action);
// unlink linked views (for interaction plugins) // unlink linked views (for interaction plugins)
PluginInteraction* pi = dynamic_cast<PluginInteraction*>(plugin); PluginInteraction* pi = dynamic_cast<PluginInteraction*>(plugin);
if(pi) if(pi)
...@@ -544,6 +539,14 @@ void SCHNApps::disablePlugin(const QString& pluginName) ...@@ -544,6 +539,14 @@ void SCHNApps::disablePlugin(const QString& pluginName)
plugin->disable(); plugin->disable();
m_plugins.remove(pluginName); m_plugins.remove(pluginName);
// remove plugin dock tabs
foreach(QWidget* tab, m_pluginTabs[plugin])
removePluginDockTab(plugin, tab);
// remove plugin menu actions
foreach(QAction* action, m_pluginMenuActions[plugin])
removeMenuAction(plugin, action);
QPluginLoader loader(plugin->getFilePath()); QPluginLoader loader(plugin->getFilePath());
loader.unload(); loader.unload();
...@@ -1019,7 +1022,11 @@ void SCHNApps::loadPythonScriptFromFile(const QString& fileName) ...@@ -1019,7 +1022,11 @@ void SCHNApps::loadPythonScriptFromFile(const QString& fileName)
void SCHNApps::loadPythonScriptFromFileDialog() void SCHNApps::loadPythonScriptFromFileDialog()
{ {
QString fileName = QFileDialog::getOpenFileName(this, "Load Python script", getAppPath(), "Python script (*.py)"); QString pypath = m_pyPathFile;
if (pypath.isEmpty())
pypath = this->getAppPath();
QString fileName = QFileDialog::getOpenFileName(this, "Load Python script", pypath, "Python script (*.py)");
loadPythonScriptFromFile(fileName); loadPythonScriptFromFile(fileName);
} }
...@@ -1059,7 +1066,11 @@ void SCHNApps::pyRecording() ...@@ -1059,7 +1066,11 @@ void SCHNApps::pyRecording()
return; return;
} }
QString fileName = QFileDialog::getSaveFileName(this, "Save python script", this->getAppPath(), " python script (*.py)"); QString pypath = m_pyPathFile;
if (pypath.isEmpty())
pypath = this->getAppPath();
QString fileName = QFileDialog::getSaveFileName(this, "Save python script", pypath, " python script (*.py)");
if (fileName.size() != 0) if (fileName.size() != 0)
{ {
m_pyRecFile = new QFile(fileName); m_pyRecFile = new QFile(fileName);
...@@ -1123,7 +1134,11 @@ void SCHNApps::appendPyRecording() ...@@ -1123,7 +1134,11 @@ void SCHNApps::appendPyRecording()
return; return;
} }
QString fileName = QFileDialog::getSaveFileName(this, "Append python script", this->getAppPath(), " python script (*.py)"); QString pypath = m_pyPathFile;
if (pypath.isEmpty())
pypath = this->getAppPath();
QString fileName = QFileDialog::getSaveFileName(this, "Append python script", pypath, " python script (*.py)");
if (fileName.size() != 0) if (fileName.size() != 0)
{ {
m_pyRecFile = new QFile(fileName); m_pyRecFile = new QFile(fileName);
...@@ -1154,6 +1169,52 @@ void SCHNApps::appendPyRecording() ...@@ -1154,6 +1169,52 @@ void SCHNApps::appendPyRecording()
} }
} }
bool SCHNApps::execPythonShortcut(quint64 key)
{
if (m_pythonShortCuts.contains(key))
{
execPythonCmd(m_pythonShortCuts[key]);
return true;
}
return false;
}
void SCHNApps::setPythonShortcut(const QString& keys, const QString& command)
{
quint64 k = 0;
if (keys.length() == 0)
return;
if (keys.length() == 1)
{
k = keys[0].unicode();
}
else
{
if (keys.contains("control", Qt::CaseInsensitive))
k |= Qt::ControlModifier;
if (keys.contains("shift", Qt::CaseInsensitive))
k |= Qt::ShiftModifier;
if (keys.contains("alt", Qt::CaseInsensitive))
k |= Qt::AltModifier;
if (keys.contains("meta", Qt::CaseInsensitive))
k |= Qt::MetaModifier;
if (keys.contains("keypad", Qt::CaseInsensitive))
k |= Qt::KeypadModifier;
k <<= 32;
QChar c = keys[keys.length() - 1];
k |= c.unicode();
}
if (command.length() > 0)
m_pythonShortCuts[k] = command;
else
m_pythonShortCuts.erase(m_pythonShortCuts.find(k));
}
void SCHNApps::closeEvent(QCloseEvent *event) void SCHNApps::closeEvent(QCloseEvent *event)
{ {
...@@ -1184,6 +1245,36 @@ QString SCHNApps::saveFileDialog(const QString& title, const QString& dir, const ...@@ -1184,6 +1245,36 @@ QString SCHNApps::saveFileDialog(const QString& title, const QString& dir, const
} }
void SCHNApps::cleanAll()
{
//remove views
foreach(View* v, m_views)
{
if (v->getName() != QString("view_0"))
removeView(v->getName());
else
v->setCurrentCamera(QString("camera_0"));
}
//remove cameras
foreach(Camera* cam, m_cameras)
{
if (cam->getName() != QString("camera_0"))
removeCamera(cam->getName());
}
//remove maps
foreach(MapHandlerGen* m, m_maps)
{
removeMap(m->getName());
}
// remove plugins
foreach(Plugin* p, m_plugins)
{
disablePlugin(p->getName());
}
}
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -46,7 +46,6 @@ View::View(const QString& name, SCHNApps* s, const QGLWidget* shareWidget) : ...@@ -46,7 +46,6 @@ View::View(const QString& name, SCHNApps* s, const QGLWidget* shareWidget) :
m_frameDrawer(NULL), m_frameDrawer(NULL),
m_textureWallpaper(NULL), m_textureWallpaper(NULL),
m_shaderWallpaper(NULL), m_shaderWallpaper(NULL),
m_scaleView(1.0f),
b_saveSnapshots(false) b_saveSnapshots(false)
{ {
++viewCount; ++viewCount;
...@@ -443,12 +442,13 @@ void View::draw() ...@@ -443,12 +442,13 @@ void View::draw()
glm::mat4 mm = getCurrentModelViewMatrix(); glm::mat4 mm = getCurrentModelViewMatrix();
glm::mat4 pm = getCurrentProjectionMatrix(); glm::mat4 pm = getCurrentProjectionMatrix();
const glm::mat4& tr = getCurrentTransfoMatrix();
MapHandlerGen* selectedMap = m_schnapps->getSelectedMap(); MapHandlerGen* selectedMap = m_schnapps->getSelectedMap();
foreach(MapHandlerGen* map, l_maps) foreach(MapHandlerGen* map, l_maps)
{ {
glm::mat4 map_mm = mm * map->getFrameMatrix() * m_scaleView;; glm::mat4 map_mm = mm * map->getFrameMatrix() * tr;;
//glm::mat4 map_mm = mm * map->getFrameMatrix(); //glm::mat4 map_mm = mm * map->getFrameMatrix();
if(map == selectedMap) if(map == selectedMap)
...@@ -504,57 +504,37 @@ void View::drawFrame() ...@@ -504,57 +504,37 @@ void View::drawFrame()
} }
void View::setViewScaling(float sx, float sy, float sz) void View::keyPressEvent(QKeyEvent* event)
{
m_scaleView[0][0] = sx;
m_scaleView[1][1] = sy;
m_scaleView[2][2] = sz;
}
float View::scaleRealSlideVal(int v)
{ {
if (v < 50) quint64 k = event->modifiers();
return 1.0f - ((50 - v) / 100.0f); k <<= 32;
return 1.0f + ((v - 50) / 25.0f); k |= event->key();
}
int View::scaleIntSlideVal(float v) // exec python shortcuts if exist
{ m_schnapps->execPythonShortcut(k);
if (v < 1.0f)
return int((v - 1.0f) * 100 + 50);
return int((v - 1.0f) * 25 + 50);
}
void View::keyPressEvent(QKeyEvent* event)
{
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Z: case Qt::Key_Z:
{ {
// m_schnapps->execPythonCmd("schnapps.getSelectedView().setViewScaling(1.,0.5,1.0);schnapps.getSelectedView().updateGL()"); const glm::mat4& msv = getCurrentCamera()->getTransfoMatrix();
int isX = scaleIntSlideVal(m_scaleView[0][0]); float sx = msv[0][0];
int isY = scaleIntSlideVal(m_scaleView[1][1]); float sy = msv[1][1];
int isZ = scaleIntSlideVal(m_scaleView[2][2]); float sz = msv[2][2];
Utils::QT::inputValues( Utils::QT::inputValues(
Utils::QT::VarSlider(0, 100, isX, "Scale X", Utils::QT::VarFloat(0.1f, 10.0f, sx, "Scale X",
Utils::QT::VarSlider(0, 100, isY, "Scale Y", Utils::QT::VarFloat(0.1f, 10.0f, sy, "Scale Y",
Utils::QT::VarSlider(0, 100, isZ, "Scale Z"))),"Scaling view"); Utils::QT::VarFloat(0.1f, 10.0f, sz, "Scale Z"))), "Scaling view");
float sx = scaleRealSlideVal(isX);
float sy = scaleRealSlideVal(isY);
float sz = scaleRealSlideVal(isZ);
setViewScaling(sx, sy, sz); getCurrentCamera()->setScaling(sx, sy, sz);
QString msg = QString("Sx=") + QString::number(m_scaleView[0][0]) + QString(" / Sy=") + QString::number(m_scaleView[1][1]) + QString(" / Sz=") + QString::number(m_scaleView[2][2]); QString msg = QString("Sx=") + QString::number(msv[0][0]) + QString(" / Sy=") + QString::number(msv[1][1]) + QString(" / Sz=") + QString::number(msv[2][2]);
m_schnapps->statusBar()->showMessage(msg, 2000); m_schnapps->statusBar()->showMessage(msg, 2000);
QTextStream* rec = m_schnapps->pythonStreamRecorder(); QTextStream* rec = m_schnapps->pythonStreamRecorder();
if (rec) if (rec)
*rec << this->getName() << ".setViewScaling(" << sx << ", " << sy << ", " << sz << ");" << endl; *rec << this->getName() << " getCurrentCamera().setScaling(" << sx << ", " << sy << ", " << sz << ");" << endl;
} }
break; break;
...@@ -767,7 +747,10 @@ glm::mat4 View::getCurrentModelViewProjectionMatrix() const ...@@ -767,7 +747,10 @@ glm::mat4 View::getCurrentModelViewProjectionMatrix() const
} }
const glm::mat4& View::getCurrentTransfoMatrix() const
{
return getCurrentCamera()->getTransfoMatrix();
}
void View::closeDialogs() void View::closeDialogs()
......