92 lines
2.3 KiB
C
92 lines
2.3 KiB
C
#include "controleur.h"
|
|
|
|
|
|
ErrEnum controlePoints(sfRenderWindow *window, const char *cheminFichier)
|
|
{
|
|
uint32_t nbElements;
|
|
Point *tabPoint = NULL;
|
|
|
|
// On vient lire les logs de géolocalisation
|
|
ErrEnum result = loadLogs(cheminFichier, &tabPoint, &nbElements);
|
|
if(result != LOAD_SUCCESS)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
Coordonnees pointHautGauche, pointBasDroite;
|
|
getExtrema(tabPoint, nbElements, &pointHautGauche, &pointBasDroite);
|
|
|
|
uint8_t zoom;
|
|
double echelle;
|
|
getZoomEchelle(&pointHautGauche, &pointBasDroite, &zoom, &echelle);
|
|
|
|
// Coordonnées du point au centre du rectangle fictif
|
|
Coordonnees pointCentral = {(pointHautGauche.lat + pointBasDroite.lat) / 2.0, (pointHautGauche.lon + pointBasDroite.lon) / 2.0};
|
|
|
|
if(!getBackgroundMap(&pointCentral, zoom))
|
|
{
|
|
return REQUEST_FAILURE;
|
|
}
|
|
|
|
// On convertit les points en coordonnées cartésiennes !
|
|
sfVector2f *tabPointConvertis = conversionPoints(tabPoint, nbElements, &pointCentral, echelle);
|
|
if(tabPointConvertis == NULL)
|
|
{
|
|
free(tabPoint);
|
|
tabPoint = NULL;
|
|
|
|
return ALLOCATION_FAILURE;
|
|
}
|
|
|
|
// On convertit les dates !
|
|
char **tabDateConverties = conversionDates(tabPoint, nbElements);
|
|
if(tabDateConverties == NULL)
|
|
{
|
|
free(tabPoint);
|
|
tabPoint = NULL;
|
|
|
|
free(tabPointConvertis);
|
|
tabPointConvertis = NULL;
|
|
|
|
return ALLOCATION_FAILURE;
|
|
}
|
|
|
|
sfRenderTexture *renderTexture = initialisationRenderTexture(sfRenderWindow_getSize(window).x, sfRenderWindow_getSize(window).y);
|
|
|
|
sfTexture *mapTexture = NULL;
|
|
sfSprite *mapSprite = NULL;
|
|
|
|
// On affiche la carte !
|
|
afficherCarte(renderTexture, &mapTexture, &mapSprite, MAPFILE);
|
|
|
|
sfCircleShape *tabPointeursCercle[nbElements];
|
|
|
|
// On affiche les points !
|
|
afficherPoints(renderTexture, tabPointConvertis, tabDateConverties, nbElements, tabPointeursCercle);
|
|
|
|
sfRenderTexture_display(renderTexture);
|
|
|
|
sfSprite *renderSprite = loadSpriteFromRenderTexture(renderTexture);
|
|
|
|
sfRenderWindow_drawSprite(window, renderSprite, NULL);
|
|
sfRenderWindow_display(window);
|
|
|
|
sfEvent event;
|
|
waitingForEvent(window, &event, renderSprite, false);
|
|
|
|
// On libère tous les éléments...
|
|
detruireCarte(&mapTexture, &mapSprite, MAPFILE);
|
|
|
|
detruireCercles(nbElements, tabPointeursCercle);
|
|
|
|
free(tabPoint);
|
|
tabPoint = NULL;
|
|
|
|
free(tabPointConvertis);
|
|
tabPointConvertis = NULL;
|
|
|
|
freeTabGeneric((void***)&tabDateConverties, nbElements);
|
|
|
|
return SUCCESS;
|
|
}
|