From 49d467b05a591dd8c9e36e1e28dc82e8aca20228 Mon Sep 17 00:00:00 2001 From: Zwarf Date: Sun, 21 Nov 2021 00:54:55 +0100 Subject: [PATCH] changing to GTK4 and restructuring the application --- LICENSE => COPYING | 9 +- build-aux/meson/postinstall.py | 21 + data/de.zwarf.picplanner.appdata.xml.in | 8 + data/de.zwarf.picplanner.desktop.in | 8 + data/de.zwarf.picplanner.gschema.xml | 5 + .../scalable/apps/de.zwarf.picplanner.svg | 105 ++ .../apps/de.zwarf.picplanner-symbolic.svg | 184 +++ data/icons/meson.build | 13 + data/meson.build | 43 + de.zwarf.picplanner.json | 38 + meson.build | 20 +- po/LINGUAS | 0 po/POTFILES | 7 + po/meson.build | 1 + src/calculations.h | 29 - src/calculations/calculations_milky_way.c | 17 + src/calculations/calculations_milky_way.h | 4 + src/calculations/calculations_moon.c | 42 + src/calculations/calculations_moon.h | 5 + src/calculations/calculations_sun.c | 35 + src/calculations/calculations_sun.h | 5 + .../calculations_transformations.c} | 390 ++++--- .../calculations_transformations.h | 31 + src/gtk/help-overlay.ui | 29 + src/handler.c | 446 ------- src/handler.h | 19 - src/main.c | 331 +----- src/meson.build | 24 +- src/picplanner-application.c | 135 +++ src/picplanner-application.h | 32 + src/picplanner-window.c | 47 + src/picplanner-window.h | 29 + src/picplanner-window.ui | 1039 +---------------- src/picplanner.gresource.xml | 3 +- src/plot.c | 656 ----------- src/plot.h | 44 - src/webconnection.c | 120 -- src/webconnection.h | 14 - 38 files changed, 1151 insertions(+), 2837 deletions(-) rename LICENSE => COPYING (99%) create mode 100755 build-aux/meson/postinstall.py create mode 100644 data/de.zwarf.picplanner.appdata.xml.in create mode 100644 data/de.zwarf.picplanner.desktop.in create mode 100644 data/de.zwarf.picplanner.gschema.xml create mode 100644 data/icons/hicolor/scalable/apps/de.zwarf.picplanner.svg create mode 100644 data/icons/hicolor/symbolic/apps/de.zwarf.picplanner-symbolic.svg create mode 100644 data/icons/meson.build create mode 100644 data/meson.build create mode 100644 de.zwarf.picplanner.json create mode 100644 po/LINGUAS create mode 100644 po/POTFILES create mode 100644 po/meson.build delete mode 100644 src/calculations.h create mode 100644 src/calculations/calculations_milky_way.c create mode 100644 src/calculations/calculations_milky_way.h create mode 100644 src/calculations/calculations_moon.c create mode 100644 src/calculations/calculations_moon.h create mode 100644 src/calculations/calculations_sun.c create mode 100644 src/calculations/calculations_sun.h rename src/{calculations.c => calculations/calculations_transformations.c} (53%) create mode 100644 src/calculations/calculations_transformations.h create mode 100644 src/gtk/help-overlay.ui delete mode 100644 src/handler.c delete mode 100644 src/handler.h create mode 100644 src/picplanner-application.c create mode 100644 src/picplanner-application.h create mode 100644 src/picplanner-window.c create mode 100644 src/picplanner-window.h delete mode 100644 src/plot.c delete mode 100644 src/plot.h delete mode 100644 src/webconnection.c delete mode 100644 src/webconnection.h diff --git a/LICENSE b/COPYING similarity index 99% rename from LICENSE rename to COPYING index f288702..10926e8 100644 --- a/LICENSE +++ b/COPYING @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found. GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. @@ -664,11 +664,12 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -. +. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. +. + diff --git a/build-aux/meson/postinstall.py b/build-aux/meson/postinstall.py new file mode 100755 index 0000000..6a3ea97 --- /dev/null +++ b/build-aux/meson/postinstall.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +from os import environ, path +from subprocess import call + +prefix = environ.get('MESON_INSTALL_PREFIX', '/usr/local') +datadir = path.join(prefix, 'share') +destdir = environ.get('DESTDIR', '') + +# Package managers set this so we don't need to run +if not destdir: + print('Updating icon cache...') + call(['gtk-update-icon-cache', '-qtf', path.join(datadir, 'icons', 'hicolor')]) + + print('Updating desktop database...') + call(['update-desktop-database', '-q', path.join(datadir, 'applications')]) + + print('Compiling GSettings schemas...') + call(['glib-compile-schemas', path.join(datadir, 'glib-2.0', 'schemas')]) + + diff --git a/data/de.zwarf.picplanner.appdata.xml.in b/data/de.zwarf.picplanner.appdata.xml.in new file mode 100644 index 0000000..2476463 --- /dev/null +++ b/data/de.zwarf.picplanner.appdata.xml.in @@ -0,0 +1,8 @@ + + + de.zwarf.picplanner.desktop + CC0-1.0 + GPL-3.0-or-later + + + diff --git a/data/de.zwarf.picplanner.desktop.in b/data/de.zwarf.picplanner.desktop.in new file mode 100644 index 0000000..f64a439 --- /dev/null +++ b/data/de.zwarf.picplanner.desktop.in @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=picplanner +Exec=picplanner +Icon=de.zwarf.picplanner +Terminal=false +Type=Application +Categories=GTK; +StartupNotify=true diff --git a/data/de.zwarf.picplanner.gschema.xml b/data/de.zwarf.picplanner.gschema.xml new file mode 100644 index 0000000..e27ab09 --- /dev/null +++ b/data/de.zwarf.picplanner.gschema.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/data/icons/hicolor/scalable/apps/de.zwarf.picplanner.svg b/data/icons/hicolor/scalable/apps/de.zwarf.picplanner.svg new file mode 100644 index 0000000..a244087 --- /dev/null +++ b/data/icons/hicolor/scalable/apps/de.zwarf.picplanner.svg @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/hicolor/symbolic/apps/de.zwarf.picplanner-symbolic.svg b/data/icons/hicolor/symbolic/apps/de.zwarf.picplanner-symbolic.svg new file mode 100644 index 0000000..e3c313a --- /dev/null +++ b/data/icons/hicolor/symbolic/apps/de.zwarf.picplanner-symbolic.svg @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/meson.build b/data/icons/meson.build new file mode 100644 index 0000000..8d6a2fc --- /dev/null +++ b/data/icons/meson.build @@ -0,0 +1,13 @@ +application_id = 'de.zwarf.picplanner' + +scalable_dir = join_paths('hicolor', 'scalable', 'apps') +install_data( + join_paths(scalable_dir, ('@0@.svg').format(application_id)), + install_dir: join_paths(get_option('datadir'), 'icons', scalable_dir) +) + +symbolic_dir = join_paths('hicolor', 'symbolic', 'apps') +install_data( + join_paths(symbolic_dir, ('@0@-symbolic.svg').format(application_id)), + install_dir: join_paths(get_option('datadir'), 'icons', symbolic_dir) +) diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..9895ad8 --- /dev/null +++ b/data/meson.build @@ -0,0 +1,43 @@ +desktop_file = i18n.merge_file( + input: 'de.zwarf.picplanner.desktop.in', + output: 'de.zwarf.picplanner.desktop', + type: 'desktop', + po_dir: '../po', + install: true, + install_dir: join_paths(get_option('datadir'), 'applications') +) + +desktop_utils = find_program('desktop-file-validate', required: false) +if desktop_utils.found() + test('Validate desktop file', desktop_utils, + args: [desktop_file] + ) +endif + +appstream_file = i18n.merge_file( + input: 'de.zwarf.picplanner.appdata.xml.in', + output: 'de.zwarf.picplanner.appdata.xml', + po_dir: '../po', + install: true, + install_dir: join_paths(get_option('datadir'), 'appdata') +) + +appstream_util = find_program('appstream-util', required: false) +if appstream_util.found() + test('Validate appstream file', appstream_util, + args: ['validate', appstream_file] + ) +endif + +install_data('de.zwarf.picplanner.gschema.xml', + install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas') +) + +compile_schemas = find_program('glib-compile-schemas', required: false) +if compile_schemas.found() + test('Validate schema file', compile_schemas, + args: ['--strict', '--dry-run', meson.current_source_dir()] + ) +endif + +subdir('icons') diff --git a/de.zwarf.picplanner.json b/de.zwarf.picplanner.json new file mode 100644 index 0000000..7dcccdf --- /dev/null +++ b/de.zwarf.picplanner.json @@ -0,0 +1,38 @@ +{ + "app-id" : "de.zwarf.picplanner", + "runtime" : "org.gnome.Platform", + "runtime-version" : "master", + "sdk" : "org.gnome.Sdk", + "command" : "picplanner", + "finish-args" : [ + "--share=network", + "--share=ipc", + "--socket=fallback-x11", + "--device=dri", + "--socket=wayland" + ], + "cleanup" : [ + "/include", + "/lib/pkgconfig", + "/man", + "/share/doc", + "/share/gtk-doc", + "/share/man", + "/share/pkgconfig", + "*.la", + "*.a" + ], + "modules" : [ + { + "name" : "picplanner", + "builddir" : true, + "buildsystem" : "meson", + "sources" : [ + { + "type" : "git", + "url" : "file:///home/user/Projekte/picplanner" + } + ] + } + ] +} diff --git a/meson.build b/meson.build index a8a8a9d..dc325d9 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,17 @@ -project('picplanner', 'c', version: '0.1.0', - meson_version: '>= 0.40.0', +project('picplanner', 'c', + version: '0.1.0', + meson_version: '>= 0.50.0', + default_options: [ 'warning_level=2', + 'c_std=gnu11', + ], ) -cc = meson.get_compiler('c') -math = cc.find_library('m', required: false) + +i18n = import('i18n') config_h = configuration_data() config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) +config_h.set_quoted('GETTEXT_PACKAGE', 'picplanner') +config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir'))) configure_file( output: 'picplanner-config.h', configuration: config_h, @@ -14,5 +20,9 @@ add_project_arguments([ '-I' + meson.build_root(), ], language: 'c') -subdir('src') +subdir('data') +subdir('src') +subdir('po') + +meson.add_install_script('build-aux/meson/postinstall.py') diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000..e69de29 diff --git a/po/POTFILES b/po/POTFILES new file mode 100644 index 0000000..a7d89a6 --- /dev/null +++ b/po/POTFILES @@ -0,0 +1,7 @@ +data/de.zwarf.picplanner.desktop.in +data/de.zwarf.picplanner.appdata.xml.in +data/de.zwarf.picplanner.gschema.xml +src/picplanner-window.ui +src/main.c +src/picplanner-window.c + diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 0000000..e9b5f5f --- /dev/null +++ b/po/meson.build @@ -0,0 +1 @@ +i18n.gettext('picplanner', preset: 'glib') diff --git a/src/calculations.h b/src/calculations.h deleted file mode 100644 index 7c0bf37..0000000 --- a/src/calculations.h +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -double calc_deg_rad (double deg); - -double calc_rad_deg (double rad); - -int times_to_zone (int day_utc, int hour_utc, int day_local, int hour_local); - -void time_to_utc (int *time_local, int *time_utc); - -void utc_zone_to_time (int *time_utc, int *time_local); - -int max_day_in_month (int month, int year); - -void calc_time_utc (int *time_utc); - -void calc_jd (int *time_utc, double *time_jd); - -void calc_sidereal_time(float longitude, double *time_jd, double *sidereal_time); - -void calc_coordinates_sun(double time_jd, float *coordinates_sun); - -void calc_coordinates_moon(double time_jd, float *coordinates_moon); - -void calc_convert_rotation_horizontal(float right_ascension, float declination, float latitude, double time_sidereal, float *coordinates); - - diff --git a/src/calculations/calculations_milky_way.c b/src/calculations/calculations_milky_way.c new file mode 100644 index 0000000..203e1c7 --- /dev/null +++ b/src/calculations/calculations_milky_way.c @@ -0,0 +1,17 @@ +#include "calculations_milky_way.h" + + +float +*get_coordinates_milky_way () +{ + float *coordinates = malloc (sizeof (float) * 2); + float right_ascension = 266.417; + float declination = -29.008; + /* Coordinates are nearly fixed compared to the non rotating coordinate system of the earth. + * Values taken from Wikipedia? TODO*/ + + coordinates[0] = right_ascension; + coordinates[1] = declination; + + return coordinates; +} diff --git a/src/calculations/calculations_milky_way.h b/src/calculations/calculations_milky_way.h new file mode 100644 index 0000000..65c23e4 --- /dev/null +++ b/src/calculations/calculations_milky_way.h @@ -0,0 +1,4 @@ +#include "calculations_transformations.h" + +float +*get_coordinates_milky_way (); diff --git a/src/calculations/calculations_moon.c b/src/calculations/calculations_moon.c new file mode 100644 index 0000000..8091a59 --- /dev/null +++ b/src/calculations/calculations_moon.c @@ -0,0 +1,42 @@ +#include "calculations_moon.h" + + +float +*calc_coordinates_moon (double time_jd) +{ + float *coordinates_moon = malloc(sizeof (float) * 2); + float right_ascension; + float declination; + double T; + double mean_anomaly; + double mean_longitude; /* ecliptic longitude? */ + double mean_distance; + double longitude_moon; + double latitude_moon; + double ecliptic; + + T = (time_jd-2451545.0)/36525; + + mean_longitude = 218.316 + (13.176396*36525) * T; + mean_anomaly = 134.963 + (13.064993*36525) * T; + mean_distance = 93.272 + (13.229350*36525) * T; + + longitude_moon = mean_longitude + 6.289 * sin(calc_deg_to_rad (mean_anomaly)); + latitude_moon = 5.128 * sin(calc_deg_to_rad(mean_distance)); + /*double distance_moon; + distance_moon = 385001. - 20905. * cos(calc_deg_rad(mean_anomaly)); Useful for super moon calculation?*/ + + ecliptic = calc_deg_to_rad(23.43928 + 0.01301*T); + longitude_moon = calc_deg_to_rad (longitude_moon); + latitude_moon = calc_deg_to_rad (latitude_moon); + + right_ascension = atan2(cos(ecliptic)*sin(longitude_moon)-sin(ecliptic)*tan(latitude_moon), cos(longitude_moon)); + declination = asin(cos(ecliptic)*sin(latitude_moon)+sin(ecliptic)*cos(latitude_moon)*sin(longitude_moon)); + + /* g_print("time_jd: %f, ecliptic: %f, longitude_moon: %f, latitude_moon: %f, right_ascension %f\n", time_jd, ecliptic, longitude_moon, latitude_moon, right_ascension); */ + + coordinates_moon[0] = calc_rad_to_deg (right_ascension); + coordinates_moon[1] = calc_rad_to_deg (declination); + + return coordinates_moon; +} diff --git a/src/calculations/calculations_moon.h b/src/calculations/calculations_moon.h new file mode 100644 index 0000000..1f1488d --- /dev/null +++ b/src/calculations/calculations_moon.h @@ -0,0 +1,5 @@ +#include "calculations_transformations.h" + + +float +*calc_coordinates_moon (double time_jd); diff --git a/src/calculations/calculations_sun.c b/src/calculations/calculations_sun.c new file mode 100644 index 0000000..75d07e4 --- /dev/null +++ b/src/calculations/calculations_sun.c @@ -0,0 +1,35 @@ +#include "calculations_sun.h" + +float +*calc_coordinates_sun (double time_jd) +{ + float *coordinates_sun = malloc(sizeof (float) * 2); + float right_ascension; + float declination; + double T; + double mean_longitude; + double mean_anomaly; + double equation_of_center; + double ecliptic_longitude; + double ecliptic; + + T = (time_jd-2451545.0)/36525; + mean_longitude = 280.46645 + (36000.76983 + 0.0003032*T)*T; + mean_anomaly = 357.52910 + (35999.05030 - (0.0001559 - 0.00000048*T)*T)*T; + equation_of_center = (1.914600 - (0.004817 - 0.000014*T)*T)*sin(calc_deg_to_rad (mean_anomaly)) + + (0.019993 - 0.000101*T)*sin(2*calc_deg_to_rad (mean_anomaly)) + + (0.00029)*sin(3*calc_deg_to_rad (mean_anomaly)); + ecliptic_longitude = mean_longitude + equation_of_center; + ecliptic = 23.43928 + 0.01301*T; + + ecliptic_longitude = calc_deg_to_rad (ecliptic_longitude); + ecliptic = calc_deg_to_rad (ecliptic); + + right_ascension = atan2 (cos(ecliptic)*sin(ecliptic_longitude), cos(ecliptic_longitude)); + declination = asin (sin(ecliptic)*sin(ecliptic_longitude)); + + coordinates_sun[0] = calc_rad_to_deg (right_ascension); + coordinates_sun[1] = calc_rad_to_deg (declination); + + return coordinates_sun; +} diff --git a/src/calculations/calculations_sun.h b/src/calculations/calculations_sun.h new file mode 100644 index 0000000..236cb0a --- /dev/null +++ b/src/calculations/calculations_sun.h @@ -0,0 +1,5 @@ +#include "calculations_transformations.h" + + +float +*calc_coordinates_sun (double time_jd); diff --git a/src/calculations.c b/src/calculations/calculations_transformations.c similarity index 53% rename from src/calculations.c rename to src/calculations/calculations_transformations.c index 4bacac4..4a7cea9 100644 --- a/src/calculations.c +++ b/src/calculations/calculations_transformations.c @@ -1,92 +1,28 @@ -#include +#include "calculations_transformations.h" -/* TODO - * Azimuth and Elevation are wrong in the calculation of the position of the Milky Way */ /* Convert degree to radiant */ -double calc_deg_rad (double deg) { +float +calc_deg_to_rad (float deg) +{ return M_PI/180*deg; } + + + /* Convert radiant to degree */ -double calc_rad_deg (double rad) { +float +calc_rad_to_deg (float rad) +{ return 180/M_PI*rad; } -int times_to_zone (int day_utc, int hour_utc, int day_local, int hour_local){ - int time_zone; - if (day_utc == day_local){ - time_zone = hour_local - hour_utc; - } - else{ - if (abs(day_utc-day_local)>1){ - if (day_utc < day_local){ - day_local = day_utc-1; - } - else{ - day_local = day_utc+1; - } - } - time_zone = 24*(day_local-day_utc)+(hour_local-hour_utc); - } - return time_zone; -} -void utc_zone_to_time (int *time_utc, int *time_local){ - int sign = *(time_utc+5)/abs(*(time_utc+5)); - *time_local=*time_utc; - *(time_local+1)=*(time_utc+1); - *(time_local+2)=*(time_utc+2); - *(time_local+3)=*(time_utc+3); - *(time_local+4)=*(time_utc+4); - *(time_local+5)=*(time_utc+5); - - *(time_local+3) = *(time_utc+3)+*(time_utc+5); - if (*(time_local+3)>24 || *(time_local+3) < 0){ /* Test if hours are still inside the same day */ - *(time_local+3) = (*(time_local+3)+24)%24; - *(time_local+2) = *(time_utc+2)+sign; - - if (*(time_local+2) > max_day_in_month (*(time_utc+1), *(time_utc)) || *(time_local+2) < 1){ /* Test if days are still inside the same month */ - *(time_local+2) = (*(time_local+2)-1)%max_day_in_month (*(time_utc+1)+sign, *(time_utc))+1; /* -1 and +1 necessary due to mod calculations */ - *(time_local+1) = *(time_utc+1)+sign; - - if (*(time_local+1) > 12 || *(time_local+1) < 1){ /* Test if months are still inside the same year */ - *(time_local+1) = (*(time_local+1)-1)%12+1; - *(time_local) = *(time_utc)+sign; - } - } - } -} - -void time_to_utc (int *time_local, int *time_utc){ - int sign = *(time_utc+5)/abs(*(time_utc+5)); - - *time_utc=*time_local; - *(time_utc+1)=*(time_local+1); - *(time_utc+2)=*(time_local+2); - *(time_utc+3)=*(time_local+3); - *(time_utc+4)=*(time_local+4); - *(time_local+5)=*(time_utc+5); - - *(time_utc+3) = *(time_local+3)-*(time_utc+5); - if (*(time_utc+3) > 24 || *(time_utc+3) < 0){ - *(time_utc+3) = (*(time_utc+3)+24)%24; - *(time_utc+2) = *(time_utc+2)+sign; - - if (*(time_utc+2) > max_day_in_month (*(time_local+1), *(time_local)) || *(time_utc+2) < 1){ - *(time_utc+2) = (*(time_utc+2)-1)%max_day_in_month (*(time_local+1)+sign, *(time_local))+1; - *(time_utc+1) = *(time_local+1)+sign; - - if (*(time_utc+1) > 12 || *(time_utc+1) < 1){ - *(time_utc+1) = (*(time_local+1)-1)%12+1; - *(time_utc) = *(time_local)+sign; - } - } - } -} - -int max_day_in_month (int month, int year){ +int +max_day_in_month (int month, int year) +{ int max_days = 30; /* check which month is set */ switch (month) { @@ -108,10 +44,37 @@ int max_day_in_month (int month, int year){ } -/* Get current time and date and return as a pointer to an array */ -void calc_time_utc (int *time_utc) + +int +times_to_time_zone (int day_utc, int hour_utc, int day_local, int hour_local) { - time_t t; + int time_zone; + if (day_utc == day_local){ + time_zone = hour_local - hour_utc; + } + else{ + if (abs(day_utc-day_local)>1){ + if (day_utc < day_local){ + day_local = day_utc-1; + } + else{ + day_local = day_utc+1; + } + } + time_zone = 24*(day_local-day_utc)+(hour_local-hour_utc); + } + return time_zone; +} + + + +/* Get current time and date and return as a pointer to an array */ +int +*get_time_utc () +{ + int *time_utc = malloc(sizeof (int) * 6); + int time_zone; + time_t t; struct tm tmp_local; struct tm *tmp; @@ -121,39 +84,113 @@ void calc_time_utc (int *time_utc) memcpy(&tmp_local, tmp, sizeof(struct tm)); tmp = gmtime(&t); - int time_zone = times_to_zone (tmp->tm_mday, tmp->tm_hour, tmp_local.tm_mday, tmp_local.tm_hour); + time_zone = times_to_time_zone (tmp->tm_mday, tmp->tm_hour, tmp_local.tm_mday, tmp_local.tm_hour); g_print ("UTC: %02d:%02d - %d.%d.%d, Time zone: %d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_mday, tmp->tm_mon+1, tmp->tm_year+1900, time_zone); - *(time_utc) = tmp->tm_year+1900; - *(time_utc+1) = tmp->tm_mon+1; - *(time_utc+2) = tmp->tm_mday; - *(time_utc+3) = tmp->tm_hour; - *(time_utc+4) = tmp->tm_min; - *(time_utc+5) = time_zone; + time_utc[0] = tmp->tm_year+1900; + time_utc[1] = tmp->tm_mon+1; + time_utc[2] = tmp->tm_mday; + time_utc[3] = tmp->tm_hour; + time_utc[4] = tmp->tm_min; + time_utc[5] = time_zone; + + return time_utc; } -/* Calculate the Julian Day */ -void calc_jd (int *time_utc, double *time_jd) + +int +*utc_time_to_local_time (int *time_utc) { - float year = *time_utc; - float month = *(time_utc+1); - double day = *(time_utc+2); - float hour = *(time_utc+3); - float min = *(time_utc+4); + int *time_local = malloc(sizeof(int)*6); + int sign = time_utc[5]/abs(time_utc[5]); + + for (int i = 0; i<6; i++) + { + time_local[i] = time_utc[i]; + } + + time_local[3] = time_utc[3]+time_utc[5]; + if (time_local[3] > 24 || time_local[3] < 0) + { /* Test if hours are still inside the same day */ + time_local[3] = (time_local[3] + 24) % 24; + time_local[2] = time_utc[2] + sign; + + if (time_local[2] > max_day_in_month (time_utc[1], time_utc[0]) || time_local[2] < 1) + { /* Test if days are still inside the same month */ + time_local[2] = (time_local[2]-1) % max_day_in_month (time_utc[1] + sign, time_utc[0]) + 1; /* -1 and +1 necessary due to mod calculations */ + time_local[1] = time_utc[1] + sign; + + if (time_local[1] > 12 || time_local[1] < 1) + { /* Test if months are still inside the same year */ + time_local[1] = (time_local[1]-1) % 12 + 1; + time_local[0] = time_utc[0] + sign; + } + } + } + return time_local; +} + + + +int +*local_time_to_utc_time (int *time_local) +{ + int *time_utc = malloc(sizeof(int)*6); + int sign = time_utc[5]/abs(time_utc[5]); + + for (int i = 0; i<6; i++) + { + time_utc[i] = time_local[i]; + } + + time_utc[3] = time_local[3] - time_utc[5]; + if (time_utc[3] > 24 || time_utc[3] < 0) + { + time_utc[3] = (time_utc[3] + 24) % 24; + time_utc[2] = time_utc[2] + sign; + + if (time_utc[2] > max_day_in_month (time_local[1], time_local[0]) || time_utc[2] < 1) + { + time_utc[2] = (time_utc[2] - 1) % max_day_in_month (time_local[1] + sign, time_local[0])+1; + *(time_utc+1) = *(time_local+1)+sign; + + if (time_utc[1] > 12 || time_utc[1] < 1) + { + time_utc[1] = (time_local[1] - 1) % 12 + 1; + time_utc[0] = time_local[0] + sign; + } + } + } + return time_utc; +} + + + +/* Calculate the Julian Day */ +double +calc_jd (int *time_utc) +{ + float year = time_utc[0]; + float month = time_utc[1]; + float day = time_utc[2]; + float hour = time_utc[3]; + float min = time_utc[4]; + double time_jd; /* g_print ("Minute: %f, Hour: %f, Day: %f, Month: %f, Year: %f\n",min,hour,day,month,year); */ /* calculate a float type day number which is direct proportional to the time went by */ day += (hour + min/60.)/24.; /*g_print("Day JD: %f\n", day);*/ - if (month<=2){ + if (month<=2) + { year --; month += 12; } - *time_jd = (int)(365.25*(year+4716.)) + (int)(30.6001*(month+1.)) - (int)(year/100.) + (int)(year/400.) + day + 2. - 1524.5; + time_jd = (int)(365.25*(year+4716.)) + (int)(30.6001*(month+1.)) - (int)(year/100.) + (int)(year/400.) + day + 2. - 1524.5; /* g_print ("Julian Day: %f, Day JD: %f, hour JD %f\n", *time_jd, day, hour); */ /*Explanation: @@ -187,32 +224,41 @@ void calc_jd (int *time_utc, double *time_jd) * * --> combining all of this leads to the above formula. */ + + return time_jd; } + /* Calculate the Sidereal time in degree (German: Sternzeit) */ -void calc_sidereal_time(float longitude, double *time_jd, double *sidereal_time) { - float hours_passed; - double jd_sidereal; +double +time_jd_to_sidereal_time(float longitude, double time_jd) +{ + float hours_passed; + double T; + double jd_sidereal; + double sidereal_time; /* Julian date at 0 UT at the current date */ - if (*time_jd - (int)*time_jd >= 0.5){ - jd_sidereal = (int)(*time_jd) + 0.5; + if (time_jd - (int)time_jd >= 0.5) + { + jd_sidereal = (int)(time_jd) + 0.5; } - else{ - jd_sidereal = (int)(*time_jd) - 0.5; + else + { + jd_sidereal = (int)(time_jd) - 0.5; } - hours_passed = 24*(*time_jd-jd_sidereal); + hours_passed = 24*(time_jd-jd_sidereal); /*g_print("hours_passed %f\n", hours_passed);*/ - double T = (jd_sidereal - 2451545)/36525; + T = (jd_sidereal - 2451545)/36525; /* This formular calculatest the amount of 100 years since the fundamental epoche J2000 (1.1.2000) * This formular is NOT allowed to get julian days which end on .5 (00:00), because the formular below only considers the rotation around the sun NOT its' own prcession. * So we only want to know in which "direktion" we look every day at 00:00 in Greenwich in comparison to the "fixed" stars. */ - *sidereal_time = 100.46061837 + T*(36000.770053608 + T*(0.000387933 - T/38710000.0)) + longitude + hours_passed*1.00273790935*15; - *sidereal_time = remainder(*sidereal_time, 360); + sidereal_time = 100.46061837 + T*(36000.770053608 + T*(0.000387933 - T/38710000.0)) + longitude + hours_passed*1.00273790935*15; + sidereal_time = remainder(sidereal_time, 360); /* g_print("time_jd: %f, sidereal_time %f, hours_passed: %f\n", *time_jd, *sidereal_time, hours_passed); */ @@ -236,116 +282,72 @@ void calc_sidereal_time(float longitude, double *time_jd, double *sidereal_time) * This can be explained because we can see the same star at the skye one time more often than the sun due to the earth rotating around the sun. * The precise time can not be took into account in the calculation of T as mentioned above. * It has to be multiplied by 15 to receive an angle (360/24=15).*/ + + return sidereal_time; } -void calc_coordinates_sun(double time_jd, float *coordinates_sun){ - float right_ascension; - float declination; - double T; - double mean_longitude; - double mean_anomaly; - double equation_of_center; - double ecliptic_longitude; - double ecliptic; - T = (time_jd-2451545.0)/36525; - mean_longitude = 280.46645 + (36000.76983 + 0.0003032*T)*T; - mean_anomaly = 357.52910 + (35999.05030 - (0.0001559 - 0.00000048*T)*T)*T; - equation_of_center = (1.914600 - (0.004817 - 0.000014*T)*T)*sin(calc_deg_rad (mean_anomaly)) - + (0.019993 - 0.000101*T)*sin(2*calc_deg_rad (mean_anomaly)) - + (0.00029)*sin(3*calc_deg_rad (mean_anomaly)); - ecliptic_longitude = mean_longitude + equation_of_center; - ecliptic = 23.43928 + 0.01301*T; - - ecliptic_longitude = calc_deg_rad (ecliptic_longitude); - ecliptic = calc_deg_rad (ecliptic); - - right_ascension = atan2 (cos(ecliptic)*sin(ecliptic_longitude), cos(ecliptic_longitude)); - declination = asin (sin(ecliptic)*sin(ecliptic_longitude)); - - *coordinates_sun = calc_rad_deg (right_ascension); - *(coordinates_sun+1) = calc_rad_deg (declination); -} - -void calc_coordinates_moon(double time_jd, float *coordinates_moon){ - float right_ascension; - float declination; - double T; - double mean_anomaly; - double mean_longitude; /* ecliptic longitude? */ - double mean_distance; - double longitude_moon; - double latitude_moon; - double ecliptic; - - T = (time_jd-2451545.0)/36525; - - mean_longitude = 218.316 + (13.176396*36525) * T; - mean_anomaly = 134.963 + (13.064993*36525) * T; - mean_distance = 93.272 + (13.229350*36525) * T; - - longitude_moon = mean_longitude + 6.289 * sin(calc_deg_rad (mean_anomaly)); - latitude_moon = 5.128 * sin(calc_deg_rad(mean_distance)); - /*double distance_moon; - distance_moon = 385001. - 20905. * cos(calc_deg_rad(mean_anomaly)); Useful for super moon calculation?*/ - - ecliptic = calc_deg_rad(23.43928 + 0.01301*T); - longitude_moon = calc_deg_rad (longitude_moon); - latitude_moon = calc_deg_rad (latitude_moon); - - right_ascension = atan2(cos(ecliptic)*sin(longitude_moon)-sin(ecliptic)*tan(latitude_moon), cos(longitude_moon)); - declination = asin(cos(ecliptic)*sin(latitude_moon)+sin(ecliptic)*cos(latitude_moon)*sin(longitude_moon)); - - /* g_print("time_jd: %f, ecliptic: %f, longitude_moon: %f, latitude_moon: %f, right_ascension %f\n", time_jd, ecliptic, longitude_moon, latitude_moon, right_ascension); */ - - *coordinates_moon = calc_rad_deg (right_ascension); - *(coordinates_moon+1) = calc_rad_deg (declination); -} /* Convert between the rotation coordinate system and the horizontal coordinate system */ -void calc_convert_rotation_horizontal(float right_ascension, float declination, float latitude, double time_sidereal, float *coordinates) +float +*convert_rotational_to_horizontal_coordinate_system (float *coordinates_rot, float latitude, double time_sidereal) { - latitude = calc_deg_rad (latitude); - right_ascension = calc_deg_rad (right_ascension); - declination = calc_deg_rad(declination); - time_sidereal = calc_deg_rad (time_sidereal); - + float x, y; float azimuth, elevation; - float x = -cos(latitude)*sin(declination)+sin(latitude)*cos(declination)*cos(time_sidereal-right_ascension); - float y = cos(declination)*sin(time_sidereal-right_ascension); + float right_ascension, declination; + float *coordinates_hor = malloc (sizeof (float) * 2); - if (x < 0 && y <= 0){ - azimuth = atan(y/x); + latitude = calc_deg_to_rad (latitude); + time_sidereal = calc_deg_to_rad (time_sidereal); + right_ascension = calc_deg_to_rad (coordinates_rot[0]); + declination = calc_deg_to_rad (coordinates_rot[1]); + + x = -cos (latitude) * sin (declination) + sin (latitude) * cos (declination) * cos (time_sidereal - right_ascension); + y = cos (declination) * sin (time_sidereal - right_ascension); + + if (x < 0 && y <= 0) + { + azimuth = atan (y / x); } - else if (x < 0 && y > 0){ - azimuth = atan(y/x)+2*M_PI; + else if (x < 0 && y > 0) + { + azimuth = atan (y / x) + 2 * M_PI; } - else if (x > 0){ - azimuth = atan(y/x)+M_PI; + else if (x > 0) + { + azimuth = atan (y / x) + M_PI; } - else if (x == 0 && y < 0){ - azimuth = M_PI/2; + else if (x == 0 && y < 0) + { + azimuth = M_PI / 2; } - else if (x == 0 && y > 0){ - azimuth = -3*M_PI/2; + else if (x == 0 && y > 0) + { + azimuth = -3 * M_PI / 2; } - else{ + else + { azimuth = 0; - g_print("Error calculating azimuth!"); + g_print("Error calculating azimuth!"); } - elevation = asin( sin(latitude)*sin(declination) + cos(latitude)*cos(declination)*cos(time_sidereal-right_ascension) ); + elevation = asin (sin (latitude) * sin (declination) + cos (latitude) * cos (declination) * cos (time_sidereal - right_ascension)); /* TODO * explanation missing!! * */ /* g_print("Latitude %f, RA %f, dec %f, time_sidereal %f, azimuth %f, elevation %f\n", latitude, right_ascension, declination, time_sidereal, azimuth, elevation); */ - azimuth = calc_rad_deg (azimuth); - elevation = calc_rad_deg (elevation); + azimuth = calc_rad_to_deg (azimuth); + elevation = calc_rad_to_deg (elevation); - *coordinates = azimuth; - *(coordinates+1) = elevation; + coordinates_hor [0] = azimuth; + coordinates_hor [1] = elevation; /*g_print("Azimuth: %f, Elevation: %f\n", azimuth, elevation);*/ + + return coordinates_hor; } + + + diff --git a/src/calculations/calculations_transformations.h b/src/calculations/calculations_transformations.h new file mode 100644 index 0000000..a5f80fa --- /dev/null +++ b/src/calculations/calculations_transformations.h @@ -0,0 +1,31 @@ +#include +#include +#include + + +float +calc_deg_to_rad (float deg); + +float +calc_rad_to_deg (float rad); + +int +max_day_in_month (int month, int year); + +int +times_to_time_zone (int day_utc, int hour_utc, int day_local, int hour_local); + +int +*get_time_utc (); + +int +*utc_time_to_local_time (int *time_utc); + +int +*local_time_to_utc_time (int *time_local); + +double +calc_jd (int *time_utc); + +double +time_jd_to_sidereal_time (float longitude, double time_jd); diff --git a/src/gtk/help-overlay.ui b/src/gtk/help-overlay.ui new file mode 100644 index 0000000..ef12f02 --- /dev/null +++ b/src/gtk/help-overlay.ui @@ -0,0 +1,29 @@ + + + + True + + + shortcuts + 10 + + + General + + + Show Shortcuts + win.show-help-overlay + + + + + Quit + app.quit + + + + + + + + diff --git a/src/handler.c b/src/handler.c deleted file mode 100644 index c33b81c..0000000 --- a/src/handler.c +++ /dev/null @@ -1,446 +0,0 @@ -#include - -void hand_overview (GtkBuilder *builder, float latitude, float longitude, int *time_utc){ - GtkWidget *box; - - float coordinates_milkyway[2]; - float coordinates_sun[2]; - float coordinates_moon[2]; - - box = GTK_WIDGET (gtk_builder_get_object (builder, "box_overview_plot")); - gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) gtk_widget_destroy, NULL); - - hand_milky_way (latitude, longitude, time_utc, coordinates_milkyway); - hand_sun (latitude, longitude, time_utc, coordinates_sun); - hand_moon (latitude, longitude, time_utc, coordinates_moon); - - plot_overview (box); - update_overview (coordinates_sun[0], coordinates_sun[1], coordinates_moon[0], coordinates_moon[1], coordinates_milkyway[0], coordinates_milkyway[1]); -} - -void hand_update_overview (float latitude, float longitude, int *time_utc){ - float coordinates_milkyway[2]; - float coordinates_sun[2]; - float coordinates_moon[2]; - - hand_milky_way (latitude, longitude, time_utc, coordinates_milkyway); - hand_sun (latitude, longitude, time_utc, coordinates_sun); - hand_moon (latitude, longitude, time_utc, coordinates_moon); - - update_overview (coordinates_sun[0], coordinates_sun[1], coordinates_moon[0], coordinates_moon[1], coordinates_milkyway[0], coordinates_milkyway[1]); -} - -void hand_sun(float latitude, float longitude, int *time_utc, float *coordinates_sun_horizontal){ - /* g_print("Handler Sun\n"); */ - - double time_jd_init; - double *time_jd = &time_jd_init; - - double sidereal_time; - float coordinates_sun[2]; - - calc_jd (time_utc, time_jd); - calc_coordinates_sun (*time_jd, coordinates_sun); - calc_sidereal_time(longitude, time_jd, &sidereal_time); - /*g_print("Sidereal Time: %f\n", sidereal_time);*/ - calc_convert_rotation_horizontal (*(coordinates_sun), *(coordinates_sun+1), latitude, sidereal_time, coordinates_sun_horizontal); - /* g_print("Sun: Azimuth: %f, Elevation: %f\n", coordinates_sun_horizontal[0], coordinates_sun_horizontal[1]); */ -} - -void hand_moon(float latitude, float longitude, int *time_utc, float *coordinates_moon_horizontal){ - /* g_print("Handler Moon\n"); */ - - double time_jd_init; - double *time_jd = &time_jd_init; - - double sidereal_time; - float coordinates_moon[2]; - - calc_jd (time_utc, time_jd); - calc_coordinates_moon (*time_jd, coordinates_moon); - //g_print("Coordinates moon: %f, %f, Time: %f\n", coordinates_moon[0], coordinates_moon[1], *time_jd); - - calc_sidereal_time (longitude, time_jd, &sidereal_time); - - calc_convert_rotation_horizontal (coordinates_moon[0], coordinates_moon[1], latitude, sidereal_time, coordinates_moon_horizontal); - //g_print("Moon: Azimuth: %f, Elevation: %f, time_jd: %f\n", coordinates_moon_horizontal[0], coordinates_moon_horizontal[1], *time_jd); -} - -void hand_milky_way(float latitude, float longitude, int *time_utc, float *coordinates){ - /* g_print("Handler Milky Way\n"); */ - - double time_jd_init; - double *time_jd = &time_jd_init; - - double sidereal_time; - - float ra_milky_way = 266.417; - float d_milky_way = -29.008; - - /* translate time to JD */ - calc_jd(time_utc, time_jd); - /* calculate siderial time */ - calc_sidereal_time(longitude, time_jd, &sidereal_time); - /* transfer rotating coordniate system to fixed coordniate system */ - calc_convert_rotation_horizontal(ra_milky_way, d_milky_way, latitude, sidereal_time, coordinates); - /* g_print("Milky Way: Azimuth: %f, Elevation: %f\n", coordinates[0], coordinates[1]); */ -} - -void hand_plot_sun(GtkBuilder *builder, float latitude, float longitude, int *time_utc){ - GtkWidget *box; - GtkLabel *label_time_culmination; - GtkLabel *label_elevation; - GtkLabel *label_sunrise; - GtkLabel *label_dark_night_end; - GtkLabel *label_blue_hour_morning; - GtkLabel *label_golden_hour_morning; - GtkLabel *label_sunset; - GtkLabel *label_dark_night_begin; - GtkLabel *label_blue_hour_evening; - GtkLabel *label_golden_hour_evening; - - int time_dyn[6] = {*time_utc, *(time_utc+1), *(time_utc+2), *(time_utc+3), *(time_utc+4), -*(time_utc+5)}; - int time_dyn_local[6]; - int time_max_elevation[2]={-90,0}; - int time_sunrise[2]={-1,0}; - int time_sunset[2]={-1,0}; - int time_blue_morning[2]; - int time_gold_morning_begin[2]; - int time_gold_morning_end[2]; - int time_blue_evening[2]; - int time_gold_evening_begin[2]; - int time_gold_evening_end[2]; - int time_dark_night_end[2]; - int time_dark_night_begin[2]; - - float azimuth[290], elevation[290]; - float result[2]; - float elevation_last; - float min_elevation, max_elevation; - float azimuth_max, azimuth_sunrise, azimuth_sunset; - - char c_time_culmination[16]; - char c_elevation_culmination[7]; - char c_time_sunrise[16]; - char c_time_sunset[16]; - char c_time_blue_morning[15]; - char c_time_gold_morning[15]; - char c_time_blue_evening[15]; - char c_time_gold_evening[15]; - char c_time_dark_night_end[6]; - char c_time_dark_night_begin[6]; - - for (int i = 0; i<1440; i++){ - time_dyn[3]=(int)(i/60); - time_dyn[4]=i-(int)(i/60)*60; - utc_zone_to_time (time_dyn, time_dyn_local); - - hand_sun (latitude, longitude, time_dyn_local, result); - - if (i%5==0){ - azimuth[i/5+2] = result[0]; - elevation[i/5+2] = result[1]; - } - - if (i==0){ - min_elevation = result[1]; - max_elevation = result[1]; - elevation_last = result[1]; - } - else{ - if (result[1]max_elevation){ - max_elevation = result[1]; - azimuth_max = result[0]; - time_max_elevation[0]=time_dyn[3]; - time_max_elevation[1]=time_dyn[4]; - } - if (result[1]>0 && elevation_last<0){ - azimuth_sunrise=result[0]; - time_sunrise[0]=time_dyn[3]; - time_sunrise[1]=time_dyn[4]; - } - if (result[1]<0 && elevation_last>0){ - azimuth_sunset=result[0]; - time_sunset[0]=time_dyn[3]; - time_sunset[1]=time_dyn[4]; - } - if (result[1]>-18 && elevation_last<-18){ - time_dark_night_end[0] = time_dyn[3]; - time_dark_night_end[1] = time_dyn[4]; - } - if (result[1]>-8 && elevation_last<-8){ - time_blue_morning[0] = time_dyn[3]; - time_blue_morning[1] = time_dyn[4]; - } - if (result[1]>-4 && elevation_last<-4){ - time_gold_morning_begin[0] = time_dyn[3]; - time_gold_morning_begin[1] = time_dyn[4]; - } - if (result[1]>6 && elevation_last<6){ - time_gold_morning_end[0] = time_dyn[3]; - time_gold_morning_end[1] = time_dyn[4]; - } - if (result[1]<-18 && elevation_last>-18){ - time_dark_night_begin[0] = time_dyn[3]; - time_dark_night_begin[1] = time_dyn[4]; - } - if (result[1]<-8 && elevation_last>-8){ - time_blue_evening[0] = time_dyn[3]; - time_blue_evening[1] = time_dyn[4]; - } - if (result[1]<6 && elevation_last>6){ - time_gold_evening_begin[0] = time_dyn[3]; - time_gold_evening_begin[1] = time_dyn[4]; - } - if (result[1]<-4 && elevation_last>-4){ - time_gold_evening_end[0] = time_dyn[3]; - time_gold_evening_end[1] = time_dyn[4]; - } - - elevation_last = result[1]; - } - } - /* g_print("Time max elevation: %02d:%02d, Time sunrise: %02d:%02d, Time sunset: %02d:%02d\n", - time_max_elevation[0],time_max_elevation[1],time_sunrise[0],time_sunrise[1],time_sunset[0],time_sunset[1]); */ - - - - elevation[0] = min_elevation; - elevation[1] = max_elevation; - - box = GTK_WIDGET (gtk_builder_get_object (builder, "box_sun_elevation_plot")); - label_time_culmination = GTK_LABEL (gtk_builder_get_object (builder, "sun_time_culmination")); - label_elevation = GTK_LABEL (gtk_builder_get_object (builder, "sun_elevation")); - label_sunrise = GTK_LABEL (gtk_builder_get_object (builder, "sunrise")); - label_dark_night_end = GTK_LABEL (gtk_builder_get_object (builder, "dark_night_end")); - label_blue_hour_morning = GTK_LABEL (gtk_builder_get_object (builder, "morning_bh")); - label_golden_hour_morning = GTK_LABEL (gtk_builder_get_object (builder, "morning_gh")); - label_sunset = GTK_LABEL (gtk_builder_get_object (builder, "sunset")); - label_dark_night_begin = GTK_LABEL (gtk_builder_get_object (builder, "dark_night_begin")); - label_blue_hour_evening = GTK_LABEL (gtk_builder_get_object (builder, "evening_bh")); - label_golden_hour_evening = GTK_LABEL (gtk_builder_get_object (builder, "evening_gh")); - - gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) gtk_widget_destroy, NULL); - plot_elevation_sun (elevation, box); - course_sun_overview (azimuth, elevation); - - sprintf (c_time_culmination, "%02d:%02d (@ %.1f\u00B0)", time_max_elevation[0], time_max_elevation[1], azimuth_max); - gtk_label_set_text (label_time_culmination, c_time_culmination); - - sprintf (c_elevation_culmination, "%.1f\u00B0", max_elevation); - gtk_label_set_text (label_elevation, c_elevation_culmination); - - sprintf (c_time_sunrise, "%02d:%02d (@ %.1f\u00B0)", time_sunrise[0], time_sunrise[1], azimuth_sunrise); - gtk_label_set_text (label_sunrise, c_time_sunrise); - - sprintf (c_time_sunset, "%02d:%02d (@ %.1f\u00B0)", time_sunset[0], time_sunset[1], azimuth_sunset); - gtk_label_set_text (label_sunset, c_time_sunset); - - sprintf (c_time_blue_morning, "%02d:%02d - %02d:%02d", - time_blue_morning[0],time_blue_morning[1], time_gold_morning_begin[0],time_gold_morning_begin[1]); - gtk_label_set_text (label_blue_hour_morning, c_time_blue_morning); - - sprintf (c_time_gold_morning, "%02d:%02d - %02d:%02d", - time_gold_morning_begin[0],time_gold_morning_begin[1],time_gold_morning_end[0],time_gold_morning_end[1]); - gtk_label_set_text (label_golden_hour_morning, c_time_gold_morning); - - sprintf (c_time_dark_night_end, "%02d:%02d", time_dark_night_end[0], time_dark_night_end[1]); - gtk_label_set_text (label_dark_night_end, c_time_dark_night_end); - - sprintf (c_time_blue_evening, "%02d:%02d - %02d:%02d", - time_gold_evening_end[0],time_gold_evening_end[1], time_blue_evening[0],time_blue_evening[1]); - gtk_label_set_text (label_blue_hour_evening, c_time_blue_evening); - - sprintf (c_time_gold_evening, "%02d:%02d - %02d:%02d", - time_gold_evening_begin[0],time_gold_evening_begin[1],time_gold_evening_end[0],time_gold_evening_end[1]); - gtk_label_set_text (label_golden_hour_evening, c_time_gold_evening); - - sprintf (c_time_dark_night_begin, "%02d:%02d", time_dark_night_begin[0], time_dark_night_begin[1]); - gtk_label_set_text (label_dark_night_begin, c_time_dark_night_begin); -} - -void hand_plot_moon(GtkBuilder *builder, float latitude, float longitude, int *time_utc){ - GtkWidget *box; - int time_dyn[6] = {*time_utc, *(time_utc+1), *(time_utc+2), *(time_utc+3), *(time_utc+4), -*(time_utc+5)}; - int time_dyn_local[6]; - float azimuth[290], elevation[290]; - float result[2]; - float min_elevation, max_elevation; - float elevation_last; - float azimuth_max; - int time_max_elevation[2]; - float azimuth_rise; - float azimuth_set; - int time_rise[2]; - int time_set[2]; - - char c_time_culmination[16]; - char c_elevation[7]; - char c_time_rise[16]; - char c_time_set[16]; - - GtkLabel *label_time_culmination; - GtkLabel *label_elevation; - GtkLabel *label_rise; - GtkLabel *label_set; - - for (int i = 0; i<1440; i++){ - *(time_dyn+3)=(int)(i/60); - *(time_dyn+4)=i-(int)(i/60)*60; - utc_zone_to_time (time_dyn, time_dyn_local); - - hand_moon (latitude, longitude, time_dyn_local, result); - - if (i%5==0){ - azimuth[i/5+2] = result[0]; - elevation[i/5+2] = result[1]; - } - - if (i==0){ - min_elevation = result[1]; - max_elevation = result[1]; - } - else{ - if (result[1]max_elevation){ - max_elevation = result[1]; - azimuth_max = result[0]; - time_max_elevation[0]=time_dyn[3]; - time_max_elevation[1]=time_dyn[4]; - } - if (result[1]>0 && elevation_last<0){ - azimuth_rise=result[0]; - time_rise[0]=time_dyn[3]; - time_rise[1]=time_dyn[4]; - } - if (result[1]<0 && elevation_last>0){ - azimuth_set=result[0]; - time_set[0]=time_dyn[3]; - time_set[1]=time_dyn[4]; - } - } - elevation_last = result[1]; - } - - elevation[0] = min_elevation; - elevation[1] = max_elevation; - - box = GTK_WIDGET (gtk_builder_get_object(builder, "box_moon_elevation_plot")); - gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) gtk_widget_destroy, NULL); - plot_elevation_moon (elevation, box); - course_moon_overview (azimuth, elevation); - - label_rise = GTK_LABEL (gtk_builder_get_object (builder, "moon_rise")); - label_set = GTK_LABEL (gtk_builder_get_object (builder, "moon_set")); - label_time_culmination = GTK_LABEL (gtk_builder_get_object (builder, "moon_time_culmination")); - label_elevation = GTK_LABEL (gtk_builder_get_object (builder, "moon_elevation")); - - sprintf (c_time_culmination, "%02d:%02d (@%.1f\u00B0)", time_max_elevation[0], time_max_elevation[1], azimuth_max); - gtk_label_set_text (label_time_culmination, c_time_culmination); - - sprintf (c_elevation, "%.1f\u00B0", max_elevation); - gtk_label_set_text (label_elevation, c_elevation); - - sprintf (c_time_rise, "%02d:%02d (@ %.1f\u00B0)", time_rise[0], time_rise[1], azimuth_rise); - gtk_label_set_text (label_rise, c_time_rise); - - sprintf (c_time_set, "%02d:%02d (@ %.1f\u00B0)", time_set[0], time_set[1], azimuth_set); - gtk_label_set_text (label_set, c_time_set); -} - - -void hand_plot_mw(GtkBuilder *builder, float latitude, float longitude, int *time_utc){ - GtkWidget *box; - int time_dyn[6] = {*time_utc, *(time_utc+1), *(time_utc+2), *(time_utc+3), *(time_utc+4), -*(time_utc+5)}; - int time_dyn_local[6]; - float azimuth[290], elevation[290]; - float result[2]; - float min_elevation, max_elevation; - float elevation_last; - float azimuth_max; - int time_max_elevation[2]; - float azimuth_rise; - float azimuth_set; - int time_rise[2]; - int time_set[2]; - - char c_time_culmination[16]; - char c_elevation[7]; - char c_time_rise[16]; - char c_time_set[16]; - - GtkLabel *label_time_culmination; - GtkLabel *label_elevation; - GtkLabel *label_rise; - GtkLabel *label_set; - - for (int i = 0; i<1440; i++){ - *(time_dyn+3)=(int)(i/60); - *(time_dyn+4)=i-(int)(i/60)*60; - utc_zone_to_time (time_dyn, time_dyn_local); - - hand_milky_way (latitude, longitude, time_dyn_local, result); - - if (i%5==0){ - azimuth[i/5+2] = result[0]; - elevation[i/5+2] = result[1]; - } - - if (i==0){ - min_elevation = result[1]; - max_elevation = result[1]; - } - else{ - if (result[1]max_elevation){ - max_elevation = result[1]; - azimuth_max = result[0]; - time_max_elevation[0]=time_dyn[3]; - time_max_elevation[1]=time_dyn[4]; - } - if (result[1]>0 && elevation_last<0){ - azimuth_rise=result[0]; - time_rise[0]=time_dyn[3]; - time_rise[1]=time_dyn[4]; - } - if (result[1]<0 && elevation_last>0){ - azimuth_set=result[0]; - time_set[0]=time_dyn[3]; - time_set[1]=time_dyn[4]; - } - } - elevation_last = result[1]; - } - - elevation[0] = min_elevation; - elevation[1] = max_elevation; - - box = GTK_WIDGET (gtk_builder_get_object(builder, "box_mw_elevation_plot")); - gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) gtk_widget_destroy, NULL); - plot_elevation_mw (elevation, box); - course_mw_overview (azimuth, elevation); - - label_rise = GTK_LABEL (gtk_builder_get_object (builder, "mw_rise")); - label_set = GTK_LABEL (gtk_builder_get_object (builder, "mw_set")); - label_time_culmination = GTK_LABEL (gtk_builder_get_object (builder, "mw_time_culmination")); - label_elevation = GTK_LABEL (gtk_builder_get_object (builder, "mw_elevation")); - - sprintf (c_time_culmination, "%02d:%02d (@%.1f\u00B0)", time_max_elevation[0], time_max_elevation[1], azimuth_max); - gtk_label_set_text (label_time_culmination, c_time_culmination); - - sprintf (c_elevation, "%.1f\u00B0", max_elevation); - gtk_label_set_text (label_elevation, c_elevation); - - sprintf (c_time_rise, "%02d:%02d (@ %.1f\u00B0)", time_rise[0], time_rise[1], azimuth_rise); - gtk_label_set_text (label_rise, c_time_rise); - - sprintf (c_time_set, "%02d:%02d (@ %.1f\u00B0)", time_set[0], time_set[1], azimuth_set); - gtk_label_set_text (label_set, c_time_set); -} diff --git a/src/handler.h b/src/handler.h deleted file mode 100644 index 58616f1..0000000 --- a/src/handler.h +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include - -void hand_overview (GtkBuilder *builder, float latitude, float longitude, int *time_utc); - -void hand_update_overview (float latitude, float longitude, int *time_utc); - -void hand_sun(float latitude, float longitude, int *time_utc, float *coordinates_sun_horizontal); - -void hand_moon(float latitude, float longitude, int *time_utc, float *coordinates_moon_horizontal); - -void hand_milky_way(float latitude, float longitude, int *time_utc, float *coordinates); - -void hand_plot_sun(GtkBuilder *builder, float latitude, float longitude, int *time_utc); - -void hand_plot_moon(GtkBuilder *builder, float latitude, float longitude, int *time_utc); - -void hand_plot_mw(GtkBuilder *builder, float latitude, float longitude, int *time_utc); diff --git a/src/main.c b/src/main.c index fe36525..5ec28ed 100644 --- a/src/main.c +++ b/src/main.c @@ -1,293 +1,58 @@ -#include /* libgtk-3-dev */ -#define HANDY_USE_UNSTABLE_API -#include +/* main.c + * + * Copyright 2021 user + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -#include -#include -#include -#include +#include -/* TODO - * Clock should show allways TWO digits - * Make everything translatable - * Timezone does not change when selecting a date in summer time for example */ +#include "picplanner-config.h" +#include "picplanner-application.h" -GtkWidget *window; -GtkWidget *button_search; -GtkWidget *button_now; -GtkWidget *button_calculate; -GtkWidget *label_heading; -GtkWidget *box_scale; -GtkWidget *scale_button; +#include "calculations/calculations_transformations.h" -GtkEntry *north_entry; -GtkEntry *east_entry; -GtkEntry *location_entry; - -GtkSearchEntry *searchentry; - -GtkSpinButton *entry_min; -GtkSpinButton *entry_hour; -GtkSpinButton *entry_day; -GtkSpinButton *entry_year; - -GtkComboBox *entry_month; - -GtkBuilder *builder; - -HdySqueezer *squeezer; -HdyViewSwitcher *view_switcher; -HdyViewSwitcherBar *switcher_bar; - -int time_utc[6]; -float latitude; -float longitude; -gboolean plotted = FALSE; - -/* Button Search */ -static int search(GtkWidget *widget, gpointer data) +int +main (int argc, + char *argv[]) { - char east_text[10]; - char north_text[10]; + g_autoptr(PicplannerApplication) app = NULL; + int ret; - double east; - double north; + /* Set up gettext translations */ + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); - const char *displayText; - const char *const_east_text; - const char *const_north_text; + /* + * Create a new GtkApplication. The application manages our main loop, + * application windows, integration with the window manager/compositor, and + * desktop features such as file opening and single-instance applications. + */ + app = picplanner_application_new ("de.zwarf.picplanner", G_APPLICATION_FLAGS_NONE); - const gchar *searchtext; + /* + * Run the application. This function will block until the application + * exits. Upon return, we have our exit code to return to the shell. (This + * is the code you see when you do `echo $?` after running a command in a + * terminal. + * + * Since GtkApplication inherits from GApplication, we use the parent class + * method "run". But we need to cast, which is what the "G_APPLICATION()" + * macro does. + */ + ret = g_application_run (G_APPLICATION (app), argc, argv); - /* Get the Text from the GtkSearchEntry field */ - searchtext = gtk_entry_get_text(GTK_ENTRY(searchentry)); - - if (strlen(searchtext)<1) - { - /* Do not search if search entry is emty */ - return 0; - } - g_print("Location to search for: %s\n", searchtext); - - /* Use webconnection.c with curl to serach at nominatim for a result */ - struct Output *search_result = search_nominatim (searchtext); - - east = search_result->east; - north = search_result->north; - displayText = search_result->displayText; - - g_print("Output of Search: %s, North: %f, East: %f\n",displayText, east, north); - - sprintf(east_text, "%f", east); - const_east_text = east_text; - gtk_entry_set_text(east_entry, const_east_text); - - sprintf(north_text, "%f", north); - const_north_text = north_text; - gtk_entry_set_text(north_entry, const_north_text); - - gtk_entry_set_text(location_entry, displayText); - - /* Inform the user if there is no search result available */ - if (displayText == NULL){gtk_entry_set_text(location_entry, "No result found or no connection to server!");} - else { gtk_window_set_focus (GTK_WINDOW(window), button_calculate);} - - return 1; + return ret; } - -static int correct_time (GtkWidget *widget, gpointer data){ - /* This function is used to choose the correct maximum available days at a spesific year and month - * For example: January 2020 has 31 days max February 2020 has 29 but February 2019 had only 28 - * It should not be possible to choose a day that does not exist */ - - double entry_day_double; - const char *entry_month_string; - double entry_year_double; - - entry_day_double = gtk_spin_button_get_value (entry_day); - entry_month_string = gtk_combo_box_get_active_id (entry_month); - entry_year_double = gtk_spin_button_get_value (entry_year); - - int max_days = max_day_in_month (atoi(entry_month_string), (int)entry_year_double); - - /* adjust the max. day that can be set */ - GtkAdjustment *d_adjust; - d_adjust = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "d_adjustment")); - gtk_adjustment_set_upper (d_adjust, max_days); - - /* if the day has already been set to a day higher than the highest possible day in this month set it to the max. possible day */ - if (entry_day_double>max_days) { - gtk_spin_button_set_value (entry_day, max_days); - } - - g_print("Day entry: %d\n", (int)entry_day_double); - g_print("Month entry: %i\n", atoi(entry_month_string)); - g_print("Max days: %i\n", max_days); - return 1; -} - -static int set_time_now (GtkWidget *widget, gpointer data){ - g_print("Now\n"); - int time_utc_now[6]; - int time_local[6]; - calc_time_utc (time_utc_now); - utc_zone_to_time (time_utc_now, time_local); - gtk_spin_button_set_value (entry_year, *(time_local)); - gtk_combo_box_set_active (entry_month, *(time_local+1)-1); - gtk_spin_button_set_value (entry_day, *(time_local+2)); - gtk_spin_button_set_value (entry_hour, *(time_local+3)); - gtk_spin_button_set_value (entry_min, *(time_local+4)); - return 1; -} - -/* Button calculate */ -static int calculate (GtkWidget *widget, gpointer data) -{ - int year; - int month; - int day; - int hour; - int min; - - const char *north_entry_string; - const char *east_entry_string; - - north_entry_string = gtk_entry_get_text (north_entry); - east_entry_string = gtk_entry_get_text (east_entry); - if (strlen(north_entry_string)<1 || strlen(east_entry_string)<1) - { - /* Do not search if coordinates are entry */ - return 0; - } - latitude = atof(north_entry_string); - longitude = atof(east_entry_string); - - year = gtk_spin_button_get_value_as_int (entry_year); - month = gtk_combo_box_get_active (entry_month)+1; - day = gtk_spin_button_get_value_as_int (entry_day); - hour = gtk_spin_button_get_value_as_int (entry_hour); - min = gtk_spin_button_get_value_as_int (entry_min); - - int time_local[6]; - - *(time_local) = year; - *(time_local+1) = month; - *(time_local+2) = day; - *(time_local+3) = hour; - *(time_local+4) = min; - - time_to_utc (time_local, time_utc); - - hand_overview (builder, latitude, longitude, time_utc); - hand_plot_mw (builder, latitude, longitude, time_utc); - hand_plot_sun (builder, latitude, longitude, time_utc); - hand_plot_moon (builder, latitude, longitude, time_utc); - - plotted = TRUE; - return 1; -} - -static int adjust_time (GtkWidget *widget, gpointer data){ - if (plotted){ - int hour = gtk_spin_button_get_value_as_int (entry_hour); - int min = gtk_spin_button_get_value_as_int (entry_min); - - int time_local[6]; - - utc_zone_to_time (time_utc, time_local); - - *(time_local+3) = hour; - *(time_local+4) = min; - - time_to_utc (time_local, time_utc); - - hand_update_overview (latitude, longitude, time_utc); - } - return 1; -} - -void scale_button_changed (GtkRange *range, GtkScrollType scroll, double value, gpointer user_data){ - if (plotted){ - plot_adjust_teta(G_PI/180*value); - } -} - - -static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) -{ - g_print ("delete event occured\n"); - return FALSE; -} -static void destroy( GtkWidget *widget, gpointer data ) -{ - gtk_main_quit (); -} -void hdy_size_config( GtkWidget *widget, gpointer data) -{ - /* Change the style of the window dependent on the resolution of the window. - * This is necessarry for mobile phones like the Librem 5 or the Pinephone. */ - int switch_size = 500; - hdy_view_switcher_bar_set_reveal (switcher_bar, gtk_widget_get_allocated_width (window)switch_size); - gtk_widget_set_visible (GTK_WIDGET(label_heading), gtk_widget_get_allocated_width (window)= 3.22.20'), - dependency('libhandy-1', version: '>= 0.0.9'), - dependency('libcurl'), - dependency('json-c'), - math + dependency('gtk4'), + meson.get_compiler('c').find_library('m', required: false), ] gnome = import('gnome') -picplanner_sources += gnome.compile_resources('picplanner-resources','picplanner.gresource.xml',c_name: 'picplanner') +picplanner_sources += gnome.compile_resources('picplanner-resources', + 'picplanner.gresource.xml', + c_name: 'picplanner' +) executable('picplanner', picplanner_sources, dependencies: picplanner_deps, diff --git a/src/picplanner-application.c b/src/picplanner-application.c new file mode 100644 index 0000000..3aa5bf3 --- /dev/null +++ b/src/picplanner-application.c @@ -0,0 +1,135 @@ +/* picplanner-application.c + * + * Copyright 2021 user + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "picplanner-application.h" +#include "picplanner-window.h" + +struct _PicplannerApplication +{ + GtkApplication parent_instance; +}; + +G_DEFINE_TYPE (PicplannerApplication, picplanner_application, GTK_TYPE_APPLICATION) + +PicplannerApplication * +picplanner_application_new (gchar *application_id, + GApplicationFlags flags) +{ + return g_object_new (PICPLANNER_TYPE_APPLICATION, + "application-id", application_id, + "flags", flags, + NULL); +} + +static void +picplanner_application_finalize (GObject *object) +{ + PicplannerApplication *self = (PicplannerApplication *)object; + + G_OBJECT_CLASS (picplanner_application_parent_class)->finalize (object); +} + +static void +picplanner_application_activate (GApplication *app) +{ + GtkWindow *window; + + /* It's good practice to check your parameters at the beginning of the + * function. It helps catch errors early and in development instead of + * by your users. + */ + g_assert (GTK_IS_APPLICATION (app)); + + /* Get the current window or create one if necessary. */ + window = gtk_application_get_active_window (GTK_APPLICATION (app)); + if (window == NULL) + window = g_object_new (PICPLANNER_TYPE_WINDOW, + "application", app, + "default-width", 600, + "default-height", 300, + NULL); + + /* Ask the window manager/compositor to present the window. */ + gtk_window_present (window); +} + + +static void +picplanner_application_class_init (PicplannerApplicationClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GApplicationClass *app_class = G_APPLICATION_CLASS (klass); + + object_class->finalize = picplanner_application_finalize; + + /* + * We connect to the activate callback to create a window when the application + * has been launched. Additionally, this callback notifies us when the user + * tries to launch a "second instance" of the application. When they try + * to do that, we'll just present any existing window. + */ + app_class->activate = picplanner_application_activate; +} + +static void +picplanner_application_show_about (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + PicplannerApplication *self = PICPLANNER_APPLICATION (user_data); + GtkWindow *window = NULL; + const gchar *authors[] = {"Zwarf", NULL}; + + g_return_if_fail (PICPLANNER_IS_APPLICATION (self)); + + window = gtk_application_get_active_window (GTK_APPLICATION (self)); + + gtk_show_about_dialog (window, + "program-name", "PicPlanner", + "authors", authors, + "version", "0.1.0", + NULL); +} + +static void +picplanner_application_show_preferences (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + +} + + +static void +picplanner_application_init (PicplannerApplication *self) +{ + GSimpleAction *quit_action = g_simple_action_new ("quit", NULL); + g_signal_connect_swapped (quit_action, "activate", G_CALLBACK (g_application_quit), self); + g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (quit_action)); + + GSimpleAction *about_action = g_simple_action_new ("about", NULL); + g_signal_connect (about_action, "activate", G_CALLBACK (picplanner_application_show_about), self); + g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (about_action)); + + GSimpleAction *preferences_action = g_simple_action_new ("preferences", NULL); + g_signal_connect (preferences_action, "activate", G_CALLBACK (picplanner_application_show_preferences), self); + g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (preferences_action)); + + const char *accels[] = {"q", NULL}; + gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.quit", accels); +} diff --git a/src/picplanner-application.h b/src/picplanner-application.h new file mode 100644 index 0000000..0e3e99f --- /dev/null +++ b/src/picplanner-application.h @@ -0,0 +1,32 @@ +/* picplanner-application.h + * + * Copyright 2021 user + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define PICPLANNER_TYPE_APPLICATION (picplanner_application_get_type()) + +G_DECLARE_FINAL_TYPE (PicplannerApplication, picplanner_application, PICPLANNER, APPLICATION, GtkApplication) + +PicplannerApplication *picplanner_application_new (gchar *application_id, + GApplicationFlags flags); + +G_END_DECLS diff --git a/src/picplanner-window.c b/src/picplanner-window.c new file mode 100644 index 0000000..f1fb324 --- /dev/null +++ b/src/picplanner-window.c @@ -0,0 +1,47 @@ +/* picplanner-window.c + * + * Copyright 2021 user + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "picplanner-config.h" +#include "picplanner-window.h" + +struct _PicplannerWindow +{ + GtkApplicationWindow parent_instance; + + /* Template widgets */ + GtkHeaderBar *header_bar; + GtkLabel *label; +}; + +G_DEFINE_TYPE (PicplannerWindow, picplanner_window, GTK_TYPE_APPLICATION_WINDOW) + +static void +picplanner_window_class_init (PicplannerWindowClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/de/zwarf/picplanner/picplanner-window.ui"); + gtk_widget_class_bind_template_child (widget_class, PicplannerWindow, header_bar); + gtk_widget_class_bind_template_child (widget_class, PicplannerWindow, label); +} + +static void +picplanner_window_init (PicplannerWindow *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} diff --git a/src/picplanner-window.h b/src/picplanner-window.h new file mode 100644 index 0000000..ab25f8c --- /dev/null +++ b/src/picplanner-window.h @@ -0,0 +1,29 @@ +/* picplanner-window.h + * + * Copyright 2021 user + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define PICPLANNER_TYPE_WINDOW (picplanner_window_get_type()) + +G_DECLARE_FINAL_TYPE (PicplannerWindow, picplanner_window, PICPLANNER, WINDOW, GtkApplicationWindow) + +G_END_DECLS diff --git a/src/picplanner-window.ui b/src/picplanner-window.ui index 9a60dcf..9241afc 100644 --- a/src/picplanner-window.ui +++ b/src/picplanner-window.ui @@ -1,1022 +1,39 @@ - - - - 1 - 31 - 1 - 10 - - - 23 - 1 - 10 - - - 59 - 1 - 10 - - - 2000 - 2200 - 1 - 10 - - - - False - GTK_WINDOW_TOPLEVEL - True - center-on-parent + + + +
+ + _Preferences + app.preferences + + + _About PicPlanner + app.about + +
+
diff --git a/src/picplanner.gresource.xml b/src/picplanner.gresource.xml index 54b5bc4..554c565 100644 --- a/src/picplanner.gresource.xml +++ b/src/picplanner.gresource.xml @@ -1,6 +1,7 @@ - + picplanner-window.ui + gtk/help-overlay.ui diff --git a/src/plot.c b/src/plot.c deleted file mode 100644 index 657624f..0000000 --- a/src/plot.c +++ /dev/null @@ -1,656 +0,0 @@ -#include - -GtkWidget *da_overview; - -float coordinate_system_settings[5]; -float teta; - -float sun_x, sun_y, sun_z; -float moon_x, moon_y, moon_z; -float mw_x, mw_y, mw_z; - -float array_sun_x[288], array_sun_y[288], array_sun_z[288]; -float array_moon_x[288], array_moon_y[288], array_moon_z[288]; -float array_mw_x[288], array_mw_y[288], array_mw_z[288]; - -void plot_set_basic_coordinate_system_settings (void){ - coordinate_system_settings[0] = -G_PI*3/5; - coordinate_system_settings[1] = -G_PI*2/5; - coordinate_system_settings[2] = 1; - coordinate_system_settings[3] = 1; - coordinate_system_settings[4] = 1.5; -} - -void plot_adjust_teta (float value){ - teta = -value; - gtk_widget_queue_draw (da_overview); -} - -void plot_adjust_coordinate_system_settings (double s0, double s1, double s2, double s3, double s4){ - coordinate_system_settings[0] = s0; - coordinate_system_settings[1] = s1; - coordinate_system_settings[2] = s2; - coordinate_system_settings[3] = s3; - coordinate_system_settings[4] = s4; -} - -double plot_calc_coordinate_x (double a1, double a2) { - float alpha, beta; - double x,a1_new, a2_new; - - if (!coordinate_system_settings[0]){ - plot_set_basic_coordinate_system_settings(); - } - - alpha = *coordinate_system_settings+G_PI; - beta = *(coordinate_system_settings+1); - a1_new = cos(teta)*a1 - sin(teta)*a2; - a2_new = sin(teta)*a1 + cos(teta)*a2; - a1_new *= coordinate_system_settings[2]; - a2_new *= coordinate_system_settings[3]; - x = (sin(alpha)*a1_new-sin(beta)*a2_new)/(cos(beta)*sin(alpha)-sin(beta)*cos(alpha)); - return x; -} - -double plot_calc_coordinate_y (double a1, double a2, double a3) { - float alpha, beta; - double y, a1_new, a2_new; - - if (!coordinate_system_settings[0]){ - plot_set_basic_coordinate_system_settings(); - } - - alpha = *coordinate_system_settings+G_PI; - beta = *(coordinate_system_settings+1); - a1_new = cos(teta)*a1 - sin(teta)*a2; - a2_new = sin(teta)*a1 + cos(teta)*a2; - a1_new *= coordinate_system_settings[2]; - a2_new *= coordinate_system_settings[3]; - a3 *= coordinate_system_settings[4]; - y = (-cos(alpha)*a1_new+cos(beta)*a2_new)/(cos(beta)*sin(alpha)-sin(beta)*cos(alpha)) + a3; - return y; -} - -void plot_line_to (cairo_t *cr, double a1, double a2, double a3){ - cairo_line_to (cr, plot_calc_coordinate_x (a1, a2), plot_calc_coordinate_y (a1, a2, a3)); -} - -void plot_move_to (cairo_t *cr, double a1, double a2, double a3) { - cairo_move_to (cr, plot_calc_coordinate_x (a1, a2), plot_calc_coordinate_y (a1, a2, a3)); -} - -void plot_vector_to (cairo_t *cr, double a1, double a2, double a3) { - double current_x = 0; - double current_y = 0; - double *x_1 = ¤t_x; - double *y_1 = ¤t_y; - double x_2 = plot_calc_coordinate_x (a1, a2); - double y_2 = plot_calc_coordinate_y (a1, a2, a3); - - cairo_get_current_point (cr, x_1, y_1); - double direct_x = x_2-*x_1; - double direct_y = y_2-*y_1; - double norm = pow(pow(direct_x,2) + pow(direct_y,2), 0.5); - direct_x /= norm; - direct_y /= norm; - /*g_print("direct_x: %f, direct_y: %f\n", direct_x, direct_y);*/ - - float gamma = 0.5326; - cairo_line_to (cr, x_2, y_2); - cairo_move_to (cr, x_2+(-direct_x*cos(gamma)+direct_y*sin(gamma))*0.2, y_2+(-direct_y*cos(gamma)-direct_x*sin(gamma))*0.2); - cairo_line_to (cr, x_2, y_2); - cairo_line_to (cr, x_2+(-direct_x*cos(gamma)-direct_y*sin(gamma))*0.2, y_2+(-direct_y*cos(gamma)+direct_x*sin(gamma))*0.2); - -} - -double plot_rotate_coordinate (double x, double y, double z, int coordinate_index, float rot, int rot_index){ - /* coordniate_index is used to specify if the coordinate is x, y or z component - * rot_index is used to specify if the rotation is around the x, y or z achsis */ - if (rot_index == 0){ - if (coordinate_index == 0) { return x; } - else if (coordinate_index == 1){ return cos(rot)*y-sin(rot)*z; } - else{ return sin(rot)*y+cos(rot)*z; } - } - else if (rot_index == 1){ - if (coordinate_index == 0){ return cos(rot)*x+sin(rot)*z; } - else if (coordinate_index == 1){ return y; } - else { return -sin(rot)*x+cos(rot)*z; } - } - else { - if (coordinate_index == 0){ return cos(rot)*x-sin(rot)*y; } - else if (coordinate_index == 1){ return sin(rot)*x+cos(rot)*y; } - else { return z; } - } -} - -void plot_circle (cairo_t *cr, double radius, float rot1, float rot2, double render){ - double x = radius; - double y = 0; - double z = 0; - double x_plot, y_plot, z_plot; - - x_plot = plot_rotate_coordinate (x,y,z,0,rot1,0); - y_plot = plot_rotate_coordinate (x,y,z,1,rot1,0); - z_plot = plot_rotate_coordinate (x,y,z,2,rot1,0); - x = x_plot; y = y_plot; z = z_plot; - x_plot = plot_rotate_coordinate (x,y,z,0,rot2,1); - y_plot = plot_rotate_coordinate (x,y,z,1,rot2,1); - z_plot = plot_rotate_coordinate (x,y,z,2,rot2,1); - - plot_move_to (cr, x_plot, y_plot, z_plot); - for (double ang = 2*G_PI/render; ang<=2*G_PI; ang += 2*G_PI/render){ - x = radius * cos(ang); - y = radius * sin(ang); - z = 0; - - x_plot = plot_rotate_coordinate (x,y,z,0,rot1,0); - y_plot = plot_rotate_coordinate (x,y,z,1,rot1,0); - z_plot = plot_rotate_coordinate (x,y,z,2,rot1,0); - x = x_plot; y = y_plot; z = z_plot; - x_plot = plot_rotate_coordinate (x,y,z,0,rot2,1); - y_plot = plot_rotate_coordinate (x,y,z,1,rot2,1); - z_plot = plot_rotate_coordinate (x,y,z,2,rot2,1); - - plot_line_to (cr, x_plot, y_plot, z_plot); - } - x = radius; - y = 0; - z = 0; - - x_plot = plot_rotate_coordinate (x,y,z,0,rot1,0); - y_plot = plot_rotate_coordinate (x,y,z,1,rot1,0); - z_plot = plot_rotate_coordinate (x,y,z,2,rot1,0); - x = x_plot; y = y_plot; z = z_plot; - x_plot = plot_rotate_coordinate (x,y,z,0,rot2,1); - y_plot = plot_rotate_coordinate (x,y,z,1,rot2,1); - z_plot = plot_rotate_coordinate (x,y,z,2,rot2,1); - - plot_line_to (cr, x_plot, y_plot, z_plot); -} - -void plot_overview (GtkWidget *box){ - g_print("plots_overview\n"); - da_overview = gtk_drawing_area_new (); - gtk_widget_set_size_request (da_overview, 200, 100); - gtk_widget_set_hexpand (da_overview, TRUE); - gtk_widget_set_vexpand (da_overview, TRUE); - - gtk_container_add (GTK_CONTAINER (box), da_overview); - gtk_widget_show_all (box); - - g_signal_connect (da_overview, "draw", G_CALLBACK (on_draw_overview), NULL); -} - -void course_sun_overview (float *array_az_sun, float *array_el_sun){ - for (int i=0; i<288; i++){ - array_sun_x[i] = cos(M_PI/180*array_az_sun[i+2])*cos(M_PI/180*array_el_sun[i+2]); - array_sun_y[i] = sin(M_PI/180*array_az_sun[i+2])*cos(M_PI/180*array_el_sun[i+2]); - array_sun_z[i] = -sin(M_PI/180*array_el_sun[i+2]); - } -} - -void course_moon_overview (float *array_az_moon, float *array_el_moon){ - for (int i=0; i<288; i++){ - array_moon_x[i] = cos(M_PI/180*array_az_moon[i+2])*cos(M_PI/180*array_el_moon[i+2]); - array_moon_y[i] = sin(M_PI/180*array_az_moon[i+2])*cos(M_PI/180*array_el_moon[i+2]); - array_moon_z[i] = -sin(M_PI/180*array_el_moon[i+2]); - } -} - -void course_mw_overview (float *array_az_mw, float *array_el_mw){ - for (int i=0; i<288; i++){ - array_mw_x[i] = cos(M_PI/180*array_az_mw[i+2])*cos(M_PI/180*array_el_mw[i+2]); - array_mw_y[i] = sin(M_PI/180*array_az_mw[i+2])*cos(M_PI/180*array_el_mw[i+2]); - array_mw_z[i] = -sin(M_PI/180*array_el_mw[i+2]); - } -} - -void update_overview (float sun_az, float sun_el, float moon_az, float moon_el, float mw_az, float mw_el){ - - sun_x = cos(M_PI/180*sun_az)*cos(M_PI/180*sun_el); - sun_y = sin(M_PI/180*sun_az)*cos(M_PI/180*sun_el); - sun_z = -sin(M_PI/180*sun_el); - - moon_x = cos(M_PI/180*moon_az)*cos(M_PI/180*moon_el); - moon_y = sin(M_PI/180*moon_az)*cos(M_PI/180*moon_el); - moon_z = -sin(M_PI/180*moon_el); - - mw_x = cos(M_PI/180*mw_az)*cos(M_PI/180*mw_el); - mw_y = sin(M_PI/180*mw_az)*cos(M_PI/180*mw_el); - mw_z = -sin(M_PI/180*mw_el); - - gtk_widget_queue_draw(da_overview); -} - -gboolean on_draw_overview (GtkWidget *widget, cairo_t *cr, gpointer gpoint){ - - GdkWindow *drawing_window; - cairo_region_t *cairo_region; - GdkDrawingContext *drawing_context; - GdkRectangle da; - gdouble dx, dy; - gdouble clip_x1, clip_y1, clip_x2, clip_y2; - - drawing_window = gtk_widget_get_window (widget); - cairo_region = cairo_region_create(); - drawing_context = gdk_window_begin_draw_frame (drawing_window,cairo_region); - cr = gdk_drawing_context_get_cairo_context (drawing_context); - - gdk_window_get_geometry (drawing_window, &da.x, &da.y, &da.width, &da.height); - cairo_translate (cr, da.width*0.5, da.height*0.5); - cairo_scale (cr, 100, 100); - dx = da.width, dy = da.height; - clip_x1 = 0.0, clip_y1 = 0.0, clip_x2 = 0.0, clip_y2 = 0.0; - cairo_device_to_user_distance (cr, &dx, &dy); - cairo_clip_extents (cr, &clip_x1, &clip_y1, &clip_x2, &clip_y2); - - plot_set_basic_coordinate_system_settings(); - - cairo_set_source_rgb (cr, 0.8, 0.8, 0.8); - cairo_paint (cr); - - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_set_line_width (cr, 0.02); - plot_move_to (cr, 0, 0, 0); - plot_circle (cr, 1, 0, 0, 50); - cairo_fill (cr); - cairo_stroke (cr); - - cairo_set_line_width (cr, 0.05); - - if (sun_z<0){ - cairo_set_source_rgb (cr, 1, 0, 0); - plot_move_to (cr, 0, 0, 0); - plot_vector_to (cr, sun_x, sun_y, sun_z); - cairo_stroke (cr); - } - - if (moon_z<0){ - cairo_set_source_rgb (cr, 0, 1, 0); - plot_move_to (cr, 0, 0, 0); - plot_vector_to (cr, moon_x, moon_y, moon_z); - cairo_stroke (cr); - } - if (mw_z<0){ - cairo_set_source_rgb (cr, 0, 0, 1); - plot_move_to (cr, 0, 0, 0); - plot_vector_to (cr, mw_x, mw_y, mw_z); - cairo_stroke (cr); - } - - cairo_set_source_rgb (cr, 1, 0.9, 0); - plot_move_to (cr, array_sun_x[0], array_sun_y[0], array_sun_z[0]); - for (int i=1; i<288; i++){ - if (array_sun_z[i]<0){ - plot_line_to (cr, array_sun_x[i], array_sun_y[i], array_sun_z[i]); - } - else{ - plot_move_to (cr, array_sun_x[i], array_sun_y[i], array_sun_z[i]); - - } - } - cairo_stroke (cr); - - cairo_set_source_rgb (cr, 0.1, 0.9, 1); - plot_move_to (cr, array_moon_x[0], array_moon_y[0], array_moon_z[0]); - for (int i=0; i<288; i++){ - if (array_moon_z[i]<0){ - plot_line_to (cr, array_moon_x[i], array_moon_y[i], array_moon_z[i]); - } - else{ - plot_move_to (cr, array_moon_x[i], array_moon_y[i], array_moon_z[i]); - } - } - cairo_stroke (cr); - - cairo_set_source_rgb (cr, 0.9, 0.9, 0.9); - plot_move_to (cr, array_mw_x[0], array_mw_y[0], array_mw_z[0]); - for (int i=0; i<288; i++){ - if (array_mw_z[i]<0){ - plot_line_to (cr, array_mw_x[i], array_mw_y[i], array_mw_z[i]); - } - else{ - plot_move_to (cr, array_mw_x[i], array_mw_y[i], array_mw_z[i]); - } - } - cairo_stroke (cr); - - cairo_surface_t *cairo_surface = cairo_get_target (cr); - unsigned char *data = cairo_image_surface_get_data(cairo_surface); - - - gdk_window_end_draw_frame(drawing_window,drawing_context); - cairo_region_destroy(cairo_region); - - return FALSE; -} - -void plot_elevation_mw (float *elevations, GtkWidget *box){ - g_print("plots_mw_elevation\n"); - GtkWidget *da; /* Drawing Area */ - - da = gtk_drawing_area_new (); - gtk_widget_set_size_request (da, 200, 100); - gtk_widget_set_hexpand (da, TRUE); - gtk_widget_set_vexpand (da, TRUE); - - gtk_container_add (GTK_CONTAINER (box), da); - gtk_widget_show_all (box); - - static float stat_elevation[290]; - for (int i = 0; i<290; i++){ - stat_elevation[i]=elevations[i]; - } - /* I found this by trail and error... Why do I need a static array? A non static arry is not able to pass data through the g_signal_connect function...? */ - - g_signal_connect (da, "draw", G_CALLBACK (on_draw_elevation_mw), stat_elevation); -} - -gboolean on_draw_elevation_mw (GtkWidget *widget, cairo_t *cr, gpointer gpoint){ - float *elevation = gpoint; - - GdkWindow *drawing_window; - cairo_region_t *cairo_region; - GdkDrawingContext *drawing_context; - GdkRectangle da; - - drawing_window = gtk_widget_get_window (widget); - - cairo_region = cairo_region_create(); - drawing_context = gdk_window_begin_draw_frame (drawing_window,cairo_region); - cr = gdk_drawing_context_get_cairo_context (drawing_context); - - gdk_window_get_geometry (drawing_window, &da.x, &da.y, &da.width, &da.height); - cairo_translate (cr, 0, da.height*0.4); - cairo_scale (cr, 100, 100); - gdouble dx = da.width, dy = da.height*0.4; - gdouble clip_x1 = 0.0, clip_y1 = 0.0, clip_x2 = 0.0, clip_y2 = 0.0; - cairo_device_to_user_distance (cr, &dx, &dy); - cairo_clip_extents (cr, &clip_x1, &clip_y1, &clip_x2, &clip_y2); - cairo_set_line_width (cr, 0.05); - - cairo_set_source_rgb (cr, 0.8, 0.8, 0.8); - cairo_paint (cr); - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, dx, 0); - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_stroke (cr); - - float extr = 0; - if (fabs(*elevation)>*(elevation+1)){ - extr=fabs(*elevation); - } - else{ - extr = fabs(*(elevation+1)); - } - - for (int i = 0; i<25; i++){ - float x = (float)i/24.*dx*0.9+0.05*dx; - - cairo_move_to (cr, x, -dy); - cairo_set_line_width (cr, 0.02); - cairo_set_source_rgb (cr, 0.95, 0.95, 0.95); - cairo_line_to (cr, x, dy); - - if (i%2==0){ - cairo_move_to (cr, x-0.1, dy*1.4); - static char label[3]; - sprintf (label, "%02d", i); - cairo_set_font_size (cr, 0.15); - cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_show_text (cr, label); - } - cairo_stroke (cr); - } - - cairo_set_line_width (cr, 0.05); - cairo_move_to (cr, 0, 0); - cairo_set_source_rgb (cr, 0, 0, 0); - for (int i = 0; i<288; i++){ - float x = (float)i/288.*dx*0.9+0.05*dx; - float y = -*(elevation+i+2)/extr*dy*0.95; - /*g_print("Elevation: %f\n", elevation[i+2]);*/ - if (i==0){ - cairo_move_to (cr, x, y); - } - else{ - cairo_line_to (cr, x, y); - } - - } - - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_stroke (cr); - - gdk_window_end_draw_frame(drawing_window,drawing_context); - cairo_region_destroy(cairo_region); - - return FALSE; -} - -void plot_elevation_sun (float *elevations, GtkWidget *box){ - g_print("plots_sun_elevation\n"); - GtkWidget *da; /* Drawing Area */ - - da = gtk_drawing_area_new (); - gtk_widget_set_size_request (GTK_WIDGET(da), 200, 100); - gtk_widget_set_hexpand (GTK_WIDGET (da), TRUE); - gtk_widget_set_vexpand (GTK_WIDGET (da), TRUE); - - gtk_container_add (GTK_CONTAINER (box), da); - gtk_widget_show_all (box); - - /*g_print("Elevation 1: %f\n",*(elevations+2));*/ - - static float stat_elevation[290]; - for (int i = 0; i<290; i++){ - stat_elevation[i]=elevations[i]; - } - /* I found this by trail and error... Why do I need a static array? A non static arry is not able to pass data through the g_signal_connect function...? */ - /*g_print("Elevation 1.1: %f\n",stat_elevation[2]);*/ - - g_signal_connect (da, "draw", G_CALLBACK (on_draw_elevation_sun), stat_elevation); -} - -gboolean on_draw_elevation_sun (GtkWidget *widget, cairo_t *cr, gpointer gpoint){ - float *elevation = gpoint; - /*g_print("on_draw_elevation_sun\n");*/ - - GdkWindow *drawing_window; - cairo_region_t *cairo_region; - GdkDrawingContext *drawing_context; - GdkRectangle da; - - drawing_window = gtk_widget_get_window (widget); - - cairo_region = cairo_region_create(); - drawing_context = gdk_window_begin_draw_frame (drawing_window,cairo_region); - cr = gdk_drawing_context_get_cairo_context (drawing_context); - - gdk_window_get_geometry (drawing_window, &da.x, &da.y, &da.width, &da.height); - cairo_translate (cr, 0, da.height*0.4); - cairo_scale (cr, 100, 100); - gdouble dx = da.width, dy = da.height*0.4; - gdouble clip_x1 = 0.0, clip_y1 = 0.0, clip_x2 = 0.0, clip_y2 = 0.0; - cairo_device_to_user_distance (cr, &dx, &dy); - cairo_clip_extents (cr, &clip_x1, &clip_y1, &clip_x2, &clip_y2); - cairo_set_line_width (cr, 0.05); - - cairo_set_source_rgb (cr, 0.8, 0.8, 0.8); - cairo_paint (cr); - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, dx, 0); - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_stroke (cr); - - float extr = 0; - if (fabs(*elevation)>*(elevation+1)){ - extr=fabs(*elevation); - } - else{ - extr = *(elevation+1); - } - - for (int i = 0; i<25; i++){ - float x = (float)i/24.*dx*0.9+0.05*dx; - - cairo_move_to (cr, x, -dy); - cairo_set_line_width (cr, 0.02); - cairo_set_source_rgb (cr, 0.95, 0.95, 0.95); - cairo_line_to (cr, x, dy); - - if (i%2==0){ - cairo_move_to (cr, x-0.1, dy*1.4); - static char label[3]; - sprintf (label, "%02d", i); - cairo_set_font_size (cr, 0.15); - cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_show_text (cr, label); - } - cairo_stroke (cr); - } - - cairo_set_line_width (cr, 0.05); - cairo_move_to (cr, 0, 0); - cairo_set_source_rgb (cr, 0, 0, 0); - for (int i = 0; i<288; i++){ - float x = (float)i/288.*dx*0.9+0.05*dx; - float y = -*(elevation+i+2)/extr*dy*0.95; - /*g_print("Elevation: %f\n", elevation[i+2]);*/ - if (i==0){ - cairo_move_to (cr, x, y); - } - else{ - cairo_line_to (cr, x, y); - } - /* - int hour=(int)(i*5/60); - int min=i*5-(int)(i*5/60)*60; - if (elevation[i+2]==elevation[1]){ - cairo_stroke (cr); - - static char label[30]; - sprintf (label, "%02d:%02d @ %.1f \u00B0", hour,min,elevation[i+2]); - cairo_move_to (cr, x-0.7, y-0.08); - - cairo_set_font_size (cr, 0.2); - cairo_select_font_face (cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_show_text (cr, label); - cairo_move_to (cr, x, y); - } */ - - } - /*cairo_line_to (cr, 160./288.*dx, -35./60.*dy);*/ - - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_stroke (cr); - - gdk_window_end_draw_frame(drawing_window,drawing_context); - cairo_region_destroy(cairo_region); - - return FALSE; -} - -void plot_elevation_moon (float *elevations, GtkWidget *box){ - GtkWidget *da; - - da = gtk_drawing_area_new (); - gtk_widget_set_size_request (GTK_WIDGET(da), 200, 100); - gtk_widget_set_hexpand (GTK_WIDGET (da), TRUE); - gtk_widget_set_vexpand (GTK_WIDGET (da), TRUE); - - gtk_container_add (GTK_CONTAINER (box), da); - gtk_widget_show_all (box); - - /*g_print("Elevation 1: %f\n",*(elevations+2));*/ - - static float stat_elevation[290]; - for (int i = 0; i<290; i++){ - stat_elevation[i]=elevations[i]; - } - /* I found this by trail and error... Why do I need a static array? A non static arry is not able to pass data through the g_signal_connect function...? */ - /*g_print("Elevation 1.1: %f\n",stat_elevation[2]);*/ - - g_signal_connect (da, "draw", G_CALLBACK (on_draw_elevation_moon), stat_elevation); -} - -gboolean on_draw_elevation_moon (GtkWidget *widget, cairo_t *cr, gpointer gpoint){ - float *elevation = gpoint; - - GdkWindow *drawing_window; - cairo_region_t *cairo_region; - GdkDrawingContext *drawing_context; - GdkRectangle da; - - drawing_window = gtk_widget_get_window (widget); - - cairo_region = cairo_region_create(); - drawing_context = gdk_window_begin_draw_frame (drawing_window,cairo_region); - cr = gdk_drawing_context_get_cairo_context (drawing_context); - - gdk_window_get_geometry (drawing_window, &da.x, &da.y, &da.width, &da.height); - cairo_translate (cr, 0, da.height*0.4); - cairo_scale (cr, 100, 100); - gdouble dx = da.width, dy = da.height*0.4; - gdouble clip_x1 = 0.0, clip_y1 = 0.0, clip_x2 = 0.0, clip_y2 = 0.0; - cairo_device_to_user_distance (cr, &dx, &dy); - cairo_clip_extents (cr, &clip_x1, &clip_y1, &clip_x2, &clip_y2); - cairo_set_line_width (cr, 0.05); - - cairo_set_source_rgb (cr, 0.8, 0.8, 0.8); - cairo_paint (cr); - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, dx, 0); - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_stroke (cr); - - float extr = 0; - if (fabs(*elevation)>*(elevation+1)){ - extr=fabs(*elevation); - } - else{ - extr = *(elevation+1); - } - - for (int i = 0; i<25; i++){ - float x = (float)i/24.*dx*0.9+0.05*dx; - - cairo_move_to (cr, x, -dy); - cairo_set_line_width (cr, 0.02); - cairo_set_source_rgb (cr, 0.95, 0.95, 0.95); - cairo_line_to (cr, x, dy); - - if (i%2==0){ - cairo_move_to (cr, x-0.1, dy*1.4); - static char label[3]; - sprintf (label, "%02d", i); - cairo_set_font_size (cr, 0.15); - cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_show_text (cr, label); - } - cairo_stroke (cr); - } - - cairo_set_line_width (cr, 0.05); - cairo_move_to (cr, 0, 0); - cairo_set_source_rgb (cr, 0, 0, 0); - for (int i = 0; i<288; i++){ - float x = (float)i/288.*dx*0.9+0.05*dx; - float y = -*(elevation+i+2)/extr*dy*0.95; - /*g_print("Elevation: %f\n", elevation[i+2]);*/ - if (i==0){ - cairo_move_to (cr, x, y); - } - else{ - cairo_line_to (cr, x, y); - } - } - - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_stroke (cr); - - gdk_window_end_draw_frame(drawing_window,drawing_context); - cairo_region_destroy(cairo_region); - - return FALSE; -} diff --git a/src/plot.h b/src/plot.h deleted file mode 100644 index cd01e8b..0000000 --- a/src/plot.h +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include - -void plot_adjust_teta (float value); - -double plot_calc_coordinate_x (double a1, double a2); - -double plot_calc_coordinate_y (double a1, double a2, double a3); - -void plot_line_to (cairo_t *cr, double a1, double a2, double a3); - -void plot_move_to (cairo_t *cr, double a1, double a2, double a3); - -void plot_vector_to (cairo_t *cr, double a1, double a2, double a3); - -double plot_rotate_coordinate (double x, double y, double z, int coordinate_index, float rot, int rot_index); - -void plot_circle (cairo_t *cr, double radius, float rot1, float rot2, double render); - -void plot_overview (GtkWidget *box); - -void update_overview (float sun_az_ud, float sun_el_ud, float moon_az_ud, float moon_el_ud, float mw_az_ud, float mw_el_ud); - -void course_sun_overview (float *array_az_sun, float *array_el_sun); - -void course_moon_overview (float *array_az_moon, float *array_el_moon); - -void course_mw_overview (float *array_az_mw, float *array_el_mw); - -gboolean on_draw_overview (GtkWidget *widget, cairo_t *cr, gpointer gpoint); - -void plot_elevation_mw (float *elevations, GtkWidget *box); - -gboolean on_draw_elevation_mw (GtkWidget *widget, cairo_t *cr, gpointer gpoint); - -void plot_elevation_sun (float *elevations, GtkWidget *box); - -gboolean on_draw_elevation_sun (GtkWidget *widget, cairo_t *cr, gpointer gpoint); - -void plot_elevation_moon (float *elevations, GtkWidget *box); - -gboolean on_draw_elevation_moon (GtkWidget *widget, cairo_t *cr, gpointer gpoint); - diff --git a/src/webconnection.c b/src/webconnection.c deleted file mode 100644 index 7271c22..0000000 --- a/src/webconnection.c +++ /dev/null @@ -1,120 +0,0 @@ -#include - -/* TODO - * From https://nominatim.org/release-docs/develop/api/Search/ - * Language of results - * accept-language= - * Preferred language order for showing search results, overrides the value specified in the "Accept-Language" HTTP header. - * Either use a standard RFC2616 accept-language string or a simple comma-separated list of language codes. - */ - -/* Below is needes for Curl to cummunicate with Nominatim */ -struct MemoryStruct { - char *memory; - size_t size; -}; - -/* some shit from curl I still don’t get... */ -size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) -{ - size_t realsize = size * nmemb; - struct MemoryStruct *mem = (struct MemoryStruct *)userp; - - char *ptr = realloc(mem->memory, mem->size + realsize + 1); - if(ptr == NULL) { - /* out of memory! */ - printf("not enough memory (realloc returned NULL)\n"); - return 0; - } - - mem->memory = ptr; - memcpy(&(mem->memory[mem->size]), contents, realsize); - mem->size += realsize; - mem->memory[mem->size] = 0; - - return realsize; -} - -/* TODO - * Make this function look nicer */ -struct Output *search_nominatim (const gchar *searchtext){ - - CURL *curl; - CURLcode res; - - struct Output nullOutput = {NULL,0.0,0.0}; - struct Output *output = &nullOutput; - - struct MemoryStruct chunk; - chunk.memory = malloc(1); - chunk.size = 0; - - curl_global_init(CURL_GLOBAL_DEFAULT); - curl = curl_easy_init(); - - if(curl) { - /* Bring the entered words into the API form of NOMINATIM see - * https://nominatim.org/release-docs/develop/api/Search/ - * for further information */ - - char *URLsearch = curl_easy_escape(curl, searchtext, 0); - char *URLosm = "https://nominatim.openstreetmap.org/search?q="; - char *URLformat = "&format=geojson"; - char *URL = (char *) malloc(1+strlen(URLsearch)+strlen(URLosm)+strlen(URLformat)); - strcpy(URL,URLosm); - strcat(URL,URLsearch); - strcat(URL,URLformat); - g_print ("%s\n", URL); - curl_easy_setopt(curl, CURLOPT_URL, URL); - /* Nominatim NEEDS a Useragent! */ - curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.58.0"); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - - /* Perform the request, res will get the return code */ - res = curl_easy_perform(curl); - - /* Check for errors */ - if(res != CURLE_OK) - { - g_print("curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); - } - else - { - /* Convert the JSON file which is handed back by nominatim - * into double variables for the north and east component */ - g_print("\nParsing location\n"); - json_object *json = json_tokener_parse(chunk.memory); - json_object *jsonFeatures; - json_object *jsonEntry; - json_object *jsonGeometry; - json_object *jsonCoordinates; - json_object *jsonProperties; - json_object *jsonDisplayName; - - json_object_object_get_ex(json, "features", &jsonFeatures); - jsonEntry = json_object_array_get_idx(jsonFeatures, 0); - - json_object_object_get_ex(jsonEntry, "geometry", &jsonGeometry); - json_object_object_get_ex(jsonGeometry, "coordinates", &jsonCoordinates); - (*output).east = json_object_get_double(json_object_array_get_idx(jsonCoordinates, 0)); - (*output).north = json_object_get_double(json_object_array_get_idx(jsonCoordinates, 1)); - - json_object_object_get_ex(jsonEntry, "properties", &jsonProperties); - json_object_object_get_ex(jsonProperties, "display_name", &jsonDisplayName); - (*output).displayText = json_object_get_string(jsonDisplayName); - - /* - * g_print("Display Text: %s, North: %f, East: %f\n",(*output).displayText, (*output).east, (*output).north); - */ - return output; - } - curl_easy_cleanup(curl); - } - curl_global_cleanup(); - - return output; -} - diff --git a/src/webconnection.h b/src/webconnection.h deleted file mode 100644 index 9e763bf..0000000 --- a/src/webconnection.h +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include /*libcurl4-openssl-dev*/ -#include /*libjson-c-dev*/ - -struct Output { - const char *displayText; - double east; - double north; -}; - -size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp); - -struct Output *search_nominatim (const gchar *searchtext); -