From 71054826f84066dd5b6c0541b1656a2d9aa0c963 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Sat, 12 Oct 2013 23:04:09 +0200 Subject: [PATCH] create empty map in modelisation plugin --- .../forms/surface_modelisation.ui | 89 ++++++++------- .../include/surface_modelisation.h | 3 +- .../include/surface_modelisation_dockTab.h | 9 +- .../src/surface_modelisation.cpp | 64 ++++++++++- .../src/surface_modelisation_dockTab.cpp | 106 +++++++++++++++++- 5 files changed, 224 insertions(+), 47 deletions(-) diff --git a/SCHNApps/Plugins/surface_modelisation/forms/surface_modelisation.ui b/SCHNApps/Plugins/surface_modelisation/forms/surface_modelisation.ui index 25fb1c129..8132b728d 100644 --- a/SCHNApps/Plugins/surface_modelisation/forms/surface_modelisation.ui +++ b/SCHNApps/Plugins/surface_modelisation/forms/surface_modelisation.ui @@ -6,7 +6,7 @@ 0 0 - 259 + 345 600 @@ -14,21 +14,52 @@ Form - + + + + Position : + + + + + + + + 0 + 0 + + + + + - select attribute - + + + + + Vertex selector : - + + + + + - select selector - + + + + + Edge selector : - + @@ -37,14 +68,14 @@ - + Face selector : - + @@ -53,37 +84,35 @@ - + Qt::Horizontal - - - - - - select selector - - - + + + + Create empty map + - - + + - Create cube + Add cube - + Flip edge - + Qt::Vertical @@ -96,28 +125,6 @@ - - - - - 0 - 0 - - - - - - select attribute - - - - - - - - - Position : - - - diff --git a/SCHNApps/Plugins/surface_modelisation/include/surface_modelisation.h b/SCHNApps/Plugins/surface_modelisation/include/surface_modelisation.h index 022a5ea1c..57c387d4b 100644 --- a/SCHNApps/Plugins/surface_modelisation/include/surface_modelisation.h +++ b/SCHNApps/Plugins/surface_modelisation/include/surface_modelisation.h @@ -75,7 +75,8 @@ public slots: void changeFaceSelector(const QString& map, const QString& name); protected: - void createCube(MapHandlerGen* mhg); + void createEmptyMap(); + void addCube(MapHandlerGen* mhg); void flipEdge(MapHandlerGen* mhg); protected: diff --git a/SCHNApps/Plugins/surface_modelisation/include/surface_modelisation_dockTab.h b/SCHNApps/Plugins/surface_modelisation/include/surface_modelisation_dockTab.h index 20f37c3b3..b05b73b4b 100644 --- a/SCHNApps/Plugins/surface_modelisation/include/surface_modelisation_dockTab.h +++ b/SCHNApps/Plugins/surface_modelisation/include/surface_modelisation_dockTab.h @@ -33,11 +33,18 @@ private slots: void edgeSelectorChanged(int index); void faceSelectorChanged(int index); - void createCubeButtonClicked(); + void createEmptyMapButtonClicked(); + void addCubeButtonClicked(); void flipEdgeButtonClicked(); private: void addVertexAttribute(const QString& name); + void addVertexSelector(const QString& name); + void removeVertexSelector(const QString& name); + void addEdgeSelector(const QString& name); + void removeEdgeSelector(const QString& name); + void addFaceSelector(const QString& name); + void removeFaceSelector(const QString& name); void updateMapParameters(); }; diff --git a/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp b/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp index d4ab2c24c..0eb770fca 100644 --- a/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp +++ b/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp @@ -49,6 +49,8 @@ void Surface_Modelisation_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHan void Surface_Modelisation_Plugin::mapAdded(MapHandlerGen* map) { connect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(attributeAdded(unsigned int, const QString&))); + connect(map, SIGNAL(cellSelectorAdded(unsigned int, const QString&)), this, SLOT(cellSelectorAdded(unsigned int, const QString&))); + connect(map, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(cellSelectorRemoved(unsigned int, const QString&))); } void Surface_Modelisation_Plugin::mapRemoved(MapHandlerGen* map) @@ -67,6 +69,48 @@ void Surface_Modelisation_Plugin::attributeAdded(unsigned int orbit, const QStri m_dockTab->addVertexAttribute(name); } +void Surface_Modelisation_Plugin::cellSelectorAdded(unsigned int orbit, const QString& name) +{ + MapHandlerGen* map = static_cast(QObject::sender()); + + if(map->isSelectedMap()) + { + switch(orbit) + { + case VERTEX : + m_dockTab->addVertexSelector(name); + break; + case EDGE : + m_dockTab->addEdgeSelector(name); + break; + case FACE : + m_dockTab->addFaceSelector(name); + break; + } + } +} + +void Surface_Modelisation_Plugin::cellSelectorRemoved(unsigned int orbit, const QString& name) +{ + MapHandlerGen* map = static_cast(QObject::sender()); + + if(map->isSelectedMap()) + { + switch(orbit) + { + case VERTEX : + m_dockTab->removeVertexSelector(name); + break; + case EDGE : + m_dockTab->removeEdgeSelector(name); + break; + case FACE : + m_dockTab->removeFaceSelector(name); + break; + } + } +} + @@ -122,7 +166,22 @@ void Surface_Modelisation_Plugin::changeFaceSelector(const QString& map, const Q -void Surface_Modelisation_Plugin::createCube(MapHandlerGen *mhg) +void Surface_Modelisation_Plugin::createEmptyMap() +{ + MapHandlerGen* mhg = m_schnapps->addMap("map", 2); + if(mhg) + { + MapHandler* mh = static_cast*>(mhg); + + // add vertex position attribute + VertexAttribute position = mh->addAttribute("position"); + + // update corresponding VBO & emit attribute update signal + mh->notifyAttributeModification(position); + } +} + +void Surface_Modelisation_Plugin::addCube(MapHandlerGen *mhg) { MapHandler* mh = static_cast*>(mhg); PFP2::MAP* map = mh->getMap(); @@ -133,6 +192,9 @@ void Surface_Modelisation_Plugin::createCube(MapHandlerGen *mhg) mh->notifyAttributeModification(position); mh->notifyConnectivityModification(); + + // compute map bounding box + mh->updateBB(position); } void Surface_Modelisation_Plugin::flipEdge(MapHandlerGen *mhg) diff --git a/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation_dockTab.cpp b/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation_dockTab.cpp index a90a8930e..f698661f2 100644 --- a/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation_dockTab.cpp +++ b/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation_dockTab.cpp @@ -17,7 +17,11 @@ Surface_Modelisation_DockTab::Surface_Modelisation_DockTab(SCHNApps* s, Surface_ setupUi(this); connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int))); - connect(button_createCube, SIGNAL(clicked()), this, SLOT(createCubeButtonClicked())); + connect(combo_vertexSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(vertexSelectorChanged(int))); + connect(combo_edgeSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(edgeSelectorChanged(int))); + connect(combo_faceSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(faceSelectorChanged(int))); + connect(button_createEmptyMap, SIGNAL(clicked()), this, SLOT(createEmptyMapButtonClicked())); + connect(button_addCube, SIGNAL(clicked()), this, SLOT(addCubeButtonClicked())); connect(button_flipEdge, SIGNAL(clicked()), this, SLOT(flipEdgeButtonClicked())); } @@ -65,13 +69,21 @@ void Surface_Modelisation_DockTab::faceSelectorChanged(int index) } } -void Surface_Modelisation_DockTab::createCubeButtonClicked() +void Surface_Modelisation_DockTab::createEmptyMapButtonClicked() +{ + if(!b_updatingUI) + { + m_plugin->createEmptyMap(); + } +} + +void Surface_Modelisation_DockTab::addCubeButtonClicked() { if(!b_updatingUI) { MapHandlerGen* map = m_schnapps->getSelectedMap(); if(map) - m_plugin->createCube(map); + m_plugin->addCube(map); } } @@ -99,12 +111,72 @@ void Surface_Modelisation_DockTab::addVertexAttribute(const QString& nameAttr) b_updatingUI = false; } +void Surface_Modelisation_DockTab::addVertexSelector(const QString& name) +{ + b_updatingUI = true; + combo_vertexSelector->addItem(name); + b_updatingUI = false; +} + +void Surface_Modelisation_DockTab::removeVertexSelector(const QString& name) +{ + b_updatingUI = true; + int curIndex = combo_vertexSelector->currentIndex(); + int index = combo_vertexSelector->findText(name, Qt::MatchExactly); + if(curIndex == index) + combo_vertexSelector->setCurrentIndex(0); + combo_vertexSelector->removeItem(index); + b_updatingUI = false; +} + +void Surface_Modelisation_DockTab::addEdgeSelector(const QString& name) +{ + b_updatingUI = true; + combo_edgeSelector->addItem(name); + b_updatingUI = false; +} + +void Surface_Modelisation_DockTab::removeEdgeSelector(const QString& name) +{ + b_updatingUI = true; + int curIndex = combo_edgeSelector->currentIndex(); + int index = combo_edgeSelector->findText(name, Qt::MatchExactly); + if(curIndex == index) + combo_edgeSelector->setCurrentIndex(0); + combo_edgeSelector->removeItem(index); + b_updatingUI = false; +} + +void Surface_Modelisation_DockTab::addFaceSelector(const QString& name) +{ + b_updatingUI = true; + combo_faceSelector->addItem(name); + b_updatingUI = false; +} + +void Surface_Modelisation_DockTab::removeFaceSelector(const QString& name) +{ + b_updatingUI = true; + int curIndex = combo_faceSelector->currentIndex(); + int index = combo_faceSelector->findText(name, Qt::MatchExactly); + if(curIndex == index) + combo_faceSelector->setCurrentIndex(0); + combo_faceSelector->removeItem(index); + b_updatingUI = false; +} + void Surface_Modelisation_DockTab::updateMapParameters() { b_updatingUI = true; combo_positionAttribute->clear(); combo_positionAttribute->addItem("- select attribute -"); + combo_vertexSelector->clear(); + combo_vertexSelector->addItem("- select selector -"); + combo_edgeSelector->clear(); + combo_edgeSelector->addItem("- select selector -"); + combo_faceSelector->clear(); + combo_faceSelector->addItem("- select selector -"); MapHandlerGen* map = m_schnapps->getSelectedMap(); @@ -127,6 +199,34 @@ void Surface_Modelisation_DockTab::updateMapParameters() ++i; } } + + i = 1; + const CellSelectorSet& vertexSelectors = map->getCellSelectorSet(VERTEX); + for(CellSelectorSet::const_iterator it = vertexSelectors.constBegin(); it != vertexSelectors.constEnd(); ++it) + { + combo_vertexSelector->addItem(it.key()); + if(p.vertexSelector && it.key() == p.vertexSelector->getName()) + combo_vertexSelector->setCurrentIndex(i); + ++i; + } + i = 1; + const CellSelectorSet& edgeSelectors = map->getCellSelectorSet(EDGE); + for(CellSelectorSet::const_iterator it = edgeSelectors.constBegin(); it != edgeSelectors.constEnd(); ++it) + { + combo_edgeSelector->addItem(it.key()); + if(p.edgeSelector && it.key() == p.edgeSelector->getName()) + combo_edgeSelector->setCurrentIndex(i); + ++i; + } + i = 1; + const CellSelectorSet& faceSelectors = map->getCellSelectorSet(FACE); + for(CellSelectorSet::const_iterator it = faceSelectors.constBegin(); it != faceSelectors.constEnd(); ++it) + { + combo_faceSelector->addItem(it.key()); + if(p.faceSelector && it.key() == p.faceSelector->getName()) + combo_faceSelector->setCurrentIndex(i); + ++i; + } } b_updatingUI = false; -- GitLab