This patch adds the world map feature.
open subsurface -> file -> export HTML
this exports an html file with your dive list to a world map, when you hover a dive the date appears (I have to add more information like the air and water temperature) I fixed the continuation lines (though I think the code now is less readable) , also I used the memory buffer functions already exciting in membuffer.c

--
Regards,
Gehad Elrobey

>From 617af30ef6033ce1087268046a3bef525f7b43b0 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Thu, 27 Mar 2014 00:47:47 +0200
Subject: [PATCH] Exporting a World-Map prototype

This patch is a proof of concept for the world map exporter.
I added worldmap-save.c that writes the html to the file, I
used google maps v3 API to put the place marks on the map.

This patch is missing some functions need to be seperated and
to be able to change some options rather than just dumping
static html to the file.

I also added the save HTML action in the mainwindow user
interface, some neat interfacing is missing with the existing
File interfaces.

Also some additional dive information should appear by mouse
hovering like the air temperature and water temperature.

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
---
 qt-ui/mainwindow.cpp |  10 +++++
 qt-ui/mainwindow.h   |   1 +
 qt-ui/mainwindow.ui  |   6 +++
 subsurface.pro       |   2 +
 worldmap-save.c      | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
 worldmap-save.h      |  16 ++++++++
 6 files changed, 136 insertions(+)
 create mode 100644 worldmap-save.c
 create mode 100644 worldmap-save.h

diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index e77fa6b..85c7470 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -38,6 +38,7 @@
 #include "about.h"
 #include "printdialog.h"
 #include "divelogimportdialog.h"
+#include "worldmap-save.h"
 
 MainWindow *MainWindow::m_Instance = NULL;
 
@@ -262,6 +263,15 @@ void MainWindow::on_actionExportUDDF_triggered()
 		export_dives_uddf(filename.toUtf8(), false);
 }
 
