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

Camera::setScaling

parent b9dd9823
......@@ -59,6 +59,9 @@ e</string>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
......@@ -163,6 +166,9 @@ d</string>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
......
......@@ -34,6 +34,7 @@
<addaction name="action_LoadPythonScript"/>
<addaction name="action_Python_Recording"/>
<addaction name="action_Append_Python_Recording"/>
<addaction name="action_Clean_All"/>
<addaction name="separator"/>
<addaction name="action_Quit"/>
</widget>
......@@ -97,6 +98,11 @@
<string>Append Python Recording</string>
</property>
</action>
<action name="action_Clean_All">
<property name="text">
<string>Clean All</string>
</property>
</action>
</widget>
<resources/>
<connections>
......
......@@ -29,6 +29,8 @@ public:
~Camera();
const QString& getName() const { return m_name; }
const glm::mat4& getTransfoMatrix() const;
public slots:
QString getName() { return m_name; }
SCHNApps* getSCHNApps() const { return m_schnapps; }
......@@ -53,6 +55,8 @@ public slots:
QString toString();
void fromString(QString cam);
void setScaling(float sx, float sy, float sz);
private:
void linkView(View* view);
void unlinkView(View* view);
......@@ -72,10 +76,13 @@ protected:
QList<View*> l_views;
glm::mat4 m_transfoMatrix;
bool b_draw;
bool b_drawPath;
bool b_fitToViewsBoundingBox;
};
} // namespace SCHNApps
......
......@@ -137,6 +137,9 @@ public:
void addMenuAction(Plugin* plugin, const QString& menuPath, QAction* action);
void removeMenuAction(Plugin* plugin, QAction* action);
bool execPythonShortcut(quint64 key);
public slots:
void aboutSCHNApps();
void aboutCGoGN();
......@@ -147,7 +150,12 @@ public slots:
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);
......@@ -155,7 +163,9 @@ public slots:
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:
void loadPythonScriptFromFileDialog();
......@@ -169,17 +179,21 @@ protected:
QFile* m_pyRecFile;
QList<QString> m_pyVarNames;
QString m_pyBuffer;
QMap<quint64, QString > m_pythonShortCuts;
QString m_pyPathFile;
private slots:
void pyRecording();
void appendPyRecording();
// void endPyRecording();
void cleanAll();
public:
inline QTextStream* pythonStreamRecorder() { return m_pyRecording; }
inline void pythonVarDeclare(const QString& var) { m_pyVarNames.push_back(var); }
inline void pythonVarsClear() { m_pyVarNames.clear(); }
signals:
void cameraAdded(Camera* camera);
void cameraRemoved(Camera* camera);
......@@ -204,6 +218,8 @@ protected:
PythonQtObjectPtr& m_pythonContext;
PythonQtScriptingConsole& m_pythonConsole;
void execPythonCmd(const QString& fileName);
QDockWidget* m_controlDock;
QTabWidget* m_controlDockTabWidget;
ControlDock_CameraTab* m_controlCameraTab;
......@@ -226,8 +242,6 @@ protected:
QMap<Plugin*, QList<QWidget*> > m_pluginTabs;
QMap<Plugin*, QList<QAction*> > m_pluginMenuActions;
QMap<int, QString > m_pythonShortCuts;
CameraSet m_cameras;
ViewSet m_views;
......
......@@ -80,8 +80,6 @@ public slots:
bool isLinkedToMap(MapHandlerGen* map) const { return l_maps.contains(map); }
bool isLinkedToMap(const QString& name) const;
void setViewScaling(float sx, float sy, float sz);
private:
bool b_updatingUI;
......@@ -104,6 +102,7 @@ private:
glm::mat4 getCurrentModelViewMatrix() const;
glm::mat4 getCurrentProjectionMatrix() const;
glm::mat4 getCurrentModelViewProjectionMatrix() const;
const glm::mat4& getCurrentTransfoMatrix() const;
private slots:
void closeDialogs();
......@@ -176,10 +175,6 @@ protected:
Utils::Texture<2, Geom::Vec3uc>* m_textureWallpaper;
Utils::ShaderWallPaper* m_shaderWallpaper;
glm::mat4 m_scaleView;
inline float scaleRealSlideVal(int v);
inline int scaleIntSlideVal(float v);
bool b_saveSnapshots;
inline int pixelRatio() const
......
......@@ -14,6 +14,7 @@ unsigned int Camera::cameraCount = 0;
Camera::Camera(const QString& name, SCHNApps* s) :
m_name(name),
m_schnapps(s),
m_transfoMatrix(1.0f),
b_draw(false),
b_drawPath(false),
b_fitToViewsBoundingBox(true)
......@@ -149,6 +150,19 @@ void Camera::fromString(QString cam)
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
......
......@@ -109,6 +109,8 @@ SCHNApps::SCHNApps(const QString& appPath, PythonQtObjectPtr& pythonContext, Pyt
connect(action_Python_Recording, SIGNAL(triggered()), this, SLOT(pyRecording()));
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_Append_Python_Recording->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_P));
......@@ -525,13 +527,6 @@ void SCHNApps::disablePlugin(const QString& 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)
PluginInteraction* pi = dynamic_cast<PluginInteraction*>(plugin);
if(pi)
......@@ -544,6 +539,14 @@ void SCHNApps::disablePlugin(const QString& pluginName)
plugin->disable();
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());
loader.unload();
......@@ -1019,7 +1022,11 @@ void SCHNApps::loadPythonScriptFromFile(const QString& fileName)
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);
}
......@@ -1059,7 +1066,11 @@ void SCHNApps::pyRecording()
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)
{
m_pyRecFile = new QFile(fileName);
......@@ -1123,7 +1134,11 @@ void SCHNApps::appendPyRecording()
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)
{
m_pyRecFile = new QFile(fileName);
......@@ -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)
{
......@@ -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
......
......@@ -46,7 +46,6 @@ View::View(const QString& name, SCHNApps* s, const QGLWidget* shareWidget) :
m_frameDrawer(NULL),
m_textureWallpaper(NULL),
m_shaderWallpaper(NULL),
m_scaleView(1.0f),
b_saveSnapshots(false)
{
++viewCount;
......@@ -443,12 +442,13 @@ void View::draw()
glm::mat4 mm = getCurrentModelViewMatrix();
glm::mat4 pm = getCurrentProjectionMatrix();
const glm::mat4& tr = getCurrentTransfoMatrix();
MapHandlerGen* selectedMap = m_schnapps->getSelectedMap();
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();
if(map == selectedMap)
......@@ -504,57 +504,37 @@ void View::drawFrame()
}
void View::setViewScaling(float sx, float sy, float sz)
{
m_scaleView[0][0] = sx;
m_scaleView[1][1] = sy;
m_scaleView[2][2] = sz;
}
float View::scaleRealSlideVal(int v)
void View::keyPressEvent(QKeyEvent* event)
{
if (v < 50)
return 1.0f - ((50 - v) / 100.0f);
return 1.0f + ((v - 50) / 25.0f);
}
quint64 k = event->modifiers();
k <<= 32;
k |= event->key();
int View::scaleIntSlideVal(float v)
{
if (v < 1.0f)
return int((v - 1.0f) * 100 + 50);
return int((v - 1.0f) * 25 + 50);
}
// exec python shortcuts if exist
m_schnapps->execPythonShortcut(k);
void View::keyPressEvent(QKeyEvent* event)
{
switch (event->key())
{
case Qt::Key_Z:
{
// m_schnapps->execPythonCmd("schnapps.getSelectedView().setViewScaling(1.,0.5,1.0);schnapps.getSelectedView().updateGL()");
int isX = scaleIntSlideVal(m_scaleView[0][0]);
int isY = scaleIntSlideVal(m_scaleView[1][1]);
int isZ = scaleIntSlideVal(m_scaleView[2][2]);
const glm::mat4& msv = getCurrentCamera()->getTransfoMatrix();
float sx = msv[0][0];
float sy = msv[1][1];
float sz = msv[2][2];
Utils::QT::inputValues(
Utils::QT::VarSlider(0, 100, isX, "Scale X",
Utils::QT::VarSlider(0, 100, isY, "Scale Y",
Utils::QT::VarSlider(0, 100, isZ, "Scale Z"))),"Scaling view");
float sx = scaleRealSlideVal(isX);
float sy = scaleRealSlideVal(isY);
float sz = scaleRealSlideVal(isZ);
Utils::QT::VarFloat(0.1f, 10.0f, sx, "Scale X",
Utils::QT::VarFloat(0.1f, 10.0f, sy, "Scale Y",
Utils::QT::VarFloat(0.1f, 10.0f, sz, "Scale Z"))), "Scaling view");
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);
QTextStream* rec = m_schnapps->pythonStreamRecorder();
if (rec)
*rec << this->getName() << ".setViewScaling(" << sx << ", " << sy << ", " << sz << ");" << endl;
*rec << this->getName() << " getCurrentCamera().setScaling(" << sx << ", " << sy << ", " << sz << ");" << endl;
}
break;
......@@ -767,7 +747,10 @@ glm::mat4 View::getCurrentModelViewProjectionMatrix() const
}
const glm::mat4& View::getCurrentTransfoMatrix() const
{
return getCurrentCamera()->getTransfoMatrix();
}
void View::closeDialogs()
......
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