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

SCHNApps: several updates about signals management

parent 4fe72dc8
...@@ -37,6 +37,7 @@ file( ...@@ -37,6 +37,7 @@ file(
SET(SCHNApps_H_OBJECT_FILES SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/view.h ${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/window.h ${SCHNApps_ROOT_DIR}/include/window.h
${SCHNApps_ROOT_DIR}/include/mapHandler.h
${SCHNApps_ROOT_DIR}/include/viewButtonArea.h ${SCHNApps_ROOT_DIR}/include/viewButtonArea.h
${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h ${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginsDialog.h ${SCHNApps_ROOT_DIR}/include/dialogs/pluginsDialog.h
......
...@@ -37,6 +37,10 @@ public: ...@@ -37,6 +37,10 @@ public:
virtual void mouseMove(View* view, int buttons, int x, int y) {} virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, 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: public slots:
void openComputeNormalDialog(); void openComputeNormalDialog();
void openComputeCurvatureDialog(); void openComputeCurvatureDialog();
......
...@@ -37,6 +37,11 @@ void ComputeCurvatureDialog::selectedMapChanged() ...@@ -37,6 +37,11 @@ void ComputeCurvatureDialog::selectedMapChanged()
{ {
combo_positionAttribute->clear(); combo_positionAttribute->clear();
combo_normalAttribute->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(); const QString& mapname = currentItems[0]->text();
MapHandlerGen* mh = m_window->getMap(mapname); MapHandlerGen* mh = m_window->getMap(mapname);
GenericMap* map = mh->getGenericMap(); GenericMap* map = mh->getGenericMap();
......
...@@ -34,6 +34,10 @@ public: ...@@ -34,6 +34,10 @@ public:
virtual void mouseMove(View* view, int buttons, int x, int y) {} virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, 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: public slots:
void importFromFile(const QString& fileName); void importFromFile(const QString& fileName);
void importFromFileDialog(); void importFromFileDialog();
......
...@@ -11,42 +11,47 @@ bool ImportVolumePlugin::enable() ...@@ -11,42 +11,47 @@ bool ImportVolumePlugin::enable()
{ {
importAction = new QAction("import", this); importAction = new QAction("import", this);
addMenuAction("Volume;Import", importAction); addMenuAction("Volume;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import())); connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
return true; 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); QFileInfo fi(fileName);
if(fi.exists()) if(fi.exists())
{ {
GenericMap* m = m_window->createMap(3); MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 3);
PFP3::MAP* map = static_cast<PFP3::MAP*>(m); if(mhg)
MapHandler<PFP3>* h = new MapHandler<PFP3>(fi.baseName(), m_window, map); {
MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(mhg);
PFP3::MAP* map = mh->getMap();
std::vector<std::string> attrNames ; std::vector<std::string> attrNames ;
Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames); Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames);
// get vertex position attribute // get vertex position attribute
VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, CGoGN::VERTEX>(attrNames[0]); VertexAttribute<PFP3::VEC3> position = map->getAttribute<PFP3::VEC3, CGoGN::VERTEX>(attrNames[0]);
// create VBO for vertex position attribute // create VBO for vertex position attribute
h->createVBO(position); mh->createVBO(position);
// compute map bounding box // compute map bounding box
h->updateBB(position); mh->updateBB(position);
// compute primitive connectivity VBOs // compute primitive connectivity VBOs
h->updatePrimitives(Algo::Render::GL2::POINTS); mh->updatePrimitives(Algo::Render::GL2::POINTS);
h->updatePrimitives(Algo::Render::GL2::LINES); mh->updatePrimitives(Algo::Render::GL2::LINES);
h->updatePrimitives(Algo::Render::GL2::TRIANGLES); mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
}
m_window->addMap(h);
} }
} }
void ImportVolumePlugin::importFromFileDialog()
{
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.node *.ts *.off *.tet)");
importFromFile(fileName);
}
#ifndef DEBUG #ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin) Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin)
#else #else
......
#ifndef _IMPORTSURFACE_PLUGIN_H_ #ifndef _IMPORTVOLUME_PLUGIN_H_
#define _IMPORTSURFACE_PLUGIN_H_ #define _IMPORTVOLUME_PLUGIN_H_
#include "plugin.h" #include "plugin.h"
...@@ -38,11 +38,9 @@ public: ...@@ -38,11 +38,9 @@ public:
virtual void viewUnlinked(View* view) {} virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {} virtual void currentViewChanged(View* view) {}
virtual void mapLinked(View* view, MapHandlerGen* m) {}
virtual void mapUnlinked(View* view, MapHandlerGen* m) {}
public slots: public slots:
void cb_import(); void importFromFile(const QString& fileName);
void importFromFileDialog();
private: private:
QAction* importAction; QAction* importAction;
......
This diff is collapsed.
...@@ -100,9 +100,6 @@ public: ...@@ -100,9 +100,6 @@ public:
virtual void viewUnlinked(View* view); virtual void viewUnlinked(View* view);
virtual void currentViewChanged(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; } void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected: protected:
...@@ -117,10 +114,23 @@ protected: ...@@ -117,10 +114,23 @@ protected:
bool b_refreshingUI; bool b_refreshingUI;
public slots: 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_selectedMapChanged();
void cb_positionVBOChanged(int index); void cb_positionVBOChanged(int index);
void cb_normalVBOChanged(int index); void cb_normalVBOChanged(int index);
void cb_refreshVBOs();
void cb_renderVerticesChanged(bool b); void cb_renderVerticesChanged(bool b);
void cb_verticesScaleFactorChanged(int i); void cb_verticesScaleFactorChanged(int i);
void cb_renderEdgesChanged(bool b); void cb_renderEdgesChanged(bool b);
......
...@@ -22,17 +22,10 @@ ...@@ -22,17 +22,10 @@
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SetDefaultConstraint</enum>
</property> </property>
<item row="1" column="0"> <item row="0" column="2">
<widget class="QLabel" name="label_3"> <widget class="QComboBox" name="combo_positionVBO">
<property name="text">
<string>Normal :</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="combo_normalVBO">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
...@@ -46,29 +39,20 @@ ...@@ -46,29 +39,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="1" column="1" colspan="2">
<widget class="QComboBox" name="combo_positionVBO"> <widget class="QComboBox" name="combo_normalVBO">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="1" column="0">
<widget class="QPushButton" name="button_refreshVBOs"> <widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text"> <property name="text">
<string>Refresh</string> <string>Normal :</string>
</property> </property>
</widget> </widget>
</item> </item>
......
...@@ -33,8 +33,7 @@ bool RenderVectorPlugin::enable() ...@@ -33,8 +33,7 @@ bool RenderVectorPlugin::enable()
connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged())); 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_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_positionVBOChanged(int)));
connect(m_dockTab->list_vectorVBO, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedVectorVBOChanged())); connect(m_dockTab->list_vectorVBO, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedVectorsVBOChanged()));
connect(m_dockTab->button_refreshVBOs, SIGNAL(clicked()), this, SLOT(cb_refreshVBOs()));
connect(m_dockTab->slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_vectorsScaleFactorChanged(int))); connect(m_dockTab->slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_vectorsScaleFactorChanged(int)));
return true; return true;
...@@ -80,16 +79,19 @@ void RenderVectorPlugin::viewLinked(View* view) ...@@ -80,16 +79,19 @@ void RenderVectorPlugin::viewLinked(View* view)
if (!maps.empty()) if (!maps.empty())
params->selectedMap = maps[0]; 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 RenderVectorPlugin::viewUnlinked(View* view) void RenderVectorPlugin::viewUnlinked(View* view)
{ {
h_viewParams.remove(view); h_viewParams.remove(view);
View* current = m_window->getCurrentView(); disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
if(isLinkedToView(current)) disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
m_dockTab->refreshUI(h_viewParams[current]);
} }
void RenderVectorPlugin::currentViewChanged(View* view) void RenderVectorPlugin::currentViewChanged(View* view)
...@@ -98,31 +100,106 @@ void RenderVectorPlugin::currentViewChanged(View* view) ...@@ -98,31 +100,106 @@ void RenderVectorPlugin::currentViewChanged(View* view)
m_dockTab->refreshUI(h_viewParams[view]); m_dockTab->refreshUI(h_viewParams[view]);
} }
void RenderVectorPlugin::mapLinked(View* view, MapHandlerGen* m) void RenderVectorPlugin::mapLinked(MapHandlerGen* m)
{ {
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view)); assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
PerMapParameterSet p(m); PerMapParameterSet p(m);
params->perMap.insert(m->getName(), p); params->perMap.insert(m->getName(), p);
if(params->perMap.count() == 1) if(params->selectedMap == NULL || params->perMap.count() == 1)
params->selectedMap = m; changeSelectedMap(view, m);
else
m_dockTab->refreshUI(params); m_dockTab->refreshUI(params);
} }
void RenderVectorPlugin::mapUnlinked(View* view, MapHandlerGen* m) void RenderVectorPlugin::mapUnlinked(MapHandlerGen* m)
{ {
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view)); assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName()); params->perMap.remove(m->getName());
if(params->selectedMap == m) if(params->selectedMap == m)
{ {
if(!params->perMap.empty()) if(!params->perMap.empty())
params->selectedMap = m_window->getMap(params->perMap.begin().key()); changeSelectedMap(view, m_window->getMap(params->perMap.begin().key()));
else else
params->selectedMap = NULL; changeSelectedMap(view, NULL);
}
else
m_dockTab->refreshUI(params); m_dockTab->refreshUI(params);
}
void RenderVectorPlugin::vboAdded(Utils::VBO* vbo)
{
m_dockTab->refreshUI(h_viewParams[m_window->getCurrentView()]);
}
void RenderVectorPlugin::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);
}
void RenderVectorPlugin::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 RenderVectorPlugin::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 RenderVectorPlugin::changeSelectedVectorsVBO(View* view, MapHandlerGen* map, const std::vector<Utils::VBO*>& vbos)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].vectorVBO = vbos;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderVectorPlugin::changeVectorsScaleFactor(View* view, MapHandlerGen* map, int i)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].vectorsScaleFactor = i / 50.0;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
} }
} }
...@@ -130,16 +207,9 @@ void RenderVectorPlugin::cb_selectedMapChanged() ...@@ -130,16 +207,9 @@ void RenderVectorPlugin::cb_selectedMapChanged()
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[view];
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems(); QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty()) if(!currentItems.empty())
{ changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
const QString& mapname = currentItems[0]->text();
params->selectedMap = m_window->getMap(mapname);
m_dockTab->refreshUI(params);
view->updateGL();
}
} }
} }
...@@ -147,48 +217,33 @@ void RenderVectorPlugin::cb_positionVBOChanged(int index) ...@@ -147,48 +217,33 @@ void RenderVectorPlugin::cb_positionVBOChanged(int index)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* map = params->selectedMap; changePositionVBO(view, map, map->getVBO(m_dockTab->combo_positionVBO->currentText()));
params->perMap[map->getName()].positionVBO = map->getVBO(m_dockTab->combo_positionVBO->currentText());
current->updateGL();
} }
} }
void RenderVectorPlugin::cb_selectedVectorVBOChanged() void RenderVectorPlugin::cb_selectedVectorsVBOChanged()
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* map = params->selectedMap;
PerMapParameterSet& mapParam = params->perMap[map->getName()];
mapParam.vectorVBO.clear();
QList<QListWidgetItem*> currentItems = m_dockTab->list_vectorVBO->selectedItems(); QList<QListWidgetItem*> currentItems = m_dockTab->list_vectorVBO->selectedItems();
std::vector<Utils::VBO*> vbos;
foreach(QListWidgetItem* item, currentItems) foreach(QListWidgetItem* item, currentItems)
mapParam.vectorVBO.push_back(map->getVBO(item->text())); vbos.push_back(map->getVBO(item->text()));
changeSelectedVectorsVBO(view, map, vbos);
current->updateGL();
} }
} }
void RenderVectorPlugin::cb_refreshVBOs()
{
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
void RenderVectorPlugin::cb_vectorsScaleFactorChanged(int i) void RenderVectorPlugin::cb_vectorsScaleFactorChanged(int i)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* m = params->selectedMap; changeVectorsScaleFactor(view, map, i);
params->perMap[m->getName()].vectorsScaleFactor = i / 50.0;
current->updateGL();
} }
} }
...@@ -219,23 +274,24 @@ void RenderVectorDockTab::refreshUI(ParameterSet* params) ...@@ -219,23 +274,24 @@ void RenderVectorDockTab::refreshUI(ParameterSet* params)
unsigned int j = 0; unsigned int j = 0;
for(int i = 0; i < vbos.count(); ++i) 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);
}
}
else if(vbos[i] == p.positionVBO)
combo_positionVBO->setCurrentIndex(i);
if(vbos[i]->dataSize() == 3) 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(j);