summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2005-07-30 16:59:09 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2005-07-30 16:59:09 +0100
commit306a3865d4874417df3ce35e5a1792d194a0a1c6 (patch)
tree69d737675fafd18a8ba610e232911ddecc9bd816 /src
parent02a0aca8283e7acd62eb4223c41a671209e5bf7d (diff)
initial track support
Diffstat (limited to 'src')
-rw-r--r--src/GipfelWidget.H3
-rw-r--r--src/GipfelWidget.cxx55
-rw-r--r--src/Hill.H9
-rw-r--r--src/Hill.cxx10
-rw-r--r--src/Panorama.H4
-rw-r--r--src/Panorama.cxx27
-rw-r--r--src/gipfel.cxx6
7 files changed, 93 insertions, 21 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index 0bfc8ac..c16c4a9 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -31,6 +31,7 @@ class GipfelWidget : public Fl_Widget {
Fl_Image *img;
Hill *cur_mountain;
Hills *marker;
+ Hills *track_points;
Hill *m1, *m2;
Panorama *pan;
Fl_Menu_Button *mb;
@@ -55,6 +56,8 @@ class GipfelWidget : public Fl_Widget {
int load_data(const char *file);
+ int load_track(const char *file);
+
int set_viewpoint(const char *pos);
void set_center_angle(double a);
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index a8a6f00..9f9d10a 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -59,6 +59,7 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) {
for (i=0; i<=3; i++) {
marker->add(new Hill(i * 10, 0));
}
+ track_points = NULL;
fl_register_images();
}
@@ -83,9 +84,27 @@ GipfelWidget::load_image(const char *file) {
int
GipfelWidget::load_data(const char *file) {
- int r;
- r = pan->load_file(file);
- return r;
+ return pan->load_data(file);
+}
+
+int
+GipfelWidget::load_track(const char *file) {
+ track_points = new Hills();
+
+ if (track_points->load(file) != 0) {
+ delete track_points;
+ track_points = NULL;
+ return 1;
+ }
+
+ for (int i=0; i<track_points->get_num(); i++) {
+ track_points->get(i)->flags |= HILL_TRACK_POINT;
+ }
+
+ pan->add_hills(track_points);
+ redraw();
+
+ return 0;
}
int
@@ -126,13 +145,14 @@ GipfelWidget::draw() {
fl_push_clip(x(), y(), w(), h());
img->draw(x(),y(),w(),h(),0,0);
-
+
+ /* hills */
fl_font(FL_HELVETICA, 10);
mnts = pan->get_visible_mountains();
for (i=0; i<mnts->get_num(); i++) {
m = mnts->get(i);
- if (m->duplicate) {
+ if (m->flags & (HILL_DUPLICATE | HILL_TRACK_POINT)) {
continue;
}
@@ -154,6 +174,7 @@ GipfelWidget::draw() {
center_y + m->label_y + y());
}
+ /* markers */
for (i=0; i<marker->get_num(); i++) {
m = marker->get(i);
@@ -163,6 +184,24 @@ GipfelWidget::draw() {
draw_flag(center_x + m->x + x(), center_y + m->y + y(), NULL);
}
+ /* track */
+ if (track_points && track_points->get_num() >= 1) {
+ int last_x, last_y, last_initialized = 0;
+
+ fl_color(FL_RED);
+ for (i=1; i<track_points->get_num(); i++) {
+ if (last_initialized) {
+ fl_line(center_x + x() + last_x,
+ center_y + y() + last_y,
+ center_x + x() + track_points->get(i)->x,
+ center_y + y() + track_points->get(i)->y);
+ }
+ last_x = track_points->get(i)->x;
+ last_y = track_points->get(i)->y;
+ last_initialized++;
+ }
+ }
+
fl_pop_clip();
}
@@ -182,7 +221,7 @@ GipfelWidget::set_labels(Hills *v) {
for (i=0; i<v->get_num(); i++) {
m = v->get(i);
- if (m->duplicate) {
+ if (m->flags & HILL_DUPLICATE) {
continue;
}
@@ -193,7 +232,7 @@ GipfelWidget::set_labels(Hills *v) {
for (j=0; j<v->get_num() && j < i; j++) {
n = v->get(j);
- if (n->duplicate) {
+ if (n->flags & HILL_DUPLICATE) {
continue;
}
@@ -380,7 +419,7 @@ GipfelWidget::update_menuitems(Hills *h) {
menuitems = (Fl_Menu_Item*) calloc(h->get_num(), sizeof(Fl_Menu_Item) + 1);
j = 0;
for (i=0; i<h_sort->get_num(); i++) {
- if (h_sort->get(i)->duplicate) {
+ if (h_sort->get(i)->flags & HILL_DUPLICATE) {
continue;
}
menuitems[j].text = h_sort->get(i)->name;
diff --git a/src/Hill.H b/src/Hill.H
index 68f6df5..b3edf28 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -22,6 +22,11 @@
#ifndef HILL_H
#define HILL_H
+
+#define HILL_DUPLICATE 0x01
+#define HILL_TRACK_POINT 0x02
+#define HILL_VISIBLE 0x04
+
class Hill;
class Hill {
@@ -37,7 +42,7 @@ class Hill {
int x, y;
int label_x, label_y;
char *name;
- int duplicate;
+ int flags;
Hill(const char *n, double p, double l, double h);
@@ -65,6 +70,8 @@ class Hills {
void add(Hill *m);
+ void add(Hills *h);
+
void sort_phi();
void sort_name();
diff --git a/src/Hill.cxx b/src/Hill.cxx
index d189bd7..35c7ada 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -38,7 +38,7 @@ Hill::Hill(const char *n, double p, double l, double h) {
alph = 0.0;
x = 0;
y = 0;
- duplicate = 0;
+ flags = 0;
}
Hill::Hill(int x_tmp, int y_tmp) {
@@ -131,7 +131,7 @@ void Hills::mark_duplicates(double dist) {
while (n && fabs(n->phi - m->phi) <= dist) {
if (fabs(n->lam - m->lam) <= dist &&
fabs(n->height - m->height) <= 50.0 ) {
- n->duplicate = 1;
+ n->flags |= HILL_DUPLICATE;
}
j = j + 1;
n = get(j);
@@ -158,6 +158,12 @@ Hills::add(Hill *m1) {
m[num++] = m1;
}
+void
+Hills::add(Hills *h) {
+ for(int i=0; i<h->get_num(); i++) {
+ add(h->get(i));
+ }
+}
static int
comp_mountains(const void *n1, const void *n2) {
diff --git a/src/Panorama.H b/src/Panorama.H
index 73e6b5d..bd44346 100644
--- a/src/Panorama.H
+++ b/src/Panorama.H
@@ -73,7 +73,9 @@ class Panorama {
~Panorama();
- int load_file(const char *name);
+ int load_data(const char *name);
+
+ void add_hills(Hills *h);
int set_viewpoint(const char *pos);
diff --git a/src/Panorama.cxx b/src/Panorama.cxx
index 8153a15..d163f38 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -73,21 +73,25 @@ Panorama::~Panorama() {
int
-Panorama::load_file(const char *name) {
- visible_mountains->clear();
- mountains->clobber();
-
+Panorama::load_data(const char *name) {
if (mountains->load(name) != 0) {
return 1;
}
mountains->mark_duplicates(0.00001);
-
update_angles();
return 0;
}
+void
+Panorama::add_hills(Hills *h) {
+ mountains->add(h);
+
+ mountains->mark_duplicates(0.00001);
+ update_angles();
+}
+
int
Panorama::set_viewpoint(const char *name) {
if (get_pos(name, &view_phi, &view_lam, &view_height) != 1) {
@@ -173,7 +177,8 @@ Panorama::guess(Hills *p, Hill *m1) {
m1->x = x1_sav;
m1->y = y1_sav;
- if (m1 == m_tmp2 || fabs(m1->alph - m_tmp2->alph) > pi_d *0.7) {
+ if (m_tmp2->flags & HILL_TRACK_POINT ||
+ m1 == m_tmp2 || fabs(m1->alph - m_tmp2->alph) > pi_d *0.7) {
continue;
}
@@ -466,9 +471,10 @@ Panorama::update_close_mountains() {
for (i=0; i<mountains->get_num(); i++) {
m = mountains->get(i);
- if ((m->phi != view_phi || m->lam != view_lam) &&
- (m->height / (m->dist * EARTH_RADIUS)
- > height_dist_ratio)) {
+ if (m->flags & HILL_TRACK_POINT ||
+ ((m->phi != view_phi || m->lam != view_lam) &&
+ (m->height / (m->dist * EARTH_RADIUS)
+ > height_dist_ratio))) {
close_mountains->add(m);
}
@@ -497,6 +503,9 @@ Panorama::update_visible_mountains() {
if (m->a_view < pi_d / 3.0 && m->a_view > - pi_d / 3.0) {
visible_mountains->add(m);
+ m->flags |= HILL_VISIBLE;
+ } else {
+ m->flags &= ~HILL_VISIBLE;
}
}
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index 74dba5e..d5392a0 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -80,6 +80,11 @@ void open_cb() {
}
}
+void track_cb() {
+ char *file = fl_file_chooser("Track File?", NULL, NULL);
+ gipf->load_track(file);
+}
+
void scale_cb(Fl_Slider* o, void*) {
if (gipf) {
gipf->set_scale(o->value());
@@ -151,6 +156,7 @@ void about_cb() {
Fl_Menu_Item menuitems[] = {
{ "&File", 0, 0, 0, FL_SUBMENU },
+ { "Load &Track", FL_CTRL + 't', (Fl_Callback *)track_cb, 0 },
{ "&Quit", FL_CTRL + 'q', (Fl_Callback *)quit_cb, 0 },
{0},
{ "&Help", 0, 0, 0, FL_SUBMENU },