]> err.no Git - mapper/commitdiff
Code formating
authorKaj-Michael Lang <milang@angel.tal.org>
Fri, 19 Oct 2007 10:57:38 +0000 (13:57 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Fri, 19 Oct 2007 10:57:38 +0000 (13:57 +0300)
src/route.c

index ba29e241b15eb052ab9c617d50c80e7399781bc4..c9886542b32a61065e85db664aa2ee7d10543db8 100644 (file)
@@ -100,6 +100,9 @@ if (open_file(&buffer, NULL, &size, &_route_dir_uri, NULL, GTK_FILE_CHOOSER_ACTI
 return FALSE;
 }
 
+/**
+ * Ask user to save route
+ */
 gboolean
 route_save(void)
 {
@@ -117,45 +120,42 @@ if (file_save(&_route_dir_uri, &_route_dir_uri, &handle)) {
 return FALSE;
 }
 
-gboolean 
-origin_type_selected(GtkWidget * toggle, OriginToggleInfo * oti)
+/**
+ *
+ */
+static gboolean 
+origin_type_selected_cb(GtkWidget * toggle, OriginToggleInfo * oti)
 {
+if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))) {
+       if (toggle == oti->rad_use_gps) {
+               gchar buffer[80];
+               gchar strlat[32];
+               gchar strlon[32];
+               g_ascii_formatd(strlat, 32, "%.06f", _gps.lat);
+               g_ascii_formatd(strlon, 32, "%.06f", _gps.lon);
+               snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
+               gtk_entry_set_text(GTK_ENTRY(oti->txt_from), buffer);
+       } else if (toggle == oti->rad_use_route) {
+               gchar buffer[80];
+               gchar strlat[32];
+               gchar strlon[32];
+               Point *p;
+               gdouble lat, lon;
 
-       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))) {
-               if (toggle == oti->rad_use_gps) {
-                       gchar buffer[80];
-                       gchar strlat[32];
-                       gchar strlon[32];
-                       g_ascii_formatd(strlat, 32, "%.06f", _gps.lat);
-                       g_ascii_formatd(strlon, 32, "%.06f", _gps.lon);
-                       snprintf(buffer, sizeof(buffer), "%s, %s", strlat,
-                                strlon);
-                       gtk_entry_set_text(GTK_ENTRY(oti->txt_from), buffer);
-               } else if (toggle == oti->rad_use_route) {
-                       gchar buffer[80];
-                       gchar strlat[32];
-                       gchar strlon[32];
-                       Point *p;
-                       gfloat lat, lon;
-
-                       /* Use last non-zero route point. */
-                       for (p = _route.tail; !p->unity; p--) {
-                       }
-
-                       unit2latlon(p->unitx, p->unity, lat, lon);
-                       g_ascii_formatd(strlat, 32, "%.06f", lat);
-                       g_ascii_formatd(strlon, 32, "%.06f", lon);
-                       snprintf(buffer, sizeof(buffer), "%s, %s", strlat,
-                                strlon);
-                       gtk_entry_set_text(GTK_ENTRY(oti->txt_from), buffer);
+               /* Use last non-zero route point. */
+               for (p = _route.tail; !p->unity; p--) {
                }
 
-               gtk_widget_set_sensitive(oti->txt_from,
-                                        toggle == oti->rad_use_text);
-               gtk_widget_set_sensitive(oti->chk_auto,
-                                        toggle == oti->rad_use_gps);
+               unit2latlon(p->unitx, p->unity, lat, lon);
+               g_ascii_formatd(strlat, 32, "%.06f", lat);
+               g_ascii_formatd(strlon, 32, "%.06f", lon);
+               snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
+               gtk_entry_set_text(GTK_ENTRY(oti->txt_from), buffer);
        }
-       return TRUE;
+       gtk_widget_set_sensitive(oti->txt_from, toggle == oti->rad_use_text);
+       gtk_widget_set_sensitive(oti->chk_auto, toggle == oti->rad_use_gps);
+}
+return TRUE;
 }
 
 /**
@@ -271,7 +271,7 @@ dialog = gtk_dialog_new_with_buttons(_("Download Route"),
                             GTK_STOCK_CANCEL,
                             GTK_RESPONSE_REJECT, NULL);
 
-#ifdef WITH_OSSO
+#ifdef WITH_OSSO_HELP
 /* Enable the help button. */
 ossohelp_dialog_help_enable(GTK_DIALOG(dialog), HELP_ID_DOWNROUTE, _osso);
 #endif
