mapsDialog.cpp 4.09 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 19 20 21 22 23 24 25 26 27 28 29 30 31 32
MapsDialog::MapsDialog(Window* window) :
	QDialog(window),
	m_window(window)
{
	this->setupUi(this);
	this->setModal(false);

	connect(removeMapButton, SIGNAL(clicked()), this, SLOT(cb_removeMap()));

	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));

	connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(cb_addMapToList(MapHandlerGen*)));
	connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(cb_removeMapFromList(MapHandlerGen*)));
}

MapsDialog::~MapsDialog()
{}

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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("");
}

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

void MapsDialog::cb_selectedMapChanged()
{
69 70
	clearInfo();

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

		const QString& name = current->text();
		MapHandlerGen* mh = m_window->getMap(name);
78
		GenericMap* m = mh->getGenericMap();
Pierre Kraemer's avatar
Pierre Kraemer committed
79
		for(unsigned int orbit = DART; orbit <= VOLUME; ++orbit)
Pierre Kraemer's avatar
Pierre Kraemer committed
80
		{
81 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
			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
108 109 110 111 112 113
				case VOLUME : {
					unsigned int nb = m->getNbOrbits<VOLUME>();
					lineEdit_volume_orbits->setText(QString::number(nb));
					lineEdit_volume_cells->setText(QString::number(nbc));
					break;
				}
114 115
			}

Pierre Kraemer's avatar
Pierre Kraemer committed
116 117
			if(m->isOrbitEmbedded(orbit))
			{
118
				AttributeContainer& cont = m->getAttributeContainer(orbit);
Pierre Kraemer's avatar
Pierre Kraemer committed
119 120 121 122 123 124 125 126 127 128
				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)
					{
129 130 131 132 133
						case DART : dartAttributes->addItem(name + " (" + type + ")"); break;
						case VERTEX : vertexAttributes->addItem(name + " (" + type + ")"); 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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
					}
				}
			}
		}
	}
}

void MapsDialog::cb_addMapToList(MapHandlerGen* m)
{
	mapList->addItem(m->getName());
}

void MapsDialog::cb_removeMapFromList(MapHandlerGen* m)
{
	for(int i = 0; i < mapList->count(); ++i)
	{
		if(mapList->item(i)->text() == m->getName())
		{
			delete mapList->item(i);
			return;
		}
	}
}
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159 160

} // namespace SCHNApps

} // namespace CGoGN