Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

importMap.cpp 2.33 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
#include "import.h"


#include <QMessageBox>

ImportMap::ImportMap(){}

ImportMap::~ImportMap(){}


bool ImportMap::activate(){
	QAction* action= new QAction( m_window);
	action->setIcon(QIcon(":icon/map.png"));
	QObject::connect(action, SIGNAL(triggered()), this, SLOT(saveMap()));
	addMenuAction("Visu;Imorter une Map", action);
	addToolbarAction(action);

	waitingForScene(0);

	return true;
}

void ImportMap::disable(){}


bool ImportMap::importMap(QString filename){
	QFileInfo fileInfo(filename);
	QString extension= fileInfo.suffix();

	PFP::MAP* myMap= new PFP::MAP();

	VertexAttribute<PFP::VEC3> position;
	VertexAttribute<PFP::VEC3> normal;

	if (extension == "map")
	{
		myMap->loadMapBin(filename.toStdString());
		position = myMap->getAttribute<PFP::VEC3, VERTEX>("position") ;
	}
	else
	{
		std::vector<std::string> attrNames ;
		if(!Algo::Import::importMesh<PFP>(*myMap, filename.toStdString().c_str(), attrNames))
		{
			return false;
		}
		position = myMap->getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
		std::cout << "import map position ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>(attrNames[0]).isValid())?"yes":"no") << std::endl;
		std::cout << "import map position ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>("position").isValid())?"yes":"no") << std::endl;
	}


	normal = myMap->getAttribute<PFP::VEC3, VERTEX>("normal") ;
	if(!normal.isValid())
		normal = myMap->addAttribute<PFP::VEC3, VERTEX>("normal") ;

	Algo::Geometry::computeNormalVertices<PFP>(*myMap, position, normal) ;

	std::cout << "import map normal ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>("normal").isValid())?"yes":"no") << std::endl;

	MapHandler* vizuHandler= new MapHandler(myMap);
	if(!addReferencedMap(fileInfo.baseName()+"_map", vizuHandler)){
		System::Error::showError();

		delete vizuHandler;

		return false;
	}

//	myMap->check();

	return true;
}

void ImportMap::saveMap(){
	QString fileName= QFileDialog::getOpenFileName(m_window, System::app_path+"../files", tr("3D files (*)"));
	if(!fileName.isEmpty()){
		if(!importMap(fileName)){
			QMessageBox msg;
			msg.setText(QString::fromUtf8("Une erreur est survenue lors de la création de la carte"));
			if(System::Error::code!=System::Error::SUCCESS){
				System::Error::showError();
			}
		}
	}
}



#ifndef DEBUG
	Q_EXPORT_PLUGIN2(ImportMap, ImportMap)
#else
	Q_EXPORT_PLUGIN2(ImportMapD, ImportMap)
#endif