@@ -337,9 +337,9 @@ gtk_table_attach(GTK_TABLE(table),
 gtk_entry_set_completion(GTK_ENTRY(oti.txt_to), to_comp);
 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_to), 25);
 
-g_signal_connect(G_OBJECT(oti.rad_use_gps), "toggled", G_CALLBACK(origin_type_selected), &oti);
-g_signal_connect(G_OBJECT(oti.rad_use_route), "toggled", G_CALLBACK(origin_type_selected), &oti);
-g_signal_connect(G_OBJECT(oti.rad_use_text), "toggled", G_CALLBACK(origin_type_selected), &oti);
+g_signal_connect(G_OBJECT(oti.rad_use_gps), "toggled", G_CALLBACK(origin_type_selected_cb), &oti);
+g_signal_connect(G_OBJECT(oti.rad_use_route), "toggled", G_CALLBACK(origin_type_selected_cb), &oti);
+g_signal_connect(G_OBJECT(oti.rad_use_text), "toggled", G_CALLBACK(origin_type_selected_cb), &oti);
 
 #if defined (WITH_HILDON) && defined (HILDON_AUTOCAP)
 g_object_set(G_OBJECT(oti.txt_from), HILDON_AUTOCAP, FALSE, NULL);
@@ -484,37 +484,37 @@ return TRUE;
 WayPoint *
 find_nearest_waypoint(guint unitx, guint unity)
 {
-       WayPoint *wcurr;
-       WayPoint *wnear;
-       guint64 nearest_squared;
-       Point pos = { unitx, unity, 0, NAN };
-
-       wcurr = wnear = _route.whead;
-       if (wcurr && wcurr != _route.wtail) {
-               nearest_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
-
-               while (wcurr++ != _route.wtail) {
-                       guint64 test_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
-                       if (test_squared < nearest_squared) {
-                               wnear = wcurr;
-                               nearest_squared = test_squared;
-                       }
+WayPoint *wcurr;
+WayPoint *wnear;
+guint64 nearest_squared;
+Point pos = { unitx, unity, 0, NAN };
+
+wcurr = wnear = _route.whead;
+if (wcurr && wcurr != _route.wtail) {
+       nearest_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
+
+       while (wcurr++ != _route.wtail) {
+               guint64 test_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
+               if (test_squared < nearest_squared) {
+                       wnear = wcurr;
+                       nearest_squared = test_squared;
                }
        }
+}
 
-       if (wnear) {
-               /* Only use the waypoint if it is within a 6*_draw_width square drawn
-                * around the position. This is consistent with select_poi(). */
-               if (abs(unitx - wnear->point->unitx) <
-                   pixel2unit(3 * _draw_width)
-                   && abs(unity - wnear->point->unity) <
-                   pixel2unit(3 * _draw_width))
-                       return wnear;
-       }
+if (wnear) {
+       /* Only use the waypoint if it is within a 6*_draw_width square drawn
+        * around the position. This is consistent with select_poi(). */
+       if (abs(unitx - wnear->point->unitx) <
+           pixel2unit(3 * _draw_width)
+           && abs(unity - wnear->point->unity) <
+           pixel2unit(3 * _draw_width))
+               return wnear;
+}
 
-       MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
+MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
 
-       return NULL;
+return NULL;
 }
 
 /**
@@ -526,95 +526,92 @@ find_nearest_waypoint(guint unitx, guint unity)
 gboolean 
 route_update_nears(gboolean quick)
 {
-       gboolean ret = FALSE;
-       Point *curr, *near;
-       WayPoint *wcurr, *wnext;
-       guint64 near_dist_squared;
-
-       /* If we have waypoints (_next_way != NULL), then determine the "next
-        * waypoint", which is defined as the waypoint after the nearest point,
-        * UNLESS we've passed that waypoint, in which case the waypoint after
-        * that waypoint becomes the "next" waypoint. */
-       if (_next_way) {
-               /* First, set near_dist_squared with the new distance from
-                * _near_point. */
-               near = _near_point;
-               near_dist_squared = DISTANCE_SQUARED(_pos, *near);
-
-               /* Now, search _route for a closer point.  If quick is TRUE, then we'll
-                * only search forward, only as long as we keep finding closer points.
-                */
-               for (curr = _near_point; curr++ != _route.tail;) {
-                       if (curr->unity) {
-                               guint dist_squared =
-                                   DISTANCE_SQUARED(_pos, *curr);
-                               if (dist_squared <= near_dist_squared) {
-                                       near = curr;
-                                       near_dist_squared = dist_squared;
-                               } else if (quick)
-                                       break;
-                       }
-               }
-
-               /* Update _near_point. */
-               _near_point = near;
-               _near_point_dist_squared = near_dist_squared;
-
-               for (wnext = wcurr = _next_way; wcurr != _route.wtail; wcurr++) {
-                       if (wcurr->point < near
-                           /* Okay, this else if expression warrants explanation.  If the
-                            * nearest track point happens to be a waypoint, then we want to
-                            * check if we have "passed" that waypoint.  To check this, we
-                            * test the distance from _pos to the waypoint and from _pos to
-                            * _next_wpt, and if the former is increasing and the latter is
-                            * decreasing, then we have passed the waypoint, and thus we
-                            * should skip it.  Note that if there is no _next_wpt, then
-                            * there is no next waypoint, so we do not skip it in that case. */
-                           || (wcurr->point == near && quick
-                               && (_next_wpt && (DISTANCE_SQUARED(_pos, *near) > _next_way_dist_squared
-                                       && DISTANCE_SQUARED(_pos, *_next_wpt) < _next_wpt_dist_squared))))
-                               wnext = wcurr + 1;
-                       else
+gboolean ret = FALSE;
+Point *curr, *near;
+WayPoint *wcurr, *wnext;
+guint64 near_dist_squared;
+
+/* If we have waypoints (_next_way != NULL), then determine the "next
+ * waypoint", which is defined as the waypoint after the nearest point,
+ * UNLESS we've passed that waypoint, in which case the waypoint after
+ * that waypoint becomes the "next" waypoint. */
+if (_next_way) {
+       /* First, set near_dist_squared with the new distance from
+        * _near_point. */
+       near = _near_point;
+       near_dist_squared = DISTANCE_SQUARED(_pos, *near);
+
+       /* Now, search _route for a closer point.  If quick is TRUE, then we'll
+        * only search forward, only as long as we keep finding closer points.
+        */
+       for (curr = _near_point; curr++ != _route.tail;) {
+               if (curr->unity) {
+                       guint dist_squared = DISTANCE_SQUARED(_pos, *curr);
+                       if (dist_squared <= near_dist_squared) {
+                               near = curr;
+                               near_dist_squared = dist_squared;
+                       } else if (quick)
                                break;
                }
+       }
 
-               if (wnext == _route.wtail && (wnext->point < near
-                                             || (wnext->point == near && quick
-                                                 && (_next_wpt && (DISTANCE_SQUARED (_pos, *near) > _next_way_dist_squared
-                                                      && DISTANCE_SQUARED(_pos, *_next_wpt) < _next_wpt_dist_squared)))))
-               {
-                       _next_way = NULL;
-                       _next_wpt = NULL;
-                       _next_way_dist_squared = -1;
-                       _next_wpt_dist_squared = -1;
-                       ret = TRUE;
-               }
-               /* Only update _next_way (and consequently _next_wpt) if _next_way is
-                * different, and record that fact for return. */
-               else {
-                       if (!quick || _next_way != wnext) {
-                               _next_way = wnext;
-                               _next_wpt = wnext->point;
-                               if (_next_wpt == _route.tail)
-                                       _next_wpt = NULL;
-                               else {
-                                       while (!(++_next_wpt)->unity) {
-                                               if (_next_wpt == _route.tail) {
-                                                       _next_wpt = NULL;
-                                                       break;
-                                               }
+       /* Update _near_point. */
+       _near_point = near;
+       _near_point_dist_squared = near_dist_squared;
+
+       for (wnext = wcurr = _next_way; wcurr != _route.wtail; wcurr++) {
+               if (wcurr->point < near
+                   /* Okay, this else if expression warrants explanation.  If the
+                    * nearest track point happens to be a waypoint, then we want to
+                    * check if we have "passed" that waypoint.  To check this, we
+                    * test the distance from _pos to the waypoint and from _pos to
+                    * _next_wpt, and if the former is increasing and the latter is
+                    * decreasing, then we have passed the waypoint, and thus we
+                    * should skip it.  Note that if there is no _next_wpt, then
+                    * there is no next waypoint, so we do not skip it in that case. */
+                   || (wcurr->point == near && quick
+                       && (_next_wpt && (DISTANCE_SQUARED(_pos, *near) > _next_way_dist_squared
+                               && DISTANCE_SQUARED(_pos, *_next_wpt) < _next_wpt_dist_squared))))
+                       wnext = wcurr + 1;
+               else
+                       break;
+       }
+
+       if (wnext == _route.wtail && (wnext->point < near
+                                     || (wnext->point == near && quick
+                                         && (_next_wpt && (DISTANCE_SQUARED (_pos, *near) > _next_way_dist_squared
+                                              && DISTANCE_SQUARED(_pos, *_next_wpt) < _next_wpt_dist_squared)))))
+       {
+               _next_way = NULL;
+               _next_wpt = NULL;
+               _next_way_dist_squared = -1;
+               _next_wpt_dist_squared = -1;
+               ret = TRUE;
+       }
+       /* Only update _next_way (and consequently _next_wpt) if _next_way is
+        * different, and record that fact for return. */
+       else {
+               if (!quick || _next_way != wnext) {
+                       _next_way = wnext;
+                       _next_wpt = wnext->point;
+                       if (_next_wpt == _route.tail)
+                               _next_wpt = NULL;
+                       else {
+                               while (!(++_next_wpt)->unity) {
+                                       if (_next_wpt == _route.tail) {
+                                               _next_wpt = NULL;
+                                               break;
                                        }
                                }
-                               ret = TRUE;
                        }
-                       _next_way_dist_squared = DISTANCE_SQUARED(_pos, *wnext->point);
-                       if (_next_wpt)
-                               _next_wpt_dist_squared =
-                                   DISTANCE_SQUARED(_pos, *_next_wpt);
+                       ret = TRUE;
                }
+               _next_way_dist_squared = DISTANCE_SQUARED(_pos, *wnext->point);
+               if (_next_wpt)
+                       _next_wpt_dist_squared = DISTANCE_SQUARED(_pos, *_next_wpt);
        }
-
-       return ret;
+}
+return ret;
 }
 
 /**
@@ -624,28 +621,26 @@ route_update_nears(gboolean quick)
 void 
 route_find_nearest_point()
 {
-
-       /* Initialize _near_point to first non-zero point. */
-       _near_point = _route.head;
-       while (!_near_point->unity && _near_point != _route.tail)
-               _near_point++;
-
-       /* Initialize _next_way. */
-       if (_route.wtail == _route.whead - 1
-           || (_autoroute_data.enabled && _route.wtail == _route.whead))
-               _next_way = NULL;
-       else
-               /* We have at least one waypoint. */
-               _next_way =
-                   (_autoroute_data.enabled ? _route.whead + 1 : _route.whead);
-       _next_way_dist_squared = -1;
-
-       /* Initialize _next_wpt. */
-       _next_wpt = NULL;
-       _next_wpt_dist_squared = -1;
-
-       route_update_nears(FALSE);
-
+/* Initialize _near_point to first non-zero point. */
+_near_point = _route.head;
+while (!_near_point->unity && _near_point != _route.tail)
+       _near_point++;
+
+/* Initialize _next_way. */
+if (_route.wtail == _route.whead - 1
+    || (_autoroute_data.enabled && _route.wtail == _route.whead))
+       _next_way = NULL;
+else
+       /* We have at least one waypoint. */
+       _next_way = (_autoroute_data.enabled ? _route.whead + 1 : _route.whead);
+
+_next_way_dist_squared = -1;
+
+/* Initialize _next_wpt. */
+_next_wpt = NULL;
+_next_wpt_dist_squared = -1;
+
+route_update_nears(FALSE);
 }
 
 /**
@@ -654,81 +649,75 @@ route_find_nearest_point()
  * next waypoint.
  */
 gboolean 
-route_show_distance_to(Point * point)
+route_show_distance_to(Point *point)
 {
-       gchar buffer[80];
-       gfloat lat1, lon1, lat2, lon2;
-       gdouble sum = 0.0;
-
-       /* If point is NULL, use the next waypoint. */
-       if (point == NULL && _next_way)
-               point = _next_way->point;
-
-       /* If point is still NULL, return an error. */
-       if (point == NULL) {
-               return FALSE;
-       }
-
-       unit2latlon(_pos.unitx, _pos.unity, lat1, lon1);
-       if (point > _near_point) {
-               Point *curr;
-               /* Skip _near_point in case we have already passed it. */
-               for (curr = _near_point + 1; curr <= point; ++curr) {
-                       if (curr->unity) {
-                               unit2latlon(curr->unitx, curr->unity, lat2,
-                                           lon2);
-                               sum += calculate_distance(lat1, lon1, lat2, lon2);
-                               lat1 = lat2;
-                               lon1 = lon2;
-                       }
+gchar buffer[80];
+gdouble lat1, lon1, lat2, lon2;
+gdouble sum = 0.0;
+
+/* If point is NULL, use the next waypoint. */
+if (point == NULL && _next_way)
+       point = _next_way->point;
+
+/* If point is still NULL, return an error. */
+if (point == NULL)
+       return FALSE;
+
+unit2latlon(_pos.unitx, _pos.unity, lat1, lon1);
+if (point > _near_point) {
+       Point *curr;
+       /* Skip _near_point in case we have already passed it. */
+       for (curr = _near_point + 1; curr <= point; ++curr) {
+               if (curr->unity) {
+                       unit2latlon(curr->unitx, curr->unity, lat2, lon2);
+                       sum += calculate_distance(lat1, lon1, lat2, lon2);
+                       lat1 = lat2;
+                       lon1 = lon2;
                }
-       } else if (point < _near_point) {
-               Point *curr;
-               /* Skip _near_point in case we have already passed it. */
-               for (curr = _near_point - 1; curr >= point; --curr) {
-                       if (curr->unity) {
-                               unit2latlon(curr->unitx, curr->unity, lat2,
-                                           lon2);
-                               sum += calculate_distance(lat1, lon1, lat2, lon2);
-                               lat1 = lat2;
-                               lon1 = lon2;
-                       }
+       }
+} else if (point < _near_point) {
+       Point *curr;
+       /* Skip _near_point in case we have already passed it. */
+       for (curr = _near_point - 1; curr >= point; --curr) {
+               if (curr->unity) {
+                       unit2latlon(curr->unitx, curr->unity, lat2, lon2);
+                       sum += calculate_distance(lat1, lon1, lat2, lon2);
+                       lat1 = lat2;
+                       lon1 = lon2;
                }
-       } else {
-               /* Waypoint _is_ the nearest point. */
-               unit2latlon(_near_point->unitx, _near_point->unity, lat2, lon2);
-               sum += calculate_distance(lat1, lon1, lat2, lon2);
        }
+} else {
+       /* Waypoint _is_ the nearest point. */
+       unit2latlon(_near_point->unitx, _near_point->unity, lat2, lon2);
+       sum += calculate_distance(lat1, lon1, lat2, lon2);
+}
 
-       snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"),
-                sum * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
-       MACRO_BANNER_SHOW_INFO(_window, buffer);
+g_snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"), sum * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
+MACRO_BANNER_SHOW_INFO(_window, buffer);
 
-       return TRUE;
+return TRUE;
 }
 
 void 
 route_show_distance_to_next()
 {
-
-       if (!route_show_distance_to(NULL)) {
-               MACRO_BANNER_SHOW_INFO(_window,
-                                      _("There is no next waypoint."));
-       }
+if (!route_show_distance_to(NULL)) {
+       MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
+}
 }
 
 void 
 route_show_distance_to_last()
 {
-
-       if (_route.head != _route.tail) {
-               /* Find last non-zero point. */
-               Point *p;
-               for (p = _route.tail; !p->unity; p--) {
-               }
-               route_show_distance_to(p);
-       } else {
-               MACRO_BANNER_SHOW_INFO(_window,
-                                      _("The current route is empty."));
+if (_route.head != _route.tail) {
+       /* Find last non-zero point. */
+       Point *p;
+       for (p = _route.tail; !p->unity; p--) {
+       }
+       route_show_distance_to(p);
+} else {
+       MACRO_BANNER_SHOW_INFO(_window, _("The current route is empty."));
        }
 }
+
+