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 <locale.h>
00029 #include <libintl.h>
00030
00031
00032
00033 #include "gxsm_app.h"
00034
00035 #include "unit.h"
00036 #include "util.h"
00037 #include "pcs.h"
00038 #include "xsmtypes.h"
00039 #include "glbvars.h"
00040
00041 #include "app_profile.h"
00042 #include "app_profilepopupdef.h"
00043
00044
00045
00046 menuoptionlist profile_modes[] = {
00047 { "Options/no Gridlines", PROFILE_MODE_XGRID, TRUE },
00048 { "Options/no Gridlines", PROFILE_MODE_YGRID, TRUE },
00049 { "Options/Ticmarks", PROFILE_MODE_NOTICS, FALSE },
00050 { "Options/Y linregression", PROFILE_MODE_YLINREG, FALSE },
00051 { "Options/Y logarithmic", PROFILE_MODE_YLOG, FALSE },
00052 { NULL, 0, 0 }
00053 };
00054
00055 menuoptionlist profile_scale[] = {
00056 { "Y hold", PROFILE_SCALE_YHOLD, FALSE },
00057 { "Y expand only", PROFILE_SCALE_YEXPAND, FALSE },
00058 { NULL, 0, 0 }
00059 };
00060
00061 #define LOG_RESCUE_RATIO 100.
00062
00063 ProfileElement::ProfileElement(Scan *sc, ProfileControl *pc, gchar *col, int Yy){
00064 XSM_DEBUG (DBG_L2, "ProfileElement::ProfileElement sc");
00065 yy = Yy;
00066 scan = sc;
00067 psd_scan = NULL;
00068
00069 if(col)
00070 color = g_strdup(col);
00071 else
00072 color = g_strdup("black");
00073
00074 pctrl=pc;
00075 pn = NULL;
00076 pathitem = NULL;
00077 XSM_DEBUG (DBG_L2, "ProfileElement::ProfileElement sc done");
00078 }
00079
00080 ProfileElement::ProfileElement(ProfileElement *pe, gchar *col, int Yy){
00081 XSM_DEBUG (DBG_L2, "ProfileElement::ProfileElement pe");
00082 yy = Yy;
00083 scan = pe->scan;
00084 psd_scan = NULL;
00085
00086 if(col)
00087 color = g_strdup(col);
00088 else
00089 color = g_strdup("black");
00090
00091 pctrl=pe->pctrl;
00092 pn = NULL;
00093 pathitem = NULL;
00094 XSM_DEBUG (DBG_L2, "ProfileElement::ProfileElement pe done.");
00095 }
00096
00097 ProfileElement::~ProfileElement(){
00098 XSM_DEBUG (DBG_L2, "ProfileElement::~ProfileElement");
00099 if(pathitem)
00100 gtk_object_destroy(GTK_OBJECT(pathitem));
00101 if(pn)
00102 gnome_canvas_points_unref(pn);
00103 g_free(color);
00104 }
00105
00106 void ProfileElement::SetMode(long Mode){
00107 mode=Mode;
00108 }
00109
00110 void ProfileElement::SetOptions(long Flg){
00111 flg=Flg;
00112 }
00113
00114 void ProfileElement::calc(int ymode){
00115 int i, ix, iy;
00116 double *xy, logymin;
00117 Scan *s;
00118
00119 n=scan->mem2d->GetNx();
00120 if(n < 2) return;
00121
00122 if(ymode & PROFILE_MODE_YPSD){
00123 if(psd_scan)
00124 delete psd_scan;
00125 psd_scan = new Scan (scan);
00126 F1D_LogPowerSpec(scan, psd_scan);
00127 s = psd_scan;
00128 }
00129 else
00130 s = scan;
00131
00132 n = s->mem2d->GetNx();
00133 if(pn)
00134 gnome_canvas_points_unref(pn);
00135 pn = NULL;
00136
00137 n=s->mem2d->GetNx();
00138 if(n < 2) return;
00139
00140 logymin = xsmres.ProfileLogLimit;
00141
00142 pn = gnome_canvas_points_new(n=s->mem2d->GetNx());
00143 xy = pn->coords;
00144
00145 if(ymode & PROFILE_MODE_YLINREG){
00146 ylocmin=ylocmax=scan->data.Zunit->Base2Usr(s->mem2d->GetDataPktLineReg(0,yy)*s->data.s.dz);
00147 for(i=0, ix=0, iy=1; i < n; ix+=2, iy+=2, ++i){
00148 xy[ix] = s->data.Xunit->Base2Usr(s->mem2d->data->GetXLookup(i));
00149 xy[iy] = s->data.Zunit->Base2Usr(s->mem2d->GetDataPktLineReg(i,yy)*scan->data.s.dz);
00150 if(xy[iy] > ylocmax) ylocmax=xy[iy];
00151 else if(xy[iy] < ylocmin) ylocmin=xy[iy];
00152 }
00153 }else{
00154 if(ymode & PROFILE_MODE_YLOG){
00155 double y = scan->data.Zunit->Base2Usr(s->mem2d->GetDataPkt(0,yy)*s->data.s.dz);
00156 if (y <= logymin) y = logymin;
00157 ylocmin = ylocmax = y;
00158 for(i=0, ix=0, iy=1; i < n; ix+=2, iy+=2, ++i){
00159 xy[ix] = s->data.Xunit->Base2Usr(s->mem2d->data->GetXLookup(i));
00160 xy[iy] = s->data.Zunit->Base2Usr(s->mem2d->GetDataPkt(i,yy)*scan->data.s.dz);
00161 if (xy[iy] <= logymin){
00162 if (iy > 2) xy[iy] = xy[iy-2];
00163 else xy[iy] = logymin;
00164 }
00165
00166
00167 if (xy[iy] > ylocmax) ylocmax = xy[iy];
00168 else if (xy[iy] < ylocmin) ylocmin = xy[iy];
00169 }
00170 }else{
00171 ylocmin=ylocmax=scan->data.Zunit->Base2Usr(s->mem2d->GetDataPkt(0,yy)*s->data.s.dz);
00172 for(i=0, ix=0, iy=1; i < n; ix+=2, iy+=2, ++i){
00173 xy[ix] = s->data.Xunit->Base2Usr(s->mem2d->data->GetXLookup(i));
00174 xy[iy] = s->data.Zunit->Base2Usr(s->mem2d->GetDataPkt(i,yy)*scan->data.s.dz);
00175 if(xy[iy] > ylocmax) ylocmax=xy[iy];
00176 else if(xy[iy] < ylocmin) ylocmin=xy[iy];
00177 }
00178 }
00179 }
00180
00181 xlocmin=xlocmax=xy[0];
00182 for (i=0; i<n; ++i){
00183 if (xlocmax < xy[2*i]) xlocmax=xy[2*i];
00184 if (xlocmin > xy[2*i]) xlocmin=xy[2*i];
00185 }
00186 }
00187
00188 void ProfileElement::draw(GtkWidget *canvas){
00189 int i;
00190 double *xy;
00191 if(!pn) return;
00192 xy = pn->coords;
00193
00194 for(i=0; i < n; ++i)
00195 pctrl->scan2canvas(xy[2*i], xy[2*i+1]);
00196
00197 if(pathitem)
00198 gnome_canvas_item_set(pathitem, "points", pn, NULL);
00199
00200
00201 else
00202 pathitem = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00203 gnome_canvas_line_get_type(),
00204 "points", pn,
00205 "fill_color", color,
00206 "width_pixels", 1,
00207
00208 NULL);
00209
00210 }
00211
00212
00213
00214 ProfileControl::ProfileControl (gchar *titlestring, int ChNo){
00215 Init(titlestring, ChNo);
00216 ref ();
00217 }
00218
00219 ProfileControl::ProfileControl (gchar *titlestring, int n, UnitObj *ux, UnitObj *uy, double xmin, double xmax, gchar *resid) : LineProfile1D(n, ux, uy, xmin, xmax){
00220 Init(titlestring, -1, resid);
00221 ref ();
00222 gtk_signal_connect(GTK_OBJECT(widget),
00223 "delete_event",
00224 GTK_SIGNAL_FUNC (ProfileControl::file_close_callback),
00225 this);
00226 gchar *tmp;
00227 SetXlabel (tmp = scan1d->data.Xunit->MakeLongLabel());
00228 g_free (tmp);
00229
00230 SetYlabel (tmp = scan1d->data.Zunit->MakeLongLabel());
00231 g_free (tmp);
00232
00233 AddScan(scan1d);
00234
00235 UpdateArea ();
00236 show();
00237 }
00238
00239 ProfileControl::ProfileControl (gchar *filename, gchar *resource_id_string){
00240 XSM_DEBUG (DBG_L3, "ProfileControl::ProfileControl from file" << filename );
00241
00242 gchar *t = g_strconcat (filename, " - Profile from File", NULL);
00243 Init (t, -1, resource_id_string);
00244 g_free (t);
00245
00246 gtk_signal_connect(GTK_OBJECT(widget),
00247 "delete_event",
00248 GTK_SIGNAL_FUNC (ProfileControl::file_close_callback),
00249 this);
00250
00251 XSM_DEBUG (DBG_L3, "ProfileControl::ProfileControl from file - Init done, loading data");
00252
00253 load (filename);
00254
00255 XSM_DEBUG (DBG_L3, "ProfileControl::ProfileControl from file - label setup...");
00256
00257 gchar *tmp;
00258 SetXlabel (tmp = scan1d->data.Xunit->MakeLongLabel());
00259 g_free (tmp);
00260
00261 SetYlabel (tmp = scan1d->data.Zunit->MakeLongLabel());
00262 g_free (tmp);
00263
00264 XSM_DEBUG (DBG_L3, "ProfileControl::ProfileControl from file Add Scan" );
00265
00266 AddScan(scan1d);
00267
00268 XSM_DEBUG (DBG_L3, "ProfileControl::ProfileControl from file Update" );
00269
00270 UpdateArea ();
00271 show();
00272
00273 XSM_DEBUG (DBG_L3, "ProfileControl::ProfileControl from file done." );
00274 }
00275
00276 void ProfileControl::Init(gchar *titlestring, int ChNo, gchar *resid){
00277 int i;
00278 GtkWidget *popup, *hbox;
00279 GtkWidget *scrollarea;
00280 gchar *tmp;
00281 gchar *defaultval;
00282
00283 ref_count = 0;
00284 tic_x1=0.,tic_x2=0.,tic_y1=0.,tic_y2=0.;
00285 tic_ym=0;
00286
00287 new_data_nl=1;
00288 new_data_lastl=-1;
00289
00290
00291
00292 if (resid)
00293 profile_res_id = g_strconcat ("Profile/", resid, NULL);
00294 else{
00295 if(strstr(titlestring, "Red"))
00296 profile_res_id = g_strdup("Profile/Red-Line");
00297 else
00298 if(strstr(titlestring, "from"))
00299 profile_res_id = g_strdup("Profile/Show-Line");
00300 else
00301 if(strstr(titlestring, "Probe"))
00302 profile_res_id = g_strdup("Profile/Probe-Data");
00303 else
00304 if(strstr(titlestring, ".asc"))
00305 profile_res_id = g_strdup("Profile/File-Data");
00306 else
00307 profile_res_id = g_strdup("Profile/Other-Line");
00308 }
00309
00310 chno=ChNo;
00311
00312 if (titlestring)
00313 AppWidgetInit (titlestring);
00314 else
00315 AppWidgetInit ("Profile");
00316
00317 XsmRescourceManager xrm (profile_res_id);
00318
00319 Cursor[0][0] = NULL;
00320 Cursor[0][1] = NULL;
00321 Cursor[1][0] = NULL;
00322 Cursor[1][1] = NULL;
00323 CursorsIdx[0]=0;
00324 CursorsIdx[1]=0;
00325 working=0;
00326
00327 last_pe = NULL;
00328 scount=0;
00329 statusheight = 20;
00330 border=0.10;
00331 pasize=1.0;
00332 aspect=3./2.;
00333 defaultval = g_strdup_printf("%g", aspect);
00334 xrm.Get("XYaspectratio", &aspect, defaultval);
00335 xrm.Put("XYaspectratio", aspect);
00336 g_free(defaultval);
00337
00338 papixel=400;
00339 defaultval = g_strdup_printf("%d", papixel);
00340 xrm.Get("Xsize", &papixel, defaultval);
00341 xrm.Put("Xsize", papixel);
00342 g_free(defaultval);
00343
00344 Yticn=8;
00345 defaultval = g_strdup_printf("%d", Yticn);
00346 xrm.Get("Yticn", &Yticn, defaultval);
00347 xrm.Put("Yticn", Yticn);
00348 g_free(defaultval);
00349
00350 Xticn=8;
00351 defaultval = g_strdup_printf("%d", Xticn);
00352 xrm.Get("Xticn", &Xticn, defaultval);
00353 xrm.Put("Xticn", Xticn);
00354 g_free(defaultval);
00355
00356
00357 Xtics = new GnomeCanvasItem*[PC_XTN];
00358 Ytics = new GnomeCanvasItem*[PC_YTN];
00359 Xlabels = new GnomeCanvasItem*[PC_XLN];
00360 Ylabels = new GnomeCanvasItem*[PC_YLN];
00361 for(i=0; i<PC_XTN; i++) Xtics[i] = NULL;
00362 for(i=0; i<PC_YTN; i++) Ytics[i] = NULL;
00363 for(i=0; i<PC_XLN; i++) Xlabels[i] = NULL;
00364 for(i=0; i<PC_YLN; i++) Ylabels[i] = NULL;
00365
00366 ScanList = NULL;
00367 background = NULL;
00368 frame = NULL;
00369 xaxislabel = NULL;
00370 yaxislabel = NULL;
00371
00372 xlabel0 = NULL;
00373 ylabel0 = NULL;
00374 xlabel = g_strdup("x");
00375 ylabel = g_strdup("y");
00376 title = g_strdup("title");
00377
00378 defaultval = g_strdup("%g");
00379 xrm.Get("XticFmt", &tmp, defaultval);
00380 xticfmt = g_strdup(tmp);
00381 xrm.Put("XticFmt", xticfmt);
00382 g_free(defaultval);
00383
00384 defaultval = g_strdup("%g");
00385 xrm.Get("YticFmt", &tmp, defaultval);
00386 yticfmt = g_strdup(tmp);
00387 xrm.Put("YticFmt", yticfmt);
00388 g_free(defaultval);
00389
00390 SetXrange(0., 1.);
00391 SetYrange(0., 1.);
00392
00393 SetMode(PROFILE_MODE_XGRID | PROFILE_MODE_YGRID | PROFILE_MODE_CONNECT);
00394 defaultval = g_strdup_printf("%d", (int) mode);
00395 xrm.Get("ModeCode", &i, defaultval);
00396 SetMode(i);
00397 g_free(defaultval);
00398
00399
00400
00401 SetScaling(PROFILE_SCALE_XAUTO | PROFILE_SCALE_YAUTO);
00402 defaultval = g_strdup_printf("%d", (int) scaleing);
00403 xrm.Get("ScalingCode", &i, defaultval);
00404 i &= ~PROFILE_SCALE_YHOLD;
00405 SetScaling(i);
00406 g_free(defaultval);
00407
00408 XSM_DEBUG (DBG_L2, "ProfileControl::ProfileControl set_data to widget");
00409
00410 gtk_object_set_data (GTK_OBJECT (widget), "Ch", (void*)chno);
00411 gtk_object_set_data (GTK_OBJECT (widget), "ChNo", (void*)(chno+1));
00412 gapp->configure_drop_on_widget(widget);
00413
00414 if(chno>=0)
00415 gtk_signal_connect(GTK_OBJECT(widget),
00416 "delete_event",
00417 GTK_SIGNAL_FUNC(App::close_scan_event_cb),
00418 this);
00419
00420
00421
00422 scrollarea = gtk_scrolled_window_new (NULL, NULL);
00423 gtk_container_set_border_width (GTK_CONTAINER (scrollarea), 0);
00424
00425
00426
00427
00428
00429
00430 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollarea),
00431 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
00432
00433
00434 gtk_box_pack_start (GTK_BOX (vbox), scrollarea, TRUE, TRUE, 0);
00435 gtk_widget_show (scrollarea);
00436
00437
00438 XSM_DEBUG (DBG_L2, "ProfileControl::ProfileControl PopupNew");
00439
00440 GtkAccelGroup *accel_group;
00441 accel_group = gtk_accel_group_new ();
00442 gtk_window_add_accel_group (GTK_WINDOW (widget), accel_group);
00443 popup = (GtkWidget*) gnome_popup_menu_new_with_accelgroup (
00444 profile_popup_menu,
00445 accel_group
00446 );
00447 gnome_popup_menu_attach ( popup, widget, this);
00448
00449
00450
00451
00452
00453 gtk_object_set_data (
00454 GTK_OBJECT (popup),
00455 "gnome_popup_menu_do_popup_user_data",
00456 this
00457 );
00458
00459 #ifdef XXXXXXX_INIT_DEFAULTS
00460
00461
00462 GtkWidget *menushell;
00463 GtkWidget *menuitem;
00464 gint pos;
00465 menuoptionlist *pmo;
00466
00467
00468
00469 XSM_DEBUG (DBG_L3, "--------- Option Modes ..." );
00470 for(pmo = profile_modes; pmo->mitem; pmo++){
00471 XSM_DEBUG (DBG_L3, "checking >" << pmo->mitem << "< neg: " << pmo->neg << " soll: " << (mode&pmo->msk) );
00472 int key;
00473 cout << "Press Key..." << endl; cin >> key;
00474 if(((mode & pmo->msk) && !pmo->neg) || (!(mode & pmo->msk) && pmo->neg)){
00475 XSM_DEBUG (DBG_L3, "searching for >" << pmo->mitem << "<" );
00476 pos=0;
00477 menushell = gnome_app_find_menu_pos (popup, pmo->mitem, &pos);
00478 if(menushell){
00479 menuitem = (GtkWidget*)g_list_nth_data(GTK_MENU_SHELL (menushell) -> children, --pos);
00480 XSM_DEBUG (DBG_L3, "found menuitem " << menuitem << " at pos: " << pos );
00481 if(menuitem){
00482 gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
00483 XSM_DEBUG (DBG_L3, "found and selected." );
00484 }
00485 }
00486 }
00487 }
00488
00489
00490 XSM_DEBUG (DBG_L3, "--------- Scaling Modes ..." );
00491 for(pmo = profile_scale; pmo->mitem; pmo++){
00492 XSM_DEBUG (DBG_L3, "checking >" << pmo->mitem << "< neg: " << pmo->neg << " soll: " << (mode&pmo->msk) );
00493 int key;
00494 cout << "Press Key..." << endl; cin >> key;
00495 if(((scaleing & pmo->msk) && !pmo->neg) || (!(scaleing & pmo->msk) && pmo->neg)){
00496 XSM_DEBUG (DBG_L3, "searching for >" << pmo->mitem << "<" );
00497 menushell = gnome_app_find_menu_pos (popup, pmo->mitem, &pos);
00498 if(menushell){
00499 menuitem = (GtkWidget*)g_list_nth_data(GTK_MENU_SHELL (menushell) -> children, --pos);
00500 if(menuitem)
00501 gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
00502 XSM_DEBUG (DBG_L3, "found and selected." );
00503 }
00504 }
00505 }
00506
00507 XSM_DEBUG (DBG_L3, "Check Menu Button Setup complete." );
00508 #endif
00509
00510
00511 XSM_DEBUG (DBG_L2, "ProfileControl::ProfileControl hbox");
00512
00513 hbox = gtk_hbox_new(FALSE, 0);
00514 gtk_widget_show(hbox);
00515 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534 statusbar = gtk_statusbar_new ();
00535 statusid = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "drag");
00536 gtk_object_set_data (GTK_OBJECT (widget), "statusbar", statusbar);
00537
00538 gtk_widget_show (statusbar);
00539 gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, TRUE, 0);
00540
00541 XSM_DEBUG (DBG_L2, "ProfileControl::ProfileControl canvas");
00542
00543 canvas = gnome_canvas_new();
00544
00545 gtk_widget_pop_visual();
00546 gtk_widget_pop_colormap();
00547
00548 gtk_object_set_data (GTK_OBJECT (canvas), "statusbar", statusbar);
00549
00550 gtk_widget_pop_visual();
00551 gtk_widget_pop_colormap();
00552
00553 SetSize();
00554
00555 gtk_container_add(GTK_CONTAINER(scrollarea), canvas);
00556
00557 gtk_widget_set_events( canvas, GDK_POINTER_MOTION_MASK |
00558 GDK_POINTER_MOTION_HINT_MASK );
00559
00560 XSM_DEBUG (DBG_L2, "ProfileControl::ProfileControl draw!");
00561
00562 drawFrame();
00563
00564 XSM_DEBUG (DBG_L2, "ProfileControl::ProfileControl show!");
00565 gtk_widget_show( canvas );
00566
00567 XSM_DEBUG (DBG_L2, "ProfileControl::ProfileControl done.");
00568 }
00569
00570 ProfileControl::~ProfileControl ()
00571 {
00572 XsmRescourceManager xrm(profile_res_id);
00573
00574 XSM_DEBUG (DBG_L2, "ProfileControl::~ProfileControl");
00575
00576
00577 xrm.Put("ModeCode", (int)mode);
00578 xrm.Put("ScalingCode", (int)scaleing);
00579
00580 RemoveScans();
00581
00582 delete[] Xtics;
00583 delete[] Ytics;
00584 delete[] Xlabels;
00585 delete[] Ylabels;
00586
00587 g_free(profile_res_id);
00588 g_free(xticfmt);
00589 g_free(yticfmt);
00590 g_free(xlabel);
00591 g_free(ylabel);
00592 g_free(title);
00593
00594 XSM_DEBUG (DBG_L2, "done.");
00595 }
00596
00597 void ProfileControl::SetSize(){
00598 cxwidth=pasize*aspect;
00599 cywidth=pasize;
00600
00601 gtk_window_set_default_size(GTK_WINDOW(widget), (int)(papixel*aspect), papixel+statusheight);
00602
00603 gnome_canvas_set_pixels_per_unit( GNOME_CANVAS(canvas), (double)papixel/(2*border+pasize));
00604 gnome_canvas_set_scroll_region( GNOME_CANVAS(canvas),
00605 -border, -border/4,
00606 cxwidth+border/4, cywidth+border );
00607 }
00608
00609 gint ProfileControl::cursor_event(GnomeCanvasItem *item, GdkEvent *event, ProfileControl *pc){
00610 static double x, y;
00611 double new_x, new_y;
00612 double item_x, item_y;
00613 static int dragging=FALSE;
00614 GdkCursor *fleur;
00615 item_x = event->button.x;
00616 item_y = event->button.y;
00617 gnome_canvas_item_w2i(item->parent, &item_x, &item_y);
00618 switch (event->type)
00619 {
00620 case GDK_BUTTON_PRESS:
00621 switch(event->button.button)
00622 {
00623 case 1:
00624 x = item_x;
00625 y = item_y;
00626 fleur = gdk_cursor_new(GDK_FLEUR);
00627 gnome_canvas_item_grab(item,
00628 GDK_POINTER_MOTION_MASK |
00629 GDK_BUTTON_RELEASE_MASK,
00630 fleur,
00631 event->button.time);
00632 gdk_cursor_destroy(fleur);
00633 dragging=TRUE;
00634 break;
00635 }
00636 break;
00637
00638 case GDK_MOTION_NOTIFY:
00639 if (dragging && (event->motion.state & GDK_BUTTON1_MASK)){
00640 new_x = item_x;
00641 new_y = item_y;
00642 pc->moveCur(item == pc->Cursor[0][1] ? 0 : 1, 0, 2, new_x);
00643 x = new_x;
00644 y = new_y;
00645 }
00646 break;
00647
00648 case GDK_BUTTON_RELEASE:
00649 switch(event->button.button){
00650 case 1:
00651 gnome_canvas_item_ungrab(item, event->button.time);
00652 dragging=FALSE;
00653 break;
00654 }
00655 break;
00656 default: break;
00657 }
00658 return FALSE;
00659 }
00660
00661 void ProfileControl::AddScan(Scan* scan, int line, gchar *col){
00662 XSM_DEBUG (DBG_L3, "ProfileControl::AddScan");
00663 if(col)
00664 last_pe = new ProfileElement(scan, this, col, line);
00665 else{
00666 gchar *sccl[] = {"red","blue","green",
00667 "SteelBlue","ForestGreen","magenta",
00668 "yellow","orange"
00669 };
00670 last_pe = new ProfileElement(scan, this, sccl[scount&7], line);
00671 }
00672 ScanList = g_slist_prepend( ScanList, last_pe);
00673 ++scount;
00674 XSM_DEBUG (DBG_L3, "ProfileControl::AddScan done.");
00675 }
00676
00677 void ProfileControl::AddLine(int line, gchar *col){
00678 if(last_pe){
00679 if(col)
00680 last_pe = new ProfileElement(last_pe, col, line);
00681 else{
00682 gchar *sccl[] = {"red","blue","green",
00683 "SteelBlue","ForestGreen","magenta",
00684 "yellow","orange"
00685 };
00686 last_pe = new ProfileElement(last_pe, sccl[scount&7], line);
00687 }
00688 ScanList = g_slist_prepend( ScanList, last_pe);
00689 ++scount;
00690 }
00691 }
00692
00693 void ProfileControl::RemoveScans(){
00694 if(ScanList)
00695 g_slist_foreach(ScanList, (GFunc) ProfileControl::kill_elem, this);
00696 g_slist_free(ScanList);
00697 ScanList = NULL;
00698 scount = 0;
00699 }
00700
00701 void ProfileControl::draw_elem(ProfileElement *pe, ProfileControl *pc){
00702 pe->calc(pc->mode);
00703 pc->SetXrange(pe->xlocmin, pe->xlocmax);
00704 if(pc->scaleing&PROFILE_SCALE_YEXPAND || (pc->SklOnly && !(pc->scaleing&PROFILE_SCALE_YHOLD)))
00705 pc->SetYrange(MIN(pe->ylocmin, pc->ymin), MAX(pe->ylocmax, pc->ymax));
00706 else
00707 if(!(pc->scaleing&PROFILE_SCALE_YHOLD))
00708 pc->SetYrange(pe->ylocmin, pe->ylocmax);
00709
00710 if(!pc->SklOnly)
00711 pe->draw(pc->canvas);
00712 }
00713
00714
00715
00716
00717
00718
00719
00720
00721 gint ProfileControl::NewData(Scan* sc, int line, int cpyscan){
00722 gchar *txt;
00723 if(working) return TRUE;
00724 ++working;
00725 XSM_DEBUG (DBG_L2, "ProfileControl::NewData");
00726
00727 if(!sc && new_data_lastl >= 0 && last_pe){
00728 new_data_lastl += line;
00729 line = new_data_lastl < 0 ? 0 : new_data_lastl >= new_data_nl ? new_data_nl-1 : new_data_lastl;
00730 XSM_DEBUG (DBG_L2, "ProfileControl::NewData new line: " << line << " lastl:" << new_data_lastl << " nl:" << new_data_nl );
00731 last_pe->SetY(line);
00732 }
00733
00734 else{
00735 if(sc){
00736 if(cpyscan){
00737 SetData(sc, line);
00738 if(! scount){
00739 XSM_DEBUG (DBG_L2, "ProfileControl::NewData AddScan, scount==0");
00740 AddScan(scan1d);
00741 XSM_DEBUG (DBG_L2, "ProfileControl::NewData AddScan, GetNy");
00742 new_data_nl = scan1d->mem2d->GetNy();
00743 XSM_DEBUG (DBG_L2, "ProfileControl::NewData AddScan, nl=" << new_data_nl);
00744 }
00745 }else{
00746 if(! scount){
00747 XSM_DEBUG (DBG_L2, "ProfileControl::NewData AddScan, scount>0, SetData");
00748 SetData(sc, -2);
00749 XSM_DEBUG (DBG_L2, "ProfileControl::NewData AddScan, sc=" << sc);
00750 AddScan(sc);
00751 new_data_nl = sc->mem2d->GetNy();
00752 XSM_DEBUG (DBG_L2, "ProfileControl::NewData AddScan, nl=" << new_data_nl);
00753 }
00754 last_pe->SetY(line);
00755 }
00756 }
00757 }
00758
00759 new_data_lastl=line;
00760 XSM_DEBUG (DBG_L3, "ProfileControl::NewData lastl=" << new_data_lastl );
00761
00762 txt=g_strdup_printf("Line: %d", line);
00763 XSM_DEBUG (DBG_L3, "ProfileControl::NewData Status=" << txt);
00764 gtk_statusbar_push(GTK_STATUSBAR(statusbar), statusid, txt);
00765 g_free(txt);
00766
00767 Scan *labsrcsc = NULL;
00768 if(cpyscan){
00769 labsrcsc = scan1d;
00770 } else labsrcsc = sc;
00771
00772 if(labsrcsc){
00773 gchar *tmp;
00774 SetXlabel (tmp=labsrcsc->data.Xunit->MakeLongLabel());
00775 g_free (tmp);
00776
00777 SetYlabel (tmp = labsrcsc->data.Zunit->MakeLongLabel());
00778 g_free (tmp);
00779 }
00780
00781 XSM_DEBUG (DBG_L3, "ProfileControl::NewData UpdateArea" );
00782 UpdateArea();
00783 --working;
00784
00785 XSM_DEBUG (DBG_L3, "ProfileControl::NewData done." );
00786
00787 return FALSE;
00788 }
00789
00790 void ProfileControl::drawScans (int flg)
00791 {
00792 SklOnly=TRUE;
00793 g_slist_foreach(ScanList, (GFunc) ProfileControl::draw_elem, this);
00794 SklOnly=FALSE;
00795 g_slist_foreach(ScanList, (GFunc) ProfileControl::draw_elem, this);
00796 }
00797
00798 void ProfileControl::drawFrame ()
00799 {
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813 if(!frame)
00814 frame = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00815 gnome_canvas_rect_get_type(),
00816 "x1",0.0,
00817 "y1",0.0,
00818 "x2",cxwidth,
00819 "y2",cywidth,
00820 "fill_color", "white",
00821 "outline_color", "black",
00822 "width_pixels",2,
00823 NULL);
00824
00825 if(!xaxislabel)
00826 xaxislabel = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00827 gnome_canvas_text_get_type(),
00828 "text","X-axis",
00829 "x", cxwidth/2.,
00830 "y", cywidth+3*border/4.,
00831 "fill_color", "blue",
00832 "font", xsmres.ProfileLabFont,
00833 "anchor", GTK_ANCHOR_CENTER,
00834 NULL);
00835
00836 if(!yaxislabel){
00837 double x,y;
00838 yaxislabel = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00839 gnome_canvas_text_get_type(),
00840 "text","Y",
00841 "x", x=-border,
00842 "y", y=cywidth/2.,
00843 "fill_color", "red",
00844 "font", xsmres.ProfileLabFont,
00845 "anchor", GTK_ANCHOR_CENTER,
00846 NULL);
00847
00848 }
00849
00850 }
00851
00852 #define TIC_TOP 1
00853 #define TIC_BOTTOM 2
00854 #define TIC_LEFT 3
00855 #define TIC_RIGHT 4
00856 #define TIC_GRID_H 5
00857 #define TIC_GRID_V 6
00858 #define TIC_EMPTY 10
00859 #define LAB_EMPTY 11
00860
00861 void ProfileControl::addTic(GnomeCanvasItem **tic, GnomeCanvasItem **lab,
00862 double val, double len, int pos, gchar *fmt, double tval){
00863 double tx=0, ty=0;
00864 GdkLineStyle lstyl;
00865 GtkAnchorType txtanchor = GTK_ANCHOR_CENTER;
00866 gchar *col = NULL;
00867 GnomeCanvasPoints *pn = gnome_canvas_points_new (2);
00868
00869 XSM_DEBUG (DBG_L5, "ProfileElement::addTic");
00870
00871 if(pos < TIC_GRID_H){
00872 col = g_strdup("black");
00873 lstyl=GDK_LINE_SOLID;
00874 }else{
00875 col = g_strdup("grey30");
00876 lstyl=GDK_LINE_ON_OFF_DASH;
00877 }
00878
00879 XSM_DEBUG (DBG_L5, "ProfileElement::addTic - select");
00880
00881 switch(pos){
00882 case TIC_EMPTY: case LAB_EMPTY:
00883 case TIC_TOP: tx=pn->coords[0]=pn->coords[2]=scan2canvasX(val); pn->coords[1]=0.;
00884 ty=-len+(pn->coords[3]=-len);
00885 txtanchor = GTK_ANCHOR_S;
00886 break;
00887 case TIC_BOTTOM: tx=pn->coords[0]=pn->coords[2]=scan2canvasX(val); pn->coords[1]=cywidth;
00888 ty=len+(pn->coords[3]=cywidth+len);
00889 txtanchor = GTK_ANCHOR_N;
00890 break;
00891 case TIC_LEFT: ty=pn->coords[1]=pn->coords[3]=scan2canvasY(val); pn->coords[0]=0.;
00892 tx=-4*len+(pn->coords[2]=-len);
00893 txtanchor = GTK_ANCHOR_E;
00894 break;
00895 case TIC_RIGHT: ty=pn->coords[1]=pn->coords[3]=scan2canvasY(val); pn->coords[0]=cxwidth;
00896 tx=4*len+(pn->coords[2]=cxwidth+len);
00897 txtanchor = GTK_ANCHOR_W;
00898 break;
00899 case TIC_GRID_V:
00900 pn->coords[0]=pn->coords[2]=scan2canvasX(val);
00901 pn->coords[1]=0.; pn->coords[3]=cywidth;
00902 break;
00903 case TIC_GRID_H:
00904 pn->coords[1]=pn->coords[3]=scan2canvasY(val);
00905 pn->coords[0]=0.; pn->coords[2]=cxwidth;
00906 break;
00907 default:
00908 gnome_canvas_points_unref (pn);
00909 return;
00910 }
00911
00912 XSM_DEBUG (DBG_L5, "ProfileElement::addTic - format");
00913
00914 if(fmt){
00915 gchar *txt=g_strdup_printf(fmt, tval);
00916 if(*lab)
00917 gnome_canvas_item_set(*lab,
00918 "text",txt,
00919 "x", tx,
00920 "y", ty,
00921 NULL);
00922 else
00923 *lab = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00924 gnome_canvas_text_get_type(),
00925 "text",txt,
00926 "x", tx,
00927 "y", ty,
00928 "fill_color", "black",
00929 "font", xsmres.ProfileTicFont,
00930 "anchor", txtanchor,
00931 NULL);
00932 g_free(txt);
00933 }
00934
00935 XSM_DEBUG (DBG_L5, "ProfileElement::addTic - item_set ");
00936
00937 if(*tic)
00938 gnome_canvas_item_set (*tic,
00939 "points", pn,
00940 "fill_color", col,
00941 "line_style", lstyl,
00942 NULL);
00943 else
00944 *tic = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)),
00945 gnome_canvas_line_get_type (),
00946 "points", pn,
00947 "fill_color", col,
00948 "width_pixels", 1,
00949 "line_style", lstyl,
00950 NULL);
00951
00952 XSM_DEBUG (DBG_L5, "ProfileElement::addTic cleanup");
00953
00954 gnome_canvas_points_unref (pn);
00955 g_free (col);
00956 }
00957
00958 gint ProfileControl::drawTics ()
00959 {
00960 int i, nTics;
00961 double l10;
00962 double Lab,dLab,MaxLab,LabW,Lab0;
00963 const double TicL1 = 0.01;
00964 const double TicL2 = 0.015;
00965 XSM_DEBUG (DBG_L5, "ProfileElement::drawTics X");
00966
00967
00968 if(tic_x1 != xmin || tic_x2 != xmax || Xtics[0]==NULL){
00969 tic_x1=xmin; tic_x2=xmax;
00970 nTics = Xticn;
00971
00972 Lab0 = xmin;
00973 MaxLab = Lab0+xrange;
00974 ixt=ixl=0;
00975 #define TICLABSEP 1
00976 if(Lab0 < MaxLab){
00977 LabW = MaxLab-Lab0;
00978 dLab = AutoSkl(LabW/(double)nTics);
00979 l10 = pow(10.,floor(log10(MaxLab)));
00980 if(l10 < 1000. && l10 > 0.01) l10=1.;
00981 if(dLab <= 0.) return(-1);
00982 for(i=0, Lab=AutoNext(Lab0,dLab); Lab<MaxLab; Lab+=dLab, ++i){
00983 if (ixt >= PC_XTN-2) break;
00984 if (ixl >= PC_XLN-2) break;
00985 if(i%TICLABSEP){
00986 addTic(&Xtics[ixt++], &Xlabels[ixl], Lab, TicL1, TIC_BOTTOM);
00987 }
00988 else{
00989 addTic(&Xtics[ixt++], &Xlabels[ixl++], Lab, TicL2, TIC_BOTTOM, xticfmt, Lab);
00990 if(mode & PROFILE_MODE_XGRID)
00991 addTic(&Xtics[ixt++], &Xlabels[ixl], Lab, TicL2, TIC_GRID_V);
00992 }
00993 }
00994 }
00995 else{
00996 LabW = Lab0-MaxLab;
00997 dLab = AutoSkl(LabW/(double)nTics);
00998 l10 = pow(10.,floor(log10(MaxLab)));
00999 if(l10 < 1000. && l10 > 0.01) l10=1.;
01000 if(dLab <= 0.) return(-1);
01001 for(i=0, Lab=AutoNext(MaxLab,dLab); Lab<Lab0; Lab+=dLab, ++i){
01002 if (ixt >= PC_XTN-2) break;
01003 if (ixl >= PC_XLN-2) break;
01004 if(i%TICLABSEP){
01005 addTic(&Xtics[ixt++], &Xlabels[ixl], Lab, TicL1, TIC_BOTTOM);
01006 }
01007 else{
01008 addTic(&Xtics[ixt++], &Xlabels[ixl++], Lab, TicL2, TIC_BOTTOM, xticfmt, Lab);
01009 if(mode & PROFILE_MODE_XGRID)
01010 addTic(&Xtics[ixt++], &Xlabels[ixl], Lab, TicL2, TIC_GRID_V);
01011 }
01012 }
01013 }
01014 while(Xtics[ixt]){
01015 gtk_object_destroy(GTK_OBJECT(Xtics[ixt]));
01016 Xtics[ixt++]=NULL;
01017 }
01018 while(Xlabels[ixl]){
01019 gtk_object_destroy(GTK_OBJECT(Xlabels[ixl]));
01020 Xlabels[ixl++]=NULL;
01021 }
01022 }
01023
01024 XSM_DEBUG (DBG_L5, "ProfileElement::drawTics Y");
01025 if (tic_y1 != ymin || tic_y2 != ymax || tic_ym != mode || Ytics[0]==NULL){
01026 tic_y1=ymin; tic_y2=ymax; tic_ym=mode;
01027 nTics = Yticn;
01028 Lab0 = ymin;
01029 MaxLab = Lab0+yrange;
01030 iyt=iyl=0;
01031
01032 if(mode & PROFILE_MODE_YLOG){
01033 XSM_DEBUG (DBG_L5, "ProfileElement::drawTics Y-log");
01034 if (Lab0 <= 0.){
01035 XSM_DEBUG_WARNING (DBG_L2, "ProfileElement::drawTics Y-log mode: negative Ymin!");
01036 Lab0 = MaxLab/LOG_RESCUE_RATIO;
01037 }
01038 if (Lab0 > 0.){
01039 l10 = pow (10.,floor (log10 (Lab0)));
01040 for (i=1, Lab=l10; Lab<MaxLab; Lab+=l10, ++i){
01041 if (iyt >= PC_YTN-2) break;
01042 if (iyl >= PC_YLN-2) break;
01043 if (Lab < Lab0) continue;
01044 if (Lab > 9.999*l10){ l10=Lab=10.*l10; i=1; }
01045 if (i!=5 && i!=1){
01046 addTic (&Ytics[iyt++], &Ylabels[iyl], Lab, TicL1, TIC_LEFT);
01047 }
01048 else{
01049 addTic (&Ytics[iyt++], &Ylabels[iyl++], Lab, TicL1, TIC_LEFT, yticfmt, Lab);
01050 if (mode & PROFILE_MODE_YGRID)
01051 addTic(&Ytics[iyt++], &Ylabels[iyl], Lab, TicL2, TIC_GRID_H);
01052 }
01053 }
01054 }
01055 }else{
01056 if(Lab0 < MaxLab){
01057 LabW = MaxLab-Lab0;
01058 dLab = AutoSkl(LabW/(double)nTics);
01059 l10 = pow(10.,floor(log10(MaxLab)));
01060 if(l10 < 1000. && l10 > 0.01) l10=1.;
01061 if(dLab <= 0.) return(-1);
01062 for(i=0, Lab=AutoNext(Lab0,dLab); Lab<MaxLab; Lab+=dLab, ++i){
01063 if (iyt >= PC_YTN-2) break;
01064 if (iyl >= PC_YLN-2) break;
01065 if(i%TICLABSEP){
01066 addTic(&Ytics[iyt++], &Ylabels[iyl], Lab, TicL1, TIC_LEFT);
01067 }
01068 else{
01069 addTic(&Ytics[iyt++], &Ylabels[iyl++], Lab, TicL1, TIC_LEFT, yticfmt, Lab);
01070 if(mode & PROFILE_MODE_YGRID)
01071 addTic(&Ytics[iyt++], &Ylabels[iyl], Lab, TicL2, TIC_GRID_H);
01072 }
01073 }
01074 }
01075 else{
01076 LabW = Lab0-MaxLab;
01077 dLab = AutoSkl(LabW/(double)nTics);
01078 l10 = pow(10.,floor(log10(MaxLab)));
01079 if(l10 < 1000. && l10 > 0.01) l10=1.;
01080 if(dLab <= 0.) return(-1);
01081 for(i=0, Lab=AutoNext(MaxLab,dLab); Lab<Lab0; Lab+=dLab, ++i){
01082 if (iyt >= PC_YTN-2) break;
01083 if (iyl >= PC_YLN-2) break;
01084 if(i%TICLABSEP){
01085 addTic(&Ytics[iyt++], &Ylabels[iyl], Lab, TicL1, TIC_LEFT);
01086 }
01087 else{
01088 addTic(&Ytics[iyt++], &Ylabels[iyl++], Lab, TicL1, TIC_LEFT, yticfmt, Lab);
01089 if(mode & PROFILE_MODE_YGRID)
01090 addTic(&Ytics[iyt++], &Ylabels[iyl], Lab, TicL2, TIC_GRID_H);
01091 }
01092 }
01093 }
01094 }
01095
01096 XSM_DEBUG (DBG_L5, "ProfileElement::drawTics - garbage collecting");
01097
01098 while(Ytics[iyt]){
01099 gtk_object_destroy(GTK_OBJECT(Ytics[iyt]));
01100 Ytics[iyt++]=NULL;
01101 }
01102 while(Ylabels[iyl]){
01103 gtk_object_destroy(GTK_OBJECT(Ylabels[iyl]));
01104 Ylabels[iyl++]=NULL;
01105 }
01106 }
01107
01108 XSM_DEBUG (DBG_L5, "ProfileElement::drawTics - done");
01109
01110 return 0;
01111 }
01112
01113 void ProfileControl::UpdateArea ()
01114 {
01115 XSM_DEBUG (DBG_L4, "ProfileControl::UpdateArea drw scans" );
01116 drawScans();
01117 XSM_DEBUG (DBG_L4, "ProfileControl::UpdateArea ticks?" );
01118 if(mode & PROFILE_MODE_NOTICS){
01119 int i=0;
01120 while(Xtics[i]){
01121 gtk_object_destroy(GTK_OBJECT(Xtics[i]));
01122 Xtics[i++]=NULL;
01123 }
01124 i=0;
01125 while(Xlabels[i]){
01126 gtk_object_destroy(GTK_OBJECT(Xlabels[i]));
01127 Xlabels[i++]=NULL;
01128 }
01129 i=0;
01130 while(Ytics[i]){
01131 gtk_object_destroy(GTK_OBJECT(Ytics[i]));
01132 Ytics[i++]=NULL;
01133 }
01134 i=0;
01135 while(Ylabels[i]){
01136 gtk_object_destroy(GTK_OBJECT(Ylabels[i]));
01137 Ylabels[i++]=NULL;
01138 }
01139 }
01140 else{
01141 XSM_DEBUG (DBG_L4, "ProfileControl::UpdateArea drawing ticks!" );
01142 drawTics();
01143 moveCur(0, 0);
01144 moveCur(1, 0);
01145 }
01146 }
01147
01148 void ProfileControl::showCur(int id, int show){
01149 if(show){
01150 if(Cursor[id][0]){
01151 gnome_canvas_item_show( Cursor[id][0] );
01152 gnome_canvas_item_show( Cursor[id][1] );
01153 }else{
01154 static char *c[]={"blue","green"};
01155
01156 GnomeCanvasPoints *pnh = gnome_canvas_points_new (2);
01157 pnh->coords[0]=pnh->coords[1]=pnh->coords[3]=0.; pnh->coords[2]=cxwidth;
01158
01159 GnomeCanvasPoints *pnv = gnome_canvas_points_new (2);
01160 pnv->coords[0]=pnv->coords[1]=pnv->coords[2]=0.; pnv->coords[3]=cywidth;
01161
01162 last_pe->GetCurXYc(&pnv->coords[0], &pnh->coords[1], CursorsIdx[id]);
01163 pnv->coords[2]=pnv->coords[0]; pnh->coords[3]=pnh->coords[1];
01164
01165 Cursor[id][0] = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
01166 gnome_canvas_line_get_type(),
01167 "points", pnh,
01168 "fill_color", c[id],
01169 "width_pixels", 2,
01170 NULL);
01171 Cursor[id][1] = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
01172 gnome_canvas_line_get_type(),
01173 "points", pnv,
01174 "fill_color", c[id],
01175 "width_pixels", 2,
01176 NULL);
01177 gtk_signal_connect(GTK_OBJECT(Cursor[id][1]), "event",
01178 (GtkSignalFunc) ProfileControl::cursor_event,
01179 this);
01180
01181 gnome_canvas_points_unref(pnv);
01182 gnome_canvas_points_unref(pnh);
01183 }
01184 }else
01185 if(Cursor[id][0]){
01186 gtk_object_destroy(GTK_OBJECT(Cursor[id][0]));
01187 gtk_object_destroy(GTK_OBJECT(Cursor[id][1]));
01188 Cursor[id][0] = NULL;
01189 Cursor[id][1] = NULL;
01190 }
01191 }
01192
01193 void ProfileControl::moveCur(int id, int dir, int search, double cx){
01194 GnomeCanvasPoints *pnh = gnome_canvas_points_new (2);
01195 pnh->coords[0]=pnh->coords[1]=pnh->coords[3]=0.; pnh->coords[2]=cxwidth;
01196
01197 GnomeCanvasPoints *pnv = gnome_canvas_points_new (2);
01198 pnv->coords[0]=pnv->coords[1]=pnv->coords[2]=0.; pnv->coords[3]=cywidth;
01199
01200 last_pe->GetCurXYc(&pnv->coords[0], &pnh->coords[1], CursorsIdx[id]);
01201 pnv->coords[2]=pnv->coords[0]; pnh->coords[3]=pnh->coords[1];
01202
01203 if(search == 2){
01204 pnv->coords[0]=cx;
01205 CursorsIdx[id] = last_pe->GetCurX(&pnv->coords[0], &pnh->coords[1]);
01206 pnv->coords[2]=pnv->coords[0]; pnh->coords[3]=pnh->coords[1];
01207 }else{
01208 if(search){
01209 if(search>0) CursorsIdx[id] = last_pe->nextMax(CursorsIdx[id], dir);
01210 if(search<0) CursorsIdx[id] = last_pe->nextMin(CursorsIdx[id], dir);
01211 last_pe->GetCurXYc(&pnv->coords[0], &pnh->coords[1], CursorsIdx[id]);
01212 pnv->coords[2]=pnv->coords[0]; pnh[3]=pnh[1];
01213 }else{
01214 last_pe->GetCurXYc(&pnv->coords[0], &pnh->coords[1], CursorsIdx[id]+=dir);
01215 pnv->coords[2]=pnv->coords[0]; pnh->coords[3]=pnh->coords[1];
01216 }
01217 }
01218
01219 if (Cursor[id][0]){
01220 gnome_canvas_item_set (Cursor[id][0],
01221 "points", pnh,
01222 NULL);
01223 gnome_canvas_item_set (Cursor[id][1],
01224 "points", pnv,
01225 NULL);
01226 gchar *p;
01227 if (Cursor[0][0] && Cursor[1][0] )
01228 gtk_statusbar_push (GTK_STATUSBAR(statusbar), statusid,
01229 p=last_pe->GetDeltaInfo( CursorsIdx[0], CursorsIdx[1] ));
01230 else
01231 gtk_statusbar_push (GTK_STATUSBAR(statusbar), statusid,
01232 p=last_pe->GetInfo( CursorsIdx[id] ));
01233 g_free (p);
01234 }
01235
01236 gnome_canvas_points_unref (pnv);
01237 gnome_canvas_points_unref (pnh);
01238 }
01239
01240 void ProfileControl::nextLine(int n){
01241 NewData (NULL, n);
01242 }
01243
01244 void ProfileControl::SetYrange (double y1, double y2)
01245 {
01246 if (y1 < y2){
01247 ymin = y1; ymax = y2; yrange=y2-y1;
01248 }else{
01249 ymin = y2; ymax = y1; yrange=y1-y2;
01250 }
01251 if (ymax > 0. && ymin > 0. && ymin < ymax){
01252 lmin = log (ymin);
01253 lmaxmin = log (ymax) - lmin;
01254 }else{
01255 if (ymax > 0.) {
01256 lmin = log (ymax/LOG_RESCUE_RATIO);
01257 lmaxmin = log (ymax) - lmin;
01258 } else {
01259 lmaxmin = 1.;
01260 lmin = 0.;
01261 }
01262 }
01263 }
01264
01265 void ProfileControl::SetXrange(double x1, double x2)
01266 {
01267 if (x1 < x2){
01268 xmin = x1; xmax = x2; xrange=x2-x1;
01269 }else{
01270 xmin = x2; xmax = x1; xrange=x1-x2;
01271 }
01272 }
01273
01274 void ProfileControl::SetXlabel (gchar *xlab)
01275 {
01276 if (xlab){
01277 if (xlabel0)
01278 g_free (xlabel0);
01279 xlabel0 = g_strdup (xlab);
01280 }
01281
01282 if (xlabel)
01283 g_free (xlabel);
01284
01285 if(mode & PROFILE_MODE_YPSD)
01286 xlabel = g_strconcat ("Inverse::", xlabel0, NULL);
01287 else
01288 xlabel = g_strdup (xlabel0);
01289
01290 if (xaxislabel)
01291 gnome_canvas_item_set(xaxislabel,"text", xlabel, NULL);
01292 }
01293
01294 void ProfileControl::SetYlabel (gchar *ylab)
01295 {
01296 if (ylab){
01297 if (ylabel)
01298 g_free (ylabel);
01299 ylabel = g_strdup (ylab);
01300 }
01301
01302 if (yaxislabel)
01303 gnome_canvas_item_set(yaxislabel,"text", ylabel, NULL);
01304 }
01305
01306 void ProfileControl::SetActive(int flg){
01307 if (flg){
01308 gnome_canvas_item_set (frame,
01309 "fill_color", "white",
01310 NULL);
01311 gtk_statusbar_push (GTK_STATUSBAR(statusbar), statusid,
01312 "channel is active now");
01313 }else{
01314 gnome_canvas_item_set (frame,
01315 "fill_color", "grey80",
01316 NULL);
01317 gtk_statusbar_push(GTK_STATUSBAR(statusbar), statusid,
01318 "inactive");
01319 }
01320 }
01321
01322 void ProfileControl::SetTitle(gchar *tit){
01323 gtk_window_set_title (GTK_WINDOW (widget), tit);
01324 }
01325
01326 void ProfileControl::file_open_callback (GtkWidget *widget, ProfileControl *pc)
01327 {
01328 gchar *ffname;
01329 ffname = gapp->file_dialog ("Profile to load", NULL,
01330 "*.asc", NULL, "profileload");
01331 if (ffname)
01332 gapp->xsm->load (ffname);
01333 }
01334
01335 void ProfileControl::file_save_callback (GtkWidget *widget, ProfileControl *pc)
01336 {
01337 gchar *ffname;
01338 gchar *mld, *oname;
01339
01340 oname = g_strconcat (pc->scan1d->data.ui.originalname, ".asc", NULL);
01341 ffname = gapp->file_dialog (N_("Profile to save"), NULL,
01342 "*.asc", oname, "profilesave");
01343 if (gapp->check_file (ffname)){
01344 pc->save (ffname);
01345 mld = g_strconcat (N_("profile saved as "), ffname, NULL);
01346 }else
01347 mld = g_strdup (N_("save canceld"));
01348 gtk_statusbar_push (GTK_STATUSBAR(pc->statusbar), pc->statusid, mld);
01349 g_free (mld);
01350 }
01351
01352 void ProfileControl::file_save_as_callback (GtkWidget *widget, ProfileControl *pc)
01353 {
01354 gchar *ffname;
01355 gchar *mld, *oname;
01356
01357 oname = g_strconcat (pc->scan1d->data.ui.originalname, ".asc", NULL);
01358 ffname = gapp->file_dialog (N_("Profile to save"), NULL,
01359 "*.asc", oname, "profilesaveas");
01360 if (gapp->check_file (ffname)){
01361 pc->save (ffname);
01362 mld = g_strconcat (N_("profile saved as "),ffname,NULL);
01363 }else
01364 mld = g_strdup (N_("save canceld"));
01365 gtk_statusbar_push (GTK_STATUSBAR(pc->statusbar), pc->statusid, mld);
01366 g_free (mld);
01367 }
01368
01369 void ProfileControl::file_close_callback (GtkWidget *widget, ProfileControl *pc){
01370 XSM_DEBUG (DBG_L2, "ProfileElement::file_close_callback, refcount=" << pc->ref_count);
01371
01372 if (pc->ref_count == 0)
01373 gapp->xsm->RemoveProfile (pc);
01374 else
01375 XSM_DEBUG_ERROR (DBG_L1, "Sorry, cant't do this, other object depends on me!" );
01376 }
01377
01378 void ProfileControl::file_print1_callback (GtkWidget *widget, ProfileControl *pc){
01379 pc->file_print_callback (widget, pc, 1);
01380 }
01381
01382 void ProfileControl::file_print2_callback (GtkWidget *widget, ProfileControl *pc){
01383 pc->file_print_callback (widget, pc, 2);
01384 }
01385
01386 void ProfileControl::file_print3_callback (GtkWidget *widget, ProfileControl *pc){
01387 pc->file_print_callback (widget, pc, 3);
01388 }
01389
01390 void ProfileControl::file_print4_callback (GtkWidget *widget, ProfileControl *pc){
01391 pc->file_print_callback (widget, pc, 4);
01392 }
01393
01394
01395 void ProfileControl::file_print5_callback (GtkWidget *widget, ProfileControl *pc){
01396 pc->file_print_callback (widget, pc, 5);
01397 }
01398
01399
01400 void ProfileControl::file_print6_callback (GtkWidget *widget, ProfileControl *pc){
01401 pc->file_print_callback (widget, pc, 6);
01402 }
01403
01404 void ProfileControl::file_print_callback (GtkWidget *widget, ProfileControl *pc, int index)
01405 {
01406 int tmpf;
01407 gchar *tmp;
01408 GError *printer_failure;
01409
01410 --index;
01411 if ((tmpf=g_file_open_tmp("GXSM_TEMPFILE_XXXXXX", &tmp, &printer_failure)) != -1){
01412 FILE *gricmd;
01413 char command[512];
01414 char retinfo[64];
01415 int ret;
01416
01417 close (tmpf);
01418 pc->save(tmp);
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429 if((index >= 0) && (index < GRIMAX)){
01430 sprintf(command, "%s %s \"%s\"\n",xsmres.gricmd1d[index], tmp, xsmres.griplottitle);
01431
01432
01433
01434 }else {
01435 ;
01436 }
01437 gricmd=popen(command,"r");
01438 ret=pclose(gricmd);
01439 if(ret){
01440 sprintf(retinfo, "%s", ret ? "Execution Error" : "OK");
01441 XSM_SHOW_ALERT("PRINT INFO", command, retinfo,1);
01442 }
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454 sprintf(command, "rm %s\n", tmp);
01455 gricmd=popen(command,"r");
01456 pclose(gricmd);
01457 }
01458 g_free (tmp);
01459 }
01460
01461 void ProfileControl::file_activate_callback (GtkWidget *widget, ProfileControl *pc){
01462 if (pc->chno >= 0)
01463 gapp->xsm->ActivateChannel (pc->chno);
01464 }
01465
01466 void ProfileControl::logy_callback (GtkWidget *widget, ProfileControl *pc)
01467 {
01468 if (GTK_CHECK_MENU_ITEM (widget)->active)
01469 pc->mode = (pc->mode & ~PROFILE_MODE_YLOG) | PROFILE_MODE_YLOG;
01470 else
01471 pc->mode &= ~PROFILE_MODE_YLOG;
01472 pc->UpdateArea ();
01473 }
01474
01475 void ProfileControl::linreg_callback (GtkWidget *widget, ProfileControl *pc)
01476 {
01477 if (GTK_CHECK_MENU_ITEM (widget)->active)
01478 pc->mode = (pc->mode & ~PROFILE_MODE_YLINREG) | PROFILE_MODE_YLINREG;
01479 else
01480 pc->mode &= ~PROFILE_MODE_YLINREG;
01481 pc->UpdateArea ();
01482 }
01483
01484 void ProfileControl::psd_callback (GtkWidget *widget, ProfileControl *pc)
01485 {
01486 if (GTK_CHECK_MENU_ITEM (widget)->active)
01487 pc->mode = (pc->mode & ~PROFILE_MODE_YPSD) | PROFILE_MODE_YPSD;
01488 else
01489 pc->mode &= ~PROFILE_MODE_YPSD;
01490
01491 pc->SetXlabel ();
01492 pc->UpdateArea ();
01493 }
01494
01495 void ProfileControl::yhold_callback (GtkWidget *widget, ProfileControl *pc)
01496 {
01497 if (GTK_CHECK_MENU_ITEM (widget)->active)
01498 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01499 else
01500 pc->scaleing &= ~PROFILE_SCALE_YHOLD;
01501 pc->UpdateArea ();
01502 }
01503
01504 void ProfileControl::yexpand_callback (GtkWidget *widget, ProfileControl *pc)
01505 {
01506 if (GTK_CHECK_MENU_ITEM (widget)->active)
01507 pc->scaleing = (pc->scaleing& ~PROFILE_SCALE_YEXPAND) | PROFILE_SCALE_YEXPAND;
01508 else
01509 pc->scaleing &= ~PROFILE_SCALE_YEXPAND;
01510 pc->UpdateArea ();
01511 }
01512
01513 void ProfileControl::skl_Yauto_callback (GtkWidget *widget, ProfileControl *pc)
01514 {
01515 pc->scaleing &= ~PROFILE_SCALE_YHOLD;
01516 pc->UpdateArea ();
01517 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01518 pc->UpdateArea ();
01519 }
01520
01521 void ProfileControl::skl_Yupperup_callback (GtkWidget *widget, ProfileControl *pc)
01522 {
01523 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01524 if(pc->mode & PROFILE_MODE_YLOG)
01525 pc->SetYrange(pc->ymin, pc->ymax*2.);
01526 else{
01527 double yrange = pc->ymax - pc->ymin;
01528 pc->SetYrange(pc->ymin, pc->ymax+0.1*yrange);
01529 }
01530 pc->UpdateArea ();
01531 }
01532
01533 void ProfileControl::skl_Yupperdn_callback (GtkWidget *widget, ProfileControl *pc)
01534 {
01535 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01536 if(pc->mode & PROFILE_MODE_YLOG)
01537 pc->SetYrange(pc->ymin, pc->ymax/2.);
01538 else{
01539 double yrange = pc->ymax - pc->ymin;
01540 pc->SetYrange(pc->ymin, pc->ymax-0.1*yrange);
01541 }
01542 pc->UpdateArea ();
01543 }
01544
01545 void ProfileControl::skl_Ylowerup_callback (GtkWidget *widget, ProfileControl *pc)
01546 {
01547 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01548 if(pc->mode & PROFILE_MODE_YLOG)
01549 pc->SetYrange(pc->ymin*2., pc->ymax);
01550 else{
01551 double yrange = pc->ymax - pc->ymin;
01552 pc->SetYrange(pc->ymin+0.1*yrange, pc->ymax);
01553 }
01554 pc->UpdateArea ();
01555 }
01556
01557 void ProfileControl::skl_Ylowerdn_callback (GtkWidget *widget, ProfileControl *pc)
01558 {
01559 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01560 if(pc->mode & PROFILE_MODE_YLOG)
01561 pc->SetYrange(pc->ymin/2., pc->ymax);
01562 else{
01563 double yrange = pc->ymax - pc->ymin;
01564 pc->SetYrange(pc->ymin-0.1*yrange, pc->ymax);
01565 }
01566 pc->UpdateArea ();
01567 }
01568
01569 void ProfileControl::skl_Yzoomin_callback (GtkWidget *widget, ProfileControl *pc)
01570 {
01571 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01572 double yrange = pc->ymax - pc->ymin;
01573 if (pc->mode & PROFILE_MODE_YLOG){
01574 if (yrange > 50.)
01575 pc->SetYrange (pc->ymin*2., pc->ymax/2.);
01576 }
01577 else
01578 pc->SetYrange (pc->ymin+0.1*yrange, pc->ymax-0.1*yrange);
01579 pc->UpdateArea ();
01580 }
01581
01582 void ProfileControl::skl_Yzoomout_callback (GtkWidget *widget, ProfileControl *pc)
01583 {
01584 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01585 if (pc->mode & PROFILE_MODE_YLOG)
01586 pc->SetYrange (pc->ymin/2., pc->ymax*2.);
01587 else{
01588 double yrange = pc->ymax - pc->ymin;
01589 pc->SetYrange (pc->ymin-0.1*yrange, pc->ymax+0.1*yrange);
01590 }
01591 pc->UpdateArea ();
01592 }
01593
01594 void ProfileControl::skl_Yset_callback (GtkWidget *widget, ProfileControl *pc)
01595 {
01596 pc->scaleing = (pc->scaleing & ~PROFILE_SCALE_YHOLD) | PROFILE_SCALE_YHOLD;
01597 pc->SetYrange (10., 1e6);
01598 pc->UpdateArea ();
01599 }
01600
01601 void ProfileControl::skl_Xauto_callback (GtkWidget *widget, ProfileControl *pc)
01602 {
01603 pc->UpdateArea();
01604 }
01605
01606 void ProfileControl::skl_Xset_callback (GtkWidget *widget, ProfileControl *pc)
01607 {
01608 pc->UpdateArea ();
01609 }
01610
01611 void ProfileControl::tics_callback (GtkWidget *widget, ProfileControl *pc)
01612 {
01613 if (GTK_CHECK_MENU_ITEM (widget)->active)
01614 pc->mode &= ~PROFILE_MODE_NOTICS;
01615 else
01616 pc->mode = (pc->mode & ~PROFILE_MODE_NOTICS) | PROFILE_MODE_NOTICS;
01617 pc->UpdateArea ();
01618 }
01619
01620 void ProfileControl::symbols_callback (GtkWidget *widget, ProfileControl *pc)
01621 {
01622 if (GTK_CHECK_MENU_ITEM (widget)->active)
01623 pc->mode = (pc->mode & ~PROFILE_MODE_SYMBOLS) | PROFILE_MODE_SYMBOLS;
01624 else
01625 pc->mode &= ~PROFILE_MODE_SYMBOLS;
01626 pc->UpdateArea();
01627 }
01628
01629 void ProfileControl::legend_callback (GtkWidget *widget, ProfileControl *pc)
01630 {
01631 if (GTK_CHECK_MENU_ITEM (widget)->active)
01632 pc->mode = (pc->mode & ~PROFILE_MODE_LEGEND) | PROFILE_MODE_LEGEND;
01633 else
01634 pc->mode &= ~PROFILE_MODE_LEGEND;
01635 pc->UpdateArea();
01636 }
01637
01638 void ProfileControl::nogrid_callback (GtkWidget *widget, ProfileControl *pc)
01639 {
01640 if (GTK_CHECK_MENU_ITEM (widget)->active)
01641 pc->mode = (pc->mode & ~(PROFILE_MODE_XGRID | PROFILE_MODE_YGRID))
01642 | (PROFILE_MODE_XGRID | PROFILE_MODE_YGRID);
01643 else
01644 pc->mode &= ~(PROFILE_MODE_XGRID | PROFILE_MODE_YGRID);
01645 pc->UpdateArea();
01646 }
01647
01648 void ProfileControl::cur_Ashow_callback (GtkWidget *widget, ProfileControl *pc)
01649 {
01650 if (GTK_CHECK_MENU_ITEM (widget)->active)
01651 pc->showCur(0,TRUE);
01652 else
01653 pc->showCur(0,FALSE);
01654 }
01655
01656 void ProfileControl::cur_Bshow_callback (GtkWidget *widget, ProfileControl *pc)
01657 {
01658 if (GTK_CHECK_MENU_ITEM (widget)->active)
01659 pc->showCur(1,TRUE);
01660 else
01661 pc->showCur(1,FALSE);
01662 }
01663
01664 void ProfileControl::cur_Aleft_callback (GtkWidget *widget, ProfileControl *pc)
01665 {
01666 pc->moveCur(0,-1);
01667 }
01668
01669 void ProfileControl::cur_Aright_callback (GtkWidget *widget, ProfileControl *pc)
01670 {
01671 pc->moveCur(0,1);
01672 }
01673
01674 void ProfileControl::cur_Bleft_callback (GtkWidget *widget, ProfileControl *pc)
01675 {
01676 pc->moveCur(1,-1);
01677 }
01678
01679 void ProfileControl::cur_Bright_callback (GtkWidget *widget, ProfileControl *pc)
01680 {
01681 pc->moveCur(1,1);
01682 }
01683
01684
01685
01686 void ProfileControl::cur_Almax_callback (GtkWidget *widget, ProfileControl *pc){
01687 pc->moveCur(0,-1,1);
01688 }
01689 void ProfileControl::cur_Almin_callback (GtkWidget *widget, ProfileControl *pc){
01690 pc->moveCur(0,-1,-1);
01691 }
01692 void ProfileControl::cur_Armax_callback (GtkWidget *widget, ProfileControl *pc){
01693 pc->moveCur(0,1,1);
01694 }
01695 void ProfileControl::cur_Armin_callback (GtkWidget *widget, ProfileControl *pc){
01696 pc->moveCur(0,1,-1);
01697 }
01698
01699 void ProfileControl::cur_Blmax_callback (GtkWidget *widget, ProfileControl *pc){
01700 pc->moveCur(1,-1,1);
01701 }
01702 void ProfileControl::cur_Blmin_callback (GtkWidget *widget, ProfileControl *pc){
01703 pc->moveCur(1,-1,-1);
01704 }
01705 void ProfileControl::cur_Brmax_callback (GtkWidget *widget, ProfileControl *pc){
01706 pc->moveCur(1,1,1);
01707 }
01708 void ProfileControl::cur_Brmin_callback (GtkWidget *widget, ProfileControl *pc){
01709 pc->moveCur(1,1,-1);
01710 }
01711
01712
01713 void ProfileControl::sel_next_p1_callback(GtkWidget *widget, ProfileControl *pc){
01714 pc->nextLine(1);
01715 }
01716 void ProfileControl::sel_next_p5_callback(GtkWidget *widget, ProfileControl *pc){
01717 pc->nextLine(5);
01718 }
01719 void ProfileControl::sel_next_p10_callback(GtkWidget *widget, ProfileControl *pc){
01720 pc->nextLine(10);
01721 }
01722 void ProfileControl::sel_next_p50_callback(GtkWidget *widget, ProfileControl *pc){
01723 pc->nextLine(50);
01724 }
01725 void ProfileControl::sel_next_p100_callback(GtkWidget *widget, ProfileControl *pc){
01726 pc->nextLine(100);
01727 }
01728 void ProfileControl::sel_next_p500_callback(GtkWidget *widget, ProfileControl *pc){
01729 pc->nextLine(500);
01730 }
01731 void ProfileControl::sel_next_m500_callback(GtkWidget *widget, ProfileControl *pc){
01732 pc->nextLine(-500);
01733 }
01734 void ProfileControl::sel_next_m100_callback(GtkWidget *widget, ProfileControl *pc){
01735 pc->nextLine(-100);
01736 }
01737 void ProfileControl::sel_next_m50_callback(GtkWidget *widget, ProfileControl *pc){
01738 pc->nextLine(-50);
01739 }
01740 void ProfileControl::sel_next_m10_callback(GtkWidget *widget, ProfileControl *pc){
01741 pc->nextLine(-10);
01742 }
01743 void ProfileControl::sel_next_m5_callback(GtkWidget *widget, ProfileControl *pc){
01744 pc->nextLine(-5);
01745 }
01746
01747 void ProfileControl::sel_next_m1_callback(GtkWidget *widget, ProfileControl *pc){
01748 pc->nextLine(-1);
01749 }
01750
01751 void ProfileControl::sel_all_callback(GtkWidget *widget, ProfileControl *pc){
01752 if(pc->last_pe){
01753 int n=pc->last_pe->GetNy();
01754 pc->last_pe->SetY();
01755 pc->RemoveScans();
01756 for(int i=0; i<n; ++i)
01757 pc->AddLine(i);
01758 pc->UpdateArea();
01759 }
01760 }
01761 void ProfileControl::sel_first_callback(GtkWidget *widget, ProfileControl *pc){
01762 if(pc->last_pe){
01763 pc->last_pe->SetY();
01764 pc->UpdateArea();
01765 }
01766 }
01767 void ProfileControl::sel_last_callback(GtkWidget *widget, ProfileControl *pc){
01768 if(pc->last_pe){
01769 pc->last_pe->SetLastY();
01770 pc->UpdateArea();
01771 }
01772 }