importSurface.cpp 1.73 KB
Newer Older
1
#include "importSurface.h"
2 3

#include "mapHandler.h"
4

5 6
#include "Algo/Import/import.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
7 8 9
#include <QFileDialog>
#include <QFileInfo>

10 11 12 13 14 15
namespace CGoGN
{

namespace SCHNApps
{

16
bool ImportSurfacePlugin::enable()
17 18
{
	importAction = new QAction("import", this);
19
	addMenuAction("Surface;Import", importAction);
20
	connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
21 22 23
	return true;
}

24
MapHandlerGen* ImportSurfacePlugin::importFromFile(const QString& fileName)
25
{
26
	QFileInfo fi(fileName);
Pierre Kraemer's avatar
Pierre Kraemer committed
27 28
	if(fi.exists())
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
29 30 31 32 33
		MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 2);
		if(mhg)
		{
			MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
			PFP2::MAP* map = mh->getMap();
Pierre Kraemer's avatar
Pierre Kraemer committed
34

35
			std::vector<std::string> attrNames;
36
			Algo::Surface::Import::importMesh<PFP2>(*map, fileName.toStdString(), attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
37

Pierre Kraemer's avatar
Pierre Kraemer committed
38
			// get vertex position attribute
39 40
			VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, VERTEX>(attrNames[0]);
			mh->registerAttribute(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
41

42
			// create position VBO
Pierre Kraemer's avatar
Pierre Kraemer committed
43
			mh->createVBO(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
44

45 46 47
			// update corresponding VBO & emit attribute update signal
			mh->notifyAttributeModification(position);

Pierre Kraemer's avatar
Pierre Kraemer committed
48 49 50
			// compute map bounding box
			mh->updateBB(position);
		}
51
		return mhg;
Pierre Kraemer's avatar
Pierre Kraemer committed
52
	}
53 54
	else
		return NULL;
55 56
}

57 58
void ImportSurfacePlugin::importFromFileDialog()
{
59 60 61 62 63 64
	QStringList fileNames = QFileDialog::getOpenFileNames(m_window, "Import surfaces", m_window->getAppPath(), "Surface mesh Files (*.ply *.off *.trian)");
	QStringList::Iterator it = fileNames.begin();
	while(it != fileNames.end()) {
		importFromFile(*it);
		++it;
	}
65 66
}

67
#ifndef DEBUG
68
Q_EXPORT_PLUGIN2(ImportSurfacePlugin, ImportSurfacePlugin)
69
#else
70
Q_EXPORT_PLUGIN2(ImportSurfacePluginD, ImportSurfacePlugin)
71
#endif
72 73 74 75

} // namespace SCHNApps

} // namespace CGoGN