Commit 7297ee8a authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

SCHNApps: update renderExplod plugin

parent 986a72a3
......@@ -54,12 +54,15 @@ bool RenderExplodPlugin::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_colorVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_colorVBOChanged(int)));
connect(m_dockTab->button_refreshVBOs, SIGNAL(clicked()), this, SLOT(cb_refreshVBOs()));
connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool)));
connect(m_dockTab->check_renderFaces, SIGNAL(toggled(bool)), this, SLOT(cb_renderFacesChanged(bool)));
connect(m_dockTab->slider_facesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_facesScaleFactorChanged(int)));
connect(m_dockTab->slider_volumesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_volumesScaleFactorChanged(int)));
connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*)));
connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));
return true;
}
......@@ -95,8 +98,10 @@ void RenderExplodPlugin::redraw(View* view)
}
}
void RenderExplodPlugin::viewLinked(View* view)
void RenderExplodPlugin::viewLinked(View* view, Plugin* plugin)
{
if(plugin == this)
{
ParameterSet* params = new ParameterSet();
h_viewParams.insert(view, params);
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
......@@ -106,107 +111,212 @@ void RenderExplodPlugin::viewLinked(View* view)
params->perMap.insert(map->getName(), p);
}
if (!maps.empty())
params->selectedMap = maps[0];
changeSelectedMap(view, maps[0]);
connect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
connect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
m_dockTab->refreshUI(params);
}
}
void RenderExplodPlugin::viewUnlinked(View* view)
void RenderExplodPlugin::viewUnlinked(View* view, Plugin* plugin)
{
if(plugin == this)
{
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 RenderExplodPlugin::currentViewChanged(View* view)
{
assert(isLinkedToView(view));
if(isLinkedToView(view))
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderExplodPlugin::mapLinked(View* view, MapHandlerGen* m)
void RenderExplodPlugin::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;
if(params->selectedMap == NULL || params->perMap.count() == 1)
changeSelectedMap(view, m);
else
m_dockTab->refreshUI(params);
}
void RenderExplodPlugin::mapUnlinked(View* view, MapHandlerGen* m)
void RenderExplodPlugin::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
changeSelectedMap(view, NULL);
}
else
params->selectedMap = NULL;
m_dockTab->refreshUI(params);
}
void RenderExplodPlugin::vboAdded(Utils::VBO* vbo)
{
m_dockTab->refreshUI(h_viewParams[m_window->getCurrentView()]);
}
void RenderExplodPlugin::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()].colorVBO == vbo)
changeColorVBO(view, map, NULL);
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderExplodPlugin::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 RenderExplodPlugin::cb_selectedMapChanged()
void RenderExplodPlugin::changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo)
{
if(!b_refreshingUI)
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].positionVBO = vbo;
if(view->isCurrentView())
{
View* view = m_window->getCurrentView();
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderExplodPlugin::changeColorVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo)
{
ParameterSet* params = h_viewParams[view];
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
params->perMap[map->getName()].colorVBO = vbo;
if(view->isCurrentView())
{
const QString& mapname = currentItems[0]->text();
params->selectedMap = m_window->getMap(mapname);
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderExplodPlugin::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 RenderExplodPlugin::cb_positionVBOChanged(int index)
void RenderExplodPlugin::changeRenderFaces(View* view, MapHandlerGen* map, bool b)
{
if(!b_refreshingUI)
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].renderFaces = b;
if(view->isCurrentView())
{
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();
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderExplodPlugin::cb_colorVBOChanged(int index)
void RenderExplodPlugin::changeFacesScaleFactor(View* view, MapHandlerGen* map, int i)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].facesScaleFactor = i / 50.0;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderExplodPlugin::changeVolumesScaleFactor(View* view, MapHandlerGen* map, int i)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].volumesScaleFactor = i / 50.0;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderExplodPlugin::cb_selectedMapChanged()
{
if(!b_refreshingUI)
{
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
}
}
void RenderExplodPlugin::cb_positionVBOChanged(int index)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changePositionVBO(view, map, map->getVBO(m_dockTab->combo_positionVBO->currentText()));
}
}
void RenderExplodPlugin::cb_refreshVBOs()
void RenderExplodPlugin::cb_colorVBOChanged(int index)
{
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeColorVBO(view, map, map->getVBO(m_dockTab->combo_positionVBO->currentText()));
}
}
void RenderExplodPlugin::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);
}
}
......@@ -214,11 +324,9 @@ void RenderExplodPlugin::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);
}
}
......@@ -226,11 +334,9 @@ void RenderExplodPlugin::cb_facesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].facesScaleFactor = i / 50.0;
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeFacesScaleFactor(view, map, i);
}
}
......@@ -238,11 +344,9 @@ void RenderExplodPlugin::cb_volumesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].volumesScaleFactor = i / 50.0;
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeVolumesScaleFactor(view, map, i);
}
}
......@@ -267,45 +371,71 @@ void RenderExplodDockTab::refreshUI(ParameterSet* params)
item[0]->setSelected(true);
PerMapParameterSet& p = params->perMap[map->getName()];
//
// QList<Utils::VBO*> vbos = map->getVBOList();
// 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);
//
// 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);
// }
// }
// 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);
// }
// if(p.normalVBO == NULL && vbos.count() > 0)
// {
// p.normalVBO = vbos[0];
// combo_normalVBO->setCurrentIndex(0);
// }
QList<Utils::VBO*> vbos = map->getVBOList();
unsigned int j = 0;
for(int i = 0; i < vbos.count(); ++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(j);
combo_colorVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.colorVBO == NULL)
{ // if nothing is specified in the parameter set
if(vbos[i]->name() == "color") // try to select a VBO named "color"
{
p.colorVBO = vbos[i];
combo_colorVBO->setCurrentIndex(j);
}
}
else if(vbos[i] == p.colorVBO)
combo_colorVBO->setCurrentIndex(j);
++j;
}
}
if(p.positionVBO == NULL && vbos.count() > 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.colorVBO == NULL && vbos.count() > 0)
{
int i = 0;
bool found = false;
while(i < vbos.count() && !found)
{
if(vbos[i]->dataSize() == 3)
{
p.colorVBO = vbos[i];
combo_colorVBO->setCurrentIndex(i);
found = true;
}
++i;
}
}
check_renderEdges->setChecked(p.renderEdges);
check_renderFaces->setChecked(p.renderFaces);
......
......@@ -84,13 +84,6 @@ 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);
virtual void mapLinked(View* view, MapHandlerGen* m);
virtual void mapUnlinked(View* view, MapHandlerGen* m);
void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected:
......@@ -100,10 +93,27 @@ protected:
bool b_refreshingUI;
public slots:
void viewLinked(View* view, Plugin* plugin);
void viewUnlinked(View* view, Plugin* plugin);
void currentViewChanged(View* view);
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 changeColorVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo);
void changeRenderEdges(View* view, MapHandlerGen* map, bool b);
void changeRenderFaces(View* view, MapHandlerGen* map, bool b);
void changeFacesScaleFactor(View* view, MapHandlerGen* map, int i);
void changeVolumesScaleFactor(View* view, MapHandlerGen* map, int i);
void cb_selectedMapChanged();
void cb_positionVBOChanged(int index);
void cb_colorVBOChanged(int index);
void cb_refreshVBOs();
void cb_renderEdgesChanged(bool b);
void cb_renderFacesChanged(bool b);
void cb_facesScaleFactorChanged(int i);
......
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