g_dat_im_export.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  *
00005  * Gxsm Plugin Name: g_dat_im_export.C
00006  * ========================================
00007  * 
00008  * Copyright (C) 1999 The Free Software Foundation
00009  *
00010  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00011  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00026  */
00027 
00028 /* Please do not change the Begin/End lines of this comment section!
00029  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00030  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00031  * --------------------------------------------------------------------------------
00032 % BeginPlugInDocuSection
00033 % PlugInDocuCaption: Import/Export of old (G-) dat files
00034 % PlugInName: G_dat_Im_Export
00035 % PlugInAuthor: Percy Zahl
00036 % PlugInAuthorEmail: zahl@users.sf.net
00037 % PlugInMenuPath: File/Import/G-dat
00038 
00039 % PlugInDescription
00040 \label{plugins:g_dat_im_export}
00041 The \GxsmEmph{g\_dat\_im\_export} plug-in supports reading and writing of
00042 the old \GxsmFile{.dat} fileformat used in Hannover at former times. It was used by
00043 the very first xxsm, pmstm and even older OS/2 software in Hannover, mostly by
00044 K\"ohler et al. Also the so called \GxsmEmph{gnutools} are can use this 16-bit data format. 
00045 To distiguish different dat files, I call it \GxsmEmph{G-dat}. 
00046 
00047 % PlugInUsage
00048 The plug-in is called by \GxsmMenu{File/Import/G-dat}.
00049 
00050 % OptPlugInKnownBugs
00051 Not yet tested.
00052 
00053 % EndPlugInDocuSection
00054  * -------------------------------------------------------------------------------- 
00055  */
00056 
00057 #include <gtk/gtk.h>
00058 #include "config.h"
00059 #include "gxsm/plugin.h"
00060 #include "gxsm/dataio.h"
00061 #include "gxsm/action_id.h"
00062 #include "gxsm/util.h"
00063 #include "gxsm/xsmtypes.h"
00064 
00065 // custom includes go here
00066 // -- START EDIT --
00067 #include "batch.h"
00068 #include "g_dat_types.h"
00069 #include "fileio.c"
00070 // -- END EDIT --
00071 
00072 // enable std namespace
00073 using namespace std;
00074 
00075 // Plugin Prototypes
00076 static void g_dat_im_export_init (void);
00077 static void g_dat_im_export_query (void);
00078 static void g_dat_im_export_about (void);
00079 static void g_dat_im_export_configure (void);
00080 static void g_dat_im_export_cleanup (void);
00081 
00082 static void g_dat_im_export_filecheck_load_callback (gpointer data );
00083 static void g_dat_im_export_filecheck_save_callback (gpointer data );
00084 
00085 static void g_dat_im_export_import_callback (GtkWidget *w, void *data);
00086 static void g_dat_im_export_export_callback (GtkWidget *w, void *data);
00087 
00088 // Fill in the GxsmPlugin Description here
00089 GxsmPlugin g_dat_im_export_pi = {
00090   NULL,                   // filled in and used by Gxsm, don't touch !
00091   NULL,                   // filled in and used by Gxsm, don't touch !
00092   0,                      // filled in and used by Gxsm, don't touch !
00093   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00094                           // filled in here by Gxsm on Plugin load, 
00095                           // just after init() is called !!!
00096 // -- START EDIT --
00097   "G-dat-ImExport",            // PlugIn name
00098   NULL,                   // PlugIn's Categorie, set to NULL for all, I just don't want this always to be loaded!
00099   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00100   "Im/Export of the old (G-) dat file format.",
00101   "Percy Zahl",
00102   N_("_File/_Import/,_File/_Export/"), // sep. im/export menuentry path by comma!
00103   N_("G-dat,G-dat"), // menu entry (same for both)
00104   N_("Old 'dat' file import,Old 'dat' file export"), // short help for menu entry
00105   N_("Old 'dat' file import and export filter."), // info
00106 // -- END EDIT --
00107   NULL,          // error msg, plugin may put error status msg here later
00108   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00109   g_dat_im_export_init,
00110   g_dat_im_export_query,
00111   // about-function, can be "NULL"
00112   // can be called by "Plugin Details"
00113   g_dat_im_export_about,
00114   // configure-function, can be "NULL"
00115   // can be called by "Plugin Details"
00116   g_dat_im_export_configure,
00117   // run-function, can be "NULL", if non-Zero and no query defined, 
00118   // it is called on menupath->"plugin"
00119   NULL,
00120   // cleanup-function, can be "NULL"
00121   // called if present at plugin removeal
00122   g_dat_im_export_cleanup
00123 };
00124 
00125 // Text used in Aboutbox, please update!!
00126 static const char *about_text = N_("GXSM 'G-dat' plugin for im-/export of old the 'dat' data file type.\n"
00127                                    "This format was used in Hannover in early times and can also be used "
00128                                    "with the 'gnutools'. This apps were using this format: PMSTM and older "
00129                                    "very first versions of XXSM and older GXSM versions were able to use it "
00130                                    "instead of NetCDF if configured this way.\n\n"
00131                                    "Now this filter is here to visit/manipulate old data files."
00132         );
00133 
00134 static const char *file_mask = "*.dat";
00135 
00136 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00137 // Essential Plugin Function!!
00138 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00139   g_dat_im_export_pi.description = g_strdup_printf(N_("Gxsm im_export plugin %s"), VERSION);
00140   return &g_dat_im_export_pi; 
00141 }
00142 
00143 // Query Function, installs Plugin's in File/Import and Export Menupaths!
00144 // ----------------------------------------------------------------------
00145 // Import Menupath is "File/Import/GME Dat"
00146 // Export Menupath is "File/Export/GME Dat"
00147 // ----------------------------------------------------------------------
00148 // !!!! make sure the "g_dat_im_export_cleanup()" function (see below) !!!!
00149 // !!!! removes the correct menuentries !!!!
00150 
00151 static void g_dat_im_export_query(void)
00152 {
00153         gchar **path  = g_strsplit (g_dat_im_export_pi.menupath, ",", 2);
00154         gchar **entry = g_strsplit (g_dat_im_export_pi.menuentry, ",", 2);
00155         gchar **help  = g_strsplit (g_dat_im_export_pi.help, ",", 2);
00156 
00157         static GnomeUIInfo menuinfo_i[] = { 
00158                 { GNOME_APP_UI_ITEM, NULL, NULL,
00159                   NULL, NULL,
00160                   NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_OPEN,
00161                   0, GDK_CONTROL_MASK, NULL },
00162                 GNOMEUIINFO_END
00163         };
00164         menuinfo_i[0].label  = entry[0];
00165         menuinfo_i[0].hint   = help[0];
00166         menuinfo_i[0].moreinfo  = (gpointer) g_dat_im_export_import_callback; 
00167         menuinfo_i[0].user_data = g_dat_im_export_pi.name;
00168 
00169         gnome_app_insert_menus (
00170                 GNOME_APP(g_dat_im_export_pi.app->getApp()), 
00171                 path[0], 
00172                 menuinfo_i
00173                 );
00174         
00175 
00176         static GnomeUIInfo menuinfo_e[] = { 
00177                 { GNOME_APP_UI_ITEM, NULL, NULL,
00178                   NULL, NULL,
00179                   NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SAVE,
00180                   0, GDK_CONTROL_MASK, NULL },
00181                 GNOMEUIINFO_END
00182         };
00183         menuinfo_e[0].label  = entry[1];
00184         menuinfo_e[0].hint   = help[1];
00185         menuinfo_e[0].moreinfo  = (gpointer) g_dat_im_export_export_callback; 
00186         menuinfo_e[0].user_data = g_dat_im_export_pi.name;
00187 
00188         gnome_app_insert_menus (
00189                 GNOME_APP(g_dat_im_export_pi.app->getApp()), 
00190                 path[1],
00191                 menuinfo_e
00192                 );
00193 
00194         if(g_dat_im_export_pi.status) g_free(g_dat_im_export_pi.status); 
00195         g_dat_im_export_pi.status = g_strconcat (
00196                 N_("Plugin query has attached "),
00197                 g_dat_im_export_pi.name, 
00198                 N_(": File IO Filters are ready to use."),
00199                 NULL);
00200         
00201         // clean up
00202         g_strfreev (path);
00203         g_strfreev (entry);
00204         g_strfreev (help);
00205 
00206         // register this plugins filecheck functions with Gxsm now!
00207         // This allows Gxsm to check files from DnD, open, 
00208         // and cmdline sources against all known formats automatically - no explicit im/export is necessary.
00209         g_dat_im_export_pi.app->ConnectPluginToLoadFileEvent (g_dat_im_export_filecheck_load_callback);
00210         g_dat_im_export_pi.app->ConnectPluginToSaveFileEvent (g_dat_im_export_filecheck_save_callback);
00211 }
00212 
00213 
00214 // 5.) Start here with the plugins code, vars def., etc.... here.
00215 // ----------------------------------------------------------------------
00216 //
00217 
00218 
00219 // init-Function
00220 static void g_dat_im_export_init(void)
00221 {
00222         PI_DEBUG (DBG_L2, g_dat_im_export_pi.name << " Plugin Init");
00223 }
00224 
00225 // about-Function
00226 static void g_dat_im_export_about(void)
00227 {
00228         const gchar *authors[] = { g_dat_im_export_pi.authors, NULL};
00229         gtk_widget_show(gnome_about_new ( g_dat_im_export_pi.name,
00230                                           VERSION,
00231                                           N_("(C) 2001 the Free Software Foundation"),
00232                                           about_text,
00233                                           authors,
00234                                           NULL, NULL, NULL
00235                                           ));
00236 }
00237 
00238 // configure-Function
00239 static void g_dat_im_export_configure(void)
00240 {
00241         if(g_dat_im_export_pi.app)
00242                 g_dat_im_export_pi.app->message("im_export Plugin Configuration");
00243 }
00244 
00245 // cleanup-Function, remove all "custom" menu entrys here!
00246 static void g_dat_im_export_cleanup(void)
00247 {
00248         gchar **path  = g_strsplit (g_dat_im_export_pi.menupath, ",", 2);
00249         gchar **entry = g_strsplit (g_dat_im_export_pi.menuentry, ",", 2);
00250 
00251         gchar *tmp = g_strconcat (path[0], entry[0], NULL);
00252         gnome_app_remove_menus (GNOME_APP (g_dat_im_export_pi.app->getApp()), tmp, 1);
00253         g_free (tmp);
00254 
00255         tmp = g_strconcat (path[1], entry[1], NULL);
00256         gnome_app_remove_menus (GNOME_APP (g_dat_im_export_pi.app->getApp()), tmp, 1);
00257         g_free (tmp);
00258 
00259         g_strfreev (path);
00260         g_strfreev (entry);
00261 
00262         PI_DEBUG (DBG_L2, "Plugin Cleanup done.");
00263 }
00264 
00265 // make a new derivate of the base class "Dataio"
00266 class  Gdat_ImExportFile : public Dataio{
00267 public:
00268          Gdat_ImExportFile(Scan *s, const char *n) : Dataio(s,n){  memset(&Kopf, 0, sizeof(Kopf)); };
00269         virtual FIO_STATUS Read();
00270         virtual FIO_STATUS Write();
00271 private:
00272         FIO_STATUS import_data(const char *fname); 
00273         HEADER Kopf;
00274 };
00275 
00276 FIO_STATUS Gdat_ImExportFile::Read(){
00277         FIO_STATUS ret;
00278         gchar *fname=NULL;
00279 
00280         PI_DEBUG (DBG_L2, "reading");
00281 
00282         fname = (gchar*)name;
00283 
00284         // name should have at least 4 chars: ".ext"
00285         if (fname == NULL || strlen(fname) < 4)
00286                 return status=FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00287  
00288         // check for file exists and is OK !
00289         // else open File Dlg
00290         ifstream f;
00291         f.open(fname, ios::in);
00292         if(!f.good()){
00293                 PI_DEBUG (DBG_L2, "Error at file open. File not good/readable.");
00294                 return status=FIO_OPEN_ERR;
00295         }
00296         f.close();
00297 
00298         // Check all known File Types:
00299         if ((ret=import_data (fname)) !=  FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00300                 return ret;
00301 
00302         return  status=FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00303 }
00304 
00305 // Utils only used here:
00306 double Contrast_to_VRangeZ (double contrast, double dz){
00307         return 64.*dz/contrast;
00308 }
00309 double VRangeZ_to_Contrast (double vrz, double dz){
00310         return 64.*dz/vrz;
00311 }
00312 
00313 FIO_STATUS Gdat_ImExportFile::import_data(const char *fname){
00314         gboolean byteswap = FALSE;
00315         GtkWidget *dialog;
00316         int pcnt = 0;
00317 
00318         // Checking resposibility for this file as good as possible, use
00319         // extension(s) (most simple), magic numbers, etc.
00320         ifstream f;
00321         GString *FileList=NULL;
00322 
00323         PI_DEBUG (DBG_L2, "importing from >" << fname << "<");
00324 
00325         f.open(fname, ios::in);
00326         if (!f.good())
00327                 return status=FIO_OPEN_ERR;
00328 
00329         // reset old scan fully to defaults
00330         SCAN_DATA scan_template;
00331 //      scan->data.CpUnits (scan_template);
00332         scan->data.GetScan_Param (scan_template);
00333 //      scan->data.GetLayer_Param (scan_template);
00334         scan->data.GetUser_Info (scan_template);
00335 //      scan->data.GetDSP_Param (scan_template);
00336         scan->data.GetDisplay_Param (scan_template);
00337 
00338         // now start importing -----------------------------------------
00339         f.seekg(0, ios::beg); // Auf Headerstart Positionieren
00340         f.read((char*)&Kopf, sizeof(HEADER));
00341     
00342         PI_DEBUG (DBG_L2, "Checking 'Kopf.Kennung'");
00343         switch(Kopf.Kennung){
00344         case 0xABCE: PI_DEBUG (DBG_L2, "Neues Dat Format detected!"); break;
00345         case 0xABCD: PI_DEBUG (DBG_L2, "Altes Dat Format (PMSTM) detected!"); break;
00346         case 0xCEAB: 
00347                 PI_DEBUG (DBG_L2, "Neues Dat Format [LE on BE] detected!\n"
00348                           << "-- But sorry, wrong endianess detected, I'm not handling this yet. --");
00349                 dialog = gtk_message_dialog_new (NULL,
00350                                                  GTK_DIALOG_DESTROY_WITH_PARENT,
00351                                                  GTK_MESSAGE_INFO,
00352                                                  GTK_BUTTONS_OK,
00353                                                  N_("New 'dat' format [LE on BE] detected!\n"
00354                                                     "But sorry, wrong endianess detected, "
00355                                                     "I'm not handling this yet."));
00356                 gtk_dialog_run (GTK_DIALOG (dialog));
00357                 gtk_widget_destroy (dialog);
00358 
00359                 byteswap = TRUE;
00360                 f.close ();
00361                 return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00362                 break;
00363         case 0xCDAB: 
00364                 PI_DEBUG (DBG_L2, "Altes Dat Format (PMSTM) [LE on BE] detected!\n"
00365                           << "-- But sorry, wrong endianess detected, I'm not handling this yet. --");
00366                 dialog = gtk_message_dialog_new (NULL,
00367                                                  GTK_DIALOG_DESTROY_WITH_PARENT,
00368                                                  GTK_MESSAGE_INFO,
00369                                                  GTK_BUTTONS_OK,
00370                                                  N_("New 'dat' format [LE on BE] detected!\n"
00371                                                     "But sorry, wrong endianess detected, "
00372                                                     "I'm not handling this yet."));
00373                 gtk_dialog_run (GTK_DIALOG (dialog));
00374                 gtk_widget_destroy (dialog);
00375                 
00376                 byteswap = TRUE;
00377                 f.close ();
00378                 return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00379                 break;
00380         case 0:
00381 // For some reason, I had to remove the following code part to get it to
00382 // compile.  AK
00383 //              gchar *message = g_strdup_printf (
00384 //                      N_("Malformed dat format Header detected!\n"
00385 //                         "You can force ignoring this in settings (not yet, sorry),\n"
00386 //                         "but it's not save. - import canceled.\n"
00387 //                         " DAT-Kopf.Kennung = 0x%4X"), Kopf.Kennung);
00388 //              PI_DEBUG (DBG_L2, message);
00389 
00390                 PI_DEBUG (DBG_L2, "Malformed dat format Header detected!");
00391 
00392 //              dialog = gtk_message_dialog_new (NULL,
00393 //                                               GTK_DIALOG_DESTROY_WITH_PARENT,
00394 //                                               GTK_MESSAGE_INFO,
00395 //                                               GTK_BUTTONS_OK,
00396 //                                               message);
00397 //              gtk_dialog_run (GTK_DIALOG (dialog));
00398 //              gtk_widget_destroy (dialog);
00399 //              g_free (message);
00400                 f.close ();
00401                 return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00402                 break;
00403         default:
00404                 f.close ();
00405                 return FIO_NOT_RESPONSIBLE_FOR_THAT_FILE;
00406                 break;
00407         }
00408 
00409         // update as much as we get...
00410         time_t t; // Scan - Startzeit eintragen 
00411         time(&t);
00412         gchar *tmp = g_strconcat ((ctime(&t)), " (Imported)", NULL); scan->data.ui.SetDateOfScan (tmp); g_free (tmp);
00413         scan->data.ui.SetName (name);
00414         scan->data.ui.SetOriginalName (name);
00415         scan->data.ui.SetType ("old G-dat");
00416         scan->data.ui.SetUser (Kopf.UserName);
00417 
00418         FileList = g_string_new ("Imported by GXSM from old dat filetype.\n");
00419         g_string_sprintfa (FileList, "Original Filename: %s\n", name);
00420         g_string_append (FileList, "Original Kopf.comment:\n");
00421         g_string_append (FileList, Kopf.comment);
00422         scan->data.ui.SetComment (FileList->str);
00423         g_string_free(FileList, TRUE); 
00424         FileList=NULL;
00425 
00426         scan->data.s.nx = Kopf.nx[pcnt];
00427         scan->data.s.ny = Kopf.ny[pcnt];
00428         scan->data.s.dx = Kopf.dx[pcnt]*Kopf.DAtoAng_X;
00429         scan->data.s.dy = Kopf.dy[pcnt]*Kopf.DAtoAng_Y;
00430         scan->data.s.dz = Kopf.DAtoAng_Z;
00431         scan->data.s.rx = scan->data.s.nx*scan->data.s.dx;
00432         scan->data.s.ry = scan->data.s.ny*scan->data.s.dy;
00433         scan->data.s.x0 = Kopf.x_Offset[pcnt]*Kopf.DAtoAng_X;
00434         scan->data.s.y0 = Kopf.y_Offset[pcnt]*Kopf.DAtoAng_Y;
00435         scan->data.s.alpha = (double)Kopf.Rotation;
00436         scan->data.display.bright = 32.; //Kopf.brightfac;
00437         scan->data.display.vrange_z = Contrast_to_VRangeZ (Kopf.greyfac, scan->data.s.dz);
00438         scan->data.display.voffset_z = 0.;
00439         
00440         scan->mem2d->Resize (scan->data.s.nx, scan->data.s.ny);
00441         scan->mem2d->DataRead (f);
00442         scan->mem2d->data->MkXLookup (-scan->data.s.rx/2., scan->data.s.rx/2.);
00443         scan->mem2d->data->MkYLookup (-scan->data.s.ry/2., scan->data.s.ry/2.);
00444 
00445         if (f.fail ()){
00446                 f.close ();
00447                 return status=FIO_READ_ERR; 
00448         }
00449         f.close();
00450         return status=FIO_OK; 
00451 }
00452 
00453 FIO_STATUS Gdat_ImExportFile::Write(){
00454         int pcnt=0;
00455         ofstream f;
00456 
00457         PI_DEBUG (DBG_L2, "writing >" << name << "<");
00458 
00459         if (name == NULL) return FIO_NO_NAME;
00460 
00461         f.open(name, ios::out);
00462         if (!f.good())
00463                 return status=FIO_OPEN_ERR;
00464 
00465         // start exporting -------------------------------------------
00466         f.seekp(0, ios::beg); // Auf Headerstart Positionieren
00467 
00468         // Kopf erstellen
00469         scan->data.ui.SetName (name);
00470         Kopf.ScMode    = TopoGraphic;
00471         Kopf.Kennung   = 0xABCE; /* NEU !!, alt=0xABCD */
00472         if(strlen(scan->data.ui.user) > 39)
00473                 XSM_SHOW_ALERT(HINT_WARN, HINT_UNAME_TRUNC, " ", 0);
00474         if(strlen(scan->data.ui.comment) > 255)
00475                 XSM_SHOW_ALERT(HINT_WARN, HINT_COMMENT_TRUNC, " ", 0);
00476         strncpy(Kopf.UserName, scan->data.ui.user, 39);
00477         strncpy(Kopf.comment, scan->data.ui.comment, 255);
00478         Kopf.nx[pcnt] = scan->data.s.nx;
00479         Kopf.ny[pcnt] = scan->data.s.ny;
00480         // ....->Inst wird nur wegen dat-Type benötigt .... :=(
00481         Kopf.dx[pcnt] = R2INT(scan->data.s.dx/gapp->xsm->Inst->XResolution());
00482         Kopf.dy[pcnt] = R2INT(scan->data.s.dy/gapp->xsm->Inst->YResolution());
00483         Kopf.x_Offset[pcnt] = R2INT(scan->data.s.x0/gapp->xsm->Inst->XResolution());
00484         Kopf.y_Offset[pcnt] = R2INT(scan->data.s.y0/gapp->xsm->Inst->XResolution());
00485         Kopf.DAtoAng_X = gapp->xsm->Inst->XResolution();
00486         Kopf.DAtoAng_Y = gapp->xsm->Inst->YResolution();
00487         Kopf.DAtoAng_Z = gapp->xsm->Inst->ZResolution();
00488         Kopf.Rotation  = (short)(rint(scan->data.s.alpha));
00489         Kopf.brightfac = scan->data.display.bright;
00490         Kopf.greyfac   = VRangeZ_to_Contrast (scan->data.display.vrange_z, scan->data.s.dz);
00491         //  Kopf.linefac   = scan->data.display.gamma;
00492         Kopf.forw_delay=10L;
00493         Kopf.back_delay=10L;
00494         Kopf.NumOfTopAve=1;
00495         // Kopf noch nicht vollständig ausgefüllt !
00496 
00497         f.write((const char*)&Kopf, sizeof(HEADER));
00498         if(f.fail()){
00499                 f.close();
00500                 return status=FIO_WRITE_ERR; 
00501         }
00502 
00503         scan->mem2d->DataWrite(f);
00504 
00505         if(f.fail()){
00506                 f.close();
00507                 return status=FIO_WRITE_ERR; 
00508         }
00509         f.close();
00510         return status=FIO_OK; 
00511 }
00512 
00513 // Plugin's Notify Cb's, registered to be called on file load/save to check file
00514 // return via filepointer, it is set to Zero or passed as Zero if file has been processed!
00515 // That's all fine, you should just change the Text Stings below...
00516 
00517 
00518 static void g_dat_im_export_filecheck_load_callback (gpointer data ){
00519         gchar **fn = (gchar**)data;
00520         if (*fn){
00521                 PI_DEBUG (DBG_L2, "checking >" << *fn << "<" );
00522 
00523                 Scan *dst = gapp->xsm->GetActiveScan();
00524                 if(!dst){ 
00525                         gapp->xsm->ActivateFreeChannel();
00526                         dst = gapp->xsm->GetActiveScan();
00527                 }
00528                 Gdat_ImExportFile fileobj (dst, *fn);
00529 
00530                 FIO_STATUS ret = fileobj.Read(); 
00531                 if (ret != FIO_OK){ 
00532                         // I'am responsible! (But failed)
00533                         if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00534                                 *fn=NULL;
00535                         // no more data: remove allocated and unused scan now, force!
00536                         gapp->xsm->SetMode(-1, ID_CH_M_OFF, TRUE); 
00537                         PI_DEBUG (DBG_L2, "Read Error " << ((int)ret) );
00538                 }else{
00539                         // got it!
00540                         *fn=NULL;
00541 
00542                         // Now update gxsm main window data fields
00543                         gapp->xsm->ActiveScan->GetDataSet(gapp->xsm->data);
00544                         gapp->spm_update_all();
00545                         dst->draw();
00546                 }
00547         }else{
00548                 PI_DEBUG (DBG_L2, "Skipping" << *fn << "<" );
00549         }
00550 }
00551 
00552 static void g_dat_im_export_filecheck_save_callback (gpointer data ){
00553         gchar **fn = (gchar**)data;
00554         if (*fn){
00555                 Scan *src;
00556                 PI_DEBUG (DBG_L2, "Saving/(checking) >" << *fn << "<" );
00557 
00558                 Gdat_ImExportFile fileobj (src = gapp->xsm->GetActiveScan(), *fn);
00559 
00560                 FIO_STATUS ret;
00561                 ret = fileobj.Write(); 
00562 
00563                 if(ret != FIO_OK){
00564                         // I'am responsible! (But failed)
00565                         if (ret != FIO_NOT_RESPONSIBLE_FOR_THAT_FILE)
00566                                 *fn=NULL;
00567                         PI_DEBUG (DBG_L2, "Write Error " << ((int)ret) );
00568                 }else{
00569                         // write done!
00570                         *fn=NULL;
00571                 }
00572         }else{
00573                 PI_DEBUG (DBG_L2, "Skipping >" << *fn << "<" );
00574         }
00575 }
00576 
00577 // Menu callback functions -- usually no need to edit
00578 
00579 static void g_dat_im_export_import_callback(GtkWidget *w, void *data){
00580         gchar **help = g_strsplit (g_dat_im_export_pi.help, ",", 2);
00581         gchar *dlgid = g_strconcat (g_dat_im_export_pi.name, "-import", NULL);
00582         gchar *fn = gapp->file_dialog(help[0], NULL, file_mask, NULL, dlgid);
00583         g_strfreev (help); 
00584         g_free (dlgid);
00585         g_dat_im_export_filecheck_load_callback (&fn );
00586 }
00587 
00588 static void g_dat_im_export_export_callback(GtkWidget *w, void *data){
00589         gchar **help = g_strsplit (g_dat_im_export_pi.help, ",", 2);
00590         gchar *dlgid = g_strconcat (g_dat_im_export_pi.name, "-export", NULL);
00591         gchar *fn = gapp->file_dialog(help[1], NULL, file_mask, NULL, dlgid);
00592         g_strfreev (help); 
00593         g_free (dlgid);
00594         g_dat_im_export_filecheck_save_callback (&fn );
00595 }

Generated on Sat Apr 1 09:04:25 2006 for GXSM by  doxygen 1.4.6