00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #include <gtk/gtk.h>
00076 #include "config.h"
00077 #include "gxsm/plugin.h"
00078 #include "gxsm/dataio.h"
00079 #include "gxsm/action_id.h"
00080
00081 using namespace std;
00082
00083
00084 static void sdfimport_init( void );
00085 static void sdfimport_about( void );
00086 static void sdfimport_configure( void );
00087 static void sdfimport_cleanup( void );
00088
00089 static void sdfimport_run(GtkWidget *w, void *data);
00090
00091
00092 GxsmPlugin sdfimport_pi = {
00093 NULL,
00094 NULL,
00095 0,
00096 NULL,
00097
00098
00099
00100
00101 "SDFimport",
00102
00103
00104
00105
00106
00107 NULL,
00108
00109 "Imports from SDF Data",
00110
00111 "Stefan Schroeder",
00112
00113 N_("_File/_Import/"),
00114
00115 N_("SDF"),
00116
00117 N_("Import SDF File"),
00118
00119 "no more info",
00120 NULL,
00121 NULL,
00122
00123
00124 sdfimport_init,
00125
00126
00127 NULL,
00128
00129
00130 sdfimport_about,
00131
00132
00133 sdfimport_configure,
00134
00135
00136 sdfimport_run,
00137
00138
00139 sdfimport_cleanup
00140 };
00141
00142
00143 static const char *about_text = N_("Gxsm SDF Data Import Plugin\n\n"
00144 "This plugin reads in a datafile\n"
00145 "in sdf-format.");
00146
00147
00148
00149 GxsmPlugin *get_gxsm_plugin_info ( void ){
00150 sdfimport_pi.description = g_strdup_printf(N_("Gxsm MathOneArg sdfimport plugin %s"), VERSION);
00151 return &sdfimport_pi;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160 static void sdfimport_init(void)
00161 {
00162 PI_DEBUG (DBG_L2, "sdfimport Plugin Init" );
00163 }
00164
00165
00166 static void sdfimport_about(void)
00167 {
00168 const gchar *authors[] = { sdfimport_pi.authors, NULL};
00169 gtk_widget_show(gnome_about_new ( sdfimport_pi.name,
00170 VERSION,
00171 N_("(C) 2000 the Free Software Foundation"),
00172 about_text,
00173 authors,
00174 NULL, NULL, NULL
00175 ));
00176 }
00177
00178
00179 static void sdfimport_configure(void)
00180 {
00181 if(sdfimport_pi.app)
00182 sdfimport_pi.app->message("sdfimport Plugin Configuration");
00183 }
00184
00185
00186 static void sdfimport_cleanup(void)
00187 {
00188 PI_DEBUG (DBG_L2, "sdfimport Plugin Cleanup" );
00189 }
00190
00191 class SDFFile : public Dataio{
00192 public:
00193 SDFFile(Scan *s, const char *n) : Dataio(s,n){};
00194 virtual FIO_STATUS Read();
00195 virtual FIO_STATUS Write(){ return FIO_OK; };
00196 private:
00197 int dummy;
00198 };
00199
00200 FIO_STATUS SDFFile::Read(){
00201
00202 PI_DEBUG (DBG_L1, "***** Importing SDF-file. *****" );
00203
00204 ifstream SDFinputstream;
00205 char SDFversionnumber [9];
00206 char SDFmanufacturerid [11];
00207 char SDFcreationdate [13];
00208 char SDFmodificationtime [13];
00209 short SDFnumpoints;
00210 short SDFnumprofiles;
00211 double SDFxscale;
00212 double SDFyscale;
00213 double SDFzscale;
00214 double SDFzresolution;
00215 char SDFcompression [2];
00216 char SDFdatatype [2];
00217 char SDFchecktype [2];
00218
00219 SDFinputstream.open(name, ios::in);
00220
00221
00222 if(!SDFinputstream.good())
00223 return status=FIO_OPEN_ERR;
00224
00225
00226 PI_DEBUG (DBG_L1, "Reading data... -- this is as worse as it could be to be portable:-(" );;
00227 SDFinputstream.read((char*)&SDFversionnumber, 8);
00228 SDFversionnumber[8] = '\0';
00229 SDFinputstream.read((char*)&SDFmanufacturerid, 10);
00230 SDFmanufacturerid[10] = '\0';
00231 SDFinputstream.read((char*)&SDFcreationdate, 12);
00232 SDFcreationdate[12] = '\0';
00233 SDFinputstream.read((char*)&SDFmodificationtime, 12);
00234 SDFmodificationtime[12] = '\0';
00235 SDFinputstream.read((char*)&SDFnumpoints, 2);
00236 SDFinputstream.read((char*)&SDFnumprofiles, 2);
00237 SDFinputstream.read((char*)&SDFxscale, 8);
00238 SDFinputstream.read((char*)&SDFyscale, 8);
00239 SDFinputstream.read((char*)&SDFzscale, 8);
00240 SDFinputstream.read((char*)&SDFzresolution, 8);
00241 SDFinputstream.read((char*)&SDFcompression, 1);
00242 SDFcompression[1] = '\0';
00243 SDFinputstream.read((char*)&SDFdatatype, 1);
00244 SDFdatatype[1] = '\0';
00245 SDFinputstream.read((char*)&SDFchecktype, 1);
00246 SDFchecktype[1] = '\0';
00247
00248 PI_DEBUG (DBG_L1, "Filename = " << name );
00249 PI_DEBUG (DBG_L1, "Versionnumber = " << SDFversionnumber );
00250 PI_DEBUG (DBG_L1, "Manufacturer = " << SDFmanufacturerid );
00251 PI_DEBUG (DBG_L1, "Creationdate = " << SDFcreationdate );
00252 PI_DEBUG (DBG_L1, "Modificationtime = " << SDFmodificationtime );
00253 PI_DEBUG (DBG_L1, "Number of points = " << SDFnumpoints );
00254 PI_DEBUG (DBG_L1, "Number of profiles = " << SDFnumprofiles );
00255 PI_DEBUG (DBG_L1, "Xscale = " << SDFxscale );
00256 PI_DEBUG (DBG_L1, "Yscale = " << SDFyscale );
00257 PI_DEBUG (DBG_L1, "Zscale = " << SDFzscale );
00258 PI_DEBUG (DBG_L1, "Zresolution = " << SDFzresolution );
00259 PI_DEBUG (DBG_L1, "Compression = " << SDFcompression );
00260 PI_DEBUG (DBG_L1, "Datatype = " << SDFdatatype );
00261 PI_DEBUG (DBG_L1, "Checktype = " << SDFchecktype );
00262
00263
00264 scan->data.s.nx = SDFnumpoints;
00265 scan->data.s.ny = SDFnumprofiles;
00266 scan->data.s.dx = SDFxscale * 10e9;
00267 scan->data.s.dy = SDFyscale * 10e9;
00268 scan->data.s.dz = SDFzscale * 10e9;
00269 scan->data.s.rx = SDFxscale * 10e9 * SDFnumpoints;
00270 scan->data.s.ry = SDFyscale * 10e9 * SDFnumprofiles;
00271
00272 scan->data.ui.SetUser (SDFmanufacturerid);
00273
00274 gchar *tmp=g_strconcat ("SDF-fileimport: ",
00275 "Compression: ,", SDFcompression,
00276 "Datatype: ,", SDFdatatype,
00277 "Creationdate: ", SDFcreationdate,
00278 NULL);
00279 scan->data.ui.SetComment (tmp);
00280 g_free (tmp);
00281
00282 PI_DEBUG (DBG_L1, "Reading data...");
00283
00284 scan->mem2d->Resize (scan->data.s.nx, scan->data.s.ny);
00285 scan->mem2d->DataRead (SDFinputstream);
00286
00287 scan->data.orgmode = SCAN_ORG_CENTER;
00288 scan->mem2d->data->MkXLookup (-scan->data.s.rx/2., scan->data.s.rx/2.);
00289 scan->mem2d->data->MkYLookup (-scan->data.s.ry/2., scan->data.s.ry/2.);
00290
00291 if(SDFinputstream.fail()){
00292 SDFinputstream.close();
00293 return status=FIO_READ_ERR;
00294 }
00295
00296 PI_DEBUG (DBG_L1, "***** Finished importing SDF-file. *****");
00297 SDFinputstream.close();
00298
00299 return status=FIO_OK;
00300 }
00301
00302
00303
00304 static void sdfimport_run(GtkWidget *w, void *data)
00305 {
00306 Scan *dst;
00307 gchar *nfname = gapp->file_dialog("sdf-file to load", NULL,
00308 "*.sdf", NULL, "sdf-Import");
00309 if( !nfname ) return;
00310
00311 gapp->xsm->ActivateFreeChannel();
00312 SDFFile sdfFile(dst = gapp->xsm->GetActiveScan(), nfname);
00313
00314 if(!dst){
00315 gapp->xsm->ActivateFreeChannel();
00316 dst = gapp->xsm->GetActiveScan();
00317 }
00318 if(sdfFile.Read() != FIO_OK){
00319
00320 gapp->xsm->SetMode(-1, ID_CH_M_OFF, TRUE);
00321 }
00322 gapp->spm_update_all();
00323 dst->draw();
00324 dst=NULL;
00325 }