Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

gtkfmaps.c

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU Library General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00015  */
00016 
00017 /* gtkfmaps.c
00018  *
00019  * Widget for map display
00020  *
00021  */
00022 #include <math.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <gtk/gtkmain.h>
00026 #include <gtk/gtksignal.h>
00027 #include <gtkgl/gtkglarea.h>
00028 #include <GL/gl.h>
00029 
00030 #include "gtkfmaps.h"
00031 #include "gtkfmapsproj.h"
00032 
00033 #define FMAPS_DEFAULT_WIDTH 200
00034 #define FMAPS_DEFAULT_HEIGHT 100
00035 
00036 static void gtk_fmaps_class_init        (GtkFMapsClass  *klass);
00037 static void gtk_fmaps_init              (GtkFMaps       *fmapsw);
00038 static void gtk_fmaps_destroy           (GtkObject      *object);
00039 static void gtk_fmaps_realize           (GtkWidget      *widget);
00040 static void gtk_fmaps_size_request      (GtkWidget      *widget,
00041                                          GtkRequisition *requisition);
00042 static void gtk_fmaps_size_allocate     (GtkWidget      *widget,
00043                                          GtkAllocation  *allocation);
00044 static gint gtk_fmaps_expose            (GtkWidget      *widget,
00045                                          GdkEventExpose *event);                                
00046 static void gtk_fmaps_update            (GtkFMaps       *fmaps);
00047 static void gtk_fmaps_adjustment_changed (GtkAdjustment *adjustment,
00048                                          gpointer       data);
00049 static void gtk_fmaps_adjustment_value_changed (GtkAdjustment *adjustment,
00050                                          gpointer       data);
00051 static gint gtk_fmaps_button_press      (GtkWidget      *widget,
00052                                          GdkEventButton *event);
00053                         
00054 /* Local data */
00055 
00056 static GtkGLAreaClass *parent_class = NULL;
00057 
00058 guint
00059 gtk_fmaps_get_type ()
00060 {
00061   static guint fmaps_type = 0;
00062 
00063   if (!fmaps_type)
00064   {
00065     GtkTypeInfo fmaps_info =
00066     {
00067       "GtkFMaps",
00068       sizeof (GtkFMaps),
00069       sizeof (GtkFMapsClass),
00070       (GtkClassInitFunc) gtk_fmaps_class_init,
00071       (GtkObjectInitFunc) gtk_fmaps_init,
00072       (GtkArgSetFunc) NULL,    /* reserved_1 */
00073       (GtkArgGetFunc) NULL,    /* reserved_2 */
00074       (GtkClassInitFunc) NULL
00075     };
00076 
00077     fmaps_type = gtk_type_unique (GTK_TYPE_GL_AREA, &fmaps_info);
00078   }
00079 
00080   return (fmaps_type);
00081 }                               
00082 
00083 
00084 static void
00085 gtk_fmaps_class_init (GtkFMapsClass *class)
00086 {
00087   GtkObjectClass *object_class;
00088   GtkWidgetClass *widget_class;
00089   GtkGLAreaClass *glarea_class;
00090 
00091 
00092   object_class = (GtkObjectClass*) class;
00093   widget_class = (GtkWidgetClass*) class;
00094   glarea_class = (GtkGLAreaClass*) class;
00095 
00096   parent_class = gtk_type_class (GTK_TYPE_GL_AREA);
00097 
00098   object_class->destroy         = gtk_fmaps_destroy;
00099 
00100   widget_class->realize         = gtk_fmaps_realize;
00101   widget_class->expose_event    = gtk_fmaps_expose;
00102   widget_class->size_request    = gtk_fmaps_size_request;
00103   widget_class->size_allocate   = gtk_fmaps_size_allocate;
00104   widget_class->button_press_event = gtk_fmaps_button_press;
00105 
00106 }
00107 
00108 static void
00109 gtk_fmaps_init (GtkFMaps *fmaps)
00110 {
00111 
00112   /* set default values of struct FMaps*/
00113   fmaps->old_value = 0;
00114   fmaps->old_lower = 0;
00115   fmaps->old_upper = 0;
00116   fmaps->adjustment = NULL;
00117 
00118   fmaps->centerx=0;
00119   fmaps->centery=0;
00120   fmaps->width=20;
00121   fmaps->height=10;
00122   fmaps->zoom=1;
00123 
00124   fmaps->actionstatus=ACTION_NONE;
00125 
00126   fmaps->nbtables = 0;          /* no tables loaded */
00127   fmaps->projdatum=NULL;        /* no preojection defined */
00128 
00129 }
00130 
00131 GtkWidget*
00132 gtk_fmaps_new (GtkAdjustment *adjustment,PGconn *conn)
00133 {
00134   GtkWidget *widget;
00135   GtkFMaps *fmaps;
00136   GtkGLArea *glarea;
00137   GdkVisual *visual;
00138   GdkGLContext *glcontext;
00139 
00140   int attrlist[] = {
00141     GDK_GL_RGBA,
00142     GDK_GL_RED_SIZE,1,
00143     GDK_GL_GREEN_SIZE,1,
00144     GDK_GL_BLUE_SIZE,1,
00145     GDK_GL_DOUBLEBUFFER,
00146     GDK_GL_NONE
00147   };
00148 
00149   g_return_val_if_fail(conn!=NULL,NULL);
00150 
00151   if (gdk_gl_query()==FALSE)
00152   {
00153     g_warning("OpenGL not supported");
00154     return (NULL);
00155   }
00156 
00157   widget = gtk_widget_new (GTK_TYPE_FMAPS,NULL);
00158 
00159   if (!adjustment)
00160   {
00161     adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
00162   }
00163 
00164   gtk_fmaps_set_adjustment (GTK_FMAPS(widget), adjustment);
00165 
00166   fmaps = GTK_FMAPS(widget);
00167   /* set the connection to the database */
00168   fmaps->conn = conn;
00169 
00170   glarea = (GtkGLArea *) fmaps;
00171 
00172   visual = gdk_gl_choose_visual(attrlist);
00173   if (visual == NULL)
00174     return NULL;
00175 
00176   glcontext = gdk_gl_context_share_new(visual, NULL, TRUE);
00177   if (glcontext == NULL)
00178     return NULL;
00179 
00180   /* use colormap and visual suitable for OpenGL rendering */
00181   gtk_widget_push_colormap(gdk_colormap_new(visual,TRUE));
00182   gtk_widget_push_visual(visual);
00183 
00184   glarea->glcontext = glcontext;
00185 
00186   /* pop back defaults */
00187   gtk_widget_pop_visual();
00188   gtk_widget_pop_colormap();
00189 
00190   return (widget);
00191 }
00192 
00193 static void
00194 gtk_fmaps_destroy (GtkObject *object)
00195 {
00196   GtkFMaps *fmaps;
00197 
00198   g_return_if_fail (object!=NULL);
00199   g_return_if_fail (GTK_IS_FMAPS(object));
00200 
00201   fmaps = GTK_FMAPS (object);
00202 
00203   if (fmaps->adjustment)
00204   {
00205     gtk_object_unref (GTK_OBJECT (fmaps->adjustment));
00206   }
00207   if (GTK_OBJECT_CLASS (parent_class)->destroy)
00208   {
00209     (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
00210   }
00211 
00212 }
00213 
00214 GtkAdjustment*
00215 gtk_fmaps_get_adjustment (GtkFMaps *fmaps)
00216 {
00217   g_return_val_if_fail (fmaps != NULL, NULL);
00218   g_return_val_if_fail (GTK_IS_FMAPS (fmaps), NULL);
00219 
00220   return fmaps->adjustment;
00221 }
00222 
00223 void
00224 gtk_fmaps_set_adjustment (GtkFMaps *fmaps,
00225                            GtkAdjustment *adjustment)
00226 {
00227   g_return_if_fail (fmaps != NULL);
00228   g_return_if_fail (GTK_IS_FMAPS (fmaps));
00229 
00230   if (fmaps->adjustment)
00231   {
00232     gtk_signal_disconnect_by_data (GTK_OBJECT (fmaps->adjustment), (gpointer) fmaps);
00233     gtk_object_unref (GTK_OBJECT (fmaps->adjustment));
00234   }
00235 
00236   fmaps->adjustment = adjustment;
00237   gtk_object_ref (GTK_OBJECT (fmaps->adjustment));
00238 
00239   gtk_signal_connect    (GTK_OBJECT(adjustment), "changed",
00240                          (GtkSignalFunc) gtk_fmaps_adjustment_changed,
00241                          (gpointer) fmaps);
00242 
00243   gtk_signal_connect    (GTK_OBJECT(adjustment), "value_changed",
00244                          (GtkSignalFunc) gtk_fmaps_adjustment_value_changed,
00245                          (gpointer) fmaps);                     
00246 
00247   fmaps->old_value = adjustment->value;
00248   fmaps->old_lower = adjustment->lower;
00249   fmaps->old_upper = adjustment->upper;
00250 
00251   gtk_fmaps_update (fmaps);
00252 
00253 }       
00254 
00255 static void
00256 gtk_fmaps_realize (GtkWidget *widget)
00257 {
00258   GtkFMaps *fmaps;
00259   GdkWindowAttr attributes;
00260   gint attributes_mask;
00261   gdouble dxy;
00262 
00263   g_return_if_fail (widget!=NULL);
00264   g_return_if_fail (GTK_IS_FMAPS (widget));
00265 
00266   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
00267   fmaps= GTK_FMAPS (widget);
00268 
00269   attributes.x = widget->allocation.x;
00270   attributes.y = widget->allocation.y;
00271   attributes.width = widget->allocation.width;
00272   attributes.height = widget->allocation.height;
00273   attributes.wclass = GDK_INPUT_OUTPUT;
00274   attributes.window_type = GDK_WINDOW_CHILD;
00275   attributes.event_mask = gtk_widget_get_events (widget) |
00276     GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK ;
00277   attributes.visual = gtk_widget_get_visual (widget);
00278   attributes.colormap = gtk_widget_get_colormap (widget);
00279 
00280   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
00281   widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
00282 
00283   widget->style = gtk_style_attach (widget->style, widget->window);
00284 
00285   gdk_window_set_user_data (widget->window, widget);
00286 
00287   gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
00288   dxy=1;
00289   /* OpenGL functions can be called only if make_current returns true */
00290   if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
00291     {
00292       glViewport(0,0, widget->allocation.width, widget->allocation.height);
00293       glMatrixMode(GL_PROJECTION);
00294       glLoadIdentity();
00295       glOrtho(-widget->allocation.width/2,widget->allocation.width/2,-widget->allocation.height/2, widget->allocation.height/2, 1,-1);
00296       glMatrixMode(GL_MODELVIEW);
00297       if (widget->allocation.height!=0)
00298       {
00299         dxy=(gdouble)widget->allocation.width/(gdouble)widget->allocation.height;
00300       }
00301       glLoadIdentity();
00302 
00303       /*glScaled(1,dxy,1);*/
00304     }
00305 
00306 
00307 }
00308 
00309 static void
00310 gtk_fmaps_size_request (GtkWidget *widget,
00311                         GtkRequisition *requisition)
00312 {
00313 
00314   requisition->width = FMAPS_DEFAULT_WIDTH;
00315   requisition->height = FMAPS_DEFAULT_HEIGHT;
00316 
00317 }
00318 
00319 static void
00320 gtk_fmaps_size_allocate (GtkWidget *widget,
00321                          GtkAllocation *allocation)
00322 {
00323   GtkFMaps *fmaps;
00324   gdouble dxy;
00325 
00326   g_return_if_fail (widget!=NULL);
00327   g_return_if_fail (GTK_IS_FMAPS(widget));
00328   g_return_if_fail (allocation!=NULL);
00329 
00330   dxy=1;
00331   fmaps = GTK_FMAPS (widget);
00332 
00333   widget->allocation = *allocation;
00334 
00335 
00336   if (GTK_WIDGET_REALIZED (widget))
00337   {
00338     gdk_window_move_resize      (widget->window,
00339                                  allocation->x, allocation->y,
00340                                  allocation->width, allocation->height);
00341     if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))  
00342     {
00343       /* OpenGL functions can be called only if make_current returns true */                    
00344       if (widget->allocation.height!=0)
00345       {
00346         dxy=(gdouble)widget->allocation.width/(gdouble)widget->allocation.height;
00347       }
00348       glViewport(0,0, widget->allocation.width, widget->allocation.height);
00349       glMatrixMode(GL_PROJECTION);
00350       glLoadIdentity();
00351       glOrtho(-widget->allocation.width/2,widget->allocation.width/2,-widget->allocation.height/2, widget->allocation.height/2, 1,-1);
00352       /*glLoadIdentity();                               
00353       glTranslated(widget->allocation.width/2,widget->allocation.height/2,1);
00354       glScaled(1,dxy,1);*/
00355     }
00356   }
00357 
00358 }
00359 
00360 static gint
00361 gtk_fmaps_expose (GtkWidget *widget,
00362                   GdkEventExpose *event)
00363 {
00364   GtkFMaps *fmaps;
00365 
00366   g_return_val_if_fail (widget != NULL, FALSE);
00367   g_return_val_if_fail (GTK_IS_FMAPS (widget), FALSE);
00368   g_return_val_if_fail (event != NULL, FALSE);
00369 
00370 
00371   if (event->count > 0 )
00372     return FALSE;
00373 
00374   fmaps = GTK_FMAPS (widget);
00375 
00376   g_return_val_if_fail (gtk_gl_area_make_current(GTK_GL_AREA(widget)),FALSE); /* not an OpenGL widget */
00377 
00378   /* clear the screen and prepare display */
00379   /*gdk_window_clear(widget->window);*/
00380   glClearColor(1,1,1,1);
00381   glClear(GL_COLOR_BUFFER_BIT);
00382 
00383   /* draw */
00384 
00385   /* the display engine is invoked and issue some vertex calls */
00386 
00387   /* init the display engine if needed */
00388 
00389   gtk_fmaps_display_engine(fmaps);
00390 
00391   /* end of the display engine call */
00392 
00393   /* Swap backbuffer to front */
00394   gtk_gl_area_swapbuffers(GTK_GL_AREA(widget));
00395 
00396   return FALSE;
00397 }
00398 
00399 static void
00400 gtk_fmaps_update (GtkFMaps *fmaps)
00401 {
00402   gfloat new_value;
00403 
00404   g_return_if_fail(fmaps != NULL);
00405   g_return_if_fail(GTK_IS_FMAPS(fmaps));
00406 
00407   new_value = fmaps->adjustment->value;
00408 
00409   if (new_value < fmaps->adjustment->lower)
00410     new_value = fmaps->adjustment->lower;
00411 
00412   if (new_value > fmaps->adjustment->upper)
00413     new_value = fmaps->adjustment->upper;
00414 
00415   if (new_value != fmaps->adjustment->value)
00416   {
00417     fmaps->adjustment->value = new_value;
00418     gtk_signal_emit_by_name (GTK_OBJECT (fmaps->adjustment), "value_changed");
00419   }
00420 
00421   gtk_widget_draw (GTK_WIDGET(fmaps),NULL);
00422 }
00423 
00424 static void
00425 gtk_fmaps_adjustment_changed    (GtkAdjustment *adjustment,
00426                                  gpointer       data)
00427 {
00428   GtkFMaps *fmaps;
00429 
00430   g_return_if_fail (adjustment !=NULL);
00431   g_return_if_fail (data != NULL);
00432 
00433   fmaps = GTK_FMAPS(data);
00434 
00435   if ((fmaps->old_value != adjustment->value ||
00436        fmaps->old_lower != adjustment->lower ||
00437        fmaps->old_upper != adjustment->upper))
00438   {
00439     gtk_fmaps_update(fmaps);
00440 
00441     fmaps->old_value = adjustment->value;
00442     fmaps->old_lower = adjustment->lower;
00443     fmaps->old_upper = adjustment->upper;
00444   }
00445 
00446 }
00447 
00448 static void
00449 gtk_fmaps_adjustment_value_changed (GtkAdjustment       *adjustment,
00450                                      gpointer           data)
00451 {
00452   GtkFMaps *fmaps;
00453 
00454   g_return_if_fail (adjustment != NULL);
00455   g_return_if_fail (data != NULL);
00456 
00457   fmaps = GTK_FMAPS (data);
00458 
00459   if (fmaps->old_value != adjustment->value)
00460   {
00461     gtk_fmaps_update (fmaps);
00462 
00463     fmaps->old_value = adjustment->value;
00464   }
00465 
00466 }
00467 
00468 
00469 void
00470 gtk_fmaps_add_table (GtkFMaps *fmaps, gchar *name,gboolean visible)
00471 {
00472   gint nbtables;
00473   gchar *buffer;
00474   PGresult *qryResult;
00475   gint nbtuples;
00476   gint projid;
00477   gint datumid;
00478   gint ellipsoidid;
00479   gint i;
00480 
00481   g_return_if_fail(fmaps != NULL);
00482   g_return_if_fail(name != NULL);
00483   g_return_if_fail(fmaps->conn !=NULL);
00484 
00485 
00486   /* call SQL and get information on the table */
00487   buffer=g_strdup_printf("SELECT DISTINCT oid,meta_file_id from f_catalogue WHERE meta_file_id='%s' ",name);
00488   qryResult = PQexec(fmaps->conn,buffer);
00489   g_free(buffer);
00490 
00491   nbtuples = PQntuples(qryResult);
00492 
00493   g_return_if_fail(nbtuples==1);
00494 
00495 
00496   /* prepare the structure */
00497 
00498   fmaps->nbtables++;
00499   nbtables=fmaps->nbtables;
00500 
00501   if (nbtables==1)
00502   {
00503     fmaps->table=g_malloc(sizeof(gpointer)*nbtables);
00504   } else
00505   {
00506     fmaps->table=g_realloc(fmaps->table,sizeof(gpointer)*nbtables);
00507   }
00508   fmaps->table[nbtables-1]=g_malloc(sizeof(GtkFMapsTable));
00509 
00510   /* fill up the tablelist structure with information */
00511   fmaps->table[nbtables-1]->name=g_strdup(name);
00512 
00513   buffer = PQgetvalue(qryResult,0,0);   /* retreive the dataid (do not free buffer!)*/
00514 
00515   fmaps->table[nbtables-1]->oid=atoi(buffer);
00516 
00517   fmaps->table[nbtables-1]->visible=TRUE;
00518 
00519   PQclear(qryResult);
00520 
00521         /* get the projection system */
00522         /* not yet implemented */
00523   projid = 0;
00524   datumid = 0;
00525   ellipsoidid = 0;
00526 
00527   /* Check the various objects included in the table */
00528         fmaps->table[nbtables-1]->text=FALSE;
00529         fmaps->table[nbtables-1]->vector=FALSE;         
00530         fmaps->table[nbtables-1]->raster=FALSE;         
00531         fmaps->table[nbtables-1]->image=FALSE;
00532                 
00533   buffer=g_strdup_printf("SELECT DISTINCT spatial_rep_type_code from f_catalogue_spatial_rep_type_code WHERE CID=%d ",fmaps->table[nbtables-1]->oid);
00534   qryResult = PQexec(fmaps->conn,buffer);
00535   g_free(buffer);
00536   
00537   nbtuples = PQntuples(qryResult);
00538   for(i=0;i<nbtuples;i++)
00539   {
00540     buffer = PQgetvalue(qryResult,i,0);
00541     switch(atoi(buffer))
00542     {
00543     case 1:
00544         fmaps->table[nbtables-1]->text=TRUE;
00545         break;
00546     case 2:
00547         fmaps->table[nbtables-1]->vector=TRUE;
00548         break;
00549     case 3:
00550         fmaps->table[nbtables-1]->raster=TRUE;
00551         break;
00552     case 4:
00553         fmaps->table[nbtables-1]->image=TRUE;
00554         break;
00555         }
00556   }
00557   PQclear(qryResult);
00558     
00559   /* set the pojdatum data */
00560   fmaps->table[nbtables-1]->projdatum=g_malloc(sizeof(GtkFMapsProjDatum));
00561 
00562   /* call SQL and get information on the projection */
00563   buffer=g_strdup_printf("SELECT name, type, par1, par2, par3, par4,par5, par6, par7, par8, par9, par10 FROM f_projection WHERE projid=%d ",projid);
00564   qryResult = PQexec(fmaps->conn,buffer);
00565   g_free(buffer);
00566 
00567   nbtuples = PQntuples(qryResult);
00568 
00569   if (nbtuples<=0)
00570   {
00571     fmaps->table[nbtables-1]->projdatum->projection=PROJ_NONE;
00572   } else
00573   {
00574 
00575     fmaps->table[nbtables-1]->projdatum->projection=atoi(PQgetvalue(qryResult,0,1));
00576     fmaps->table[nbtables-1]->projdatum->par1=atof(PQgetvalue(qryResult,0,2));
00577     fmaps->table[nbtables-1]->projdatum->par2=atof(PQgetvalue(qryResult,0,3));
00578     fmaps->table[nbtables-1]->projdatum->par3=atof(PQgetvalue(qryResult,0,4));
00579     fmaps->table[nbtables-1]->projdatum->par4=atof(PQgetvalue(qryResult,0,5));
00580     fmaps->table[nbtables-1]->projdatum->par5=atof(PQgetvalue(qryResult,0,6));
00581     fmaps->table[nbtables-1]->projdatum->par6=atof(PQgetvalue(qryResult,0,7));
00582     fmaps->table[nbtables-1]->projdatum->par7=atof(PQgetvalue(qryResult,0,8));
00583     fmaps->table[nbtables-1]->projdatum->par8=atof(PQgetvalue(qryResult,0,9));
00584     fmaps->table[nbtables-1]->projdatum->par9=atof(PQgetvalue(qryResult,0,10));
00585     fmaps->table[nbtables-1]->projdatum->par10=atof(PQgetvalue(qryResult,0,11));
00586   }
00587   PQclear(qryResult);
00588 
00589   /* call SQL and get information on the datum */
00590   buffer=g_strdup_printf("SELECT name,type,dx,dy,dz,ox,oy,oz,scale,pm FROM f_datum WHERE datumid=%d ",datumid);
00591   qryResult = PQexec(fmaps->conn,buffer);
00592   g_free(buffer);
00593 
00594   nbtuples = PQntuples(qryResult);
00595 
00596   if (nbtuples<=0)
00597   {
00598     fmaps->table[nbtables-1]->projdatum->datumtransform=DAT_NONE;
00599   } else
00600   {
00601     fmaps->table[nbtables-1]->projdatum->datumtransform=atoi(PQgetvalue(qryResult,0,1));
00602     fmaps->table[nbtables-1]->projdatum->dx=atof(PQgetvalue(qryResult,0,2));
00603     fmaps->table[nbtables-1]->projdatum->dy=atof(PQgetvalue(qryResult,0,3));
00604     fmaps->table[nbtables-1]->projdatum->dz=atof(PQgetvalue(qryResult,0,4));
00605     fmaps->table[nbtables-1]->projdatum->ex=atof(PQgetvalue(qryResult,0,5));
00606     fmaps->table[nbtables-1]->projdatum->ey=atof(PQgetvalue(qryResult,0,6));
00607     fmaps->table[nbtables-1]->projdatum->ez=atof(PQgetvalue(qryResult,0,7));
00608     fmaps->table[nbtables-1]->projdatum->m=atof(PQgetvalue(qryResult,0,8));
00609     fmaps->table[nbtables-1]->projdatum->pm=atof(PQgetvalue(qryResult,0,9));
00610   }
00611   PQclear(qryResult);
00612 
00613   /* call SQL and get information on the ellipsoid */
00614   buffer=g_strdup_printf("SELECT name,a,f FROM f_ellipsoid WHERE ellipsoidid=%d ",ellipsoidid);
00615   qryResult = PQexec(fmaps->conn,buffer);
00616   g_free(buffer);
00617 
00618   nbtuples = PQntuples(qryResult);
00619 
00620   if(nbtuples>0)
00621   {
00622     fmaps->table[nbtables-1]->projdatum->a=atof(PQgetvalue(qryResult,0,1));
00623     fmaps->table[nbtables-1]->projdatum->f=atof(PQgetvalue(qryResult,0,2));
00624     fmaps->table[nbtables-1]->projdatum->e=2*fmaps->table[nbtables-1]->projdatum->f-fmaps->table[nbtables-1]->projdatum->f*fmaps->table[nbtables-1]->projdatum->f;
00625   }
00626   PQclear(qryResult);
00627 
00628   /* store the first table projection as the projection of the map */
00629   if (nbtables==1)
00630   {
00631     if (fmaps->projdatum==NULL)
00632       fmaps->projdatum=g_malloc(sizeof(GtkFMapsProjDatum));
00633 
00634       fmaps->projdatum->projection=fmaps->table[nbtables-1]->projdatum->projection;
00635       fmaps->projdatum->par1=fmaps->table[nbtables-1]->projdatum->par1;
00636       fmaps->projdatum->par2=fmaps->table[nbtables-1]->projdatum->par2;
00637       fmaps->projdatum->par3=fmaps->table[nbtables-1]->projdatum->par3;
00638       fmaps->projdatum->par4=fmaps->table[nbtables-1]->projdatum->par4;
00639       fmaps->projdatum->par5=fmaps->table[nbtables-1]->projdatum->par5;
00640       fmaps->projdatum->par6=fmaps->table[nbtables-1]->projdatum->par6;
00641       fmaps->projdatum->par7=fmaps->table[nbtables-1]->projdatum->par7;
00642       fmaps->projdatum->par8=fmaps->table[nbtables-1]->projdatum->par8;
00643       fmaps->projdatum->par9=fmaps->table[nbtables-1]->projdatum->par9;
00644       fmaps->projdatum->par10=fmaps->table[nbtables-1]->projdatum->par10;
00645 
00646       fmaps->projdatum->datumtransform=fmaps->table[nbtables-1]->projdatum->datumtransform;
00647       fmaps->projdatum->dx=fmaps->table[nbtables-1]->projdatum->dx;
00648       fmaps->projdatum->dy=fmaps->table[nbtables-1]->projdatum->dy;
00649       fmaps->projdatum->dz=fmaps->table[nbtables-1]->projdatum->dz;
00650       fmaps->projdatum->ex=fmaps->table[nbtables-1]->projdatum->ex;
00651       fmaps->projdatum->ey=fmaps->table[nbtables-1]->projdatum->ey;
00652       fmaps->projdatum->ez=fmaps->table[nbtables-1]->projdatum->ez;
00653       fmaps->projdatum->m=fmaps->table[nbtables-1]->projdatum->m;
00654       fmaps->projdatum->pm=fmaps->table[nbtables-1]->projdatum->pm;
00655 
00656       fmaps->projdatum->a=fmaps->table[nbtables-1]->projdatum->a;
00657       fmaps->projdatum->f=fmaps->table[nbtables-1]->projdatum->f;
00658       fmaps->projdatum->e=fmaps->table[nbtables-1]->projdatum->e;
00659 
00660   }
00661 
00662 }
00663 
00664 static gint
00665 gtk_fmaps_button_press (GtkWidget      *widget,
00666                          GdkEventButton *event)
00667 {
00668   GtkFMaps *fmaps;
00669 
00670   g_return_val_if_fail (widget != NULL, FALSE);
00671   g_return_val_if_fail (GTK_IS_FMAPS(widget), FALSE);
00672   g_return_val_if_fail (event != NULL, FALSE);
00673 
00674   fmaps = GTK_FMAPS(widget);
00675 
00676   switch (fmaps->actionstatus)
00677   {
00678     case ACTION_ZOOM:
00679       fmaps->centerx=((event->x-widget->allocation.width/2)*fmaps->width/widget->allocation.width)+fmaps->centerx;
00680       fmaps->centery=((event->y-widget->allocation.height/2)*fmaps->width/widget->allocation.width)+fmaps->centery;
00681       switch (event->button)
00682       {
00683         case 1:
00684           fmaps->width = fmaps->width/1.5;
00685           break;
00686         case 3:
00687           fmaps->width = fmaps->width*1.5;
00688           break;
00689       }
00690       gtk_widget_draw(GTK_WIDGET(fmaps),NULL);
00691   }
00692 
00693   return FALSE;
00694 }                       
00695                         

Generated at Sat Jan 6 20:55:34 2001 for FMaps by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000