mapsDialog.cpp 3.24 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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()
{}

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())
			m_window->removeMap(name);
		else
			QMessageBox::warning(this, tr("Warning"), "Map is currently used");
	}
}

void MapsDialog::cb_selectedMapChanged()
{
	QList<QListWidgetItem*> currentItems = mapList->selectedItems();
	if(!currentItems.empty())
	{
		QListWidgetItem* current = currentItems[0];

		dartAttributes->clear();
		vertexAttributes->clear();
		edgeAttributes->clear();
		faceAttributes->clear();
		volumeAttributes->clear();

		const QString& name = current->text();
		MapHandlerGen* mh = m_window->getMap(name);
		CGoGN::GenericMap* m = mh->getGenericMap();
		for(unsigned int orbit = CGoGN::DART; orbit <= CGoGN::VOLUME; ++orbit)
		{
			if(m->isOrbitEmbedded(orbit))
			{
//				unsigned int nb = 0;
//				switch(orbit)
//				{
//					case CGoGN::DART :
//						nb = m->getNbOrbits<CGoGN::DART>();
//						break;
//					case CGoGN::VERTEX :
//						nb = m->getNbOrbits<CGoGN::VERTEX>();
//						break;
//					case CGoGN::EDGE :
//						nb = m->getNbOrbits<CGoGN::EDGE>();
//						break;
//					case CGoGN::FACE :
//						nb = m->getNbOrbits<CGoGN::FACE>();
//						break;
//					case CGoGN::VOLUME :
//						nb = m->getNbOrbits<CGoGN::VOLUME>();
//						break;
//				}

				CGoGN::AttributeContainer& cont = m->getAttributeContainer(orbit);
				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)
					{
						case CGoGN::DART : dartAttributes->addItem(name + "(" + type + ")"); break;
						case CGoGN::VERTEX : vertexAttributes->addItem(name + "(" + type + ")"); break;
						case CGoGN::EDGE : edgeAttributes->addItem(name + "(" + type + ")"); break;
						case CGoGN::FACE : faceAttributes->addItem(name + "(" + type + ")"); break;
						case CGoGN::VOLUME : volumeAttributes->addItem(name + "(" + type + ")"); break;
					}
				}

			}
		}
	}
}

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
127
128
129
130

} // namespace SCHNApps

} // namespace CGoGN