changing to GTK4 and restructuring the application

merge-requests/1/head
Zwarf 2021-11-21 00:54:55 +01:00
rodzic 059e918f59
commit 49d467b05a
38 zmienionych plików z 1151 dodań i 2837 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
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 <https://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.
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
<https://www.gnu.org/licenses/>.
<http://www.gnu.org/licenses/>.
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
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

Wyświetl plik

@ -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')])

Wyświetl plik

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>de.zwarf.picplanner.desktop</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0-or-later</project_license>
<description>
</description>
</component>

Wyświetl plik

@ -0,0 +1,8 @@
[Desktop Entry]
Name=picplanner
Exec=picplanner
Icon=de.zwarf.picplanner
Terminal=false
Type=Application
Categories=GTK;
StartupNotify=true

Wyświetl plik

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="picplanner">
<schema id="de.zwarf.picplanner" path="/de/zwarf/picplanner/">
</schema>
</schemalist>

Wyświetl plik

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="120mm"
height="120mm"
viewBox="0 0 120 120"
version="1.1"
id="svg5"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs2">
<linearGradient
id="linearGradient11154">
<stop
style="stop-color:#ffffff;stop-opacity:1"
offset="0"
id="stop11150" />
<stop
style="stop-color:#ffe600;stop-opacity:1"
offset="1"
id="stop11152" />
</linearGradient>
<radialGradient
xlink:href="#linearGradient11154"
id="radialGradient11182"
cx="183.50667"
cy="142.3913"
fx="183.50667"
fy="142.3913"
r="19"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.85470377,0,0,0.85470377,132.80565,-9.7410232)" />
</defs>
<g
id="layer1"
transform="translate(-69.954025,-229.38797)">
<circle
style="fill:#464646;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.49514;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path5856"
cx="129.95403"
cy="289.38797"
r="58.25243" />
<path
style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 128.13765,238.53399 27.5446,35.82589 4.46703,-24.27508"
id="path6127" />
<g
id="g11562"
transform="matrix(1.0885685,0,0,1.0885685,-7.5065883,-21.001121)">
<rect
style="opacity:1;fill:#ffe600;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2.56411;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect10551"
width="32.478745"
height="32.478745"
x="109.91594"
y="267.41592" />
<rect
style="fill:url(#radialGradient11182);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2.56411;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect10551-0"
width="32.478745"
height="32.478745"
x="273.41013"
y="95.721977"
transform="rotate(45)" />
</g>
<path
style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 164.92264,253.8231 -8.01043,43.17332 20.90233,-16.14294"
id="path6127-2" />
<path
style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 179.37052,287.88723 -34.91342,26.71716 26.70733,1.10576"
id="path6127-2-3" />
<path
style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 167.23625,321.52368 -43.45146,-2.45903 18.13098,18.38126"
id="path6127-2-3-7" />
<path
style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 134.67521,338.4435 -29.21186,-30.86914 0.7311,26.41444"
id="path6127-5" />
<path
style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 100.50113,329.96069 -1.115623,-45.69896 -16.96772,20.06653"
id="path6127-2-9" />
<path
style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 80.182974,298.23593 28.839086,-33.66566 -24.577728,2.88439"
id="path6127-2-3-2" />
<path
style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 88.473839,260.28664 132.81588,256.0324 119.85137,240.24226"
id="path6127-2-3-7-2" />
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path11838"
cx="129.85677"
cy="289.59003"
rx="48.861397"
ry="48.861401" />
</g>
</svg>

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 4.7 KiB

Wyświetl plik

