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 #include <time.h>
00029
00030 #include <signal.h>
00031
00032 #ifndef __XSM_H
00033 #include "xsm.h"
00034 #endif
00035
00036 #ifndef __PLUGIN_CTRL_H
00037 #include "plugin_ctrl.h"
00038 #endif
00039
00040 #ifndef __GLBVARS_H
00041 #include "glbvars.h"
00042 #endif
00043 #define UTF8_DEGREE "\302\260"
00044 #define UTF8_MU "\302\265"
00045 #define UTF8_ANGSTROEM "\303\205"
00046
00047
00048 UnitsTable XsmUnitsTable[] = {
00049
00050 { "AA", UTF8_ANGSTROEM, "\305", 1e0, ".1f", ".2f" },
00051 { "nm", "nm", "nm", 10e0, ".1f", ".2f" },
00052 { "um", UTF8_MU"m", "\265m", 10e3, ".1f", ".2f" },
00053 { "mm", "mm", "mm", 10e6, ".1f", ".2f" },
00054 { "BZ", "%BZ", "%BZ", 1e0, ".1f", ".2f" },
00055 { "sec","\"", "\"", 1e0, ".1f", ".2f" },
00056 { "V", "V", "V", 1e0, ".2f", ".3f" },
00057 { "1", " ", " ", 1e0, ".3f", ".4f" },
00058 { "Amp", "A", "A", 1e9, "g", "g" },
00059 { "nA", "nA", "nA", 1e0, ".2f", ".3f" },
00060 { "pA", "pA", "pA", 1e-3, ".1f", ".2f" },
00061 { "nN", "nN", "nN", 1e0, ".2f", ".3f" },
00062 { "Hz", "Hz", "Hz", 1e0, ".2f", ".3f" },
00063 { "K", "K", "K", 1e0, ".2f", ".3f" },
00064 { "amu","amu", "amu", 1e0, ".1f", ".2f" },
00065 { "CPS","Cps", "Cps", 1e0, ".1f", ".2f" },
00066 { "Int","Int", "Int", 1e0, ".1f", ".2f" },
00067 { NULL, NULL, NULL, 0e0, NULL, NULL }
00068 };
00069
00070
00071
00072
00073
00074
00075 Xsm::Xsm(){
00076
00077
00078 if(xsmres.UnitCmd)
00079 strcpy(xsmres.Unit, xsmres.UnitCmd);
00080
00081
00082 for(AktUnit=XsmUnitsTable; AktUnit->alias; ++AktUnit)
00083 if(! strcmp(AktUnit->alias, xsmres.Unit)) break;
00084
00085 if(!AktUnit->alias){
00086 AktUnit = &XsmUnitsTable[1];
00087 XSM_DEBUG_ERROR (DBG_L1, "Invalid Unit specified ! Falling back to default." );
00088 }
00089
00090
00091 Unity = new UnitObj(" "," ");
00092 ArcUnit = new UnitObj(UTF8_DEGREE,"\260");
00093 HzUnit = new UnitObj("Hz","Hz");
00094 RadUnit = new LinUnit(" "," ",180./M_PI);
00095 VoltUnit = new UnitObj("V","V",".2f","Volt");
00096 BZSymUnit = new UnitObj("%BZ","%BZ");
00097 CurrentUnit = new UnitObj("nA","nA","g","Current");
00098 TimeUnitms = new LinUnit("ms","ms", "Time", 1e-3);
00099 TimeUnit = new UnitObj("s","s", "g", "Time");
00100 CPSUnit = new CPSCNTUnit("Cps","Cps","Int.");
00101 CPSHiLoUnit = new CPSCNTUnit("Cps","Cps","Int.");
00102 EnergyUnit = new UnitObj("eV","eV",".2f","Energy");
00103 BZ_Unit = new BZUnit("%BZ","%BZ", xsmres.Sensitivity, 1.);
00104 YSUnit = new SUnit("S","S", xsmres.SampleLayerDist, xsmres.ThetaChGunInt);
00105
00106 LenUnit = NULL;
00107 LenUnitZ = NULL;
00108
00109
00110 X_Unit = Y_Unit = Z_Unit = NULL;
00111
00112 if( IS_SPALEED_CTRL ){
00113 if(! strcmp(AktUnit->alias, "BZ") )
00114 X_Unit = Y_Unit = BZ_Unit;
00115 else
00116 X_Unit = Y_Unit = VoltUnit;
00117 Z_Unit = CPSUnit;
00118 X_Unit->SetAlias (AktUnit->alias);
00119 Z_Unit->SetAlias ("Cps");
00120 }else{
00121 LenUnit = new LinUnit(AktUnit->s, AktUnit->pss, "L",AktUnit->fac);
00122 LenUnit->SetAlias (AktUnit->alias);
00123 LenUnitZ = new LinUnit(AktUnit->s, AktUnit->pss, "H",AktUnit->fac);
00124 LenUnitZ->SetAlias (AktUnit->alias);
00125 Z_Unit = LenUnitZ;
00126 X_Unit = Y_Unit = LenUnit;
00127 }
00128
00129
00130 if(xsmres.HardwareTypeCmd)
00131 strcpy(xsmres.HardwareType, xsmres.HardwareTypeCmd);
00132
00133 hardware=NULL;
00134 HwI_plugins = NULL;
00135
00136
00137 if(IS_SPALEED_CTRL)
00138 Inst = new SPALEED_Instrument(xsmres,
00139 &data.s.Energy,
00140 &data.display.cnttime,
00141 &ModeFlg);
00142 else
00143 Inst = new XSM_Instrument(xsmres);
00144
00145
00146 ModeFlg = 0;
00147 ZoomFlg = VIEW_ZOOM | VIEW_Z400;
00148
00149
00150 data.LoadValues(Inst, hardware);
00151
00152 mradius=1.;
00153
00154 counter = 0;
00155 subcounter = 0;
00156
00157 data.ui.MakeUIdefaults();
00158
00159 data.Xunit = NULL;
00160 data.Yunit = NULL;
00161 data.Zunit = NULL;
00162 data.Vunit = NULL;
00163
00164 data.SetXUnit (X_Unit);
00165 data.SetYUnit (Y_Unit);
00166 data.SetZUnit (Z_Unit);
00167 data.SetVUnit (VoltUnit);
00168
00169 data.CurrentUnit= CurrentUnit->Copy ();
00170 data.VoltUnit = VoltUnit->Copy ();
00171 data.TimeUnit = TimeUnit->Copy ();
00172 data.TimeUnitms = TimeUnitms->Copy ();
00173 data.CPSUnit = CPSUnit->Copy ();
00174 data.EnergyUnit = EnergyUnit->Copy ();
00175
00176 XSM_DEBUG (DBG_L2, "Xsm::Xsm : Init done");
00177 }
00178
00179 Xsm::~Xsm(){
00180 XSM_DEBUG (DBG_L2, "Xsm::~Xsm deleting unit objects");
00181
00182 if(LenUnit)
00183 delete LenUnit;
00184 if(LenUnitZ)
00185 delete LenUnitZ;
00186 delete YSUnit;
00187 delete BZ_Unit;
00188 delete EnergyUnit;
00189 delete CPSUnit;
00190 delete TimeUnit;
00191 delete TimeUnitms;
00192 delete CurrentUnit;
00193 delete BZSymUnit;
00194 delete VoltUnit;
00195 delete RadUnit;
00196 delete HzUnit;
00197 delete ArcUnit;
00198 delete Unity;
00199
00200 XSM_DEBUG (DBG_L2, "Xsm::~Xsm delete hardware");
00201 if (HwI_plugins) {
00202 if (!HwI_plugins -> get_xsm_hwi_class () && hardware)
00203 delete hardware;
00204 delete HwI_plugins;
00205 } else
00206 delete hardware;
00207
00208 hardware=NULL;
00209
00210 delete Inst;
00211 Inst=NULL;
00212
00213 XSM_DEBUG (DBG_L2, "Xsm::~Xsm done.");
00214
00215 }
00216
00217
00218 void Xsm::reload_hardware_interface (App *app){
00219
00220 if (HwI_plugins) {
00221 if (!HwI_plugins -> get_xsm_hwi_class () && hardware)
00222 delete hardware;
00223 delete HwI_plugins;
00224 } else
00225 if (hardware)
00226 delete hardware;
00227
00228 HwI_plugins = NULL;
00229 hardware=NULL;
00230
00231
00232 if (!app) return;
00233
00234
00235 if(!hardware)
00236 hardware = HwI_Plugin_Load (app);
00237
00238 if(!hardware)
00239 hardware = new XSM_Hardware;
00240 }
00241
00242 UnitObj *Xsm::MakeUnit(const gchar *alias, const gchar *label){
00243 UnitsTable *u;
00244
00245
00246 for(u=XsmUnitsTable; u->alias; ++u)
00247 if(! strcmp(u->alias, alias)) break;
00248
00249 if(!u->alias){
00250 u = &XsmUnitsTable[1];
00251 XSM_DEBUG_ERROR (DBG_L3, "Invalid Unit >" << alias << "< specified ! Falling back to default.");
00252 }
00253 XSM_DEBUG(DBG_L3, "MakeUnit" << u->alias );
00254 UnitObj *uob = new LinUnit(u->s, u->pss, label, u->fac);
00255 uob->SetAlias (u->alias);
00256 XSM_DEBUG(DBG_L3, "MakeUnit" << u->alias << " done." );
00257
00258 return uob;
00259 }
00260
00261 void Xsm::UpdateUnits(){
00262 if(IsMode(MODE_BZUNIT) && X_Unit != BZ_Unit){
00263 X_Unit = Y_Unit = BZ_Unit;
00264 gapp->spm_update_all();
00265 }else
00266 if(IsMode(MODE_VOLTUNIT) && X_Unit != VoltUnit){
00267 X_Unit = Y_Unit = VoltUnit;
00268 gapp->spm_update_all();
00269 }
00270 }
00271
00272
00273
00274
00275
00276
00277 gint Xsm::HwI_Plugin_Check (const gchar *category){
00278 gint ret = FALSE;
00279 gint i;
00280 gchar **catlist, **cs;
00281 gchar *key, *fullclass;
00282 XsmRescourceManager xrm("HardwareInterfaces");
00283
00284 if( ! category )
00285 return ret;
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 for (cs = catlist = g_strsplit (category, ":", 0); *cs; ++cs){
00301 fullclass = g_strdup (*catlist);
00302 if (cs == catlist) ++cs;
00303 if (*cs){
00304 g_free (fullclass);
00305 fullclass = g_strconcat (*catlist, ":", *cs, NULL);
00306 }
00307 xrm.Get ("HwI-count", &i);
00308 key = g_strdup_printf ("HwI-%02d", i);
00309 xrm.Put (key, fullclass);
00310 g_free (key);
00311 xrm.Put ("HwI-count", ++i);
00312
00313 if ( !strcmp (xsmres.HardwareType, fullclass) )
00314 ret = TRUE;
00315
00316 g_free (fullclass);
00317
00318 if (! *cs) break;
00319 }
00320 g_strfreev (catlist);
00321
00322 return ret;
00323 }
00324
00325 XSM_Hardware* Xsm::HwI_Plugin_Load (App* app){
00326 XsmRescourceManager xrm("HardwareInterfaces");
00327 xrm.Put("HwI-count", 0);
00328
00329 gint (*hwi_type_check_func)(const gchar *) = HwI_Plugin_Check;
00330 GList *PluginDirs = NULL;
00331 XSM_DEBUG(DBG_L2, "Load/select GXSM HwI plugin(s)" );
00332
00333
00334 PluginDirs = g_list_prepend
00335 (PluginDirs, g_strconcat(PACKAGE_PLUGIN_DIR, "/hard", NULL));
00336
00337 HwI_plugins = new gxsm_hwi_plugins (PluginDirs, hwi_type_check_func, xsmres.HardwareType, app);
00338
00339
00340 GList *node = PluginDirs;
00341 while(node){
00342 g_free(node->data);
00343 node = node->next;
00344 }
00345 g_list_free(PluginDirs);
00346
00347 return HwI_plugins -> get_xsm_hwi_class ();
00348 }
00349
00350
00351
00352
00353
00354
00355 SCAN_DATA::SCAN_DATA(){
00356
00357 if(xsmres.ScanOrgCenter)
00358 orgmode = SCAN_ORG_CENTER;
00359 else
00360 orgmode = SCAN_ORG_MIDDLETOP;
00361
00362 scan_mode = SCAN_MODE_SINGLE_DSPSET;
00363 scan_repeat_mode = SCAN_REPEAT_MODE_UNIDIR;
00364 scan_type = SCAN_TYPE_NORMAL;
00365
00366 UnitObj UnityNA ("N/A","N/A");
00367
00368 Zunit = UnityNA.Copy ();
00369 Xunit = UnityNA.Copy ();
00370 Yunit = UnityNA.Copy ();
00371 Vunit = UnityNA.Copy ();
00372 CurrentUnit = UnityNA.Copy ();
00373 VoltUnit = UnityNA.Copy ();
00374 TimeUnit = UnityNA.Copy ();
00375 TimeUnitms = UnityNA.Copy ();
00376 CPSUnit = UnityNA.Copy ();
00377 EnergyUnit = UnityNA.Copy ();
00378
00379 UnitsAlloc = TRUE;
00380
00381 XSM_DEBUG (DBG_L2, "SCAN_DATA::SCANDATA #" << ++scandatacount); cnt=scandatacount;
00382 }
00383
00384 SCAN_DATA::~SCAN_DATA(){
00385 if(UnitsAlloc){
00386 if(Zunit) {
00387 delete Zunit; Zunit=NULL;
00388 }
00389 if(Xunit) {
00390 delete Xunit; Xunit=NULL;
00391 }
00392 if(Yunit) {
00393 delete Yunit; Yunit=NULL;
00394 }
00395 if(Vunit) {
00396 delete Vunit; Vunit=NULL;
00397 }
00398 if(CurrentUnit) {
00399 delete CurrentUnit; CurrentUnit=NULL;
00400 }
00401 if(VoltUnit) {
00402 delete VoltUnit; VoltUnit=NULL;
00403 }
00404 if(TimeUnit) {
00405 delete TimeUnit; TimeUnit=NULL;
00406 }
00407 if(TimeUnitms) {
00408 delete TimeUnitms; TimeUnitms=NULL;
00409 }
00410 if(CPSUnit) {
00411 delete CPSUnit; CPSUnit=NULL;
00412 }
00413 if(EnergyUnit) {
00414 delete EnergyUnit; EnergyUnit=NULL;
00415 }
00416 }
00417 XSM_DEBUG (DBG_L2, "SCAN_DATA::~SCANDATA #" << scandatacount--);
00418 }
00419
00420
00421 void SCAN_DATA::CpUnits(SCAN_DATA &src){
00422 XSM_DEBUG (DBG_L2, "SCAN_DATA: CpUnits #" << cnt);
00423
00424 if(Zunit) delete Zunit;
00425 Zunit = src.Zunit->Copy();
00426
00427 if(Xunit){
00428 delete Xunit;
00429 Xunit = NULL;
00430 }
00431 if(src.Xunit)
00432 Xunit = src.Xunit->Copy();
00433
00434 if(Yunit){
00435 delete Yunit;
00436 Yunit=NULL;
00437 }
00438 if(src.Yunit)
00439 Yunit = src.Yunit->Copy();
00440
00441 if(Vunit){
00442 delete Vunit;
00443 Vunit=NULL;
00444 }
00445 if(src.Vunit)
00446 Vunit = src.Vunit->Copy();
00447
00448 if(CurrentUnit) delete CurrentUnit;
00449 CurrentUnit = src.CurrentUnit->Copy();
00450
00451 if(VoltUnit) delete VoltUnit;
00452 VoltUnit = src.VoltUnit->Copy();
00453
00454 if(TimeUnit) delete TimeUnit;
00455 TimeUnit = src.TimeUnit->Copy();
00456
00457 if(TimeUnitms) delete TimeUnitms;
00458 TimeUnitms = src.TimeUnitms->Copy();
00459
00460 if(CPSUnit) delete CPSUnit;
00461 CPSUnit = src.CPSUnit->Copy();
00462
00463 if(EnergyUnit) delete EnergyUnit;
00464 EnergyUnit = src.EnergyUnit->Copy();
00465
00466 UnitsAlloc = TRUE;
00467 }
00468
00469 void SCAN_DATA::SetXUnit(UnitObj *u){
00470 if(Xunit) delete Xunit;
00471 Xunit = u->Copy();
00472 }
00473
00474 void SCAN_DATA::SetYUnit(UnitObj *u){
00475 if(Yunit) delete Yunit;
00476 Yunit = u->Copy();
00477 }
00478
00479 void SCAN_DATA::SetVUnit(UnitObj *u){
00480 if(Vunit) delete Vunit;
00481 Vunit = u->Copy();
00482 }
00483
00484 void SCAN_DATA::SetZUnit(UnitObj *u){
00485 if(Zunit) delete Zunit;
00486 Zunit = u->Copy();
00487 }
00488
00489
00490 void SCAN_DATA::SaveValues(gchar *SetName){
00491 XsmRescourceManager xrm("Values", SetName);
00492 xrm.Put("XSMVersion", PACKAGE "-" VERSION);
00493 xrm.Put("XSMBuild", COMPILEDBYNAME);
00494
00495 xrm.Put("s.ntimes", s.ntimes);
00496 xrm.Put("s.values", s.nvalues);
00497 xrm.Put("s.nx", s.nx);
00498 xrm.Put("s.ny", s.ny);
00499
00500 xrm.Put("s.rx", s.rx);
00501 xrm.Put("s.ry", s.ry);
00502 xrm.Put("s.rz", s.rz);
00503 xrm.Put("s.dx", s.dx);
00504 xrm.Put("s.dy", s.dy);
00505 xrm.Put("s.dz", s.dz);
00506 xrm.Put("s.dl", s.dl);
00507
00508 xrm.Put("s.alpha", s.alpha);
00509 xrm.Put("s.x0", s.x0);
00510 xrm.Put("s.y0", s.y0);
00511 xrm.Put("s.SPA_OrgX", s.SPA_OrgX);
00512 xrm.Put("s.SPA_OrgY", s.SPA_OrgY);
00513
00514 xrm.Put("s.Bias", s.Bias);
00515 xrm.Put("s.Current", s.Current);
00516 xrm.Put("s.SetPoint", s.SetPoint);
00517 xrm.Put("s.Energy", s.Energy);
00518 xrm.Put("s.GateTime", s.GateTime);
00519
00520 xrm.Put("display.ViewFlg", display.ViewFlg);
00521 xrm.Put("display.contrast", display.contrast);
00522 xrm.Put("display.bright", display.bright);
00523 xrm.Put("display.cpshigh", display.cpshigh);
00524 xrm.Put("display.cpslow", display.cpslow);
00525 xrm.Put("display.vrange_z", display.vrange_z);
00526 xrm.Put("display.voffset_z", display.voffset_z);
00527 xrm.Put("display.vframe", display.vframe);
00528 xrm.Put("display.vlayer", display.vlayer);
00529 };
00530
00531 void SCAN_DATA::LoadValues(XSM_Instrument *Inst, XSM_Hardware *hardware, gchar *SetName){
00532 gchar *defaultval;
00533 XsmRescourceManager xrm("Values", SetName);
00534
00535
00536
00537 if(Inst){
00538 defaultval = g_strdup_printf("%g", 2000.*Inst->XResolution());
00539 xrm.Get("s.rx", &s.rx, defaultval);
00540 g_free(defaultval);
00541 defaultval = g_strdup_printf("%g", 2000.*Inst->YResolution());
00542 xrm.Get("s.ry", &s.ry, defaultval);
00543 g_free(defaultval);
00544 xrm.Get("s.rz", &s.rz, "1000");
00545 defaultval = g_strdup_printf("%g", 10.*Inst->XResolution());
00546 xrm.Get("s.dx", &s.dx, defaultval);
00547 g_free(defaultval);
00548 defaultval = g_strdup_printf("%g", 10.*Inst->YResolution());
00549 xrm.Get("s.dy", &s.dy, defaultval);
00550 g_free(defaultval);
00551 }
00552 xrm.Get("s.dz", &s.dz, "10");
00553 xrm.Get("s.dl", &s.dl, "10");
00554 xrm.Get("s.alpha", &s.alpha);
00555 xrm.Get("s.x0", &s.x0, "0");
00556 xrm.Get("s.y0", &s.y0, "0");
00557 xrm.Get("s.SPA_OrgX", &s.SPA_OrgX, "0");
00558 xrm.Get("s.SPA_OrgY", &s.SPA_OrgY, "0");
00559
00560 if(hardware)
00561 defaultval = g_strdup_printf("%d", (int) MIN(R2INT(s.rx/s.dx), hardware->GetMaxPointsPerLine()));
00562 else
00563 defaultval = g_strdup_printf("10000");
00564
00565 xrm.Get("s.nx", &s.nx, defaultval);
00566 g_free(defaultval);
00567 defaultval = g_strdup_printf("%d", R2INT(s.ry/s.dy));
00568 xrm.Get("s.ny", &s.ny, defaultval);
00569 g_free(defaultval);
00570
00571 xrm.Get("s.nvalues", &s.nvalues, "1");
00572 xrm.Get("s.ntimes", &s.ntimes, "1");
00573
00574 xrm.Get("s.Bias", &s.Bias, "2");
00575 xrm.Get("s.Current", &s.Current, "1");
00576 xrm.Get("s.SetPoint", &s.SetPoint, "0");
00577 xrm.Get("s.GateTime", &s.GateTime, "1");
00578 xrm.Get("s.Energy", &s.Energy, "72");
00579
00580 defaultval = g_strdup_printf("%d", SCAN_V_QUICK);
00581 xrm.Get("display.ViewFlg", &display.ViewFlg, defaultval);
00582 g_free(defaultval);
00583 xrm.Get("display.contrast", &display.contrast, "0.5");
00584 xrm.Get("display.bright", &display.bright, "32.0");
00585 xrm.Get("display.cpshigh", &display.cpshigh, "1e6");
00586 xrm.Get("display.cpslow", &display.cpslow, "0.0");
00587 xrm.Get("display.vrange_z", &display.vrange_z, "25.0");
00588 xrm.Get("display.voffset_z", &display.voffset_z, "0.0");
00589 xrm.Get("display.vframe", &display.vframe, "0");
00590 xrm.Get("display.vlayer", &display.vlayer, "0");
00591 }
00592
00593
00594