mapsDialog.cpp 4.83 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
#include "dialogs/mapsDialog.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
2 3 4

#include "window.h"
#include "mapHandler.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
5

Pierre Kraemer's avatar
Pierre Kraemer committed
6 7 8
#include <QMessageBox>
#include <QMouseEvent>

Pierre Kraemer's avatar
Pierre Kraemer committed
9 10 11 12 13 14
namespace CGoGN
{

namespace SCHNApps
{

Pierre Kraemer's avatar
Pierre Kraemer committed
15 16 17 18
MapsDialog::MapsDialog(Window* window) :
	QDialog(window),
	m_window(window)
{
19
	setupUi(this);
20
//	setModal(false);
Pierre Kraemer's avatar
Pierre Kraemer committed
21

22 23
	connect(button_removeMap, SIGNAL(clicked()), this, SLOT(removeMap()));
	connect(button_refreshMapInfo, SIGNAL(clicked()), this, SLOT(selectedMapChanged()));
Pierre Kraemer's avatar
Pierre Kraemer committed
24

25 26
	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
	connect(vertexAttributes, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(toggleVBO(QListWidgetItem*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
27

28 29
	connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(addMapToList(MapHandlerGen*)));
	connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(removeMapFromList(MapHandlerGen*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34
}

MapsDialog::~MapsDialog()
{}

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
void MapsDialog::clearInfo()
{
	dartAttributes->clear();
	vertexAttributes->clear();
	edgeAttributes->clear();
	faceAttributes->clear();
	volumeAttributes->clear();
	lineEdit_dart_orbits->setText("");
	lineEdit_dart_cells->setText("");
	lineEdit_vertex_orbits->setText("");
	lineEdit_vertex_cells->setText("");
	lineEdit_edge_orbits->setText("");
	lineEdit_edge_cells->setText("");
	lineEdit_face_orbits->setText("");
	lineEdit_face_cells->setText("");
}

52
void MapsDialog::removeMap()
Pierre Kraemer's avatar
Pierre Kraemer committed
53 54 55 56 57 58 59
{
	QList<QListWidgetItem*> currentItems = mapList->selectedItems();
	if(!currentItems.empty())
	{
		const QString& name = currentItems[0]->text();
		MapHandlerGen* m = m_window->getMap(name);
		if(!m->isUsed())
60
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
61
			m_window->removeMap(name);
62
			clearInfo();
63
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
64 65 66 67 68
		else
			QMessageBox::warning(this, tr("Warning"), "Map is currently used");
	}
}

69
void MapsDialog::selectedMapChanged()
Pierre Kraemer's avatar
Pierre Kraemer committed
70
{
71 72
	clearInfo();

Pierre Kraemer's avatar
Pierre Kraemer committed
73 74 75 76 77 78 79
	QList<QListWidgetItem*> currentItems = mapList->selectedItems();
	if(!currentItems.empty())
	{
		QListWidgetItem* current = currentItems[0];

		const QString& name = current->text();
		MapHandlerGen* mh = m_window->getMap(name);
80
		GenericMap* m = mh->getGenericMap();
Pierre Kraemer's avatar
Pierre Kraemer committed
81
		for(unsigned int orbit = DART; orbit <= VOLUME; ++orbit)
Pierre Kraemer's avatar
Pierre Kraemer committed
82
		{
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
			unsigned int nbc = m->getNbCells(orbit);
			switch(orbit)
			{
				case DART : {
					unsigned int nb = m->getNbDarts();
					lineEdit_dart_orbits->setText(QString::number(nb));
					lineEdit_dart_cells->setText(QString::number(nbc));
					break;
				}
				case VERTEX : {
					unsigned int nb = m->getNbOrbits<VERTEX>();
					lineEdit_vertex_orbits->setText(QString::number(nb));
					lineEdit_vertex_cells->setText(QString::number(nbc));
					break;
				}
				case EDGE : {
					unsigned int nb = m->getNbOrbits<EDGE>();
					lineEdit_edge_orbits->setText(QString::number(nb));
					lineEdit_edge_cells->setText(QString::number(nbc));
					break;
				}
				case FACE : {
					unsigned int nb = m->getNbOrbits<FACE>();
					lineEdit_face_orbits->setText(QString::number(nb));
					lineEdit_face_cells->setText(QString::number(nbc));
					break;
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112 113 114 115
				case VOLUME : {
					unsigned int nb = m->getNbOrbits<VOLUME>();
					lineEdit_volume_orbits->setText(QString::number(nb));
					lineEdit_volume_cells->setText(QString::number(nbc));
					break;
				}
116 117
			}

Pierre Kraemer's avatar
Pierre Kraemer committed
118 119
			if(m->isOrbitEmbedded(orbit))
			{
120
				AttributeContainer& cont = m->getAttributeContainer(orbit);
Pierre Kraemer's avatar
Pierre Kraemer committed
121 122 123 124 125 126 127 128 129 130
				std::vector<std::string> names;
				std::vector<std::string> types;
				cont.getAttributesNames(names);
				cont.getAttributesTypes(types);
				for(unsigned int i = 0; i < names.size(); ++i)
				{
					QString name = QString::fromStdString(names[i]);
					QString type = QString::fromStdString(types[i]);
					switch(orbit)
					{
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
						case DART : {
							dartAttributes->addItem(name + " (" + type + ")");
						} break;
						case VERTEX : {
							QListWidgetItem* item = new QListWidgetItem(name + " (" + type + ")", vertexAttributes);
							if(mh->getVBO(name))
								item->setCheckState(Qt::Checked);
							else
								item->setCheckState(Qt::Unchecked);
						} break;
						case EDGE : {
							edgeAttributes->addItem(name + " (" + type + ")");
						} break;
						case FACE : {
							faceAttributes->addItem(name + " (" + type + ")");
						} break;
						case VOLUME : {
							volumeAttributes->addItem(name + " (" + type + ")");
						} break;
Pierre Kraemer's avatar
Pierre Kraemer committed
150 151 152 153 154 155 156
					}
				}
			}
		}
	}
}

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
void MapsDialog::toggleVBO(QListWidgetItem *item)
{
	QList<QListWidgetItem*> currentItems = mapList->selectedItems();
	if(!currentItems.empty())
	{
//		QListWidgetItem* current = currentItems[0];
//		const QString& mapName = current->text();
//		MapHandlerGen* mh = m_window->getMap(mapName);

		if(item->checkState() == Qt::Checked)
		{

		}
		else // Unchecked
		{

		}
	}
}

void MapsDialog::addMapToList(MapHandlerGen* m)
Pierre Kraemer's avatar
Pierre Kraemer committed
178 179 180 181
{
	mapList->addItem(m->getName());
}

182
void MapsDialog::removeMapFromList(MapHandlerGen* m)
Pierre Kraemer's avatar
Pierre Kraemer committed
183
{
Pierre Kraemer's avatar
Pierre Kraemer committed
184 185 186
	QList<QListWidgetItem*> items = mapList->findItems(m->getName(), Qt::MatchExactly);
	if(!items.empty())
		delete items[0];
Pierre Kraemer's avatar
Pierre Kraemer committed
187
}
Pierre Kraemer's avatar
Pierre Kraemer committed
188 189 190 191

} // namespace SCHNApps

} // namespace CGoGN