@ -0,0 +1,184 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="93.426376mm"
height="93.426384mm"
viewBox="0 0 93.426373 93.426384"
version="1.1"
id="svg5"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs2">
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1899">
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.573619;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse1901"
cx="128.22453"
cy="287.95779"
rx="46.713188"
ry="46.713192"
mask="none"
clip-path="none" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1903">
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.573619;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse1905"
cx="128.22453"
cy="287.95779"
rx="46.713188"
ry="46.713192"
mask="none"
clip-path="none" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1907">
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.573619;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse1909"
cx="128.22453"
cy="287.95779"
rx="46.713188"
ry="46.713192"
mask="none"
clip-path="none" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1911">
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.573619;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse1913"
cx="128.22453"
cy="287.95779"
rx="46.713188"
ry="46.713192"
mask="none"
clip-path="none" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1915">
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.573619;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse1917"
cx="128.22453"
cy="287.95779"
rx="46.713188"
ry="46.713192"
mask="none"
clip-path="none" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1919">
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.573619;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse1921"
cx="128.22453"
cy="287.95779"
rx="46.713188"
ry="46.713192"
mask="none"
clip-path="none" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1923">
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.573619;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse1925"
cx="128.22453"
cy="287.95779"
rx="46.713188"
ry="46.713192"
mask="none"
clip-path="none" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1927">
<ellipse
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.573619;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse1929"
cx="128.22453"
cy="287.95779"
rx="46.713188"
ry="46.713192"
mask="none"
clip-path="none" />
</clipPath>
</defs>
<g
id="layer1"
transform="translate(-81.511345,-241.2446)">
<path
style="fill:#000001;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 126.55014,236.41731 27.5446,35.82589 4.46703,-24.27508"
id="path6127"
clip-path="url(#clipPath1927)"
mask="none" />
<g
id="g11562"
transform="matrix(1.0885685,0,0,1.0885685,-9.0940884,-23.117789)"
style="fill:#000000;fill-opacity:1">
<rect
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2.56411;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect10551"
width="32.478745"
height="32.478745"
x="109.91594"
y="267.41592" />
<rect
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2.56411;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect10551-0"
width="32.478745"
height="32.478745"
x="273.41013"
y="95.721977"
transform="rotate(45)" />
</g>
<path
style="fill:#000001;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 163.33513,251.70642 -8.01043,43.17332 20.90233,-16.14294"
id="path6127-2"
clip-path="url(#clipPath1923)" />
<path
style="fill:#000001;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 177.78301,285.77055 -34.91342,26.71716 26.70733,1.10576"
id="path6127-2-3"
clip-path="url(#clipPath1919)" />
<path
style="fill:#000001;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 165.64874,319.407 -43.45146,-2.45903 18.13098,18.38126"
id="path6127-2-3-7"
clip-path="url(#clipPath1915)" />
<path
style="fill:#000001;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 133.0877,336.32682 -29.21186,-30.86914 0.7311,26.41444"
id="path6127-5"
clip-path="url(#clipPath1911)" />
<path
style="fill:#000001;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 98.913629,327.84401 -1.115623,-45.69896 -16.96772,20.06653"
id="path6127-2-9"
clip-path="url(#clipPath1907)" />
<path
style="fill:#000001;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 78.595473,296.11925 30.957537,-33.18717 -26.696179,2.4059"
id="path6127-2-3-2"
clip-path="url(#clipPath1903)" />
<path
style="fill:#000001;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 86.886338,257.64079 45.734682,-1.30041 -14.35716,-18.74397"
id="path6127-2-3-7-2"
clip-path="url(#clipPath1899)" />
</g>
</svg>

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 7.6 KiB

Wyświetl plik

@ -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)
)

43
data/meson.build 100644
Wyświetl plik

@ -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')

Wyświetl plik

@ -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"
}
]
}
]
}

Wyświetl plik

@ -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')

0
po/LINGUAS 100644
Wyświetl plik

7
po/POTFILES 100644
Wyświetl plik

@ -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

1
po/meson.build 100644
Wyświetl plik

@ -0,0 +1 @@
i18n.gettext('picplanner', preset: 'glib')

Wyświetl plik

@ -1,29 +0,0 @@
#include <gtk/gtk.h>
#include <time.h>
#include <math.h>
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);

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -0,0 +1,4 @@
#include "calculations_transformations.h"
float
*get_coordinates_milky_way ();

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -0,0 +1,5 @@
#include "calculations_transformations.h"
float
*calc_coordinates_moon (double time_jd);

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -0,0 +1,5 @@
#include "calculations_transformations.h"
float
*calc_coordinates_sun (double time_jd);

Wyświetl plik

@ -1,92 +1,28 @@
#include <calculations.h>
#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;
}

Wyświetl plik

@ -0,0 +1,31 @@
#include <time.h>
#include <math.h>
#include <glib.h>
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);

Wyświetl plik

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkShortcutsWindow" id="help_overlay">
<property name="modal">True</property>
<child>
<object class="GtkShortcutsSection">
<property name="section-name">shortcuts</property>
<property name="max-height">10</property>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcut window">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Show Shortcuts</property>
<property name="action-name">win.show-help-overlay</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Quit</property>
<property name="action-name">app.quit</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

Wyświetl plik

@ -1,446 +0,0 @@
#include <handler.h>
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]<min_elevation){
min_elevation = result[1];
}
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]<min_elevation){
min_elevation = result[1];
}
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]<min_elevation){
min_elevation = result[1];
}
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);
}

Wyświetl plik

@ -1,19 +0,0 @@
#include <gtk/gtk.h>
#include <calculations.h>
#include <plot.h>
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);

Wyświetl plik