+void MainWindow::on_actionExportHTMLworldmap_triggered()
+{
+	QFileInfo fi(system_default_filename());
+	QString filename = QFileDialog::getSaveFileName(this, tr("Export World Map"), fi.absolutePath(),
+							tr("HTML files (*.html)"));
+	if (!filename.isNull() && !filename.isEmpty())
+		export_worldmap_HTML(filename.toStdString().c_str());
+}
+
 void MainWindow::on_actionPrint_triggered()
 {
 	PrintDialog dlg(this);
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index e249398..37f6f86 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -91,6 +91,7 @@ slots:
 	void on_actionSaveAs_triggered();
 	void on_actionClose_triggered();
 	void on_actionExportUDDF_triggered();
+	void on_actionExportHTMLworldmap_triggered();
 	void on_actionPrint_triggered();
 	void on_actionPreferences_triggered();
 	void on_actionQuit_triggered();
diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui
index a933a2d..329015e 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -551,6 +551,7 @@
     <addaction name="separator"/>
     <addaction name="actionClose"/>
     <addaction name="actionExportUDDF"/>
+    <addaction name="actionExportHTMLworldmap"/>
     <addaction name="actionPrint"/>
     <addaction name="actionPreferences"/>
     <addaction name="separator"/>
@@ -681,6 +682,11 @@
     <string>Ctrl+U</string>
    </property>
   </action>
+   <action name="actionExportHTMLworldmap">
+   <property name="text">
+    <string>Export &amp;HTML</string>
+   </property>
+  </action>
   <action name="actionPrint">
    <property name="text">
     <string>&amp;Print</string>
diff --git a/subsurface.pro b/subsurface.pro
index 98f23b7..e27e235 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -27,6 +27,7 @@ HEADERS = \
 	helpers.h \
 	libdivecomputer.h \
 	planner.h \
+	worldmap-save.h \
 	pref.h \
 	profile.h \
 	qt-gui.h \
@@ -90,6 +91,7 @@ SOURCES =  \
 	parse-xml.c \
 	planner.c \
 	profile.c \
+	worldmap-save.c \
 	qt-gui.cpp \
 	qthelper.cpp \
 	qt-ui/about.cpp \
diff --git a/worldmap-save.c b/worldmap-save.c
new file mode 100644
index 0000000..9b7bb0f
--- /dev/null
+++ b/worldmap-save.c
@@ -0,0 +1,101 @@
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "dive.h"
+#include "worldmap-save.h"
+#include "membuffer.h"
+
+char* getlonlat(degrees_t lat,degrees_t lon)
+{
+	char* output = malloc(50*sizeof(char));
+	sprintf(output,"%f,%f",lat.udeg/1000000.0,(float)lon.udeg/1000000.0);
+	return output;
+}
+
+char* getdivedate(int when)
+{
+	char* output = malloc(50*sizeof(char));
+	struct tm t;
+	utc_mkdate(when, &t);
+	sprintf(output,"%04u-%02u-%02u",
+		   t.tm_year + 1900, t.tm_mon + 1, t.tm_mday);
+	return output;
+}
+
+char* getGoogleApi()
+{
+	/* google maps api auth*/
+	return "https://maps.googleapis.com/maps/api/js?key=AIzaSyDzo9PWsqYDDSddVswg_13rpD9oH_dLuoQ";;
+}
+
+void writeMarkers(struct membuffer *b)
+{
+	int i;
+	struct dive *dive;
+
+	for_each_dive(i, dive) {
+		/*export selected dives only ? */
+		char* latlng = getlonlat (dive->latitude , dive->longitude);
+		char* month  = getdivedate(dive->when);
+		put_string(b,"temp = new google.maps.Marker({position: new google.maps.LatLng(");put_string(b,latlng);
+		put_string(b,"),title: \"");put_string(b,month);put_string(b,"\"});\r\n");
+		put_string(b,"markers.push(temp);\n");
+		free(latlng);
+		free(month);
+	}
+}
+
+void insert_html_header(struct membuffer *b)
+{
+	put_string(b,"<!DOCTYPE html>\n<html>\n<head>\n<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\" />\n");
+}
+
+void insert_css(struct membuffer *b)
+{
+	put_string(b,"<style type=\"text/css\">\n\thtml { height: 100% }\n\tbody { height: 100%; margin: 0; padding: 0 }\n\t\
+#map-canvas { height: 100% }\n</style>\n");
+}
+
+void insert_javascript(struct membuffer *b)
+{
+	put_string(b,"<script type=\"text/javascript\"src=\"");
+	put_string(b,getGoogleApi());
+	put_string(b,"&sensor=false\">\n</script>\n<script type=\"text/javascript\">\nvar map;\n");
+	put_string(b,"function initialize() {\n\
+var mapOptions = {\n\tcenter: new google.maps.LatLng(0,0),\n\tzoom: 3,\n\tminZoom: 2,\n\tmapTypeId: google.maps.MapTypeId.SATELLITE,\n\t");
+	put_string(b,"rotateControl: false,\n\tstreetViewControl: false,\n\tmapTypeControl: false\n};\n");
+	put_string(b,"map = new google.maps.Map(document.getElementById(\"map-canvas\"),mapOptions);\nvar markers = new Array();\n");
+	//put dynamic markers into file
+	put_string(b,"var temp;\n");
+	writeMarkers(b);
+	put_string(b,"\nfor(var i=0;i<markers.length;i++)\n\tmarkers[i].setMap(map);\n}\n");
+	put_string(b,"google.maps.event.addDomListener(window, 'load', initialize);</script>\n");
+}
+
+void export(struct membuffer *b)
+{
+	insert_html_header(b);
+	insert_css(b);
+	insert_javascript(b);
+	put_string(b,"\t</head>\n\
+<body>\n\
+<div id=\"map-canvas\"/>\n\
+</body>\n\
+</html>");
+}
+
+void export_worldmap_HTML(const char* file_name)
+{
+	FILE *f;
+
+	struct membuffer buf = { 0 };
+	export(&buf);
+
+	f = fopen(file_name,"w+");
+	if(!f)printf("error"); /*report error*/
+
+	flush_buffer(&buf,f); /*check for writing errors? */
+	free_buffer(&buf);
+	fclose(f);
+}
diff --git a/worldmap-save.h b/worldmap-save.h
new file mode 100644
index 0000000..514f982
--- /dev/null
+++ b/worldmap-save.h
@@ -0,0 +1,16 @@
+#ifndef WORLDMAPSAVE_H
+#define WORLDMAPSAVE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void export_worldmap_HTML(const char* x);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
-- 
1.8.3.2

_______________________________________________
subsurface mailing list
subsurface@hohndel.org
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to