1 /* SpectrumWin.c */
2 /**********************************************************************************************************
3 Copyright (c) 2002-2013 Abdul-Rahman Allouche. All rights reserved
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 documentation files (the Gabedit), to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
10 The above copyright notice and this permission notice shall be included in all copies or substantial portions
11 of the Software.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
14 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
16 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 DEALINGS IN THE SOFTWARE.
18 ************************************************************************************************************/
19
20 #include <math.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <gtk/gtk.h>
24 #include "../Common/Global.h"
25 #include "../Utils/GabeditXYPlot.h"
26 #include "SpectrumWin.h"
27
28 /****************************************************************************************/
get_ymax(XYPlotData * dataCurve)29 static gdouble get_ymax(XYPlotData* dataCurve)
30 {
31 gdouble ymax = 1;
32 gint loop;
33 if(dataCurve->size<1) return 1.0;
34 ymax = dataCurve->y[0];
35 for (loop=1; loop<dataCurve->size; loop++)
36 if(ymax<dataCurve->y[loop]) ymax = dataCurve->y[loop];
37 return ymax;
38 }
39 /****************************************************************************************/
get_ymin(XYPlotData * dataCurve)40 static gdouble get_ymin(XYPlotData* dataCurve)
41 {
42 gdouble ymin = 1;
43 gint loop;
44 if(dataCurve->size<1) return 0.0;
45 ymin = dataCurve->y[0];
46 for (loop=1; loop<dataCurve->size; loop++)
47 if(ymin<dataCurve->y[loop]) ymin = dataCurve->y[loop];
48 return ymin;
49 }
50 /****************************************************************************************/
set_ymax_to_one(XYPlotData * dataCurve,XYPlotData * dataPeaks)51 static void set_ymax_to_one(XYPlotData* dataCurve, XYPlotData* dataPeaks)
52 {
53 gdouble ymax = 0;
54 gint loop;
55 if(dataCurve->size<1) return;
56 ymax = dataCurve->y[0];
57 for (loop=1; loop<dataCurve->size; loop++)
58 if(ymax<dataCurve->y[loop]) ymax = dataCurve->y[loop];
59 if(ymax!=0)
60 for (loop=0; loop<dataCurve->size; loop++)
61 dataCurve->y[loop] /= ymax;
62 if(ymax!=0)
63 for (loop=0; loop<dataPeaks->size; loop++)
64 dataPeaks->y[loop] /= ymax;
65 }
66 /****************************************************************************************/
build_data_xyplot_curve_noconv(XYPlotWinData * winData,XYPlotData * dataCurve)67 static void build_data_xyplot_curve_noconv(XYPlotWinData* winData, XYPlotData* dataCurve)
68 {
69 gint loop;
70 gint line_width = winData->line_width;
71 gint point_size = winData->point_size;
72 GdkColor line_color = winData->line_color;
73 GdkColor point_color = winData->point_color;
74
75 if(dataCurve->x && dataCurve->y)
76 {
77 line_width = dataCurve->line_width;
78 point_size = dataCurve->point_size;
79 line_color = dataCurve->line_color;
80 point_color = dataCurve->point_color;
81 }
82
83 dataCurve->size=winData->size;
84 if(dataCurve->size>0)
85 {
86 if(dataCurve->x) g_free(dataCurve->x);
87 if(dataCurve->y) g_free(dataCurve->y);
88 dataCurve->x = (gdouble*)g_malloc(sizeof(gdouble)*dataCurve->size);
89 dataCurve->y = (gdouble*)g_malloc(sizeof(gdouble)*dataCurve->size);
90 }
91
92 for (loop=0; loop<dataCurve->size; loop++){
93 dataCurve->x[loop]=winData->x[loop]*winData->scaleX+winData->shiftX;
94 dataCurve->y[loop]=winData->y[loop]*winData->scaleY;
95 }
96 sprintf(dataCurve->point_str,"+");
97 dataCurve->point_size=point_size;
98 dataCurve->line_width=line_width;
99 dataCurve->point_color=point_color;
100 dataCurve->line_color=line_color;
101
102 dataCurve->line_style=winData->line_style;
103
104 }
105 /********************************************************************************/
lorentzianLineshape(gdouble rel_offset)106 static gdouble lorentzianLineshape(gdouble rel_offset)
107 {
108 return 1.0 / (1.0 + rel_offset * rel_offset);
109 }
110 /********************************************************************************/
gaussianLineshape(gdouble rel_offset)111 static gdouble gaussianLineshape(gdouble rel_offset)
112 {
113 gdouble nln2 = -log(2.0);
114 return exp(nln2 * rel_offset * rel_offset);
115 }
116 /****************************************************************************************/
build_data_xyplot_curve_withconv(XYPlotWinData * winData,XYPlotData * dataCurve)117 static void build_data_xyplot_curve_withconv(XYPlotWinData* winData, XYPlotData* dataCurve)
118 {
119 gint i;
120 gint j;
121 gdouble (*lineshape)(gdouble);
122 gint line_width = winData->line_width;
123 gint point_size = winData->point_size;
124 GdkColor line_color = winData->line_color;
125 GdkColor point_color = winData->point_color;
126 gint n = 0;
127 gdouble xx = winData->xmin;
128 gdouble h0 = winData->halfWidth/20;
129
130 if(dataCurve->x && dataCurve->y)
131 {
132 line_width = dataCurve->line_width;
133 point_size = dataCurve->point_size;
134 line_color = dataCurve->line_color;
135 point_color = dataCurve->point_color;
136 }
137
138 if(winData->convType==GABEDIT_CONV_TYPE_LORENTZ)
139 lineshape = lorentzianLineshape;
140 else
141 lineshape = gaussianLineshape;
142
143
144
145 if(dataCurve->size>0 && winData->size)
146 {
147 if(dataCurve->x) g_free(dataCurve->x);
148 if(dataCurve->y) g_free(dataCurve->y);
149 dataCurve->x = NULL;
150 dataCurve->y = NULL;
151 }
152
153 dataCurve->size=0;
154 xx = winData->xmin;
155 h0 = winData->halfWidth/10;
156 n = (gint)((winData->xmax-winData->xmin)/h0+0.5)+winData->size;
157 if(n>0) dataCurve->x = (gdouble*)g_malloc(sizeof(gdouble)*n);
158 if(winData->size>0 && n>0)
159 do
160 {
161 gdouble dmin = 0.0;
162 gdouble d = 0.0;
163 gint jmin = 0;
164 for (j=0; j < winData->size; j++)
165 {
166 gdouble center = (gdouble) winData->x[j]*winData->scaleX+winData->shiftX;
167
168 d = fabs(xx - center);
169 if(d<dmin || j==0)
170 {
171 jmin = j;
172 dmin = d;
173 }
174 }
175 dataCurve->x[dataCurve->size] = xx;
176 if(dmin<h0)
177 {
178 if(xx< winData->x[jmin]*winData->scaleX+winData->shiftX)
179 {
180 xx = (gdouble) winData->x[jmin]*winData->scaleX+winData->shiftX;
181 dataCurve->x[dataCurve->size] = xx;
182 xx += h0+1e-8;
183 }
184 else
185 {
186 xx = (gdouble) winData->x[jmin]*winData->scaleX+winData->shiftX;
187 dataCurve->x[dataCurve->size] = xx;
188 xx += h0+1e-8;
189 }
190 }
191 else
192 {
193 if(dmin> 5*winData->halfWidth) xx += h0+dmin/5;
194 else xx += h0;
195 }
196
197 dataCurve->size++;
198 }while(xx<winData->xmax && dataCurve->size<n);
199
200 if(dataCurve->size>0)
201 {
202 dataCurve->x = (gdouble*)g_realloc(dataCurve->x,sizeof(gdouble)*dataCurve->size);
203 dataCurve->y = (gdouble*)g_malloc(sizeof(gdouble)*dataCurve->size);
204 }
205
206 if(winData->size>0)
207 for (i=0; i < dataCurve->size; i++)
208 {
209 gdouble yy = 0.0;
210 for (j=0; j < winData->size; j++)
211 {
212 gdouble center = (gdouble) winData->x[j]*winData->scaleX+winData->shiftX;
213 gdouble rel_offset = (dataCurve->x[i] - center) / winData->halfWidth;
214 yy += winData->y[j]*lineshape(rel_offset)*winData->scaleY;
215 }
216 dataCurve->y[i] = yy;
217 }
218
219 sprintf(dataCurve->point_str,"+");
220 dataCurve->point_size=point_size;
221 dataCurve->line_width=line_width;
222 dataCurve->point_color=point_color;
223
224 dataCurve->line_color=line_color;
225
226 dataCurve->line_style=winData->line_style;
227
228
229 }
230 /****************************************************************************************/
build_data_xyplot_curve(XYPlotWinData * winData,XYPlotData * dataCurve)231 static void build_data_xyplot_curve(XYPlotWinData* winData, XYPlotData* dataCurve)
232 {
233 switch(winData->convType)
234 {
235 case GABEDIT_CONV_TYPE_NONE :
236 build_data_xyplot_curve_noconv(winData, dataCurve);
237 break;
238 case GABEDIT_CONV_TYPE_LORENTZ :
239 case GABEDIT_CONV_TYPE_GAUSS :
240 build_data_xyplot_curve_withconv(winData, dataCurve);
241 }
242
243 }
244 /****************************************************************************************/
build_data_xyplot_peaks(XYPlotWinData * winData,XYPlotData * dataPeaks)245 static void build_data_xyplot_peaks(XYPlotWinData* winData, XYPlotData* dataPeaks)
246 {
247 gint loop;
248 gint line_width = winData->line_width;
249 gint point_size = winData->point_size;
250 GdkColor line_color = winData->line_color;
251 GdkColor point_color = winData->point_color;
252
253 line_color.red *=0.9;
254 line_color.green *=0.9;
255 line_color.blue *=0.9;
256 point_color.red *=0.9;
257 point_color.green *=0.9;
258 point_color.blue *=0.9;
259 if(dataPeaks->x && dataPeaks->y)
260 {
261 line_width = dataPeaks->line_width;
262 point_size = dataPeaks->point_size;
263 line_color = dataPeaks->line_color;
264 point_color = dataPeaks->point_color;
265 }
266
267 dataPeaks->size=3*winData->size+2;
268 if(dataPeaks->size>0)
269 {
270 if(dataPeaks->x) g_free(dataPeaks->x);
271 if(dataPeaks->y) g_free(dataPeaks->y);
272 dataPeaks->x = (gdouble*)g_malloc(sizeof(gdouble)*dataPeaks->size);
273 dataPeaks->y = (gdouble*)g_malloc(sizeof(gdouble)*dataPeaks->size);
274 }
275
276
277 dataPeaks->x[0]=winData->xmin;
278 /* dataPeaks->y[0]=winData->ymin;*/
279 dataPeaks->y[0]=0;
280 dataPeaks->x[dataPeaks->size-1]=winData->xmax;
281 /* dataPeaks->y[dataPeaks->size-1]=winData->ymin;*/
282 dataPeaks->y[dataPeaks->size-1]=0;
283 for (loop=0; loop<winData->size; loop++){
284 gint iold = loop*3+1;
285 gdouble xx = winData->x[loop]*winData->scaleX+winData->shiftX;
286 dataPeaks->x[iold]=xx;
287 /* dataPeaks->y[iold]=winData->ymin;*/
288 dataPeaks->y[iold]=0;
289
290 dataPeaks->x[iold+1]=xx;
291 dataPeaks->y[iold+1]=winData->y[loop]*winData->scaleY;
292
293 dataPeaks->x[iold+2]=xx;
294 /* dataPeaks->y[iold+2]=winData->ymin;*/
295 dataPeaks->y[iold+2]=0;
296 }
297
298 sprintf(dataPeaks->point_str,"+");
299 dataPeaks->point_size=point_size;
300 dataPeaks->line_width=line_width;
301 dataPeaks->point_color=point_color;
302
303 dataPeaks->line_color=line_color;
304
305 dataPeaks->line_style=winData->line_style;
306 }
307 /****************************************************************************************/
build_data_xyplot(XYPlotWinData * winData)308 static void build_data_xyplot(XYPlotWinData* winData)
309 {
310 XYPlotData* dataPeaks = NULL;
311 XYPlotData* dataCurve = NULL;
312 if(!winData->showDataPeaks && !winData->showDataCurve) return;
313 if(!winData->dataPeaks)
314 {
315 winData->dataPeaks = (XYPlotData*)g_malloc(sizeof(XYPlotData));
316 winData->dataPeaks->size = 0;
317 winData->dataPeaks->x = NULL;
318 winData->dataPeaks->y = NULL;
319 }
320 if(!winData->dataCurve)
321 {
322 winData->dataCurve = (XYPlotData*)g_malloc(sizeof(XYPlotData));
323 winData->dataCurve->size = 0;
324 winData->dataCurve->x = NULL;
325 winData->dataCurve->y = NULL;
326 }
327
328 dataPeaks = winData->dataPeaks;
329 dataCurve = winData->dataCurve;
330
331 build_data_xyplot_curve(winData, dataCurve);
332 build_data_xyplot_peaks(winData, dataPeaks);
333 if(winData->ymaxToOne)
334 set_ymax_to_one(dataCurve, dataPeaks);
335 }
336 /****************************************************************************************/
get_win_data(GabeditXYPlot * xyplot,gint size,gdouble * x,gdouble * y)337 static XYPlotWinData* get_win_data(GabeditXYPlot *xyplot, gint size, gdouble* x, gdouble* y)
338 {
339 XYPlotWinData* winData = (XYPlotWinData*)g_malloc(sizeof(XYPlotWinData));
340 gint loop;
341 winData->showDataPeaks = FALSE;
342 winData->showDataCurve = TRUE;
343 winData->dataPeaks = NULL;
344 winData->dataCurve = NULL;
345
346
347 winData->size=size;
348 winData->x = NULL;
349 winData->y = NULL;
350 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &(winData->xmin), &(winData->xmax), &(winData->ymin), &(winData->ymax));
351 if(size>0)
352 {
353 winData->x = (gdouble*) g_malloc(sizeof(gdouble)*size);
354 winData->y = (gdouble*) g_malloc(sizeof(gdouble)*size);
355 for(loop=0;loop<size;loop++)
356 {
357 winData->x[loop] = x[loop];
358 winData->y[loop] = y[loop];
359 }
360 }
361 winData->point_size=0;
362 winData->line_width=1;
363
364 winData->point_color.red=0;
365 winData->point_color.green=0;
366 winData->point_color.blue=0;
367
368 winData->line_color.red=65000;
369 winData->line_color.green=0;
370 winData->line_color.blue=0;
371
372 winData->line_style=GDK_LINE_SOLID;
373
374 winData->halfWidth = fabs(winData->xmax-winData->xmin)/30;
375 winData->convType = GABEDIT_CONV_TYPE_LORENTZ;
376 winData->scaleX = 1;
377 winData->scaleY = 1;
378 winData->shiftX = 0;
379 winData->ymaxToOne = FALSE;
380
381
382 build_data_xyplot(winData);
383
384 return winData;
385
386 }
387 /****************************************************************************************/
gabedit_xyplot_add_windata(GabeditXYPlot * xyplot,XYPlotWinData * data)388 static void gabedit_xyplot_add_windata(GabeditXYPlot *xyplot, XYPlotWinData* data)
389 {
390 GList* data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
391 if (!data_list || g_list_find (data_list, (gpointer)data)==NULL)
392 {
393 data_list=g_list_append(data_list, (gpointer) data);
394 g_object_set_data(G_OBJECT (xyplot), "DataList", data_list);
395 }
396 }
397 /****************************************************************************************/
gabedit_xyplot_show_curve_peaks(GabeditXYPlot * xyplot)398 static void gabedit_xyplot_show_curve_peaks(GabeditXYPlot *xyplot)
399 {
400 GList* data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
401 GList* current = NULL;
402 XYPlotWinData* data;
403 if(!data_list) return;
404 current=g_list_first(data_list);
405 for(; current != NULL; current = current->next)
406 {
407 data = (XYPlotWinData*)current->data;
408 if(data->showDataPeaks) gabedit_xyplot_add_data(xyplot, data->dataPeaks);
409 if(data->showDataCurve) gabedit_xyplot_add_data(xyplot, data->dataCurve);
410 }
411 }
412 /****************************************************************************************/
gabedit_xyplot_refresh_dat(GabeditXYPlot * xyplot)413 static void gabedit_xyplot_refresh_dat(GabeditXYPlot *xyplot)
414 {
415 GList* data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
416 GList* current = NULL;
417 XYPlotWinData* data = NULL;
418 if(!data_list) return;
419 current=g_list_first(data_list);
420 for(; current != NULL; current = current->next)
421 {
422 data = (XYPlotWinData*)current->data;
423 if(data->convType!=GABEDIT_CONV_TYPE_NONE)
424 {
425 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &(data->xmin), &(data->xmax), &(data->ymin), &(data->ymax));
426 build_data_xyplot(data);
427 }
428 }
429 }
430 /****************************************************************************************/
toggle_no_convolution_toggled(GtkToggleButton * togglebutton,gpointer user_data)431 static void toggle_no_convolution_toggled(GtkToggleButton *togglebutton, gpointer user_data)
432 {
433 GtkWidget* xyplot = NULL;
434 GList* data_list = NULL;
435 GList* current = NULL;
436 XYPlotWinData* data;
437
438
439 if(!user_data || !G_IS_OBJECT(user_data)) return;
440 if(!gtk_toggle_button_get_active(togglebutton)) return;
441
442 xyplot = GTK_WIDGET(user_data);
443 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
444
445 if(!data_list) return;
446 current=g_list_first(data_list);
447 for(; current != NULL; current = current->next)
448 {
449 data = (XYPlotWinData*)current->data;
450 if(data->convType!=GABEDIT_CONV_TYPE_NONE)
451 {
452 data->convType=GABEDIT_CONV_TYPE_NONE;
453 build_data_xyplot(data);
454 }
455 }
456 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
457 }
458 /********************************************************************************/
toggle_lorentzian_toggled(GtkToggleButton * togglebutton,gpointer user_data)459 static void toggle_lorentzian_toggled(GtkToggleButton *togglebutton, gpointer user_data)
460 {
461 GtkWidget* xyplot = NULL;
462 GList* data_list = NULL;
463 GList* current = NULL;
464 XYPlotWinData* data;
465
466
467 if(!user_data || !G_IS_OBJECT(user_data)) return;
468 if(!gtk_toggle_button_get_active(togglebutton)) return;
469
470 xyplot = GTK_WIDGET(user_data);
471 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
472
473 if(!data_list) return;
474 current=g_list_first(data_list);
475 for(; current != NULL; current = current->next)
476 {
477 data = (XYPlotWinData*)current->data;
478 if(data->convType!=GABEDIT_CONV_TYPE_LORENTZ)
479 {
480 data->convType=GABEDIT_CONV_TYPE_LORENTZ;
481 build_data_xyplot(data);
482 }
483 }
484 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
485 }
486 /********************************************************************************/
toggle_gaussian_toggled(GtkToggleButton * togglebutton,gpointer user_data)487 static void toggle_gaussian_toggled(GtkToggleButton *togglebutton, gpointer user_data)
488 {
489 GtkWidget* xyplot = NULL;
490 GList* data_list = NULL;
491 GList* current = NULL;
492 XYPlotWinData* data;
493
494
495 if(!user_data || !G_IS_OBJECT(user_data)) return;
496 if(!gtk_toggle_button_get_active(togglebutton)) return;
497
498 xyplot = GTK_WIDGET(user_data);
499 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
500
501 if(!data_list) return;
502 current=g_list_first(data_list);
503 for(; current != NULL; current = current->next)
504 {
505 data = (XYPlotWinData*)current->data;
506 if(data->convType!=GABEDIT_CONV_TYPE_GAUSS)
507 {
508 data->convType=GABEDIT_CONV_TYPE_GAUSS;
509 build_data_xyplot(data);
510 }
511 }
512 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
513 }
514 /********************************************************************************/
toggle_show_peaks_toggled(GtkToggleButton * togglebutton,gpointer user_data)515 static void toggle_show_peaks_toggled(GtkToggleButton *togglebutton, gpointer user_data)
516 {
517 GtkWidget* xyplot = NULL;
518 GList* data_list = NULL;
519 GList* current = NULL;
520 XYPlotWinData* data;
521 gboolean showPeaks = FALSE;
522
523 if(!user_data || !G_IS_OBJECT(user_data)) return;
524
525 xyplot = GTK_WIDGET(user_data);
526 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
527
528 if(!data_list) return;
529
530 showPeaks = gtk_toggle_button_get_active(togglebutton);
531 current=g_list_first(data_list);
532 for(; current != NULL; current = current->next)
533 {
534 data = (XYPlotWinData*)current->data;
535 gabedit_xyplot_remove_data(GABEDIT_XYPLOT(xyplot), (gpointer)data->dataPeaks);
536 if(data->showDataPeaks!=showPeaks)
537 {
538 data->showDataPeaks=showPeaks;
539 build_data_xyplot(data);
540 if(data->showDataPeaks)
541 gabedit_xyplot_add_data(GABEDIT_XYPLOT(xyplot), (gpointer)data->dataPeaks);
542 }
543 }
544 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
545
546 }
547 /********************************************************************************/
toggle_ymax_to_one_toggled(GtkToggleButton * togglebutton,gpointer user_data)548 static void toggle_ymax_to_one_toggled(GtkToggleButton *togglebutton, gpointer user_data)
549 {
550 GtkWidget* xyplot = NULL;
551 GList* data_list = NULL;
552 GList* current = NULL;
553 XYPlotWinData* data;
554 gboolean ymaxToOne = FALSE;
555 gdouble ymin = 0;
556 gdouble ymax = 0;
557 gdouble a;
558
559 if(!user_data || !G_IS_OBJECT(user_data)) return;
560
561 xyplot = GTK_WIDGET(user_data);
562 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
563
564 if(!data_list) return;
565
566 ymaxToOne = gtk_toggle_button_get_active(togglebutton);
567 current=g_list_first(data_list);
568 for(; current != NULL; current = current->next)
569 {
570 data = (XYPlotWinData*)current->data;
571 gabedit_xyplot_remove_data(GABEDIT_XYPLOT(xyplot), (gpointer)data->dataCurve);
572 if(data->ymaxToOne!=ymaxToOne)
573 {
574 data->ymaxToOne=ymaxToOne;
575 build_data_xyplot(data);
576 gabedit_xyplot_add_data(GABEDIT_XYPLOT(xyplot), (gpointer)data->dataCurve);
577 a =get_ymin(data->dataCurve);
578 if(ymin>a) ymin = a;
579 a =get_ymax(data->dataCurve);
580 if(ymax<a) ymax = a;
581
582 }
583 }
584 if(ymaxToOne)
585 {
586 ymin = 0.0;
587 ymax = 1.0;
588 }
589 {
590 gabedit_xyplot_set_range_ymin (GABEDIT_XYPLOT(xyplot), ymin);
591 gabedit_xyplot_set_range_ymax (GABEDIT_XYPLOT(xyplot), ymax);
592 }
593 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
594
595 }
596 /****************************************************************************************/
xyplot_motion_notify_event(GtkWidget * xyplot,GdkEventMotion * event,gpointer user_data)597 static gboolean xyplot_motion_notify_event(GtkWidget *xyplot, GdkEventMotion *event, gpointer user_data)
598 {
599 double xv, yv;
600 int x, y;
601 char str[50];
602 int context_id;
603 GtkWidget* statusbar = g_object_get_data(G_OBJECT (xyplot), "StatusBar");
604
605 x=event->x;
606 y=event->y;
607
608 if (event->is_hint || (event->window != xyplot->window))
609 gdk_window_get_pointer (xyplot->window, &x, &y, NULL);
610
611 if(gabedit_xyplot_get_point(GABEDIT_XYPLOT(xyplot), x, y, &xv, &yv))
612 snprintf(str, 50, _("Mouse position: %lf, %lf"), xv, yv);
613 else
614 sprintf(str, " ");
615 context_id=gtk_statusbar_get_context_id (GTK_STATUSBAR(statusbar), "mouse position");
616 gtk_statusbar_push (GTK_STATUSBAR(statusbar), context_id, str);
617
618 return TRUE;
619 }
620 /********************************************************************************/
activate_entry_xmin(GtkWidget * entry,gpointer user_data)621 static void activate_entry_xmin(GtkWidget *entry, gpointer user_data)
622 {
623 G_CONST_RETURN gchar* t;
624 gdouble a;
625 GtkWidget* xyplot = NULL;
626 gdouble xmin;
627 gdouble ymin;
628 gdouble xmax;
629 gdouble ymax;
630
631
632 if(!user_data || !G_IS_OBJECT(user_data)) return;
633
634 xyplot = GTK_WIDGET(user_data);
635 t= gtk_entry_get_text(GTK_ENTRY(entry));
636 a = atof(t);
637 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &xmin, &xmax, &ymin, &ymax);
638
639 if(a>= xmax)
640 {
641 gchar* tmp = g_strdup_printf("%0.3f",xmin);
642 gtk_entry_set_text(GTK_ENTRY(entry),tmp);
643 g_free(tmp);
644 return;
645 }
646 gabedit_xyplot_set_range_xmin (GABEDIT_XYPLOT(xyplot), a);
647 gabedit_xyplot_refresh_dat(GABEDIT_XYPLOT(xyplot));
648 }
649 /********************************************************************************/
activate_entry_xmax(GtkWidget * entry,gpointer user_data)650 static void activate_entry_xmax(GtkWidget *entry, gpointer user_data)
651 {
652 G_CONST_RETURN gchar* t;
653 gdouble a;
654 GtkWidget* xyplot = NULL;
655 gdouble xmin;
656 gdouble ymin;
657 gdouble xmax;
658 gdouble ymax;
659
660
661 if(!user_data || !G_IS_OBJECT(user_data)) return;
662
663 xyplot = GTK_WIDGET(user_data);
664 t= gtk_entry_get_text(GTK_ENTRY(entry));
665 a = atof(t);
666 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &xmin, &xmax, &ymin, &ymax);
667
668 if(a<=xmin)
669 {
670 gchar* tmp = g_strdup_printf("%0.3f",xmax);
671 gtk_entry_set_text(GTK_ENTRY(entry),tmp);
672 g_free(tmp);
673 return;
674 }
675 gabedit_xyplot_set_range_xmax (GABEDIT_XYPLOT(xyplot), a);
676 gabedit_xyplot_refresh_dat(GABEDIT_XYPLOT(xyplot));
677 }
678 /********************************************************************************/
activate_entry_half_width(GtkWidget * entry,gpointer user_data)679 static void activate_entry_half_width(GtkWidget *entry, gpointer user_data)
680 {
681 G_CONST_RETURN gchar* t;
682 gdouble a;
683 GtkWidget* xyplot = NULL;
684 gdouble xmin;
685 gdouble ymin;
686 gdouble xmax;
687 gdouble ymax;
688 GList* data_list = NULL;
689 GList* current = NULL;
690 XYPlotWinData* data;
691
692
693 if(!user_data || !G_IS_OBJECT(user_data)) return;
694
695 xyplot = GTK_WIDGET(user_data);
696 t= gtk_entry_get_text(GTK_ENTRY(entry));
697 a = atof(t);
698 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &xmin, &xmax, &ymin, &ymax);
699
700 if(a<= 0)
701 {
702 gchar* tmp = g_strdup_printf("%0.3f",fabs(xmax-xmin)/30);
703 gtk_entry_set_text(GTK_ENTRY(entry),tmp);
704 g_free(tmp);
705 return;
706 }
707 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
708 if(!data_list) return;
709 current=g_list_first(data_list);
710 for(; current != NULL; current = current->next)
711 {
712 data = (XYPlotWinData*)current->data;
713 data->halfWidth = a;
714 if(data->convType!=GABEDIT_CONV_TYPE_NONE)
715 {
716 build_data_xyplot(data);
717 }
718 }
719 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
720 }
721 /********************************************************************************/
activate_entry_scale_x(GtkWidget * entry,gpointer user_data)722 static void activate_entry_scale_x(GtkWidget *entry, gpointer user_data)
723 {
724 G_CONST_RETURN gchar* t;
725 gdouble a;
726 GtkWidget* xyplot = NULL;
727 gdouble xmin;
728 gdouble ymin;
729 gdouble xmax;
730 gdouble ymax;
731 GList* data_list = NULL;
732 GList* current = NULL;
733 XYPlotWinData* data;
734
735
736 if(!user_data || !G_IS_OBJECT(user_data)) return;
737
738 xyplot = GTK_WIDGET(user_data);
739 t= gtk_entry_get_text(GTK_ENTRY(entry));
740 a = atof(t);
741 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &xmin, &xmax, &ymin, &ymax);
742
743 if(a<= 0)
744 {
745 gchar* tmp = g_strdup_printf("%0.3f",1.0);
746 gtk_entry_set_text(GTK_ENTRY(entry),tmp);
747 g_free(tmp);
748 return;
749 }
750 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
751 if(!data_list) return;
752 current=g_list_first(data_list);
753 for(; current != NULL; current = current->next)
754 {
755 data = (XYPlotWinData*)current->data;
756 data->scaleX = a;
757 build_data_xyplot(data);
758 }
759 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
760 }
761 /********************************************************************************/
activate_entry_scale_y(GtkWidget * entry,gpointer user_data)762 static void activate_entry_scale_y(GtkWidget *entry, gpointer user_data)
763 {
764 G_CONST_RETURN gchar* t;
765 gdouble a;
766 GtkWidget* xyplot = NULL;
767 gdouble xmin;
768 gdouble ymin;
769 gdouble xmax;
770 gdouble ymax;
771 GList* data_list = NULL;
772 GList* current = NULL;
773 XYPlotWinData* data;
774
775
776 if(!user_data || !G_IS_OBJECT(user_data)) return;
777
778 xyplot = GTK_WIDGET(user_data);
779 t= gtk_entry_get_text(GTK_ENTRY(entry));
780 a = atof(t);
781 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &xmin, &xmax, &ymin, &ymax);
782
783 if(a<= 0)
784 {
785 gchar* tmp = g_strdup_printf("%0.3f",1.0);
786 gtk_entry_set_text(GTK_ENTRY(entry),tmp);
787 g_free(tmp);
788 return;
789 }
790 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
791 if(!data_list) return;
792 current=g_list_first(data_list);
793 for(; current != NULL; current = current->next)
794 {
795 data = (XYPlotWinData*)current->data;
796 data->scaleY = a;
797 build_data_xyplot(data);
798 }
799 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
800 }
801 /********************************************************************************/
activate_entry_shift_x(GtkWidget * entry,gpointer user_data)802 static void activate_entry_shift_x(GtkWidget *entry, gpointer user_data)
803 {
804 G_CONST_RETURN gchar* t;
805 gdouble a;
806 GtkWidget* xyplot = NULL;
807 gdouble xmin;
808 gdouble ymin;
809 gdouble xmax;
810 gdouble ymax;
811 GList* data_list = NULL;
812 GList* current = NULL;
813 XYPlotWinData* data;
814
815
816 if(!user_data || !G_IS_OBJECT(user_data)) return;
817
818 xyplot = GTK_WIDGET(user_data);
819 t= gtk_entry_get_text(GTK_ENTRY(entry));
820 a = atof(t);
821 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &xmin, &xmax, &ymin, &ymax);
822
823 data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
824 if(!data_list) return;
825 current=g_list_first(data_list);
826 for(; current != NULL; current = current->next)
827 {
828 data = (XYPlotWinData*)current->data;
829 data->shiftX = a;
830 build_data_xyplot(data);
831 }
832 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
833 }
834 /*************************************************************************************/
gabedit_xyplot_autorange(GabeditXYPlot * xyplot)835 static void gabedit_xyplot_autorange(GabeditXYPlot *xyplot)
836 {
837 GList* data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
838 GList* current = NULL;
839 XYPlotWinData* data;
840 GtkWidget *entry_half_width = g_object_get_data(G_OBJECT (xyplot), "EntryHalfWidth");
841 GtkWidget *entry_scale_x = g_object_get_data(G_OBJECT (xyplot), "EntryScaleX");
842 GtkWidget *entry_scale_y = g_object_get_data(G_OBJECT (xyplot), "EntryScaleY");
843 GtkWidget *entry_shift_x = g_object_get_data(G_OBJECT (xyplot), "EntryShiftX");
844 GtkWidget*entry_x_min = g_object_get_data(G_OBJECT (xyplot), "EntryXMin");
845 GtkWidget*entry_x_max = g_object_get_data(G_OBJECT (xyplot), "EntryXMax");
846
847 if(!data_list) return;
848 current=g_list_first(data_list);
849 if(!current) return;
850 data = (XYPlotWinData*)current->data;
851 if(data->dataCurve) gabedit_xyplot_set_autorange (xyplot, data->dataCurve);
852 if(data->dataPeaks) gabedit_xyplot_set_autorange (xyplot, data->dataPeaks);
853 if(data->convType!=GABEDIT_CONV_TYPE_NONE && (data->dataCurve ||data->dataPeaks ))
854 {
855 gchar tmp[100];
856 gabedit_xyplot_get_range (GABEDIT_XYPLOT(xyplot), &(data->xmin), &(data->xmax), &(data->ymin), &(data->ymax));
857
858 sprintf(tmp,"%0.3f",data->xmin);
859 gtk_entry_set_text(GTK_ENTRY(entry_x_min),tmp);
860 sprintf(tmp,"%0.3f",data->xmax);
861 gtk_entry_set_text(GTK_ENTRY(entry_x_max),tmp);
862
863 gabedit_xyplot_set_range_ymin (GABEDIT_XYPLOT(xyplot), data->ymin);
864 gabedit_xyplot_set_range_ymin (GABEDIT_XYPLOT(xyplot), data->ymax);
865
866 data->halfWidth = fabs(data->xmax-data->xmin)/30;
867
868 build_data_xyplot(data);
869
870 sprintf(tmp,"%0.3f",data->halfWidth);
871 gtk_entry_set_text(GTK_ENTRY(entry_half_width),tmp);
872
873 sprintf(tmp,"%0.3f",data->scaleX);
874 gtk_entry_set_text(GTK_ENTRY(entry_scale_x),tmp);
875
876 sprintf(tmp,"%0.3f",data->scaleY);
877 gtk_entry_set_text(GTK_ENTRY(entry_scale_y),tmp);
878
879 sprintf(tmp,"%0.3f",data->shiftX);
880 gtk_entry_set_text(GTK_ENTRY(entry_shift_x),tmp);
881
882 }
883 gtk_widget_queue_draw(GTK_WIDGET(xyplot));
884 }
885 /****************************************************************************************/
spectrum_win_add_data(GtkWidget * winXYPlot,gint size,gdouble * x,gdouble * y)886 void spectrum_win_add_data(GtkWidget *winXYPlot, gint size, gdouble* x, gdouble* y)
887 {
888 GabeditXYPlot *xyplot = g_object_get_data(G_OBJECT (winXYPlot), "XYPLOT");
889 XYPlotWinData* winData = NULL;
890 if(!xyplot || !G_IS_OBJECT(xyplot)) return;
891 winData = get_win_data(xyplot, size, x, y);
892 gabedit_xyplot_add_windata(xyplot, winData);
893 gabedit_xyplot_refresh_dat(GABEDIT_XYPLOT(xyplot));
894 gabedit_xyplot_show_curve_peaks(GABEDIT_XYPLOT(xyplot));
895 }
896 /****************************************************************************************/
spectrum_win_autorange(GtkWidget * winXYPlot)897 void spectrum_win_autorange(GtkWidget *winXYPlot)
898 {
899 GabeditXYPlot *xyplot = g_object_get_data(G_OBJECT (winXYPlot), "XYPLOT");
900 if(!xyplot || !G_IS_OBJECT(xyplot)) return;
901 gabedit_xyplot_autorange(xyplot);
902 }
903 /****************************************************************************************/
free_data(GtkWidget * window)904 static void free_data(GtkWidget *window)
905 {
906 GtkWidget* xyplot = g_object_get_data(G_OBJECT (window), "XYPLOT");
907 GList* data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
908 GList* current = NULL;
909 XYPlotWinData* data = NULL;
910 if(!data_list) return;
911 current=g_list_first(data_list);
912 for(; current != NULL; current = current->next)
913 {
914 data = (XYPlotWinData*)current->data;
915 if(data)
916 {
917 if(data->dataCurve) gabedit_xyplot_remove_data(GABEDIT_XYPLOT(xyplot), (gpointer)data->dataCurve);
918 if(data->dataPeaks) gabedit_xyplot_remove_data(GABEDIT_XYPLOT(xyplot), (gpointer)data->dataPeaks);
919 if(data->dataCurve && data->dataCurve->x) g_free(data->dataCurve->x);
920 if(data->dataCurve && data->dataCurve->y) g_free(data->dataCurve->y);
921 if(data->dataCurve) g_free(data->dataCurve);
922 if(data->dataPeaks && data->dataPeaks->x) g_free(data->dataPeaks->x);
923 if(data->dataPeaks && data->dataPeaks->y) g_free(data->dataPeaks->y);
924 if(data->dataPeaks) g_free(data->dataPeaks);
925 if(data->x) g_free(data->x);
926 if(data->y) g_free(data->y);
927 }
928 g_free(data);
929 }
930 g_object_set_data(G_OBJECT (xyplot), "DataList",NULL);
931 }
932 /****************************************************************************************/
spectrum_win_remove_data(GtkWidget * window)933 void spectrum_win_remove_data(GtkWidget *window)
934 {
935 free_data(window);
936 }
937 /****************************************************************************************/
destroy_spectrum_win(GtkWidget * window,gpointer data)938 static void destroy_spectrum_win(GtkWidget *window, gpointer data)
939 {
940 free_data(window);
941 gtk_widget_destroy(window);
942 }
943 /****************************************************************************************/
spectrum_win_new(gchar * title)944 GtkWidget* spectrum_win_new(gchar* title)
945 {
946 GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
947 GtkWidget* table1 = NULL;
948 GtkWidget* table2 = NULL;
949 GtkWidget* frame_xyplot = NULL;
950 GtkWidget* xyplot = NULL;
951 GtkWidget* tmp_label = NULL;
952 GtkWidget* vbox = NULL;
953
954 GtkWidget* entry_x_min = NULL;
955 GtkWidget* entry_x_max = NULL;
956
957 GtkWidget *statusbar = NULL;
958
959 GtkWidget *frame_set_data = NULL;
960 GtkWidget *toggle_no_convolution = NULL;
961 GtkWidget *toggle_lorentzian = NULL;
962 GtkWidget *toggle_gaussian = NULL;
963 GtkWidget *toggle_show_peaks = NULL;
964 GtkWidget *toggle_ymax_to_one = NULL;
965 GtkWidget *entry_half_width = NULL;
966 GtkWidget *entry_scale_x = NULL;
967 GtkWidget *entry_scale_y = NULL;
968 GtkWidget *entry_shift_x = NULL;
969 GtkWidget* hbox_data = NULL;
970 GtkWidget* first_hbox = NULL;
971
972 GList* data_list = NULL;
973
974 gdouble xmin = 0;
975 gdouble xmax = 10;
976
977 gchar tmp[100];
978
979 gtk_window_set_title (GTK_WINDOW (window), title);
980 gtk_signal_connect (GTK_OBJECT (window), "delete_event", G_CALLBACK (destroy_spectrum_win), NULL);
981 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
982
983 table1=gtk_table_new(5, 3, FALSE);
984 gtk_container_add(GTK_CONTAINER(window), table1);
985 gtk_widget_show(table1);
986
987 frame_xyplot=gtk_frame_new("XY GabeditPlot");
988 gtk_table_attach(GTK_TABLE(table1), frame_xyplot, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
989 gtk_widget_show(frame_xyplot);
990
991 xyplot = gabedit_xyplot_new();
992 gtk_container_add(GTK_CONTAINER(frame_xyplot), xyplot);
993 gtk_widget_show (xyplot);
994
995 g_object_set_data (G_OBJECT (window), "XYPLOT",xyplot);
996
997 frame_set_data=gtk_frame_new(_("Set data"));
998 gtk_table_attach(GTK_TABLE(table1), frame_set_data, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 5);
999 gtk_widget_show(frame_set_data);
1000
1001 table2=gtk_table_new(2, 5, FALSE);
1002 gtk_container_add(GTK_CONTAINER(frame_set_data), table2);
1003 gtk_widget_show(table2);
1004
1005 hbox_data = gtk_hbox_new(FALSE,2);
1006 gtk_table_attach(GTK_TABLE(table2), hbox_data, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 2, 2);
1007 gtk_widget_show(hbox_data);
1008
1009 first_hbox = hbox_data;
1010
1011 toggle_no_convolution = gtk_radio_button_new_with_label( NULL,_("No convolution"));
1012 gtk_box_pack_start(GTK_BOX(hbox_data), toggle_no_convolution, FALSE, FALSE, 2);
1013 gtk_widget_show(toggle_no_convolution);
1014
1015 toggle_lorentzian = gtk_radio_button_new_with_label(gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle_no_convolution)),_("Lorentzian lineshape") );
1016 gtk_box_pack_start(GTK_BOX(hbox_data), toggle_lorentzian, FALSE, FALSE, 2);
1017 gtk_widget_show(toggle_lorentzian);
1018
1019 toggle_gaussian = gtk_radio_button_new_with_label(gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle_no_convolution)),_("Gaussian lineshape") );
1020 gtk_box_pack_start(GTK_BOX(hbox_data), toggle_gaussian, FALSE, FALSE, 2);
1021 gtk_widget_show(toggle_gaussian);
1022
1023 toggle_show_peaks = gtk_check_button_new_with_label(_("Show peaks"));
1024 gtk_box_pack_start(GTK_BOX(hbox_data), toggle_show_peaks, FALSE, FALSE, 2);
1025 gtk_widget_show(toggle_show_peaks);
1026
1027 toggle_ymax_to_one = gtk_check_button_new_with_label(_("Set ymax=1"));
1028 gtk_box_pack_start(GTK_BOX(hbox_data), toggle_ymax_to_one, FALSE, FALSE, 2);
1029 gtk_widget_show(toggle_ymax_to_one);
1030
1031 hbox_data = gtk_hbox_new(FALSE,2);
1032 gtk_table_attach(GTK_TABLE(table2), hbox_data, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 2, 2);
1033 gtk_widget_show(hbox_data);
1034
1035 tmp_label=gtk_label_new(_("X Min: "));
1036 gtk_box_pack_start(GTK_BOX(hbox_data), tmp_label, FALSE, FALSE, 2);
1037 gtk_widget_show(tmp_label);
1038
1039 entry_x_min = gtk_entry_new();
1040 gtk_widget_set_size_request(entry_x_min,50,-1);
1041 sprintf(tmp,"%0.3f",xmin);
1042 gtk_entry_set_text(GTK_ENTRY(entry_x_min),tmp);
1043 gtk_box_pack_start(GTK_BOX(hbox_data), entry_x_min, FALSE, FALSE, 2);
1044 gtk_widget_show(entry_x_min);
1045
1046 tmp_label=gtk_label_new(_("X Max: "));
1047 gtk_box_pack_start(GTK_BOX(hbox_data), tmp_label, FALSE, FALSE, 2);
1048 gtk_widget_show(tmp_label);
1049
1050 entry_x_max = gtk_entry_new();
1051 gtk_widget_set_size_request(entry_x_max,50,-1);
1052 sprintf(tmp,"%0.3f",xmax);
1053 gtk_entry_set_text(GTK_ENTRY(entry_x_max),tmp);
1054 gtk_box_pack_start(GTK_BOX(hbox_data), entry_x_max, FALSE, FALSE, 2);
1055 gtk_widget_show(entry_x_max);
1056
1057 tmp_label=gtk_label_new(_("Half-Width : "));
1058 gtk_box_pack_start(GTK_BOX(hbox_data), tmp_label, FALSE, FALSE, 2);
1059 gtk_widget_show(tmp_label);
1060
1061 entry_half_width = gtk_entry_new();
1062 gtk_widget_set_size_request(entry_half_width,50,-1);
1063 gtk_entry_set_text(GTK_ENTRY(entry_half_width),"0.25");
1064 gtk_box_pack_start(GTK_BOX(hbox_data), entry_half_width, FALSE, FALSE, 2);
1065 gtk_widget_show(entry_half_width);
1066
1067 tmp_label=gtk_label_new(_("Scale X : "));
1068 gtk_box_pack_start(GTK_BOX(hbox_data), tmp_label, FALSE, FALSE, 2);
1069 gtk_widget_show(tmp_label);
1070
1071 entry_scale_x = gtk_entry_new();
1072 gtk_widget_set_size_request(entry_scale_x,50,-1);
1073 gtk_entry_set_text(GTK_ENTRY(entry_scale_x),"1.0");
1074 gtk_box_pack_start(GTK_BOX(hbox_data), entry_scale_x, FALSE, FALSE, 2);
1075 gtk_widget_show(entry_scale_x);
1076
1077 tmp_label=gtk_label_new(_("Scale Y : "));
1078 gtk_box_pack_start(GTK_BOX(hbox_data), tmp_label, FALSE, FALSE, 2);
1079 gtk_widget_show(tmp_label);
1080
1081 entry_scale_y = gtk_entry_new();
1082 gtk_widget_set_size_request(entry_scale_y,50,-1);
1083 gtk_entry_set_text(GTK_ENTRY(entry_scale_y),"1.0");
1084 gtk_box_pack_start(GTK_BOX(hbox_data), entry_scale_y, FALSE, FALSE, 2);
1085 gtk_widget_show(entry_scale_y);
1086
1087 tmp_label=gtk_label_new(_("Shift X : "));
1088 gtk_box_pack_start(GTK_BOX(hbox_data), tmp_label, FALSE, FALSE, 2);
1089 gtk_widget_show(tmp_label);
1090
1091 entry_shift_x = gtk_entry_new();
1092 gtk_widget_set_size_request(entry_shift_x,50,-1);
1093 gtk_entry_set_text(GTK_ENTRY(entry_shift_x),"0.0");
1094 gtk_box_pack_start(GTK_BOX(hbox_data), entry_shift_x, FALSE, FALSE, 2);
1095 gtk_widget_show(entry_shift_x);
1096
1097
1098 g_object_set_data(G_OBJECT (xyplot), "DataList", data_list);
1099
1100 statusbar=gtk_statusbar_new();
1101 gtk_table_attach(GTK_TABLE(table1), statusbar, 0, 1, 3, 4, GTK_FILL, GTK_FILL, 2, 2);
1102 gtk_widget_show (statusbar);
1103 g_object_set_data(G_OBJECT (xyplot), "StatusBar", statusbar);
1104
1105 vbox = gtk_vbox_new(FALSE,2);
1106 gtk_table_attach(GTK_TABLE(table1), vbox, 0, 1, 4, 5, GTK_FILL, GTK_FILL, 2, 2);
1107 gtk_widget_show(vbox);
1108
1109
1110 gabedit_xyplot_set_range(GABEDIT_XYPLOT(xyplot), 0.0, 10, 0, 20);
1111
1112 gabedit_xyplot_set_x_legends_digits(GABEDIT_XYPLOT(xyplot), 5);
1113 gabedit_xyplot_set_y_legends_digits(GABEDIT_XYPLOT(xyplot), 5);
1114
1115 g_signal_connect (G_OBJECT (entry_x_min), "activate", (GCallback)activate_entry_xmin, xyplot);
1116 g_signal_connect (G_OBJECT (entry_x_max), "activate", (GCallback)activate_entry_xmax, xyplot);
1117
1118 g_signal_connect(G_OBJECT(toggle_no_convolution), "toggled", G_CALLBACK(toggle_no_convolution_toggled), xyplot);
1119 g_signal_connect(G_OBJECT(toggle_lorentzian), "toggled", G_CALLBACK(toggle_lorentzian_toggled), xyplot);
1120 g_signal_connect(G_OBJECT(toggle_gaussian), "toggled", G_CALLBACK(toggle_gaussian_toggled), xyplot);
1121 g_signal_connect (G_OBJECT (entry_half_width), "activate", (GCallback)activate_entry_half_width, xyplot);
1122 g_signal_connect (G_OBJECT (entry_scale_x), "activate", (GCallback)activate_entry_scale_x, xyplot);
1123 g_signal_connect (G_OBJECT (entry_scale_y), "activate", (GCallback)activate_entry_scale_y, xyplot);
1124 g_signal_connect (G_OBJECT (entry_shift_x), "activate", (GCallback)activate_entry_shift_x, xyplot);
1125 g_signal_connect(G_OBJECT(toggle_show_peaks), "toggled", G_CALLBACK(toggle_show_peaks_toggled), xyplot);
1126
1127 g_signal_connect(G_OBJECT(toggle_ymax_to_one), "toggled", G_CALLBACK(toggle_ymax_to_one_toggled), xyplot);
1128
1129
1130 g_signal_connect_after(G_OBJECT(xyplot), "motion-notify-event", G_CALLBACK(xyplot_motion_notify_event), NULL);
1131
1132 gtk_widget_show (window);
1133
1134
1135 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_show_peaks), FALSE);
1136 toggle_show_peaks_toggled(GTK_TOGGLE_BUTTON(toggle_show_peaks), xyplot);
1137
1138 g_object_set_data(G_OBJECT (xyplot), "EntryHalfWidth", entry_half_width);
1139 g_object_set_data(G_OBJECT (xyplot), "EntryScaleX", entry_scale_x);
1140 g_object_set_data(G_OBJECT (xyplot), "EntryScaleY", entry_scale_y);
1141 g_object_set_data(G_OBJECT (xyplot), "EntryShiftX", entry_shift_x);
1142 g_object_set_data(G_OBJECT (xyplot), "EntryXMin", entry_x_min);
1143 g_object_set_data(G_OBJECT (xyplot), "EntryXMax", entry_x_max);
1144 g_object_set_data(G_OBJECT (xyplot), "HBoxData", first_hbox);
1145 g_object_set_data(G_OBJECT (xyplot), "HBoxData2", hbox_data);
1146 g_object_set_data(G_OBJECT (xyplot), "VBox", vbox);
1147 g_object_set_data(G_OBJECT (xyplot), "Window", window);
1148 g_object_set_data(G_OBJECT (window), "HBoxData", first_hbox);
1149 g_object_set_data(G_OBJECT (window), "HBoxData2", hbox_data);
1150 g_object_set_data(G_OBJECT (window), "VBox", vbox);
1151 g_object_set_data(G_OBJECT (window), "NoConvolutionButton", toggle_no_convolution);
1152
1153 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_lorentzian), TRUE);
1154 toggle_lorentzian_toggled((GtkToggleButton*)toggle_lorentzian,xyplot);
1155
1156 gabedit_xyplot_set_font (GABEDIT_XYPLOT(xyplot), "sans 10");
1157 gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(Fenetre));
1158
1159
1160 gabedit_xyplot_enable_grids (GABEDIT_XYPLOT(xyplot), GABEDIT_XYPLOT_HMAJOR_GRID, FALSE);
1161 gabedit_xyplot_enable_grids (GABEDIT_XYPLOT(xyplot), GABEDIT_XYPLOT_VMAJOR_GRID, FALSE);
1162
1163 gabedit_xyplot_reflect_x (GABEDIT_XYPLOT(xyplot), FALSE);
1164 gabedit_xyplot_reflect_y (GABEDIT_XYPLOT(xyplot), FALSE);
1165
1166
1167 return window;
1168 }
1169 /****************************************************************************************/
spectrum_win_relect_x(GtkWidget * winSpectrum,gboolean active)1170 void spectrum_win_relect_x(GtkWidget* winSpectrum, gboolean active)
1171 {
1172 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1173 gabedit_xyplot_reflect_x (GABEDIT_XYPLOT(xyplot), active);
1174 }
1175 /****************************************************************************************/
spectrum_win_relect_y(GtkWidget * winSpectrum,gboolean active)1176 void spectrum_win_relect_y(GtkWidget* winSpectrum, gboolean active)
1177 {
1178 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1179 gabedit_xyplot_reflect_y (GABEDIT_XYPLOT(xyplot), active);
1180 }
1181 /****************************************************************************************/
spectrum_win_set_half_width(GtkWidget * winSpectrum,gdouble value)1182 void spectrum_win_set_half_width(GtkWidget* winSpectrum, gdouble value)
1183 {
1184 gchar tmp[100];
1185 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1186 GtkWidget *entry_half_width = g_object_get_data(G_OBJECT (xyplot), "EntryHalfWidth");
1187 sprintf(tmp,"%0.3f",value);
1188 gtk_entry_set_text(GTK_ENTRY(entry_half_width),tmp);
1189 activate_entry_half_width(entry_half_width, xyplot);
1190 }
1191 /****************************************************************************************/
spectrum_win_set_xmin(GtkWidget * winSpectrum,gdouble value)1192 void spectrum_win_set_xmin(GtkWidget* winSpectrum, gdouble value)
1193 {
1194 gchar tmp[100];
1195 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1196 GtkWidget *entry_x_min = g_object_get_data(G_OBJECT (xyplot), "EntryXMin");
1197 sprintf(tmp,"%0.3f",value);
1198 gtk_entry_set_text(GTK_ENTRY(entry_x_min),tmp);
1199 activate_entry_xmin(entry_x_min, xyplot);
1200 }
1201 /****************************************************************************************/
spectrum_win_set_xmax(GtkWidget * winSpectrum,gdouble value)1202 void spectrum_win_set_xmax(GtkWidget* winSpectrum, gdouble value)
1203 {
1204 gchar tmp[100];
1205 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1206 GtkWidget *entry_x_max = g_object_get_data(G_OBJECT (xyplot), "EntryXMax");
1207 sprintf(tmp,"%0.3f",value);
1208 gtk_entry_set_text(GTK_ENTRY(entry_x_max),tmp);
1209 activate_entry_xmax(entry_x_max, xyplot);
1210 }
1211 /****************************************************************************************/
spectrum_win_set_ymin(GtkWidget * winSpectrum,gdouble value)1212 void spectrum_win_set_ymin(GtkWidget* winSpectrum, gdouble value)
1213 {
1214 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1215 gabedit_xyplot_set_range_ymin (GABEDIT_XYPLOT(xyplot), value);
1216 }
1217 /****************************************************************************************/
spectrum_win_set_ymax(GtkWidget * winSpectrum,gdouble value)1218 void spectrum_win_set_ymax(GtkWidget* winSpectrum, gdouble value)
1219 {
1220 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1221 gabedit_xyplot_set_range_ymax (GABEDIT_XYPLOT(xyplot), value);
1222 }
1223 /****************************************************************************************/
spectrum_win_set_xlabel(GtkWidget * winSpectrum,gchar * label)1224 void spectrum_win_set_xlabel(GtkWidget* winSpectrum, gchar* label)
1225 {
1226 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1227 if(!xyplot) printf("ERROR xyplot =0\n");
1228 gabedit_xyplot_set_x_label (GABEDIT_XYPLOT(xyplot), label);
1229 }
1230 /****************************************************************************************/
spectrum_win_set_ylabel(GtkWidget * winSpectrum,gchar * label)1231 void spectrum_win_set_ylabel(GtkWidget* winSpectrum, gchar* label)
1232 {
1233 GtkWidget* xyplot = g_object_get_data (G_OBJECT (winSpectrum), "XYPLOT");
1234 gabedit_xyplot_set_y_label (GABEDIT_XYPLOT(xyplot), label);
1235 }
1236 /****************************************************************************************/
spectrum_win_reset_ymin_ymax(GtkWidget * xyplot)1237 void spectrum_win_reset_ymin_ymax(GtkWidget *xyplot)
1238 {
1239 GList* data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
1240 GList* current = NULL;
1241 XYPlotWinData* data = NULL;
1242 if(!data_list) return;
1243 current=g_list_first(data_list);
1244 if(current) data = (XYPlotWinData*)current->data;
1245 if(data && data->ymaxToOne)
1246 {
1247 gabedit_xyplot_set_range_ymin (GABEDIT_XYPLOT(xyplot), 0.0);
1248 gabedit_xyplot_set_range_ymax (GABEDIT_XYPLOT(xyplot), 1.0);
1249 }
1250 }
1251 /****************************************************************************************/
1252 /*
1253 GtkWidget* spectrum_win_new_testing(gchar* title)
1254 {
1255 GtkWidget* window = spectrum_win_new(title);
1256 gint size = 20;
1257 gint i;
1258 gdouble x[20];
1259 gdouble y[20];
1260 for(i=0;i<size;i++)
1261 {
1262 x[i] = i;
1263 y[i] = rand()/(gdouble)RAND_MAX*size;
1264 }
1265 spectrum_win_add_data(winSpectrum, size, x, y);
1266 spectrum_win_autorange(window);
1267 return window;
1268 }
1269 */
1270 /****************************************************************************************/
spectrum_win_new_with_xy(gchar * title,gint size,gdouble * x,gdouble * y)1271 GtkWidget* spectrum_win_new_with_xy(gchar* title, gint size, gdouble* x, gdouble* y)
1272 {
1273 GtkWidget* winSpectrum = spectrum_win_new(title);
1274 spectrum_win_add_data(winSpectrum, size, x, y);
1275 spectrum_win_autorange(winSpectrum);
1276 return winSpectrum;
1277 }
1278 /****************************************************************************************/
spectrum_win_get_dataCurve(GtkWidget * winSpectrum)1279 XYPlotData* spectrum_win_get_dataCurve(GtkWidget *winSpectrum)
1280 {
1281 GtkWidget* xyplot = g_object_get_data(G_OBJECT (winSpectrum), "XYPLOT");
1282 GList* data_list = g_object_get_data(G_OBJECT (xyplot), "DataList");
1283 GList* current = NULL;
1284 XYPlotWinData* data = NULL;
1285 if(!data_list) return NULL;
1286 current=g_list_first(data_list);
1287 for(; current != NULL; current = current->next)
1288 {
1289 data = (XYPlotWinData*)current->data;
1290 if(data && data->dataCurve) return data->dataCurve;
1291 }
1292 return NULL;
1293 }
1294