@ -1,293 +1,58 @@
#include <gtk/gtk.h> /* libgtk-3-dev */
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
/* 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 <http://www.gnu.org/licenses/>.
*/
#include <calculations.h>
#include <webconnection.h>
#include <handler.h>
#include <plot.h>
#include <glib/gi18n.h>
/* 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(view_switcher), gtk_widget_get_allocated_width (window)>switch_size);
gtk_widget_set_visible (GTK_WIDGET(label_heading), gtk_widget_get_allocated_width (window)<switch_size);
g_string_free(g_string_new(NULL), TRUE);
}
/* initial function */
int main( int argc, char *argv[] )
{
gtk_init (&argc, &argv);
hdy_action_row_get_type ();
builder = gtk_builder_new_from_resource("/main/picplanner-window.ui");
window = GTK_WIDGET (gtk_builder_get_object(builder, "window"));
button_search = GTK_WIDGET (gtk_builder_get_object(builder, "button_search"));
button_now = GTK_WIDGET (gtk_builder_get_object(builder, "button_now"));
button_calculate = GTK_WIDGET (gtk_builder_get_object(builder, "button_calculate"));
squeezer = HDY_SQUEEZER (gtk_builder_get_object (builder, "squeezer"));
view_switcher = HDY_VIEW_SWITCHER (gtk_builder_get_object (builder, "title_wide_switcher"));
switcher_bar = HDY_VIEW_SWITCHER_BAR (gtk_builder_get_object(builder, "switcher_bar"));
label_heading = GTK_WIDGET (gtk_builder_get_object (builder, "label_heading"));
entry_min = GTK_SPIN_BUTTON (gtk_builder_get_object(builder, "entry_min"));
entry_hour = GTK_SPIN_BUTTON (gtk_builder_get_object(builder, "entry_hour"));
entry_day = GTK_SPIN_BUTTON (gtk_builder_get_object(builder, "entry_day"));
entry_month = GTK_COMBO_BOX (gtk_builder_get_object (builder, "entry_month"));
entry_year = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "entry_year"));
location_entry = GTK_ENTRY(gtk_builder_get_object(builder, "location_entry"));
north_entry = GTK_ENTRY(gtk_builder_get_object(builder, "north_entry"));
east_entry = GTK_ENTRY(gtk_builder_get_object(builder, "east_entry"));
searchentry = GTK_SEARCH_ENTRY(gtk_builder_get_object(builder, "searchentry"));
box_scale = GTK_WIDGET (gtk_builder_get_object (builder, "scale_rotation"));
scale_button = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 360, 1);
gtk_widget_set_hexpand (scale_button, TRUE);
gtk_container_add (GTK_CONTAINER (box_scale), scale_button);
g_signal_connect (window, "delete-event", G_CALLBACK (delete_event), NULL);
g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
g_signal_connect (window, "configure-event", G_CALLBACK(hdy_size_config), NULL);
g_signal_connect (button_search, "clicked", G_CALLBACK (search), NULL);
g_signal_connect (button_now, "clicked", G_CALLBACK(set_time_now), NULL);
g_signal_connect (button_calculate, "clicked", G_CALLBACK (calculate), NULL);
g_signal_connect (entry_month, "changed", G_CALLBACK (correct_time), NULL);
g_signal_connect (entry_year, "changed", G_CALLBACK (correct_time), NULL);
g_signal_connect (entry_hour, "changed", G_CALLBACK (adjust_time), NULL);
g_signal_connect (entry_min, "changed", G_CALLBACK (adjust_time), NULL);
g_signal_connect (searchentry, "activate", G_CALLBACK (search), NULL);
g_signal_connect (scale_button, "change-value", G_CALLBACK(scale_button_changed), NULL);
set_time_now (window, NULL);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}

Wyświetl plik

@ -1,22 +1,24 @@
picplanner_sources = [
'main.c',
'calculations.c',
'webconnection.c',
'handler.c',
'plot.c',
]
'picplanner-window.c',
'picplanner-application.c',
'calculations/calculations_transformations.c',
'calculations/calculations_sun.c',
'calculations/calculations_moon.c',
'calculations/calculations_milky_way.c',
]
picplanner_deps = [
dependency('gtk+-3.0', version: '>= 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,

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/>.
*/
#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[] = {"<primary>q", NULL};
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.quit", accels);
}

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <gtk/gtk.h>
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

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/>.
*/
#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));
}

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define PICPLANNER_TYPE_WINDOW (picplanner_window_get_type())
G_DECLARE_FINAL_TYPE (PicplannerWindow, picplanner_window, PICPLANNER, WINDOW, GtkApplicationWindow)
G_END_DECLS

Plik diff jest za duży Load Diff

Wyświetl plik

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/main">
<gresource prefix="/de/zwarf/picplanner">
<file>picplanner-window.ui</file>
<file>gtk/help-overlay.ui</file>
</gresource>
</gresources>

Wyświetl plik

@ -1,656 +0,0 @@
#include <plot.h>
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 = &current_x;
double *y_1 = &current_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;
}

Wyświetl plik

@ -1,44 +0,0 @@
#include <gtk/gtk.h>
#include <math.h>
#include <cairo.h>
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);

Wyświetl plik

@ -1,120 +0,0 @@
#include <webconnection.h>
/* TODO
* From https://nominatim.org/release-docs/develop/api/Search/
* Language of results
* accept-language=<browser language string>
* 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 dont 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;
}

Wyświetl plik

@ -1,14 +0,0 @@
#include <gtk/gtk.h>
#include <curl/curl.h> /*libcurl4-openssl-dev*/
#include <json.h> /*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);