Commit 9f27e691 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps: several updates about signals management

parent 4fe72dc8
......@@ -37,6 +37,7 @@ file(
SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/window.h
${SCHNApps_ROOT_DIR}/include/mapHandler.h
${SCHNApps_ROOT_DIR}/include/viewButtonArea.h
${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginsDialog.h
......
......@@ -37,6 +37,10 @@ public:
virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view) {}
virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {}
public slots:
void openComputeNormalDialog();
void openComputeCurvatureDialog();
......
......@@ -37,6 +37,11 @@ void ComputeCurvatureDialog::selectedMapChanged()
{
combo_positionAttribute->clear();
combo_normalAttribute->clear();
combo_KmaxAttribute->clear();
combo_KminAttribute->clear();
combo_KnormalAttribute->clear();
combo_kmaxAttribute->clear();
combo_kminAttribute->clear();
const QString& mapname = currentItems[0]->text();
MapHandlerGen* mh = m_window->getMap(mapname);
GenericMap* map = mh->getGenericMap();
......
......@@ -34,6 +34,10 @@ public:
virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view) {}
virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {}
public slots:
void importFromFile(const QString& fileName);
void importFromFileDialog();
......
......@@ -11,42 +11,47 @@ bool ImportVolumePlugin::enable()
{
importAction = new QAction("import", this);
addMenuAction("Volume;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
return true;
}
void ImportVolumePlugin::cb_import()
void ImportVolumePlugin::importFromFile(const QString& fileName)
{
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.node *.ts *.off *.tet)");
QFileInfo fi(fileName);
if(fi.exists())
{
GenericMap* m = m_window->createMap(3);
PFP3::MAP* map = static_cast<PFP3::MAP*>(m);
MapHandler<PFP3>* h = new MapHandler<PFP3>(fi.baseName(), m_window, map);
MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 3);
if(mhg)
{
MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(mhg);
PFP3::MAP* map = mh->getMap();
std::vector<std::string> attrNames ;
Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames);
std::vector<std::string> attrNames ;
Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames);
// get vertex position attribute
VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, CGoGN::VERTEX>(attrNames[0]);
// get vertex position attribute
VertexAttribute<PFP3::VEC3> position = map->getAttribute<PFP3::VEC3, CGoGN::VERTEX>(attrNames[0]);
// create VBO for vertex position attribute
h->createVBO(position);
// create VBO for vertex position attribute
mh->createVBO(position);
// compute map bounding box
h->updateBB(position);
// compute map bounding box
mh->updateBB(position);
// compute primitive connectivity VBOs
h->updatePrimitives(Algo::Render::GL2::POINTS);
h->updatePrimitives(Algo::Render::GL2::LINES);
h->updatePrimitives(Algo::Render::GL2::TRIANGLES);
m_window->addMap(h);
// compute primitive connectivity VBOs
mh->updatePrimitives(Algo::Render::GL2::POINTS);
mh->updatePrimitives(Algo::Render::GL2::LINES);
mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
}
}
}
void ImportVolumePlugin::importFromFileDialog()
{
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.node *.ts *.off *.tet)");
importFromFile(fileName);
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin)
#else
......
#ifndef _IMPORTSURFACE_PLUGIN_H_
#define _IMPORTSURFACE_PLUGIN_H_
#ifndef _IMPORTVOLUME_PLUGIN_H_
#define _IMPORTVOLUME_PLUGIN_H_
#include "plugin.h"
......@@ -38,11 +38,9 @@ public:
virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {}
virtual void mapLinked(View* view, MapHandlerGen* m) {}
virtual void mapUnlinked(View* view, MapHandlerGen* m) {}
public slots:
void cb_import();
void importFromFile(const QString& fileName);
void importFromFileDialog();
private:
QAction* importAction;
......
......@@ -60,7 +60,6 @@ bool RenderPlugin::enable()
connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
connect(m_dockTab->combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_positionVBOChanged(int)));
connect(m_dockTab->combo_normalVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_normalVBOChanged(int)));
connect(m_dockTab->button_refreshVBOs, SIGNAL(clicked()), this, SLOT(cb_refreshVBOs()));
connect(m_dockTab->check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(cb_renderVerticesChanged(bool)));
connect(m_dockTab->slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_verticesScaleFactorChanged(int)));
connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool)));
......@@ -142,16 +141,19 @@ void RenderPlugin::viewLinked(View* view)
if (!maps.empty())
params->selectedMap = maps[0];
m_dockTab->refreshUI(params);
connect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
connect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
if(view->isCurrentView())
m_dockTab->refreshUI(params);
}
void RenderPlugin::viewUnlinked(View* view)
{
h_viewParams.remove(view);
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
}
void RenderPlugin::currentViewChanged(View* view)
......@@ -160,31 +162,156 @@ void RenderPlugin::currentViewChanged(View* view)
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderPlugin::mapLinked(View* view, MapHandlerGen* m)
void RenderPlugin::mapLinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
PerMapParameterSet p(m);
params->perMap.insert(m->getName(), p);
if(params->perMap.count() == 1)
params->selectedMap = m;
m_dockTab->refreshUI(params);
if(params->selectedMap == NULL || params->perMap.count() == 1)
changeSelectedMap(view, m);
else
m_dockTab->refreshUI(params);
}
void RenderPlugin::mapUnlinked(View* view, MapHandlerGen* m)
void RenderPlugin::mapUnlinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName());
if(params->selectedMap == m)
{
if(!params->perMap.empty())
params->selectedMap = m_window->getMap(params->perMap.begin().key());
changeSelectedMap(view, m_window->getMap(params->perMap.begin().key()));
else
params->selectedMap = NULL;
changeSelectedMap(view, NULL);
}
else
m_dockTab->refreshUI(params);
}
void RenderPlugin::vboAdded(Utils::VBO* vbo)
{
m_dockTab->refreshUI(h_viewParams[m_window->getCurrentView()]);
}
void RenderPlugin::vboRemoved(Utils::VBO* vbo)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[view];
if(params->perMap[map->getName()].positionVBO == vbo)
changePositionVBO(view, map, NULL);
if(params->perMap[map->getName()].normalVBO == vbo)
changeNormalVBO(view, map, NULL);
}
void RenderPlugin::changeSelectedMap(View* view, MapHandlerGen* map)
{
ParameterSet* params = h_viewParams[view];
MapHandlerGen* prev = params->selectedMap;
params->selectedMap = map;
if(view->isCurrentView())
{
if(prev)
disconnect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
if(map)
connect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].positionVBO = vbo;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeNormalVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].normalVBO = vbo;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeRenderVertices(View* view, MapHandlerGen* map, bool b)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].renderVertices = b;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeVerticesScaleFactor(View* view, MapHandlerGen* map, int i)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].verticesScaleFactor = i / 50.0;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeRenderEdges(View* view, MapHandlerGen* map, bool b)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].renderEdges = b;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeRenderFaces(View* view, MapHandlerGen* map, bool b)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].renderFaces = b;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeFacesStyle(View* view, MapHandlerGen* map, FaceShadingStyle style)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].faceStyle = style;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
......@@ -192,16 +319,9 @@ void RenderPlugin::cb_selectedMapChanged()
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[view];
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
{
const QString& mapname = currentItems[0]->text();
params->selectedMap = m_window->getMap(mapname);
m_dockTab->refreshUI(params);
view->updateGL();
}
changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
}
}
......@@ -209,11 +329,9 @@ void RenderPlugin::cb_positionVBOChanged(int index)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* map = params->selectedMap;
params->perMap[map->getName()].positionVBO = map->getVBO(m_dockTab->combo_positionVBO->currentText());
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changePositionVBO(view, map, map->getVBO(m_dockTab->combo_positionVBO->currentText()));
}
}
......@@ -221,30 +339,19 @@ void RenderPlugin::cb_normalVBOChanged(int index)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* map = params->selectedMap;
params->perMap[map->getName()].normalVBO = map->getVBO(m_dockTab->combo_normalVBO->currentText());
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeNormalVBO(view, map, map->getVBO(m_dockTab->combo_normalVBO->currentText()));
}
}
void RenderPlugin::cb_refreshVBOs()
{
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
void RenderPlugin::cb_renderVerticesChanged(bool b)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].renderVertices = b;
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeRenderVertices(view, map, b);
}
}
......@@ -252,11 +359,9 @@ void RenderPlugin::cb_verticesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].verticesScaleFactor = i / 50.0;
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeVerticesScaleFactor(view, map, i);
}
}
......@@ -264,11 +369,9 @@ void RenderPlugin::cb_renderEdgesChanged(bool b)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].renderEdges = b;
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeRenderEdges(view, map, b);
}
}
......@@ -276,11 +379,9 @@ void RenderPlugin::cb_renderFacesChanged(bool b)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].renderFaces = b;
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeRenderFaces(view, map, b);
}
}
......@@ -288,14 +389,12 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
if(m_dockTab->radio_flatShading->isChecked())
params->perMap[m->getName()].faceStyle = FLAT;
changeFacesStyle(view, map, FLAT);
else if(m_dockTab->radio_phongShading->isChecked())
params->perMap[m->getName()].faceStyle = PHONG;
current->updateGL();
changeFacesStyle(view, map, PHONG);
}
}
......@@ -323,42 +422,68 @@ void RenderDockTab::refreshUI(ParameterSet* params)
PerMapParameterSet& p = params->perMap[map->getName()];
QList<Utils::VBO*> vbos = map->getVBOList();
unsigned int j = 0;
for(int i = 0; i < vbos.count(); ++i)
{
combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.positionVBO == NULL)
{ // if nothing is specified in the parameter set
if(vbos[i]->name() == "position") // try to select a VBO named "position"
{
p.positionVBO = vbos[i];
combo_positionVBO->setCurrentIndex(i);
if(vbos[i]->dataSize() == 3)
{
combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.positionVBO == NULL)
{ // if nothing is specified in the parameter set
if(vbos[i]->name() == "position") // try to select a VBO named "position"
{
p.positionVBO = vbos[i];
combo_positionVBO->setCurrentIndex(j);
}
}
}
else if(vbos[i] == p.positionVBO)
combo_positionVBO->setCurrentIndex(i);
else if(vbos[i] == p.positionVBO)
combo_positionVBO->setCurrentIndex(j);
combo_normalVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.normalVBO == NULL)
{ // if nothing is specified in the parameter set
if(vbos[i]->name() == "normal") // try to select a VBO named "normal"
{
p.normalVBO = vbos[i];
combo_normalVBO->setCurrentIndex(i);
combo_normalVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.normalVBO == NULL)
{ // if nothing is specified in the parameter set
if(vbos[i]->name() == "normal") // try to select a VBO named "normal"
{
p.normalVBO = vbos[i];
combo_normalVBO->setCurrentIndex(j);
}
}
else if(vbos[i] == p.normalVBO)
combo_normalVBO->setCurrentIndex(j);
++j;
}
else if(vbos[i] == p.normalVBO)
combo_normalVBO->setCurrentIndex(i);
}
if(p.positionVBO == NULL && vbos.count() > 0)
{
p.positionVBO = vbos[0];
combo_positionVBO->setCurrentIndex(0);
int i = 0;
bool found = false;
while(i < vbos.count() && !found)
{
if(vbos[i]->dataSize() == 3)
{
p.positionVBO = vbos[i];
combo_positionVBO->setCurrentIndex(i);
found = true;
}
++i;
}
}
if(p.normalVBO == NULL && vbos.count() > 0)
{
p.normalVBO = vbos[0];
combo_normalVBO->setCurrentIndex(0);
int i = 0;
bool found = false;
while(i < vbos.count() && !found)
{
if(vbos[i]->dataSize() == 3)
{
p.normalVBO = vbos[i];
combo_normalVBO->setCurrentIndex(i);
found = true;
}
++i;
}
}
check_renderVertices->setChecked(p.renderVertices);
......
......@@ -100,9 +100,6 @@ public:
virtual void viewUnlinked(View* view);
virtual void currentViewChanged(View* view);
virtual void mapLinked(View* view, MapHandlerGen* m);
virtual void mapUnlinked(View* view, MapHandlerGen* m);
void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected:
......@@ -117,10 +114,23 @@ protected:
bool b_refreshingUI;
public slots:
void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m);
void vboAdded(Utils::VBO* vbo);
void vboRemoved(Utils::VBO* vbo);
void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo);
void changeNormalVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo);
void changeRenderVertices(View* view, MapHandlerGen* map, bool b);
void changeVerticesScaleFactor(View* view, MapHandlerGen* map, int i);
void changeRenderEdges(View* view, MapHandlerGen* map, bool b);
void changeRenderFaces(View* view, MapHandlerGen* map, bool b);
void changeFacesStyle(View* view, MapHandlerGen* map, FaceShadingStyle style);
void cb_selectedMapChanged();
void cb_positionVBOChanged(int index);
void cb_normalVBOChanged(int index);
void cb_refreshVBOs();
void cb_renderVerticesChanged(bool b);
void cb_verticesScaleFactorChanged(int i);
void cb_renderEdgesChanged(bool b);
......
......@@ -22,17 +22,10 @@
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Normal :</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="combo_normalVBO">
<item row="0" column="2">
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -46,29 +39,20 @@
</property>
</widget>
</item>