Finalized API
From this on, API (and hopefully ABI) change is very unlikely
This commit is contained in:
parent
2fe9e524e9
commit
f65f66fd72
@ -268,7 +268,7 @@ find_by_planet_id(gconstpointer a, gconstpointer b)
|
||||
}
|
||||
|
||||
static void
|
||||
gswe_calculate_data_by_position(GsweMoment *moment, GswePlanet planet, gdouble position)
|
||||
gswe_calculate_data_by_position(GsweMoment *moment, GswePlanet planet, gdouble position, GError **err)
|
||||
{
|
||||
GswePlanetData *planet_data = (GswePlanetData *)(g_list_find_custom(moment->priv->planet_list, &planet, find_by_planet_id)->data);
|
||||
GsweZodiac sign;
|
||||
@ -290,16 +290,17 @@ gswe_calculate_data_by_position(GsweMoment *moment, GswePlanet planet, gdouble p
|
||||
|
||||
planet_data->position = position;
|
||||
planet_data->retrograde = FALSE;
|
||||
planet_data->house = gswe_moment_get_house(moment, position);
|
||||
planet_data->house = gswe_moment_get_house(moment, position, err);
|
||||
planet_data->sign = sign_info;
|
||||
planet_data->revision = moment->priv->revision;
|
||||
}
|
||||
|
||||
static void
|
||||
gswe_moment_calculate_house_positions(GsweMoment *moment)
|
||||
gswe_moment_calculate_house_positions(GsweMoment *moment, GError **err)
|
||||
{
|
||||
gdouble cusps[13],
|
||||
ascmc[10];
|
||||
ascmc[10],
|
||||
jd;
|
||||
gint i;
|
||||
GsweHouseSystemInfo *house_system_data;
|
||||
|
||||
@ -308,14 +309,26 @@ gswe_moment_calculate_house_positions(GsweMoment *moment)
|
||||
}
|
||||
|
||||
if ((house_system_data = g_hash_table_lookup(gswe_house_system_info_table, GINT_TO_POINTER(moment->priv->house_system))) == NULL) {
|
||||
g_error("Unknown house system!");
|
||||
g_set_error(err, GSWE_MOMENT_ERROR, GSWE_MOMENT_ERROR_UNKNOWN_HSYS, "Unknown house system");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
swe_houses(gswe_timestamp_get_julian_day(moment->priv->timestamp), moment->priv->coordinates.latitude, moment->priv->coordinates.longitude, house_system_data->sweph_id, cusps, ascmc);
|
||||
jd = gswe_timestamp_get_julian_day(moment->priv->timestamp, err);
|
||||
|
||||
if ((err) && (*err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
swe_houses(jd, moment->priv->coordinates.latitude, moment->priv->coordinates.longitude, house_system_data->sweph_id, cusps, ascmc);
|
||||
|
||||
g_list_free_full(moment->priv->house_list, g_free);
|
||||
moment->priv->house_list = NULL;
|
||||
|
||||
/* TODO: SWE house system 'G' (Gauquelin sector cusps) have 36 houses; we
|
||||
* should detect that somehow (house system 'G' is not implemented yet in
|
||||
* GsweHouseSystem, and all other house systems have exactly 12 houses, so
|
||||
* this should not cause trouble yet, though) */
|
||||
for (i = 12; i >= 1; i--) {
|
||||
GsweHouseData *house_data = g_new0(GsweHouseData, 1);
|
||||
|
||||
@ -323,7 +336,10 @@ gswe_moment_calculate_house_positions(GsweMoment *moment)
|
||||
house_data->cusp_position = cusps[i];
|
||||
|
||||
if ((house_data->sign = g_hash_table_lookup(gswe_sign_info_table, GINT_TO_POINTER((gint)ceilf(cusps[i] / 30.0)))) == NULL) {
|
||||
g_error("Calculations brought an unknown sign!");
|
||||
g_list_free_full(moment->priv->house_list, g_free);
|
||||
g_set_error(err, GSWE_MOMENT_ERROR, GSWE_MOMENT_ERROR_UNKNOWN_SIGN, "Calculation brought an unknown sign");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
moment->priv->house_list = g_list_prepend(moment->priv->house_list, house_data);
|
||||
@ -332,15 +348,15 @@ gswe_moment_calculate_house_positions(GsweMoment *moment)
|
||||
moment->priv->house_revision = moment->priv->revision;
|
||||
|
||||
if (gswe_moment_has_planet(moment, GSWE_PLANET_ASCENDENT)) {
|
||||
gswe_calculate_data_by_position(moment, GSWE_PLANET_ASCENDENT, ascmc[0]);
|
||||
gswe_calculate_data_by_position(moment, GSWE_PLANET_ASCENDENT, ascmc[0], err);
|
||||
}
|
||||
|
||||
if (gswe_moment_has_planet(moment, GSWE_PLANET_MC)) {
|
||||
gswe_calculate_data_by_position(moment, GSWE_PLANET_MC, ascmc[1]);
|
||||
gswe_calculate_data_by_position(moment, GSWE_PLANET_MC, ascmc[1], err);
|
||||
}
|
||||
|
||||
if (gswe_moment_has_planet(moment, GSWE_PLANET_VERTEX)) {
|
||||
gswe_calculate_data_by_position(moment, GSWE_PLANET_VERTEX, ascmc[3]);
|
||||
gswe_calculate_data_by_position(moment, GSWE_PLANET_VERTEX, ascmc[3], err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,10 +369,10 @@ gswe_moment_calculate_house_positions(GsweMoment *moment)
|
||||
* Returns: (element-type GsweHouseData) (transfer none): a GList of #GsweHouseData
|
||||
*/
|
||||
GList *
|
||||
gswe_moment_get_house_cusps(GsweMoment *moment)
|
||||
gswe_moment_get_house_cusps(GsweMoment *moment, GError **err)
|
||||
{
|
||||
if (moment->priv->house_revision != moment->priv->revision) {
|
||||
gswe_moment_calculate_house_positions(moment);
|
||||
gswe_moment_calculate_house_positions(moment, err);
|
||||
}
|
||||
|
||||
return moment->priv->house_list;
|
||||
@ -410,12 +426,14 @@ gswe_moment_add_all_planets(GsweMoment *moment)
|
||||
}
|
||||
|
||||
static void
|
||||
gswe_moment_calculate_planet(GsweMoment *moment, GswePlanet planet)
|
||||
gswe_moment_calculate_planet(GsweMoment *moment, GswePlanet planet, GError **err)
|
||||
{
|
||||
GswePlanetData *planet_data = (GswePlanetData *)(g_list_find_custom(moment->priv->planet_list, &planet, find_by_planet_id)->data);
|
||||
gchar serr[AS_MAXCH];
|
||||
gint ret;
|
||||
gdouble x2[6];
|
||||
gdouble x2[6],
|
||||
jd;
|
||||
GError *calc_err = NULL;
|
||||
|
||||
if (planet_data == NULL) {
|
||||
return;
|
||||
@ -432,32 +450,43 @@ gswe_moment_calculate_planet(GsweMoment *moment, GswePlanet planet)
|
||||
}
|
||||
|
||||
swe_set_topo(moment->priv->coordinates.longitude, moment->priv->coordinates.latitude, moment->priv->coordinates.altitude);
|
||||
if ((ret = swe_calc(gswe_timestamp_get_julian_day(moment->priv->timestamp), planet_data->planet_info->sweph_id, SEFLG_SPEED | SEFLG_TOPOCTR, x2, serr)) < 0) {
|
||||
g_warning("Swiss Ephemeris error: %s", serr);
|
||||
jd = gswe_timestamp_get_julian_day(moment->priv->timestamp, err);
|
||||
|
||||
if ((err) && (*err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ret = swe_calc(jd, planet_data->planet_info->sweph_id, SEFLG_SPEED | SEFLG_TOPOCTR, x2, serr)) < 0) {
|
||||
g_set_error(err, GSWE_MOMENT_ERROR, GSWE_MOMENT_ERROR_SWE_ERROR_FATAL, "Swiss Ephemeris error: %s", serr);
|
||||
|
||||
return;
|
||||
} else if (ret != (SEFLG_SPEED | SEFLG_TOPOCTR)) {
|
||||
g_warning("Swiss Ephemeris error: %s", serr);
|
||||
g_set_error(err, GSWE_MOMENT_ERROR, GSWE_MOMENT_ERROR_SWE_ERROR_NONFATAL, "Swiss Ephemeris error: %s", serr);
|
||||
}
|
||||
|
||||
gswe_calculate_data_by_position(moment, planet, x2[0]);
|
||||
gswe_calculate_data_by_position(moment, planet, x2[0], &calc_err);
|
||||
|
||||
if (calc_err != NULL) {
|
||||
g_clear_error(err);
|
||||
|
||||
if (err) {
|
||||
*err = calc_err;
|
||||
}
|
||||
}
|
||||
|
||||
planet_data->retrograde = (x2[3] < 0);
|
||||
}
|
||||
|
||||
void
|
||||
calculate_planet(gpointer data, gpointer user_data)
|
||||
static void
|
||||
calculate_planet(GswePlanetData *planet_data, GsweMoment *moment)
|
||||
{
|
||||
GswePlanetData *planet_data = data;
|
||||
GsweMoment *moment = user_data;
|
||||
|
||||
gswe_moment_calculate_planet(moment, planet_data->planet_id);
|
||||
gswe_moment_calculate_planet(moment, planet_data->planet_id, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
gswe_moment_calculate_all_planets(GsweMoment *moment)
|
||||
{
|
||||
g_list_foreach(moment->priv->planet_list, calculate_planet, moment);
|
||||
g_list_foreach(moment->priv->planet_list, (GFunc)calculate_planet, moment);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -475,11 +504,15 @@ gswe_moment_get_planets(GsweMoment *moment)
|
||||
}
|
||||
|
||||
gint
|
||||
gswe_moment_get_house(GsweMoment *moment, gdouble position)
|
||||
gswe_moment_get_house(GsweMoment *moment, gdouble position, GError **err)
|
||||
{
|
||||
gint i;
|
||||
gswe_moment_calculate_house_positions(moment);
|
||||
gswe_moment_calculate_house_positions(moment, err);
|
||||
|
||||
/* TODO: SWE house system 'G' (Gauquelin sector cusps) have 36 houses; we
|
||||
* should detect that somehow (house system 'G' is not implemented yet in
|
||||
* GsweHouseSystem, and all other house systems have exactly 12 houses, so
|
||||
* this should not cause trouble yet, though) */
|
||||
for (i = 1; i <= 12; i++) {
|
||||
gint j = (i < 12) ? i + 1 : 1;
|
||||
gdouble cusp_i = *(gdouble *)g_list_nth_data(moment->priv->house_list, i - 1),
|
||||
@ -500,15 +533,17 @@ gswe_moment_get_house(GsweMoment *moment, gdouble position)
|
||||
}
|
||||
|
||||
GswePlanetData *
|
||||
gswe_moment_get_planet(GsweMoment *moment, GswePlanet planet)
|
||||
gswe_moment_get_planet(GsweMoment *moment, GswePlanet planet, GError **err)
|
||||
{
|
||||
GswePlanetData *planet_data = (GswePlanetData *)(g_list_find_custom(moment->priv->planet_list, &planet, find_by_planet_id)->data);
|
||||
|
||||
if (planet_data == NULL) {
|
||||
g_set_error(err, GSWE_MOMENT_ERROR, GSWE_MOMENT_ERROR_NONADDED_PLANET, "Specified planet is not added to the moment object");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gswe_moment_calculate_planet(moment, planet);
|
||||
gswe_moment_calculate_planet(moment, planet, err);
|
||||
|
||||
return planet_data;
|
||||
}
|
||||
@ -518,7 +553,7 @@ add_points(GswePlanetData *planet_data, GsweMoment *moment)
|
||||
{
|
||||
guint point;
|
||||
|
||||
gswe_moment_calculate_planet(moment, planet_data->planet_id);
|
||||
gswe_moment_calculate_planet(moment, planet_data->planet_id, NULL);
|
||||
|
||||
point = GPOINTER_TO_INT(g_hash_table_lookup(moment->priv->element_points, GINT_TO_POINTER(planet_data->sign->element))) + planet_data->planet_info->points;
|
||||
g_hash_table_replace(moment->priv->element_points, GINT_TO_POINTER(planet_data->sign->element), GINT_TO_POINTER(point));
|
||||
@ -569,16 +604,30 @@ gswe_moment_get_quality_points(GsweMoment *moment, GsweQuality quality)
|
||||
}
|
||||
|
||||
GsweMoonPhaseData *
|
||||
gswe_moment_get_moon_phase(GsweMoment *moment)
|
||||
gswe_moment_get_moon_phase(GsweMoment *moment, GError **err)
|
||||
{
|
||||
gdouble difference,
|
||||
phase_percent;
|
||||
phase_percent,
|
||||
jd,
|
||||
jdb;
|
||||
|
||||
if (moment->priv->moon_phase_revision == moment->priv->revision) {
|
||||
return &(moment->priv->moon_phase);
|
||||
}
|
||||
|
||||
difference = (gswe_timestamp_get_julian_day(moment->priv->timestamp) - gswe_timestamp_get_julian_day(gswe_full_moon_base_date));
|
||||
jd = gswe_timestamp_get_julian_day(moment->priv->timestamp, err);
|
||||
|
||||
if ((err) && (*err)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jdb = gswe_timestamp_get_julian_day(gswe_full_moon_base_date, err);
|
||||
|
||||
if ((err) && (*err)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
difference = (jd - jdb);
|
||||
phase_percent = fmod((difference * 100) / SYNODIC, 100);
|
||||
|
||||
if (phase_percent < 0) {
|
||||
@ -743,11 +792,17 @@ gswe_moment_get_all_aspects(GsweMoment *moment)
|
||||
* returns NULL.
|
||||
*/
|
||||
GList *
|
||||
gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet)
|
||||
gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet, GError **err)
|
||||
{
|
||||
GList *ret = NULL,
|
||||
*aspect;
|
||||
|
||||
if (!gswe_moment_has_planet(moment, planet)) {
|
||||
g_set_error(err, GSWE_MOMENT_ERROR, GSWE_MOMENT_ERROR_NONADDED_PLANET, "Specified planet is not added to the moment object");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gswe_moment_calculate_aspects(moment);
|
||||
|
||||
for (aspect = moment->priv->aspect_list; aspect; aspect = aspect->next) {
|
||||
@ -888,11 +943,17 @@ gswe_moment_get_all_mirrorpoints(GsweMoment *moment)
|
||||
* returns NULL.
|
||||
*/
|
||||
GList *
|
||||
gswe_moment_get_all_planet_mirrorpoints(GsweMoment *moment, GswePlanet planet)
|
||||
gswe_moment_get_all_planet_mirrorpoints(GsweMoment *moment, GswePlanet planet, GError **err)
|
||||
{
|
||||
GList *ret = NULL,
|
||||
*mirror;
|
||||
|
||||
if (!gswe_moment_has_planet(moment, planet)) {
|
||||
g_set_error(err, GSWE_MOMENT_ERROR, GSWE_MOMENT_ERROR_NONADDED_PLANET, "Specified planet is not added to the moment object");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gswe_moment_calculate_mirrorpoints(moment);
|
||||
|
||||
for (mirror = moment->priv->mirrorpoint_list; mirror; mirror = mirror->next) {
|
||||
@ -952,11 +1013,17 @@ gswe_moment_get_mirror_all_mirrorpoints(GsweMoment *moment, GsweMirror mirror)
|
||||
* returns NULL.
|
||||
*/
|
||||
GList *
|
||||
gswe_moment_get_mirror_planet_mirrorpoints(GsweMoment *moment, GsweMirror mirror, GswePlanet planet)
|
||||
gswe_moment_get_mirror_planet_mirrorpoints(GsweMoment *moment, GsweMirror mirror, GswePlanet planet, GError **err)
|
||||
{
|
||||
GList *ret = NULL,
|
||||
*mirror_l;
|
||||
|
||||
if (!gswe_moment_has_planet(moment, planet)) {
|
||||
g_set_error(err, GSWE_MOMENT_ERROR, GSWE_MOMENT_ERROR_NONADDED_PLANET, "Specified planet is not added to the moment object");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gswe_moment_calculate_mirrorpoints(moment);
|
||||
|
||||
for (mirror_l = moment->priv->mirrorpoint_list; mirror_l; mirror_l = mirror_l->next) {
|
||||
|
@ -24,8 +24,14 @@ GQuark gswe_moment_error_quark(void);
|
||||
*
|
||||
* Error values for GsweTimestamp initialization
|
||||
*/
|
||||
//typedef enum {
|
||||
//} GsweMomentError;
|
||||
typedef enum {
|
||||
GSWE_MOMENT_ERROR_SUCCESS,
|
||||
GSWE_MOMENT_ERROR_UNKNOWN_HSYS,
|
||||
GSWE_MOMENT_ERROR_UNKNOWN_SIGN,
|
||||
GSWE_MOMENT_ERROR_NONADDED_PLANET,
|
||||
GSWE_MOMENT_ERROR_SWE_ERROR_NONFATAL,
|
||||
GSWE_MOMENT_ERROR_SWE_ERROR_FATAL
|
||||
} GsweMomentError;
|
||||
|
||||
/**
|
||||
* GsweCoordinates:
|
||||
@ -139,9 +145,7 @@ struct _GsweMomentClass {
|
||||
/* Parent class structure */
|
||||
GObjectClass parent_class;
|
||||
|
||||
/* Class members */
|
||||
|
||||
/*< private >*/
|
||||
/* Signals */
|
||||
void (*changed)(GsweMoment *moment);
|
||||
|
||||
/* Padding for future expansion */
|
||||
@ -174,22 +178,22 @@ GType gswe_moment_get_type(void);
|
||||
GsweMoment *gswe_moment_new(void);
|
||||
GsweMoment *gswe_moment_new_full(GsweTimestamp *timestamp, gdouble longitude, gdouble latitude, gdouble altitude, GsweHouseSystem house_system);
|
||||
void gswe_moment_set_timestamp(GsweMoment *moment, GsweTimestamp *timestamp);
|
||||
GList *gswe_moment_get_house_cusps(GsweMoment *moment);
|
||||
gint gswe_moment_get_house(GsweMoment *moment, gdouble position);
|
||||
GList *gswe_moment_get_house_cusps(GsweMoment *moment, GError **err);
|
||||
gint gswe_moment_get_house(GsweMoment *moment, gdouble position, GError **err);
|
||||
gboolean gswe_moment_has_planet(GsweMoment *moment, GswePlanet planet);
|
||||
void gswe_moment_add_planet(GsweMoment *moment, GswePlanet planet);
|
||||
void gswe_moment_add_all_planets(GsweMoment *moment);
|
||||
GList *gswe_moment_get_planets(GsweMoment *moment);
|
||||
GswePlanetData *gswe_moment_get_planet(GsweMoment *moment, GswePlanet planet);
|
||||
GswePlanetData *gswe_moment_get_planet(GsweMoment *moment, GswePlanet planet, GError **err);
|
||||
guint gswe_moment_get_element_points(GsweMoment *moment, GsweElement element);
|
||||
guint gswe_moment_get_quality_points(GsweMoment *moment, GsweQuality quality);
|
||||
GsweMoonPhaseData *gswe_moment_get_moon_phase(GsweMoment *moment);
|
||||
GsweMoonPhaseData *gswe_moment_get_moon_phase(GsweMoment *moment, GError **err);
|
||||
GList *gswe_moment_get_all_aspects(GsweMoment *moment);
|
||||
GList *gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet);
|
||||
GList *gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet, GError **err);
|
||||
GList *gswe_moment_get_all_mirrorpoints(GsweMoment *moment);
|
||||
GList *gswe_moment_get_all_planet_mirrorpoints(GsweMoment *moment, GswePlanet planet);
|
||||
GList *gswe_moment_get_all_planet_mirrorpoints(GsweMoment *moment, GswePlanet planet, GError **err);
|
||||
GList *gswe_moment_get_mirror_all_mirrorpoints(GsweMoment *moment, GsweMirror mirror);
|
||||
GList *gswe_moment_get_mirror_planet_mirrorpoints(GsweMoment *moment, GsweMirror mirror, GswePlanet planet);
|
||||
GList *gswe_moment_get_mirror_planet_mirrorpoints(GsweMoment *moment, GsweMirror mirror, GswePlanet planet, GError **err);
|
||||
|
||||
GType gswe_moon_phase_data_get_type(void);
|
||||
#define GSWE_TYPE_MOON_PHASE_DATA (gswe_moon_phase_data_get_type())
|
||||
|
@ -54,9 +54,9 @@ static void gswe_timestamp_dispose(GObject *gobject);
|
||||
static void gswe_timestamp_finalize(GObject *gobject);
|
||||
static void gswe_timestamp_set_property(GObject *gobject, guint prop_id, const GValue *value, GParamSpec *pspec);
|
||||
static void gswe_timestamp_get_property(GObject *gobject, guint prop_id, GValue *value, GParamSpec *pspec);
|
||||
static void gswe_timestamp_calculate_all(GsweTimestamp *timestamp);
|
||||
static void gswe_timestamp_calculate_all(GsweTimestamp *timestamp, GError **err);
|
||||
static void gswe_timestamp_calculate_gregorian(GsweTimestamp *timestamp);
|
||||
static void gswe_timestamp_calculate_julian(GsweTimestamp *timestamp);
|
||||
static void gswe_timestamp_calculate_julian(GsweTimestamp *timestamp, GError **err);
|
||||
|
||||
G_DEFINE_TYPE(GsweTimestamp, gswe_timestamp, G_TYPE_OBJECT);
|
||||
|
||||
@ -87,7 +87,7 @@ gswe_timestamp_class_init(GsweTimestampClass *klass)
|
||||
* If set to TRUE, recalculate timestamp values instantly, when changing a
|
||||
* parameter (e.g. recalculate Julian date when changing Gregorian year).
|
||||
* Otherwise, the values are recalculated only upon request (e.g. on
|
||||
* calling #gswe_timestamp_get_julian_day()).
|
||||
* calling gswe_timestamp_get_julian_day()).
|
||||
*/
|
||||
g_object_class_install_property(gobject_class, PROP_INSTANT_RECALC, g_param_spec_boolean("instant-recalc", "Instant recalculation", "Instantly recalculate values upon parameter change", FALSE, G_PARAM_READWRITE));
|
||||
|
||||
@ -200,47 +200,47 @@ gswe_timestamp_set_property(GObject *object, guint prop_id, const GValue *value,
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_INSTANT_RECALC:
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PROP_GREGORIAN_YEAR:
|
||||
gswe_timestamp_set_gregorian_year(timestamp, g_value_get_int(value));
|
||||
gswe_timestamp_set_gregorian_year(timestamp, g_value_get_int(value), NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PROP_GREGORIAN_MONTH:
|
||||
gswe_timestamp_set_gregorian_month(timestamp, g_value_get_int(value));
|
||||
gswe_timestamp_set_gregorian_month(timestamp, g_value_get_int(value), NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PROP_GREGORIAN_DAY:
|
||||
gswe_timestamp_set_gregorian_day(timestamp, g_value_get_int(value));
|
||||
gswe_timestamp_set_gregorian_day(timestamp, g_value_get_int(value), NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PROP_GREGORIAN_HOUR:
|
||||
gswe_timestamp_set_gregorian_hour(timestamp, g_value_get_int(value));
|
||||
gswe_timestamp_set_gregorian_hour(timestamp, g_value_get_int(value), NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PROP_GREGORIAN_MINUTE:
|
||||
gswe_timestamp_set_gregorian_minute(timestamp, g_value_get_int(value));
|
||||
gswe_timestamp_set_gregorian_minute(timestamp, g_value_get_int(value), NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PROP_GREGORIAN_SECOND:
|
||||
gswe_timestamp_set_gregorian_second(timestamp, g_value_get_int(value));
|
||||
gswe_timestamp_set_gregorian_second(timestamp, g_value_get_int(value), NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PROP_GREGORIAN_MICROSECOND:
|
||||
gswe_timestamp_set_gregorian_microsecond(timestamp, g_value_get_int(value));
|
||||
gswe_timestamp_set_gregorian_microsecond(timestamp, g_value_get_int(value), NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PROP_GREGORIAN_TIMEZONE_OFFSET:
|
||||
gswe_timestamp_set_gregorian_timezone(timestamp, g_value_get_double(value));
|
||||
gswe_timestamp_set_gregorian_timezone(timestamp, g_value_get_double(value), NULL);
|
||||
|
||||
break;
|
||||
|
||||
@ -327,10 +327,10 @@ gswe_timestamp_get_property(GObject *object, guint prop_id, GValue *value, GPara
|
||||
}
|
||||
|
||||
static void
|
||||
gswe_timestamp_calculate_all(GsweTimestamp *timestamp)
|
||||
gswe_timestamp_calculate_all(GsweTimestamp *timestamp, GError **err)
|
||||
{
|
||||
if ((timestamp->priv->valid_dates & VALID_JULIAN_DAY) != VALID_JULIAN_DAY) {
|
||||
gswe_timestamp_calculate_julian(timestamp);
|
||||
gswe_timestamp_calculate_julian(timestamp, err);
|
||||
}
|
||||
|
||||
if ((timestamp->priv->valid_dates & VALID_GREGORIAN) != VALID_GREGORIAN) {
|
||||
@ -353,12 +353,12 @@ gswe_timestamp_calculate_gregorian(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_instant_recalc(GsweTimestamp *timestamp, gboolean instant_recalc)
|
||||
gswe_timestamp_set_instant_recalc(GsweTimestamp *timestamp, gboolean instant_recalc, GError **err)
|
||||
{
|
||||
timestamp->priv->instant_recalc = instant_recalc;
|
||||
|
||||
if (instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,7 +369,7 @@ gswe_timestamp_get_instant_recalc(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_full(GsweTimestamp *timestamp, gint year, gint month, gint day, gint hour, gint minute, gint second, gint microsecond, gdouble time_zone_offset)
|
||||
gswe_timestamp_set_gregorian_full(GsweTimestamp *timestamp, gint year, gint month, gint day, gint hour, gint minute, gint second, gint microsecond, gdouble time_zone_offset, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_year = year;
|
||||
timestamp->priv->gregorian_month = month;
|
||||
@ -382,20 +382,20 @@ gswe_timestamp_set_gregorian_full(GsweTimestamp *timestamp, gint year, gint mont
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_year(GsweTimestamp *timestamp, gint gregorian_year)
|
||||
gswe_timestamp_set_gregorian_year(GsweTimestamp *timestamp, gint gregorian_year, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_year = gregorian_year;
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
@ -410,13 +410,13 @@ gswe_timestamp_get_gregorian_year(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_month(GsweTimestamp *timestamp, gint gregorian_month)
|
||||
gswe_timestamp_set_gregorian_month(GsweTimestamp *timestamp, gint gregorian_month, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_month = gregorian_month;
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
@ -431,13 +431,13 @@ gswe_timestamp_get_gregorian_month(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_day(GsweTimestamp *timestamp, gint gregorian_day)
|
||||
gswe_timestamp_set_gregorian_day(GsweTimestamp *timestamp, gint gregorian_day, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_day = gregorian_day;
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
@ -452,13 +452,13 @@ gswe_timestamp_get_gregorian_day(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_hour(GsweTimestamp *timestamp, gint gregorian_hour)
|
||||
gswe_timestamp_set_gregorian_hour(GsweTimestamp *timestamp, gint gregorian_hour, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_hour = gregorian_hour;
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
@ -473,13 +473,13 @@ gswe_timestamp_get_gregorian_hour(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_minute(GsweTimestamp *timestamp, gint gregorian_minute)
|
||||
gswe_timestamp_set_gregorian_minute(GsweTimestamp *timestamp, gint gregorian_minute, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_minute = gregorian_minute;
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
@ -494,13 +494,13 @@ gswe_timestamp_get_gregorian_minute(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_second(GsweTimestamp *timestamp, gint gregorian_second)
|
||||
gswe_timestamp_set_gregorian_second(GsweTimestamp *timestamp, gint gregorian_second, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_second = gregorian_second;
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
@ -515,13 +515,13 @@ gswe_timestamp_get_gregorian_second(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_microsecond(GsweTimestamp *timestamp, gint gregorian_microsecond)
|
||||
gswe_timestamp_set_gregorian_microsecond(GsweTimestamp *timestamp, gint gregorian_microsecond, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_microsecond = gregorian_microsecond;
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
@ -536,13 +536,13 @@ gswe_timestamp_get_gregorian_microsecond(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
void
|
||||
gswe_timestamp_set_gregorian_timezone(GsweTimestamp *timestamp, gdouble gregorian_timezone_offset)
|
||||
gswe_timestamp_set_gregorian_timezone(GsweTimestamp *timestamp, gdouble gregorian_timezone_offset, GError **err)
|
||||
{
|
||||
timestamp->priv->gregorian_timezone_offset = gregorian_timezone_offset;
|
||||
timestamp->priv->valid_dates = VALID_GREGORIAN;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, err);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
@ -557,7 +557,7 @@ gswe_timestamp_get_gregorian_timezone(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
static void
|
||||
gswe_timestamp_calculate_julian(GsweTimestamp *timestamp)
|
||||
gswe_timestamp_calculate_julian(GsweTimestamp *timestamp, GError **err)
|
||||
{
|
||||
gint utc_year,
|
||||
utc_month,
|
||||
@ -574,13 +574,14 @@ gswe_timestamp_calculate_julian(GsweTimestamp *timestamp)
|
||||
}
|
||||
|
||||
if (timestamp->priv->valid_dates == 0) {
|
||||
g_error("This timestamp object holds no valid values. This can't be good.");
|
||||
g_set_error(err, GSWE_TIMESTAMP_ERROR, GSWE_TIMESTAMP_ERROR_NO_VALID, "This timestamp object holds no valid values");
|
||||
return;
|
||||
}
|
||||
|
||||
swe_utc_time_zone(timestamp->priv->gregorian_year, timestamp->priv->gregorian_month, timestamp->priv->gregorian_day, timestamp->priv->gregorian_hour, timestamp->priv->gregorian_minute, timestamp->priv->gregorian_second + timestamp->priv->gregorian_microsecond / 1000.0, timestamp->priv->gregorian_timezone_offset, &utc_year, &utc_month, &utc_day, &utc_hour, &utc_minute, &utc_second);
|
||||
|
||||
if ((retval = swe_utc_to_jd(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_second, SE_GREG_CAL, dret, serr)) == ERR) {
|
||||
g_error("Swiss Ephemeris error: %s", serr);
|
||||
g_set_error(err, GSWE_TIMESTAMP_ERROR, GSWE_TIMESTAMP_ERROR_SWE_ERROR, "Swiss Ephemeris error: %s", serr);
|
||||
} else {
|
||||
timestamp->priv->julian_day = dret[0];
|
||||
timestamp->priv->valid_dates |= VALID_JULIAN_DAY;
|
||||
@ -594,16 +595,16 @@ gswe_timestamp_set_julian_day(GsweTimestamp *timestamp, gdouble julian_day)
|
||||
timestamp->priv->valid_dates = VALID_JULIAN_DAY;
|
||||
|
||||
if (timestamp->priv->instant_recalc == TRUE) {
|
||||
gswe_timestamp_calculate_all(timestamp);
|
||||
gswe_timestamp_calculate_all(timestamp, NULL);
|
||||
}
|
||||
|
||||
gswe_timestamp_emit_changed(timestamp);
|
||||
}
|
||||
|
||||
gdouble
|
||||
gswe_timestamp_get_julian_day(GsweTimestamp *timestamp)
|
||||
gswe_timestamp_get_julian_day(GsweTimestamp *timestamp, GError **err)
|
||||
{
|
||||
gswe_timestamp_calculate_julian(timestamp);
|
||||
gswe_timestamp_calculate_julian(timestamp, err);
|
||||
|
||||
return timestamp->priv->julian_day;
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ GQuark gswe_timestamp_error_quark(void);
|
||||
*/
|
||||
typedef enum {
|
||||
GSWE_TIMESTAMP_ERROR_INVALID_DATE,
|
||||
GSWE_TIMESTAMP_ERROR_INVALID_TIME
|
||||
GSWE_TIMESTAMP_ERROR_INVALID_TIME,
|
||||
GSWE_TIMESTAMP_ERROR_NO_VALID,
|
||||
GSWE_TIMESTAMP_ERROR_SWE_ERROR
|
||||
} GsweTimestampError;
|
||||
|
||||
struct _GsweTimestamp {
|
||||
@ -47,8 +49,7 @@ struct _GsweTimestampClass {
|
||||
/* Parent class */
|
||||
GObjectClass parent_class;
|
||||
|
||||
/* Class members */
|
||||
/*< private >*/
|
||||
/* Signals */
|
||||
void (*changed)(GsweTimestamp *self);
|
||||
|
||||
/* Padding for future expansion */
|
||||
@ -80,27 +81,27 @@ GType gswe_timestamp_get_type(void);
|
||||
GsweTimestamp *gswe_timestamp_new(void);
|
||||
GsweTimestamp *gswe_timestamp_new_from_julian_day(gdouble julian_day);
|
||||
GsweTimestamp * gswe_timestamp_new_from_gregorian_full(gint year, gint month, gint day, gint hour, gint minute, gint second, gint microsecond, gdouble time_zone_offset);
|
||||
void gswe_timestamp_set_gregorian_full(GsweTimestamp *timestamp, gint year, gint month, gint day, gint hour, gint minute, gint second, gint microsecond, gdouble time_zone_offset);
|
||||
void gswe_timestamp_set_instant_recalc(GsweTimestamp *timestamp, gboolean instant_recalc);
|
||||
void gswe_timestamp_set_gregorian_full(GsweTimestamp *timestamp, gint year, gint month, gint day, gint hour, gint minute, gint second, gint microsecond, gdouble time_zone_offset, GError **err);
|
||||
void gswe_timestamp_set_instant_recalc(GsweTimestamp *timestamp, gboolean instant_recalc, GError **err);
|
||||
gboolean gswe_timestamp_get_instant_recalc(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_gregorian_year(GsweTimestamp *timestamp, gint gregorian_year);
|
||||
void gswe_timestamp_set_gregorian_year(GsweTimestamp *timestamp, gint gregorian_year, GError **err);
|
||||
gint gswe_timestamp_get_gregorian_year(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_gregorian_month(GsweTimestamp *timestamp, gint gregorian_month);
|
||||
void gswe_timestamp_set_gregorian_month(GsweTimestamp *timestamp, gint gregorian_month, GError **err);
|
||||
gint gswe_timestamp_get_gregorian_month(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_gregorian_day(GsweTimestamp *timestamp, gint gregorian_day);
|
||||
void gswe_timestamp_set_gregorian_day(GsweTimestamp *timestamp, gint gregorian_day, GError **err);
|
||||
gint gswe_timestamp_get_gregorian_day(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_gregorian_hour(GsweTimestamp *timestamp, gint gregorian_hour);
|
||||
void gswe_timestamp_set_gregorian_hour(GsweTimestamp *timestamp, gint gregorian_hour, GError **err);
|
||||
gint gswe_timestamp_get_gregorian_hour(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_gregorian_minute(GsweTimestamp *timestamp, gint gregorian_minute);
|
||||
void gswe_timestamp_set_gregorian_minute(GsweTimestamp *timestamp, gint gregorian_minute, GError **err);
|
||||
gint gswe_timestamp_get_gregorian_minute(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_gregorian_second(GsweTimestamp *timestamp, gint gregorian_second);
|
||||
void gswe_timestamp_set_gregorian_second(GsweTimestamp *timestamp, gint gregorian_second, GError **err);
|
||||
gint gswe_timestamp_get_gregorian_second(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_gregorian_microsecond(GsweTimestamp *timestamp, gint gregorian_microsecond);
|
||||
void gswe_timestamp_set_gregorian_microsecond(GsweTimestamp *timestamp, gint gregorian_microsecond, GError **err);
|
||||
gint gswe_timestamp_get_gregorian_microsecond(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_gregorian_timezone(GsweTimestamp *timestamp, gdouble gregorian_timezone_offset);
|
||||
void gswe_timestamp_set_gregorian_timezone(GsweTimestamp *timestamp, gdouble gregorian_timezone_offset, GError **err);
|
||||
gdouble gswe_timestamp_get_gregorian_timezone(GsweTimestamp *timestamp);
|
||||
void gswe_timestamp_set_julian_day(GsweTimestamp *timestamp, gdouble julian_day);
|
||||
gdouble gswe_timestamp_get_julian_day(GsweTimestamp *timestamp);
|
||||
gdouble gswe_timestamp_get_julian_day(GsweTimestamp *timestamp, GError **err);
|
||||
|
||||
#endif /* __SWE_GLIB_GSWE_TIMESTAMP_H__ */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user